/* =============================================================================
 * carte-panel.css — Agent Panneau & UX
 * Bottom-sheet mobile (3 crans) + panneau lateral desktop, chips de couches.
 * Mobile-first, zones tactiles >= 44px, mode sombre via prefers-color-scheme.
 * Palette coherente avec le vert du site (#16a34a).
 * =========================================================================== */

:root {
  --sm-green: #16a34a;
  --sm-green-dk: #128a3e;
  --sm-panel-bg: #ffffff;
  --sm-panel-fg: #1f2937;
  --sm-panel-muted: #6b7280;
  --sm-panel-border: #e5e7eb;
  --sm-panel-surface: #f3f4f6;
  --sm-panel-shadow: 0 -4px 24px rgba(0, 0, 0, .14);
  --sm-radius: 16px;
  --sm-z-panel: 1200;
}

/* --------------------------------------------------------------------- */
/* Conteneur / bottom-sheet (mobile)                                     */
/* --------------------------------------------------------------------- */

.sm-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--sm-z-panel);
  pointer-events: none;           /* seul le sheet capte les clics */
}

.sm-panel[aria-hidden="true"] .sm-sheet {
  transform: translateY(100%);
}

.sm-sheet {
  pointer-events: auto;
  position: relative;
  height: 88vh;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--sm-panel-bg);
  color: var(--sm-panel-fg);
  border-radius: var(--sm-radius) var(--sm-radius) 0 0;
  box-shadow: var(--sm-panel-shadow);
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
  touch-action: none;
  overscroll-behavior: contain;
}

/* Poignee de glissement */
.sm-grip {
  flex: 0 0 auto;
  height: 30px;
  min-height: 44px;              /* zone tactile confortable */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.sm-grip:active { cursor: grabbing; }
.sm-grip-bar {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: #cbd1d9;
  transition: background 200ms ease;
}
.sm-grip:hover .sm-grip-bar { background: var(--sm-green); }
.sm-grip:focus-visible {
  outline: 2px solid var(--sm-green);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Bouton fermer */
.sm-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--sm-panel-muted);
  font-size: 20px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease;
}
.sm-close:hover { background: var(--sm-panel-surface); color: var(--sm-panel-fg); }
.sm-close:focus-visible { outline: 2px solid var(--sm-green); outline-offset: 2px; }

/* Zone de contenu scrollable */
.sm-content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  touch-action: pan-y;
}
.sm-content:focus { outline: none; }

/* --------------------------------------------------------------------- */
/* Etats generiques                                                      */
/* --------------------------------------------------------------------- */

.sm-empty {
  text-align: center;
  color: var(--sm-panel-muted);
  padding: 32px 16px;
}
.sm-empty i { font-size: 34px; color: var(--sm-green); opacity: .8; }
.sm-empty p { margin-top: 12px; font-size: 15px; }

.sm-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 8px;
  color: var(--sm-panel-muted);
  font-size: 15px;
}
.sm-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--sm-panel-border);
  border-top-color: var(--sm-green);
  border-radius: 50%;
  animation: sm-spin 800ms linear infinite;
}
@keyframes sm-spin { to { transform: rotate(360deg); } }

.sm-error {
  padding: 24px 8px;
  color: #b91c1c;
  font-size: 15px;
}
.sm-error i { margin-right: 6px; }
.sm-error .sm-btn { margin-top: 12px; }

.sm-muted { color: var(--sm-panel-muted); font-size: 14px; margin: 6px 0; }
.sm-muted i { margin-right: 4px; }

/* Enveloppe de la jauge d'affluence dans la fiche arret */
.sm-aff-wrap { margin: 4px 0 2px; }

/* Etat "pas de temps reel" -> renvoi vers la fiche arret */
.sm-next-empty {
  background: var(--sm-panel-surface);
  border-radius: 12px;
  padding: 14px;
  margin-top: 4px;
}
.sm-next-empty .sm-muted { margin: 0 0 10px; }
.sm-btn-link { text-decoration: none; }

.sm-section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sm-panel-muted);
  margin: 18px 0 8px;
}
.sm-section-label i { color: var(--sm-green); margin-right: 4px; }

/* --------------------------------------------------------------------- */
/* Fiche arret                                                           */
/* --------------------------------------------------------------------- */

.sm-stop-head { margin-top: 4px; }
.sm-stop-type {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sm-green);
}
.sm-stop-titlerow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}
.sm-stop-name {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.2;
  margin: 0;
}

