:root {
  --bg: #0E1116;
  --card: #171B22;
  --map-bg: #141920;
  --line: #222832;
  --track: #232A34;
  --text: #EEF1F5;
  --text-2: #C9D0D8;
  --muted: #9AA3AF;
  --good: #3DDC97;
  --weak: #F5B544;
  --dead: #FF6B6B;
  --unknown: #3A414C;
  --danger-bg: #2A1416;
  --danger-line: #5A2226;
  --danger-label: #FFB3B3;
  --danger-text: #E9C7C7;
  --danger-strong: #FFD6D6;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --tabbar-h: 66px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2 { font-family: 'Space Grotesk', Inter, sans-serif; font-weight: 700; margin: 0; letter-spacing: -0.5px; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 22px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

main {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--sat) + 20px) calc(var(--sar) + 20px) calc(var(--tabbar-h) + var(--sab) + 24px) calc(var(--sal) + 20px);
}
.view { display: flex; flex-direction: column; gap: 0; }
#idle, #live { display: flex; flex-direction: column; }

/* En-têtes */
.head { display: flex; flex-direction: column; gap: 4px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.meta { font-size: 13px; color: var(--muted); font-weight: 500; }
.sub { font-size: 13px; color: var(--muted); margin: 0; }
p.sub { font-size: 14px; color: var(--text-2); margin-top: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.pill-on { color: var(--good); }
.pill-on .dot { animation: pulse 1.6s ease-in-out infinite; }
.pill-off { color: var(--muted); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pill-on .dot { animation: none; } }

/* Cartes */
.card {
  margin-top: 16px;
  padding: 20px;
  border-radius: 20px;
  background: var(--card);
  display: flex; flex-direction: column; gap: 12px;
}
.head + .card { margin-top: 20px; }
.card-tight { gap: 6px; }
.card.danger { background: var(--danger-bg); border: 1px solid var(--danger-line); }
.label { font-size: 13px; color: var(--muted); font-weight: 500; }
.card.danger .label { color: var(--danger-label); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint.center { text-align: center; }
.body-text { margin: 0; font-size: 14px; color: var(--text-2); }

/* Maintenant */
.now-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.now-state { font-family: 'Space Grotesk', sans-serif; font-size: 40px; font-weight: 700; line-height: 1; }
.now-detail { font-size: 15px; color: var(--text-2); }
.bars { display: flex; gap: 4px; align-items: flex-end; height: 36px; }
.bars span { flex: 1; border-radius: 2px; min-height: 3px; }

/* Prochaine coupure */
.big-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.big { font-family: 'Space Grotesk', sans-serif; font-size: 48px; font-weight: 700; color: var(--dead); letter-spacing: -1px; line-height: 1; }
.big-sub { font-size: 16px; color: var(--danger-strong); font-weight: 500; }
.outage-text { font-size: 14px; color: var(--danger-text); margin: 0; }
.empty-big { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; color: var(--good); }

/* Bande 40 km */
.ahead { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.ahead-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.ahead-band { height: 14px; display: flex; gap: 2px; }
.ahead-band span { height: 14px; border-radius: 3px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend i.me { border-radius: 5px; background: var(--text); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--text); }
.legend-map { margin-top: 12px; }

/* Boutons */
.actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.btn {
  min-height: 52px; border: 0; border-radius: 14px; padding: 0 18px;
  font-size: 16px; font-weight: 600;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-secondary { background: var(--track); color: var(--text); }
.btn-small { min-height: 44px; font-size: 15px; background: var(--track); color: var(--text); border-radius: 12px; }
.btn:disabled { opacity: .5; }
.link-btn {
  min-height: 44px; background: none; border: 0; color: var(--text-2);
  font-size: 13px; text-decoration: underline; text-underline-offset: 3px;
}
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center;
  background: none; border: 0; border-radius: 12px; color: var(--text-2);
}

/* Pastilles opérateur */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.ops-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ops-field legend { padding: 0; margin-bottom: 10px; }
.pill-btn, .pill-radio span {
  min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid #323A46; background: transparent; color: var(--text-2);
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center;
}
.pill-btn[aria-pressed="true"], .pill-radio input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.pill-radio { position: relative; }
.pill-radio input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.pill-radio input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
#view-carte .head { gap: 12px; }

/* Carte */
.map-wrap { margin-top: 16px; position: relative; border-radius: 20px; overflow: hidden; background: var(--map-bg); }
#map { height: min(46vh, 400px); min-height: 280px; background: var(--map-bg); }
.leaflet-container { background: var(--map-bg); font-family: Inter, system-ui, sans-serif; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.9) saturate(0.35); }
.leaflet-control-attribution { background: rgba(14,17,22,.8) !important; color: var(--text-2) !important; font-size: 11px; }
.leaflet-control-attribution a { color: var(--text) !important; }
.leaflet-bar a { background: var(--card) !important; color: var(--text) !important; border-color: var(--line) !important; width: 36px !important; height: 36px !important; line-height: 36px !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.map-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 20px; text-align: center; color: var(--text-2); font-size: 14px; }

.usable { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.usable-row { display: grid; grid-template-columns: 76px 1fr 48px; align-items: center; gap: 10px; }
.usable-row .name { font-size: 14px; color: var(--text-2); }
.usable-row .track { height: 10px; border-radius: 5px; background: var(--track); display: flex; }
.usable-row .fill { height: 10px; border-radius: 5px; }
.usable-row .pct { font-size: 14px; font-weight: 600; text-align: right; }

/* Trajets */
.todo { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.todo li { display: flex; align-items: center; gap: 4px; }
.todo label { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; }
.todo input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--good); margin: 0; flex: none; }
.todo .done { color: var(--muted); text-decoration: line-through; }
.add-row { display: flex; gap: 8px; }
input[type="text"], textarea {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid #323A46; background: var(--bg); color: var(--text); font-size: 16px;
}
textarea { resize: vertical; width: 100%; }
::placeholder { color: #8A939F; }
.url-status { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.url-status li { display: flex; justify-content: space-between; gap: 10px; align-items: center; color: var(--text-2); }
.url-status .u { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.url-status .ok { color: var(--good); }
.url-status .ko { color: var(--danger-label); }
.url-status a { color: var(--text); white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; }

.history { margin-top: 20px; display: flex; flex-direction: column; gap: 4px; }
.trip { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.trip-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.trip-route { font-size: 15px; font-weight: 600; }
.trip-date { font-size: 13px; color: var(--muted); white-space: nowrap; }
.trip-band { display: flex; gap: 2px; height: 8px; }
.trip-band span { border-radius: 2px; }
.trip-sum { font-size: 13px; color: var(--text-2); }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  background: rgba(14,17,22,.96);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 10px calc(var(--sar)) calc(var(--sab) + 10px) calc(var(--sal));
}
.tabbar button {
  background: none; border: 0; min-height: 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 12px; font-weight: 500;
}
.tabbar button[aria-current="page"] { color: var(--text); font-weight: 600; }

/* Bannière d'alerte */
.alert-banner {
  position: fixed; z-index: 2000; left: 12px; right: 12px; top: calc(var(--sat) + 10px);
  max-width: 456px; margin: 0 auto;
  background: var(--danger-bg); border: 1px solid var(--danger-line); border-radius: 18px;
  padding: 14px 8px 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.alert-banner strong { display: block; font-family: 'Space Grotesk', sans-serif; font-size: 22px; color: var(--dead); }
.alert-banner span { font-size: 14px; color: var(--danger-text); }

/* Réglages */
dialog {
  width: min(440px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); color: var(--text); padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-inner { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 16px; }
.dialog-block { display: flex; flex-direction: column; gap: 6px; }
.switch-row { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; font-size: 15px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--good); margin: 2px 0 0; flex: none; }
.switch-row small { color: var(--muted); font-size: 12px; }
