/* Airlift Planner dashboard. One typeface, tokens for both themes. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6b6963;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --gateway: #2a78d6;
  --forward: #1baf7a;
  --trap: #e34948;
  --trap-text: #b3261e;
  --control-border: #8f8d86;
  --cand: #898781;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --tile-filter: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --gateway: #3987e5;
    --forward: #199e70;
    --trap: #e66767;
    --trap-text: #e66767;
    --control-border: #707069;
    --cand: #898781;
    --focus: #3987e5;
    --shadow: none;
    --tile-filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6);
  }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --gateway: #3987e5;
    --forward: #199e70;
    --trap: #e66767;
    --trap-text: #e66767;
    --control-border: #707069;
    --cand: #898781;
    --focus: #3987e5;
    --shadow: none;
    --tile-filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; letter-spacing: -0.01em; }
h2 { font-size: 13px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin-bottom: 6px; }
p { margin: 0 0 8px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 0 20px; min-height: 48px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.wordmark { font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; font-size: 12px; }
.tagline { color: var(--ink-2); font-size: 12px; }
.topbar-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.select-wrap { display: flex; align-items: center; gap: 8px; }
.select-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
select {
  padding: 5px 28px 5px 8px; border: 1px solid var(--control-border); border-radius: 4px; background: var(--surface);
  max-width: min(420px, 55vw); appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.built, .toplink { font-size: 12px; color: var(--ink-2); }
.toplink { text-decoration: none; border-bottom: 1px solid var(--border); }
.toplink:hover { border-color: var(--ink-2); }

/* ---------- layout */
.page { max-width: 1440px; margin: 0 auto; padding: 16px 20px 40px; display: grid; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow);
  padding: 14px 16px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-sub { font-size: 12px; color: var(--muted); }

.event-strip { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; padding: 2px 0; }
.meta { color: var(--ink-2); font-size: 12px; margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 3px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; border: 1px solid var(--border); color: var(--ink-2);
}
.badge-red { border-color: var(--trap); color: var(--trap-text); }
.badge-orange { border-color: #ec835a; color: #b5532e; }
.badge-yellow { border-color: #c98500; color: #8a5b00; }
.badge-green { border-color: #0ca30c; color: #006300; }
.event-nav { display: flex; gap: 6px; }

.btn {
  padding: 5px 10px; border: 1px solid var(--control-border); border-radius: 4px; background: var(--surface); cursor: pointer; font-size: 12px;
}
.btn:hover { border-color: var(--ink-2); }
.btn-quiet { border-color: transparent; color: var(--muted); padding: 2px 6px; }
.btn-quiet:hover { color: var(--ink); border-color: var(--border); }

/* ---------- kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 600; line-height: 1.15; margin: 4px 0 2px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.kpi-sub { font-size: 12px; color: var(--ink-2); }
.kpi-value.kpi-text { font-size: 17px; line-height: 1.3; }
.kpi-note { grid-column: 1 / -1; }

/* ---------- main grid */
.main-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: stretch; }
.main-grid > * { min-width: 0; }
.page > * { min-width: 0; }
.side { display: grid; gap: 14px; min-width: 0; align-content: start; }
.map-card { padding-bottom: 12px; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 560px; border-radius: 4px; border: 1px solid var(--border); background: var(--page); }
.leaflet-tile-pane { filter: var(--tile-filter); }
.leaflet-container { font: inherit; }
.leaflet-tooltip { font-size: 12px; line-height: 1.35; border-radius: 3px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-tooltip-top:before { border-top-color: var(--surface); }
.leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--ink-2); }
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--border); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.glyph { display: inline-block; width: 10px; height: 10px; }
.g-gateway { background: var(--gateway); }
.g-alt { border: 2px solid var(--gateway); width: 8px; height: 8px; }
.g-forward { background: var(--forward); border-radius: 50%; }
.g-trap { border: 2px solid var(--trap); border-radius: 50%; width: 8px; height: 8px; }
.g-cand { background: var(--cand); border-radius: 50%; width: 6px; height: 6px; margin: 2px; }
.g-quake { background: var(--ink); border-radius: 50%; }
.g-center { border: 2px solid var(--ink); border-radius: 50%; width: 6px; height: 6px; }
.g-shake { height: 8px; width: 22px; background: linear-gradient(90deg, #ffff00, #ffc800, #ff9100, #ff0000); margin: 1px 0; opacity: .8; }
.g-leg { height: 0; width: 18px; border-top: 2px dashed var(--gateway); margin: 4px 0; }

/* markers on the map */
.mk { display: block; box-sizing: border-box; }
.mk-gateway { width: 16px; height: 16px; background: var(--gateway); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--gateway); }
.mk-alt { width: 14px; height: 14px; border: 3px solid var(--gateway); background: var(--surface); }

/* ---------- controls */
.controls { display: grid; gap: 12px; }
.ctl { display: grid; gap: 4px; }
.ctl-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); }
.ctl-label em { font-style: normal; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.ctl-hint { font-size: 11px; color: var(--muted); }
.ctl-check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
input[type="range"] { width: 100%; accent-color: var(--gateway); margin: 0; }
input[type="checkbox"] { accent-color: var(--gateway); width: 14px; height: 14px; margin: 0; }
input[type="search"] {
  padding: 5px 8px; border: 1px solid var(--control-border); border-radius: 4px; background: var(--surface); width: min(260px, 100%);
}

/* ---------- key/value tables */
.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.kv td { padding: 5px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.kv tr:last-child td { border-bottom: 0; }
.kv td.k { color: var(--ink-2); padding-right: 10px; }
.kv td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv td.wrap { white-space: normal; overflow-wrap: anywhere; }
.role-dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; vertical-align: -1px; }
.role-gateway { background: var(--gateway); }
.role-alternative { border: 2px solid var(--gateway); width: 7px; height: 7px; }
.role-forward { background: var(--forward); border-radius: 50%; }
.role-knocked-out { border: 2px solid var(--trap); border-radius: 50%; width: 7px; height: 7px; }
.role-candidate { background: var(--cand); border-radius: 50%; width: 6px; height: 6px; margin: 0 8px 0 1px; }

.strips { width: 100%; border-collapse: collapse; font-size: 12px; }
.strips th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 0 0 6px; border-bottom: 1px solid var(--grid); }
.strips td { padding: 5px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.strips tr:last-child td { border-bottom: 0; }
.strips .n, .strips th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 8px; }
.strips .sub { display: block; color: var(--muted); font-size: 11px; }
.empty { color: var(--muted); font-size: 12px; padding: 6px 0; }
.note { font-size: 12px; color: var(--ink-2); }

