/* style.css — UberSDR Packet dark theme */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #181c27;
  --bg3:       #1e2333;
  --border:    #2a3050;
  --accent:    #4a9eff;
  --accent2:   #2d7dd2;
  --text:      #d0d8f0;
  --text-dim:  #7a88aa;
  --green:     #3ecf6e;
  --red:       #e05252;
  --yellow:    #e0b84a;
  --orange:    #e07a30;
  --radius:    6px;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ── Receiver info (header) ──────────────────────────────────────────────── */
.rx-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.82em;
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
}
.rx-info.hidden { display: none; }
.rx-callsign {
  font-weight: 700;
  color: var(--accent);
  font-size: 1em;
  letter-spacing: 0.03em;
}
.rx-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.rx-location {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.rx-map-btn {
  text-decoration: none;
  padding: 3px 8px;
  font-size: 0.85em;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: background 0.15s;
}
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c04040; }
.btn-sm { padding: 3px 9px; font-size: 12px; }

/* ── Connection status dot ───────────────────────────────────────────────── */
.conn-status { font-size: 18px; line-height: 1; }
.conn-connected    { color: var(--green); }
.conn-disconnected { color: var(--red); }

/* ── Add-channel panel ───────────────────────────────────────────────────── */
.add-panel {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.add-panel.hidden { display: none; }
.add-panel-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}
.add-panel-inner h2 { font-size: 1rem; margin-bottom: 12px; color: var(--accent); }
.add-panel-inner h3 { font-size: 0.9rem; margin: 14px 0 8px; color: var(--text-dim); }

.freq-preset-row {
  margin-bottom: 14px;
}
.freq-preset-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 420px;
}
.freq-preset-row select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 0.85rem;
  width: 100%;
}
.freq-preset-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.form-grid label, label.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.form-grid input, .form-grid select,
input.form-input, select.form-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}
.form-grid input:focus, .form-grid select:focus,
input.form-input:focus, select.form-select:focus {
  border-color: var(--accent);
}

.add-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
}

/* ── Modem channel config grid ───────────────────────────────────────────── */
.modem-channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.modem-ch-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.modem-ch-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 13px;
}
.modem-ch-header input[type=checkbox] { accent-color: var(--accent); }
.modem-ch-params { display: flex; flex-direction: column; gap: 6px; }
.modem-ch-params.disabled { opacity: 0.4; pointer-events: none; }
.param-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.param-row label { flex: 1; }
.param-input-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.param-input-wrap input,
.param-input-wrap select {
  width: 100%;
}
.modem-rf-hint {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  text-align: right;
  line-height: 1.2;
  min-height: 1em;
}
.param-row select, .param-row input {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--font);
  width: 110px;
}

/* ── Main channel cards ──────────────────────────────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  font-size: 15px;
}

.channel-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.channel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.channel-header:hover { background: #232840; }
.channel-label {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}
.channel-freq {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.channel-status-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.channel-status-badge.running { color: var(--green); border-color: var(--green); }
.channel-status-badge.reconnecting { color: var(--yellow); border-color: var(--yellow); }
.channel-mqtt-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: rgba(100, 180, 255, 0.08);
  white-space: nowrap;
  font-family: monospace;
}

/* ── Config pane locked state (not authenticated) ───────────────────────── */
/* Driven by body classes set in renderAuthBar() — no per-card class needed. */
body.pw-configured:not(.is-authed) .config-pane input,
body.pw-configured:not(.is-authed) .config-pane select,
body.pw-configured:not(.is-authed) .config-pane button,
body.pw-configured:not(.is-authed) .config-pane textarea,
body.pw-configured:not(.is-authed) .config-pane .modem-ch-header input {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Remove button locked state (not authenticated) ─────────────────────── */
body.pw-configured:not(.is-authed) .channel-actions .btn-danger {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Channel settings row (name + bandwidth in config pane) ─────────────── */
.ch-settings-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.ch-setting-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
  min-width: 140px;
}
.ch-setting-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 4px 8px;
  width: 100%;
  box-sizing: border-box;
}
.ch-setting-input:focus {
  outline: none;
  border-color: var(--accent);
}
.ch-setting-input-narrow {
  max-width: 140px;
}

