:root {
  --bg: #f4f5f8; --card: #ffffff; --text: #14181f; --muted: #5b6472; --line: #e1e4ea;
  --ok: #1b7f3b; --ok-bg: #e5f4ea; --bad: #b42318; --bad-bg: #fde8e6;
  --unk: #8a5a00; --unk-bg: #fdf1d8; --accent: #14213d; --accent-fg: #ffffff;
  --shadow: 0 4px 18px rgba(20, 24, 31, .14);
  --appbar-h: 64px; --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --card: #171b22; --text: #e8ebf0; --muted: #9aa3b2; --line: #2a303a;
    --ok: #6fd391; --ok-bg: #12301d; --bad: #ff8a80; --bad-bg: #3a1714;
    --unk: #f5c46b; --unk-bg: #33280f; --accent: #9db4ff; --accent-fg: #0e1116;
    --shadow: 0 4px 18px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 18px 0 8px; }
.muted { color: var(--muted); font-size: .86rem; margin: 2px 0; }
.error { color: var(--bad); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.gap { justify-content: flex-start; flex-wrap: wrap; }

/* ---------- barre haute / navigation */
.appbar {
  position: sticky; top: 0; z-index: 1000; background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 8px; border-bottom: 1px solid var(--line);
}
main { max-width: 680px; margin: 0 auto; }
.view { padding: 0 16px calc(var(--tabbar-h) + var(--safe-b) + 20px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .74rem; font-weight: 600; position: relative;
}
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.tabbar .dot { position: absolute; top: 8px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }

/* ---------- cartes */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
}
.line-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.line-head .grow { flex: 1; min-width: 0; }
.badge {
  min-width: 2.3rem; height: 2.3rem; padding: 0 6px; border-radius: 9px; display: inline-grid; place-items: center;
  color: #fff; font-weight: 800; letter-spacing: -.02em; flex: none;
}
.badge.sm { min-width: 1.9rem; height: 1.7rem; border-radius: 7px; font-size: .85rem; }
.verdict { font-weight: 650; padding: 2px 9px; border-radius: 999px; font-size: .86rem; white-space: nowrap; }
.v-AUCUN_INCIDENT { color: var(--ok); background: var(--ok-bg); }
.v-PERTURBATIONS { color: var(--bad); background: var(--bad-bg); }
.v-INCONNU { color: var(--unk); background: var(--unk-bg); }
.chev { color: var(--muted); transition: transform .15s; }
.open .chev { transform: rotate(90deg); }
.alert { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; }
.alert p { margin: 4px 0; white-space: pre-line; }
.alert .when { font-size: .82rem; color: var(--muted); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-right: 6px; vertical-align: 1px; }
.tag.now { background: var(--bad-bg); color: var(--bad); }
.tag.soon { background: var(--unk-bg); color: var(--unk); }

.departures { list-style: none; margin: 8px 0 0; padding: 0; }
.departures li { display: grid; grid-template-columns: 4.2rem 1fr auto; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.departures .mins { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.departures .mins small { font-weight: 600; font-size: .75rem; }
.departures .clock { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.chip { font-size: .72rem; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.chip.rt { color: var(--ok); }
.chip.th { color: var(--muted); }
.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: 9px 0; border-top: 1px solid var(--line); }
.events small { color: var(--muted); }

button {
  font: inherit; border: 0; border-radius: 11px; padding: 10px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); font-weight: 650;
}
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.small { padding: 6px 10px; font-size: .86rem; }
button:disabled { opacity: .5; cursor: default; }
input { font: inherit; width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); margin: 6px 0 10px; }
.overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.overlay[hidden] { display: none; }
.overlay .card { width: min(420px, 100%); }

/* ---------- carte */
.view-map { position: fixed; left: 0; right: 0; top: var(--appbar-top, var(--appbar-h)); bottom: calc(var(--tabbar-h) + var(--safe-b)); padding: 0; }
.view-map[hidden] { display: none; }
#map { position: absolute; inset: 0; background: var(--bg); }
.leaflet-container { font: inherit; }
.map-top { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 500; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; pointer-events: none; }
.map-top > * { pointer-events: auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; max-width: 100%; padding-bottom: 2px; scrollbar-width: none; }
.chips button {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 5px; border-radius: 999px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .85rem; white-space: nowrap;
}
.chips button[aria-pressed="false"] { opacity: .5; }
.chips .sw { min-width: 1.7rem; height: 1.45rem; padding: 0 5px; border-radius: 999px; color: #fff; display: inline-grid; place-items: center; font-weight: 800; font-size: .78rem; }
.chips .n { color: var(--muted); font-weight: 600; }
.pill { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 999px; padding: 5px 11px; font-size: .8rem; color: var(--muted); }
.pill.ok::before, .pill.warn::before, .pill.bad::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.pill.ok::before { background: var(--ok); }
.pill.warn { color: var(--unk); } .pill.warn::before { background: var(--unk); }
.pill.bad { color: var(--bad); } .pill.bad::before { background: var(--bad); }
.map-fabs { position: absolute; right: 10px; bottom: 18px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.fab { width: 46px; height: 46px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.fab.active { color: #1a73e8; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-control-zoom { display: none; }

/* marqueurs véhicules */
.veh { position: relative; width: 34px; height: 34px; }
.veh .arrow { position: absolute; inset: 0; }
.veh .arrow::before { content: ""; position: absolute; left: 50%; top: -5px; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom: 9px solid var(--c); border-top: 0; }
.veh .body { position: absolute; inset: 3px; border-radius: 50%; background: var(--c); color: #fff; border: 2.5px solid #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 11px; letter-spacing: -.03em; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.veh.old { opacity: .45; filter: grayscale(.6); }
.veh.sel .body { outline: 3px solid var(--accent); outline-offset: 2px; }
.veh.late .body::after { content: ""; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: #e8590c; border: 2px solid #fff; }
.place-pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--accent); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); display: grid; place-items: center; }
.place-pin span { transform: rotate(45deg); color: var(--accent-fg); font-weight: 800; font-size: 11px; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(26,115,232,.35); }

/* panneau du bas */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 600; max-height: 62%; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.22);
  padding: 14px 16px 18px; animation: up .18s ease-out;
}
.sheet[hidden] { display: none; }
.sheet::before { content: ""; display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: -4px auto 10px; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.sheet-close { position: absolute; top: 8px; right: 10px; width: 34px; height: 34px; padding: 0; border-radius: 50%; background: var(--bg); color: var(--text); font-size: 1.3rem; line-height: 1; }
.sheet h3 { margin: 0; font-size: 1.05rem; }
.sheet .head { display: flex; gap: 10px; align-items: center; padding-right: 40px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .86rem; }
.kv dd { margin: 0; font-weight: 600; }
.highlight { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: 8px 10px; margin: 0 0 10px; font-weight: 650; }
.delay-ok { color: var(--ok); } .delay-late { color: #e8590c; } .delay-early { color: #1a73e8; }
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.vlist .sub { color: var(--muted); font-size: .8rem; }
.notice { background: var(--unk-bg); color: var(--unk); border-radius: 10px; padding: 8px 10px; font-size: .86rem; margin: 8px 0; }

.vlist .eta { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--ok); }
.vlist .eta small { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.88) contrast(.92) saturate(.6); }
  .leaflet-container { background: #1b1f24; }
}
.sheet-open .map-fabs { display: none; }
@media (prefers-color-scheme: dark) {
  .leaflet-container .leaflet-control-attribution { background: rgba(23, 27, 34, .85); color: var(--muted); }
  .leaflet-container .leaflet-control-attribution a { color: var(--accent); }
}
.group { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 2px 6px; }
