/* ============================================================
   CFF Alert — SBB delay monitor
   Palette: validated data-viz reference instance (light + dark
   are separately selected steps, never an automatic flip).
   ============================================================ */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --surface-1:      #fcfcfb;
  --surface-2:      #f4f3f0;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --border-strong:  rgba(11, 11, 11, 0.16);
  --shadow:         0 1px 2px rgba(11,11,11,.05), 0 8px 24px -12px rgba(11,11,11,.14);

  /* series (categorical slot 1 = the only series hue used) */
  --series-1:       #2a78d6;
  --series-1-wash:  rgba(42, 120, 214, 0.10);

  /* Ordinal blue ramp for the ordered severity buckets.
     Validated with validate_palette.js --ordinal --mode light:
     monotone lightness, all adjacent gaps >= 0.06, light end 2.06:1
     on the surface, single hue. Light mode starts no lighter than step 250. */
  --ord-1: #86b6ef;
  --ord-2: #5598e7;
  --ord-3: #2a78d6;
  --ord-4: #1c5cab;
  --ord-5: #104281;
  --meter-track: #cde2fb;

  /* status — fixed, never themed */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;

  --radius:    14px;
  --radius-sm: 9px;
  --gap:       18px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.16);
    --shadow:         0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7);
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57, 135, 229, 0.14);
    /* dark ramp validated separately against #1a1a19 — not a flip of light */
    --ord-1: #cde2fb;
    --ord-2: #9ec5f4;
    --ord-3: #5598e7;
    --ord-4: #2a78d6;
    --ord-5: #184f95;
    --meter-track: #184f95;
    --good-ink: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.16);
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7);
  --series-1:       #3987e5;
  --series-1-wash:  rgba(57, 135, 229, 0.14);
  --ord-1: #cde2fb;
  --ord-2: #9ec5f4;
  --ord-3: #5598e7;
  --ord-4: #2a78d6;
  --ord-5: #184f95;
  --meter-track: #184f95;
  --good-ink: #0ca30c;
}

*, *::before, *::after { box-sizing: border-box; }

/* `hidden` must win over any component display rule (.drawer is display:flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }

.vh {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 60;
  background: var(--surface-1); color: var(--text-primary);
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); text-decoration: none;
  transition: top .16s ease;
}
.skip:focus { top: 12px; }

:where(button, input, a, [tabindex]):focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------- top bar ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 26px; flex-wrap: wrap;
  padding: 14px clamp(16px, 3vw, 30px);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; }
.brand-mark { color: var(--critical); display: flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--text-muted); }

.topbar-meta { display: flex; gap: 22px; flex-wrap: wrap; }
.meta-block { display: flex; flex-direction: column; gap: 1px; }
.meta-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 600;
}
.meta-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.topbar-actions { display: flex; align-items: center; gap: 7px; }

.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 11px; font: inherit; font-size: 12.5px; font-weight: 550;
  color: var(--text-secondary); background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: background .14s, color .14s, border-color .14s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn[aria-pressed="true"] {
  color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 45%, transparent);
  background: var(--series-1-wash);
}
.icon-btn-label { display: none; }
@media (min-width: 1100px) { .icon-btn-label { display: inline; } }

.btn-primary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; font: inherit; font-size: 12.5px; font-weight: 600;
  color: #fff; background: var(--series-1);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; transition: filter .14s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary[data-busy="1"] { opacity: .6; pointer-events: none; }

.loadbar { height: 2px; background: var(--gridline); overflow: hidden; }
.loadbar span {
  display: block; height: 100%; width: 34%; background: var(--series-1);
  animation: slide 1.05s cubic-bezier(.4,0,.2,1) infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(400%); } }

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

.controls {
  display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-end;
  padding: 16px clamp(16px, 3vw, 30px);
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.control { display: flex; flex-direction: column; gap: 7px; }
.control-grow { flex: 1 1 320px; min-width: 0; }
.control-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 600;
}

.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.segmented button {
  padding: 6px 12px; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--text-secondary); background: transparent; border: 0;
  border-radius: 7px; cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background .14s, color .14s;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button.is-on {
  background: var(--surface-1); color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,.10);
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); background: transparent;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-on {
  background: var(--series-1); border-color: var(--series-1); color: #fff;
}

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.search input {
  font: inherit; font-size: 13px; padding: 7px 12px 7px 31px; width: 210px;
  color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.search input::placeholder { color: var(--text-muted); }

/* ---------------- layout ---------------- */

