/* Desktop-first, but every row is a flex block that stacks, so a narrow
   viewport degrades rather than breaks. */

:root {
  --bg: #0f1720;
  --panel: #17212e;
  --panel-2: #1e2b3a;
  --line: #2b3a4d;
  --text: #e8eef6;
  --muted: #93a4b8;
  --accent: #57b6ff;
  --delayed: #ff8f6b;
  --on-time: #5fd0a0;
  --cancelled: #ff6b8a;
  --diverted: #c79bff;
  --on-fill: #04121f;       /* text on an outcome-coloured fill */
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --panel-2: #f0f4f9;
    --line: #dbe3ed;
    --text: #16202c;
    --muted: #5d6e83;
    --accent: #0b69c7;
    --delayed: #c4491d;
    --on-time: #12795a;
    --cancelled: #bc2246;
    --diverted: #6b3bb5;
    --on-fill: #ffffff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.tagline { margin: 0 0 2rem; color: var(--muted); }

/* ---------- filter builder ---------- */

.builder {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;          /* stacks on a narrow viewport */
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 0.5rem;
}

.filter-label { font-weight: 600; }
.control { display: flex; align-items: center; gap: 0.4rem; }
.conjunction { color: var(--muted); }

.builder-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
}

select:disabled { opacity: 0.5; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }

/* The surprise button is the highest-value control on the page -- it removes
   the blank-page problem -- so it is the one thing that looks clickable. */
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121f;
  font-weight: 650;
  margin-left: auto;
}

.ghost { background: transparent; }

.remove {
  margin-left: auto;
  padding: 0.1rem 0.5rem;
  line-height: 1.2;
  background: transparent;
  color: var(--muted);
}
.remove:hover { color: var(--cancelled); }

/* ---------- results ---------- */

#results { transition: opacity 0.12s ease; }
#results.loading { opacity: 0.45; }

/* One quiet line, not a banner: the toy is the point. No display rule, so the
   hidden attribute main.ts toggles keeps working. */
.forecast-cta {
  margin: 1rem 0 0;
  padding: 0.6rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.forecast-cta a { color: var(--accent); font-weight: 600; }

.summary { margin: 0 0 0.25rem; font-size: 1.15rem; font-weight: 650; }
.count { margin: 0 0 1.25rem; color: var(--muted); }

.notice {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.stat-delayed   { border-top-color: var(--delayed); }
.stat-on_time   { border-top-color: var(--on-time); }
.stat-cancelled { border-top-color: var(--cancelled); }
.stat-diverted  { border-top-color: var(--diverted); }

.stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-compare { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.delay-stats {
  margin-top: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.delay-stats h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }

.delay-stats dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem 1rem;
}

.delay-stats dt { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.delay-stats dd { margin: 0.15rem 0 0; font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */

.chart-title { margin: 1.1rem 0 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.chart-note { margin-top: 0.5rem; font-size: 0.8rem; color: var(--muted); }

/* Outcome bars: these flights over all flights, one 100% scale. */
.outcome-bars { display: grid; gap: 0.4rem; margin: 0 0 1rem; }
.outcome-row { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); align-items: center; gap: 0.75rem; }
.outcome-name { font-size: 0.85rem; color: var(--muted); }
.outcome-bar { display: flex; height: 1.6rem; border-radius: 6px; overflow: hidden; background: var(--panel-2); }

.segment {
  flex-basis: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--on-fill);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.segment + .segment { box-shadow: inset 1px 0 var(--panel); }
.seg-delayed   { background: var(--delayed); }
.seg-on_time   { background: var(--on-time); }
.seg-cancelled { background: var(--cancelled); }
.seg-diverted  { background: var(--diverted); }

/* Delay histogram: solid bars for these flights, a line for all flights. */
.hist { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; }
.hist-plot { position: relative; height: 90px; border-bottom: 1px solid var(--line); }
.hist-bar { position: absolute; left: 0; right: 0; bottom: 0; background: var(--delayed); border-radius: 3px 3px 0 0; }
.hist-ghost { position: absolute; left: -2px; right: -2px; height: 0; border-top: 2px solid var(--text); opacity: 0.75; }
.hist-label { margin-top: 0.2rem; text-align: center; font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Breakdown: bars rise or fall from the rate with that filter removed. */
#breakdowns { display: grid; gap: 1rem; margin-top: 1.25rem; }
#breakdowns:empty { display: none; }

.breakdown {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.breakdown h3 { margin: 0 0 0.3rem; font-size: 0.95rem; }
.breakdown.pending { opacity: 0.6; }
.breakdown-rank { margin-bottom: 0.6rem; font-weight: 600; }

.bd-chart { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 2px; }
.bd-plot { position: relative; height: 120px; }
.bd-plot::after {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: 50%;
  border-top: 1px solid var(--muted);
  opacity: 0.6;
}
.bd-bar { position: absolute; left: 15%; right: 15%; min-height: 2px; opacity: 0.4; }
.bd-bar.up   { bottom: 50%; background: var(--delayed); border-radius: 3px 3px 0 0; }
.bd-bar.down { top: 50%;    background: var(--on-time); border-radius: 0 0 3px 3px; }
.bd-col.selected .bd-bar { opacity: 1; }
.bd-col.selected .bd-plot { background: var(--panel-2); border-radius: 4px; }

/* Below the minimum-n guard: a slot, not a short bar. */
.bd-empty::before {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  top: 30%;
  bottom: 30%;
  /* --muted, not --line: --line all but vanishes on the dark panel. */
  border: 1px dashed var(--muted);
  border-radius: 3px;
  opacity: 0.5;
}

.bd-label {
  margin-top: 0.25rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.bd-col.selected .bd-label { color: var(--text); font-weight: 700; }

/* ---------- sample ---------- */

#sample-section {
  margin-top: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

#sample-section summary { cursor: pointer; font-weight: 600; }
.sample-note { color: var(--muted); font-size: 0.85rem; }

/* A wide table scrolls inside its own box rather than the page. */
#sample { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
td { font-variant-numeric: tabular-nums; }

.row-delayed   td:last-child { color: var(--delayed); }
.row-cancelled td:last-child { color: var(--cancelled); }
.row-diverted  td:last-child { color: var(--diverted); }
.row-on_time   td:last-child { color: var(--on-time); }

.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.pager span { color: var(--muted); font-size: 0.85rem; }

/* ---------- faq ---------- */

.faq { margin-top: 2.5rem; }
.faq h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }

.faq details {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 0.6rem 0 0; color: var(--muted); }
.faq details ul { margin: 0.6rem 0 0; color: var(--muted); }

footer {
  margin-top: 2.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.sep { margin: 0 0.4rem; }

/* Narrow viewport: give the filter label its own line so the control and the
   remove button share the next one, rather than the × wrapping alone. */
@media (max-width: 560px) {
  .filter-label { flex: 1 0 100%; }
  .primary { margin-left: 0; }
  .builder-actions { flex-direction: column; align-items: stretch; }
  .outcome-row { grid-template-columns: 1fr; gap: 0.15rem; }
  .hist-label.thin,
  .bd-chart.many .bd-label.thin { visibility: hidden; }
}
