:root {
  --rail: #0f1b2d;
  --rail-ink: #a9b6c9;
  --rail-active: #1d3048;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #e2e6ec;
  --ink: #152033;
  --ink-2: #4b5a70;
  --ink-3: #6f7d92;
  --accent: #0b6e79;
  --accent-ink: #ffffff;
  --accent-soft: #e0f1f3;
  --good: #137a3f;
  --good-soft: #e1f4e9;
  --warn: #a35a06;
  --warn-soft: #fbefdc;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --idle: #5d6b7f;
  --idle-soft: #e9ecf1;
  --info: #1d5fbf;
  --info-soft: #e3edfb;
  --shadow: 0 1px 2px rgb(15 27 45 / 8%), 0 4px 16px rgb(15 27 45 / 6%);
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1420;
    --surface: #152030;
    --surface-2: #1b2839;
    --line: #2a384b;
    --ink: #e8edf4;
    --ink-2: #b1bdcd;
    --ink-3: #8c9aad;
    --accent: #2fb2c0;
    --accent-ink: #06222a;
    --accent-soft: #123640;
    --good: #4cc98a;
    --good-soft: #123527;
    --warn: #e9a94f;
    --warn-soft: #3a2a11;
    --bad: #f28b82;
    --bad-soft: #3d1b19;
    --idle: #9aa8ba;
    --idle-soft: #243142;
    --info: #7fb0f5;
    --info-soft: #182c47;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); overflow: hidden; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.3rem; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 650; }
.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
[dir="rtl"] .flip svg { transform: scaleX(-1); }
/* Valeurs et unités gardent leur ordre de lecture dans une page en arabe. */
[dir="rtl"] .tile strong, [dir="rtl"] .fact strong, [dir="rtl"] .stats-grid strong, [dir="rtl"] td.right { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] td.right { text-align: left; }
code { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Connexion */
.login {
  height: 100%; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: linear-gradient(145deg, #0f1b2d 0%, #123246 60%, #0b6e79 130%);
}
.login-card {
  width: min(600px, 100%); background: var(--surface); border-radius: 20px; padding: 48px;
  display: flex; flex-direction: column; gap: 20px; box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.login-card h1 { font-size: 2.1rem; }
.login-card .muted { font-size: 1.1rem; text-align: center; }
.login-card label { font-size: 1rem; gap: 7px; }
.login-card input, .login-card select { min-height: 52px; font-size: 1.05rem; padding: 10px 14px; }
.login-card .btn { min-height: 56px; font-size: 1.1rem; }
@media (max-width: 600px) {
  .login-card { padding: 28px; gap: 16px; }
  .login-card h1 { font-size: 1.7rem; }
}

/* Structure */
.shell { height: 100dvh; display: grid; grid-template-columns: 208px 1fr; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; color: #fff; font-weight: 650; font-size: 1rem; line-height: 1.25; padding: 6px 8px 18px; text-align: center; }
.brand img { border-radius: 8px; }
.nav-item {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 8px; font-size: 0.93rem; position: relative;
}
.nav-item:hover { background: rgb(255 255 255 / 6%); color: #fff; }
.nav-item:focus-visible { outline: 2px solid #5fd0dc; outline-offset: -2px; }
.nav-item.active { background: var(--rail-active); color: #fff; font-weight: 600; }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-more { display: none; }
.tracking-dot { width: 9px; height: 9px; border-radius: 50%; background: #35d07f; margin-inline-start: auto; flex: none; animation: pulse 1.8s infinite; }
.badge-count {
  margin-inline-start: auto; background: #d93a30; color: #fff; font-size: 0.72rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: grid; place-items: center;
}
.content { display: flex; min-width: 0; height: 100dvh; }
.panel { width: 400px; flex: none; background: var(--surface); border-inline-end: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.mapwrap { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; background: var(--bg); direction: ltr; }
.content.full .panel { width: 100%; border: 0; background: var(--bg); }
.content.full .mapwrap { display: none; }
.page { width: 100%; padding: 20px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.side { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h2 { flex: 1; min-width: 160px; }

/* Composants */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px;
  padding: 8px 13px; font: inherit; font-weight: 550; font-size: 0.9rem; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: 7px; min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.danger, .btn.good { color: #10161f; } }
.btn.wide { width: 100%; }
.btn.small-btn { min-height: 30px; padding: 4px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { all: unset; cursor: pointer; padding: 6px; border-radius: 6px; display: inline-grid; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; font-weight: 550; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 450; color: var(--ink); min-height: 28px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; min-width: 0;
}
input[type="checkbox"] { width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); flex: none; }
input[type="range"] { padding: 0; accent-color: var(--accent); border: 0; background: transparent; }
.hint { font-size: 0.78rem; font-weight: 400; color: var(--ink-3); }
.form-error { color: var(--bad); font-size: 0.87rem; }
.form-error:empty { display: none; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span { grid-column: 1 / -1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.content.full .card { box-shadow: var(--shadow); border-color: transparent; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h3 { flex: 1; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 99px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.moving { background: var(--good-soft); color: var(--good); }
.status.stopped { background: var(--info-soft); color: var(--info); }
.status.offline, .status.never { background: var(--idle-soft); color: var(--idle); }
.status.blocked, .status.due { background: var(--bad-soft); color: var(--bad); }
.status.soon { background: var(--warn-soft); color: var(--warn); }
.status.ok { background: var(--good-soft); color: var(--good); }
.status.pending { background: var(--warn-soft); color: var(--warn); }
.status.moving::before { animation: pulse 1.8s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .status.moving::before, .tracking-dot { animation: none; } }

/* Compteurs de la flotte */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kpi {
  all: unset; box-sizing: border-box; cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; text-align: center;
}
.kpi strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 0.72rem; color: var(--ink-3); }
.kpi.active { border-color: var(--accent); background: var(--accent-soft); }
.kpi:focus-visible { outline: 2px solid var(--accent); }

.dev-list { display: flex; flex-direction: column; margin: 0 -8px; }
.dev-row {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; gap: 11px; padding: 10px 8px; border-radius: 8px; align-items: center; width: 100%;
}
.dev-row:hover { background: var(--surface-2); }
.dev-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb { width: 46px; height: 46px; border-radius: 9px; flex: none; object-fit: cover; background: var(--surface-2); color: var(--ink-3); display: grid; place-items: center; border: 1px solid var(--line); }
.thumb svg { width: 28px; height: 28px; }
.dev-name { font-weight: 600; }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* Détail d'un véhicule */
.hero { height: 150px; border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, #123246, #0b6e79); color: #d8eef1; display: grid; place-items: center; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero svg { width: 104px; height: 104px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.fact span { display: block; font-size: 0.76rem; color: var(--ink-3); }
.fact strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.cmd-line { display: flex; gap: 8px; font-size: 0.82rem; padding: 6px 0; border-top: 1px solid var(--line); align-items: center; }
.notice { padding: 10px 12px; border-radius: 8px; font-size: 0.87rem; background: var(--info-soft); color: var(--ink); }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }

/* Marqueurs */
.veh-marker { position: relative; width: 38px; height: 38px; }
.veh-disc { position: absolute; inset: 3px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid #fff; box-shadow: 0 1px 5px rgb(0 0 0 / 45%); }
.veh-disc svg { width: 19px; height: 19px; }
.veh-arrow { position: absolute; inset: 0; }
.veh-arrow::before { content: ""; position: absolute; left: 50%; top: -4px; margin-left: -5px; border: 5px solid transparent; border-bottom: 7px solid #152033; border-top: 0; }
.leaflet-tooltip.veh-label { background: var(--surface); color: var(--ink); border: 0; box-shadow: 0 1px 4px rgb(0 0 0 / 30%); font-weight: 600; padding: 2px 7px; }
.leaflet-tooltip.veh-label::before { display: none; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th { text-align: start; font-size: 0.75rem; font-weight: 650; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: end; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: 0; }

/* Rapports */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.content.full .tile { border-color: transparent; box-shadow: var(--shadow); }
.tile span { font-size: 0.78rem; color: var(--ink-3); display: block; }
.tile strong { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tile small { font-size: 0.8rem; color: var(--ink-3); margin-inline-start: 3px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters label { flex: 1 1 150px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { all: unset; cursor: pointer; font-size: 0.82rem; border: 1px solid var(--line); border-radius: 99px; padding: 4px 11px; color: var(--ink-2); background: var(--surface); }
.chip:hover { background: var(--surface-2); }
.chip:focus-visible { outline: 2px solid var(--accent); }

.bars { display: flex; align-items: flex-end; gap: 2px; height: 150px; border-bottom: 1px solid var(--line); position: relative; }
.bar-slot { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; cursor: default; }
.bar { width: 100%; max-width: 36px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-slot:hover .bar { filter: brightness(1.2); }
.bar-tip {
  display: none; position: absolute; bottom: calc(100% - 22px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface);
  font-size: 0.75rem; padding: 3px 8px; border-radius: 5px; white-space: nowrap; z-index: 2;
}
.bar-slot:hover .bar-tip, .bar-slot:focus .bar-tip { display: block; }
.bar-axis { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--ink-3); margin-top: 5px; }

/* Parcours */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats-grid div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stats-grid span { display: block; font-size: 0.73rem; color: var(--ink-3); }
.stats-grid strong { font-variant-numeric: tabular-nums; }
.stop-marker { width: 24px; height: 24px; border-radius: 50%; background: #c2410c; color: #fff; border: 2px solid #fff; display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; box-shadow: 0 1px 4px rgb(0 0 0 / 40%); }
.end-marker { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 40%); }
.end-marker.start { background: #137a3f; }
.end-marker.finish { background: #b3261e; }
.play-marker { width: 16px; height: 16px; border-radius: 50%; background: #1d5fbf; border: 3px solid #fff; box-shadow: 0 1px 6px rgb(0 0 0 / 50%); }

/* Alertes */
.ev { display: flex; gap: 11px; padding: 11px 4px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.ev:last-child { border-bottom: 0; }
.ev-icon { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--idle-soft); color: var(--idle); }
.ev-icon svg { width: 17px; height: 17px; }
.ev-icon.bad { background: var(--bad-soft); color: var(--bad); }
.ev-icon.warn { background: var(--warn-soft); color: var(--warn); }
.ev-icon.good { background: var(--good-soft); color: var(--good); }
.ev-icon.info { background: var(--info-soft); color: var(--info); }
.ev.unread { background: linear-gradient(90deg, var(--accent-soft), transparent 60%); }

.toasts { position: fixed; top: 14px; inset-inline-end: 14px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 28px)); }
.toast { background: var(--surface); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgb(0 0 0 / 25%); font-size: 0.9rem; }
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--good); }

.dlg { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 24px 70px rgb(0 0 0 / 40%); }
.dlg::backdrop { background: rgb(10 18 30 / 55%); }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.type-picker { border: 0; padding: 0; margin: 0; }
.type-picker legend { padding: 0; margin-bottom: 7px; font-size: .85rem; font-weight: 550; color: var(--ink-2); }
.type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.type-choice { cursor: pointer; }
.type-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.type-choice span { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px; border: 1.5px solid var(--line); border-radius: 10px; font-size: .78rem; text-align: center; color: var(--ink-2); }
.type-choice svg { width: 34px; height: 34px; }
.type-choice span:hover { background: var(--surface-2); }
.type-choice input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 650; }
.type-choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
details summary { cursor: pointer; font-size: 0.87rem; font-weight: 600; color: var(--ink-2); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; overflow-wrap: anywhere; }

.more-list { display: flex; flex-direction: column; gap: 4px; }
.more-list button { all: unset; cursor: pointer; display: flex; gap: 12px; padding: 13px 8px; border-radius: 8px; align-items: center; }
.more-list button:hover { background: var(--surface-2); }
.more-list svg { width: 20px; height: 20px; }

/* Téléphone */
@media (max-width: 820px) {
  .shell { display: flex; flex-direction: column-reverse; }
  .rail { flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow: visible; flex: none; }
  .brand, .nav-item.secondary { display: none; }
  .nav-item { flex: 1; flex-direction: column; gap: 3px; font-size: 0.68rem; padding: 6px 2px; text-align: center; justify-content: center; }
  .nav-more { display: flex; }
  .badge-count { position: absolute; top: 2px; left: 54%; margin: 0; }
  .tracking-dot { position: absolute; top: 5px; left: 58%; margin: 0; }
  .content { flex: 1; min-height: 0; height: auto; flex-direction: column-reverse; }
  .panel { width: 100%; flex: 1; min-height: 0; border: 0; }
  .mapwrap { flex: 0 0 44dvh; }
  .page { padding: 16px 16px 28px; }
  .toasts { top: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
}

@media print {
  body { overflow: visible; background: #fff; }
  .rail, .no-print, .toasts, .mapwrap { display: none !important; }
  .shell, .content, .panel { display: block; height: auto; overflow: visible; }
  .content.full .card, .content.full .tile { box-shadow: none; border: 1px solid #ccc; }
  .page { max-width: none; padding: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* Bulles d'aide */
.help { flex: none; display: inline-grid; place-items: center; width: 18px; height: 18px; border: 1.5px solid currentColor; border-radius: 50%; font-size: 0.68rem; font-weight: 700; line-height: 1; color: var(--ink-3); background: var(--surface); cursor: help; user-select: none; }
.help:hover, .help:focus-visible { color: var(--accent); }
.help:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.help-line { display: inline-flex; align-items: center; gap: 6px; }
.help-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.help-row > input, .help-row > select, .help-row > .btn { flex: 1; min-width: 0; }
.help-row > select[style*="width:auto"], .help-row > .btn.small-btn { flex: 0 1 auto; }
.nav-item, .kpi, .dev-row { position: relative; }
.help.corner { position: absolute; top: 4px; inset-inline-end: 4px; width: 15px; height: 15px; font-size: 0.6rem; color: inherit; background: transparent; opacity: 0.75; }
.help.corner:hover, .help.corner:focus-visible { opacity: 1; color: inherit; }
.help-tip { position: fixed; z-index: 5000; width: max-content; max-width: min(280px, calc(100vw - 16px)); padding: 8px 11px; border-radius: 8px; background: #0b1524; color: #fff; font-size: 0.82rem; font-weight: 450; line-height: 1.4; text-align: start; box-shadow: 0 8px 24px rgb(0 0 0 / 35%); pointer-events: none; }
@media print { .help, .help-tip { display: none !important; } }