/* Bouton favori */
.sm-fav-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 20px;
  border-radius: 50%;
  cursor: pointer;
  transition: color 200ms ease, transform 200ms ease, background 200ms ease;
}
.sm-fav-btn:hover { background: var(--sm-panel-surface); }
.sm-fav-btn.is-fav { color: #f59e0b; }
.sm-fav-btn.is-fav:active { transform: scale(1.2); }
.sm-fav-btn:focus-visible { outline: 2px solid var(--sm-green); outline-offset: 2px; }

/* Pastilles lignes */
.sm-line-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.sm-line-badge {
  min-width: 44px;
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.sm-line-badge:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.sm-line-badge:focus-visible { outline: 2px solid #111; outline-offset: 2px; }

/* Prochains passages */
.sm-next { list-style: none; margin: 0; padding: 0; }
.sm-next-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--sm-panel-border);
}
.sm-next-line {
  flex: 0 0 auto;
  min-width: 34px;
  height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sm-next-dir { flex: 1 1 auto; font-size: 14px; color: var(--sm-panel-fg); }
.sm-next-time { flex: 0 0 auto; font-weight: 700; color: var(--sm-green); display: inline-flex; align-items: center; gap: 6px; }

/* Badge temps réel : point vert pulsant */
.sm-next-rt { display: inline-flex; align-items: center; }
.sm-next-rt-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--sm-green);
  box-shadow: 0 0 0 0 rgba(22, 163, 74, .6);
  animation: sm-rt-pulse 1.8s infinite;
}
@keyframes sm-rt-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, .55); }
  70%  { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
@media (prefers-reduced-motion: reduce) { .sm-next-rt-dot { animation: none; } }
.sm-next-updated {
  margin: 8px 2px 0; font-size: 12px; color: var(--sm-panel-muted);
  display: flex; align-items: center; gap: 6px;
}

/* Actions */
.sm-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.sm-actions-util { margin-top: 10px; }
.sm-btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 200ms ease, box-shadow 200ms ease, transform 150ms ease, border-color 200ms ease;
}
.sm-btn:active { transform: translateY(1px); }
.sm-btn:focus-visible { outline: 2px solid var(--sm-green); outline-offset: 2px; }
.sm-btn-primary { background: var(--sm-green); color: #fff; }
.sm-btn-primary:hover { background: var(--sm-green-dk); }
.sm-btn-secondary {
  background: rgba(22,163,74,.10);
  color: var(--sm-green-dk);
  border-color: rgba(22,163,74,.30);
}
.sm-btn-secondary:hover { background: rgba(22,163,74,.18); }
.sm-btn-ghost {
  background: var(--sm-panel-surface);
  color: var(--sm-panel-fg);
}
.sm-btn-ghost:hover { background: #e6e9ee; }

/* Arrets proches */
.sm-nearby, .sm-fav-items, .sm-line-stops { list-style: none; margin: 0; padding: 0; }
.sm-nearby-item, .sm-fav-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: var(--sm-panel-fg);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--sm-panel-border);
  transition: background 160ms ease;
}
.sm-nearby-item:hover, .sm-fav-item:hover { background: var(--sm-panel-surface); }
.sm-nearby-item:focus-visible, .sm-fav-item:focus-visible {
  outline: 2px solid var(--sm-green);
  outline-offset: -2px;
}
.sm-nearby-item i, .sm-fav-item i { color: var(--sm-green); width: 18px; text-align: center; }
.sm-nearby-name { flex: 1 1 auto; }
.sm-nearby-dist { flex: 0 0 auto; font-size: 13px; color: var(--sm-panel-muted); }

/* --------------------------------------------------------------------- */
/* Fiche ligne                                                           */
/* --------------------------------------------------------------------- */

.sm-line-head { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.sm-line-chip {
  flex: 0 0 auto;
  min-width: 48px;
  height: 48px;
  padding: 0 12px;
  border-radius: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.sm-line-headtxt { min-width: 0; }
.sm-line-type {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sm-green);
}
.sm-line-type i { margin-right: 4px; }
.sm-line-name { font-size: 18px; font-weight: 800; margin: 0; line-height: 1.2; }

.sm-line-stops { position: relative; margin-top: 4px; }
.sm-line-stop {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--sm-panel-fg);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease;
}
.sm-line-stop:hover { background: var(--sm-panel-surface); }
.sm-line-stop:focus-visible { outline: 2px solid var(--sm-green); outline-offset: -2px; }
.sm-line-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--sm-line-col, var(--sm-green));
  position: relative;
}
/* trait vertical reliant les arrets */
.sm-line-stops li { position: relative; }
.sm-line-stops li:not(:last-child) .sm-line-dot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  width: 3px;
  height: 44px;
  background: var(--sm-line-col, var(--sm-green));
  opacity: .5;
}

