/* LamboMap console. Dark first (an operations screen), with a light theme for bright rooms. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --surface-3: #ecebe7;
  --line: #dcdbd5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #c98500;
  --accent-ink: #0b0b0b;
  --grid: #e6e5e0;
  --t-police: #2a78d6;
  --t-traffic: #eb6834;
  --t-weather: #1baf7a;
  --t-hazard: #eda100;
  --t-closure: #e87ba4;
  --t-camera: #6250d6;
  --t-accident: #e34948;
  --driver: #0b0b0b;
  --good: #0ca30c;
  --critical: #d03b3b;
  --shadow: 0 6px 24px rgba(0,0,0,.12);
  --glass: rgba(252,252,251,.88);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0e11;
    --surface-1: #15171b;
    --surface-2: #1b1d22;
    --surface-3: #24272d;
    --line: #2c2f36;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c85;
    --accent: #f5b400;
    --accent-ink: #14161b;
    --grid: #262930;
    --t-police: #3987e5;
    --t-traffic: #d95926;
    --t-weather: #199e70;
    --t-hazard: #c98500;
    --t-closure: #d55181;
    --t-camera: #9085e9;
    --t-accident: #e66767;
    --driver: #f0efec;
    --shadow: 0 8px 30px rgba(0,0,0,.45);
    --glass: rgba(21,23,27,.86);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e11; --surface-1: #15171b; --surface-2: #1b1d22; --surface-3: #24272d; --line: #2c2f36;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c85; --accent: #f5b400; --accent-ink: #14161b;
  --grid: #262930; --t-police: #3987e5; --t-traffic: #d95926; --t-weather: #199e70; --t-hazard: #c98500;
  --t-closure: #d55181; --t-camera: #9085e9; --t-accident: #e66767; --driver: #f0efec;
  --shadow: 0 8px 30px rgba(0,0,0,.45); --glass: rgba(21,23,27,.86);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); }
h3 { font-size: 13px; margin: 0 0 12px; color: var(--text-secondary); font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error { color: var(--critical); min-height: 1.2em; margin: 0; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Brand */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-lg { font-size: 24px; }
.brand-mark { width: 24px; height: 24px; display: inline-block; background: url("/favicon.svg") center/contain no-repeat; }
.brand-lg .brand-mark { width: 32px; height: 32px; }

/* Buttons and controls */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-primary);
  border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-3); }
.btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--critical); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-size: 12px;
  font-weight: 600; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
.check input { accent-color: var(--accent); }

/* Sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 70% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface-1); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.login-card input {
  font: inherit; font-size: 15px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-primary);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login-card .btn { padding: 11px; margin-top: 4px; }

/* App frame */
.app { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 16px; background: var(--surface-1);
  border-bottom: 1px solid var(--line); z-index: 1000;
}
.tabs { display: flex; gap: 4px; }
.tabs button {
  appearance: none; border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-weight: 600;
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button:hover { color: var(--text-primary); background: var(--surface-3); }
.tabs button[aria-selected="true"] { color: var(--text-primary); background: var(--surface-3); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.live-state { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.live-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.live-state[data-state="live"] i { background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); animation: pulse 2s infinite; }
.live-state[data-state="offline"] i { background: var(--critical); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .live-state i { animation: none !important; } }

.tab { min-height: 0; }
.tab-scroll { overflow: auto; }

/* Live map */
.tab-live { position: relative; display: grid; grid-template-columns: 1fr 320px; }
.map { position: relative; height: 100%; min-height: 300px; background: var(--surface-3); }
.leaflet-container { font: inherit; background: var(--surface-3); }
.kpis {
  position: absolute; top: 14px; left: 14px; z-index: 500; display: flex; gap: 8px; flex-wrap: wrap; max-width: calc(100% - 360px);
}
.kpi {
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; min-width: 104px; display: grid; box-shadow: var(--shadow);
}
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.map-controls {
  position: absolute; left: 14px; bottom: 26px; z-index: 500; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); max-width: calc(100% - 360px);
}
.side { background: var(--surface-1); border-left: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px 8px; }
.feed { list-style: none; margin: 0; padding: 0 8px; overflow: auto; min-height: 0; }
.feed li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer;
}
.feed li:hover { background: var(--surface-3); }
.feed li.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
.feed .what { font-weight: 600; font-size: 13px; }
.feed .meta { font-size: 12px; color: var(--text-muted); }
.feed .when { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.feed .empty { display: block; padding: 24px 8px; color: var(--text-muted); cursor: default; }
.feed .empty:hover { background: none; }
.legend { border-top: 1px solid var(--line); padding: 12px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.legend span { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }

/* Type badge: colour plus its own icon, so a type is never told by colour alone. */
.badge {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--c);
  color: #fff; box-shadow: 0 0 0 2px var(--surface-1);
}
.badge svg { width: 16px; height: 16px; }
.badge-sm { width: 20px; height: 20px; }
.badge-sm svg { width: 12px; height: 12px; }
.t-police { --c: var(--t-police); } .t-traffic { --c: var(--t-traffic); } .t-weather { --c: var(--t-weather); }
.t-hazard { --c: var(--t-hazard); } .t-closure { --c: var(--t-closure); } .t-camera { --c: var(--t-camera); }
.t-accident { --c: var(--t-accident); }

.pin { position: relative; }
.pin .badge { width: 30px; height: 30px; box-shadow: 0 0 0 2px var(--surface-1), 0 3px 10px rgba(0,0,0,.35); }
.pin.new .badge { animation: drop .5s cubic-bezier(.2,1.4,.4,1); }
@keyframes drop { from { transform: translateY(-14px) scale(.6); opacity: 0; } }
.pin .count {
  position: absolute; right: -6px; top: -6px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
  background: var(--surface-1); color: var(--text-primary); font-size: 10px; font-weight: 700; display: grid; place-items: center;
  box-shadow: 0 0 0 1px var(--line);
}
.leaflet-div-icon { background: none; border: 0; }

.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.leaflet-popup-content-wrapper { border-radius: 14px; border: 1px solid var(--line); }
.leaflet-popup-content { margin: 14px 16px; min-width: 230px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
.pop-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.pop-head b { display: block; font-size: 15px; }
.pop-head span { font-size: 12px; color: var(--text-muted); }
.pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 12px; margin: 0 0 12px; }
.pop-grid dt { color: var(--text-muted); }
.pop-grid dd { margin: 0; font-variant-numeric: tabular-nums; }
.pop-actions { display: flex; gap: 6px; }
.leaflet-control-attribution { background: var(--glass) !important; color: var(--text-muted); }
.leaflet-control-attribution a { color: var(--text-secondary); }
.leaflet-bar a { background: var(--surface-1); color: var(--text-primary); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-3); }
.leaflet-tooltip.drv { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-tooltip.drv::before { display: none; }

/* Pages */
.page { max-width: 1280px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0; }
.card-flush { padding: 0; overflow: auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.tile .kpi-value { font-size: 28px; display: block; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.chart { position: relative; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .series-label { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.chart .empty { fill: var(--text-muted); font-size: 13px; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin: -4px 0 8px; }
.chart-legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; }
.bars { display: grid; gap: 8px; }
.bars-sep { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.bar-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar-row .track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--c, var(--t-police)); border-radius: 4px; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--text-secondary); min-width: 2.5em; text-align: right; }
.bars .none { color: var(--text-muted); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface-1); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-3); cursor: pointer; }
.table .type { display: flex; align-items: center; gap: 8px; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-secondary); }
.status.active { color: var(--good); }
.status.not_there, .status.admin { color: var(--critical); }

.tooltip {
  position: fixed; z-index: 3000; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); max-width: 260px;
}
.tooltip .tt-time { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row i { width: 10px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; margin-right: 6px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 3000; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; box-shadow: var(--shadow); font-weight: 600; font-size: 13px;
}

@media (max-width: 1000px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .tab-live { grid-template-columns: 1fr; grid-template-rows: 1fr 40%; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .kpis, .map-controls { max-width: calc(100% - 28px); }
  .kpi { min-width: 0; padding: 6px 10px; }
  .kpi-value { font-size: 18px; }
  .topbar { gap: 10px; flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .brand span:last-child { display: none; }
}
.card-title { padding: 16px 16px 4px; }
.map-dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.45); }
