:root {
  --navy: #0b1f3a;
  --navy2: #13305a;
  --orange: #ff7a00;
  --green: #12a150;
  --red: #d93025;
  --blue: #1a73e8;
  --grey: #8a94a6;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #17202e;
  --muted: #5d6778;
  --line: #e2e6ee;
  --input: #ffffff;
  --shadow: 0 2px 10px rgba(11, 31, 58, .08);
  --radius: 12px;
  --top: 56px;
  --bottom: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1422; --card: #142033; --text: #e8edf5; --muted: #9aa6ba; --line: #24344d; --input: #0f1a2b;
    --shadow: 0 2px 10px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1422; --card: #142033; --text: #e8edf5; --muted: #9aa6ba; --line: #24344d; --input: #0f1a2b;
  --shadow: 0 2px 10px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }

/* ---------- splash / login ---------- */
.splash, .login {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, var(--navy2), var(--navy)); color: #fff; padding: 16px;
}
.logo-big { font-size: 2.4rem; font-weight: 800; letter-spacing: .08em; }
.logo-big span, .brand b span { color: var(--orange); }
.login form {
  width: 100%; max-width: 380px; background: var(--card); color: var(--text); border-radius: 16px; padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3); margin-top: 18px;
}
.login .slogan { opacity: .85; margin: 6px 0 0; text-align: center; }
.login .foot { margin-top: 18px; font-size: .85rem; opacity: .75; text-align: center; }

/* ---------- formulaires ---------- */
label { display: block; font-weight: 600; font-size: .85rem; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--input);
  min-height: 42px;
}
input[type=checkbox] { width: auto; min-height: 0; margin-right: 8px; }
.check { display: flex; align-items: center; font-weight: 500; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange); border-color: transparent; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px;
  padding: 10px 14px; min-height: 42px; cursor: pointer; font-weight: 600; background: var(--line); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--orange); color: #fff; }