/* --------------------------------------------------------------------- */
/* Favoris (etat vide)                                                   */
/* --------------------------------------------------------------------- */

.sm-favlist { margin-top: 8px; text-align: left; }

/* --------------------------------------------------------------------- */
/* #sm-layers : chips de couches                                         */
/* --------------------------------------------------------------------- */

.sm-layers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sm-chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--sm-panel-border);
  background: var(--sm-panel-bg);
  color: var(--sm-panel-fg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  transition: background 200ms ease, color 200ms ease, border-color 200ms ease, transform 150ms ease;
}
.sm-chip i { font-size: 13px; opacity: .75; }
.sm-chip:hover { border-color: var(--sm-green); }
.sm-chip:active { transform: scale(.97); }
.sm-chip:focus-visible { outline: 2px solid var(--sm-green); outline-offset: 2px; }
.sm-chip.is-on {
  background: var(--sm-green);
  border-color: var(--sm-green);
  color: #fff;
}
.sm-chip.is-on i { opacity: 1; }

/* --------------------------------------------------------------------- */
/* Toast (feedback partage / favori)                                     */
/* --------------------------------------------------------------------- */

.sm-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  z-index: calc(var(--sm-z-panel) + 10);
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 240ms ease, transform 240ms ease;
}
.sm-toast i { color: var(--sm-green); margin-right: 4px; }
.sm-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 768px) {
  .sm-toast { bottom: 24px; }
}

/* --------------------------------------------------------------------- */
/* Panneau lateral (desktop >= 768px)                                    */
/* --------------------------------------------------------------------- */

@media (min-width: 768px) {
  .sm-panel {
    left: auto;
    right: 12px;
    top: 12px;
    bottom: 12px;
    width: 380px;
    max-width: 40vw;
  }
  .sm-sheet {
    height: 100%;
    max-height: 100%;
    border-radius: var(--sm-radius);
    transform: none !important;
    box-shadow: 0 8px 30px rgba(0,0,0,.18);
    touch-action: auto;
  }
  .sm-panel[aria-hidden="true"] .sm-sheet {
    transform: translateX(120%) !important;
  }
  .sm-panel[aria-hidden="true"] { pointer-events: none; }
  /* La poignee devient un simple bandeau decoratif */
  .sm-grip { cursor: default; min-height: 22px; height: 22px; }
  .sm-grip:hover .sm-grip-bar { background: #cbd1d9; }
}

/* --------------------------------------------------------------------- */
/* Mode sombre                                                           */
/* --------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  :root {
    --sm-panel-bg: #1b2430;
    --sm-panel-fg: #e5e9f0;
    --sm-panel-muted: #9aa5b5;
    --sm-panel-border: #2c3846;
    --sm-panel-surface: #243040;
    --sm-panel-shadow: 0 -4px 24px rgba(0, 0, 0, .5);
  }
  .sm-grip-bar { background: #47566a; }
  .sm-btn-ghost:hover { background: #2c3a4c; }
  .sm-chip { box-shadow: 0 1px 4px rgba(0,0,0,.4); }
  .sm-line-dot { background: var(--sm-panel-bg); }
  .sm-error { color: #f87171; }
  .sm-toast { background: #e5e9f0; color: #111827; box-shadow: 0 6px 24px rgba(0, 0, 0, .6); }
  .sm-toast i { color: var(--sm-green-dk); }
}

/* --------------------------------------------------------------------- */
/* Override via attribut data-theme (bascule manuelle du site)           */
/* --------------------------------------------------------------------- */
:root[data-theme="light"] .sm-toast { background: #111827; color: #fff; }
:root[data-theme="light"] .sm-toast i { color: var(--sm-green); }

/* Respect des preferences de mouvement reduit */
@media (prefers-reduced-motion: reduce) {
  .sm-sheet { transition: none; }
  .sm-spinner { animation-duration: 1.6s; }
  .sm-toast { transition: opacity 200ms ease; transform: translate(-50%, 0); }
}
