/* SkyTrace — base layout & chrome (dark aviation theme) */
:root {
  color-scheme: dark; /* native selects, inputs, scrollbars follow the dark theme */
  --tb-h: 52px;       /* live topbar height (kept in sync by js/ui.js) — offsets #main/#sidebar */
  --bg: #0b0e14;
  --bg2: #11151f;
  --panel: #141926;
  --panel2: #1a2032;
  --line: #232b40;
  --line2: #2e3854;
  --txt: #dbe4f3;
  --txt2: #8fa0bd;
  --txt3: #5f6f8f;
  --acc: #4da3ff;
  --acc2: #7fd4a8;
  --warn: #fbbf24;
  --bad: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px;
  background: var(--bg); color: var(--txt);
  overflow: hidden; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
a { color: var(--acc); }

/* Keyboard focus visibility (was missing — keyboard users could not see focus) */
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
/* Text fields already announce focus via a coloured border — no extra ring needed */
#searchInput:focus-visible, #listSearch:focus-visible, .accbody input:focus-visible,
.accbody select:focus-visible, .fleet-add input:focus-visible, .fleet-add select:focus-visible { outline: none; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.mono { font-family: var(--mono); font-size: 12px; }
.count { color: var(--txt2); font-weight: 600; font-size: 12px; }

/* ── Top bar ─────────────────────────────────────────── */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: 52px; z-index: 1200;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: linear-gradient(180deg, #10141d, #0d1118);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: .2px; white-space: nowrap; }
.brand b { color: var(--acc); font-weight: 700; }
.brand h1 { margin: 0; font-size: inherit; font-weight: 600; letter-spacing: .2px; white-space: nowrap; }
.searchwrap { position: relative; flex: 1 1 340px; max-width: 460px; }
#searchInput {
  width: 100%; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--bg2); color: var(--txt); outline: none;
}
#searchInput:focus { border-color: var(--acc); }
#searchResults {
  position: absolute; top: 38px; left: 0; right: 0; z-index: 1300;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
#searchResults .sr {
  display: flex; gap: 8px; align-items: baseline; padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
#searchResults .sr:hover { background: var(--panel2); }
#searchResults .sr b { color: var(--acc); }
#searchResults .sr .dim { color: var(--txt3); font-size: 12px; }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.tbtn {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--txt2); cursor: pointer; font-weight: 600; font-size: 13px;
}
.tbtn:hover { color: var(--txt); background: var(--panel2); }
.tbtn.active { color: var(--txt); background: var(--panel2); border-color: var(--line2); }
.topright { display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 11px; font-weight: 700; letter-spacing: .4px; padding: 4px 10px;
  border-radius: 999px; background: var(--panel2); color: var(--txt2); border: 1px solid var(--line2);
  white-space: nowrap;
}
.chip.ok { color: #9ff2c4; border-color: #1f5c40; background: #10231c; }
.chip.sim { color: #ffd98a; border-color: #6b5416; background: #241d0c; }
.chip.err { color: #ffb3b3; border-color: #6b1f1f; background: #241010; }

.ibtn {
  height: 32px; min-width: 32px; padding: 0 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line2); background: var(--panel2); color: var(--txt); font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.ibtn:hover { border-color: var(--acc); }
.ibtn.wide { width: 100%; height: 34px; justify-content: flex-start; gap: 8px; }
.ibtn.on { border-color: var(--acc); color: var(--acc); }
/* Close button: an ordinary in-flow flex item, so the header's
   align-items:center keeps it vertically centred on the title row.
   (The old position:absolute top:10px made the ✕ sit ~6px lower than the
   "Menu & controls" title and overlap the header divider; in the help modal,
   whose header is not a positioned ancestor, it escaped to the screen corner.) */
.ibtn.close { flex: 0 0 auto; margin-left: auto; }

.sbtns { display: grid; gap: 6px; margin-bottom: 8px; }

/* ── Sidebar ─────────────────────────────────────────── */
#sidebar {
  position: fixed; top: var(--tb-h, 52px); bottom: 26px; left: 0; width: 300px; z-index: 1100;
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain; padding: 10px;
  transform: translateX(-100%); transition: transform .22s ease;
}
#sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
.sb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 2px 8px; font-size: 13px; color: var(--txt);
  border-bottom: 1px solid var(--line); margin-bottom: 8px;
  position: sticky; top: -10px; background: var(--panel); z-index: 3;
  margin-top: -10px; padding-top: 12px; margin-left: -10px; margin-right: -10px; padding-left: 12px; padding-right: 10px;
}
.acc { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: var(--bg2); overflow: hidden; }
.acc h2 {
  margin: 0; padding: 10px 12px; font-size: 13px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; color: var(--txt); font-weight: 600;
}
.acc h2 .car { margin-left: auto; color: var(--txt3); transition: transform .15s; }
.acc.open h2 .car { transform: rotate(180deg); }
.acc h2 .info {
  flex: 0 0 auto; width: 17px; height: 17px; margin-left: -2px; padding: 0;
  border-radius: 50%; border: 1px solid var(--line2); background: transparent;
  color: var(--txt3); font-size: 10px; line-height: 15px; cursor: pointer; text-align: center;
}
.acc h2 .info:hover { color: var(--acc); border-color: var(--acc); }

/* Sidebar long-form content (About / FAQ) + site nav + share */
.faq-q { font-size: 12.5px; font-weight: 700; color: var(--txt); margin: 12px 0 3px; }
.faq-a, .about-p { font-size: 12.5px; color: var(--txt2); line-height: 1.55; margin: 3px 0 6px; }
.faq-a code, .about-p code { color: var(--txt); background: var(--panel2); padding: 0 4px; border-radius: 4px; }
.site-nav {
  margin-top: 10px; padding: 10px 2px 4px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 6px 12px;
}
.sn-t {
  flex-basis: 100%; font-size: 11px; color: var(--txt3); text-transform: uppercase;
  letter-spacing: .6px; font-weight: 600;
}
.site-nav a { font-size: 12.5px; color: var(--acc); text-decoration: none; }
.site-nav a:hover { text-decoration: underline; }
.share-row { margin-top: 12px; }
.share-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* Airport arrivals/departures link grid (About section) */
.apt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; margin: 8px 0; }
.apt-grid .apt { font-size: 12.5px; color: var(--txt2); display: flex; gap: 5px; align-items: baseline; flex-wrap: wrap; }
.apt-grid .apt b { color: var(--txt); font-weight: 600; }
.apt-grid .apt a { color: var(--acc); text-decoration: none; white-space: nowrap; }
.apt-grid .apt a:hover { text-decoration: underline; }
.sharer {
  display: inline-flex; align-items: center; height: 26px; padding: 0 11px;
  border-radius: 999px; border: 1px solid var(--line2); background: var(--panel2);
  color: var(--txt); font-size: 11.5px; font-weight: 600; text-decoration: none;
}
.sharer:hover { border-color: var(--acc); color: var(--acc); }
.accbody { display: none; padding: 4px 12px 12px; }
.acc.open .accbody { display: block; }
.lbl { display: block; font-size: 11px; color: var(--txt3); text-transform: uppercase; letter-spacing: .6px; margin: 8px 0 6px; }
.chklist label, .radio-row label { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; color: var(--txt); }
.chklist input, .radio-row input { accent-color: var(--acc); }
.radio-row { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.subctl { margin: 4px 0 4px 22px; }
.subctl .mini { font-size: 12px; color: var(--txt2); }
#windLevel { width: 100%; accent-color: var(--acc); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.grid2 label, .accbody > label { display: block; font-size: 12px; color: var(--txt2); margin: 6px 0; }
.grid2 input, .accbody > label input, .accbody select {
  width: 100%; height: 30px; margin-top: 3px; padding: 0 8px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 7px; color: var(--txt); outline: none;
}
.accbody input:focus, .accbody select:focus { border-color: var(--acc); }
.rowbtns { display: flex; gap: 8px; margin-top: 8px; }
.hint { font-size: 11.5px; color: var(--txt3); line-height: 1.45; margin-top: 8px; }
.hint code { color: var(--txt2); }
.itemlist { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.itemlist .it {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
  background: var(--panel2); border: 1px solid var(--line); font-size: 12.5px; cursor: pointer;
}
.itemlist .it:hover { border-color: var(--acc); }
.itemlist .it .x { margin-left: auto; color: var(--txt3); cursor: pointer; padding: 2px 6px; }
.itemlist .it .x:hover { color: var(--bad); }
.fleet-add { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.fleet-add input, .fleet-add select {
  height: 30px; padding: 0 8px; background: var(--bg); color: var(--txt);
  border: 1px solid var(--line2); border-radius: 7px; outline: none; font-size: 12.5px;
}
.fleet-add input:first-child { grid-column: 1 / -1; }
.fleet-add button { grid-column: 1 / -1; }

/* ── Buttons ─────────────────────────────────────────── */
.pbtn {
  height: 34px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--acc);
  background: var(--acc); color: #06121f; font-weight: 700; cursor: pointer;
}
.pbtn:hover { filter: brightness(1.1); }
.pbtn.ghost { background: transparent; color: var(--acc); }
.pbtn.small { height: 30px; padding: 0 12px; font-size: 12.5px; }

/* ── Status bar ──────────────────────────────────────── */
#statusbar {
  position: fixed; inset: auto 0 0 0; height: 26px; z-index: 1200;
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: var(--bg2); border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--txt2); white-space: nowrap; overflow: hidden;
}
#statusbar .spacer { flex: 1; }
#statusbar .attrib { color: var(--txt3); overflow: hidden; text-overflow: ellipsis; }
#dataMode { font-weight: 800; letter-spacing: .8px; padding: 2px 8px; border-radius: 5px; font-size: 10.5px; }
#dataMode.live { background: #10231c; color: #9ff2c4; }
#dataMode.sim { background: #241d0c; color: #ffd98a; }
#dataMode.err { background: #241010; color: #ffb3b3; }

