/* FleetTaggerTraker — interface web.
   Direction artistique : sobre, épurée, professionnelle. Fond blanc, hairlines,
   une seule couleur d'accent (reprise de la charte société), typographie
   soignée, icônes vectorielles au trait. */

:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --subtle: #f7f8fa;
  --hair: #e8ebf0;
  --hair-strong: #d7dce4;
  --ink: #0b1220;
  --text: #263143;
  --muted: #6b7688;
  --faint: #97a0b0;
  --accent: #4f46e5; /* périwinkle Dembedded — surchargé au runtime depuis /api/brand */
  --accent-weak: rgba(79, 70, 229, 0.08);
  --accent-ink: #ffffff;
  --ink-panel: #0b0b12; /* fond sombre de marque (héros de connexion) */
  --green: #0f9d58;
  --amber: #c2610a;
  --red: #d0342c;
  --radius: 12px;
  --radius-sm: 9px;
  --nav-w: 248px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --mono: "Space Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --map-filter: none;
  color-scheme: light;
}

/* ---------- Thème sombre ----------
   Appliqué via l'attribut data-theme sur <html> (réglage dans Paramétrage,
   mémorisé localement). Seules les variables changent : aucune règle de mise
   en page n'est dupliquée. */
:root[data-theme="dark"] {
  --bg: #0b0b12;
  --panel: #14141d;
  --subtle: #1b1b26;
  --hair: #262633;
  --hair-strong: #343444;
  --ink: #f2f4f8;
  --text: #d3d7e0;
  --muted: #9aa2b4;
  --faint: #737c90;
  --accent-ink: #ffffff;
  --ink-panel: #05050a;
  --green: #35c07a;
  --amber: #e2913c;
  --red: #f0655c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.35);
  /* Les tuiles OpenStreetMap sont claires : on les assombrit pour rester lisible. */
  --map-filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.75);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
svg { display: block; }
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 26px; height: 26px; }

