:root {
  --bg: #0b1218;
  --panel: #111b23;
  --card: #15222c;
  --line: #22323e;
  --text: #dbe6ec;
  --muted: #8aa0ad;
  --accent: #5fd4a6;
  --warn: #f0b35a;
  --bad: #ef7d72;
  --fix: #7cc7ff;
  --hyp: #c79bff;
  --land: #17232c;
  --sea: #0b1218;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover { border-color: var(--accent); }
button.primary { background: #1d3b33; border-color: #2f6b58; }
button svg { width: 16px; height: 16px; }
.icon-button { padding: 6px; }
select, input[type="text"], input[type="password"], input[type="url"] { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 100%; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 1000; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .02em; }
.brand svg { color: var(--accent); }
.brand small { color: var(--muted); font-weight: 500; }
.modes { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.modes button { border: 0; border-radius: 0; background: transparent; }
.modes button[aria-selected="true"] { background: #1d3b33; color: #e7fff6; }
.status-line { margin-left: auto; display: flex; align-items: center; gap: 14px; min-width: 0; }
.status { color: var(--muted); font: 12px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.next-window { font: 12px var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64ch; flex: none; }
.next-window b { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }
.next-window .targets { color: var(--muted); }
.next-window.paused { color: var(--warn); flex: 0 1 auto; }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.status.ok .dot { background: var(--accent); }
.status.warn .dot { background: var(--warn); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: calc(100vh - 53px); }
.map-card { position: relative; min-height: 420px; }
#map { position: absolute; inset: 0; background: var(--sea); }
.leaflet-container { background: var(--sea); font: inherit; }
.map-overlay { position: absolute; left: 12px; right: 12px; z-index: 500; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.map-overlay.top { top: 12px; justify-content: flex-end; }
.map-overlay.bottom { bottom: 12px; }
.badge { font: 600 11px var(--mono); letter-spacing: .06em; padding: 4px 8px; border-radius: 6px; background: #0f2a22; color: var(--accent); border: 1px solid #275a4a; }
.badge.replay { background: #2b2210; color: var(--warn); border-color: #6b5222; }
.switch { background: rgba(17, 27, 35, .9); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.legend { background: rgba(17, 27, 35, .9); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); width: max-content; max-width: calc(100% - 24px); }
.legend span { display: inline-flex; align-items: center; gap: 5px; margin-right: 8px; }
.key { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.key.track { border: 2px solid var(--accent); background: rgba(95, 212, 166, .25); }
.key.fix { border: 1.5px solid var(--fix); }
.key.hyp { border: 1.5px dashed var(--hyp); }
.key.rx-used { background: var(--accent); border-radius: 50%; width: 10px; }
.key.rx-heard { border: 2px solid var(--muted); border-radius: 50%; width: 10px; }

.panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.filters label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card h2 { font-size: 13px; margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; }
.card h2 small { color: var(--muted); font-weight: 500; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 300px; overflow-y: auto; }
.list li button { width: 100%; justify-content: space-between; text-align: left; background: transparent; border-color: transparent; padding: 6px 8px; }
.list li button:hover, .list li button.active { border-color: var(--line); background: #1a2a35; }
.list .call { font-weight: 650; }
.list .meta { color: var(--muted); font: 11px var(--mono); }
.list.compact li button { padding: 4px 8px; }
.empty { color: var(--muted); margin: 4px 0 0; font-size: 12px; }
.table-scroll { overflow-x: auto; }
table.stats { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.stats th, table.stats td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--muted); font-weight: 500; }
/* The row label stays visible while the wide statistics table scrolls sideways. */
.card table.stats th:first-child, .card table.stats td:first-child { position: sticky; left: 0; background: var(--card); box-shadow: 1px 0 0 var(--line); }
table.stats td.note { white-space: normal; text-align: left; min-width: 18em; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.replay p { margin: 0 0 8px; color: var(--muted); font-size: 12px; }

.inspector { position: fixed; top: 64px; left: 12px; width: min(420px, calc(100vw - 24px)); max-height: calc(100vh - 140px); overflow-y: auto; z-index: 1100; background: rgba(17, 27, 35, .97); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45); }
.inspector h3 { margin: 0; font-size: 16px; }
.inspector .sub { color: var(--muted); font: 12px var(--mono); margin: 2px 0 10px; }
.inspector .close { position: absolute; top: 8px; right: 8px; }
.inspector dl { display: grid; grid-template-columns: 120px 1fr; gap: 3px 10px; margin: 0 0 10px; font-size: 12.5px; }
.inspector dt { color: var(--muted); }
.inspector dd { margin: 0; }
.inspector h4 { margin: 12px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.status-pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 650; }
.status-pill.located { background: #173b30; color: var(--accent); }
.status-pill.undetermined { background: #3a2f17; color: var(--warn); }
.status-pill.none { background: #2b2b2b; color: var(--muted); }
.rx-row, .pair-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; font-size: 12px; padding: 3px 0; border-bottom: 1px solid #1d2b35; }
.pair-row { grid-template-columns: 1fr auto auto; font-family: var(--mono); font-size: 11.5px; }
.rx-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); }
.rx-dot.used { background: var(--accent); border-color: var(--accent); }
.rx-dot.heard { border-color: var(--fix); }
.note { color: var(--muted); font-size: 12px; }
.bad { color: var(--bad); }
.good { color: var(--accent); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(620px, calc(100vw - 24px)); padding: 14px 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; }
.modal-head h2 { margin: 0; font-size: 16px; }
#modal-body label { display: grid; gap: 4px; margin: 8px 0; font-size: 12px; color: var(--muted); }
#modal-body p, #modal-body li { color: #c4d3db; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #2a1f1d; border: 1px solid #6a3b35; color: #ffd8d2; padding: 8px 14px; border-radius: 9px; z-index: 2000; max-width: calc(100vw - 32px); }

.city { color: #5f7684; font-size: 11px; white-space: nowrap; }
.rx-icon { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); background: rgba(11, 18, 24, .6); }
.rx-icon.used { background: var(--accent); border-color: #b6f3dd; }
.rx-icon.heard { border-color: var(--fix); }
.tx-label { color: #e8fff7; font: 650 11px system-ui; text-shadow: 0 0 3px #000, 0 0 6px #000; white-space: nowrap; }

/* Leaflet's light controls restyled for the dark map. */
.leaflet-bar, .leaflet-touch .leaflet-bar { border: 1px solid var(--line); box-shadow: none; }
.leaflet-bar a { background: var(--card); color: var(--text); border-bottom-color: var(--line); }
.leaflet-bar a:hover, .leaflet-bar a:focus { background: #1a2a35; color: #fff; }
.leaflet-bar a.leaflet-disabled { background: var(--panel); color: #4a5d69; }
.leaflet-container .leaflet-control-scale-line { background: rgba(17, 27, 35, .85); color: var(--muted); border-color: var(--muted); text-shadow: none; }
.leaflet-container .leaflet-control-attribution { background: rgba(17, 27, 35, .85); color: var(--muted); }
.leaflet-container .leaflet-control-attribution a { color: var(--muted); }

.credit { margin-top: auto; padding: 2px 4px 0; font-size: 11px; color: #5f7684; }
.credit a { color: inherit; text-decoration-color: var(--line); }
.credit a:hover { color: var(--text); }

@media (max-width: 860px) {
  /* minmax(0, …): the wide statistics table scrolls inside its card instead of widening the page. */
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  #help { margin-left: auto; }
  .status-line { order: 3; flex: 1 1 100%; margin-left: 0; justify-content: space-between; }
  .map-card { height: 62vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .filters { grid-template-columns: 1fr 1fr; }
  .legend { display: none; }
  .inspector { top: auto; bottom: 0; left: 0; width: 100vw; max-height: 60vh; border-radius: 12px 12px 0 0; }
}
@media (max-width: 420px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand small { display: none; }
  .filters { grid-template-columns: 1fr; }
  .next-window .targets { display: none; }
}