/* ── MQTT prefix row — hidden unless broker is configured ────────────────── */
/* body.mqtt-enabled is set by loadConfig() so all rows update without        */
/* re-rendering cards.                                                         */
.mqtt-prefix-row {
  display: none;
  margin: 8px 0 4px;
}
body.mqtt-enabled .mqtt-prefix-row {
  display: block;
}
.mqtt-prefix-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.mqtt-prefix-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 4px 8px;
  width: 100%;
  box-sizing: border-box;
}
.mqtt-prefix-input:focus {
  outline: none;
  border-color: var(--accent);
}
/* Split topic field: [prefix/] [suffix-input] */
.mqtt-topic-field {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.mqtt-topic-prefix-badge {
  padding: 4px 6px;
  background: var(--bg3);
  color: var(--accent);
  font-size: 12px;
  font-family: monospace;
  white-space: nowrap;
  border-right: 1px solid var(--border);
  user-select: none;
}
.mqtt-topic-field .mqtt-prefix-input {
  border: none;
  border-radius: 0;
  background: transparent;
  flex: 1;
  min-width: 0;
}
.mqtt-topic-field .mqtt-prefix-input:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

.dcd-indicators {
  display: flex;
  gap: 4px;
}
.dcd-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 2px solid #444;
  transition: background 0.1s, border-color 0.1s, box-shadow 0.1s;
}
/* Per-channel border colour when enabled (idle) */
.dcd-led-0 { border-color: rgba(41,  182, 246, 0.5); }
.dcd-led-1 { border-color: rgba(102, 187, 106, 0.5); }
.dcd-led-2 { border-color: rgba(206, 147, 216, 0.5); }
.dcd-led-3 { border-color: rgba(255, 167,  38, 0.5); }
/* Grey ring when channel is disabled — overrides channel colour */
.dcd-led.disabled { border-color: rgba(120, 120, 120, 0.35); opacity: 0.45; }
/* Per-channel fill + glow when DCD active */
.dcd-led-0.on { background: #29B6F6; border-color: #29B6F6; box-shadow: 0 0 5px #29B6F6; }
.dcd-led-1.on { background: #66BB6A; border-color: #66BB6A; box-shadow: 0 0 5px #66BB6A; }
.dcd-led-2.on { background: #CE93D8; border-color: #CE93D8; box-shadow: 0 0 5px #CE93D8; }
.dcd-led-3.on { background: #FFA726; border-color: #FFA726; box-shadow: 0 0 5px #FFA726; }

.channel-actions { display: flex; gap: 6px; }

/* ── Channel body ────────────────────────────────────────────────────────── */
.channel-body { display: flex; flex-direction: column; }
.channel-body.collapsed { display: none; }

.channel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.tab-btn {
  padding: 7px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font);
  transition: color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Frames tab ──────────────────────────────────────────────────────────── */
.frames-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.frames-toolbar select, .frames-toolbar input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
}
.frames-toolbar label { font-size: 12px; color: var(--text-dim); }
.frame-count { font-size: 12px; color: var(--text-dim); margin-left: auto; }

/* ── Search bar (below toolbar) ──────────────────────────────────────────── */
.frames-search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
}
.search-bar-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
  min-width: 90px;
}
.search-icon {
  font-size: 13px;
  opacity: 0.6;
  flex-shrink: 0;
}
.search-input {
  flex: 1;
  min-width: 120px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
}
.search-input:focus { outline: none; border-color: var(--accent); }
.btn-search-clear {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  padding: 3px 7px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-search-clear:hover { color: var(--text); border-color: var(--text-dim); }

.frames-stats-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.frames-stat { color: var(--text-dim); }
.frames-stat-sep { color: var(--border); margin: 0 2px; }
.frames-stat-label { color: var(--text-dim); }
.frames-stat-callsign {
  color: var(--text);
  font-weight: 600;
  font-family: monospace;
}
.frames-stat-ago {
  color: var(--text-dim);
  font-style: italic;
}

.frames-list {
  min-height: 120px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
}

/* Rich frame row — badge | time | path | type-tag | payload */
.frame-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  padding: 5px 12px;
  border-bottom: 1px solid #1a1f30;
  cursor: default;
  line-height: 1.5;
}
.frame-row:hover { background: var(--bg3); }

/* Channel badge (A/B/C/D) — bright palette matching waterfall/extension */
.frame-ch-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  color: #000;
}
.frame-ch-badge-0 { background: #29B6F6; }  /* Ch A — sky blue */
.frame-ch-badge-1 { background: #66BB6A; }  /* Ch B — bright green */
.frame-ch-badge-2 { background: #CE93D8; }  /* Ch C — light purple */
.frame-ch-badge-3 { background: #FFA726; }  /* Ch D — amber */

/* Left-border colour per channel on frame rows */
.frame-row { border-left: 3px solid transparent; }
.frame-ch-0 { border-left-color: #29B6F6; }
.frame-ch-1 { border-left-color: #66BB6A; }
.frame-ch-2 { border-left-color: #CE93D8; }
.frame-ch-3 { border-left-color: #FFA726; }

/* Timestamp */
.frame-time { color: var(--text-dim); white-space: nowrap; flex-shrink: 0; }

/* FROM→TO via DIGI path */
.frame-path {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Frame-type tag pill */
.frame-type-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
/* Frame-type tag colours — exact match to the ubersdr extension styles.css */
.frame-type-tag-aprs   { background: #1B5E20; color: #a5d6a7; }
.frame-type-tag-ui     { background: #0D47A1; color: #90caf9; }
.frame-type-tag-i      { background: #E65100; color: #ffe082; }
.frame-type-tag-rr,
.frame-type-tag-rnr,
.frame-type-tag-rej,
.frame-type-tag-srej   { background: #263238; color: #90a4ae; }
.frame-type-tag-sabm,
.frame-type-tag-sabme  { background: #006064; color: #80deea; }
.frame-type-tag-ua     { background: #004D40; color: #b2dfdb; }
.frame-type-tag-disc,
.frame-type-tag-dm     { background: #BF360C; color: #ffab91; }
.frame-type-tag-frmr   { background: #B71C1C; color: #ef9a9a; }
.frame-type-tag-xid    { background: #4A148C; color: #ce93d8; }
.frame-type-tag-test   { background: #263238; color: #90a4ae; }
.frame-type-tag-netrom { background: #E65100; color: #ffcc80; }
.frame-type-tag-nodes  { background: #F57F17; color: #fff9c4; }
.frame-type-tag-ip     { background: #01579B; color: #81d4fa; }
.frame-type-tag-arp    { background: #006064; color: #b3e5fc; }

/* Payload text */
.frame-payload {
  color: var(--text);
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

/* Raw hex fallback */
.frame-raw { color: #888; font-size: 11px; word-break: break-all; flex: 1; }

/* Clickable links inside payload */
.frame-aprs-link,
.frame-url-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.frame-aprs-link:hover,
.frame-url-link:hover { color: #7ec8ff; }

/* ── Monitor tab ─────────────────────────────────────────────────────────── */
.monitor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.monitor-ch-select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 6px;
  font-size: 12px;
  cursor: pointer;
}
.monitor-search-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
  flex: 1;
  min-width: 120px;
  max-width: 280px;
}
.monitor-search-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12px;
  width: 100%;
  min-width: 0;
}
.monitor-search-input::placeholder { color: var(--text-dim); }
.monitor-list {
  min-height: 120px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 0;
}
.monitor-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 12px;
  border-bottom: 1px solid #1a1f30;
}
.monitor-line.tx { background: rgba(224,122,48,0.05); }
.monitor-line.rx { background: transparent; }
.monitor-time { color: var(--text-dim); white-space: nowrap; flex-shrink: 0; }
.monitor-ch-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}
/* Monitor channel badges — same bright palette */
.monitor-ch-badge-0 { background: #29B6F6; color: #000; }
.monitor-ch-badge-1 { background: #66BB6A; color: #000; }
.monitor-ch-badge-2 { background: #CE93D8; color: #000; }
.monitor-ch-badge-3 { background: #FFA726; color: #000; }
.monitor-dir {
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  width: 20px;
}
.monitor-line.tx .monitor-dir { color: var(--orange); }
.monitor-line.rx .monitor-dir { color: var(--green); }
.monitor-text {
  color: var(--text);
  word-break: break-all;
  flex: 1;
}
.monitor-line.tx .monitor-text { color: var(--orange); }

/* ── Log tab ─────────────────────────────────────────────────────────────── */
.log-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}
.log-list {
  min-height: 120px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 0;
  color: var(--text-dim);
}
.log-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 12px;
}
.log-time { color: #555e7a; white-space: nowrap; flex-shrink: 0; }
.log-text { word-break: break-all; flex: 1; }

/* ── Config tab ──────────────────────────────────────────────────────────── */
.config-pane {
  padding: 14px;
}
.config-pane h4 { font-size: 13px; margin-bottom: 10px; color: var(--text-dim); }
.config-modem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.config-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4060; }

/* ── Login modal ─────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none !important; }
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-box h2 { font-size: 1rem; color: var(--accent); }
.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.modal-box input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}
.modal-box input:focus { border-color: var(--accent); }
.modal-error { color: var(--red); font-size: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Auth bar ────────────────────────────────────────────────────────────── */
.auth-authed { font-size: 12px; color: var(--text-dim); }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }

/* ── Waterfall ───────────────────────────────────────────────────────────── */
.wf-section {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 6px 12px 8px;
}
.wf-btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

/* Collapsed-state last-frame summary — right-aligned, shows a full frame row */
.wf-collapsed-info {
  margin-left: auto;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  /* Hidden when body is expanded */
  display: none;
}
/* Show only when body is collapsed */
.channel-card.body-collapsed .wf-collapsed-info {
  display: block;
}
/* The embedded frame-row should be flush — no extra border/margin */
.wf-collapsed-info .frame-row {
  border-bottom: none;
  border-left: none;
  padding: 0 4px;
  background: transparent !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-wrap: nowrap;
}
.wf-collapsed-info .frame-payload {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wf-wrap {
  /* empty until Preview is clicked */
}
.wf-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.wf-hdr-canvas,
.wf-ftr-canvas {
  display: block;
  width: 100%;
  background: #1a1a1a;
  cursor: crosshair;
}
.wf-stack {
  position: relative;
  width: 100%;
  height: 120px;
}
.wf-canvas,
.wf-ovl-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.wf-canvas  { z-index: 1; }
.wf-ovl-canvas { z-index: 2; cursor: crosshair; }

/* ── SNR badge on decoded frames ─────────────────────────────────────────── */
.frame-snr-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.72em;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
}
.snr-good {
  background: rgba(62, 207, 110, 0.18);
  color: var(--green);
  border: 1px solid rgba(62, 207, 110, 0.35);
}
.snr-ok {
  background: rgba(224, 184, 74, 0.18);
  color: var(--yellow);
  border: 1px solid rgba(224, 184, 74, 0.35);
}
.snr-poor {
  background: rgba(224, 82, 82, 0.18);
  color: var(--red);
  border: 1px solid rgba(224, 82, 82, 0.35);
}

/* ── Stats modal (.stm-*) ────────────────────────────────────────────────── */
.stm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px;
  overflow-y: auto;
}
.stm-overlay.hidden { display: none; }

.stm-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.stm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stm-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}
.stm-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stm-ctrl-label {
  font-size: 0.85em;
  color: var(--text-dim);
  white-space: nowrap;
}
.stm-select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 0.85em;
  min-width: 200px;
}
.stm-select:focus { outline: 1px solid var(--accent); }

.stm-status {
  font-size: 0.8em;
  color: var(--text-dim);
  min-height: 1.2em;
}

/* 2-column responsive grid of chart boxes */
.stm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 16px;
}
.stm-chart-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stm-chart-title {
  font-size: 0.78em;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stm-canvas {
  width: 100%;
  height: 220px;
  display: block;
}

.stm-tooltip {
  position: fixed;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 0.8em;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  z-index: 600;
  line-height: 1.6;
  display: flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.stm-tooltip.hidden { display: none; }

/* ── SNR History modal ───────────────────────────────────────────────────── */
.snrh-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.snrh-overlay.hidden { display: none; }

.snrh-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(900px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.snrh-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.snrh-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  flex: 1;
}
.snrh-close {
  margin-left: auto;
}

.snrh-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.snrh-label {
  color: var(--text-dim);
  font-size: 0.85em;
  white-space: nowrap;
}
.snrh-select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 0.85em;
  min-width: 160px;
}
.snrh-select:focus { outline: 1px solid var(--accent); }
/* Compact sub-channel selector (A/B/C/D) */
.snrh-sm-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.snrh-sm-row.hidden { display: none; }
.snrh-select-sm { min-width: 70px; }
.snrh-auto-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82em;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.snrh-auto-chk { accent-color: var(--accent); cursor: pointer; }

.snrh-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8em;
  color: var(--text-dim);
  min-height: 1.2em;
}
.snrh-status { color: var(--yellow); }
.snrh-count  { color: var(--text-dim); }

.snrh-canvas-wrap {
  flex: 1;
  min-height: 260px;
  max-height: 420px;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.snrh-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.snrh-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.78em;
  color: var(--text-dim);
}
.snrh-leg { display: flex; align-items: center; gap: 4px; }
.snrh-leg-good   { color: var(--green); }
.snrh-leg-ok     { color: var(--yellow); }
.snrh-leg-poor   { color: var(--red); }
.snrh-leg-sender { font-weight: 600; letter-spacing: 0.02em; }

.snrh-tooltip {
  position: absolute;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.8em;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  line-height: 1.5;
}
.snrh-tooltip.hidden { display: none; }

/* SNR History button on channel card header */
.btn-snr-history {
  font-size: 0.78em;
  padding: 3px 8px;
}

/* ── API Docs modal (.apidocs-*) ─────────────────────────────────────────── */
.apidocs-box {
  max-width: 780px;
  width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.apidocs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.apidocs-header h2 { margin: 0; font-size: 1.1rem; }

.apidocs-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  flex: 1;
}

.apidocs-section {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 20px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.apidocs-section:first-child { margin-top: 0; }

.apidocs-endpoint {
  margin-bottom: 16px;
}

.apidocs-sig {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.apidocs-method {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.apidocs-method-get    { background: #1a3a5c; color: #4a9eff; }
.apidocs-method-post   { background: #1a3d2a; color: #3ecf6e; }
.apidocs-method-patch  { background: #3a2e10; color: #e0b84a; }
.apidocs-method-delete { background: #3a1a1a; color: #e05252; }

.apidocs-path {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
}

.apidocs-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 2px 0 6px;
  line-height: 1.5;
}

.apidocs-note {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0 0 6px;
  line-height: 1.5;
}
.apidocs-note code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--text);
  background: var(--bg3);
  padding: 1px 4px;
  border-radius: 3px;
}

.apidocs-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
  margin: 0;
  line-height: 1.6;
}

.apidocs-curl-line:empty::before { content: '\00a0'; }

/* ── SNR Dashboard page (.snrd-*) ───────────────────────────────────────── */
#snrd-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px;
}

.snrd-back {
  color: var(--accent);
  text-decoration: none;
}
.snrd-back:hover { text-decoration: underline; }

.snrd-status {
  font-size: 0.82em;
  color: var(--text-dim);
}

.snrd-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 0.95em;
}

.snrd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.snrd-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.snrd-card-hdr {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 12px 6px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.snrd-callsign {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  font-family: var(--mono);
}

.snrd-card-meta {
  font-size: 0.75em;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.snrd-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 160px;
  background: var(--bg);
}

.snrd-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.snrd-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8em;
  color: var(--text-dim);
  background: var(--bg);
}
.snrd-loading.hidden { display: none; }

.snrd-tooltip {
  position: absolute;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 9px;
  font-size: 0.78em;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  line-height: 1.5;
}
.snrd-tooltip.hidden { display: none; }

/* ── Mobile: truncate long frame payloads, tap to expand ────────────────── */
@media (max-width: 768px) {
  .frame-row {
    flex-wrap: nowrap;
    align-items: center;
    cursor: pointer;
  }
  .frame-path {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex-shrink: 1;
  }
  .frame-payload {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: normal;
    min-width: 0;
    flex-shrink: 1;
  }
  .frame-row.expanded {
    flex-wrap: wrap;
    align-items: baseline;
    cursor: default;
  }
  .frame-row.expanded .frame-payload {
    flex-basis: 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-all;
  }
}
