/* Camera Map -- Washington, DC preview.
 *
 * Every rule lives in this file, and that is not a style preference. The site
 * this app is hosted on serves `style-src 'self'` with no 'unsafe-inline', so
 * a `style="..."` attribute on an element is DROPPED by the browser with a
 * console warning and nothing else -- the page renders, subtly wrong, and
 * looks fine under a local server that sends no policy. Anything genuinely
 * dynamic is set from JavaScript as a property (el.style.width = ...), which
 * is CSSOM and exempt.
 *
 * Colours are the desktop app's, so the two look like the same tool.
 */

:root {
  --bg:        #0f1218;
  --panel:     #161b23;
  --panel-2:   #1b1f27;
  --line:      #2c3542;
  --ink:       #e6ecf5;
  --muted:     #8b95a5;
  --accent:    #2f6fdb;
  --live:      #2ecc71;   /* live video a browser opens directly       */
  --still:     #95a5a6;   /* still picture, refreshed on a timer       */
  --rtsp:      #f5a623;   /* an RTSP camera -- what the app is for     */
  --dead:      #e74c3c;   /* nothing a browser can show at all         */
}

* { box-sizing: border-box; }

/* `hidden` is only a `display: none` in the UA sheet, and the .panel rule
   below sets `display` and would beat it on specificity. Without this the
   side panel is on screen from first paint. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: #7fb0ff; }

/* ---------- header ---------------------------------------------------- */

.topbar {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
}
.topbar img { flex: none; margin-top: 2px; }
.topbar h1 { margin: 0 0 4px; font-size: 20px; font-weight: 650; }
.topbar h1 .tag {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: #0f1218; background: var(--rtsp);
  padding: 2px 7px; border-radius: 4px; vertical-align: 3px; font-weight: 700;
}
.topbar p { margin: 0; color: var(--muted); font-size: 13px; max-width: 78ch; }

button, .srclink {
  font: inherit; cursor: pointer; border-radius: 6px;
  border: 1px solid var(--line); padding: 7px 13px;
}
.iconbtn {
  background: none; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 2px 8px;
}
.iconbtn:hover { color: var(--ink); }

.notice {
  margin: 0; padding: 11px 20px; font-size: 13px;
  background: #1d1a12; color: #e8d6ae; border-bottom: 1px solid #3a3020;
}
.notice strong { color: #ffd489; }

/* ---------- the legend -------------------------------------------------
 *
 * This is the one thing on the page that has to land in about two seconds,
 * because the split it describes -- four cameras in five are RTSP -- is the
 * argument for the desktop app. So each entry carries the marker shape the
 * map actually draws, at the size the map draws it, not a coloured dot that
 * the eye then has to match up to something different.
 */
.status {
  margin: 0; padding: 10px 20px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
}
.status .lede { color: var(--ink); font-weight: 600; }
.key { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.key b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }
.key svg { display: block; flex: none; }
.key .why { color: var(--muted); }

/* ---------- map + panel ----------------------------------------------- */

.stage { position: relative; display: flex; }
#map {
  flex: 1; height: 70vh; min-height: 420px;
  background: #10141b; z-index: 1;
}
.leaflet-container { background: #10141b; font: inherit; }
.leaflet-bar a, .leaflet-control-attribution { color: #222; }

/* divIcon wrappers get a white box by default -- strip it so only the camera
   SVG shows, and let clicks fall through the view cone's empty area. */
.cam-marker { background: none; border: none; }
.cam-marker svg { overflow: visible; display: block; }
/* A cluster bubble sits above the loose markers around it, so its count is
   never half-hidden behind a camera at the edge of the cell. */
.cam-cluster { background: none; border: none; cursor: zoom-in; z-index: 600; }
.cam-cluster svg { display: block; }
.tip-dim { opacity: .7; }

.panel {
  width: 380px; flex: none; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
}
.panel-head { display: flex; align-items: flex-start; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 620; flex: 1; line-height: 1.4; }
.kindline { margin: 0; font-size: 12px; color: var(--muted); }
.kindline .dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.kindline .dot.live  { background: var(--live); }
.kindline .dot.still { background: var(--still); }
.kindline .dot.rtsp  { background: var(--rtsp); }
.kindline .dot.dead  { background: var(--dead); }

/* Fixed 16:9 box whatever arrives, so the panel does not jump size when the
   picture loads and move the link out from under a finger already on its way
   down.

   Both frames of a still camera and the video sit stacked and absolutely
   positioned, hidden until they have something to show. That is what makes
   the refresh flicker-free: the new JPEG loads underneath and the old one is
   only taken away once it has. */
.view {
  position: relative; overflow: hidden; background: #05070a;
  display: flex; align-items: center; justify-content: center;
  width: 100%; aspect-ratio: 16 / 9;
  border: 1px solid var(--line); border-radius: 6px;
}
.frame, .view video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; display: block; background: #05070a;
  opacity: 0; transition: opacity .12s linear;
}
.frame.on, .view video.on { opacity: 1; }
.msg {
  position: relative; z-index: 2;
  margin: 0; font-size: 12px; color: var(--muted); text-align: center;
  padding: 0 16px; line-height: 1.5;
}
.msg strong { color: #d9e2ee; display: block; margin-bottom: 5px; }
.age { margin: 0; font-size: 11.5px; color: var(--muted); min-height: 1.2em; }
.note { margin: 0; font-size: 12.5px; color: #aab4c2; }
.panel-actions { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 6px; }
.srclink {
  background: var(--panel-2); color: var(--ink); text-decoration: none;
  font-size: 13px; display: inline-block;
}
.srclink:hover { border-color: #3f4b5e; }

/* The RTSP address, shown as text because it is the one thing on the page a
   browser cannot follow. Wrapping matters: these run past 60 characters and
   an overflowing URL pushes the panel sideways. */
.rtspaddr {
  margin: 0; font: 11.5px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: #c8d2e0; background: #0d1117; border: 1px solid var(--line);
  border-radius: 4px; padding: 6px 8px; overflow-wrap: anywhere;
}

/* ---------- the honest bit -------------------------------------------- */

.about {
  padding: 22px 20px 40px; border-top: 1px solid var(--line);
  background: var(--panel);
}
.about h2 { margin: 0 0 12px; font-size: 15px; font-weight: 620; }
.about p { margin: 0 0 13px; max-width: 82ch; font-size: 13.5px; color: #c3ccda; }
.about strong { color: var(--ink); }
.about .getit { color: var(--ink); }
.about .credit { color: var(--muted); font-size: 12px; }

/* ---------- narrow screens -------------------------------------------- */

@media (max-width: 860px) {
  .stage { flex-direction: column; }
  #map { height: 56vh; min-height: 320px; }
  .panel { width: auto; border-left: none; border-top: 1px solid var(--line); }
  .panel-actions { margin-top: 8px; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 14px 11px; }
  .notice, .status, .about { padding-left: 14px; padding-right: 14px; }
  /* The legend is three lines on a phone rather than a wrapped run-on. */
  .status { flex-direction: column; align-items: flex-start; gap: 7px; }
}