/* ---------- Coquille ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--hair);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand .mark { width: 36px; height: 36px; border-radius: 50%; background: var(--ink-panel); color: #fff; display: grid; place-items: center; flex: none; }
.brand .mark svg { width: 22px; height: 22px; stroke: #fff; }
.brand .bt { line-height: 1.1; }
.brand .bt b { font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; display: block; }
.brand .bt span { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.12em; font-family: var(--mono); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 14px; font-weight: 600;
  background: none; border: none; width: 100%; text-align: left; cursor: pointer;
  position: relative; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--subtle); color: var(--text); }
.nav-item.active { background: var(--accent-weak); color: var(--accent); }
.nav-item.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-item .icon { color: inherit; }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--hair); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-weak); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.side-user .su-name { font-size: 13px; font-weight: 650; color: var(--ink); }
.side-user .su-role { font-size: 11px; color: var(--faint); }
.link-btn { background: none; border: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.link-btn:hover { background: var(--subtle); color: var(--red); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--hair); position: sticky; top: 0; z-index: 20; }
.content { padding: 30px 34px; max-width: 1180px; width: 100%; margin: 0 auto; flex: 1; }
.bottomnav { display: none; }

/* ---------- Pied de page ---------- */
.foot { border-top: 1px solid var(--hair); padding: 22px 34px; color: var(--faint); font-size: 12.5px; max-width: 1180px; margin: 20px auto 0; width: 100%; display: flex; flex-wrap: wrap; gap: 6px 20px; align-items: center; justify-content: space-between; }
.foot a { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.foot .fl { display: flex; gap: 18px; flex-wrap: wrap; }
.foot .legal { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-top: 6px; letter-spacing: .01em; }
.foot > div:first-child > div { margin-bottom: 2px; }

/* ---------- Titres ---------- */
.h1 { font-family: var(--serif); font-size: 32px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; margin: 0 0 6px; line-height: 1.1; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; max-width: 70ch; }
.sec { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.14em; margin: 30px 0 14px; }
.sec::before { content: "[ "; opacity: .55; }
.sec::after { content: " ]"; opacity: .55; }

/* ---------- Grilles & cartes ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(272px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--hair); border-radius: var(--radius); padding: 18px; }
.card.click { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
.card.click:hover { border-color: var(--hair-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; color: var(--ink); }
.card.click.cover-card { padding: 0; overflow: hidden; }
.cover-card > :not(.cover) { padding-left: 18px; padding-right: 18px; }
.cover-card > .ttl { padding-top: 14px; }
.cover-card > :last-child { padding-bottom: 16px; }
.cover { height: 150px; background: var(--subtle); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-empty { display: grid; place-items: center; color: var(--faint); }
.cover-empty .icon { width: 40px; height: 40px; }

/* Avatar chauffeur (photo de profil ou initiales) */
.dhead { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.avatar.ph { padding: 0; overflow: hidden; background: none; }
.avatar.ph img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.lg { width: 52px; height: 52px; font-size: 16px; }

/* Galerie photos du véhicule (multi-angles) */
.gallery { margin-bottom: 6px; }
.gmain { border: 1px solid var(--hair); border-radius: var(--radius); overflow: hidden; background: var(--subtle); aspect-ratio: 16 / 9; max-height: 340px; }
.gmain img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gmain-empty { width: 100%; height: 100%; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--faint); }
.gmain-empty .icon { width: 46px; height: 46px; }
.gthumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; margin-top: 10px; }
.gthumb { position: relative; aspect-ratio: 4 / 3; border: 1px solid var(--hair); border-radius: var(--radius-sm); overflow: hidden; background: var(--subtle); padding: 0; cursor: default; }
.gthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gthumb.is-primary { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.glabel { position: absolute; left: 0; bottom: 0; right: 0; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.6)); padding: 10px 8px 5px; font-weight: 600; }
.gbadge { position: absolute; top: 6px; left: 6px; display: inline-flex; align-items: center; gap: 3px; background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; padding: 2px 7px 2px 4px; border-radius: 999px; }
.gbadge .icon { width: 12px; height: 12px; }
.gactions { position: absolute; top: 6px; right: 6px; display: flex; gap: 5px; opacity: 0; transition: opacity .12s; }
.gthumb:hover .gactions { opacity: 1; }
.gbtn { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; border: none; background: rgba(11,11,18,.72); color: #fff; cursor: pointer; }
.gbtn .icon { width: 14px; height: 14px; }
.gbtn.danger:hover { background: var(--red); }
.gadd { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; border-style: dashed; border-color: var(--hair-strong); background: var(--panel); }
.gadd:hover { color: var(--accent); border-color: var(--accent); }
.gadd .icon { width: 22px; height: 22px; }
.card .ttl { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card .plate { color: var(--faint); font-size: 13px; }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); margin-bottom: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--hair); border-radius: var(--radius); padding: 16px 18px; }
.kpi .kl { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi .kl .icon { width: 15px; height: 15px; color: var(--faint); }
.kpi .kv { font-size: 24px; font-weight: 780; color: var(--ink); margin-top: 8px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--hair); font-size: 14px; }
.row:last-child { border-bottom: none; }
.row .v { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--ink); }
.muted { color: var(--muted); }
.pos { color: var(--green); font-weight: 750; }
.neg { color: var(--red); font-weight: 750; }
.meta { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- Badges / statuts ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.badge.green { background: rgba(15,157,88,.1); color: var(--green); }
.badge.amber { background: rgba(194,97,10,.1); color: var(--amber); }
.badge.red { background: rgba(208,52,44,.1); color: var(--red); }
.badge.gray { background: var(--subtle); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 650; font-size: 14px; cursor: pointer; background: var(--accent); color: var(--accent-ink); transition: filter .12s, background .12s; }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: default; }
.btn .icon { width: 17px; height: 17px; }
.btn.ghost { background: var(--panel); border-color: var(--hair-strong); color: var(--text); }
.btn.ghost:hover { background: var(--subtle); filter: none; }
.btn.green { background: var(--green); } .btn.red { background: var(--red); } .btn.amber { background: var(--amber); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 16px; }
code { font-family: var(--mono); font-size: 11.5px; background: var(--subtle); padding: 1px 5px; border-radius: 5px; }

