/* styles.css — unified Feedback app. Two layers:
   1) the dashboard chrome + dashboard views (global), and
   2) the reporter's meter/spectrum styles, SCOPED under `.reporter` so its
      bare-element rules (button/input/h1…) can't leak into the dashboard views.
   Shared colour variables live in one :root below. */

:root {
  --bg: #0e1116;
  --bg-elev: #171c24;
  --bg-elev-2: #1f2630;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --accent: #4aa3ff;
  --ok: #2ea043;
  --warn: #d29922;
  --bad: #f85149;
  --cold: #388bfd;
  --stale: #6e7681;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* reporter aliases */
  --surface: #161b22;
  --surface2: #1f2630;
  --dim: #8b949e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
}

/* --- Connect bar (legacy standalone) --------------------------------------- */
.connect { display: flex; gap: 8px; flex: 1; min-width: 280px; flex-wrap: wrap; }
.connect input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}
#broker-url { flex: 2; min-width: 200px; }
#device-name, #username, #password { flex: 1; min-width: 110px; }

.btn {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04121f; border-color: var(--accent); font-weight: 600; }

/* --- Status pill ----------------------------------------------------------- */
.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  cursor: pointer;
}
/* In the tab strip the pill sits at the right, just before the gear. */
.tabs .status-pill { margin-left: auto; align-self: center; }
.tabs .status-pill:hover { border-color: var(--accent); }
.status-pill[data-status="connected"] { background: rgba(46,160,67,.15); color: var(--ok); border-color: var(--ok); }
.status-pill[data-status="connecting"],
.status-pill[data-status="reconnecting"] { background: rgba(210,153,34,.15); color: var(--warn); border-color: var(--warn); animation: pillPulse 1.2s ease-in-out infinite; }
@keyframes pillPulse { 50% { opacity: .5; } }
.status-pill[data-status="error"],
.status-pill[data-status="offline"] { background: rgba(248,81,73,.15); color: var(--bad); border-color: var(--bad); }
.status-pill[data-status="closed"] { color: var(--text-dim); }

