/* Flight tracker dashboard. Palette: dataviz reference palette (validated, light and dark). Dark values are
   declared twice on purpose: once for the system setting, once for the theme button, which must win both ways. */
:root {
  color-scheme: light;
  --plane: #f9f9f7;              /* page */
  --surface: #fcfcfb;            /* cards, charts */
  --ink: #0b0b0b;
  --ink-2: #52514e;              /* secondary text: 7.7:1 on the surface */
  --ink-3: #898781;              /* control borders and decoration only: 3.5:1, never text */
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;                 /* categorical slot 1 (blue) */
  --s2: #eb6834;                 /* slot 2 (orange) */
  --s1-wash: rgba(42, 120, 214, 0.14);
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --halo: #ffffff;
  --tile-filter: none;
  --attr-bg: rgba(255, 255, 255, 0.85);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --s1: #3987e5; --s2: #d95926; --s1-wash: rgba(57, 135, 229, 0.22);
    --halo: #1a1a19; --attr-bg: rgba(26, 26, 25, 0.85);
    --tile-filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --s1: #3987e5; --s2: #d95926; --s1-wash: rgba(57, 135, 229, 0.22);
  --halo: #1a1a19; --attr-bg: rgba(26, 26, 25, 0.85);
  --tile-filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--plane); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3, p { margin: 0; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px 24px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 16px; }
sup { font-size: 0.7em; line-height: 0; }

.ico {
  width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ico.big { width: 40px; height: 40px; color: var(--ink-2); }

/* header and status */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 14px 0 10px; }
.top h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.session-line { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--ink-2); font-size: 14px; }
#session-name { overflow-wrap: anywhere; }
.badge {
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--ink-3);
  color: var(--ink); white-space: nowrap;
}
.badge.private { border-color: var(--serious); }
.status { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 9px; border-radius: 999px;
  background: var(--surface); border: 2px solid var(--ink-3); font-size: 13px; font-weight: 700; letter-spacing: 0.05em;
}
.chip-live { border-color: var(--good); } .chip-live .ico { color: var(--good); }
.chip-delayed { border-color: var(--warn); } .chip-delayed .ico { color: var(--warn); }
.chip-stale { border-color: var(--crit); } .chip-stale .ico { color: var(--crit); }
.chip-waiting .ico { color: var(--ink-2); }
.banner, .notice { font-size: 13px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--ink-3); background: var(--surface); }
.banner { border-color: var(--crit); font-weight: 600; }

/* controls */
.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; padding: 10px 0 12px; border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-2); min-width: 0; }
select, .btn {
  height: 40px; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--ink-3); border-radius: 8px;
}
select { padding: 0 8px; max-width: 100%; }
#session { min-width: 220px; }
.field.grow { min-width: 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--s1-wash); }
.btn[aria-pressed="true"] { background: var(--s1-wash); border-color: var(--s1); border-width: 2px; padding: 0 11px; }
.btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }
.admin {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 12px; padding: 8px 12px;
  border: 1px solid var(--crit); border-left-width: 6px; border-radius: 8px; background: var(--surface);
}
.admin-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; margin-right: 6px; }
.btn.danger { border-color: var(--crit); }
.btn.danger:hover { background: rgba(208, 59, 59, 0.14); }
.admin-msg { font-size: 13px; color: var(--ink-2); }

/* empty state */
.empty {
  display: flex; align-items: center; gap: 16px; margin-bottom: 12px; padding: 16px 18px;
  background: var(--surface); border: 1px dashed var(--ink-3); border-radius: 12px;
}
.empty h2 { font-size: 18px; font-weight: 650; }
.empty p { color: var(--ink-2); margin-top: 2px; }