.btn.navy { background: var(--navy); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn.block { width: 100%; margin-top: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btns .btn { flex: 1 1 auto; }
.error { color: var(--red); font-size: .9rem; margin-top: 10px; min-height: 1em; }

/* ---------- structure ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top); background: var(--navy); color: #fff; z-index: 1000;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
}
.brand { display: flex; flex-direction: column; line-height: 1.05; text-decoration: none; color: #fff; }
.brand b { font-size: 1.25rem; letter-spacing: .06em; }
.brand small { font-size: .68rem; opacity: .75; }
.nav { display: flex; gap: 2px; margin-left: 12px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  color: #cfd8e8; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: .9rem; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.nav a .ico { font-size: 1.05rem; }
.top-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.icon-btn {
  position: relative; background: rgba(255,255,255,.1); border: 0; color: #fff; border-radius: 10px; min-width: 40px; height: 40px;
  cursor: pointer; font-size: 1.05rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; gap: 4px;
}
.icon-btn.on { background: var(--green); }
.icon-btn .badge {
  position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border-radius: 10px; font-size: .7rem; padding: 1px 5px; font-weight: 700;
}
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--grey); display: inline-block; }
.conn.ok { background: var(--green); }

.layout { position: fixed; top: var(--top); bottom: var(--bottom); left: 0; right: 0; display: flex; }
.side { width: 390px; max-width: 100%; overflow-y: auto; overflow-x: hidden; background: var(--bg); border-right: 1px solid var(--line); padding: 12px; }
.mapwrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; background: #dfe5ec; }
.layout.full .mapwrap { display: none; }
.layout.full .side { width: 100%; border: 0; }
.layout.full .side > .page { max-width: 1100px; margin: 0 auto; }
.eco-banner { background: #fff4e5; color: #8a4b00; border-radius: 10px; padding: 8px 10px; font-size: .85rem; margin-bottom: 10px; }
.map-tools { position: absolute; z-index: 500; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.map-tools button { background: var(--card); color: var(--text); border: 0; box-shadow: var(--shadow); border-radius: 10px; width: 42px; height: 42px; cursor: pointer; font-size: 1.1rem; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h2:last-child { margin-bottom: 0; }

/* ---------- liste de véhicules ---------- */
.search { margin-bottom: 10px; }
.vlist { display: flex; flex-direction: column; gap: 8px; }
.veh {
  display: flex; gap: 10px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow); cursor: pointer; border: 2px solid transparent; text-align: left; width: 100%;
}
.veh.sel { border-color: var(--orange); }
.veh .emo { font-size: 1.5rem; width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--bg); flex: none; }
.veh .info { flex: 1; min-width: 0; }
.veh .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.veh .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.veh .spd { text-align: right; font-weight: 700; font-size: .95rem; }
.veh .spd small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 700; color: #fff; background: var(--grey); vertical-align: middle; }
.st-moving { background: var(--green) !important; }
.st-idle { background: var(--orange) !important; }
.st-stopped { background: var(--blue) !important; }
.st-offline, .st-nodata { background: var(--grey) !important; }
.st-expired { background: var(--red) !important; }
.src { display: inline-block; font-size: .7rem; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.src.lbs { border-color: var(--orange); color: var(--orange); }
.src.sms { border-color: var(--blue); color: var(--blue); }
.summary-bar { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.summary-bar .pill { font-size: .75rem; padding: 4px 10px; }

/* ---------- détail véhicule ---------- */
.detail .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.detail .head .emo { font-size: 2rem; }
.detail .head h2 { margin: 0; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.kv div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.kv b { display: block; font-size: 1.05rem; }
.kv span { font-size: .75rem; color: var(--muted); }
.addr { font-size: .9rem; margin: 6px 0; }
.back { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 4px 0; margin-bottom: 6px; font-weight: 600; }
.cmdlog { font-size: .82rem; margin-top: 8px; }
.cmdlog div { padding: 6px 0; border-top: 1px solid var(--line); }

/* ---------- marqueurs ---------- */
.mk { position: relative; width: 40px; height: 40px; }
.mk .dot {
  position: absolute; inset: 4px; border-radius: 50%; background: var(--grey); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.mk .arw {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin-left: -7px; margin-top: -29px;
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 11px solid var(--navy);
  transform-origin: 7px 29px;
}
.mk .lbl {
  position: absolute; top: 40px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; font-size: 11px;
  padding: 1px 6px; border-radius: 6px; white-space: nowrap; font-weight: 600;
}
.mk.sel .dot { border-color: var(--orange); }
.leaflet-container { font: inherit; }

/* ---------- historique ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stats div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.stats b { display: block; font-size: 1.1rem; }
.stats span { font-size: .75rem; color: var(--muted); }
.player { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.player input[type=range] { flex: 1; padding: 0; min-height: 0; }
.player .now { font-size: .85rem; min-width: 120px; text-align: right; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- alertes ---------- */
.ev { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:last-child { border-bottom: 0; }
.ev .t { font-size: .78rem; color: var(--muted); }
.ev.unread .m { font-weight: 700; }

/* ---------- tableaux ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
tr:hover td { background: rgba(127,127,127,.05); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input { max-width: 280px; }
.toolbar .grow { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 1.5rem; }
.kpi span { color: var(--muted); font-size: .82rem; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; border-radius: 20px; background: var(--card); text-decoration: none; color: var(--text); box-shadow: var(--shadow); font-size: .9rem; }
.tabs a.on { background: var(--navy); color: #fff; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: .85em; }

/* ---------- abonnement ---------- */
.sub { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-top: 10px; }
.plan { border: 2px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; background: var(--card); text-align: left; }
.plan.sel { border-color: var(--orange); }
.plan b { display: block; font-size: 1.1rem; }

/* ---------- modale ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 12, 25, .55); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 20px; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .x { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; margin-top: 12px; color: var(--blue); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 18px); transform: translateX(-50%) translateY(150%);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 3000; transition: transform .25s;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
#toast:not(.show) { visibility: hidden; transition: transform .25s, visibility 0s .25s; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  :root { --bottom: 62px; }
  .brand small { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom); margin: 0; background: var(--navy); z-index: 1000;
    justify-content: space-around; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 1px; font-size: .68rem; padding: 4px 6px; }
  .nav a .ico { font-size: 1.25rem; }
  .layout { flex-direction: column; }
  .mapwrap { flex: none; height: 48vh; order: 0; }
  .side { width: 100%; flex: 1; border: 0; order: 1; }
  .layout.mapfirst .mapwrap { height: 55vh; }
}

/* ---------- menu « Plus » (mobile) ---------- */
.nav a.m-only { display: none; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.menu-item { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; border-radius: 12px; background: var(--bg); color: var(--text); text-decoration: none; font-weight: 600; }
.menu-item span { font-size: 1.6rem; }

/* ---------- graphiques, rapports, entretien ---------- */
.chart { margin-top: 12px; }
.chart-head, .chart-foot { display: flex; justify-content: space-between; font-size: .85rem; }
.chart svg { width: 100%; height: 110px; display: block; background: var(--bg); border-radius: 8px; }
.chart-line { fill: none; stroke: var(--orange); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--orange); opacity: .12; stroke: none; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; max-height: 180px; overflow-y: auto; padding: 4px 0; }
.checks .check { margin: 0; }
.maint { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.maint.due { background: linear-gradient(90deg, rgba(217,48,37,.08), transparent); }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; max-width: 320px; }
.bar span { display: block; height: 100%; background: var(--green); }
.maint.due .bar span { background: var(--red); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 6px; }
.seg button { border: 0; background: transparent; color: var(--text); padding: 8px 12px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--navy); color: #fff; }
.notif-ch { padding: 8px 0 12px; }
table.notif td:not(:first-child), table.notif th:not(:first-child) { text-align: center; }
table.notif input { width: 18px; height: 18px; }

/* ---------- suivi partagé ---------- */
.share-info { margin-left: auto; text-align: right; font-size: .9rem; line-height: 1.3; }
.share-info a { color: #ffb366; }
.share-map { position: fixed; top: var(--top); bottom: 0; left: 0; right: 0; background: #dfe5ec; }

@media (max-width: 820px) {
  .nav a.m-hide { display: none; }
  .nav a.m-only { display: flex; }
  .share-info { font-size: .8rem; }
}

/* ---------- note de conduite ---------- */
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 26px; padding: 0 6px; border-radius: 13px; font-weight: 800; color: #fff; background: var(--grey); }
.score.big { min-width: 64px; height: 64px; border-radius: 50%; font-size: 1.6rem; flex: none; }
.score.good { background: var(--green); } .score.ok { background: #7cb342; } .score.warn { background: var(--orange); } .score.bad { background: var(--red); }
.score-row { display: flex; gap: 14px; align-items: center; }
.up { color: var(--green); } .down { color: var(--red); }

.apk-link { max-width: 380px; margin: 14px auto 0; background: rgba(255,255,255,.1); color: #fff; }
