/* Dark theme, but tuned for outdoor legibility rather than low-light comfort:
   near-white text on near-black, saturated status colours, no grey-on-grey. */

:root {
  --fg: #f1f3f4;
  --fg-dim: #b8bcc0;
  --bg: #16191c;
  --bg-raised: #22262a;
  --bg-sunken: #0e1113;
  --line: #454b52;
  --alert: #ff6b5e;
  --alert-bg: #4a1512;
  --alert-solid: #b3261e;
  --ok: #7ee2a8;
  --warn: #ffd166;
  --accent: #8ab4f8;
}

* { box-sizing: border-box; }

/* The `hidden` attribute only implies `display: none`, so any explicit
   `display` rule (e.g. .arm-overlay's flex) silently overrides it and the
   element stays visible. Everything here toggled via `.hidden` needs this. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
}

button, input, label { touch-action: manipulation; }
button, label span { user-select: none; }

/* ---- header ---- */

.bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  min-height: 48px;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
}

.pill {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.ok   { background: #123a24; color: var(--ok); }
.pill.warn { background: #3d3212; color: var(--warn); }
.pill.bad  { background: var(--alert-bg); color: var(--alert); }

.count { margin-left: auto; text-align: right; line-height: 1; }
/* Pills shrink before they wrap; the count and buttons keep their size. */
.bar .pill { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bar .count { flex: 0 0 auto; }
#audio-warn { flex: 0 0 auto; }
#inzone-count { font-size: 26px; font-weight: 800; }
#inzone-label { display: block; font-size: 11px; font-weight: 600; }
.count.alerting #inzone-count { color: var(--alert); }

.ctl {
  min-height: 44px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--fg);
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.ctl.icon { min-width: 44px; padding: 0; font-size: 18px; }
.ctl.wide { flex: 1; }
.row.buttons { gap: 6px; margin-bottom: 10px; }
#audio-warn { animation: pulse 1.6s ease-in-out infinite; }
.ctl.needs-unlock { border-color: var(--warn); color: var(--warn); }
.ctl.armed { border-color: var(--ok); color: var(--ok); }
.ctl.muted { border-color: var(--line); }

/* ---- alert banner ---- */

.banner {
  position: sticky; top: 48px; z-index: 999;
  padding: 16px 10px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #fff;
  background: var(--alert-solid);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  border-bottom: 3px solid #7a1a15;
  animation: flash 1s ease-in-out infinite;
}
@media (max-width: 420px) {
  .banner { font-size: 17px; padding: 13px 8px; }
}
@keyframes flash { 50% { background: #e8483c; } }

/* Faults are amber and slower than the red aircraft alert, so the two are
   never confused at a glance. */
.banner.fault {
  color: #1a1400;
  background: var(--warn);
  animation: faultflash 2s ease-in-out infinite;
}
@keyframes faultflash { 50% { background: #b8912f; } }

/* ---- map ---- */

/* ---- map + arm overlay ---- */

.map-wrap { position: relative; display: flex; flex: 1 1 auto; min-height: 180px; }

/* The overlay must not swallow pan/zoom gestures — only the Cancel button is
   interactive, so the map stays fully usable while placement is armed. */
.arm-overlay {
  position: absolute; inset: 0; z-index: 500;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: 10px;
  pointer-events: none;
  background: rgba(11, 87, 208, 0.14);
  box-shadow: inset 0 0 0 3px var(--accent);
}
.arm-hint {
  padding: 6px 12px;
  font-size: 14px; font-weight: 800;
  color: #fff; background: rgba(11, 87, 208, 0.92);
  border-radius: 999px;
}
.arm-overlay .ctl { pointer-events: auto; }

.ctl.armed-mode {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* The map stays light: OSM tiles are authored for light UIs, and inverting
   them muddies terrain and road colours. Leaflet's own chrome stays light to
   match the tiles rather than the surrounding dark shell. */
#map { flex: 1 1 auto; min-height: 180px; background: #e9eaed; }
.map-wrap #map { width: 100%; }
.leaflet-container { background: #e9eaed; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #ffffff; color: #111418;
}
.leaflet-popup-content { font-weight: 600; }
/* Separate the bright map from the dark shell above and below it. */
#map { border-top: 2px solid var(--line); border-bottom: 2px solid var(--line); }
.ac-pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .banner, .ac-pulse { animation: none; }
}

/* ---- settings panel ---- */

.scrim {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0, 0, 0, 0.55);
}

.panel {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1200;
  width: min(88vw, 340px);
  display: flex; flex-direction: column;
  background: var(--bg-raised);
  border-right: 2px solid var(--line);
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.5);
  transform: translateX(-100%);
  transition: transform 0.18s ease-out;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
}
.panel.open { transform: translateX(0); }

/* Right-hand drawer: same mechanics, mirrored. */
.panel-right {
  left: auto; right: 0;
  border-right: none;
  border-left: 2px solid var(--line);
  box-shadow: -4px 0 18px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px;
  font-size: 16px;
  border-bottom: 2px solid var(--line);
}

/* ---- controls ---- */

.controls { padding: 10px; }

.sec {
  margin: 16px 0 8px;
  padding-bottom: 4px;
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
}
.sec:first-child { margin-top: 0; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.row > span:first-child { min-width: 52px; }
.row > input[type=range] + output { flex: 0 0 auto; }
.controls .row > span:first-child { min-width: 116px; font-size: 13px; }
.row input[type=range] { flex: 1; height: 34px; }
.row output { min-width: 54px; font-weight: 800; text-align: right; }
.coords { flex-wrap: wrap; }
.coords input[type=text] {
  flex: 1 1 40%; min-width: 0; min-height: 44px; padding: 0 8px;
  font-size: 15px; font-weight: 600;
  color: var(--fg); background: var(--bg-sunken);
  border: 2px solid var(--line); border-radius: 8px;
}
.row input[type=range] { accent-color: var(--accent); }
.row.check input { accent-color: var(--accent); }
.row.check { gap: 10px; }
.wl-status { display: block; font-size: 11px; font-weight: 700; color: var(--fg-dim); }
.wl-status.ok   { color: var(--ok); }
.wl-status.warn { color: var(--warn); }
.wl-status.bad  { color: var(--alert); }
.row.check input { width: 22px; height: 22px; }

/* ---- aircraft list ---- */

.ac-list { flex: 1 1 auto; margin: 0; padding: 0; list-style: none; overflow-y: auto; }

.ac {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.ac.lost { opacity: 0.55; }

.ac-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ac-mid { margin-top: 1px; }
.ac-bot {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  margin-top: 4px; font-size: 13px; font-weight: 700;
}

.callsign { font-weight: 800; font-size: 15px; }
.subtle { font-size: 11px; font-weight: 600; color: var(--fg-dim); }
.dist { font-size: 20px; font-weight: 800; white-space: nowrap; }
.dist .unit { font-size: 11px; font-weight: 700; margin-left: 2px; }
.brg { white-space: nowrap; }
.alt { white-space: nowrap; }
.seen { white-space: nowrap; }
.seen.fresh { color: var(--ok); }
.seen.aging { color: var(--warn); }
.seen.old   { color: var(--alert); }
.seen.unk   { color: var(--fg-dim); }

.empty { padding: 14px 10px; font-size: 13px; font-weight: 600; color: var(--fg-dim); }

.chip {
  display: inline-block; padding: 1px 6px;
  font-size: 10px; font-weight: 800; border-radius: 4px; border: 1px solid var(--line);
}
.chip.gnd   { background: var(--bg-sunken); color: var(--fg-dim); }
.chip.unk   { background: #3d3212; color: var(--warn); }
.chip.stale { background: #3d3212; color: var(--warn); }
.chip.mlat  { background: #14294d; color: var(--accent); }
.chip.lost  { background: var(--alert-bg); color: var(--alert); }
.vs.up { color: var(--ok); }
.vs.down { color: var(--accent); }
.badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.badges:empty { display: none; }

/* ---- disclaimer ---- */

.disclaimer {
  flex: 0 0 auto;
  padding: 10px; font-size: 11px; font-weight: 600; line-height: 1.35;
  color: var(--warn); background: #2a2412; border-top: 2px solid var(--line);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* On a wide screen the list sits beside the map rather than over it, so the
   map is inset instead of covered. Same .open class as the left panel — one
   convention, not two. */
@media (min-width: 900px) {
  .panel-right { box-shadow: none; }
  .panel-right.open ~ .map-wrap,
  body.list-open .map-wrap { margin-right: min(88vw, 340px); }
  body.list-open .scrim { display: none !important; }
}

.bar { position: sticky; }

body.mock-mode .bar::after {
  content: "MOCK";
  position: absolute; right: 4px; top: 2px;
  font-size: 9px; font-weight: 800; color: var(--alert);
}
