:root {
  --bg: #0a0e14;
  --panel: #121822;
  --panel-2: #171f2b;
  --stroke: rgba(255, 255, 255, .08);
  --text: #e8edf4;
  --muted: #8a96a8;
  --accent: #22d3ee;
  --route: #3b82f6;
  --off: #94a3b8;
  --sb: #818cf8;
  --d: #22c55e;
  --on: #f59e0b;
  --bad: #f43f5e;
  --warn: #f59e0b;
  --good: #34d399;
  --navy-1: #13274a;
  --navy-2: #0c1830;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--stroke); background: var(--panel-2); padding: 9px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: rgba(255,255,255,.2); }
.btn.primary { background: var(--accent); color: #00222a; border: none; }
.btn.blue { background: var(--route); color: #fff; border: none; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 9px; }
input, select, textarea { background: #0d131c; border: 1px solid var(--stroke); border-radius: 12px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.err { color: var(--bad); min-height: 18px; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 70% -10%, #13274a 0, transparent 60%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--stroke); border-radius: 24px; padding: 28px; display: grid; gap: 14px; }
.brand { font-weight: 800; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.brand.small { font-size: 20px; justify-content: center; padding: 14px 0 10px; }
.logo { color: var(--accent); }

/* ---------- shell ---------- */
.app { display: flex; height: 100%; }
.rail { width: 84px; flex: none; background: var(--panel); border-right: 1px solid var(--stroke); display: flex; flex-direction: column; align-items: center; gap: 4px; padding-bottom: 10px; }
.rail a, .rail-btn { width: 68px; display: grid; justify-items: center; gap: 2px; padding: 8px 0; border-radius: 14px; color: var(--muted); font-size: 11px; font-weight: 600; background: none; border: none; cursor: pointer; }
.rail svg { width: 22px; height: 22px; fill: currentColor; }
.rail a.active { color: var(--text); }
.rail a.active svg { background: var(--accent); fill: #00222a; border-radius: 999px; padding: 4px 14px; width: 52px; height: 30px; }
.rail-spacer { flex: 1; }
main { flex: 1; min-width: 0; height: 100%; overflow: hidden; position: relative; }
.page { height: 100%; overflow: auto; padding: 22px; }
.page-inner { max-width: 1280px; margin: 0 auto; display: grid; gap: 16px; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
.card { background: var(--panel); border: 1px solid var(--stroke); border-radius: var(--radius); padding: 18px; }
.label { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--muted); text-transform: uppercase; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 360px 1fr; gap: 16px; }

/* ---------- fleet ---------- */
.fleet { display: grid; grid-template-columns: 380px 1fr; height: 100%; }
.fleet-list { border-right: 1px solid var(--stroke); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.fleet-head { padding: 18px 18px 10px; display: grid; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--stroke); border-radius: 14px; padding: 8px 10px; }
.stat b { font-size: 20px; display: block; }
.stat span { font-size: 11px; color: var(--muted); }
.units { overflow: auto; padding: 4px 10px 16px; display: grid; gap: 8px; align-content: start; }
.unit { background: var(--panel); border: 1px solid var(--stroke); border-radius: 16px; padding: 12px 14px; cursor: pointer; display: grid; gap: 6px; }
.unit:hover, .unit.sel { border-color: var(--route); }
.unit .title { font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.chip { font-weight: 800; font-size: 11px; padding: 2px 8px; border-radius: 8px; letter-spacing: .03em; }
.chip.OFF { color: var(--off); background: rgba(148,163,184,.15); }
.chip.SB { color: var(--sb); background: rgba(129,140,248,.15); }
.chip.D { color: var(--d); background: rgba(34,197,94,.15); }
.chip.ON { color: var(--on); background: rgba(245,158,11,.15); }
.mini-clocks { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.mini-clocks b { color: var(--text); font-family: "JetBrains Mono", monospace; }
.map { position: absolute; inset: 0; background: #0d0d0d; }
.map-wrap { position: relative; height: 100%; }
.empty { padding: 30px 18px; color: var(--muted); text-align: center; }
.vehicle-icon { width: 34px; height: 34px; }

/* ---------- unit detail ---------- */
.unit-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--stroke); }
.tab { padding: 10px 14px; color: var(--muted); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; background: none; border-top: 0; border-left: 0; border-right: 0; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.detail-map { height: 420px; border-radius: var(--radius); overflow: hidden; position: relative; border: 1px solid var(--stroke); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--stroke); border-radius: 14px; padding: 10px 14px; }
.kpi b { display: block; font-size: 20px; font-family: "JetBrains Mono", monospace; }

/* ELD clocks */
.clocks-panel { border-radius: 24px; padding: 20px; background: linear-gradient(180deg, var(--navy-1), var(--navy-2)); border: 1px solid rgba(59,130,246,.15); }
.clocks { display: flex; justify-content: space-evenly; flex-wrap: wrap; gap: 14px; margin: 16px 0 10px; }
.clock { position: relative; width: 150px; height: 150px; }
.clock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.clock .val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.clock .val b { font-size: 32px; font-weight: 700; color: #fff; }
.clock .val span { font-size: 12px; letter-spacing: .1em; color: #c9d6ee; font-weight: 600; }
.clock-foot { display: flex; justify-content: center; gap: 26px; color: #9db2d6; flex-wrap: wrap; }
.clock-foot b { color: var(--text); font-family: "JetBrains Mono", monospace; margin-left: 6px; }
.status-big { font-size: 30px; font-weight: 900; }

/* log graph */
.graph svg { width: 100%; height: auto; display: block; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--stroke); }
td { padding: 9px 10px; border-bottom: 1px solid var(--stroke); vertical-align: middle; }
tr.deleted td { opacity: .4; text-decoration: line-through; }
.recap-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; border-radius: 12px; }
.recap-row:hover { background: rgba(255,255,255,.03); }
.recap-row.sel { background: rgba(59,130,246,.12); }
.badge-office { font-size: 10px; font-weight: 800; color: var(--accent); border: 1px solid rgba(34,211,238,.4); padding: 1px 6px; border-radius: 6px; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--stroke); border-radius: 22px; padding: 22px; display: grid; gap: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--stroke); padding: 10px 18px; border-radius: 12px; z-index: 3000; }
.code { font-family: "JetBrains Mono", monospace; font-size: 28px; letter-spacing: .12em; font-weight: 700; color: var(--accent); }

.leaflet-container { background: #0e0e0e; font-family: Inter, sans-serif; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-control-attribution { background: rgba(0,0,0,.5) !important; color: #888 !important; }
.leaflet-control-attribution a { color: #aaa !important; }

@media (max-width: 900px) {
  .fleet { grid-template-columns: 1fr; grid-template-rows: 45% 55%; }
  .fleet-list { border-right: 0; order: 2; }
  .grid2 { grid-template-columns: 1fr; }
  .rail { width: 64px; }
  .rail a, .rail-btn { width: 56px; }
  .page { padding: 14px; }
  .clock { width: 120px; height: 120px; }
  .clock .val b { font-size: 24px; }
}
