/* ---- color tokens (dark default; auto-light via prefers-color-scheme) --
 * `color-scheme` tells the browser our page supports dark + light, which
 * makes native form widgets (inputs, selects, scrollbars, checkboxes) honor
 * our custom dark backgrounds instead of forcing OS-default light theme. */
:root {
  color-scheme: dark;
  accent-color: #2563eb;
  --bg: #111;
  --panel-bg: #1a1a1a;
  --border: #2a2a2a;
  --text: #ddd;
  --text-strong: #fff;
  --text-muted: #888;
  --input-bg: #222;
  --input-border: #333;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-disabled: #444;
  --secondary-bg: #2a2a2a;
  --secondary-bg-hover: #333;
  --secondary-border: #3a3a3a;
  --secondary-disabled-text: #666;
  --danger: #7f1d1d;
  --danger-hover: #991b1b;
  --danger-text: #fee;
  --selected-bg: #1e3a8a;
  --selected-border: #2563eb;
  --legend-border: #333;
  --status-error: #f87171;
  --status-done: #4ade80;
  --rep-form-bg: #1f1f1f;
  --rep-hover: #222;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f5f5f5;
    --panel-bg: #ffffff;
    --border: #e0e0e0;
    --text: #222;
    --text-strong: #000;
    --text-muted: #666;
    --input-bg: #ffffff;
    --input-border: #ccc;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-disabled: #cbd5e1;
    --secondary-bg: #f0f0f0;
    --secondary-bg-hover: #e5e5e5;
    --secondary-border: #d0d0d0;
    --secondary-disabled-text: #aaa;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-text: #fff;
    --selected-bg: #dbeafe;
    --selected-border: #2563eb;
    --legend-border: #999;
    --status-error: #dc2626;
    --status-done: #16a34a;
    --rep-form-bg: #fafafa;
    --rep-hover: #f0f0f0;
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--text); background: var(--bg);
}

#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto 1fr;
}

/* Org-branding banner across the top of the app. Light background fixed
   for both themes because the SVG uses navy (#1a3a5c) text that is
   unreadable against the dark page background. */
#site-header {
  grid-column: 1 / -1;
  background: #f5f5f5;
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#site-header img { display: block; height: 60px; width: auto; }

#panel {
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  display: flex; flex-direction: column;
}
#panel h1 { margin: 0 0 8px; font-size: 18px; letter-spacing: 0.04em; color: var(--text-strong); }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

label { display: block; margin: 8px 0 4px; font-size: 12px; color: var(--text-muted); }
input, select, textarea {
  appearance: none; -webkit-appearance: none;
  width: 100%; padding: 6px 8px;
  background: var(--input-bg) !important;
  color: var(--text) !important;
  border: 1px solid var(--input-border); border-radius: 4px; font-size: 13px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}
