/* JoAT SDR. Layout follows SDR++: controls on the left (where people look for
   them), the spectrum and waterfall filling the middle (where the eyes rest),
   occasional controls on the right edge, a quiet status line at the bottom.
   Colours: deep blue-grey instead of black, off-white instead of white, one
   calm teal for controls, and warm amber only for the channel you are on. */
:root {
  --bg: #10161c;
  --panel: #141c23;
  --raise: #1a242d;
  --line: #24313b;
  --text: #d6dde4;
  --muted: #8796a4;
  --accent: #5fb8ac;
  --accent-ink: #0c1a1b;
  --amber: #e0b062;
  --bad: #d9675f;
  --good: #6cc08f;
  --warn: #e0b062;
  --plot: #0b1117;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e9edf0;
  --panel: #f5f7f8;
  --raise: #ffffff;
  --line: #d0d8de;
  --text: #1c262e;
  --muted: #56646f;
  --accent: #2b8076;
  --accent-ink: #ffffff;
  --amber: #a5711a;
  --warn: #a5711a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- shell */
.app {
  display: grid;
  height: 100dvh;
  grid-template-columns: 68px 292px minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr) 30px;
  grid-template-areas: "top top top" "rail panel stage" "status status status";
}
.app.collapsed, .app.no-panel { grid-template-columns: 68px 0 minmax(0, 1fr); }
.app.collapsed .panel, .app.no-panel .panel { display: none; }

