:root {
  --bg: #0b1210;
  --bg-panel: #121c19;
  --bg-elevated: #182622;
  --border: #243833;
  --text: #e7f0ec;
  --muted: #8aa399;
  --accent: #3ddeb0;
  --accent-dim: #1f8f70;
  --aprs: #5b9dff;
  --ais: #37d6c6;
  --ism: #f0b429;
  --private: #c084fc;
  --adsb: #ff7a59;
  --danger: #ff5d6c;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

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

#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  min-height: 560px;
}

/* —— Sidebar —— */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  background:
    radial-gradient(ellipse 120% 60% at 0% 0%, rgba(61, 222, 176, 0.08), transparent 50%),
    var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 500;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent-dim), #0d3d32);
  color: var(--accent);
  font-size: 1.25rem;
  box-shadow: inset 0 0 0 1px rgba(61, 222, 176, 0.3);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
}

.region {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 500;
}

.muted {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  user-select: none;
}

.toggle-row:hover {
  background: rgba(61, 222, 176, 0.06);
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  cursor: pointer;
  flex: 1;
}

.toggle-row input {
  accent-color: var(--accent);
}

.toggle-row .count {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.field select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font-family: var(--font);
  font-size: 0.88rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.84rem;
  color: var(--text);
  margin-top: 0.35rem;
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
}

.source-stats {
  display: grid;
  gap: 0.4rem;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.5rem;
  font-size: 0.8rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(36, 56, 51, 0.7);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .label {
  color: var(--text);
}

.stat-row .value {
  font-family: var(--mono);
  color: var(--accent);
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.84rem;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.dot.aprs { background: var(--aprs); }
.dot.ais { background: var(--ais); }
.dot.ism { background: var(--ism); }
.dot.private { background: var(--private); }
.dot.adsb { background: var(--adsb); }
.dot.fm { background: #a3e635; }
.dot.tropo { background: #f472b6; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.sidebar-foot a {
  color: var(--accent);
  text-decoration: none;
}

.sidebar-foot a:hover {
  text-decoration: underline;
}

.sidebar-foot p {
  margin: 0.2rem 0;
}

/* —— Map —— */
#map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #0a1412;
}

#map-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
  max-width: min(100% - 24px, 480px);
}

.hud-chip,
.hud-btn {
  background: rgba(18, 28, 25, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-family: var(--font);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

#hud-opening.opening-quiet { border-color: #64748b; color: #94a3b8; }
#hud-opening.opening-elevated { border-color: #eab308; color: #fde047; }
#hud-opening.opening-active { border-color: #f97316; color: #fdba74; }
#hud-opening.opening-strong { border-color: #f472b6; color: #f9a8d4; }
#hud-opening.opening-extreme { border-color: #ef4444; color: #fca5a5; font-weight: 600; }

.hud-btn {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
}

.hud-btn:hover {
  border-color: var(--accent-dim);
  background: rgba(31, 143, 112, 0.2);
}

.detail {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1000;
  width: min(360px, calc(100% - 24px));
  background: rgba(18, 28, 25, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.detail.hidden {
  display: none;
}

.detail h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.detail .meta {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--mono);
  margin-bottom: 0.6rem;
}

.detail .metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.84rem;
}

.detail .metrics dt {
  color: var(--muted);
  font-size: 0.72rem;
  margin: 0;
}

.detail .metrics dd {
  margin: 0 0 0.25rem;
  font-family: var(--mono);
  font-weight: 500;
}

.detail .close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.detail .badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.badge.aprs { background: rgba(91, 157, 255, 0.2); color: var(--aprs); }
.badge.ais_buoy { background: rgba(55, 214, 198, 0.2); color: var(--ais); }
.badge.ism { background: rgba(240, 180, 41, 0.2); color: var(--ism); }
.badge.private_csv { background: rgba(192, 132, 252, 0.2); color: var(--private); }
.badge.adsb { background: rgba(255, 122, 89, 0.2); color: var(--adsb); }
.badge.fm_rssi { background: rgba(163, 230, 53, 0.2); color: #a3e635; }
.badge.tropo_dx { background: rgba(244, 114, 182, 0.2); color: #f472b6; }

/* Leaflet overrides */
.leaflet-container {
  font-family: var(--font);
  background: #0a1412;
}

.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-attribution {
  background: rgba(11, 18, 16, 0.75) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.wx-marker {
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #06120e;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.wx-marker .barb {
  position: absolute;
  width: 2px;
  height: 14px;
  background: currentColor;
  transform-origin: bottom center;
  bottom: 50%;
  left: calc(50% - 1px);
  opacity: 0.9;
}

.wx-marker.aircraft {
  border-radius: 4px;
  transform: rotate(0deg);
}

.wx-marker.prop {
  border-radius: 6px;
  border-style: solid;
  font-size: 9px;
}

/* Region outline */
.region-rect {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  fill: rgba(61, 222, 176, 0.04);
}

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
  }

  #sidebar {
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #map-wrap {
    min-height: 55vh;
  }
}

/* —— Live data additions —— */
.small { font-size: 0.75rem; }
.wx-marker.stale { opacity: 0.5; filter: saturate(0.5); }

.collectors { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; }
.col-group { margin-top: 0.35rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.col-row { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 0.45rem; }
.col-row a { color: var(--text); text-decoration: none; }
.col-row a:hover { color: var(--accent); }
.col-val { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.status-dot.ok { background: #4ade80; }
.status-dot.bad { background: transparent; border: 2px solid #f87171; }

.diamond, .square { display: inline-block; width: 9px; height: 9px; vertical-align: middle; }
.diamond { background: #e2e8f0; transform: rotate(45deg); }
.square { background: #94a3b8; }
.rx-sym { color: var(--accent); font-size: 0.8rem; }

.aton { width: 9px; height: 9px; margin: 1.5px; background: #e2e8f0; border: 1px solid #0b1210; transform: rotate(45deg); }
.aton.virtual { background: transparent; border: 1.5px solid #e2e8f0; }
.basestn { width: 9px; height: 9px; margin: 1.5px; background: #94a3b8; border: 1px solid #0b1210; }
.rx-site { font-size: 16px; line-height: 16px; text-align: center; text-shadow: 0 0 3px #000, 0 0 6px #000; }
.rx-site.up { color: var(--accent); }
.rx-site.down { color: #f87171; }
.rx-pop { margin-bottom: 0.4rem; font-size: 0.8rem; }
.rx-pop .ok { color: #16a34a; }
.rx-pop .bad { color: #dc2626; }

.detail { max-height: calc(100vh - 6rem); overflow-y: auto; }
.history h4 { margin: 0.8rem 0 0.3rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.spark { margin-bottom: 0.5rem; }
.spark-head, .spark-foot { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); }
.spark-head .spark-val { font-family: var(--mono); color: var(--text); }
.spark-foot { font-family: var(--mono); }
.spark-tip { color: var(--text); }
.spark svg { display: block; cursor: crosshair; touch-action: none; }
.osm-dark { filter: invert(100%) hue-rotate(180deg) brightness(0.9) contrast(0.9) saturate(0.6); }
.hud-chip[hidden] { display: none; }