.grid {
  display: grid;
  /* minmax(0,1fr), not 1fr: an auto minimum lets the wide alert table
     stretch its track and scroll the whole page sideways */
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--gap) clamp(16px, 3vw, 30px) 34px;
  align-items: start;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 14px;
}
.card-title { font-size: 14px; font-weight: 650; letter-spacing: -0.005em; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.card-hero  { grid-column: span 4; }
.kpi-row    { grid-column: span 8; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.card-chart { grid-column: span 6; }
.card-wide  { grid-column: span 12; }

@media (max-width: 1180px) {
  .card-hero { grid-column: span 12; }
  .kpi-row   { grid-column: span 12; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-chart{ grid-column: span 12; }
}
@media (max-width: 560px) {
  .kpi-row { grid-template-columns: 1fr; }
}

/* ---------------- hero + stats ---------------- */

.card-hero { display: flex; flex-direction: column; }
.hero-figure {
  font-size: clamp(52px, 6vw, 68px); font-weight: 660; letter-spacing: -0.03em;
  line-height: 1; margin: 12px 0 6px;
  /* proportional figures — never tabular-nums on a display number */
}
.hero-caption { font-size: 12.5px; color: var(--text-secondary); }
.hero-note { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

.meter {
  margin-top: 16px; height: 8px; border-radius: 999px;
  background: var(--meter-track); overflow: hidden;
}
.meter-fill {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: var(--series-1); transition: width .5s cubic-bezier(.4,0,.2,1);
}

.stat { display: flex; flex-direction: column; gap: 3px; }
.stat-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.stat-sub { font-size: 12px; color: var(--text-secondary); }
.stat-sub .up { color: var(--critical); font-weight: 600; }
.stat-sub .ok { color: var(--good-ink); font-weight: 600; }

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

.chart-holder { width: 100%; }
.chart-holder svg { display: block; width: 100%; height: auto; overflow: visible; }

.axis-text { font-size: 10.5px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.axis-text.is-strong { fill: var(--text-secondary); }
.value-label { font-size: 10.5px; fill: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--gridline); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.bar { fill: var(--series-1); }
.hit { fill: transparent; cursor: pointer; }
.hit:hover + .bar, .bar.is-hot { filter: brightness(1.14); }

.chart-tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 8px 11px; font-size: 12px; box-shadow: var(--shadow);
  min-width: 116px; opacity: 0; transition: opacity .1s;
}
.chart-tip.is-on { opacity: 1; }
.chart-tip .tip-k { color: var(--text-muted); font-size: 11px; }
.chart-tip .tip-v { font-weight: 650; font-variant-numeric: tabular-nums; }

.toggle-table {
  padding: 5px 11px; font: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--text-secondary); background: transparent;
  border: 1px solid var(--border); border-radius: 7px; cursor: pointer;
  white-space: nowrap;
}
.toggle-table:hover { background: var(--surface-2); color: var(--text-primary); }
.toggle-table[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); }

.table-view table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table-view th, .table-view td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--gridline);
}
.table-view th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.table-view td { font-variant-numeric: tabular-nums; }
.table-view td:first-child { font-variant-numeric: normal; }

/* ---------------- alert table ---------------- */