input[type="color"] { padding: 2px; height: 30px; }
input[type="checkbox"] {
  appearance: auto; -webkit-appearance: auto;   /* let accent-color theme it */
  width: auto !important;
}
select { background-image: linear-gradient(to bottom, transparent, transparent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row label { margin-top: 8px; }

button {
  appearance: none; -webkit-appearance: none;
  padding: 8px 10px; border: 0; border-radius: 4px;
  font-weight: 600; cursor: pointer; font-size: 13px; font-family: inherit;
  color: var(--text-strong);
}
button.primary { background: var(--primary); color: white; }
button.primary:hover { background: var(--primary-hover); }
button.primary:disabled { background: var(--primary-disabled); cursor: progress; }
button.secondary {
  background: var(--secondary-bg); color: var(--text);
  border: 1px solid var(--secondary-border);
}
button.secondary:hover { background: var(--secondary-bg-hover); }
button.secondary:disabled { color: var(--secondary-disabled-text); cursor: not-allowed; }
button.secondary.active { background: var(--primary); color: white; border-color: var(--primary); }
button.danger { background: var(--danger); color: var(--danger-text); }
button.danger:hover { background: var(--danger-hover); }
button.small { padding: 4px 8px; font-size: 12px; }

#go, #rep-coverage-btn { width: 100%; margin-top: 10px; }

.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; font-size: 12px; color: var(--text);
}
.checkbox-row input[type=checkbox] { width: auto; margin: 0; }

.status-pill {
  margin: 0 0 8px; padding: 4px 8px; border-radius: 4px;
  background: var(--input-bg); border: 1px solid var(--input-border);
  font-family: ui-monospace, monospace; font-size: 11px;
}
.status-pill.ok { color: var(--status-done); }
.status-pill.warn { color: #fbbf24; }
.status-pill.error { color: var(--status-error); }
.hint { margin: 6px 0 4px; line-height: 1.45; }
.hint code {
  background: var(--input-bg); color: var(--text);
  padding: 1px 4px; border-radius: 3px;
  border: 1px solid var(--input-border);
  font-size: 11px;
}

.progress-wrap {
  margin-top: 10px;
  height: 18px; position: relative;
  background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: 4px; overflow: hidden;
}
.progress-bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(to right, #2563eb, #06b6d4);
  transition: width 0.4s ease-out;
}
.progress-text {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-strong); text-shadow: 0 0 3px rgba(0,0,0,0.6);
  font-family: ui-monospace, monospace; font-weight: 600;
  /* The phase string can get long ("[work-queue] 7/12 passes done
     across 2 GPUs — 58%"). Keep it on one line and ellipsize when
     it would otherwise overflow the narrow sidebar. font-size shrinks
     as well so progress detail stays readable in the 280-340 px tab. */
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}

#status { margin-top: 10px; min-height: 1.2em; }
#status.error { color: var(--status-error); }
#status.done { color: var(--status-done); }

/* ---- tabs ---------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin: 4px 0 12px; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; color: var(--text-muted); padding: 7px 12px;
  border-radius: 4px 4px 0 0; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text-strong); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- legend -------------------------------------------------------- */
.legend { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.legend h3 { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.08em; }
.legend ul { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.legend li { display: flex; align-items: center; margin: 3px 0; }
.legend li span {
  display: inline-block; width: 16px; height: 12px; margin-right: 8px;
  border: 1px solid var(--legend-border);
}

/* ---- repeater list / form ----------------------------------------- */
.rep-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.rep-list {
  max-height: 240px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px; margin-bottom: 12px;
}
.rep-item {
  padding: 6px 8px; border-radius: 3px; cursor: pointer;
  border: 1px solid transparent; margin: 2px 0;
}
.rep-item:hover { background: var(--rep-hover); }
.rep-item.selected { background: var(--selected-bg); border-color: var(--selected-border); }
.rep-row { display: flex; align-items: center; gap: 6px; }
.rep-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; border: 1px solid var(--text-strong); flex: 0 0 auto;
}
.rep-multi-cb { flex: 0 0 auto; cursor: pointer; }
.opacity-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; margin: 6px 0 10px;
}
.opacity-row input[type=range] { flex: 1; }
.rep-multi-toolbar { display: flex; gap: 6px; margin: 8px 0 4px; }
.rep-multi-toolbar > #rep-multi-btn { flex: 1; }

.rep-form {
  padding: 10px; background: var(--rep-form-bg);
  border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px;
}
.rep-form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.rep-form button[type=submit] { width: 100%; margin-top: 10px; }

#map { width: 100%; height: 100%; }

/* MapLibre popup */
.maplibregl-popup-content { background: var(--panel-bg); color: var(--text); border: 1px solid var(--border); }
.maplibregl-popup-tip { border-top-color: var(--panel-bg) !important; }

/* Antenna pattern polar plots — side-by-side H-plane (azimuth, top-down)
   + E-plane (elevation, side cut). 3e.4. */
.polar-plot-wrap {
  display: flex; justify-content: center; gap: 10px;
  margin: 8px 0;
}
.polar-plot-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.polar-plot-caption {
  font-size: 10px; color: var(--muted);
}
#antenna-polar-plot,
#antenna-polar-plot-v {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.polar-grid {
  fill: none; stroke: var(--border); stroke-width: 0.5; stroke-dasharray: 2 2;
}
.polar-axis {
  fill: none; stroke: var(--border); stroke-width: 0.5;
}
.polar-shape {
  fill: rgba(99, 162, 255, 0.25); stroke: rgb(99, 162, 255); stroke-width: 1.2;
}
.polar-label {
  font-size: 9px; fill: var(--muted); text-anchor: middle;
  dominant-baseline: middle; user-select: none;
}
.polar-boresight-arrow {
  stroke: rgb(255, 100, 80); stroke-width: 1.5; fill: rgb(255, 100, 80);
}
.polar-horizon-line {
  stroke: rgb(255, 180, 0); stroke-width: 0.8; stroke-dasharray: 3 2;
}

