/* Cockpit — interface pensée pour l'écran central (tactile, paysage, lisible d'un coup d'œil) */
:root {
  --bg: #0b0d10;
  --bg-2: #12161b;
  --card: #161b21;
  --card-2: #1d232b;
  --line: #262d36;
  --text: #eef1f4;
  --muted: #8b95a1;
  --accent: #3ecf8e;        /* énergie */
  --accent-2: #3e9cf5;
  --warn: #f5a524;
  --danger: #e5484d;
  --home: #3ecf8e;
  --supercharger: #e5484d;
  --public: #3e9cf5;
  --radius: 18px;
  --rail: 104px;
  --top: 68px;
  --tap: 64px;              /* cible tactile minimale en voiture */
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
svg { display: block; }
button, input, select { font-family: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
small { font-size: .6em; }
code, .code { font: 500 14px/1.4 ui-monospace, "SF Mono", Consolas, monospace; }
.code { display: block; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; word-break: break-all; }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 22px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text);
  font-weight: 600; font-size: 17px; line-height: 1; text-decoration: none; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: #04140c; }
.btn.danger { color: #ffb4b6; border-color: #4a2427; }
.btn.big { min-height: var(--tap); font-size: 19px; width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-col { display: grid; gap: 12px; margin-top: 14px; }
.btn-col form { display: contents; }
.btn-col form .btn { width: 100%; }

/* ---------- authentification ---------- */
body.auth { display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 50% -10%, #17301f 0%, var(--bg) 60%); }
.auth-card { width: min(440px, 100%); display: grid; gap: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 32px; }
.auth-card label { display: grid; gap: 8px; color: var(--muted); font-size: 15px; }
.auth-card label.check { display: flex; align-items: center; gap: 12px; color: var(--text); }
.auth-card input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }
input, select {
  min-height: 56px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font: inherit; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.alert { margin: 0; padding: 12px 14px; border-radius: 12px; background: #3a1517; color: #ffb4b6; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 24px; letter-spacing: .02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent)); box-shadow: inset 0 0 0 7px var(--bg); }

/* ---------- structure ---------- */
body.app { display: grid; grid-template-columns: var(--rail) 1fr; grid-template-rows: var(--top) 1fr; height: 100vh; overflow: hidden; }
.rail { grid-row: 1 / 3; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 0; background: var(--bg-2); border-right: 1px solid var(--line); }
.rail .brand-mark { margin-bottom: 14px; }
.rail-btn { width: 84px; min-height: 84px; display: grid; place-items: center; gap: 4px; border-radius: 18px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; }
.rail-btn svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn.on { background: var(--card-2); color: var(--text); }
.rail-btn.on svg { stroke: var(--accent); }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

/* ---------- bouton portail ---------- */
/* Plein, contrasté (≈10:1), 58 px de haut : lisible en plein soleil comme de nuit, pas de survol */
.gate-btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 58px; min-width: 210px; padding: 0 24px;
  border: 2px solid transparent; border-radius: 16px;
  background: var(--accent); color: #04140c;
  font-family: inherit; font-size: 21px; font-weight: 800; letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .08s ease, background .15s ease;
}
.gate-btn svg { width: 28px; height: 28px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.gate-btn:active:not(:disabled) { transform: scale(.96); }
.gate-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.gate-btn:disabled { cursor: default; background: var(--card-2); color: var(--text); border-color: var(--line); }
.gate-btn[data-state=sending], .gate-btn[data-state=sent] { color: var(--accent); border-color: var(--accent); }
.gate-btn[data-state=wait] { color: var(--warn); border-color: var(--warn); }
.gate-btn[data-state=error] { color: #ff9a9d; border-color: var(--danger); }
.gate-progress { position: absolute; left: 0; bottom: 0; height: 5px; width: 0; background: currentColor; }
.gate-btn:disabled .gate-progress { animation: gate-lock var(--lock-ms, 6000ms) linear forwards; }
@keyframes gate-lock { from { width: 100%; } to { width: 0; } }

.clock { font-weight: 600; font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.status { display: flex; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px; background: var(--card-2); font-size: 15px; font-weight: 600; }
.pill.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--accent); border-color: #1e4a35; }
.pill.warn { color: var(--warn); border-color: #4d3a14; }
.pill.bad { color: #ffb4b6; border-color: #4a2427; }
body[data-mode=drive] #mode-pill { background: var(--accent); color: #04140c; }

main { overflow: auto; position: relative; }
.view { display: none; padding: 24px; min-height: 100%; }
.view.on { display: block; }
#view-copilote.on { padding: 0; height: 100%; }

.grid { display: grid; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.link-card { cursor: pointer; }
.link-card.wide { grid-column: span 2; }
.footnote { margin: 14px 2px 0; font-size: 13px; color: var(--muted); }
.eyebrow { color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 19px; }
.kv-row:last-child { border-bottom: 0; }
.kv-row span { color: var(--muted); }
.big-num { font-weight: 700; font-size: 46px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big-num small { font-size: 20px; color: var(--muted); font-weight: 600; }

/* ---------- cockpit ---------- */
.cockpit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.hero { grid-column: span 3; padding: 28px; background: linear-gradient(135deg, #14231b 0%, var(--card) 55%); }
.hero-top { display: flex; justify-content: space-between; gap: 20px; }
.soc { font-weight: 700; font-size: 120px; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.soc small { font-size: 44px; color: var(--muted); margin-left: 4px; }
.range { font-size: 26px; color: var(--muted); margin-top: 6px; }
.range span { color: var(--text); font-weight: 700; }
.charge-state { text-align: right; font-size: 22px; }
.charge-state b { display: block; font-size: 40px; color: var(--accent); }
.battery { position: relative; height: 22px; margin-top: 24px; border-radius: 11px; background: #0d1813; overflow: hidden; border: 1px solid #1e3a2b; }
.battery-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2aa36f, var(--accent)); transition: width .6s ease; }
.battery-fill.low { background: linear-gradient(90deg, #b8322f, var(--danger)); }
.battery-fill.charging { background-image: repeating-linear-gradient(115deg, #2aa36f 0 18px, #46dc9a 18px 36px); background-size: 200% 100%; animation: flow 1.6s linear infinite; }
@keyframes flow { to { background-position: -72px 0; } }
.battery-limit { position: absolute; top: -2px; bottom: -2px; width: 3px; background: #fff; opacity: .7; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 26px; margin-top: 16px; color: var(--muted); font-size: 17px; }
.hero-meta b { color: var(--text); }

.tires { display: grid; grid-template-columns: 1fr 70px 1fr; grid-template-rows: 70px 70px; gap: 0 18px; align-items: center; font-weight: 700; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.tires-car { grid-row: 1 / 3; grid-column: 2; height: 140px; border: 2px solid var(--line); border-radius: 28px 28px 22px 22px; }
.tires #tp-fl { grid-column: 1; grid-row: 1; text-align: right; } .tires #tp-fr { grid-column: 3; grid-row: 1; }
.tires #tp-rl { grid-column: 1; grid-row: 2; text-align: right; } .tires #tp-rr { grid-column: 3; grid-row: 2; }
.tires .low { color: var(--warn); }

/* mode roulant : on allège */
body[data-mode=drive] .drive-hide { display: none !important; }

/* ---------- copilote ---------- */
.copilot { position: relative; height: 100%; display: grid; grid-template-columns: 1fr 380px; }
#map { height: 100%; background: #0e1116; }
.leaflet-container { font: inherit; background: #0e1116; }
.leaflet-control-attribution { background: rgba(11,13,16,.7) !important; color: var(--muted) !important; font-size: 11px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { width: 48px !important; height: 48px !important; line-height: 48px !important; background: var(--card-2) !important; color: var(--text) !important; border-color: var(--line) !important; }
.hz-badge { display: grid; place-items: center; border-radius: 50%; }
.hz-marker { background: none; border: 0; }
.me-marker { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-2); border: 4px solid #fff; box-shadow: 0 0 0 8px rgba(62,156,245,.25); position: relative; }
.me-marker::after { content: ""; position: absolute; left: 50%; top: -18px; transform: translateX(-50%); border: 8px solid transparent; border-bottom: 12px solid #fff; }
.me-marker.no-heading::after { display: none; }

.map-tools { position: absolute; left: 18px; bottom: 18px; display: grid; gap: 12px; z-index: 500; }
.fab { width: var(--tap); height: var(--tap); border-radius: 18px; border: 1px solid var(--line); background: rgba(22,27,33,.92); color: var(--text); display: grid; place-items: center; cursor: pointer; }
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.fab[aria-pressed=true] { color: var(--accent); border-color: #1e4a35; }

.alert-banner {
  position: absolute; top: 18px; left: 18px; right: 398px; z-index: 600;
  display: flex; align-items: center; gap: 18px; padding: 16px 22px; border-radius: 20px;
  background: rgba(22,27,33,.96); border: 2px solid var(--warn); box-shadow: 0 10px 30px rgba(0,0,0,.5);
  font-size: 24px; font-weight: 700;
}
.alert-banner.red { border-color: var(--danger); }
.alert-banner.blue { border-color: #3d63dd; }
.alert-banner .dist { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 34px; }

.hazard-panel { background: var(--bg-2); border-left: 1px solid var(--line); padding: 20px; display: flex; flex-direction: column; min-height: 0; }
.hazard-panel h3 { margin: 0 0 12px; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hazard-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.hazard-list li { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.hazard-list .hz-text { flex: 1; min-width: 0; }
.hazard-list .hz-text b { display: block; }
.hazard-list .hz-text span { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hazard-list .hz-dist { font-weight: 700; font-variant-numeric: tabular-nums; }
.report-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.report-btn { min-height: 82px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: grid; place-items: center; gap: 4px; font-weight: 600; font-size: 13px; line-height: 1.1; cursor: pointer; padding: 8px 4px; }
.report-btn:active { transform: scale(.96); }

/* ---------- recharges ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.seg button { min-height: 48px; padding: 0 18px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; font-size: 16px; line-height: 1; cursor: pointer; }
.seg button.on { background: var(--card-2); color: var(--text); }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.kpi span { display: block; color: var(--muted); font-size: 15px; }
.kpi b { font-weight: 700; font-size: 38px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 20px; color: var(--muted); font-size: 15px; margin-bottom: 14px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.sw.home { background: var(--home); } .sw.supercharger { background: var(--supercharger); } .sw.public { background: var(--public); }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 220px; padding-top: 22px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.bar .seg-home { background: var(--home); } .bar .seg-supercharger { background: var(--supercharger); } .bar .seg-public, .bar .seg-manual { background: var(--public); }
.bar > div:first-of-type { border-radius: 6px 6px 0 0; }
.bar .lbl { position: absolute; bottom: -24px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); }
.bar .tot { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#view-recharges > .card + .card { margin-top: 18px; }
#view-recharges .card:has(.bars) { padding-bottom: 40px; }
.table { width: 100%; border-collapse: collapse; font-size: 17px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 14px; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 14px 8px; border-bottom: 1px solid var(--line); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.src { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.src.home { background: #12301f; color: var(--home); }
.src.supercharger { background: #3a1517; color: #ff8d90; }
.src.public, .src.manual { background: #102540; color: #8cc4ff; }

.dialog { border: 1px solid var(--line); border-radius: 22px; background: var(--card); color: var(--text); padding: 26px; width: min(520px, 92vw); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog form { display: grid; gap: 14px; }
.dialog h3 { margin: 0; }
.dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 15px; }
.dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 6px; }

/* ---------- réglages ---------- */
.settings-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); align-items: start; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.checklist li::before { content: ""; flex: none; width: 22px; height: 22px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--line); }
.checklist li.ok::before { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--card); }
.checklist li.todo::before { border-color: var(--warn); }
.checklist small { display: block; color: var(--muted); font-size: 14px; }
.span-2 { grid-column: span 2; }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 22px; margin-top: 8px; }
.field { display: grid; gap: 8px; min-width: 0; }
.field label { font-weight: 600; }
.field-row { display: flex; gap: 10px; }
.field-row input { flex: 1; min-width: 0; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 16px; }
.field-row .btn { flex: none; min-height: 56px; }
.field small { color: var(--muted); font-size: 14px; }
.field small.ok { color: #8fe0b9; }
.field-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.token-once { margin-top: 12px; border-color: var(--accent); }
.sessions { list-style: none; padding: 0; margin: 0; font-size: 15px; }
.sessions li { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 1000; background: var(--card-2); border: 1px solid var(--line); padding: 16px 24px; border-radius: 16px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.5); }

/* ---------- petits écrans (téléphone) ---------- */
@media (max-width: 900px) {
  :root { --rail: 0px; --top: 60px; }
  body.app { grid-template-columns: 1fr; grid-template-rows: var(--top) 1fr 76px; }
  .rail { grid-row: 3; flex-direction: row; justify-content: space-around; padding: 4px; border-right: 0; border-top: 1px solid var(--line); }
  .rail .brand-mark { display: none; }
  .rail-btn { width: auto; min-height: 66px; flex: 1; }
  .topbar { padding: 0 12px; } .clock { font-size: 22px; } #gps-pill, #car-pill { display: none; }
  .topbar-right { gap: 10px; }
  .gate-btn { height: 50px; min-width: 0; padding: 0 16px; font-size: 18px; }
  .span-2 { grid-column: auto; }
  .settings-form { grid-template-columns: minmax(0, 1fr); }
  .view { padding: 16px; }
  .cockpit-grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero, .link-card.wide { grid-column: auto; }
  .hero-top { flex-wrap: wrap; } .charge-state { text-align: left; }
  .soc { font-size: 84px; } .kpi b { font-size: 26px; }
  .toolbar .spacer { display: none; }
  .table { font-size: 15px; } .table th:nth-child(3), .table td:nth-child(3) { display: none; }
  .copilot { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .hazard-panel { max-height: 45vh; border-left: 0; border-top: 1px solid var(--line); }
  .alert-banner { right: 18px; font-size: 18px; }
  .settings-grid { grid-template-columns: 1fr; }
  .table th:nth-child(6), .table td:nth-child(6) { display: none; }
}

/* fond OSM de repli assombri + popups Leaflet en thème sombre */
.osm-dark { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { font-size: 16px; margin: 14px 18px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); width: 32px; height: 32px; font-size: 24px; }

/* ---------- sens de circulation ---------- */
.hz-dir { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hz-dir.rel-same { color: var(--accent); }
.hz-dir.rel-opposite { color: var(--muted); }
.hz-dir.rel-both { color: var(--warn); }
.hz-dir.rel-cross, .hz-dir.rel-unknown { color: #b9c2cc; }
.hazard-list li.is-opposite { opacity: .5; }
.hz-src { font-style: normal; font-size: 12px; font-weight: 700; margin-left: 8px; padding: 2px 7px; border-radius: 999px; background: var(--card-2); color: var(--muted); vertical-align: 2px; }
.alert-banner .banner-text { display: grid; gap: 2px; min-width: 0; }
.alert-banner .hz-dir { font-size: 19px; }
.leaflet-popup-content .hz-dir { white-space: normal; }
/* flèche sur le bord de la pastille, orientée dans le sens de circulation concerné */
.hz-wrap { position: relative; display: block; width: 34px; height: 34px; }
.hz-arrows { position: absolute; inset: -9px; pointer-events: none; }
.hz-arrows::before, .hz-arrows.both::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent;
}
.hz-arrows::before { top: -4px; border-bottom: 9px solid #fff; border-top: 0; }
.hz-arrows.both::after { bottom: -4px; border-top: 9px solid #fff; border-bottom: 0; }
