:root {
  --navy: #0A1628;
  --navy-2: #0F1F36;
  --navy-3: #16294A;
  --orange: #F59E0B;
  --orange-2: #FBBF24;
  --ink: #1E293B;
  --muted: #64748B;
  --line: #E2E8F0;
  --bg: #F1F5F9;
  --white: #FFFFFF;
  --green: #22C55E;
  --red: #EF4444;
  --gray: #94A3B8;
  --blue: #3B82F6;
  --shadow: 0 4px 24px rgba(10, 22, 40, 0.10);
  --shadow-lg: 0 12px 40px rgba(10, 22, 40, 0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
input, select, button { font-family: 'Inter', sans-serif; }

/* ============ LOGIN ============ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 700px at 20% -10%, #16294A 0%, #0A1628 55%, #060D18 100%);
  overflow: hidden;
}
.login-bg-glow {
  position: absolute; width: 700px; height: 700px;
  background: radial-gradient(circle, rgba(245,158,11,0.16), transparent 60%);
  top: -200px; right: -150px; border-radius: 50%;
  pointer-events: none;
}
.login-card {
  position: relative;
  width: 400px; max-width: 92vw;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 20px;
  padding: 40px 36px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.brand-logo { display: flex; align-items: center; }
.brand-name { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }
.brand-name span { color: var(--orange); }
.login-subtitle { color: #94A3B8; font-size: 14px; margin-bottom: 28px; }

.field { display: block; margin-bottom: 18px; }
.field span { display: block; color: #CBD5E1; font-size: 12.5px; font-weight: 600; margin-bottom: 7px; text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select {
  width: 100%; padding: 13px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 11px;
  color: #fff; font-size: 15px;
  outline: none; transition: border-color .15s, background .15s;
}
.field input:focus, .field select:focus { border-color: var(--orange); background: rgba(255,255,255,0.09); }
.field input::placeholder { color: #475569; }
.field select option { color: var(--ink); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #94A3B8; font-size: 18px; cursor: pointer; padding: 8px;
}
.login-error { color: #F87171; font-size: 13px; min-height: 20px; margin-bottom: 8px; }

.btn-primary {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  border: none; border-radius: 11px;
  color: #0A1628; font-size: 15.5px; font-weight: 700;
  cursor: pointer; transition: transform .1s, box-shadow .15s;
}
.btn-primary.sm { width: auto; padding: 10px 16px; font-size: 13.5px; }
.btn-primary:hover { box-shadow: 0 6px 20px rgba(245,158,11,0.35); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .6; cursor: default; transform: none; }

.btn-ghost {
  background: rgba(255,255,255,0.08); border: none; color: #fff;
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 16px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.16); }
.btn-ghost.muted { opacity: 0.55; filter: grayscale(1); }
#logout-btn { display: inline-flex; align-items: center; justify-content: center; }
#logout-btn:hover svg { color: var(--orange-2); }

.btn-outline {
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: #FEE2E2; color: #B91C1C; border-color: #FECACA; }
.btn-danger:hover { background: #FECACA; }

/* ============ APP LAYOUT ============ */
.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 58px; flex: none;
  background: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; color: #fff;
  z-index: 1000;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand .brand-name { font-size: 20px; }
.brand-logo.sm { display: flex; }

.topbar-stats { display: flex; gap: 16px; }
.stat-pill { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #CBD5E1; }
.stat-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.stat-dot.online { background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,.7); }
.stat-dot.stopped { background: var(--orange); }
.stat-dot.offline { background: var(--red); }

.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13.5px; color: #CBD5E1; font-weight: 600; }

.main { flex: 1; display: flex; min-height: 0; }

/* ============ NAV RAIL ============ */
.nav-rail {
  width: 82px; flex: none;
  background: var(--navy);
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0; gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.nav-rail::-webkit-scrollbar { width: 5px; }
.nav-rail::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
.nav-item {
  width: 66px; padding: 10px 4px; border: none; border-radius: 11px;
  background: none; color: #94A3B8; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600;
  transition: background .12s, color .12s;
}
.nav-item .nav-ico { font-size: 20px; line-height: 1; }
.nav-ico svg { width: 1em; height: 1em; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--orange); color: #0A1628; }
.nav-divider { width: 40px; height: 1px; background: rgba(255,255,255,0.12); margin: 8px 0; }

/* ============ VIEWS ============ */
.view { flex: 1; min-width: 0; min-height: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

/* Suivi layout */
.suivi-layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 320px; flex: none;
  background: var(--white);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.search-wrap { flex: 1; }
.search-wrap input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 13.5px; outline: none; background: var(--bg);
}
.search-wrap input:focus { border-color: var(--orange); background: #fff; }
.icon-btn {
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  width: 38px; height: 38px; cursor: pointer; font-size: 16px; color: var(--ink);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { background: #E2E8F0; }

.vehicle-list { flex: 1; overflow-y: auto; padding: 6px; }
.vehicle-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 10px; border-radius: 11px; cursor: pointer;
  transition: background .12s;
}
.vehicle-item:hover { background: var(--bg); }
.vehicle-item.st-moving { background: #E8F9EE; }
.vehicle-item.st-stopped, .vehicle-item.st-idle { background: #FDECEC; }
.vehicle-item.st-offline, .vehicle-item.st-unknown { background: #F1F5F9; }
.vehicle-item.active { background: #FEF3C7; }
.vehicle-icon {
  width: 30px; height: 30px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.vehicle-icon img { width: 26px; height: 26px; display: block; }
.vehicle-info { flex: 1; min-width: 0; }
.vehicle-name { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vehicle-meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; margin-top: 2px; }
.vehicle-status { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.map-wrap { flex: 1; position: relative; min-width: 0; direction: ltr; }
#map { position: absolute; inset: 0; z-index: 0; direction: ltr; }
#hist-map { position: absolute; inset: 0; z-index: 0; border-radius: 12px; direction: ltr; }

.map-controls {
  position: absolute; top: 14px; right: 14px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px;
}
.map-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: #fff; border: 1px solid var(--line);
  box-shadow: var(--shadow); cursor: pointer; font-size: 18px;
  color: var(--ink);
}
.map-btn:hover { background: var(--bg); }
.map-btn.active { background: var(--orange); color: #0A1628; border-color: var(--orange); }

.follow-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff;
  padding: 9px 16px; border-radius: 20px; font-size: 13.5px; font-weight: 600;
  display: flex; align-items: center; gap: 12px; z-index: 600;
  box-shadow: var(--shadow-lg);
}
.follow-close { background: none; border: none; color: var(--orange); cursor: pointer; font-size: 14px; }

.detail-drawer {
  position: absolute; left: 14px; bottom: 14px; z-index: 550;
  width: 300px; max-width: 84vw;
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.detail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--navy); color: #fff;
}
.detail-title { font-weight: 700; font-size: 14px; }
.detail-head .icon-btn { background: rgba(255,255,255,0.1); border: none; color: #fff; }
.detail-body { padding: 14px; font-size: 13px; }
.detail-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--muted); }
.detail-row .v { font-weight: 600; color: var(--ink); }
.detail-sub {
  margin: 10px 0 4px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--orange);
}
.detail-actions { display: flex; gap: 8px; margin-top: 12px; }
.detail-actions button {
  flex: 1; padding: 9px; border-radius: 9px; border: none; cursor: pointer;
  font-weight: 600; font-size: 13px;
}
.btn-history { background: var(--navy-3); color: #fff; }
.btn-center { background: var(--orange); color: #0A1628; }
.btn-follow { background: #22C55E; color: #052e16; }
.btn-rename { background: var(--navy-3); color: #fff; }

/* ============ PANEL VIEWS (historique, rapports, etc.) ============ */
.panel-view { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 22px; overflow-y: auto; }
.panel-head { margin-bottom: 18px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; }
.panel-head h2 { font-size: 20px; font-weight: 800; color: var(--ink); }
.panel-head p { font-size: 13px; color: var(--muted); width: 100%; margin-top: -8px; }
.panel-head .btn-primary { margin-left: auto; }

.input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13.5px; outline: none; background: #fff; color: var(--ink);
  min-width: 140px;
}
.input:focus { border-color: var(--orange); }

.hist-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.hist-map-wrap { position: relative; flex: 1; min-height: 320px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.hist-summary { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 12px; }

/* Replay bar */
.replay-bar {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px; padding: 12px 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
}
.replay-btn {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: var(--navy); color: #fff; border: none; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.replay-btn:hover { background: var(--navy-3); }
.replay-speed { display: flex; gap: 5px; }
.speed-btn {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.speed-btn:hover { background: var(--bg); }
.speed-btn.active { background: var(--orange); color: #0A1628; border-color: var(--orange); }
.replay-slider { flex: 1; min-width: 120px; accent-color: var(--orange); }
.replay-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Speed chart */
.hist-chart-wrap {
  position: relative; height: 200px; margin-top: 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px;
}

.summary-card {
  background: #fff; border: 1px solid var(--line); border-radius: 11px;
  padding: 14px 18px; min-width: 130px;
}
.summary-card .sc-v { font-size: 20px; font-weight: 800; color: var(--ink); }
.summary-card .sc-k { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============ DASHBOARD ============ */
.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 14px 0 20px;
}
.dash-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 6px;
}
.dash-card .dc-v { font-size: 26px; font-weight: 800; color: var(--ink); line-height: 1; }
.dash-card .dc-k { font-size: 12px; color: var(--muted); }
.dash-card.green { border-top: 3px solid #22C55E; }
.dash-card.red { border-top: 3px solid #EF4444; }
.dash-vehicles { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
.dash-vname { font-weight: 600; color: var(--ink); }
.dash-badge {
  display: inline-block; color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.dash-dist-cell { display: block; min-width: 130px; }
.dash-dist-val { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.dash-dist-bar { height: 6px; background: #E2E8F0; border-radius: 999px; overflow: hidden; }
.dash-dist-fill { height: 100%; background: var(--orange); border-radius: 999px; }
.dash-row { cursor: pointer; }
.dash-row:hover td { background: #FAFBFC; }
/* Détail véhicule (modal) */
.vd-loading { padding: 20px; text-align: center; color: var(--muted); }
.vd-total { font-size: 24px; font-weight: 800; color: var(--ink); margin-bottom: 4px; }
.vd-total span { font-size: 13px; font-weight: 500; color: var(--muted); }
.vd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.vd-item { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.vd-item .vd-v { font-size: 15px; font-weight: 700; color: var(--ink); }
.vd-item .vd-k { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ============ TABLES ============ */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; padding: 12px 14px; background: var(--bg);
  color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.4px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #FAFBFC; }
.row-actions { display: flex; gap: 6px; }
.row-actions button {
  padding: 5px 9px; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px;
}
.row-actions button:hover { background: var(--bg); }
.row-actions button.del { border-color: #FECACA; background: #FEE2E2; }

/* ============ ZONES / ALERTES ============ */
.zone-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.zone-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
  transition: box-shadow .16s ease, transform .16s ease;
}
.zone-card:hover { box-shadow: 0 12px 28px rgba(10,22,40,0.09); transform: translateY(-2px); }
/* legacy (modèles) */
.zone-card .zc-top { display: flex; align-items: center; gap: 10px; }
.zone-color { width: 16px; height: 16px; border-radius: 4px; flex: none; }
.zone-name { font-weight: 700; font-size: 14.5px; flex: 1; }
.zone-desc { font-size: 12.5px; color: var(--muted); }
.zone-meta { font-size: 12px; color: var(--muted); }
.zone-actions { display: flex; gap: 8px; margin-top: 4px; }
/* premium (zones + alertes) */
.zc-head { display: flex; align-items: center; gap: 12px; }
.zc-icon { width: 46px; height: 46px; border-radius: 13px; flex: none; display: flex; align-items: center; justify-content: center; border: 1.5px solid; }
.zc-ident { flex: 1; min-width: 0; }
.zc-name { font-weight: 700; font-size: 15.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zc-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.zc-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }
.zc-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 30px; padding: 4px 10px; }
.type-badge { display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 30px; }
.zc-actions { display: flex; gap: 8px; margin-top: auto; }
.zc-actions button { flex: 1; }

.notif-chans { display: flex; gap: 16px; }
.notif-chans .chan {
  display: flex; align-items: center; gap: 6px;
  font-size: 13.5px; color: var(--ink); cursor: pointer; font-weight: 500;
}
.notif-chans .chan input { accent-color: var(--orange); width: 16px; height: 16px; cursor: pointer; }

.tpl-vars { display: flex; flex-wrap: wrap; gap: 6px; }
.tpl-vars code {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 7px; font-size: 11.5px; color: var(--navy-3); cursor: default;
}

/* ============ SETTINGS ============ */
.settings-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 1160px; align-items: start; }
.settings-body .full { grid-column: 1 / -1; }
#advanced-config { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.setting-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.setting-card h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: none; }
.setting-row .sk { font-size: 13.5px; color: var(--ink); }
.setting-row .sv { font-size: 13px; color: var(--muted); }

.setting-input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; outline: none; color: var(--ink); background: #fff;
  width: 200px; text-align: left;
}
.setting-input:focus { border-color: var(--orange); }
.setting-input[type="number"] { width: 100px; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #CBD5E1; border-radius: 24px; transition: .2s;
}
.switch .slider:before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--orange); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(10,22,40,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: #fff; border-radius: 14px; width: 460px; max-width: 94vw;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-title { font-weight: 800; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-group input, .form-group select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; outline: none; color: var(--ink);
}
.form-group input:focus, .form-group select:focus { border-color: var(--orange); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 3000;
  background: var(--navy); color: #fff; padding: 13px 18px; border-radius: 11px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
}
.toast.error { background: #B91C1C; }
.toast.success { background: #15803D; }
.toast.event { background: #F59E0B; color: #0A1628; }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============ PANNEAU D'ALERTES WEB (bas-droite carte) ============ */
.web-alert-panel {
  position: fixed; bottom: 20px; right: 20px; z-index: 2500;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 340px; width: max-content;
  opacity: 0; transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}
.web-alert-panel.show { opacity: 1; transform: none; pointer-events: auto; }
.web-alert-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--navy); color: #fff;
  border-left: 4px solid var(--orange);
  border-radius: 10px; padding: 11px 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
}
.web-alert-item .wa-ico { font-size: 18px; }
.web-alert-item .wa-body { flex: 1; min-width: 0; }
.web-alert-item .wa-title { font-weight: 700; font-size: 13.5px; }
.web-alert-item .wa-count { opacity: .8; font-weight: 600; margin-left: 2px; }
.web-alert-item .wa-type { opacity: .75; font-size: 11.5px; margin-top: 1px; }
.web-alert-item .wa-lines { margin-top: 3px; }
.web-alert-item .wa-line {
  opacity: 0; transform: translateY(3px);
  transition: opacity .25s ease, transform .25s ease;
  font-size: 12px; line-height: 1.5;
}
.web-alert-item .wa-line.show { opacity: .92; transform: none; }
.web-alert-item .wa-close {
  background: rgba(255,255,255,.12); border: none; color: #fff;
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
  font-size: 12px; line-height: 1; flex-shrink: 0; padding: 0;
}
.web-alert-item .wa-close:hover { background: rgba(255,255,255,.25); }

/* Leaflet overrides */
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 12px 14px; font-family: 'Inter', sans-serif; }

/* Vehicle marker (arrow + label) */
.v-marker { width: 28px; height: 28px; position: relative; pointer-events: none; }
.v-marker .v-car {
  width: 28px; height: 28px; display: block;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.45));
  pointer-events: auto;
}
.v-marker-wrap { overflow: visible !important; }
.v-arrow {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}
.v-label-tip {
  background: #fff !important;
  border: 1px solid #E2E8F0 !important;
  border-radius: 5px !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15) !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  color: #1E293B !important;
  padding: 2px 7px !important;
  font-family: 'Inter', sans-serif !important;
}
.v-label-tip::before { display: none !important; }

/* Cluster (véhicules regroupés) */
.cluster-marker { background: transparent; }
.cluster-icon {
  background: #0A1628;
  border: 2px solid #F59E0B;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

/* Barre de stats mobile (fixée en bas) */
.mobile-stats-bar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  height: 56px; background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(10,22,40,0.07);
  align-items: center; justify-content: space-around;
  padding: 6px 12px; padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.msb-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink); white-space: nowrap; }
.msb-item .stat-dot { width: 9px; height: 9px; }
.msb-val { font-weight: 800; font-size: 15px; color: var(--navy); font-variant-numeric: tabular-nums; }
.msb-lbl { color: var(--muted); font-size: 11px; }
.msb-total .msb-val { color: var(--ink); }

/* Éléments mobile-only (masqués sur desktop) */
.menu-toggle, .base-layer-select, .mobile-only { display: none; }

/* ============ RESPONSIVE (mobile) ============ */
@media (max-width: 768px) {
  /* Topbar bleu (comme l'ancien serveur) */
  .topbar { height: 52px; padding: 0 8px; background: #337ab7; }
  .topbar-stats { display: none; }
  .user-name { display: none; }
  .topbar-brand .brand-name { font-size: 17px; }
  .topbar-brand .brand-logo.sm { display: none; }
  .topbar-user { gap: 8px; }
  .menu-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: none; padding: 0;
    background: none; border: none; color: #fff; font-size: 22px; cursor: pointer;
  }
  .base-layer-select {
    display: block;
    height: 34px; padding: 0 8px; border: none; border-radius: 6px;
    background: #fff; color: #1E293B; font-size: 12px; font-weight: 600;
    max-width: 132px; cursor: pointer; flex: none;
  }
  .mobile-only { display: flex; }
  .mobile-stats-bar { display: flex; }

  /* Nav rail -> menu plein écran en tuiles (comme l'ancien serveur) */
  .main { flex-direction: column; position: relative; }
  .nav-rail {
    position: fixed; top: 52px; bottom: 0; left: 0; right: 0; z-index: 1500;
    width: auto; height: auto; flex: none;
    flex-direction: row; flex-wrap: wrap; align-content: flex-start;
    padding: 16px; gap: 12px;
    background: #F1F5F9;
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto; overflow-x: hidden;
  }
  .nav-rail.open { transform: translateX(0); }
  .nav-item {
    width: calc(33.333% - 8px); flex: none; min-width: 0;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 22px 6px;
    background: #fff; color: #475569;
    border-radius: 14px;
    font-size: 13px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  }
  .nav-item .nav-ico { font-size: 28px; }
  .nav-item:hover { background: #E2E8F0; color: #475569; }
  .nav-item.active { background: var(--orange); color: #0A1628; }
  .nav-divider { display: none; }

  /* Suivi : carte plein écran, sidebar en tiroir */
  .suivi-layout { flex-direction: column; position: relative; }
  .sidebar {
    position: absolute; top: 0; bottom: 0; right: 0; z-index: 1200;
    width: 82%; max-width: 320px; height: auto;
    border-right: none; border-left: 1px solid var(--line);
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .map-wrap { flex: 1; min-height: 0; }

  /* Detail drawer pleine largeur */
  .detail-drawer { left: 8px; right: 8px; bottom: 8px; width: auto; max-width: none; }

  /* Panel views */
  .panel-view { padding: 12px; -webkit-overflow-scrolling: touch; }
  .panel-head h2 { font-size: 17px; }
  .hist-controls .input { flex: 1; min-width: 0; }

  /* Tables -> cartes (mobile) */
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; overflow: visible; background: transparent; border: none; }
  table.data { min-width: 0 !important; }
  table.data thead { display: none; }
  table.data tbody { display: block; }
  table.data tr {
    display: block;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: #fff;
  }
  table.data tr:hover td { background: transparent; }
  table.data td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid #F1F5F9;
  }
  table.data td:last-child { border-bottom: none; }
  table.data td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
  }
  table.data td:not([data-label])::before { display: none; }
  table.data td:not([data-label]) { justify-content: flex-end; }

  /* Réglages : une colonne */
  .settings-body { grid-template-columns: 1fr; max-width: none; }
  #advanced-config { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Zones / alertes : une colonne */
  .zone-list { grid-template-columns: 1fr; }

  /* Modal pleine largeur */
  .modal { padding: 10px; }
  .modal-card { width: 100%; max-width: 100%; max-height: 92vh; }

  /* Toast au-dessus de la nav basse */
  .toast { left: 12px; right: 12px; bottom: 70px; }
  .web-alert-panel { left: 12px; right: 12px; bottom: 70px; max-width: none; }
}

/* ============ ZONE DRAW OVERLAY ============ */
.zone-draw {
  position: fixed; inset: 0; z-index: 3000; display: flex; flex-direction: column;
  background: #fff;
}
.zone-draw.hidden { display: none; }
.zone-draw-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--navy); color: #fff;
  font-size: 14px; font-weight: 600;
}
.zone-draw-head .icon-btn { color: #fff; }
#zone-draw-map { flex: 1; min-height: 300px; }
.zone-draw-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid #E2E8F0; background: #F8FAFC;
}
.zone-draw-bar #zd-count { font-size: 13px; color: #475569; font-weight: 600; }

/* Points de zone déplaçables */
.zd-point {
  width: 20px; height: 20px; border-radius: 50%;
  background: #F59E0B; border: 2px solid #0A1628;
  color: #0A1628; font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: grab;
}
.zd-point:active { cursor: grabbing; }

/* ============ MULTI-SELECT (alertes) ============ */
.msel-search {
  width: 100%; padding: 8px 12px; border: 1px solid #E2E8F0; border-radius: 9px;
  font-size: 13px; margin-bottom: 6px; font-family: inherit;
}
.msel-list { max-height: 180px; overflow-y: auto; border: 1px solid #E2E8F0; border-radius: 9px; padding: 6px; background: #fff; }
.msel-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.msel-item:hover { background: #F1F5F9; }
.msel-item input { accent-color: var(--orange); width: 15px; height: 15px; flex-shrink: 0; cursor: pointer; }

/* ============ VEHICULES TOOLBAR ============ */
.veh-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 0; margin-bottom: 4px;
}
.veh-count { font-size: 13px; color: #64748B; font-weight: 600; }

/* ============ VEHICULES — CARTES PREMIUM ============ */
.veh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.veh-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 13px;
  transition: box-shadow .16s ease, transform .16s ease, border-color .16s ease;
}
.veh-card:hover { box-shadow: 0 12px 28px rgba(10,22,40,0.09); transform: translateY(-2px); }
.veh-card.selected { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(245,158,11,0.16); }
.veh-card-head { display: flex; align-items: center; gap: 12px; }
.veh-avatar {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 19px; border: 1.5px solid;
}
.veh-ident { flex: 1; min-width: 0; }
.veh-name { font-weight: 700; font-size: 15.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.veh-plate {
  display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 8px;
}
.veh-check input { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }
.veh-status-line { display: flex; }
.vs-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; padding: 5px 12px; border-radius: 30px; }
.vs-dot { width: 8px; height: 8px; border-radius: 50%; }
.veh-meta { display: flex; flex-direction: column; gap: 7px; }
.vm { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 12.5px; }
.vm span { color: var(--muted); flex: none; }
.vm b { color: var(--ink); font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.veh-actions { display: flex; gap: 8px; margin-top: auto; }
.veh-actions button { flex: 1; }

/* ============ SERVER STATUS ============ */
.sys-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.sys-cell { background: #F8FAFC; border: 1px solid #E2E8F0; border-radius: 10px; padding: 12px; }
.sys-v { font-size: 18px; font-weight: 700; color: var(--navy); }
.sys-k { font-size: 12px; color: #64748B; margin: 2px 0 8px; }
.meter { height: 6px; background: #E2E8F0; border-radius: 3px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; transition: width .3s ease; }

/* ===== Permissions & device assignment ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.perm-section { margin: 14px 0 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.perm-title { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.perm-switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; padding: 6px 0; }
.perm-switch .switch { width: 40px; height: 22px; flex: none; }
.perm-switch .switch .slider:before { height: 16px; width: 16px; }
.perm-switch .switch input:checked + .slider:before { transform: translateX(18px); }
.perm-text { color: var(--ink); font-weight: 500; }
.dev-assign-list { max-height: 320px; overflow-y: auto; border: 1px solid #E2E8F0; border-radius: 10px; padding: 8px; }
.dev-check { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.dev-check:hover { background: var(--bg); }
.dev-check small { color: #94A3B8; margin-left: auto; }

/* ===== Assignation véhicules (recherche + sélection) ===== */
.assign-results {
  max-height: 220px; overflow-y: auto;
  border: 1px solid #E2E8F0; border-radius: 10px; padding: 6px; background: #fff;
  -webkit-overflow-scrolling: touch;
}
.assign-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.assign-row:hover { background: #F1F5F9; }
.assign-row .assign-add {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--orange); color: #0A1628;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.assign-row .assign-row-name { font-weight: 600; color: var(--ink); }
.assign-row small { color: #94A3B8; margin-left: auto; }
.assign-selected { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.assign-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #FEF3C7; border: 1px solid #FDE68A; border-radius: 999px;
  padding: 5px 10px; font-size: 12.5px; font-weight: 600; color: #1E293B;
}
.assign-chip button {
  background: none; border: none; cursor: pointer;
  color: #B45309; font-size: 13px; padding: 0; line-height: 1;
}
.assign-empty { padding: 12px; text-align: center; color: #94A3B8; font-size: 13px; }

/* ===== Sous-comptes ===== */
.sub-remaining {
  display: inline-block; margin-bottom: 12px;
  background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: #1D4ED8;
}
.sub-remaining:empty { display: none; }
.sub-dev-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 260px; overflow-y: auto; padding: 4px 2px;
}
.sub-dev {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; background: #fff;
  transition: border-color .15s, background .15s;
}
.sub-dev:hover { border-color: var(--accent); background: #FFFBF0; }
.sub-dev input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.sub-dev span { font-weight: 600; color: var(--ink); font-size: 13.5px; }
.sub-dev small { color: #94A3B8; margin-left: auto; font-size: 12px; }

/* ===== Partage (liens de suivi) ===== */
.dur-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.dur-btn {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 13px; font-weight: 600; transition: all .15s;
}
.dur-btn:hover { border-color: var(--accent); }
.dur-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mt8 { margin-top: 8px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-on { background: #DCFCE7; color: #15803D; }
.badge-off { background: #FEE2E2; color: #B91C1C; }
.share-result p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.share-url {
  background: #F8FAFC; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-family: monospace; font-size: 12.5px;
  word-break: break-all; color: var(--ink); margin-bottom: 14px; user-select: all;
}

/* ===== Masquer le pied de page Google Maps (attribution, Terms, Report a map error) ===== */
.gm-style-cc,
.gm-style a[target="_blank"] {
  display: none !important;
}
.gm-style a[href*="maps.google"] {
  display: none !important;
}
.sys-updated { font-size: 11px; color: #94A3B8; font-weight: 500; margin-left: 6px; }
.logo-preview { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-height: 56px; }
.logo-preview img { border: 1px solid var(--line); background: #f8fafc; }
.drag-item { cursor: grab; }
.drag-item:active { cursor: grabbing; }
.drag-item.dragging { opacity: 0.35; }
.hist-presets { display: flex; gap: 6px; margin: 8px 0 2px; flex-wrap: wrap; }
.hist-presets .preset { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.hist-presets .preset.active { background: var(--orange); color: #0A1628; border-color: var(--orange); font-weight: 600; }