/* ---------- charts */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart { width: 100%; min-height: 240px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: inherit; fill: var(--ink-2); font-size: 11px; }
.chart .tick { font-variant-numeric: tabular-nums; fill: var(--muted); }
.chart .lab { fill: var(--ink); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .leader { stroke: var(--cand); stroke-width: 1; opacity: 0.8; }
.chart .hit { fill: transparent; cursor: default; }

/* ---------- ledger */
.ledger-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.ledger, .scorecard { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ledger th, .scorecard th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 6px 8px 6px 0; border-bottom: 1px solid var(--axis); white-space: nowrap; user-select: none;
}
.th-btn { all: unset; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; }
.th-btn:hover, .th-btn.sorted { color: var(--ink); }
.th-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.th-btn.sorted::after { content: " \2191"; }
.th-btn.sorted.desc::after { content: " \2193"; }
.ledger td, .scorecard td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.ledger td.n, .ledger th.n, .scorecard td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger td.role { white-space: nowrap; }
.ledger tr.hl-gateway td { background: color-mix(in srgb, var(--gateway) 8%, transparent); }
.ledger tr.hl-knocked-out td { background: color-mix(in srgb, var(--trap) 7%, transparent); }
.scorecard a, .note a, .card-head a { color: inherit; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 2px; }
.scorecard a:hover, .note a:hover, .card-head a:hover { text-decoration-color: var(--ink-2); }
.scorecard tr.active td { background: color-mix(in srgb, var(--gateway) 8%, transparent); }
.match-yes { color: #006300; font-weight: 600; }
.match-no { color: var(--trap-text); font-weight: 600; }
.match-part { color: #8a5b00; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .match-yes { color: #0ca30c; }
  :root:not([data-theme="light"]) .match-part { color: #fab219; }
  :root:not([data-theme="light"]) .badge-green { color: #0ca30c; }
  :root:not([data-theme="light"]) .badge-yellow { color: #fab219; }
  :root:not([data-theme="light"]) .badge-orange { color: #ec835a; }
}

:root[data-theme="dark"] .match-yes, :root[data-theme="dark"] .badge-green { color: #0ca30c; }
:root[data-theme="dark"] .match-part, :root[data-theme="dark"] .badge-yellow { color: #fab219; }
:root[data-theme="dark"] .badge-orange { color: #ec835a; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- method */
.method { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 14px; }
.method p { font-size: 12.5px; color: var(--ink-2); }
.formula { font-variant-numeric: tabular-nums; color: var(--ink) !important; font-size: 12px !important; border-left: 2px solid var(--grid); padding-left: 10px; }
.limits { margin: 0 0 12px; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.limits li { margin-bottom: 4px; }

.foot { max-width: 1440px; margin: 0 auto; padding: 0 20px 30px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }

/* ---------- tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 9px; font-size: 12px; line-height: 1.4; box-shadow: 0 2px 8px rgba(11, 11, 11, 0.12);
}
.tooltip b { font-weight: 600; }
.tooltip .n { font-variant-numeric: tabular-nums; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr; }
  .method { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  #map { min-height: 420px; }
  .kpi-value { font-size: 24px; }
  .page { padding: 12px 16px 32px; }
}
