/* Fleet Platform — design tokens first, then components. */
/* Samora Fleet Vision brand: charcoal and black, electric blue, silver. Dark is the default; light is optional. */
:root {
  --bg: #07090c;
  --surface: #10151c;
  --surface-2: #18202a;
  --border: #263242;
  --text: #e8eef5;
  --muted: #8e9aab;
  --silver: #c9d2dd;
  --accent: #2b7bff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(43, 123, 255, 0.16);
  --ok: #2fbf71;
  --warn: #f0a83a;
  --off: #6c7987;
  --danger: #ff5c5c;
  --video-bg: #05070a;
  --route: #2b7bff;
  --deliver: #2b7bff;
  --collect: #f0a83a;
  --brand-bar: #05070a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --map-filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f4f7; --surface: #ffffff; --surface-2: #edf0f4; --border: #d6dce4;
  --text: #121a24; --muted: #5a6778; --silver: #3a4655; --accent: #1d63e0; --accent-ink: #ffffff; --accent-soft: #e2ecfd;
  --ok: #1a8f4c; --warn: #b7791f; --off: #8a96a3; --danger: #c43c3c; --route: #1d63e0; --deliver: #1d63e0; --collect: #c27a10;
  --shadow: 0 6px 24px rgba(16, 24, 32, 0.12); --map-filter: none;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
[hidden] { display: none !important; }
h2 { font-size: 13px; font-weight: 600; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
code { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons and inputs */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px;
  padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { font-weight: 400; font-size: 14px; }
.form-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 13px; }

/* Brand */
.brand { display: flex; align-items: center; flex: none; }
.brand-logo { height: 34px; width: auto; display: block; mix-blend-mode: screen; }
.login-logo { width: min(520px, 100%); display: block; mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 62%, transparent 100%); mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 62%, transparent 100%); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; align-content: center; gap: 10px; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, #0d1a2e 0%, #05070a 60%); }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }

/* App shell */
.app { height: 100%; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
.topbar { display: flex; align-items: center; gap: 20px; padding: 0 16px; height: 56px; background: var(--brand-bar);
  border-bottom: 1px solid #1d2733; box-shadow: inset 0 -1px 0 rgba(43, 123, 255, .25); color: #e8eef5; }
.topbar .tab { color: #8e9aab; }
.topbar .tab[aria-selected="true"], .topbar .tab:hover { color: #ffffff; }
.topbar .tab[aria-selected="true"] { border-bottom-color: #2b7bff; }
.topbar .btn { background: #10151c; border-color: #263242; color: #e8eef5; }
.topbar .btn-ghost { background: transparent; border-color: transparent; }
.topbar select { background: #10151c; border-color: #263242; color: #e8eef5; }
.topbar .muted, .topbar .account-name { color: #8e9aab; }
.tabs { display: flex; gap: 2px; height: 100%; }
.tab { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 0 14px; cursor: pointer;
  border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }
.count { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.count:empty { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.pill.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill.demo { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.view { min-height: 0; }

/* Map view */
.view-map { display: grid; grid-template-columns: 350px 1fr; height: 100%; }
.side { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.search { display: flex; gap: 6px; padding: 12px 12px 8px; }
.search-results { padding: 0 12px; display: grid; gap: 4px; }
.search-results button { text-align: left; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 12px 6px; }
.vehicle-list { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; flex: 1; }
.vehicle { display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 10px; align-items: center; padding: 9px 8px;
  border-radius: 6px; cursor: pointer; }
.vehicle:hover, .vehicle.selected { background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.dot.moving { background: var(--ok); }
.dot.idle { background: var(--warn); }
.v-name { font-weight: 600; }
.v-reg { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 6px; }
.v-meta { grid-column: 2 / 4; display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.v-actions { display: flex; gap: 2px; }
.v-actions button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 3px 5px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.v-actions button:hover { background: var(--surface); color: var(--accent); }
.fuel { display: inline-flex; align-items: center; gap: 5px; }
.fuel-bar { width: 36px; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.fuel-bar i { display: block; height: 100%; background: var(--ok); }
.fuel-bar i.low { background: var(--danger); }
.hint { margin: 0; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.map-wrap { position: relative; min-height: 0; }
.map { position: absolute; inset: 0; background: var(--surface-2); }
.map-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* Leaflet markers and popups */
.veh-icon svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.veh-label { position: absolute; left: 30px; top: 6px; white-space: nowrap; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font: 600 11px/18px var(--font); }
.job-pin { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  color: #fff; font: 700 11px var(--font); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.job-pin span { transform: rotate(45deg); }
.leaflet-popup-content { font: 13px/1.4 var(--font); margin: 12px 14px; }
.popup-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* Multi-view */
.view-multiview { display: grid; grid-template-rows: auto 1fr; height: 100%; background: var(--video-bg); }
.mv-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; padding: 5px 13px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mv-hint { margin-left: auto; font-size: 12px; }
.mv-grid { display: grid; gap: 4px; padding: 4px; min-height: 0; overflow: hidden; }
/* Grid fills the screen: every tile visible at once, like a control-room wall. */
.mv-grid[data-layout="1"] { grid-template: 1fr / 1fr; }
.mv-grid[data-layout="4"] { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.mv-grid[data-layout="9"] { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.mv-grid[data-layout="16"] { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }
.tile { position: relative; min-height: 0; background: #000; border: 1px solid #1d2632; border-radius: 4px; overflow: hidden; }
.tile video, .tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.tile-bar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 8px; padding: 5px 7px;
  background: linear-gradient(rgba(0,0,0,.75), transparent); z-index: 2; }
.tile-bar select { width: auto; max-width: 75%; background: rgba(10,14,20,.7); color: #e6edf3; border-color: #2c3947; padding: 3px 6px; font-size: 12px; }
.live-badge { display: inline-flex; align-items: center; gap: 5px; color: #fff; font: 700 10px var(--font); letter-spacing: .08em; margin-left: auto;
  flex-shrink: 0; background: rgba(10,14,20,.7); padding: 3px 7px; border-radius: 4px; }
.live-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: blink 1.4s infinite; }
.tile-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #8899aa; font-size: 13px; text-align: center; padding: 20px; }
.tile-empty { color: #5d6b79; }
.tile-msg:has(.tile-play) { gap: 10px; align-content: center; }
.tile-play { width: 64px; height: 64px; border-radius: 50%; border: 2px solid rgba(255,255,255,.85); background: rgba(10,14,20,.55);
  color: #fff; font-size: 24px; cursor: pointer; display: grid; place-items: center; padding-left: 5px; transition: transform .12s, background .12s; }
.tile-play:hover { background: var(--accent); transform: scale(1.06); }
.tile-stop { border: 0; background: rgba(10,14,20,.7); color: #fff; border-radius: 4px; padding: 2px 8px; font-size: 12px; cursor: pointer; }
.tile-stop:hover { background: var(--danger); }
@keyframes blink { 50% { opacity: .25; } }

/* Jobs */
.view-jobs { padding: 16px; overflow: auto; height: 100%; }
.jobs-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.jobs-toolbar .btn-primary { margin-left: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 12px;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.jobs-table { width: 100%; border-collapse: collapse; }
.jobs-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.jobs-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.jobs-table tbody tr { cursor: pointer; }
.jobs-table tbody tr:hover { background: var(--surface-2); }
.jobs-table td.addr { max-width: 340px; }
.ref { font-family: var(--mono); font-size: 12px; }
.status { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.status.sent, .status.accepted, .status.enroute { background: var(--accent-soft); color: var(--accent); }
.status.arrived { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.status.completed { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.status.failed { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.type-badge { font-size: 12px; font-weight: 600; }
.type-badge.collection { color: var(--collect); }
.type-badge.delivery { color: var(--deliver); }
.actions-col { width: 1%; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty { padding: 32px; text-align: center; color: var(--muted); margin: 0; }

/* Dialogs */
.dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(8, 12, 18, .5); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }
.dialog-body { padding: 16px 18px; display: grid; gap: 12px; overflow: auto; }
.dialog-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.spacer { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg-field { display: flex; gap: 16px; }
.radio { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); font-weight: 600; }
.radio input { width: auto; }
.parts { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px 10px; margin: 0; }
.parts legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.parts-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.parts-table th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 2px 4px; }
.parts-table td { padding: 3px 4px; }
.parts-table td:nth-child(1) { width: 32%; }
.parts-table td:nth-child(3) { width: 70px; }
.parts-table td:nth-child(4) { width: 30px; }
.cam-rows { display: grid; gap: 8px; }
.cam-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 8px; align-items: center; }

.dialog-sm { width: min(420px, calc(100vw - 32px)); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Accounts */
body:not(.is-admin) .admin-only { display: none !important; }
.switcher select { width: auto; max-width: 220px; padding: 4px 8px; font-size: 13px; font-weight: 600; }
.account-name { font-weight: 600; font-size: 13px; }
.v-owner { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border-radius: 4px; padding: 0 6px; vertical-align: 1px; }
.v-owner.none { color: var(--muted); background: var(--surface-2); }
.field-note { align-self: end; font-size: 12px; color: var(--muted); padding-bottom: 8px; }

/* Alerts */
.alerts { border-bottom: 1px solid var(--border); }
.alert-list { list-style: none; margin: 0; padding: 0 8px 8px; max-height: 190px; overflow: auto; }
.alert-list button { width: 100%; display: grid; grid-template-columns: 8px 1fr auto; gap: 2px 10px; align-items: center; text-align: left;
  border: 0; background: none; color: var(--text); font: inherit; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.alert-list button:hover { background: var(--surface-2); }
.sev { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.sev.high { background: var(--danger); }
.sev.medium { background: var(--warn); }
.alert-name { font-weight: 600; font-size: 13px; }
.alert-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.alert-veh { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.dvr-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; }
.dvr-add label:first-child { flex: 1 1 220px; }
.dvr-add label:nth-child(2) { flex: 0 0 90px; }

/* Settings */
.view-settings { overflow: auto; padding: 20px; height: 100%; }
.settings-panel { max-width: 860px; }
.cms-form { display: grid; gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.test-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.test-steps li { display: grid; grid-template-columns: 22px 1fr; gap: 2px 8px; }
.test-steps .mark { font-weight: 700; }
.test-steps .ok .mark { color: var(--ok); }
.test-steps .bad .mark { color: var(--danger); }
.test-steps .na .mark { color: var(--muted); }
.test-steps .detail { grid-column: 2; font-size: 12px; color: var(--muted); word-break: break-word; }
.test-steps .mini-table { grid-column: 2; margin-top: 4px; }

/* Customers screen */
.view-customers { display: grid; grid-template-columns: 300px 1fr; height: 100%; min-height: 0; }
.cust-side { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.cust-new { display: flex; gap: 6px; align-items: end; padding: 12px; border-bottom: 1px solid var(--border); }
.cust-new label { flex: 1; }
.cust-list { list-style: none; margin: 0; padding: 6px 8px; overflow: auto; flex: 1; }
.cust-list button { width: 100%; text-align: left; border: 0; background: none; color: var(--text); font: inherit; padding: 9px 10px;
  border-radius: 6px; cursor: pointer; display: grid; gap: 2px; }
.cust-list button:hover, .cust-list button[aria-current="true"] { background: var(--surface-2); }
.cust-list button[aria-current="true"] { box-shadow: inset 3px 0 0 var(--accent); }
.cust-list strong { font-weight: 600; }
.cust-list span { font-size: 12px; color: var(--muted); }
.cust-unassigned { margin: 0; padding: 10px 14px; border-top: 1px solid var(--border); }
.cust-detail { overflow: auto; padding: 20px; display: grid; gap: 16px; align-content: start; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; }
.cust-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cust-title h2 { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.inline-form > label { flex: 1 1 200px; min-width: 0; }
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.mini-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.mini-table tr:last-child td { border-bottom: 0; }
.mini-table .user-name { font-family: var(--mono); font-size: 13px; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { font-family: var(--mono); }
.veh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.veh-check { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; color: var(--text); font-weight: 400; cursor: pointer; }
.veh-check input { width: auto; }
.veh-check.mine { border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: var(--accent-soft); }
.veh-check small { color: var(--muted); display: block; font-size: 11px; }
.danger-zone { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Narrow screens */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; height: auto; min-height: 52px; flex-wrap: wrap; }
  .brand-logo { height: 26px; }
  .tabs { order: 3; flex: 1 0 100%; overflow-x: auto; scrollbar-width: none; }
  .tab { padding: 0 9px; height: 46px; flex: none; }
  .pill { display: none; }
  .view-map { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .view-customers { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .cust-side { border-right: 0; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .cust-detail { padding: 12px; }
  .switcher select { max-width: 130px; }
  .topbar-right { min-width: 0; }
  .switcher, .switcher select { min-width: 0; }
  .account-name { display: none; }
  .map-wrap { order: -1; }
  .side { border-right: 0; border-top: 1px solid var(--border); }
  .mv-grid { overflow: auto; align-content: start; }
  .mv-grid[data-layout] { grid-template-rows: none; grid-auto-rows: auto; }
  .mv-grid[data-layout="9"], .mv-grid[data-layout="16"] { grid-template-columns: repeat(2, 1fr); }
  .tile { aspect-ratio: 16 / 9; }
  .mv-hint { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .view-jobs { padding: 10px; }
  .jobs-table td.addr { min-width: 200px; }
}

/* ---------------- Recordings */
.view-recordings { display: grid; grid-template-columns: 300px 1fr; gap: 16px; padding: 16px; height: 100%; overflow: auto; align-items: start; }
.rec-side h3 { margin: 0 0 12px; }
.rec-form { display: grid; gap: 10px; }
.rec-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.rec-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rec-raw { white-space: pre-wrap; word-break: break-all; font: 11px var(--mono); max-height: 200px; overflow: auto; background: var(--surface-2); padding: 8px; border-radius: 6px; }
.rec-main { display: grid; gap: 16px; min-width: 0; }
.rec-player { padding: 0; overflow: hidden; }
.rec-video { position: relative; aspect-ratio: 16 / 9; max-height: 60vh; background: var(--video-bg); display: grid; place-items: center; }
.rec-video video { width: 100%; height: 100%; object-fit: contain; }
.rec-video .tile-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #c8d1da; text-align: center; padding: 16px; }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.rec-now { font-weight: 600; margin-right: auto; }
.rec-timeline { display: grid; gap: 6px; margin-bottom: 12px; }
.tl-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; }
.tl-label { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track { position: relative; height: 22px; background: var(--surface-2); border-radius: 4px; cursor: pointer; }
.tl-seg { position: absolute; top: 3px; bottom: 3px; background: var(--accent); border-radius: 3px; opacity: 0.85; }
.tl-track:hover .tl-seg { opacity: 1; }
.tl-axis { position: relative; height: 16px; font-size: 11px; color: var(--muted); }
.tl-axis span { position: absolute; transform: translateX(-50%); }
.rec-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; }
.rec-list li { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.rec-time { font-family: var(--mono); font-size: 13px; }
@media (max-width: 800px) {
  .view-recordings { grid-template-columns: 1fr; padding: 12px; }
  .rec-list li { grid-template-columns: 1fr auto; }
  .rec-list .rec-cam { grid-column: 1; }
  .rec-list li button { grid-row: 1 / span 2; grid-column: 2; }
}

/* ---------------- DVR setup */
.view-dvrsetup { height: 100%; overflow: auto; }
.dvr-setup { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; padding: 16px; align-items: start; }
.dvr-side h4 { margin: 8px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dvr-upload { justify-content: center; cursor: pointer; }
.dvr-list, .dvr-tpl-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dvr-item { width: 100%; text-align: left; display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.dvr-item:hover { border-color: var(--accent); }
.dvr-item.active { border-color: var(--accent); background: var(--accent-soft); }
.dvr-tpl-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.dvr-editor { display: grid; gap: 14px; min-width: 0; }
.dvr-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.dvr-label { font-size: 20px; font-weight: 600; border: 1px solid transparent; background: transparent; color: var(--text); padding: 2px 6px; border-radius: 6px; min-width: 0; }
.dvr-label:hover, .dvr-label:focus { border-color: var(--border); background: var(--surface); }
.dvr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; min-width: 0; }
.dvr-card h4 { margin: 0; font-size: 15px; }
.dvr-card summary { cursor: pointer; }
.dvr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.dvr-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); align-content: start; }
.dvr-grid input, .dvr-grid select, .dvr-table input, .dvr-table select { height: 34px; box-sizing: border-box; }
.dvr-grid input, .dvr-grid select, .dvr-table input, .dvr-table select, #dvr-filter, #dvr-tpl-pick {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 0; }
.dvr-grid input[readonly] { background: var(--surface-2); color: var(--muted); }
.dvr-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.dvr-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.dvr-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.dvr-table td input { width: 100%; min-width: 110px; }
.dvr-table td select { min-width: 100%; width: max-content; }
.dvr-all-wrap { max-height: 420px; }
.mono { font-family: var(--mono); }
[data-key].changed { border-color: var(--warn) !important; box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 25%, transparent); }
.dvr-change-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dvr-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }
.dvr-toast.bad { background: var(--danger); color: #fff; }
.empty-state { padding: 24px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
@media (max-width: 800px) {
  .dvr-setup { grid-template-columns: 1fr; padding: 12px; }
}


/* ---------------- Map in the brand theme, routes and job progress */
.leaflet-tile-pane { filter: var(--map-filter); }
.leaflet-container { background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.stop-num { width: 22px; height: 22px; border-radius: 50%; background: var(--route); color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center; border: 2px solid #fff; }
.run-list { margin: 8px 0 0; padding-left: 0; list-style: none; display: grid; gap: 3px; font-size: 12px; }
.job-route { min-height: 22px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.route-pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 10px; font-weight: 600; }
.job-progress { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: grid; gap: 10px; }
.job-progress legend { font-weight: 600; font-size: 12px; color: var(--muted); padding: 0 4px; }
.progress-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.progress-list li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.pod-photos { display: flex; gap: 8px; flex-wrap: wrap; }
.pod-photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.pod-sig { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pod-sig img { height: 70px; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.pod-flag { color: var(--ok); font-weight: 600; }
.role-badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.role-badge.driver { background: var(--accent-soft); color: var(--accent); }
.theme-btn { font-size: 16px; }

/* ---------------- Compact vehicle list and the vehicle page */
.v-filter { margin: 0 12px 8px; width: calc(100% - 24px); }
.vehicle-list.compact .vehicle { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.vehicle-list.compact .vehicle:hover, .vehicle-list.compact .vehicle:focus-visible { background: var(--surface-2); outline: none; }
.vehicle-list.compact .vehicle.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.v-reg-big { font-weight: 700; letter-spacing: .04em; font-size: 14px; font-family: var(--mono); }
.v-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.v-fuel.low { color: var(--warn); }
.cam-dot { font-size: 10px; }
.cam-dot.on { color: var(--ok); }
.cam-dot.off { color: var(--danger); }
#vehicles-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow: auto; }
.vehicle-detail { padding: 10px 14px 18px; display: grid; gap: 12px; overflow: auto; align-content: start; }
.vehicle-detail .back { justify-self: start; padding: 2px 0; font-size: 13px; background: none; border: 0; color: var(--accent); cursor: pointer; }
.vp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.vp-reg { font: 700 22px/1.1 var(--mono); letter-spacing: .05em; }
.vp-status { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-align: right; }
.vp-status.moving { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.vp-status.idle { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; display: grid; gap: 2px; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat b { font-size: 16px; }
.stat.warn b { color: var(--warn); }
.vp-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.vp-card h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.vp-card label { font-size: 12px; }
.unit-pill { text-transform: none; letter-spacing: 0; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.unit-pill.on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.unit-pill.off { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.cam-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cam-list li { display: grid; grid-template-columns: 10px auto 1fr; gap: 8px; align-items: center; font-size: 13px; }
.cam-list li .small { text-align: right; }
.cam-st { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.cam-st.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.cam-st.bad { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent); }
.cam-st.unknown { background: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.kv span:nth-child(odd) { color: var(--muted); }

/* ---------------- Alerts tab, geofences */
.view-alerts { height: 100%; overflow: auto; }
.alerts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 16px; align-items: start; }
.alerts-grid .panel { display: grid; gap: 12px; }
.geo-panel, .recent-panel { grid-column: span 1; }
.type-checks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text); }
.check input { width: auto; }
.rules-form { display: grid; gap: 12px; }
.rules-form .inline, .inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
.rules-form input[type=number] { width: 90px; }
.rules-form input[type=time] { width: 120px; }
.ooh { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 12px; display: grid; gap: 10px; }
.ooh legend { padding: 0 4px; }
.days { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.geo-list, .recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 420px; overflow: auto; }
.geo-list li { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.geo-swatch { width: 14px; height: 14px; border-radius: 4px; }
.recent-list li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.recent-list li:hover { background: var(--surface-2); }
.geo-draw { position: absolute; z-index: 600; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); max-width: calc(100% - 24px); font-size: 13px; }
.geo-draw .radius { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.geo-draw input[type=range] { width: 160px; padding: 0; }
.map.drawing { cursor: crosshair; }
.map.drawing .leaflet-interactive { cursor: crosshair; }
.inline-checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.geo-vehicles { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; display: grid; gap: 6px; }
.veh-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 160px; overflow: auto; padding-left: 22px; }
@media (max-width: 900px) { .alerts-grid { grid-template-columns: 1fr; padding: 12px; } }
/* While drawing a geofence, clicks go to the map, not to vans, jobs or other geofences. */
.map.drawing .leaflet-marker-pane, .map.drawing .leaflet-marker-pane *, .map.drawing .leaflet-overlay-pane path { pointer-events: none !important; }

/* ---------------- Walkaround checks */
.view-checks { height: 100%; overflow: auto; }
.checks-wrap { display: grid; gap: 16px; padding: 16px; max-width: 1100px; }
.count.warn { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }
.defect-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.defect-list > li { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 12px; border: 1px solid var(--danger); border-radius: 8px; background: color-mix(in srgb, var(--danger) 7%, transparent); }
.fault-items { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.check-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.check-items li { display: grid; grid-template-columns: 70px 1fr; gap: 10px; padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.check-items li.fault { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.check-items li.fault .ck-word { color: var(--danger); font-weight: 700; }
.check-items li.ok .ck-word { color: var(--ok); font-weight: 600; }
.check-items li.na .ck-word { color: var(--muted); }
.check-items .pod-photos { display: flex; margin-top: 6px; }
.vp-card.walk.bad { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.vp-card.walk.good { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.vp-card h3 .link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; text-transform: none; letter-spacing: 0; }

/* Company roles: office logins don't see admin-only controls; the Team tab is for company admins */
body:not(.is-owner) .owner-only { display: none !important; }
body:not(.is-company-admin) .owner-tab { display: none !important; }
.login-title { margin: 0; font-size: 18px; }
.team-wrap { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; padding: 16px; align-items: start; }
.view-team { height: 100%; overflow: auto; }
.team-form { display: grid; gap: 10px; }
@media (max-width: 900px) { .team-wrap { grid-template-columns: 1fr; padding: 12px; } }

/* Clearing alerts */
#alerts .side-head { gap: 8px; }
#alerts-clear-all { margin-left: auto; }
.alert-row { display: grid; grid-template-columns: auto 1fr; align-items: stretch; }
.alert-clear { width: 34px; border: 0; border-right: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; }
.alert-clear:hover { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.recent-list li.cleared { opacity: .55; }
.recent-list li.cleared b { text-decoration: line-through; }
.recent-list li > span:last-child { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