/* Coverage diff / what-if panel ------------------------------------- */
.diff-panel {
  margin-top: 14px; padding: 10px;
  background: var(--rep-form-bg);
  border: 1px solid var(--border); border-radius: 6px;
}
.diff-panel summary {
  cursor: pointer; font-weight: 600; color: var(--text-strong);
  margin-bottom: 6px; user-select: none;
}
.diff-panel summary::marker { color: var(--text-muted); }
.diff-panel .rep-multi-toolbar { margin-top: 8px; }
.diff-legend {
  display: flex; gap: 1px; margin-top: 8px;
  border: 1px solid var(--legend-border); border-radius: 3px;
  overflow: hidden;
}
.diff-legend-stripe {
  flex: 1; height: 14px; min-width: 8px;
}
.diff-legend-stripe[title]:hover { outline: 1px solid var(--text-strong); }
#diff-status.error { color: var(--status-error); }
#diff-status.ok { color: var(--status-done); }

/* External overlays (FCC sites, future RepeaterBook, ...) ------------- */
.external-overlays {
  margin: 8px 0 12px;
  padding: 8px 10px;
  background: var(--rep-form-bg);
  border: 1px solid var(--border); border-radius: 4px;
}
.external-overlays .checkbox-row { margin-top: 0; }
#fcc-sites-status.error { color: var(--status-error); }
#fcc-sites-status.ok { color: var(--status-done); }
#fcc-sites-status.warn { color: #fbbf24; }
#hillshade-status.error { color: var(--status-error); }
#hillshade-status.ok { color: var(--status-done); }

/* Color → RSSI legend pinned to top-right of the map, below MapLibre's
   NavigationControl (which sits at top:10px, ~108 px tall with zoom +
   compass + pitch). Static palette matching backend colormap.py. */
.rssi-ref {
  position: absolute; top: 130px; right: 10px;
  z-index: 5;
  background: rgba(20, 20, 20, 0.85);
  color: #ddd;
  border: 1px solid #2a2a2a; border-radius: 6px;
  padding: 6px 8px; min-width: 110px;
  font-family: ui-monospace, monospace; font-size: 11px;
  pointer-events: none;        /* let map drag/click through */
}
.rssi-ref-title {
  font-size: 10px; color: #888; text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 4px;
}
.rssi-ref ul {
  list-style: none; padding: 0; margin: 0;
}
.rssi-ref li {
  display: flex; align-items: center; gap: 6px; line-height: 1.3;
}
.rssi-ref li span.swatch {
  display: inline-block; width: 14px; height: 10px;
  border: 1px solid #444; flex: 0 0 auto;
}

/* AOI polygon controls ------------------------------------------------ */
.aoi-controls { margin: 10px 0; }
.aoi-controls .rep-multi-toolbar { margin-bottom: 4px; }
#aoi-status.error { color: var(--status-error); }
#aoi-status.ok { color: var(--status-done); }
#aoi-status.warn { color: #fbbf24; }

/* HF/Skip tab --------------------------------------------------------- */
#sw-status.error { color: var(--status-error); }
#sw-status.ok { color: var(--status-done); }
#skywave-solar-status.error { color: var(--status-error); }
#skywave-solar-status.ok { color: var(--status-done); }
#skywave-solar-status.warn { color: #fbbf24; }
.rssi-ref li span.swatch {
  display: inline-block; width: 14px; height: 10px;
  border: 1px solid #444; flex: 0 0 auto; border-radius: 2px;
}