/* layout: map left, values right */
.grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(340px, 1fr); gap: 12px; align-items: stretch; }
.map-card { position: relative; min-height: 440px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
#map { position: absolute; inset: 0; background: var(--surface); }
.map-btn { position: absolute; z-index: 1000; left: 50%; bottom: 28px; transform: translateX(-50%); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3); }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { min-width: 0; padding: 11px 14px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.tile.hero, .tile.wide { grid-column: 1 / -1; }
.lbl { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 3px; }
.val { font-size: 30px; font-weight: 650; line-height: 1.12; letter-spacing: -0.015em; display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 4px; }
.hero .val { font-size: 56px; line-height: 1.05; }
.tile.na .val { font-size: 20px; font-weight: 600; color: var(--ink-2); }
.val.pos { font-size: 22px; gap: 0 12px; }
.unit { font-size: 0.42em; font-weight: 600; color: var(--ink-2); }
.val .ico { align-self: center; width: 0.8em; height: 0.8em; }
.sub { font-size: 13px; color: var(--ink-2); margin-top: 3px; min-height: 1.2em; }
.sub .ico { margin-right: 4px; }
.tile.stale .val { color: var(--ink-2); }
.tile.dim .val { color: var(--ink-2); }
.hero .sub:empty { display: none; }
.tile.stale .sub.pres { color: var(--ink-2); }
.hero .sub.pres { color: var(--ink); font-size: 15px; font-weight: 550; margin-top: 4px; }
.hdg-arrow { transition: transform 0.5s; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; align-self: center; margin-left: 6px; height: 20px; }
.bars i { display: block; width: 5px; border-radius: 1px; background: var(--axis); }
.bars i:nth-child(1) { height: 6px; } .bars i:nth-child(2) { height: 10px; } .bars i:nth-child(3) { height: 15px; } .bars i:nth-child(4) { height: 20px; }
.bars[data-n="1"] i:nth-child(-n+1), .bars[data-n="2"] i:nth-child(-n+2), .bars[data-n="3"] i:nth-child(-n+3), .bars[data-n="4"] i { background: var(--ink); }
.meter { display: block; height: 6px; margin-top: 6px; border-radius: 3px; background: var(--s1-wash); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--s1); border-radius: 3px; }
.meter.low i { background: var(--warn); }
.meter.crit i { background: var(--crit); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.card-h { font-size: 14px; font-weight: 650; }
.card-h .u { font-weight: 500; color: var(--ink-2); }
.note { font-size: 13px; color: var(--ink-2); margin-top: 6px; }

.feed-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.feed-list li { display: grid; grid-template-columns: minmax(70px, 1fr) auto auto auto; align-items: center; gap: 4px 12px; font-size: 14px; }
.feed-list .name { font-weight: 600; overflow-wrap: anywhere; }
.feed-list .st { display: inline-flex; align-items: center; gap: 5px; min-width: 76px; }
.feed-list .st.live .ico { color: var(--good); }
.feed-list .st.delayed .ico { color: var(--warn); }
.feed-list .st.silent .ico { color: var(--crit); }
.feed-list .age, .feed-list .n { color: var(--ink-2); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.feed-list .none { color: var(--ink-2); display: block; }

/* charts */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.chart { margin: 0; min-width: 0; }
.chart.wide { grid-column: 1 / -1; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 16px; margin-bottom: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 13px; color: var(--ink-2); }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-weight: 650; }
.key { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--c, var(--s1)); border-radius: 1px; }
.k1 { --c: var(--s1); } .k2 { --c: var(--s2); }
.plot { position: relative; height: 230px; }
.uplot .u-cursor-x { border-right: 1px solid var(--ink-2); }
.u-over { cursor: crosshair; }
.u-over:focus-visible { outline-offset: -2px; }
.tip {
  position: absolute; z-index: 5; top: 6px; min-width: 150px; padding: 6px 10px; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--ink-3); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); font-size: 13px;
}
.tip .t { color: var(--ink-2); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.tip .r { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.tip .r b { font-weight: 650; }
.tip .r span { color: var(--ink-2); }
.tip .r .key { align-self: center; flex: none; }

/* table */
.table-card { margin-top: 12px; }
.table-wrap { margin-top: 8px; max-height: 70vh; overflow: auto; border-top: 1px solid var(--grid); }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; }
th:first-child, td:first-child, th:last-child, td:last-child { text-align: left; }
th:first-child, td:first-child { position: sticky; left: 0; background: var(--surface); }     /* time stays visible when the table scrolls sideways */
th:first-child { z-index: 1; }

.foot { margin-top: 16px; font-size: 12px; color: var(--ink-2); max-width: 90ch; }

/* Leaflet */
.leaflet-container { font: inherit; background: var(--surface); }
.leaflet-tile-pane { filter: var(--tile-filter); }
.leaflet-control-attribution { background: var(--attr-bg) !important; color: var(--ink-2) !important; }
.leaflet-control-attribution a { color: var(--ink) !important; }
.leaflet-bar a, .leaflet-bar a:hover { background-color: var(--surface); color: var(--ink); border-bottom-color: var(--ink-3); }
.leaflet-bar { border-color: var(--ink-3) !important; }
.leaflet-control-scale-line { background: var(--attr-bg); color: var(--ink); border-color: var(--ink-2); text-shadow: none; }
path.trk-halo { stroke: var(--halo); }
path.trk-line { stroke: var(--s1); }
path.trk-halo.trk-gap, path.trk-line.trk-gap { stroke-dasharray: 8 9; stroke-linecap: butt; }
path.start-dot { fill: var(--surface); stroke: var(--s1); }
.plane-icon svg { display: block; width: 100%; height: 100%; overflow: visible; transition: transform 0.5s; }
.plane-icon path { fill: var(--s1); stroke: var(--halo); stroke-width: 1.6; stroke-linejoin: round; paint-order: stroke; }
.plane-icon.dim path { fill: var(--surface); stroke: var(--s1); stroke-width: 1.8; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .map-card { min-height: 0; height: 340px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .field.grow { flex: 1 1 180px; }
  #session { min-width: 0; width: 100%; }
}
@media (max-width: 520px) {
  .wrap { padding: 0 12px 20px; }
  .hero .val { font-size: 52px; }
  .val { font-size: 26px; }
  .tile.na .val { font-size: 20px; font-weight: 600; color: var(--ink-2); }
.val.pos { font-size: 19px; gap: 0 10px; }
  .controls .btn { padding: 0 10px; }
  .feed-list li { grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }       /* name + status, then age + count */
  .feed-list .age { text-align: left; }
  .plot { height: 210px; }
}
@media (prefers-reduced-motion: reduce) {
  .hdg-arrow, .plane-icon svg { transition: none; }
}