.table-scroll { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.alert-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.alert-table th {
  text-align: left; padding: 0 12px 9px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.th-sort {
  font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  background: transparent; border: 0; padding: 0; cursor: pointer;
}
.th-sort:hover { color: var(--text-primary); }
.th-sort.is-sorted { color: var(--text-primary); }
.th-sort.is-sorted::after { content: " ↓"; }
.th-sort.is-sorted[data-dir="asc"]::after { content: " ↑"; }
.alert-table th:not(:has(.th-sort)) {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
}

.alert-table tbody tr { border-bottom: 1px solid var(--gridline); }
.alert-table tbody tr:hover { background: var(--surface-2); }
.alert-table td { padding: 9px 12px; vertical-align: middle; white-space: nowrap; }
.alert-table td.c-num { font-variant-numeric: tabular-nums; font-weight: 650; }
.alert-table td.c-time { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.alert-table td.c-stop { white-space: normal; min-width: 150px; }
.row-new { animation: flashRow 2.4s ease-out; }
@keyframes flashRow {
  0%, 30% { background: var(--series-1-wash); }
  100% { background: transparent; }
}

/* status badge — icon + label, never colour alone */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
}
.badge-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  box-shadow: 0 0 0 2px var(--surface-1);
}
.sev-warning  .badge-dot { background: var(--warning); }
.sev-serious  .badge-dot { background: var(--serious); }
.sev-critical .badge-dot { background: var(--critical); }
.sev-cancelled .badge-dot { background: var(--critical); border-radius: 2px; transform: rotate(45deg); }
.badge svg { flex: none; }

.line-tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 650; letter-spacing: .01em;
}

.btn-row {
  font: inherit; font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 9px; cursor: pointer;
}
.btn-row:hover { background: var(--surface-2); color: var(--text-primary); }

.table-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-top: 13px; font-size: 12px; color: var(--text-muted);
}
.btn-ghost {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-primary);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 15px; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--border-strong); }

.empty {
  padding: 34px 12px; text-align: center; color: var(--text-muted); font-size: 13px;
}

/* ---------------- drawer ---------------- */

.drawer { position: fixed; inset: 0; z-index: 55; display: flex; justify-content: flex-end; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.42); }
.drawer-panel {
  position: relative; width: min(560px, 100%); height: 100%;
  background: var(--surface-1); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slideIn .22s cubic-bezier(.4,0,.2,1);
}
@keyframes slideIn { from { transform: translateX(22px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 15px; font-weight: 650; }
.drawer-body { padding: 16px 20px 30px; overflow-y: auto; }

.stopline { display: flex; flex-direction: column; }
.stop-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; align-items: center; padding: 7px 0; }
.stop-rail { position: relative; height: 100%; display: flex; justify-content: center; }
.stop-rail::before {
  content: ""; position: absolute; top: -7px; bottom: -7px; width: 2px; background: var(--gridline);
}
.stop-row:first-child .stop-rail::before { top: 50%; }
.stop-row:last-child .stop-rail::before { bottom: 50%; }
.stop-dot {
  position: relative; width: 9px; height: 9px; border-radius: 50%;
  background: var(--axis); box-shadow: 0 0 0 3px var(--surface-1);
}
.stop-dot.is-late { background: var(--critical); }
.stop-dot.is-ok { background: var(--good); }
.stop-dot.is-cancel { background: var(--critical); border-radius: 2px; }
.stop-name { font-size: 13px; font-weight: 550; }
.stop-meta { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.stop-delay { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.stop-delay.is-late { color: var(--critical); }
.stop-delay.is-ok { color: var(--good-ink); }

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 9px; max-width: 340px;
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--series-1);
  border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow);
  animation: toastIn .2s cubic-bezier(.4,0,.2,1);
}
.toast.is-critical { border-left-color: var(--critical); }
.toast.is-good { border-left-color: var(--good); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast-title { font-size: 12.5px; font-weight: 650; }
.toast-body { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

/* ---------------- footer ---------------- */

.site-foot {
  padding: 20px clamp(16px, 3vw, 30px) 34px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  display: flex; flex-direction: column; gap: 5px;
}
.site-foot a { color: var(--text-secondary); }
.site-foot code {
  font-size: 11.5px; background: var(--surface-2);
  padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
