:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #dde3ea;
  --text: #14202e;
  --muted: #5d6b7b;
  --accent: #0f6fde;
  --accent-soft: #e3effd;
  --ok: #1f9d55;
  --ok-soft: #e1f5e9;
  --warn: #d98200;
  --warn-soft: #fdf0dc;
  --late: #d93b3b;
  --late-soft: #fde4e4;
  --theo: #8a97a6;
  --theo-soft: #eceff3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
  --topbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c2430;
    --border: #2a3441;
    --text: #e6edf3;
    --muted: #8b98a8;
    --accent: #4c9bff;
    --accent-soft: #17283f;
    --ok: #3fbf74;
    --ok-soft: #14301f;
    --warn: #f0a23a;
    --warn-soft: #3a2a12;
    --late: #ff6b6b;
    --late-soft: #3d1a1c;
    --theo: #7d8a99;
    --theo-soft: #222b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }

/* ---------- Barre du haut ---------- */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 8h14a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2zm0 3v5h14v-5z' fill='white'/%3E%3Ccircle cx='11' cy='25' r='2' fill='white'/%3E%3Ccircle cx='21' cy='25' r='2' fill='white'/%3E%3C/svg%3E") center/26px no-repeat;
}
h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.kpis { display: flex; gap: 22px; margin-left: auto; }
.kpi { display: flex; flex-direction: column; align-items: flex-end; }
.kpi-v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-v.warn { color: var(--warn); }
.kpi-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.feed {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px;
  white-space: nowrap;
}
.feed .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--theo); }
.feed.ok .dot { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
.feed.err .dot { background: var(--late); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 400px; flex: none;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
  z-index: 1000;
}
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.sheet-handle { display: none; }

.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); flex: none; }
.tab {
  background: none; border: 0; padding: 8px 12px 10px;
  color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.toolbar { padding: 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--border); flex: none; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.toolbar.row { flex-direction: row; gap: 16px; flex-wrap: wrap; }
.toolbar.row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input[type=search], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  outline: none;
}
select { width: auto; padding: 6px 10px; }
input[type=search]:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 550; }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 12px;
  align-items: center;
  cursor: pointer;
}
.list li:hover { background: var(--surface-2); }
.list li.sel { background: var(--accent-soft); }
.num {
  grid-row: span 2;
  min-width: 52px; text-align: center;
  font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums;
  padding: 5px 6px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.route { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.list .stop-row { grid-template-columns: 1fr auto; }
.list .stop-row .meta { grid-column: 1 / 3; }

.pill {
  font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.late { background: var(--late-soft); color: var(--late); }
.pill.theo { background: var(--theo-soft); color: var(--theo); }
.pill.cancel { background: var(--late); color: #fff; }

/* ---------- Détail course ---------- */
.detail-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.back { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; font-size: 18px; flex: none; }
.back:hover { background: var(--surface-2); }
.detail-title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 4px; background: var(--surface-2); flex: none; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .6s; }
.detail-status { padding: 12px 14px 4px; color: var(--muted); font-size: 13px; }
.detail-status b { color: var(--text); }

.timeline { list-style: none; margin: 0; padding: 8px 14px 8px 14px; }
.timeline li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; position: relative; padding: 8px 0; }
.timeline li::before {
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--border);
}
.timeline li:first-child::before { top: 50%; }
.timeline li:last-child::before { bottom: 50%; }
.timeline li.passed::before { background: var(--accent); }
.timeline li.half::before { background: linear-gradient(var(--accent) 50%, var(--border) 50%); }
.timeline .tdot {
  width: 12px; height: 12px; border-radius: 50%; margin: 5px auto 0; z-index: 1;
  background: var(--surface); border: 2px solid var(--theo);
}
.timeline li.passed .tdot { background: var(--accent); border-color: var(--accent); }
.timeline li.current .tdot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.timeline li.cancelled .tname { text-decoration: line-through; color: var(--late); }
.tname { font-weight: 550; cursor: pointer; }
.tname:hover { color: var(--accent); }
.tsub { font-size: 12px; color: var(--muted); }
.ttimes { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.ttimes .main { font-weight: 650; }
.ttimes s { color: var(--muted); font-size: 12px; margin-right: 4px; }
.ttimes .src { display: block; font-size: 11px; color: var(--muted); }
.t-ok { color: var(--ok); }
.t-warn { color: var(--warn); }
.t-late { color: var(--late); }
.bus-here { grid-column: 2 / 4; font-size: 12px; color: var(--accent); font-weight: 600; padding: 2px 0; }
.note { font-size: 12px; color: var(--muted); padding: 4px 14px 18px; margin: 0; }

.detail-actions { padding: 10px 14px 2px; display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 550; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.icon { width: 34px; justify-content: center; padding: 7px 0; }

/* ---------- Écran à bord (modale) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(4, 8, 14, .82);
  display: flex; flex-direction: column; padding: 18px; gap: 10px;
}
.modal-bar { display: flex; align-items: center; gap: 8px; color: #fff; }
.modal-bar .btn { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .18); color: #fff; }
.modal-bar .btn:hover { background: rgba(255, 255, 255, .16); }
.modal-title { flex: 1; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-screen { flex: 1; min-height: 0; display: grid; place-items: center; }
.modal-screen iframe {
  width: min(100%, calc((100vh - 90px) * 16 / 9)); aspect-ratio: 16 / 9; max-height: 100%;
  border: 10px solid #1a1d22; border-radius: 14px; background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
@media (max-width: 820px) {
  .modal { padding: 10px; }
  .modal-screen iframe { border-width: 5px; border-radius: 8px; }
  #bord-full { display: none; }
}

/* ---------- Tableau d'arrêt ---------- */
.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 2px 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center;
}
.board li:hover { background: var(--surface-2); }
.board li.past { opacity: .55; }
.board .time { grid-row: span 2; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.board .time s { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.board .dir { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board .meta { grid-column: 2 / 4; }

/* ---------- Statistiques ---------- */
.stats { padding: 14px; display: flex; flex-direction: column; gap: 18px; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.card .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card .l { font-size: 11.5px; color: var(--muted); }
.stats h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 6px; border-bottom: 1px solid var(--border); }
.bars .b { flex: 1; min-width: 4px; background: var(--ok); border-radius: 3px 3px 0 0; position: relative; }
.bars .b.warn { background: var(--warn); }
.bars .b.late { background: var(--late); }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.worst { list-style: none; margin: 0; padding: 0; }
.worst li { display: grid; grid-template-columns: 52px 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--border); align-items: center; }
.worst .meta { grid-column: 2 / 4; }

/* ---------- Carte ---------- */
.legend {
  position: absolute; left: 12px; bottom: 22px; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px 10px; font-size: 12px; color: var(--muted);
  display: flex; gap: 12px; flex-wrap: wrap;
}
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.lg.ok { background: var(--ok); } .lg.warn { background: var(--warn); } .lg.late { background: var(--late); } .lg.theo { background: var(--theo); }

small.tz { font-size: 10px; font-weight: 500; color: var(--muted); }
.maplibregl-map { font: inherit; }
.tip .maplibregl-popup-content {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 7px 10px; pointer-events: none;
}
.tip.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--surface); }
.tip.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--surface); }
.tip.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface); }
.tip.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface); }
.maplibregl-ctrl-group { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--border); }
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1); }
  .maplibregl-ctrl-attrib { background: rgba(21, 27, 35, .8) !important; color: var(--muted); }
  .maplibregl-ctrl-attrib-button { filter: invert(1); }
}
.maplibregl-ctrl-attrib a { color: var(--accent); }
.tip-title { font-weight: 650; }
.tip-sub { color: var(--muted); font-size: 12px; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  :root { --topbar-h: 56px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .sub, .kpi:nth-child(3), .kpi:nth-child(4) { display: none; }
  .kpis { gap: 14px; }
  .kpi-v { font-size: 17px; }
  .feed #feed-text { display: none; }
  .feed { padding: 8px; }
  .layout { position: relative; }
  .map-wrap { position: absolute; inset: 0; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    width: auto; height: 45%;
    border-right: 0; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
    transition: height .25s ease;
  }
  .panel.expanded { height: calc(100% - 12px); }
  .panel.collapsed { height: 104px; }
  .sheet-handle { display: flex; justify-content: center; align-items: center; height: 18px; border: 0; background: none; flex: none; padding: 0; }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--border); }
  .tabs { padding-top: 0; }
  .legend { bottom: auto; top: 10px; left: 10px; right: 56px; gap: 4px 10px; font-size: 11px; }
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
}
