:root {
  /* Night theme: always dark, neon curb colors (matches the map). */
  color-scheme: dark;
  --good: #22e584;
  --meter: #38bdf8;
  --short: #fbbf24;
  --no: #ff4d6d;
  --cam: #8b5cf6;
  --bg: #0f1420;
  --fg: #e6ebf5;
  --muted: #8e9ab3;
  --line: #222b3b;
  --glass: rgba(15, 20, 32, 0.82);
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.18);
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg); }
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; }

.bar {
  position: fixed; left: 12px; right: 12px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px;
}
.bar.top { top: calc(env(safe-area-inset-top) + 10px); }
.bar.bottom { bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 10px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--good); color: #fff; display: grid; place-items: center; font-weight: 800; }
.tag { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
.status { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); font-weight: 700; flex: none; }

.legend {
  position: fixed; z-index: 4; left: 12px; top: calc(env(safe-area-inset-top) + 66px);
  display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); max-width: calc(100% - 24px);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 16px; height: 5px; border-radius: 3px; display: inline-block; }
.legend .cam-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cam); }

.plan { flex: 1; text-align: left; background: none; border: 0; display: flex; flex-direction: column; line-height: 1.25; padding: 2px 6px; }
.plan span { font-size: 13px; color: var(--muted); }
.primary { background: var(--good); color: #05210f; border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; }
.secondary { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-weight: 600; }

/* Panel: bottom sheet on phones, side panel on tablets/laptops */
.panel {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; max-height: 72vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  -webkit-overflow-scrolling: touch;
}
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.close { position: absolute; top: 12px; right: 14px; }
@media (min-width: 820px) {
  .panel { left: auto; top: 12px; right: 12px; bottom: 12px; width: 400px; max-height: none; border-radius: var(--radius); padding: 18px; }
  .grip { display: none; }
  .bar.bottom { right: auto; width: 420px; }
  .bar.top { right: auto; width: 520px; }
}

.panel h2 { font-size: 20px; margin: 4px 40px 2px 0; }
.panel h3 { font-size: 15px; margin: 18px 0 8px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.verdict { border-radius: 14px; padding: 12px 14px; border: 1px solid var(--line); }
.verdict .big { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.verdict p { margin: 6px 0 0; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.timeline { display: flex; height: 20px; border-radius: 6px; overflow: hidden; }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.sign { padding: 8px 0; border-top: 1px solid var(--line); }
.sign b { display: block; font-size: 14px; }
.sign small { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.row .bar-color { width: 6px; align-self: stretch; border-radius: 3px; flex: none; }
.row small { color: var(--muted); display: block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions a { text-decoration: none; }
.note { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.45; }

.cam-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 352 / 240; }
.cam-wrap canvas { width: 100%; height: 100%; display: block; }
.live { position: absolute; left: 8px; bottom: 8px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.6); color: #fff; border-radius: 999px; padding: 3px 8px; }
.stats { display: flex; gap: 18px; margin: 12px 0 4px; }
.stats div b { display: block; font-size: 22px; }
.stats div span { font-size: 12px; color: var(--muted); }
.key { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.key i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

form.plan-form label { display: block; margin: 12px 0 6px; font-weight: 600; font-size: 14px; }
form.plan-form select, form.plan-form input { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: inherit; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 10px; border: 0; background: var(--bg); }
.seg button.on { background: var(--good); color: #fff; font-weight: 700; }

/* Camera markers */
.cam-pin { width: 30px; height: 30px; border-radius: 50%; background: var(--cam); border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); display: grid; place-items: center; position: relative; padding: 0; }
.cam-pin svg { width: 15px; height: 15px; fill: #fff; }
.cam-pin .badge { position: absolute; top: -8px; right: -10px; min-width: 18px; height: 18px; border-radius: 9px; font-size: 11px; font-weight: 800; color: #fff; display: grid; place-items: center; padding: 0 4px; border: 1.5px solid #fff; }
.cam-pin.watching { outline: 3px solid rgba(109, 40, 217, .35); }

.maplibregl-ctrl-top-right { top: calc(env(safe-area-inset-top) + 64px); }
@media (max-width: 819px) { .maplibregl-ctrl-top-right { top: calc(env(safe-area-inset-top) + 104px); } }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: calc(env(safe-area-inset-bottom) + 80px); }

@media (max-width: 480px) {
  .brand .name, .brand .tag { display: none; }
  .status { font-size: 12px; }
}

.legend-note { flex-basis: 100%; color: var(--muted); font-size: 11px; }
.caveat { font-size: 13px; color: var(--muted); background: var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 10px; }
