/* Bay Bridge Watch — mobile-first, one-handed use */
:root {
  --navy: #0b2545; --navy2: #13315c; --bg: #f4f6fa; --card: #ffffff;
  --text: #17233b; --muted: #5b6b85; --accent: #f4a418; --ok: #1a7f4e;
  --warn: #c0392b; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(24px + var(--safe-b));
}
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--navy); color: #fff;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { font-size: 26px; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.status-strip { font-size: 12.5px; color: #c9d6ea; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.status-strip .warn { color: #ffb3a7; font-weight: 600; }
.status-link { color: var(--accent); text-decoration: none; font-weight: 600; white-space: nowrap; }
.refresh-box { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.refresh-btn {
  background: var(--navy2); border: 1px solid #2a4a7f; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  cursor: pointer;
}
.refresh-btn:active { transform: rotate(90deg); }
.countdown {
  font-variant-numeric: tabular-nums; font-size: 13px; color: #c9d6ea;
  min-width: 2ch; text-align: center;
}

/* Quick actions */
.quick-actions {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 12px 12px 0;
}
.qa {
  background: var(--card); border-radius: var(--radius); text-decoration: none;
  color: var(--text); text-align: center; padding: 10px 6px; font-weight: 700; font-size: 14px;
  box-shadow: 0 1px 3px rgba(11,37,69,.08);
}
.qa span { display: block; font-weight: 500; font-size: 12px; color: var(--muted); margin-top: 2px; }
.qa-call { border: 1.5px solid var(--accent); }

/* Fake-door card */
.alerts-card {
  margin: 12px; padding: 14px; border-radius: var(--radius); cursor: pointer;
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy2) 100%);
  color: #fff; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 8px rgba(11,37,69,.25);
}
.alerts-card-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.alerts-card-text strong { font-size: 15.5px; }
.alerts-card-text span { font-size: 13px; color: #c9d6ea; }
.alerts-chev { margin-left: auto; font-size: 26px; color: var(--accent); }

/* Zones & camera grid */
.zone { padding: 6px 12px 0; }
.zone h2 { font-size: 15px; margin: 12px 2px 2px; }
.zone .zone-sub { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }
.cam-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 640px) { .cam-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .cam-grid { grid-template-columns: repeat(4, 1fr); } main { max-width: 1100px; margin: 0 auto; } }

.cam {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(11,37,69,.08); cursor: pointer; border: 0; padding: 0;
  text-align: left; display: block; width: 100%;
}
.cam-imgwrap { position: relative; aspect-ratio: 4/3; background: #dde5f0; }
.cam-imgwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-live-badge {
  position: absolute; right: 6px; top: 6px; background: rgba(11,37,69,.75); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 20px;
}
.cam-live-badge::before { content: '▶ '; color: var(--accent); }
.cam-offline {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(23,35,59,.55); color: #fff; font-weight: 700; font-size: 13px;
}
.cam-meta { padding: 8px 10px 9px; }
.cam-name { font-size: 13.5px; font-weight: 700; line-height: 1.25; }
.cam-dir { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.freshness-note { font-size: 12.5px; color: var(--muted); margin: 14px; text-align: center; }
.footer { font-size: 11.5px; color: var(--muted); text-align: center; margin: 18px 14px 8px; }
.footer a { color: var(--muted); }

/* Viewer */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column;
}
.viewer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; color: #fff; background: #0b2545;
}
.viewer-title { font-weight: 700; font-size: 15px; }
.viewer-sub { font-size: 12px; color: #c9d6ea; }
.viewer-body { flex: 1; display: grid; place-items: center; position: relative; min-height: 0; }
.viewer-body video, .viewer-body img { max-width: 100%; max-height: 100%; width: 100%; }
.viewer-msg { position: absolute; color: #fff; background: rgba(11,37,69,.85); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 85%; text-align: center; }
.viewer-foot { color: #8fa3c0; font-size: 11px; text-align: center; padding: 8px 8px calc(10px + var(--safe-b)); background: #06162e; }
.close-btn {
  background: rgba(255,255,255,.12); border: 0; color: #fff; width: 40px; height: 40px;
  border-radius: 50%; font-size: 17px; cursor: pointer; flex-shrink: 0;
}

/* Fake-door sheet */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(11,37,69,.55); display: grid; place-items: end center; }
.sheet-card {
  background: #fff; border-radius: 20px 20px 0 0; padding: 22px 20px calc(26px + var(--safe-b));
  width: 100%; max-width: 560px; position: relative;
}
.sheet-close { position: absolute; right: 12px; top: 12px; background: #eef1f7; color: var(--text); }
.sheet-card h2 { margin: 2px 0 4px; font-size: 20px; }
.sheet-lead { font-weight: 700; color: var(--navy); margin: 4px 0; }
.sheet-card p { margin: 8px 0; font-size: 14.5px; }
.sheet-fine { font-size: 12px; color: var(--muted); }
#fd-form label { font-size: 13.5px; font-weight: 600; display: block; margin: 14px 0 6px; }
#fd-email {
  width: 100%; padding: 12px; border: 1.5px solid #c6d0e0; border-radius: 10px; font-size: 16px;
}
#fd-submit {
  margin-top: 10px; width: 100%; padding: 13px; border: 0; border-radius: 10px;
  background: var(--navy); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}
#fd-submit:disabled { opacity: .6; }

/* Install hint */
.install-hint {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--safe-b)); z-index: 40;
  background: var(--card); border-radius: 12px; box-shadow: 0 4px 18px rgba(11,37,69,.25);
  padding: 12px 14px; display: flex; align-items: center; gap: 10px; font-size: 13.5px;
}
.install-hint button {
  border: 0; border-radius: 8px; padding: 8px 12px; font-weight: 700; cursor: pointer;
}
#install-btn { background: var(--navy); color: #fff; }
#install-dismiss { background: #eef1f7; color: var(--muted); margin-left: auto; }