/* ── Map ─────────────────────────────────────────────── */
#main { position: fixed; inset: var(--tb-h, 52px) 0 26px 0; }
#map { position: absolute; inset: 0; background: #05070c; }
#map.grabbing { cursor: grabbing; }

/* Leaflet overrides to match theme */
.leaflet-container { font-family: var(--font); background: #05070c; }
.leaflet-bar, .leaflet-control-attribution { border-radius: 8px !important; }
.leaflet-control-attribution {
  background: rgba(10,13,20,.72) !important; color: var(--txt3) !important; font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--txt2) !important; }
.leaflet-bar a {
  background: var(--panel) !important; color: var(--txt) !important; border-color: var(--line2) !important;
}
.leaflet-bar a:hover { background: var(--panel2) !important; }
.leaflet-tooltip {
  background: rgba(13,17,26,.94) !important; color: var(--txt) !important;
  border: 1px solid var(--line2) !important; border-radius: 7px !important;
  box-shadow: var(--shadow) !important; font-size: 11.5px !important;
}
.leaflet-tooltip::before { display: none; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel) !important; color: var(--txt) !important; border: 1px solid var(--line2);
}
.leaflet-popup-content { margin: 10px 14px; font-size: 12.5px; line-height: 1.5; }

/* Aircraft markers */
.plwrap { background: none !important; border: none !important; }
.pl { position: relative; width: 26px; height: 26px; will-change: transform; transition: transform .12s linear; }
.pl svg { position: absolute; inset: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.65)); }
.pl.sel::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--acc); animation: pulse 1.6s ease-out infinite;
}
.pl.emg::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--bad); animation: pulse 1s ease-out infinite;
}
@keyframes pulse { 0% { opacity: .95; transform: scale(.7);} 100% { opacity: 0; transform: scale(1.25);} }
.pl .badge {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 10px; padding: 1px 6px; border-radius: 999px; white-space: nowrap;
  background: rgba(13,17,26,.92); border: 1px solid var(--line2); color: var(--txt);
  pointer-events: none;
}
.pl .badge .fl { font-size: 11px; }