/* --- Tabs ------------------------------------------------------------------ */
/* The tab strip is the very top line now, so pad past the status-bar/notch. */
.tabs { display: flex; align-items: center; gap: 4px; padding: max(8px, env(safe-area-inset-top)) 16px 0; background: var(--bg-elev); border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; border: none; color: var(--text-dim);
  padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 0.92rem;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
/* Settings gear at the far right of the tab strip (the status pill's auto margin
   pushes the pill + gear group over). */
.tab-gear { background: transparent; border: none; color: var(--text-dim); font-size: 18px; line-height: 1; padding: 6px 10px; cursor: pointer; align-self: center; }
.tab-gear:hover { color: var(--accent); }

/* App shell is a fixed, viewport-sized scroll container so the flip below can
   rotate it around the screen centre (rotating <body> pivots around the full
   content height, which scrolls the page off-screen on tall views). */
#app { position: fixed; inset: 0; overflow-y: auto; }

/* Flip the whole UI 180° for phones mounted upside-down (mic at the top). The
   app shell + the (also viewport-sized) settings overlay rotate as whole blocks;
   the toast keeps its horizontal centring and just spins in place. */
body.flip #app,
body.flip .settings-overlay { transform: rotate(180deg); }
body.flip .toast { transform: translateX(-50%) rotate(180deg); }

/* --- Full-screen landscape meter ------------------------------------------
   One tap on the ⛶ in the meter's top-right corner blows the meter card up to
   fill the viewport, rotated 90° into landscape. The phone stays physically in
   portrait — there's no Orientation API here (iOS Safari lacks it), so instead
   of asking the OS to rotate, the card rotates and the user just turns the
   phone. The card is position:fixed so it lifts out of flow and covers the rest
   of the app; the scroll container behind it is frozen. */
body.meter-fs #app { overflow: hidden; }
/* A flipped app rotates #app 180°, which would become the fixed card's
   containing block and double-transform it — neutralise it in full screen. */
body.meter-fs.flip #app { transform: none; }
body.meter-fs .meter-fs-card {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vh;               /* dims swapped: card width spans the viewport height */
  height: 100vw;
  margin: 0;
  border: 0;
  border-radius: 0;
  z-index: 2000;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  transform-origin: top left;
  transform: translateX(100vw) rotate(90deg);
}
/* Full screen is a pure "look at the meter" view: hide the whole bottom control
   row (start/stop, simple-dBA toggle, flip) and the start hint, then let the
   spectrum grow to fill every pixel that frees up. Reset-peaks stays reachable as
   an overlay on the plot (see .spec-reset-peaks below). */
body.meter-fs .reporter .meter-controls,
body.meter-fs .reporter .hint { display: none; }
body.meter-fs .reporter .spl { font-size: 62px; }
body.meter-fs .reporter .spl .u { font-size: 24px; }
/* Push the avg + Peak/kHz readout further left so the corner ✕ can't cover it. */
body.meter-fs .reporter .meter-right { padding-right: 78px !important; }
/* Stretch the spectrum to fill the card instead of centring it. */
body.meter-fs .meter-fs-card { justify-content: flex-start; gap: 10px; padding: 12px 16px; }
body.meter-fs .reporter .spectrum { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
body.meter-fs .reporter .spectrum-wrap { flex: 1 1 auto; min-height: 0; }
body.meter-fs .reporter .plot-col { display: flex; flex-direction: column; min-height: 0; }
body.meter-fs .reporter .plot { flex: 1 1 auto; height: auto; min-height: 0; }
body.meter-fs .reporter .axis { height: auto; }
/* If the meter-settings overlay is opened from full screen (via the on-plot ⚙),
   rotate it into landscape too so it reads correctly while the phone is turned. */
body.meter-fs .settings-overlay {
  width: 100vh;
  height: 100vw;
  transform-origin: top left;
  transform: translateX(100vw) rotate(90deg);
}

/* --- View area ------------------------------------------------------------- */
.view { padding: 16px; }
.hint { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 12px; }

/* --- Raw feed -------------------------------------------------------------- */
.raw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.raw-col { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; max-height: 70vh; }
.raw-col h3 { margin: 0; padding: 8px 12px; font-size: 0.85rem; background: var(--bg-elev-2); border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.raw-col-body { overflow-y: auto; padding: 4px 0; }
.raw-line { display: grid; grid-template-columns: 64px 84px 1fr; gap: 6px; padding: 3px 12px; font-family: var(--mono); font-size: 0.72rem; border-bottom: 1px solid rgba(42,50,61,.4); }
.raw-time { color: var(--stale); }
.raw-topic { color: var(--accent); }
.raw-payload { color: var(--text-dim); word-break: break-all; }

/* --- Floor plan view ------------------------------------------------------- */
.feedback { display: flex; flex-direction: column; gap: 12px; }

.alert-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 42px; padding: 8px 12px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.alert-strip.empty { color: var(--text-dim); }
.alert-title { color: var(--bad); font-weight: 800; }
.alert-chip { border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 0.8rem; background: var(--bg-elev-2); display: inline-flex; align-items: center; gap: 4px; }
.alert-time { color: var(--text-dim); }
.alert-ack { border: none; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 0.85rem; line-height: 1; padding: 2px 4px; border-radius: 50%; }
.alert-ack:hover { color: var(--bad); background: rgba(248,81,73,.15); }
.alert-empty { color: var(--stale); }

.cmp-strip { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 8px 12px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.cmp-strip.empty { color: var(--stale); font-size: 0.85rem; }
.cmp-head { display: flex; flex-direction: column; line-height: 1.2; min-width: 120px; }
.cmp-head strong { font-size: 0.9rem; }
.cmp-meta { color: var(--text-dim); font-size: 0.72rem; font-family: var(--mono); }
.cmp-cells { display: flex; flex-wrap: wrap; gap: 8px; }
.cmp-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 1px solid var(--border); border-radius: 10px; padding: 5px 12px; background: var(--bg-elev-2); }
.cmp-cell.miss { opacity: 0.5; }
.cmp-zone { color: var(--text-dim); font-size: 0.7rem; }
.cmp-val { font-size: 1.15rem; font-weight: 800; line-height: 1; }
.cmp-unit { font-size: 0.7rem; font-weight: 700; }
.cmp-peak { color: var(--text-dim); font-size: 0.72rem; font-family: var(--mono); line-height: 1; }
.cmp-peak-cap { opacity: 0.7; }

.feedback-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.switch { color: var(--text-dim); font-size: 0.85rem; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.metric-ctl { display: flex; align-items: center; gap: 6px; }
.metric-cap { color: var(--text-dim); font-size: 0.85rem; }
.metric-group { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.metric-btn { background: var(--bg-elev); border: none; color: var(--text-dim); padding: 5px 11px; font-size: 0.8rem; cursor: pointer; }
.metric-btn.on { background: rgba(74,163,255,.16); color: var(--accent); }
/* (color legend removed — pin colors are self-explanatory in use) */

/* Desk's own sound meter strip, pinned above the dashboard when enabled. */
.desk-meter {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px; margin-bottom: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
}
.desk-meter .dm-rta-wrap { flex: 1; min-width: 120px; display: flex; flex-direction: column; }
.desk-meter .dm-peak { font-size: 11px; font-weight: 700; color: var(--warn); min-height: 14px; line-height: 14px; text-align: right; }
.desk-meter .dm-rta { width: 100%; height: 52px; display: block; }
.desk-meter.hidden { display: none; }
.desk-meter .dm-cap { color: var(--text-dim); font-size: 0.8rem; }
.desk-meter .dm-val { font-size: 2rem; font-weight: 800; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.desk-meter .dm-unit { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); }
.desk-meter .dm-off { color: var(--stale); font-size: 0.86rem; }

/* Broadcast composer (desk → monitors) */
.msg-btn { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 5px 11px; font-size: 0.82rem; cursor: pointer; }
.msg-btn:hover { border-color: var(--accent); color: var(--accent); }
.msg-composer { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.msg-composer.hidden { display: none; }
.msg-row { display: flex; gap: 8px; align-items: center; }
.msg-input { flex: 1; min-width: 0; background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 0.9rem; }
.msg-send { background: var(--accent); border: none; color: #04210d; font-weight: 800; border-radius: 8px; padding: 8px 16px; cursor: pointer; }
.msg-cancel { background: transparent; border: none; color: var(--text-dim); cursor: pointer; font-size: 1rem; padding: 4px 6px; }
.msg-zones { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.msg-cap { color: var(--text-dim); font-size: 0.8rem; }
.msg-zone { color: var(--text-dim); font-size: 0.82rem; display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }
.msg-status { color: var(--ok); font-size: 0.82rem; min-height: 1em; }
.msg-hint { color: var(--stale); font-size: 0.82rem; }

/* Remote calibration control (in a zone's detail panel) */
.cal-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 4px; }
.cal-cap { color: var(--text-dim); font-size: 0.82rem; }
.cal-ref { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 0.82rem; }
.cal-go { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 12px; font-size: 0.82rem; cursor: pointer; }
.cal-go:hover { border-color: var(--accent); color: var(--accent); }
.cal-hint { color: var(--stale); font-size: 0.78rem; }

/* A zone idle >5 min (Show offline): dimmed but still readable */
.pin.dimmed { opacity: 0.45; }
.detail-panel.dimmed { opacity: 0.6; }

.feedback-body { display: flex; gap: 12px; align-items: flex-start; }
.plan { position: relative; flex: 1; min-width: 0; aspect-ratio: 1000 / 600; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; touch-action: none; }
/* Inner transform layer: the map image + pins, pinch-zoomed as a unit. */
.plan-inner { position: absolute; inset: 0; background-size: contain; background-repeat: no-repeat; background-position: center; transform-origin: 0 0; will-change: transform; }
.plan-zoom-reset { position: absolute; top: 6px; right: 6px; z-index: 5; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 15px; line-height: 1; }
.plan-zoom-reset.hidden { display: none; }
/* Counter-scaled by --pin-inv (1/zoom from JS) so cards keep their original size
   while the map zooms — dense zones spread apart instead of cards ballooning. */
.pin { position: absolute; transform: translate(-50%, -50%) scale(var(--pin-inv, 1)); background: var(--bg-elev); border: 2px solid var(--border); border-radius: 10px; padding: 6px 8px; min-width: 86px; cursor: pointer; color: var(--text); text-align: left; }
/* Delete (offline/idle zones) lives on the detail card header, next to ✕. */
.detail-del { background: transparent; border: none; color: var(--text-dim); font-size: 0.9rem; cursor: pointer; margin-left: auto; padding: 2px 6px; }
.detail-del:hover { color: var(--bad); }
.detail-del + .detail-close { margin-left: 0; }
.pin.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(74,163,255,.3); }
.pin-head { display: flex; align-items: center; gap: 5px; }
.pin-dot { width: 8px; height: 8px; border-radius: 50%; }
.pin-name { font-size: 0.72rem; color: var(--text-dim); }
.pin-status { margin-left: auto; font-size: 0.6rem; font-weight: 700; text-transform: uppercase; color: var(--stale); letter-spacing: 0.5px; }
.pin-spl { font-size: 1.2rem; font-weight: 800; line-height: 1.1; }
.pin-unit { font-size: 0.68rem; font-weight: 600; }
.pin-tags { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.chip { background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; font-size: 0.66rem; color: var(--text-dim); }
.plan-empty { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 70%; text-align: center; color: var(--text-dim); font-size: 0.9rem; background: rgba(14,17,22,.7); padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border); }
.heat-blob { position: absolute; inset: -28px; border-radius: 50%; opacity: 0.18; filter: blur(18px); z-index: -1; }
.plan.heat .pin { background: transparent; border-color: transparent; }
.plan.heat .pin-name, .plan.heat .pin-tags { opacity: 0; }

.detail { width: 360px; max-width: 42%; display: flex; flex-direction: column; gap: 12px; }
.detail.hidden { display: none; }
.detail-panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; }
.detail-head h3 { margin: 0; }
.detail-close { background: transparent; border: none; color: var(--text-dim); font-size: 1rem; cursor: pointer; }
.detail-meta { color: var(--text-dim); font-size: 0.8rem; margin-bottom: 8px; }
.detail h4 { margin: 12px 0 6px; font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

/* Live / Avg / Max at a glance on each zone card. */
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.metric-stat {
  background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px;
}
.metric-stat .ms-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }
.metric-stat .ms-val { font-size: 1.5rem; font-weight: 800; line-height: 1.05; }
.metric-stat .ms-unit { font-size: 0.58rem; font-weight: 700; color: var(--text-dim); }
.spark { width: 100%; height: 64px; background: var(--bg-elev-2); border-radius: 8px; display: block; }

.rta { display: flex; align-items: flex-end; gap: 4px; height: 80px; }
.rta-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; }
.rta-track { flex: 1; width: 70%; background: var(--bg-elev-2); display: flex; align-items: flex-end; overflow: hidden; }
.rta-fill { width: 100%; background: var(--accent); }
.rta-label { font-size: 8px; color: var(--stale); }

.events { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.event { display: grid; grid-template-columns: 58px 1fr; gap: 8px; font-size: 0.78rem; align-items: center; }
.event-time { color: var(--stale); font-family: var(--mono); font-size: 0.7rem; }
.event-body { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.sev-dot { width: 8px; height: 8px; border-radius: 50%; }

@media (max-width: 820px) {
  .feedback-body { flex-direction: column; align-items: stretch; }
  .plan { flex: none; width: 100%; aspect-ratio: auto; min-height: 340px; }
  .detail { width: 100%; max-width: none; }
  .pin { min-width: 68px; padding: 4px 6px; }
  .pin-spl { font-size: 1rem; }
  .pin-name { font-size: 0.64rem; }
  .pin .chip { font-size: 0.58rem; padding: 1px 4px; }
}

@media (min-width: 1201px) {
  /* Roomy screens: widen the detail column and lay the open zone cards out in a
     grid so several zones' Live/Avg/Max are visible at once. */
  .detail {
    width: min(56%, 900px); max-width: 56%;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px; align-content: start;
  }
}

/* --- Setup mode ------------------------------------------------------------ */
.setup { display: flex; flex-direction: column; gap: 12px; }
.setup-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.setup-bar input[type="text"], .setup-bar input[type="number"], .setup-preset { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 0.9rem; }
.setup-bar input[type="text"] { min-width: 200px; }
.setup-sync-label { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 0.85rem; }
.setup-sync { width: 64px; }
.setup-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }
.setup-msg { color: var(--text-dim); font-size: 0.85rem; }
.setup-msg.err { color: var(--bad); }

.setup-plan { cursor: default; }
.setup-plan.no-plan { background: repeating-linear-gradient(45deg, #11161d, #11161d 12px, #141a22 12px, #141a22 24px); }
.setup-pin { cursor: grab; touch-action: none; user-select: none; }
.setup-pin:active { cursor: grabbing; }

.setup-editor input { width: 100%; }
.setup-editor .row input { width: auto; flex: 1; min-width: 0; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: rgba(248,81,73,.12); }

/* ===========================================================================
   REPORTER — scoped under `.reporter` so these rules apply only inside the
   Reporter view and never restyle the dashboard chrome/views.
   =========================================================================== */
.reporter { max-width: 680px; margin: 0 auto; }

.reporter h1 { font-size: 22px; margin: 8px 0 4px; }
.reporter h2 { font-size: 15px; color: var(--dim); font-weight: 600; margin: 18px 0 8px; }
.reporter .dim { color: var(--dim); font-size: 13px; }
.reporter .row { display: flex; align-items: center; gap: 8px; }
.reporter .spread { justify-content: space-between; }
.reporter .wrap { flex-wrap: wrap; }

.reporter label { display: block; color: var(--dim); font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.reporter input[type=text], .reporter input[type=password], .reporter input[type=number] {
  width: 100%; min-height: 46px; padding: 0 12px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 16px;
}
/* Role picker in the Connection window — matches the text inputs. */
.reporter select.rolesel {
  width: 100%; min-height: 46px; padding: 0 12px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 16px;
}
.reporter button {
  min-height: 46px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 15px; font-weight: 700;
}
.reporter button.primary { background: var(--accent); border-color: var(--accent); color: #04223f; }
.reporter button.ghost { background: transparent; }
.reporter button.ghost.on { border-color: var(--accent); color: var(--accent); }
.reporter button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.reporter button:disabled { opacity: .5; }
.reporter button.block { width: 100%; }

/* Password field with a reveal (eye) toggle */
.reporter .pw-wrap { position: relative; }
.reporter .pw-wrap input { padding-right: 46px; }
.reporter button.pw-eye {
  position: absolute; right: 4px; top: 0; height: 46px; width: 40px; min-height: 0;
  padding: 0; border: none; background: transparent; font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center; opacity: 0.75;
}
.reporter button.pw-eye:hover { opacity: 1; }
.reporter .err { color: var(--bad); font-weight: 700; }
.status-pill[data-status="unauthorized"] { background: rgba(248,81,73,.15); color: var(--bad); border-color: var(--bad); }

.reporter .card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }

/* Full-screen toggle pinned to the meter's top-right corner. */
.reporter .fsbtn { position: absolute; top: 10px; right: 10px; z-index: 6; min-height: 36px; min-width: 36px; padding: 0 8px; font-size: 18px; }
body.meter-fs .reporter .fsbtn { top: 14px; right: 14px; }

/* Offline/Test badge in place of the sending dot on the meter header. */
.reporter .test-badge { display: inline-block; background: var(--warn); color: #2a1a04; font-size: 11px; font-weight: 800; letter-spacing: .5px; padding: 2px 6px; border-radius: 6px; margin-right: 8px; vertical-align: middle; }

/* zone grid */
.reporter .zones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.reporter .zone { padding: 18px 12px; text-align: center; }
.reporter .zone .znum { font-size: 22px; font-weight: 800; }
.reporter .zone .zname { color: var(--dim); font-size: 13px; }

/* --- Map zone picker --------------------------------------------------------
   Tap where you're standing; the tap snaps to a nearby admin zone or a grid
   cell (demand-created zone). Dots: accent = defined zone, gray = covered by
   another monitor; the ring marks your unconfirmed tap. */
.reporter .zonemap {
  position: relative; width: 100%; aspect-ratio: 1000 / 600; cursor: crosshair;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  touch-action: pan-y; /* one finger scrolls the page; two fingers pinch/pan the map */
}
/* Inner transform layer: the plan image + markers, pinch-zoomed as a unit. */
.reporter .zm-inner {
  position: absolute; inset: 0;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  transform-origin: 0 0; will-change: transform;
}
/* Full-bleed on phones: break out of the view padding so the plan uses every px. */
@media (max-width: 700px) {
  .reporter .zonemap { margin-left: -16px; margin-right: -16px; width: calc(100% + 32px); border-radius: 0; border-left: 0; border-right: 0; }
}
.reporter .zm-zoom-reset {
  position: absolute; top: 6px; right: 6px; z-index: 5; width: 36px; height: 36px; min-height: 0;
  padding: 0; border-radius: 8px; border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 16px; line-height: 1;
}
.reporter .zm-zoom-reset.hidden { display: none; }
/* Markers counter-scale (--zm-inv = 1/zoom) so dots keep their size while the map zooms. */
.reporter .zm-dot {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  transform: translate(-50%, -50%) scale(var(--zm-inv, 1)); pointer-events: none;
  background: var(--accent); border: 2px solid var(--bg);
}
.reporter .zm-dot.taken { background: var(--dim); opacity: .75; }
.reporter .zm-ring {
  position: absolute; width: 30px; height: 30px; border-radius: 50%;
  transform: translate(-50%, -50%) scale(var(--zm-inv, 1)); pointer-events: none;
  border: 3px solid var(--accent); background: rgba(88, 166, 255, .18);
}
.reporter .zm-confirm {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 10px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 12px;
}
.reporter .zm-info { min-width: 0; }
.reporter .zm-name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.reporter .zm-rename { min-height: 30px; min-width: 30px; padding: 0 6px; font-size: 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--dim); }
.reporter .zm-avail { color: var(--ok); font-size: 13px; }
.reporter .zm-covered { color: var(--warn); font-size: 13px; }
.reporter .zm-confirm .primary { flex-shrink: 0; }

/* SPL readout */
.reporter .spl { font-size: 46px; font-weight: 800; line-height: 1; }
.reporter .spl .u { font-size: 18px; font-weight: 700; }

/* gear / settings */
.reporter .iconbtn { min-height: 46px; min-width: 46px; padding: 0 12px; font-size: 20px; line-height: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; }
.reporter .iconbtn.on { background: rgba(74,163,255,.16); color: var(--accent); border-color: var(--accent); }
/* Play (start) = accent, Stop = red — the primary metering action stands out. */
.reporter .iconbtn.go { background: var(--accent); border-color: var(--accent); color: #04223f; }
.reporter .iconbtn.stop { background: var(--bad); border-color: var(--bad); color: #2a0a08; }
/* Settings overlay is shell-owned (mounted on body), so these are global; its
   inner content is wrapped in `.reporter` so the scoped control styles apply. */
.settings-overlay { position: fixed; inset: 0; z-index: 50; display: none; background: rgba(0, 0, 0, .55); align-items: flex-start; justify-content: center; padding: env(safe-area-inset-top) 12px 12px; overflow-y: auto; }
.settings-overlay.open { display: flex; }

/* "How to calibrate" popup — sits ABOVE the settings overlay. */
.cal-help-overlay { position: fixed; inset: 0; z-index: 60; display: flex; background: rgba(0, 0, 0, .6); align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.cal-help { max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.cal-help .cal-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.45; }
.reporter .cal-help-btn {
  width: 26px; height: 26px; min-height: 0; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface2); color: var(--dim);
  font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
/* Rotate the help popup along with the settings window in full-screen landscape. */
body.meter-fs .cal-help-overlay {
  width: 100vh; height: 100vw;
  transform-origin: top left; transform: translateX(100vw) rotate(90deg);
}
.settings-sheet { width: 100%; max-width: 560px; margin-top: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
/* Tabbed settings — each pane fits without scrolling the sheet. */
.set-tabs { display: flex; gap: 4px; margin: 10px 0 4px; border-bottom: 1px solid var(--border); }
.set-tab { background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--dim); padding: 8px 12px; font-size: 14px; font-weight: 700; cursor: pointer; min-height: 0; border-radius: 0; }
.set-tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.set-tabpane { display: flex; flex-direction: column; gap: 6px; }
/* The raw feed in the settings sheet: single column, capped height + scroll. */
.set-tabpane.raw-feed .raw-grid { grid-template-columns: 1fr; }
.set-tabpane .raw-col { max-height: 46vh; }
.reporter .raw-feed .hint { color: var(--text-dim); font-size: 0.82rem; }
.reporter .setrow { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.reporter .chk { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text); font-size: 14px; font-weight: 600; }
.reporter .chk input { min-height: 0; width: auto; }
.reporter .setsep { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 12px 0 4px; }

/* analyzer resolution toggle */
.reporter .restoggle { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.reporter .resgroup { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.reporter .restab { min-height: 32px; padding: 0 12px; border: 0; border-radius: 0; font-size: 13px; color: var(--dim); background: var(--surface); font-weight: 700; }
.reporter .resgroup.wide .restab { padding: 0 9px; }
.reporter .restab.on { background: rgba(74,163,255,.16); color: var(--accent); }
.reporter .scalesel { min-height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; color: var(--text); background: var(--surface); }

/* spectrum */
.reporter .spectrum-wrap { display: flex; gap: 6px; margin-top: 4px; }
.reporter .axis { display: flex; flex-direction: column; justify-content: space-between; height: 140px; width: 22px; text-align: right; }
.reporter .axval { font-size: 8px; color: var(--dim); line-height: 1; }
.reporter .plot-col { flex: 1; min-width: 0; }
.reporter .plot { position: relative; display: flex; align-items: flex-end; gap: 4px; height: 140px; touch-action: none; }
.reporter .scale-hint { font-size: 11px; opacity: 0.7; }
.reporter button.spec-zoom-reset {
  position: absolute; top: 4px; right: 4px; z-index: 4; width: 26px; height: 26px; min-height: 0;
  padding: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 7px; border: 1px solid var(--border); background: var(--surface2); font-size: 13px; opacity: 0.85;
}
.reporter button.spec-zoom-reset.hidden { display: none; }
/* Reset-peaks button overlaid on the plot's bottom-right — full-screen only (the
   normal bottom control row carries its own reset). Larger tap target than the
   zoom-reset since it's the only on-plot control in full screen. */
.reporter button.spec-reset-peaks,
.reporter button.spec-settings { display: none; }
body.meter-fs .reporter button.spec-reset-peaks,
body.meter-fs .reporter button.spec-settings {
  position: absolute; bottom: 6px; z-index: 5; width: 40px; height: 40px; min-height: 0;
  padding: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); font-size: 18px; opacity: 0.9;
}
body.meter-fs .reporter button.spec-reset-peaks { right: 6px; }
/* Meter-settings ⚙ sits just left of reset-peaks. */
body.meter-fs .reporter button.spec-settings { right: 52px; }
.reporter .plot.dense { gap: 2px; }
.reporter .plot.super { gap: 1px; }
.reporter .plot.super .track { width: 90%; }
.reporter .gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); opacity: .45; pointer-events: none; }
.reporter .col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; z-index: 1; }
.reporter .track { position: relative; width: 52%; height: 100%; }
.reporter .plot.dense .track { width: 72%; }
/* Fills are full-height and squashed with scaleY (set from JS) — a compositor-only
   paint, so the ~30 fps analyzer repaint never triggers layout. */
.reporter .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: var(--accent); transform: scaleY(0); transform-origin: 50% 100%; will-change: transform; }
.reporter .peak { position: absolute; left: 0; right: 0; height: 1px; background: var(--dim); opacity: .7; }
.reporter .maxline { position: absolute; left: 0; right: 0; height: 1px; background: var(--warn); }
.reporter .xlabels { display: flex; gap: 4px; margin-top: 4px; }
.reporter .xlabels.dense { gap: 2px; }
.reporter .xlabels.super { gap: 1px; }
.reporter .collabel { flex: 1; min-width: 0; text-align: center; color: var(--dim); font-size: 9px; line-height: 12px; height: 12px; white-space: nowrap; }
.reporter .xlabels.dense .collabel { font-size: 8px; }
.reporter .xlabels.super .collabel { font-size: 7px; }

/* live peak crosshair */
.reporter .xhair-v, .reporter .xhair-h { position: absolute; background: var(--dim); opacity: 0; transition: opacity .15s; pointer-events: none; z-index: 3; }
.reporter .xhair-v { top: 0; bottom: 0; width: 1px; }
.reporter .xhair-h { left: 0; right: 0; height: 1px; }
.reporter .xhair-v.on, .reporter .xhair-h.on { opacity: .45; }
.reporter .xhair-lbl { position: absolute; transform: translate(5px, 50%); font-size: 9px; line-height: 1; color: var(--dim); background: rgba(14, 17, 22, .72); padding: 1px 4px; border-radius: 3px; white-space: nowrap; pointer-events: none; opacity: 0; z-index: 4; }
.reporter .xhair-lbl.on { opacity: .9; }
.reporter .xhair-lbl.flip { transform: translate(calc(-100% - 5px), 50%); }
.reporter .specmax { display: block; color: var(--warn); font-size: 13px; font-weight: 700; }
.reporter .xhair-lbl.pinned { color: var(--accent); opacity: 1; font-weight: 700; }
.reporter .xhair-v.pinned, .reporter .xhair-h.pinned { background: var(--accent); }
.reporter .xhair-v.pinned.on, .reporter .xhair-h.pinned.on { opacity: .6; }

/* 60 s dBA history sparkline under the readout. Hidden in full screen, where the
   spectrum gets every free pixel instead. */
.reporter .spl-spark { display: block; width: 100%; height: 34px; margin: 2px 0 4px; }
body.meter-fs .reporter .spl-spark { display: none; }

/* One-shot full-screen gesture hint, centered over the (rotated) meter card so it
   reads in landscape. Fades out at the end of its life; JS removes the node. */
.reporter .fs-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 7; pointer-events: none; text-align: center;
  background: rgba(14, 17, 22, .88); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 20px; font-size: 15px; line-height: 1.6; color: var(--text);
  animation: fsHintFade 6s forwards;
}
@keyframes fsHintFade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.reporter .peakrow { color: var(--warn); font-size: 13px; font-weight: 700; }

/* Sending indicator: a dot next to the zone name — green when metering to a zone
   over a live socket, red when not currently sending (connected != reporting). */
.reporter .zone-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.reporter .zone-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,160,67,.2); }
.reporter .zone-dot.off { background: var(--bad); box-shadow: 0 0 0 3px rgba(248,81,73,.2); }

/* Rolling L_Aeq being sent to the dashboard, shown small beside the live dBA. */
.reporter .spl-avg { display: block; font-size: 18px; font-weight: 700; color: var(--text-dim); white-space: nowrap; }

/* tags */
/* Tag sections have no headings now — keep a small gap between them (about half
   the old label-driven spacing) so the groups still read as separate. */
.reporter .tagsections { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.reporter .taggroup { margin: 0; }
.reporter .tags { display: flex; flex-wrap: wrap; gap: 8px; }
.reporter .tag { flex: 1 1 45%; min-height: 48px; border: 2px solid var(--border); background: var(--surface); }
.reporter .tag.on { border-color: var(--accent); background: rgba(74,163,255,.16); color: var(--accent); }

.reporter .actions { display: flex; gap: 8px; margin-top: 14px; }
.reporter .actions button { flex: 1; }

.reporter .hint { color: var(--warn); font-size: 12px; margin-top: 6px; }

/* toast lives on document.body (outside .reporter), so keep it global */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; background: var(--ok); color: #04210d; font-weight: 800; padding: 12px 20px; border-radius: 999px; z-index: 60; max-width: 90vw; text-align: center; }
/* A broadcast note from the desk: wider, blue, wraps for longer text. */
.toast.msg { background: var(--accent); color: #04210d; border-radius: 14px; white-space: normal; line-height: 1.3; }
