/* ========================================================================
   RTM Live — styles (thème sombre/clair)
   ======================================================================== */
:root {
  --bg: #0f1419;
  --bg-elev: #171e27;
  --bg-elev2: #1f2832;
  --border: #2a3542;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #009fe3;            /* bleu RTM */
  --accent-contrast: #ffffff;
  --danger: #ff5d5d;
  --warn: #ffb020;
  --ok: #30d158;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --radius: 12px;
  --sidebar-w: 360px;
}
:root[data-theme="light"] {
  --bg: #eef2f6;
  --bg-elev: #ffffff;
  --bg-elev2: #f4f7fa;
  --border: #d9e1e8;
  --text: #16202a;
  --text-dim: #5a6b7b;
  --accent: #0082bd;
  --accent-contrast: #ffffff;
  --danger: #d53b3b;
  --warn: #b8780a;
  --ok: #1f9d4d;
  --shadow: 0 8px 30px rgba(20,40,60,.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 1000;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.icon-btn {
  background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--accent); }

.tabs { display: flex; padding: 10px 12px 0; gap: 6px; }
.tab {
  flex: 1; background: transparent; border: none; color: var(--text-dim);
  padding: 9px 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  border-radius: 8px 8px 0 0; position: relative;
}
.tab.is-active { color: var(--text); background: var(--bg-elev2); }
.badge {
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 6px; margin-left: 2px;
}

.panel { display: none; flex: 1; overflow-y: auto; padding: 14px; }
.panel.is-active { display: block; }
.hint { color: var(--text-dim); font-size: 13px; line-height: 1.5; }

.search-row input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elev2);
  color: var(--text); font-size: 14px;
}
.search-row input:focus { outline: none; border-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip {
  border: 1px solid var(--border); background: var(--bg-elev2);
  color: var(--text-dim); border-radius: 20px; padding: 5px 12px;
  font-size: 12px; cursor: pointer; font-weight: 600;
}
.chip.is-active { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }

/* ---------------- Listes de lignes ---------------- */
.route-list { list-style: none; margin: 8px 0 0; padding: 0; }
.route-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-radius: 10px; cursor: pointer;
}
.route-item:hover { background: var(--bg-elev2); }
.route-item.is-selected { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.route-badge {
  min-width: 42px; height: 30px; padding: 0 8px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; flex-shrink: 0;
}
.route-meta { flex: 1; min-width: 0; }
.route-name { font-size: 13px; line-height: 1.3; }
.route-type { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.fav-btn {
  background: none; border: none; cursor: pointer; font-size: 18px;
  color: var(--text-dim); padding: 2px 4px;
}
.fav-btn.is-fav { color: var(--warn); }

/* ---------------- Alertes ---------------- */
.alerts-list { list-style: none; margin: 0; padding: 0; }
.alert-item {
  background: var(--bg-elev2); border-left: 3px solid var(--warn);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
}
.alert-item.lvl-warn  { border-left-color: var(--warn); }
.alert-item.lvl-alert { border-left-color: var(--danger); }
.alert-item.lvl-info  { border-left-color: var(--accent); }
.alert-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 5px;
}
.alert-tag {
  font-size: 10px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
  color: var(--text-dim); background: var(--bg); padding: 2px 7px; border-radius: 5px;
}
.alert-date { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.alert-item h3 { margin: 0 0 4px; font-size: 13px; }
.alert-item p { margin: 0; font-size: 12px; color: var(--text-dim); line-height: 1.45; }
/* Description repliée par défaut (4 lignes), dépliée au clic. */
.alert-desc {
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.alert-item.open .alert-desc { -webkit-line-clamp: unset; }
.mini-badge-plain {
  background: var(--bg); color: var(--text-dim); border: 1px solid var(--border);
}
.alert-routes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.alert-routes .mini-badge {
  font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px;
}

/* ---------------- Footer / statut temps réel ---------------- */
.sidebar-foot {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim);
}
.rt-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); }
.rt-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.rt-dot.err { background: var(--danger); }
.rt-dot.off { background: var(--text-dim); }

/* ---------------- Carte ---------------- */
#map { flex: 1; height: 100%; background: var(--bg); }
.leaflet-container { background: var(--bg); font-family: inherit; }

/* Rendu sombre des tuiles OSM (uniquement les tuiles, pas les marqueurs/contrôles). */
:root[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9);
}

/* Marqueur arrêt */
.stop-marker {
  width: 11px; height: 11px; background: var(--bg-elev);
  border: 2px solid var(--accent); border-radius: 50%;
}
/* Marqueur véhicule */
.veh-marker {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); border: 2px solid #fff;
}
.veh-marker span { transform: rotate(45deg); font-size: 11px; font-weight: 800; color: #fff; }

/* ---------------- Fiche détail ---------------- */
.detail {
  position: absolute; right: 16px; top: 16px; width: 320px; max-height: calc(100% - 32px);
  overflow-y: auto; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; z-index: 1200;
}
.detail-close { position: absolute; right: 10px; top: 10px; }
.detail h2 { margin: 0 0 10px; font-size: 16px; padding-right: 30px; }
.detail .stop-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer;
}
.detail .stop-row:hover { color: var(--accent); }

/* ---------------- Responsive ---------------- */
@media (max-width: 760px) {
  :root { --sidebar-w: 100%; }
  #app { flex-direction: column; }
  #sidebar { height: 46vh; min-width: 0; width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  #map { height: 54vh; }
  .detail { left: 16px; width: auto; }
}