/* ===== v2: tab bar, map, chips, notices, snapshot ages ===== */
.has-tabbar { padding-bottom: calc(64px + var(--safe-b)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  background: var(--navy); display: flex;
  padding-bottom: var(--safe-b); box-shadow: 0 -2px 10px rgba(11,37,69,.3);
}
.tab {
  flex: 1; text-align: center; color: #8fa3c0; text-decoration: none;
  font-size: 20px; padding: 8px 0 6px; line-height: 1.1;
}
.tab span { display: block; font-size: 11px; font-weight: 600; margin-top: 1px; }
.tab.active { color: var(--accent); }

.dir-chips {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 12px 0;
}
.chip {
  background: var(--card); border-radius: 12px; padding: 8px 10px;
  box-shadow: 0 1px 3px rgba(11,37,69,.08); display: flex; flex-direction: column; gap: 1px;
}
.chip-dir { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.chip-spd { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chip-sub { font-size: 11px; color: var(--muted); }

.map-section { margin: 12px; }
.map-wrap {
  position: relative; border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 4px rgba(11,37,69,.15); background: #cfe0ee;
}
.map-wrap img { display: block; width: 100%; height: auto; }
#map-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-pin, .inc-pin { cursor: pointer; }
.cam-pin:hover rect, .cam-pin:focus rect { fill: #f4a418; }
.map-legend {
  display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted);
  padding: 8px 4px 0;
}
.map-legend .lg { display: inline-block; width: 14px; height: 5px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
.lg-g { background: #1a9850; } .lg-y { background: #e6b112; }
.lg-o { background: #f46d43; } .lg-r { background: #d73027; } .lg-n { background: #9aa7b8; }
.map-note { font-size: 11.5px; color: var(--muted); margin: 6px 4px 0; }

.notices-section { margin: 16px 12px 4px; }
.sec-h { font-size: 15px; margin: 0 2px 8px; }
.notice {
  background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(11,37,69,.08); font-size: 13.5px;
  display: flex; flex-direction: column; gap: 3px;
}
.notice-ok { color: var(--ok); font-weight: 600; }
.notice-kind {
  align-self: flex-start; font-size: 10.5px; font-weight: 800; letter-spacing: .5px;
  color: #fff; background: var(--warn); border-radius: 20px; padding: 2px 8px; text-transform: uppercase;
}
.notice-lanes { font-size: 12px; color: var(--warn); font-weight: 600; }

.snap-age {
  position: absolute; left: 6px; bottom: 6px; background: rgba(11,37,69,.75); color: #fff;
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 20px;
}
.snap-age.snap-stale { background: rgba(192,57,43,.85); }
.has-tabbar .install-hint { bottom: calc(66px + var(--safe-b)); }
/* map: pannable on narrow screens, touch-sized pins */
.map-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.map-scroll::-webkit-scrollbar { display: none; }
.map-hint { font-size: 11px; color: var(--muted); text-align: center; margin: 4px 0 0; }
@media (min-width: 801px) { .map-hint { display: none; } }
/* zoom control */
.map-frame { position: relative; }
.zoom-ctl {
  position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 5;
}
.zoom-ctl button {
  width: 38px; height: 38px; border-radius: 10px; border: 0; cursor: pointer;
  background: rgba(11,37,69,.85); color: #fff; font-size: 19px; font-weight: 700;
  box-shadow: 0 1px 4px rgba(11,37,69,.3);
}
.zoom-ctl button:disabled { opacity: .35; cursor: default; }
.map-inner { width: 100%; }
.trends-section { margin: 16px 12px 4px; }
.trend-route { font-weight: 700; font-size: 13.5px; }
.trend-txt { color: var(--muted); font-size: 13px; }
/* camera tap hint (first visit only) */
.cam-hint {
  position: absolute; left: 8px; bottom: 8px; z-index: 6;
  background: rgba(11,37,69,.92); color: #fff; border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 2px 10px rgba(11,37,69,.4); max-width: 78%;
}
.cam-hint button {
  background: rgba(255,255,255,.15); border: 0; color: #fff; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; flex-shrink: 0; font-size: 12px;
}
/* viewer back button */
.back-btn {
  background: rgba(255,255,255,.12); border: 0; color: #fff; cursor: pointer;
  border-radius: 20px; padding: 9px 14px 9px 10px; font-size: 15px; font-weight: 700;
  flex-shrink: 0;
}
.viewer-head-text { min-width: 0; flex: 1; }
/* map pan arrows (zoomed only) */
.pan-btn {
  position: absolute; top: 62%; transform: translateY(-50%); z-index: 5;
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(11,37,69,.78); color: #fff; font-size: 24px; font-weight: 700;
  line-height: 1; box-shadow: 0 1px 5px rgba(11,37,69,.35);
}
.pan-btn:active { background: rgba(11,37,69,.95); }
.pan-l { left: 8px; }
.pan-r { right: 8px; }
/* dead-stream tile badge */
.cam-live-badge.badge-snap { background: rgba(91,107,133,.85); }
.cam-live-badge.badge-snap::before { content: ''; }
/* typical-traffic chart (Concept B) */
.trends-section .tdays { display: flex; gap: 5px; margin-bottom: 8px; }
.tday { flex: 1; text-align: center; font-size: 11.5px; font-weight: 700; padding: 7px 0;
  border-radius: 9px; background: #eef1f7; color: var(--muted); border: 0; cursor: pointer; }
.tday.on { background: var(--navy); color: #fff; }
.ttoggle { display: flex; gap: 6px; margin-bottom: 10px; }
.tdir { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 16px;
  background: #eef1f7; color: var(--muted); border: 0; cursor: pointer; }
.tdir.on { background: var(--navy); color: #fff; }
.tbars { display: flex; align-items: flex-end; gap: 2px; height: 92px;
  border-bottom: 1px solid #e2e8f2; background: var(--card); border-radius: 10px 10px 0 0; padding: 6px 6px 0; }
.tbar { flex: 1; border-radius: 2px 2px 0 0; cursor: pointer; min-height: 4px; }
.tbar-na { height: 4px; background: #d4dbe6; }
.tax { position: relative; height: 15px; font-size: 9.5px; color: var(--muted);
  margin: 3px 6px 0; }
.tax span { position: absolute; top: 0; transform: translateX(-50%); }
.twin { font-size: 13px; margin: 8px 2px 2px; }
.twin strong { color: var(--warn); }
.treadout { font-size: 12px; color: var(--muted); margin: 2px 2px 0; min-height: 15px; }
