/* Seventara Fleet web app - operations console styling. No external fonts or CDNs (strict CSP). */
:root {
  --bg: #f3f4f1; --panel: #ffffff; --panel-2: #f8f9f7; --ink: #15212a; --ink-2: #4b5862; --ink-3: #7c8891;
  --line: #e1e4e0; --line-2: #cfd4cf;
  --nav: #12232e; --nav-ink: #c9d4da; --nav-active: #1d3646;
  --brand: #f2a93b; --brand-ink: #3d2700; --cold: #2a9cb0; --cold-soft: #e3f3f6;
  --ok: #2e8b57; --ok-soft: #e4f3ea; --warn: #c7770a; --warn-soft: #fbf0dc; --crit: #c8352b; --crit-soft: #fbe5e3;
  --info: #3c6fb0; --info-soft: #e5edf8; --muted-soft: #eceeeb;
  --moving: #2e8b57; --idling: #3c6fb0; --parked: #7c8891; --stale: #c7770a; --offline: #c8352b;
  --radius: 10px; --shadow: 0 1px 2px rgba(18,35,46,.06), 0 1px 1px rgba(18,35,46,.04);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --map-land: #eef1ea; --map-grid: #dfe4dc; --map-route: #1d3646;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e171d; --panel: #15222b; --panel-2: #1a2933; --ink: #e6ecef; --ink-2: #aab7bf; --ink-3: #7d8c96;
    --line: #23343f; --line-2: #2e424e; --nav: #0a1217; --nav-ink: #9fb0ba; --nav-active: #172833;
    --cold-soft: #12323a; --ok-soft: #133224; --warn-soft: #3a2a10; --crit-soft: #3d1a17; --info-soft: #172a42; --muted-soft: #1e2d37;
    --shadow: none; --map-land: #172630; --map-grid: #20323d; --map-route: #9fc3d6;
  }
}
:root[data-theme="dark"] {
  --bg: #0e171d; --panel: #15222b; --panel-2: #1a2933; --ink: #e6ecef; --ink-2: #aab7bf; --ink-3: #7d8c96;
  --line: #23343f; --line-2: #2e424e; --nav: #0a1217; --nav-ink: #9fb0ba; --nav-active: #172833;
  --cold-soft: #12323a; --ok-soft: #133224; --warn-soft: #3a2a10; --crit-soft: #3d1a17; --info-soft: #172a42; --muted-soft: #1e2d37;
  --shadow: none; --map-land: #172630; --map-grid: #20323d; --map-route: #9fc3d6;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--info); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--ink-3); }
.hidden { display: none !important; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mt-s { margin-top: 10px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; letter-spacing: .2px; font-size: 16px; }
.brand svg { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--nav-ink); letter-spacing: .3px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: var(--nav-ink); border-left: 3px solid transparent; }
.nav a:hover { background: var(--nav-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--nav-active); color: #fff; border-left-color: var(--brand); }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; }
.nav .grow { flex: 1; }
.nav .sim-note { margin: 12px; padding: 10px 12px; border: 1px dashed #2f4a5a; border-radius: 8px; font-size: 12px; color: #9fb0ba; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .crumbs { color: var(--ink-3); font-size: 13px; }
.topbar .spacer { flex: 1; }
.topbar .who { text-align: right; font-size: 12px; color: var(--ink-3); line-height: 1.25; }
.topbar .who b { color: var(--ink); font-weight: 600; font-size: 13px; }
.btn.menu-btn { display: none; }
.content { padding: 20px 24px 60px; max-width: 1480px; width: 100%; }

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card > header h2 { font-size: 14px; margin: 0; font-weight: 650; }
.card > header .spacer { flex: 1; }
.card .body { padding: 14px 16px; }
.card .body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--ink-3); }
.kpi .value { font-size: 26px; font-weight: 650; font-family: var(--mono); letter-spacing: -.5px; }
.kpi .sub { font-size: 12px; color: var(--ink-2); }
.kpi.crit { border-color: var(--crit); background: linear-gradient(0deg, var(--crit-soft), var(--panel) 70%); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-3); } .small { font-size: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn.primary { background: var(--nav); border-color: var(--nav); color: #fff; }
.btn.brand { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--crit); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 11px; cursor: pointer; font-size: 12px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--nav); color: #fff; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 80px; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--muted-soft); color: var(--ink-2); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.moving, .pill.ok, .pill.online, .pill.available, .pill.resolved { background: var(--ok-soft); color: var(--ok); }
.pill.idling, .pill.info, .pill.acknowledged, .pill.uploading { background: var(--info-soft); color: var(--info); }
.pill.parked, .pill.no_data, .pill.expired { background: var(--muted-soft); color: var(--ink-3); }
.pill.stale, .pill.warning, .pill.attention, .pill.on_device { background: var(--warn-soft); color: var(--warn); }
.pill.offline, .pill.critical, .pill.open { background: var(--crit-soft); color: var(--crit); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }

table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; position: sticky; top: 0; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow: auto; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li.click { cursor: pointer; } .list li.click:hover { background: var(--panel-2); }
.note { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); color: var(--ink-2); font-size: 12.5px; }
.note.warn { background: var(--warn-soft); }
.sev-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--ink-3); flex: none; }
.sev-bar.critical { background: var(--crit); } .sev-bar.warning { background: var(--warn); } .sev-bar.info { background: var(--info); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--ink-3); font-family: var(--mono); }