.topbar { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 16px 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.rail { grid-area: rail; display: flex; flex-direction: column; gap: 4px; padding: 10px 6px; background: var(--panel); border-right: 1px solid var(--line); }
.panel { grid-area: panel; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 6px 0 24px; }
.stage { grid-area: stage; min-width: 0; min-height: 0; overflow: auto; }
.status { grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 16px; font-size: 13px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ---- controls */
button { font: inherit; color: var(--text); background: var(--raise); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 14px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.icon { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); }
button.icon:hover { color: var(--text); background: var(--raise); }
button.go { min-width: 84px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.quiet { padding: 6px 12px; }
button.chip { padding: 2px 8px; font-size: 13px; background: transparent; }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; min-width: 0; width: 100%; }
input[type="range"] { padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }

/* rail */
.rail button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px; font-size: 11px; color: var(--muted); background: transparent; border: 0; border-radius: var(--radius); }
.rail button:hover { color: var(--text); background: var(--raise); }
.rail button[aria-selected="true"] { color: var(--text); background: var(--raise); box-shadow: inset 3px 0 0 var(--accent); }

/* left panel sections, folding like SDR++ */
.panel details { border-bottom: 1px solid var(--line); }
.panel summary { list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: ""; width: 7px; height: 7px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
.panel details:not([open]) summary::after { transform: rotate(-45deg); }
.panel details > :not(summary) { margin: 0 16px 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline { display: flex; gap: 8px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; margin: 0; }
#hosts { display: flex; flex-wrap: wrap; gap: 6px; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.modes button { padding: 7px 0; font-size: 13px; font-weight: 600; letter-spacing: .02em; background: var(--bg); }
.modes button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.station { display: flex; flex-direction: column; gap: 6px; font-size: 14px; margin: 0; }
.station strong { font-size: 16px; font-weight: 600; }
.station .rt { color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.badge { align-self: flex-start; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 4px; border: 1px solid currentColor; color: var(--accent); }

/* ---- top bar */
.vol { flex-direction: row; align-items: center; gap: 8px; color: var(--muted); }
.vol input { width: 110px; }
/* The one bold element: the frequency, large and light, leading zeros dimmed. */
.readout { display: flex; align-items: baseline; margin-left: 8px; font-size: 34px; font-weight: 300; letter-spacing: .01em; font-variant-numeric: tabular-nums; line-height: 1; cursor: ns-resize; user-select: none; white-space: nowrap; border-radius: var(--radius); padding: 2px 4px; }
.readout .d { display: inline-block; min-width: .6em; text-align: center; }
.readout .d:hover { color: var(--accent); }
.readout .z { color: var(--muted); opacity: .45; }
.readout .sep { color: var(--muted); opacity: .6; margin: 0 1px; }
.readout .unit { font-size: 15px; color: var(--muted); margin-left: 8px; font-weight: 400; }
.readout input { font-size: 26px; width: 9em; font-variant-numeric: tabular-nums; }
.readout-mode { font-size: 13px; font-weight: 600; color: var(--amber); min-width: 3em; }
.meter { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-bar { width: 150px; height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
#meter-fill { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
#meter-db { min-width: 4.5em; text-align: right; }

/* ---- radio stage */
#radio { height: 100%; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
#radio .scope { flex: 1; min-height: 240px; }
.scope { display: grid; grid-template-columns: minmax(0, 1fr) 46px; grid-template-rows: minmax(0, 1fr) auto; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--plot); }
.plot { position: relative; display: grid; grid-template-rows: 34% minmax(0, 1fr); min-height: 0; }
canvas { display: block; width: 100%; height: 100%; }
.plot canvas { cursor: crosshair; touch-action: none; }
#spectrum { border-bottom: 1px solid #1b2731; }
.sliders { grid-row: 1 / 3; grid-column: 2; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; border-left: 1px solid #1b2731; background: #0d141a; }
.sliders label { align-items: center; font-size: 11px; color: #7f8e9b; flex: 1; min-height: 0; }
.sliders input { writing-mode: vertical-lr; direction: rtl; width: 18px; flex: 1; min-height: 40px; }
.axis { position: relative; height: 26px; padding: 5px 10px; font-size: 12px; color: #8796a4; background: #0d141a; border-top: 1px solid #1b2731; font-variant-numeric: tabular-nums; }
.axis span { position: absolute; top: 5px; white-space: nowrap; }
.axis span:first-child { padding-left: 8px; }
.axis span:last-child { padding-right: 8px; }
/* The channel you are listening to: warm amber, the only warm colour on screen. */
.marker { position: absolute; top: 0; bottom: 0; background: rgba(224, 176, 98, 0.10); border-left: 1px solid rgba(224, 176, 98, 0.75); border-right: 1px solid rgba(224, 176, 98, 0.75); pointer-events: none; }
.marker[data-label]:not([data-label=""])::before { content: attr(data-label); position: absolute; top: 4px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 12px; padding: 1px 6px; border-radius: 3px; background: rgba(11, 17, 23, 0.85); color: #f0d39a; }

/* ---- other sections */
.tab:not(#radio) { padding: 24px; max-width: 1100px; }
.lead { color: var(--muted); font-size: 15px; line-height: 1.5; max-width: 70ch; margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.wide { grid-column: 1 / -1; }
.grid button[type="submit"], .row button[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
a { color: var(--accent); overflow-wrap: anywhere; }
.ok { color: var(--good); }
.no { color: var(--bad); }
.warn { color: var(--warn); overflow-wrap: anywhere; }
ol.steps { padding-left: 20px; }
ol.steps li { margin: 8px 0; }
ol.steps .w { color: var(--warn); font-size: 12px; margin-left: 6px; }
ol.steps .d { color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- narrow screens: rail along the bottom, controls slide over the waterfall */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 58px; grid-template-areas: "top" "stage" "rail"; }
  .app.collapsed, .app.no-panel { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .readout { order: 5; width: 100%; font-size: 28px; margin-left: 0; }
  .vol input { width: 80px; }
  .meter-bar { width: 70px; }
  .rail { flex-direction: row; justify-content: space-around; padding: 4px; border-right: 0; border-top: 1px solid var(--line); }
  .rail button { flex: 1; }
  .status { display: none; }
  .panel { position: fixed; z-index: 5; left: 0; top: 0; bottom: 58px; width: min(320px, 88vw); box-shadow: 6px 0 24px rgba(0, 0, 0, .35); }
  #radio { padding: 6px; }
  .tab:not(#radio) { padding: 16px; }
}

/* Decoders: each button names what you will see, then the system and band. */
.decoders { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.decoders button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; background: var(--bg); text-align: left; }
.decoders button span { font-size: 12px; color: var(--muted); }
.decoders button[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* Traffic table under the waterfall. */
.traffic { flex: 0 0 auto; height: 44%; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-height: 0; }
.traffic-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.traffic-head .seg { margin-left: auto; }
.traffic-body { overflow: auto; flex: 1; min-height: 0; position: relative; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 12px; font-size: 13px; background: transparent; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--raise); color: var(--text); }
.traffic tbody tr { cursor: pointer; }
.traffic tbody tr:hover td { background: var(--raise); }

/* Map: OpenStreetMap tiles, tinted to sit quietly in the dark theme. */
.map { position: absolute; inset: 0; background: #0f1a22; }
:root:not([data-theme="light"]) .map .leaflet-tile-pane { filter: invert(1) hue-rotate(190deg) brightness(0.78) contrast(0.9) saturate(0.45); }
.map .leaflet-control-attribution { background: rgba(16, 22, 28, 0.75); color: #8796a4; font-size: 11px; }
.map .leaflet-control-attribution a { color: #a9c4c0; }
:root[data-theme="light"] .map .leaflet-control-attribution { background: rgba(255, 255, 255, 0.8); color: #56646f; }
.map .leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }
.tgt svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
.tgt svg path { fill: var(--accent); stroke: #0b1117; stroke-width: 1.2; }
.tgt.old svg path { fill: #6b7a86; }
.tgt.picked svg path { fill: var(--amber); }
.map .leaflet-tooltip.tgt-label { background: rgba(11, 17, 23, 0.82); color: #d6dde4; border: 0; box-shadow: none; font-size: 12px; padding: 1px 6px; }
.map .leaflet-tooltip.tgt-label::before { display: none; }
.home-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(224, 176, 98, 0.3); }
.traffic table { font-size: 13px; font-variant-numeric: tabular-nums; }
.traffic th { position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
.traffic td { white-space: nowrap; }
.traffic td.num, .traffic th.num { text-align: right; }
.traffic tr.stale td { color: var(--muted); }
.traffic tbody tr[data-id] { cursor: pointer; }
.traffic tr.picked td { background: color-mix(in srgb, var(--amber) 14%, transparent); }
/* Leaflet sizes its drawing layer with attributes; undo the icon defaults above. */
.map .leaflet-overlay-pane svg { width: auto; height: auto; fill: initial; stroke: initial; stroke-width: initial; }
.ring-label { color: var(--amber); font-size: 11px; text-align: center; opacity: .8; text-shadow: 0 0 3px var(--bg); }

/* ---- SD card updater (Firmware tab) */
.sd { margin-bottom: 36px; }
.sd-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sd h2, .fw-h { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.fw-h { margin-top: 8px; }
.sd-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 16px 18px; margin: 14px 0; }
.sd-card h3 { font-size: 16px; margin: 0; }
.sd-card .where { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.sd-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 14px 0; font-size: 14px; }
.sd-facts dt { color: var(--muted); }
.sd-facts dd { margin: 0; }
.sd-alert { border-left: 3px solid var(--amber); padding: 6px 12px; margin: 0 0 14px; font-size: 14px; line-height: 1.5; max-width: 72ch; }
.sd-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sd-actions button.go { min-width: 0; }
.sd-panel { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.sd-panel h4 { font-size: 14px; margin: 0 0 8px; }
.sd-panel .pick { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.sd-panel input[type=file] { display: none; }
.sd-files { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 10px; }
.sd-files td, .sd-files th { text-align: left; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--line); }
.sd-files th { color: var(--muted); font-weight: 500; }
.sd-files .hash { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
.sd-confirm { background: var(--raise); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; font-size: 14px; line-height: 1.5; }
.sd-confirm .sd-actions { margin-top: 10px; }
.sd-result { margin-top: 12px; font-size: 14px; line-height: 1.55; }
.sd-result ul { margin: 6px 0; padding-left: 20px; }
.sd details { margin-top: 12px; font-size: 14px; }
.sd details summary { cursor: pointer; color: var(--muted); }
.sd details[open] summary { margin-bottom: 8px; }
.sd .inline { display: inline-flex; gap: 8px; align-items: center; margin: 6px 16px 6px 0; }
.sd-other { margin-top: 18px; }
.sd-other h4 { font-size: 14px; font-weight: 500; color: var(--muted); margin: 0 0 6px; }
.sd-other .vol { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sd-find { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 10px; }
.sd-find label { flex: 1 1 280px; max-width: 460px; }
.btnlike { display: inline-flex; flex-direction: row; }
.sd-progress { margin-top: 12px; max-width: 520px; }
.sd-progress-label { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.sd-track { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.sd-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .2s linear; }
@media (prefers-reduced-motion: reduce) { .sd-fill { transition: none; } }
.sd-panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.sd-panel-head h4 { margin: 0; }
.sd-panel .src { padding: 10px 0; border-bottom: 1px solid var(--line); }
.sd-panel .src h5 { font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.sd-panel .src .note { margin: 0 0 8px; }
.sd-panel .src-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.sd-panel .src-row select { flex: 1 1 320px; max-width: 640px; }
.sd-panel .pick { margin-bottom: 0; }
[data-staged] { margin-top: 12px; }
.traffic td.msg { white-space: normal; min-width: 18ch; max-width: 70ch; overflow-wrap: anywhere; }

/* ---- IQ recording */
button.rec { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; font-variant-numeric: tabular-nums; }
button.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: #c9655a; box-shadow: 0 0 0 2px color-mix(in srgb, #c9655a 25%, transparent); }
button.rec.on { border-color: #c9655a; color: var(--text); }
button.rec.on .dot { animation: rec-pulse 1.6s ease-in-out infinite; }
@keyframes rec-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { button.rec.on .dot { animation: none; } }
.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.45; }
.rec-actions { display: flex; flex-direction: column; gap: 4px; }
.rec-actions button { padding: 3px 10px; font-size: 13px; }

/* ---- the site's wrapper around the app (demo only) */
body.demo { display: flex; flex-direction: column; height: 100dvh; }
body.demo .app { height: auto; flex: 1 1 auto; min-height: 0; }
.site-nav { --bg: #f3f5f7; --fg: #141a21; --muted: #56616e; --line: #d6dce3; --accent: #157a70; flex: none; }
.demo-banner { flex: none; background: var(--raise); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.5; padding: 7px 16px; }
.demo-banner p { margin: 0 auto; max-width: 1180px; }
.demo-banner strong { color: var(--text); font-weight: 600; }
.demo-banner .short { display: none; }
@media (max-width: 760px) {
  .demo-banner .short { display: inline; }
  .demo-banner .long { display: none; }
  body.demo { display: block; height: auto; }
  body.demo .app { height: 100dvh; }
}