/* ---------- Formulaires ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--hair-strong); background: var(--panel); color: var(--ink); font: inherit; font-size: 15px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.hint { font-size: 12px; color: var(--faint); margin-top: 6px; }

/* Sélecteur segmenté (thème d'interface) */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--subtle); border: 1px solid var(--hair); border-radius: var(--radius-sm); }
.seg-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px; border: none; background: none; border-radius: 7px; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--hair); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--panel); min-width: 560px; }
th, td { padding: 12px 14px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
th { background: var(--subtle); font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .plate { color: var(--faint); font-size: 12px; }

/* ---------- Carte ---------- */
#map { height: 58vh; min-height: 340px; border-radius: var(--radius); border: 1px solid var(--hair); overflow: hidden; }
.leaflet-container { font-family: var(--font); background: var(--subtle); }
.leaflet-tile-pane { filter: var(--map-filter); }
:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip,
:root[data-theme="dark"] .leaflet-control-zoom a,
:root[data-theme="dark"] .leaflet-control-attribution {
  background: var(--panel);
  color: var(--text);
}
:root[data-theme="dark"] .leaflet-control-zoom a { border-color: var(--hair); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--muted); }

/* ---------- Modale ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(11,18,32,.5); backdrop-filter: blur(2px); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--panel); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 22px; max-height: 90vh; overflow-y: auto; }
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }
.modal h3 { margin: 0 0 16px; font-size: 17px; color: var(--ink); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 900px) { .login { grid-template-columns: 1.1fr 1fr; } }
.login-hero { display: none; background: radial-gradient(130% 130% at 8% 0%, #171733 0%, #0e0e1c 45%, var(--ink-panel) 100%); color: #fff; padding: 56px; flex-direction: column; justify-content: space-between; position: relative; }
.login-hero::after { content: ""; position: absolute; inset: 0; background: radial-gradient(60% 50% at 85% 15%, var(--accent-weak), transparent 70%); pointer-events: none; }
@media (min-width: 900px) { .login-hero { display: flex; } }
.login-hero > * { position: relative; z-index: 1; }
.login-hero .mark { width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); display: grid; place-items: center; }
.login-hero .mark svg { width: 28px; height: 28px; stroke: #fff; }
.login-hero h2 { font-family: var(--serif); font-size: 36px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 14px; max-width: 14ch; line-height: 1.08; }
.login-hero p { color: #aeb8cc; font-size: 15px; line-height: 1.6; max-width: 42ch; }
.login-hero .feat { display: flex; gap: 12px; align-items: center; color: #cdd5e5; font-size: 14px; margin-top: 12px; }
.login-hero .feat .icon { color: #8fa0c4; }
.login-hero .cr { color: #6b7791; font-size: 12px; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 28px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { padding: 0 0 22px; }
.login-card h1 { font-family: var(--serif); font-size: 27px; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
.login-card .lead { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.gbtn-wrap { display: flex; justify-content: center; margin-bottom: 18px; min-height: 44px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 12px; margin: 6px 0 18px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--hair); flex: 1; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.ok { color: var(--green); font-size: 13px; margin-bottom: 8px; line-height: 1.5; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.link-inline { background: none; border: none; padding: 0; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.link-inline:hover { text-decoration: underline; }

.toast { position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 14px; max-width: 90%; display: flex; gap: 9px; align-items: center; }
.toast .icon { color: #86efac; }
@media (min-width: 900px) { .toast { bottom: 26px; } }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Bascule mobile ---------- */
@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { display: flex; }
  .content { padding: 18px 16px 92px; }
  .foot { padding: 18px 16px 92px; flex-direction: column; align-items: flex-start; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--panel); border-top: 1px solid var(--hair); padding: 7px 4px calc(7px + env(safe-area-inset-bottom)); }
  .bottomnav .nav-item { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 5px 2px; border-radius: 8px; }
  .bottomnav .nav-item.active { background: none; }
  .bottomnav .nav-item.active::before { display: none; }
  .h1 { font-size: 21px; }
}