/* ---------- reefer tiles ---------- */
.reefer-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.reefer-tile { padding: 12px 14px; cursor: pointer; border-left: 4px solid var(--ok); }
.reefer-tile.warning { border-left-color: var(--warn); } .reefer-tile.critical { border-left-color: var(--crit); } .reefer-tile.no_data { border-left-color: var(--ink-3); }
.reefer-tile .unit { font-weight: 700; font-size: 15px; }
.reefer-tile .temps { display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap; }
.reefer-tile .temp { font-family: var(--mono); font-size: 20px; font-weight: 650; }
.reefer-tile .temp.out { color: var(--crit); }
.reefer-tile .lbl { font-size: 11px; color: var(--ink-3); }
.mini-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-strip a { display: inline-flex; gap: 6px; align-items: center; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font-size: 12px; }

/* ---------- map & chart ---------- */
.map-wrap { position: relative; }
.map-svg { display: block; width: 100%; height: auto; background: var(--map-land); border-radius: 0 0 var(--radius) var(--radius); }
.map-svg .grid line { stroke: var(--map-grid); stroke-width: 1; }
.map-svg .fence { fill: rgba(42,156,176,.10); stroke: var(--cold); stroke-width: 1; stroke-dasharray: 3 3; }
.map-svg .fence-label { font-size: 10px; fill: var(--ink-3); }
.map-svg .route { fill: none; stroke: var(--map-route); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; opacity: .75; }
.map-svg .route.late { stroke: var(--warn); stroke-dasharray: 4 3; opacity: 1; }
.map-svg .veh { cursor: pointer; }
.map-svg .veh text { font-size: 10.5px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: var(--map-land); stroke-width: 3px; }
.map-svg .ev { stroke: #fff; stroke-width: 1.5; }
.map-badge { position: absolute; left: 10px; bottom: 10px; font-size: 11px; background: var(--panel); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; color: var(--ink-2); max-width: 70%; }
.map-legend { position: absolute; right: 10px; top: 10px; display: flex; gap: 8px; font-size: 11px; background: var(--panel); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }
.dot.moving { background: var(--moving); } .dot.idling { background: var(--idling); } .dot.parked { background: var(--parked); } .dot.stale { background: var(--stale); } .dot.offline { background: var(--offline); }
.chart { width: 100%; height: auto; display: block; }
.chart .axis text { font-size: 10.5px; fill: var(--ink-3); font-family: var(--mono); }
.chart .axis line, .chart .gridline { stroke: var(--line); }
.chart .band { fill: var(--ok); opacity: .07; }
.chart .limit { stroke: var(--crit); stroke-dasharray: 4 3; stroke-width: 1; opacity: .7; }
.chart .exc { fill: var(--crit); opacity: .09; }
.chart .series { fill: none; stroke-width: 1.8; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; opacity: .5; }
.chart .marker { stroke: var(--panel); stroke-width: 1.5; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); padding: 0 16px 10px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.tooltip { position: fixed; pointer-events: none; z-index: 50; background: var(--nav); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; font-family: var(--mono); }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 4px 0; position: relative; }
.timeline li { display: grid; grid-template-columns: 74px 22px 1fr; gap: 8px; padding: 7px 16px; align-items: start; }
.timeline li.active { background: var(--info-soft); }
.timeline li.click { cursor: pointer; }
.timeline .time { font-family: var(--mono); font-size: 12px; color: var(--ink-2); text-align: right; padding-top: 1px; }
.timeline .icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--muted-soft); color: var(--ink-2); }
.timeline .icon svg { width: 13px; height: 13px; }
.timeline .icon.gps { background: var(--info-soft); color: var(--info); }
.timeline .icon.camera { background: var(--warn-soft); color: var(--warn); }
.timeline .icon.reefer, .timeline .icon.reefer_reading { background: var(--cold-soft); color: var(--cold); }
.timeline .icon.reefer.critical, .timeline .icon.reefer.warning { background: var(--crit-soft); color: var(--crit); }
.timeline .icon.data { background: var(--muted-soft); color: var(--ink-3); }
.timeline .icon.ack { background: var(--ok-soft); color: var(--ok); }
.timeline .title { font-size: 13px; }
.timeline .meta { font-size: 11.5px; color: var(--ink-3); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.chip { border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--nav); color: #fff; border-color: var(--nav); }
.playback { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }
.playback input[type=range] { flex: 1; accent-color: var(--brand); }
.playback .clock { font-family: var(--mono); font-size: 12px; min-width: 170px; text-align: right; }

/* ---------- login & modal ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% 0%, #1d3646, var(--nav)); }
.login .card { width: 100%; max-width: 380px; padding: 26px; }
.login h1 { margin: 10px 0 4px; font-size: 20px; }
.login form { display: grid; gap: 12px; margin-top: 16px; }
.login .err { color: var(--crit); font-size: 13px; min-height: 18px; }
.modal-back { position: fixed; inset: 0; background: rgba(10,18,23,.55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; }
.modal.narrow { max-width: 460px; }
.clip-frame { width: 100%; border-radius: 8px; background: #000; display: block; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 70; }
#toast div { background: var(--nav); color: #fff; padding: 9px 14px; border-radius: 8px; margin-top: 6px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--crit); }

@media print {
  .nav, .topbar, .no-print, .btn { display: none !important; }
  .shell { display: block; } .content { padding: 0; } .card { border: 0; box-shadow: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .18s ease; }
  .shell.nav-open .nav { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; } .content { padding: 14px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar .who { display: none; }
  .hide-sm { display: none; }
  .timeline li { grid-template-columns: 58px 22px 1fr; padding: 7px 10px; }
  .playback .clock { min-width: 0; }
}

/* ---------- street map (OpenStreetMap tiles + SVG overlay) ---------- */
.smap { position: relative; overflow: hidden; background: var(--map-land); touch-action: none; cursor: grab; user-select: none; border-radius: 0 0 var(--radius) var(--radius); }
.smap.dragging { cursor: grabbing; }
.smap-tiles { position: absolute; inset: 0; z-index: 0; }
.smap-tile { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; pointer-events: none; }
.smap-tile-err { visibility: hidden; }
.smap-overlay { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: visible; }
.smap-overlay .fence { fill: rgba(42,156,176,.14); stroke: var(--cold); stroke-width: 1.5; stroke-dasharray: 4 3; }
.smap-overlay .fence-label { font-size: 11px; font-weight: 600; fill: #1d3646; paint-order: stroke; stroke: rgba(255,255,255,.9); stroke-width: 3px; }
.smap-overlay .route-casing { fill: none; stroke: #ffffff; stroke-width: 7; stroke-linejoin: round; stroke-linecap: round; opacity: .9; }
.smap-overlay .route { fill: none; stroke: #1f6fd1; stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; }
.smap-overlay .route.late { stroke: var(--warn); stroke-dasharray: 6 4; }
.smap-overlay .ev { stroke: #fff; stroke-width: 2; }
.smap-overlay .veh { pointer-events: auto; cursor: pointer; }
.smap-overlay .veh-tag { fill: #ffffff; stroke: rgba(18,35,46,.25); }
.smap-overlay .veh-label text { font: 700 11px var(--sans); fill: #15212a; }
.smap-zoom { position: absolute; left: 10px; top: 10px; z-index: 2; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.smap-zoom button { width: 32px; height: 32px; border: 0; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--ink); font-size: 18px; line-height: 1; cursor: pointer; }
.smap-zoom button:last-child { border-bottom: 0; font-size: 15px; }
.smap-zoom button:hover:not([disabled]) { background: var(--panel-2); }
.smap-zoom button[disabled] { opacity: .4; cursor: default; }
.smap-attr { position: absolute; right: 0; bottom: 0; z-index: 2; font-size: 10.5px; background: rgba(255,255,255,.85); color: #333; padding: 2px 6px; border-top-left-radius: 6px; }
.smap-attr a { color: #1f5fa8; }
.smap-notice { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); max-width: calc(100% - 100px); z-index: 2; background: var(--panel); border: 1px solid var(--line-2); padding: 8px 12px; border-radius: 8px; font-size: 12.5px; color: var(--ink-2); }
.map-wrap .map-legend, .map-wrap .map-badge { z-index: 3; }
.map-wrap .map-badge { bottom: 26px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .smap-tile { filter: brightness(.72) contrast(1.1) saturate(.75); } }
:root[data-theme="dark"] .smap-tile { filter: brightness(.72) contrast(1.1) saturate(.75); }
@media (max-width: 860px) { .smap { max-height: 60vh; } }
