:root {
  --bg: #0f1419;
  --panel: #171d24;
  --panel-2: #1f2730;
  --line: #2b3540;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #3b9eff;
  --ok: #30a46c;
  --warn: #f5a524;
  --bad: #e5484d;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.4em; }
.hidden { display: none !important; }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.warn { background: var(--warn); color: #1a1200; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.brand { font-weight: 800; letter-spacing: .3px; white-space: nowrap; }
.brand.big { font-size: 22px; margin-bottom: 6px; }

/* ---------- connexion ---------- */
.login {
  position: fixed; inset: 0; background: var(--bg); z-index: 3000;
  display: grid; place-items: center; padding: 16px;
}
.login-card { width: 100%; max-width: 320px; text-align: center; }
.pin-display {
  font-size: 32px; letter-spacing: 8px; height: 56px; margin: 18px 0 10px;
  background: var(--panel); border-radius: var(--radius); display: grid; place-items: center;
}
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button {
  height: 64px; font-size: 24px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); cursor: pointer;
}
.pin-pad button:active { background: var(--panel-2); }
.pin-pad button[data-k="OK"] { background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* ---------- répartition ---------- */
.dispatch { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.storm { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.storm-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { flex: 1; max-width: 320px; height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--ok); transition: width .4s; }
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 380px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; background: none; border: 0; padding: 12px 6px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: none; flex-direction: column; min-height: 0; flex: 1; }
.tab.active { display: flex; }
.row { display: flex; gap: 8px; padding: 10px 12px 0; align-items: center; }
.row > input, .row > select { flex: 1; }
.list { overflow-y: auto; flex: 1; padding: 10px 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.item {
  background: var(--panel-2); border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start;
}
.item:hover { border-color: var(--line); }
.item.selected { border-color: var(--accent); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.item-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 4px; }
.pill {
  font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--line); color: var(--text);
  white-space: nowrap; font-weight: 600;
}
.pill.on { background: rgba(48,164,108,.2); color: #5fd49a; }
.pill.off { background: rgba(139,152,165,.15); color: var(--muted); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; font-size: 15px; }
.icon-btn:hover { color: var(--text); }
.count { color: var(--muted); font-size: 12px; padding: 8px 12px 0; }
#map { flex: 1; min-height: 0; background: #1b232c; }

.report { overflow-y: auto; padding: 12px; flex: 1; }
.report h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.report table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report td, .report th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.report th { color: var(--muted); font-weight: 500; }

/* ---------- fenêtres ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 2000;
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 20px;
}
.modal-card h2 { margin: 0 0 6px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.inline { display: flex; gap: 8px; }
.geo-results { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.geo-results button {
  text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 13px;
}
.geo-results button:hover { border-color: var(--accent); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 99px; z-index: 4000;
  pointer-events: none; transition: .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.pick-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 99px; font-weight: 600;
  display: flex; gap: 10px; align-items: center;
}

/* ---------- marqueurs ---------- */
.veh-icon { background: none; border: 0; }
.veh { position: relative; width: 44px; height: 44px; }
.veh-dot {
  width: 34px; height: 34px; margin: 5px; border-radius: 50%; background: var(--c);
  border: 3px solid #fff; display: grid; place-items: center; font-size: 17px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5); position: relative;
}
.veh.me .veh-dot { width: 40px; height: 40px; margin: 2px; box-shadow: 0 0 0 6px rgba(59,158,255,.35), 0 2px 8px rgba(0,0,0,.5); }
.veh.off .veh-dot { filter: grayscale(1); opacity: .6; }
.veh-arrow {
  position: absolute; inset: -12px; pointer-events: none;
}
.veh-arrow::before {
  content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border: 7px solid transparent; border-bottom: 10px solid var(--c); border-top: 0;
}
.veh-label {
  position: absolute; top: 44px; left: 50%; transform: translateX(-50%);
  background: #000b; color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px;
  border-radius: 4px; white-space: nowrap;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup h4 { margin: 0 0 4px; font-size: 15px; }
.popup .line { color: var(--muted); font-size: 12px; margin: 2px 0; }
.popup .notes { background: rgba(245,165,36,.12); color: #ffd28a; padding: 6px 8px; border-radius: 6px; margin: 6px 0; }
.popup .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- tablette ---------- */
.driver { display: flex; flex-direction: column; height: 100%; overflow: hidden; font-size: 16px; }
.d-status {
  display: flex; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  align-items: center; flex-wrap: wrap;
}
.d-status .veh-name { font-weight: 800; font-size: 18px; margin-right: auto; cursor: pointer; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--panel-2); white-space: nowrap; }
.chip.good { background: rgba(48,164,108,.2); color: #5fd49a; }
.chip.bad { background: rgba(229,72,77,.2); color: #ff8b8e; }
.chip.warn { background: rgba(245,165,36,.2); color: #ffc65c; }
.d-body { flex: 1; display: grid; grid-template-columns: 1fr 420px; min-height: 0; }
.d-map-wrap { position: relative; min-height: 0; }
.d-map-wrap #map { position: absolute; inset: 0; }
.d-map-btns { position: absolute; right: 10px; bottom: 20px; z-index: 900; display: flex; flex-direction: column; gap: 8px; }
.d-map-btns button {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--panel); color: var(--text);
  font-size: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.5); cursor: pointer;
}
.d-map-btns button.active { background: var(--accent); }
.d-side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.job { padding: 14px; border-bottom: 1px solid var(--line); }
.job .label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.job .name { font-size: 22px; font-weight: 800; margin: 2px 0; }
.job .addr { font-size: 16px; }
.job .notes { background: rgba(245,165,36,.14); color: #ffd28a; padding: 8px 10px; border-radius: 8px; margin-top: 8px; }
.job .arrived { background: rgba(48,164,108,.2); color: #5fd49a; padding: 6px 10px; border-radius: 8px; margin-top: 8px; font-weight: 700; }
.job-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.job-btns .btn { padding: 14px; font-size: 17px; border-radius: 12px; }
.job-btns .btn.done { grid-column: 1 / -1; padding: 20px; font-size: 22px; }
.d-tabs { display: flex; gap: 6px; padding: 10px 14px 0; }
.d-tabs button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: none; cursor: pointer;
}
.d-tabs button.active { background: var(--panel-2); border-color: var(--accent); }
.d-list { overflow-y: auto; flex: 1; padding: 10px 14px 20px; display: flex; flex-direction: column; gap: 6px; }
.d-list .item { padding: 12px; font-size: 15px; }
.d-list .item-sub { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.vehicle-pick { display: grid; gap: 10px; margin-top: 18px; }
.vehicle-pick button {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); font-size: 18px; font-weight: 700; text-align: left;
}

@media (max-width: 900px) {
  .layout { flex-direction: column-reverse; }
  .panel { width: auto; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  #map { min-height: 45%; }
  .d-body { grid-template-columns: 1fr; grid-template-rows: 45% 55%; }
  .d-side { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar { gap: 8px; }
}
