:root {
  --bg: #0d0f12; --panel: #15181d; --panel-2: #1b1f25; --border: #252a32; --text: #e9ecf0; --muted: #8b929c;
  --accent: #3e9cff; --accent-2: #2b7fd6; --green: #2fbf71; --orange: #f2994a; --red: #eb5757; --yellow: #f2c94c; --purple: #9b7bff;
  --radius: 14px; --sidebar: 232px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
small, .muted { color: var(--muted); }
code { background: var(--panel-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* Layout */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 20px; letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: rgba(62,156,255,.12); color: var(--text); }
.nav a.active svg { color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.sidebar .foot { margin-top: auto; padding: 10px 12px; border-top: 1px solid var(--border); font-size: 12.5px; }
.sidebar .foot button { margin-top: 8px; }
.main { padding: 28px 32px 60px; min-width: 0; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.back:hover { color: var(--text); }

/* Mobile */
.topbar { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 1000; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 900; font-weight: 700; }
  .main { padding: 18px 16px 50px; }
}

/* Cards, grids */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-hero { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-hero { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g2, .g3 { grid-template-columns: 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 20px; font-weight: 650; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #39404a; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: transparent; border-color: rgba(235,87,87,.5); color: var(--red); }
.btn.danger:hover { background: rgba(235,87,87,.1); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 9px 11px; border-radius: 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(62,156,255,.18); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters > * { flex: 0 1 170px; }
.filters .grow { flex: 1 1 220px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.error-box { background: rgba(235,87,87,.1); border: 1px solid rgba(235,87,87,.35); color: #ffb4b4; padding: 10px 12px; border-radius: 10px; }
.info-box { background: rgba(62,156,255,.08); border: 1px solid rgba(62,156,255,.3); padding: 12px 14px; border-radius: 10px; }
.ok-box { background: rgba(47,191,113,.08); border: 1px solid rgba(47,191,113,.3); padding: 10px 12px; border-radius: 10px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-driving { color: var(--accent); } .st-charging { color: var(--green); } .st-online { color: var(--yellow); }
.st-asleep { color: var(--purple); } .st-offline { color: var(--muted); }
.st-driving i, .st-charging i { animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.pill { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; }
.pill.ac { background: rgba(47,191,113,.15); color: var(--green); }
.pill.dc { background: rgba(242,153,74,.15); color: var(--orange); }
.pill.partial { background: rgba(139,146,156,.15); color: var(--muted); }
.pill.tag { background: rgba(155,123,255,.15); color: var(--purple); }

/* Battery */
.battery { position: relative; height: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.battery-fill { height: 100%; background: linear-gradient(90deg, #26a862, var(--green)); border-radius: 6px; transition: width .4s; }
.battery-fill.mid { background: var(--yellow); } .battery-fill.low { background: var(--red); }
.battery-limit { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .5; }
.mini-bat { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.mini-bat .battery { width: 44px; height: 7px; }

/* Vehicle hero */
.hero { display: flex; flex-direction: column; gap: 16px; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero-name { font-size: 22px; font-weight: 700; }
.hero-model { color: var(--muted); }
.hero-big { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.hero-big .pct { font-size: 46px; font-weight: 700; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-big .range { font-size: 18px; color: var(--muted); }
.live-panel { border-radius: 12px; padding: 14px; background: var(--panel-2); border: 1px solid var(--border); }
.live-panel.charging { border-color: rgba(47,191,113,.4); background: rgba(47,191,113,.06); }
.live-panel.driving { border-color: rgba(62,156,255,.4); background: rgba(62,156,255,.06); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px 16px; }
.kv div span { display: block; color: var(--muted); font-size: 12px; }
.kv div b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Maps */
.map { height: 340px; background: var(--panel-2); }
.map.tall { height: 460px; }
.map.small { height: 220px; }
.map-dot { border-radius: 50%; background: var(--c); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--c), 0 2px 6px rgba(0,0,0,.5); box-sizing: border-box; }
.map-car { filter: drop-shadow(0 2px 4px rgba(0,0,0,.6)); }
.leaflet-container { background: #1a1d22; font: inherit; }
.osm-tiles { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.6); }
.leaflet-control-attribution { background: rgba(13,15,18,.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--border) !important; }
.speed-legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--border); }
.speed-legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* Charts */
.chart { position: relative; height: 260px; }
.chart.short { height: 200px; }

/* Lists */
.day-group { margin-top: 22px; }
.day-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 600; padding: 0 4px 8px; }
.day-head span:first-child::first-letter { text-transform: uppercase; }
.list { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--border); color: var(--text); }
.item:first-child { border-top: 0; }
.item:hover { background: var(--panel-2); }
.item .when { font-variant-numeric: tabular-nums; font-weight: 600; }
.item .when small { display: block; font-weight: 400; }
.route { display: grid; grid-template-columns: 12px minmax(0, 1fr); column-gap: 10px; row-gap: 3px; }
.route .ln { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route .p { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.route .p.a { background: var(--green); } .route .p.b { background: var(--red); }
.item .metrics { display: flex; gap: 22px; text-align: right; }
.item .metrics div b { display: block; font-variant-numeric: tabular-nums; }
.item .metrics div span { color: var(--muted); font-size: 12px; }
@media (max-width: 800px) {
  .item { grid-template-columns: 1fr; gap: 8px; }
  .item .metrics { text-align: left; gap: 16px; flex-wrap: wrap; }
}
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; opacity: .5; margin-bottom: 8px; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; border-top: 0; }
.table-wrap { overflow-x: auto; }

/* Timeline états */
.timeline { display: flex; height: 18px; border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.timeline div { height: 100%; }
.tl-driving { background: var(--accent); } .tl-charging { background: var(--green); } .tl-online { background: var(--yellow); }
.tl-asleep { background: var(--purple); opacity: .55; } .tl-offline { background: #3a3f47; }
.tl-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.tl-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Settings */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps > li { position: relative; padding: 0 0 18px 42px; }
.steps > li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.steps > li.done::before { content: '✓'; background: rgba(47,191,113,.15); border-color: rgba(47,191,113,.5); color: var(--green); }
.steps b { display: block; margin-bottom: 4px; }
.copy { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.copy code { flex: 1; padding: 6px 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 70% -10%, rgba(62,156,255,.14), transparent), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; font-size: 26px; padding-bottom: 6px; }
.login .tagline { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* Misc */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.loading { display: grid; place-items: center; padding: 60px; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--green); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: opacity .4s; max-width: 360px; }
.toast-err { border-left-color: var(--red); }
.toast.out { opacity: 0; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 2000; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: 440px; width: 100%; }
.modal p { margin-top: 0; }
.pager { display: flex; justify-content: center; margin-top: 18px; }
.g-hero > .card.flush { display: flex; flex-direction: column; }
.g-hero > .card.flush > .map { flex: 1; min-height: 340px; }

/* Commandes véhicule */
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }
.btn.ctl { flex-direction: column; padding: 14px 10px; gap: 6px; }
.ctl-ico { font-size: 22px; line-height: 1; }
.btn.loading-btn { position: relative; color: transparent; }
.btn.loading-btn::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2px solid var(--text); border-right-color: transparent; border-radius: 50%; animation: ctlspin .8s linear infinite; }
@keyframes ctlspin { to { transform: rotate(360deg); } }