/* Airport markers */
.apwrap { background: none !important; border: none !important; }
.ap {
  display: flex; align-items: center; gap: 4px; cursor: pointer;
  color: #cfe0ff; text-shadow: 0 1px 2px rgba(0,0,0,.9); white-space: nowrap;
}
.ap .dot {
  width: 9px; height: 9px; border-radius: 50%; background: #7fb2ff;
  border: 1.5px solid #dcebff; flex: 0 0 auto; box-shadow: 0 0 6px rgba(80,140,255,.8);
}
.ap.big .dot { width: 11px; height: 11px; }
.ap .lb { font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.ap:hover .lb { color: #fff; }

/* Congestion + jamming + FIR */
.cong { background: none !important; border: none !important; }
.jam { background: none !important; border: none !important; }
.jam .sq { width: 10px; height: 10px; border-radius: 2px; }
.legend {
  position: absolute; right: 12px; top: 12px; z-index: 900;
  background: rgba(13,17,26,.9); border: 1px solid var(--line2); border-radius: 9px;
  padding: 8px 10px; font-size: 11px; color: var(--txt2); box-shadow: var(--shadow);
}
.legend .row { display: flex; align-items: center; gap: 7px; padding: 2px 0; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; }

/* Floating view buttons */
#viewButtons { position: absolute; right: 12px; bottom: 14px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.fbtn {
  height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  background: rgba(20,25,38,.92); color: var(--txt); border: 1px solid var(--line2);
  font-size: 12.5px; font-weight: 600; backdrop-filter: blur(4px);
}
.fbtn:hover, .fbtn.on { border-color: var(--acc); color: var(--acc); }

/* keep legend & floating buttons clear of the open right detail panel */
body.panel-open .legend, body.panel-open #viewButtons { right: 392px; }

/* Wind canvas + playback ghosts above tiles but below UI */
#windCanvas.leaflet-pane { z-index: 450; }

/* Toasts */
.toast.info { border-color: #1f4a6b; }

/* Floating fullscreen-exit — only visible while in zen mode */
#btnZenExit { position: absolute; top: 12px; right: 12px; z-index: 1250; }
body:not(.zen) #btnZenExit { display: none !important; }
body.zen #btnZenExit { display: inline-flex; border-color: var(--acc); color: var(--acc); }

/* ── Help modal ──────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,10,.66); backdrop-filter: blur(2px); padding: 18px;
}
.modal-card {
  width: min(560px, 100%); max-height: min(86vh, 720px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 14px;
  box-shadow: var(--shadow); animation: tin .18s ease;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.modal-head .hm-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--txt); }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.hm-row {
  display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.5; color: var(--txt2);
}
.hm-row:last-of-type { border-bottom: none; }
.hm-row h3 { margin: 0 0 2px; font-size: 12.5px; font-weight: 700; color: var(--txt); }
.hm-row p { margin: 0; }
.hm-row .k { color: var(--acc); font-weight: 600; }
.sb-t { font-weight: 600; }
.hm-row .hm-ic {
  flex: 0 0 34px; height: 34px; border-radius: 9px; background: var(--panel2);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* Respect users who prefer less motion (e.g. the infinite emergency pulse) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 860px) {
  #btnMenu { display: inline-flex; }
  .topnav {
    display: flex; order: 3; flex-basis: 100%; overflow-x: auto; gap: 2px;
    padding-bottom: 4px;
  }
  #topbar { flex-wrap: wrap; height: auto; min-height: 52px; padding-bottom: 2px; }
  /* topbar height varies with wrapping (was a hardcoded 88px while the real
     bar can grow to ~121px, hiding the top of the map) — js/ui.js measures it
     into --tb-h on load, resize and wrap changes */
  #main, #sidebar { top: var(--tb-h, 88px); bottom: 24px; }
  .tbtn { padding: 0 9px; font-size: 12px; height: 28px; }
  .searchwrap { max-width: none; flex: 1 1 200px; }
  .brand h1 { font-size: 14px; }
  #statusChip { display: none; }
  #statusbar { height: 24px; font-size: 10.5px; gap: 8px; }
  .attrib { display: none; }
  #viewButtons { right: 8px; bottom: 10px; }
}
