/* NWB Console — operator surface, mobile-first.
   The owner runs this one-handed on a phone while standing in a driveway.
   Every tap target is >=44px; nothing depends on hover. */

:root {
  --bg: #0b0f1a;
  --panel: #131a2a;
  --panel-2: #1a2338;
  --line: #24304a;
  --ink: #e8eefc;
  --ink-dim: #94a3c4;
  --ink-faint: #6b7a9c;
  --accent: #4338ca;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --unknown: #64748b;
  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }

/* The UA stylesheet's [hidden] { display: none } is a LOW-specificity rule,
   so any author rule that sets display beats it and the "hidden" element
   keeps rendering. That shipped here: .gate sets display:grid, so hiding the
   login gate left a full-screen z-index:100 overlay sitting invisibly over
   the whole console, swallowing every tap. The board underneath rendered
   perfectly and could not be touched. .summary (display:flex) had the same
   latent bug. Pin it once, for every element the JS toggles. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ── auth gate ─────────────────────────────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 22px;
}
.gate-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.gate-sub { margin: 0 0 20px; color: var(--ink-dim); font-size: 14px; }
.gate input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
}
.gate button {
  width: 100%;
  min-height: var(--tap);
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.gate-err { margin: 12px 0 0; color: var(--bad); font-size: 14px; }

/* ── top bar ───────────────────────────────────────────────────────────── */
/* ONE sticky container for the header + nav. Two separate sticky/top:0
   elements stacked on each other and swallowed every tab tap. */
.stickyhead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(11, 15, 26, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
}
.brand-name { font-weight: 700; letter-spacing: 0.01em; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.live {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--unknown);
  transition: background 0.2s;
}
.live[data-state="live"]   { background: var(--ok); }
.live[data-state="stale"]  { background: var(--warn); }
.live[data-state="error"]  { background: var(--bad); }
.live[data-state="paused"] { background: var(--unknown); }
.live-label { font-size: 12px; color: var(--ink-faint); }

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-dim);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--panel); }

/* ── tab nav — persistent, scrollable on narrow phones ─────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tabs a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
}

/* ── main / views ──────────────────────────────────────────────────────── */
main { padding: 14px 14px calc(28px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 14px;
}
.view-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
h3.sub { margin: 22px 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
h3.sub .hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.lede { margin: 0 0 14px; color: var(--ink-dim); font-size: 14px; }

.datepick { display: flex; align-items: center; gap: 6px; }
.datepick input {
  min-height: 38px;
  padding: 4px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
}

/* ── summary bar ───────────────────────────────────────────────────────── */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.summary .stat {
  flex: 1 1 auto;
  min-width: 88px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.summary .stat b { display: block; font-size: 22px; line-height: 1.1; }
.summary .stat span { font-size: 12px; color: var(--ink-faint); }

/* ── list + cards ──────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
}
.card[data-state="ready"]   { border-left-color: var(--ok); }
.card[data-state="partial"] { border-left-color: var(--warn); }
.card[data-state="empty"]   { border-left-color: var(--unknown); }
.card[data-state="sent"]    { border-left-color: var(--accent); }
.card[data-state="bad"]     { border-left-color: var(--bad); }

.card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.card-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.card-addr { margin: 3px 0 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.card-meta { margin: 5px 0 0; font-size: 13px; color: var(--ink-dim); }
.card-meta span + span::before { content: " · "; color: var(--ink-faint); }

.badge {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.badge[data-tone="ok"]      { background: rgba(5,150,105,0.16);  color: #34d399; border-color: rgba(5,150,105,0.4); }
.badge[data-tone="warn"]    { background: rgba(217,119,6,0.16);  color: #fbbf24; border-color: rgba(217,119,6,0.4); }
.badge[data-tone="bad"]     { background: rgba(220,38,38,0.16);  color: #f87171; border-color: rgba(220,38,38,0.4); }
.badge[data-tone="accent"]  { background: rgba(67,56,202,0.22);  color: #a5b4fc; border-color: rgba(67,56,202,0.5); }
.badge[data-tone="muted"]   { background: rgba(100,116,139,0.16);color: #94a3b8; border-color: rgba(100,116,139,0.4); }

/* container pills — what the job owes vs what's in */
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pill {
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.pill[data-state="filled"]  { border-color: rgba(5,150,105,0.5);  color: #34d399; }
.pill[data-state="partial"] { border-color: rgba(217,119,6,0.5);  color: #fbbf24; }
.pill[data-state="empty"]   { border-color: var(--line);          color: var(--ink-faint); }

/* ── chips (heartbeats, expiries) ──────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}
.chip b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.chip span { color: var(--ink-faint); font-size: 12px; }
.chip[data-state="amber"]   { border-color: rgba(217,119,6,0.5); }
.chip[data-state="expired"] { border-color: rgba(220,38,38,0.5); }

/* ── health strip ──────────────────────────────────────────────────────── */
.strip { display: flex; flex-wrap: wrap; gap: 8px; }
.sub-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}
.sub-item .led { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.sub-item[data-status="ok"] .led           { background: var(--ok); }
.sub-item[data-status="fail"] .led         { background: var(--bad); }
.sub-item[data-status="unknown"] .led      { background: var(--warn); }
.sub-item[data-status="unconfigured"] .led { background: var(--unknown); }
.sub-item[data-status="fail"] { border-color: rgba(220,38,38,0.5); }

/* ── proxied surfaces ──────────────────────────────────────────────────── */
/* A framed surface fills everything below the persistent shell. The shell
   stays put; only this region swaps. The iframe scrolls internally, so the
   operator never scrolls the console itself away from the nav. */
#frames { display: contents; }

.frame-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: var(--shell-h, 116px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.frame-wrap .surface {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  background: var(--bg);
}

/* A marketing site is not an operator surface — label it so nobody mistakes
   a public page for a console screen. */
.preview-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 12px;
}
.preview-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(217,119,6,0.18);
  border: 1px solid rgba(217,119,6,0.45);
  color: #fbbf24;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* While a surface is framed the page itself must not scroll — otherwise the
   shell scrolls off and "persistent nav" stops being true on a phone. */
body.framed { overflow: hidden; }
body.framed #content { padding: 0; }

.warn-text { color: #fbbf24; }

/* ── big link buttons ──────────────────────────────────────────────────── */
.bigbtn {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  gap: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--tap);
  margin-bottom: 10px;
  padding: 13px 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.bigbtn:active { background: var(--line); }
.bigbtn-note { font-weight: 400; font-size: 13px; color: var(--ink-faint); }

/* ── empty / error states ──────────────────────────────────────────────── */
.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--ink-faint);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}
.empty.bad { color: #f87171; border-color: rgba(220,38,38,0.4); }

/* ── toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  max-width: 90vw;
  padding: 11px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

/* ── desktop ───────────────────────────────────────────────────────────── */
@media (min-width: 720px) {
  .tabs { justify-content: flex-start; padding: 10px 14px; }
  main { padding-top: 18px; }
  .summary .stat { min-width: 110px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
