:root {
  --blue: #1f6bff;
  --blue-dark: #0b4fd1;
  --ink: #0f172a;
  --ink-2: #5b6b82;
  --bg: #ffffff;
  --bg-2: #eef2f7;
  --line: #e3e8ef;
  --orange: #ff6a00;
  --red: #e5262a;
  --green: #0f9d58;
  --banner: #0e1a2b;
  --shadow: 0 8px 28px rgba(15, 23, 42, .18), 0 1px 3px rgba(15, 23, 42, .14);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sheet-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2f7;
    --ink-2: #93a3b8;
    --bg: #1b2433;
    --bg-2: #263142;
    --line: #2f3b4e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #dfe5ec; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

.card { background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Pile du haut ---------- */
.top {
  position: fixed; z-index: 10;
  top: calc(10px + var(--safe-top)); left: 10px; right: 10px;
  max-width: 440px;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }

/* Recherche */
.search { padding: 6px; }
.field { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 4px 0 12px; }
.field + .field { border-top: 1px solid var(--line); }
.field input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: transparent; font-size: 16px;
}
.field input::placeholder { color: var(--ink-2); }
.field input::-webkit-search-cancel-button { display: none; }
.pin { width: 12px; height: 12px; flex: none; border-radius: 50%; }
.pin-from { background: var(--blue); box-shadow: 0 0 0 4px rgba(31, 107, 255, .22); }
.pin-to { background: var(--red); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.pin-stop { width: 18px; height: 18px; margin: 0 -3px; display: grid; place-items: center; background: #f59e0b; color: #fff; font-size: 11px; font-weight: 800; }
.stop-name { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #f59e0b; color: #fff; border: 3px solid #fff; font-size: 12px; font-weight: 800; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
.chip-btn span { border-style: dashed; }
.suggest li .s-body { flex: 1; min-width: 0; }
.s-edit { width: 32px; height: 32px; }
.icon-btn { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:hover { background: var(--bg-2); }

.suggest { list-style: none; margin: 4px 0 0; padding: 6px 0 2px; border-top: 1px solid var(--line); max-height: 52vh; overflow: auto; }
.suggest li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.suggest li:hover, .suggest li.active { background: var(--bg-2); }
.suggest .s-ico { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); color: var(--ink-2); }
.suggest .s-ico.me { background: rgba(31, 107, 255, .14); color: var(--blue); }
.suggest .s-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.suggest .s-sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; line-height: 1.25; }
.suggest .s-empty { color: var(--ink-2); cursor: default; font-size: 14px; }
.suggest .s-empty:hover { background: none; }

/* Bandeau de guidage */
.banner {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px 14px 14px; border-radius: 22px;
  background: var(--banner); color: #fff; box-shadow: var(--shadow);
}
.banner-icon { width: 58px; height: 58px; flex: none; color: #fff; }
.banner-icon svg { width: 100%; height: 100%; display: block; }
.banner-main { min-width: 0; }
.banner-dist { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.banner-text { font-size: 17px; font-weight: 500; line-height: 1.25; margin-top: 3px; opacity: .92;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.man-sign { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; font-size: 13px; font-weight: 700; }
.exitno { background: #fff; color: #0e1a2b; padding: 2px 7px; border-radius: 6px; }
.ref { padding: 2px 7px; border-radius: 6px; border: 1.5px solid #fff; }
.ref-a { background: #d7262b; color: #fff; }
.ref-d { background: #f7c600; color: #111; border-color: #111; }
.ref-o { background: #fff; color: #111; }
.toward { background: #1f6bff; color: #fff; padding: 2px 8px; border-radius: 6px; }
.then {
  align-self: flex-start; display: flex; align-items: center; gap: 8px;
  margin-top: -6px; padding: 7px 14px 7px 10px; border-radius: 0 0 14px 14px;
  background: #1c2c45; color: #fff; font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
.then svg { width: 22px; height: 22px; }

/* Carte radar */
.radar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; align-self: flex-start; min-width: 230px;
  transition: background .25s, color .25s;
}
.radar-badge { width: 44px; height: 44px; flex: none; border-radius: 13px; display: grid; place-items: center; background: var(--orange); color: #fff; }
.radar-txt { flex: 1; min-width: 0; }
.radar-dist { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.radar-sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.limit {
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: #111; border: 5px solid var(--red);
  font-weight: 800; font-size: 17px; letter-spacing: -.03em;
}
.radar.near { background: var(--orange); color: #fff; }
.radar.near .radar-sub, .radar.close .radar-sub { color: rgba(255, 255, 255, .9); }
.radar.near .radar-badge, .radar.close .radar-badge { background: rgba(255, 255, 255, .22); }
.radar.close { background: var(--red); color: #fff; animation: pulse 1s ease-in-out infinite; }
.radar.none { opacity: .92; }
.radar.none .radar-badge { background: var(--bg-2); color: var(--ink-2); }
.radar.none .radar-dist { font-size: 15px; font-weight: 600; }
@keyframes pulse { 50% { transform: scale(1.04); box-shadow: 0 0 0 8px rgba(229, 38, 42, .25), var(--shadow); } }

/* ---------- Boutons flottants ---------- */
.fabs {
  position: fixed; z-index: 5; right: 10px;
  bottom: calc(28px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
  transition: bottom .25s;
}
.fab { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.fab:active { transform: scale(.95); }
.mode-preview .fabs { bottom: calc(var(--sheet-h) + 22px); }
.mode-nav .fabs { display: none; }

/* ---------- Carburant ---------- */
.fuel {
  position: fixed; z-index: 11; left: 10px; right: 70px;
  bottom: calc(28px + var(--safe-bottom)); max-width: 420px;
  padding: 8px; max-height: 46vh; overflow: auto;
}
.mode-preview .fuel { bottom: calc(var(--sheet-h) + 12px); }
.mode-nav .fuel { display: none; }
.fuel-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 4px 8px; font-size: 14px; }
.fuel-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 8px; border-radius: 12px; }
.fuel-row:hover { background: var(--bg-2); }
.fuel-price { flex: none; font-weight: 800; font-size: 15px; padding: 4px 8px; border-radius: 8px; background: var(--bg-2); }
.fuel-price.best { background: var(--green); color: #fff; }
.fuel-txt { min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.fuel-txt small { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fuel-mk {
  padding: 3px 7px; border-radius: 8px; border: 2px solid #fff;
  background: #0e1a2b; color: #fff; font-size: 12px; font-weight: 800;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35); cursor: pointer;
}
.fuel-mk.best { background: var(--green); }
.fab-report { background: #f59e0b; color: #fff; }

/* ---------- Signalements ---------- */
.round.round-report { background: #f59e0b; color: #fff; }
.ask {
  position: fixed; z-index: 12; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + var(--safe-bottom));
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px;
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.dlg-pad { padding: 8px 18px 18px; }
.rep-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rep-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 6px; border-radius: 16px; background: var(--bg-2); font-weight: 700; font-size: 13.5px;
}
.rep-grid button span { font-size: 30px; line-height: 1; }
.rep-grid button:active { transform: scale(.96); }

/* ---------- Choix de l'itinéraire ---------- */
.sheet {
  position: fixed; z-index: 9; left: 0; right: 0; bottom: 0;
  border-radius: 24px 24px 0 0;
  padding: 10px 14px calc(14px + var(--safe-bottom));
  max-height: 62vh; display: flex; flex-direction: column; gap: 10px;
}
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-title { flex: 1; min-width: 0; font-size: 15px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.sheet-title b { color: var(--ink); }
.routes { display: flex; flex-direction: column; gap: 8px; overflow: auto; min-height: 0; }
.route {
  text-align: left; width: 100%;
  padding: 12px 14px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--bg);
}
.route.sel { border-color: var(--blue); background: rgba(31, 107, 255, .06); }
.route-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.route-top b { font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.route.sel .route-top b { color: var(--blue); }
.route-top span { color: var(--ink-2); font-size: 15px; }
.route-top em { font-style: normal; font-size: 12px; font-weight: 700; color: var(--green); background: rgba(15, 157, 88, .12); padding: 2px 8px; border-radius: 99px; }
.route-sub { font-size: 14px; color: var(--ink-2); margin-top: 3px; }
.tag { color: #b45309; font-weight: 600; }
.route-cams { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 14px; font-weight: 600; color: var(--orange); }
.route-cams.muted { color: var(--ink-2); font-weight: 500; }

.opts { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { padding: 7px 12px; border-radius: 99px; border: 1.5px solid var(--line); color: var(--ink-2); }
.chip input:checked + span { border-color: var(--blue); background: rgba(31, 107, 255, .1); color: var(--blue); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

.sheet-actions { display: flex; gap: 10px; }
.btn { height: 52px; border-radius: 16px; padding: 0 18px; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { transform: scale(.98); }
.btn-primary { flex: 1; background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(31, 107, 255, .35); }
.btn-ghost { background: var(--bg-2); color: var(--ink); }
.btn-sm { height: 38px; font-size: 14px; border-radius: 12px; padding: 0 14px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Navigation ---------- */
.navbar {
  position: fixed; z-index: 9; left: 10px; right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  display: flex; align-items: center; gap: 14px; padding: 12px;
  border-radius: 22px;
}
.nav-stats { flex: 1; min-width: 0; text-align: center; }
.eta { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.eta b { font-size: 26px; font-weight: 800; color: var(--green); letter-spacing: -.02em; }
.eta span { color: var(--ink-2); font-size: 14px; }
.nav-sub { color: var(--ink-2); font-size: 15px; margin-top: 1px; }
.round { width: 52px; height: 52px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); }
.round-red { background: rgba(229, 38, 42, .12); color: var(--red); }

/* Panneau de limitation au-dessus du compteur */
.speedbox {
  position: fixed; z-index: 8; left: 12px;
  bottom: calc(100px + var(--safe-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.mode-idle .speedbox { bottom: calc(28px + var(--safe-bottom)); }
.road-limit { width: 60px; height: 60px; border-width: 6px; font-size: 22px; box-shadow: var(--shadow); }
.road-limit.over { animation: pulse 1s ease-in-out infinite; }
.speedo {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); box-shadow: var(--shadow); border: 3px solid transparent;
}
.speedo b { font-size: 27px; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.speedo small { font-size: 11px; color: var(--ink-2); font-weight: 600; }
.speedo.over { background: var(--red); color: #fff; border-color: #fff; }
.speedo.over small { color: #fff; }

.recenter {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + var(--safe-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 18px; border-radius: 99px;
  background: var(--bg); color: var(--blue); font-weight: 700; box-shadow: var(--shadow);
}
.sim-ctrl {
  position: fixed; z-index: 8; right: 12px;
  bottom: calc(100px + var(--safe-bottom));
  display: flex; align-items: center; gap: 4px; padding: 5px 5px 5px 12px;
  border-radius: 99px; background: rgba(14, 26, 43, .88); color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.sim-ctrl span { margin-right: 4px; opacity: .85; }
.sim-ctrl button { height: 30px; min-width: 38px; padding: 0 8px; border-radius: 99px; color: #fff; font-weight: 700; }
.sim-ctrl button.on { background: var(--blue); }

/* Position de l'utilisateur */
.me { width: 46px; height: 46px; position: relative; pointer-events: none; }
.me-halo { position: absolute; inset: 7px; border-radius: 50%; background: rgba(31, 107, 255, .2); }
.me-arrow { position: absolute; inset: 5px; width: 36px; height: 36px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); }
.me-arrow path { fill: var(--blue); stroke: #fff; stroke-width: 3; stroke-linejoin: round; }
.me-dot { position: absolute; inset: 14px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); display: none; }
.me.no-heading .me-arrow { display: none; }
.me.no-heading .me-dot { display: block; }
.origin-dot { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 5px solid var(--blue); box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }

/* Popups carte */
.maplibregl-popup-content { border-radius: 16px !important; padding: 12px 14px !important; box-shadow: var(--shadow) !important; background: var(--bg) !important; color: var(--ink); font-family: inherit; }
.maplibregl-popup-tip { border-top-color: var(--bg) !important; border-bottom-color: var(--bg) !important; }
.maplibregl-popup-close-button { font-size: 20px; width: 30px; height: 30px; color: var(--ink-2); }
.pp-title { font-weight: 700; font-size: 15px; max-width: 220px; padding-right: 18px; }
.pp-sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.pp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pp-actions .btn-primary { flex: none; box-shadow: none; }
.pp-limits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-width: 250px; }
.pp-limits .pp-sub { width: 100%; margin: 0 0 2px; }
.lim {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: #111; border: 4px solid var(--red);
  font-weight: 800; font-size: 13px; letter-spacing: -.03em;
}
.lim:active { transform: scale(.94); }

/* ---------- Réglages ---------- */
.dlg {
  width: min(420px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 22px;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow);
}
.dlg::backdrop { background: rgba(15, 23, 42, .4); }
.dlg form { padding: 8px 18px 18px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg h2 { font-size: 20px; margin: 10px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.row small { display: block; font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.row select { border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; padding: 7px 10px; }
.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; flex: none; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(20px); }
.about { font-size: 12.5px; line-height: 1.5; color: var(--ink-2); margin: 14px 0 0; }

/* ---------- Divers ---------- */
.loading {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  top: calc(130px + var(--safe-top));
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: 99px;
  background: var(--bg); box-shadow: var(--shadow); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.mode-preview .loading { top: auto; bottom: calc(var(--sheet-h) + 22px); }
.mode-nav .loading { top: auto; bottom: calc(100px + var(--safe-bottom)); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--blue); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(110px + var(--safe-bottom));
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px;
  background: rgba(14, 26, 43, .94); color: #fff; font-size: 14px; font-weight: 500; text-align: center;
  box-shadow: var(--shadow);
}

.maplibregl-ctrl-bottom-left { bottom: var(--safe-bottom); }
.mode-nav .maplibregl-ctrl-bottom-left, .mode-preview .maplibregl-ctrl-bottom-left { display: none; }

/* ---------- Grand écran ---------- */
@media (min-width: 760px) {
  .top { left: 16px; top: 16px; }
  .sheet {
    left: 16px; right: auto; bottom: 16px; width: 440px;
    border-radius: 22px; max-height: calc(100vh - 200px);
  }
  .mode-preview .fabs { bottom: 28px; }
  .mode-preview .loading { bottom: 28px; left: 472px; transform: none; }
  .navbar { left: 50%; right: auto; transform: translateX(-50%); width: 460px; bottom: 16px; }
}
