:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --ink: #16191d;
  --ink-2: #4b5159;
  --ink-3: #737982;
  --rule: #dddbd3;
  --accent: #233a8b;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --bad-bg: #fde4e1;
  --bad-ink: #8a1c12;
  --ok: #1f7a3a;
  --empty-ink: #7a5a00;
  --empty-bg: #fbf1d2;
  --line: #7b868c;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10151c; --surface: #171d26; --surface-2: #1e2530; --ink: #e9ecef; --ink-2: #b3bac3;
    --ink-3: #8c949e; --rule: #2a3340; --accent: #8fa6ff; --warn-bg: #3a2f10; --warn-ink: #f3d68a;
    --bad-bg: #3d1a17; --bad-ink: #ffb4a9; --ok: #6fd48f; --empty-ink: #f0cf73; --empty-bg: #3a3014;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10151c; --surface: #171d26; --surface-2: #1e2530; --ink: #e9ecef; --ink-2: #b3bac3;
  --ink-3: #8c949e; --rule: #2a3340; --accent: #8fa6ff; --warn-bg: #3a2f10; --warn-ink: #f3d68a;
  --bad-bg: #3d1a17; --bad-ink: #ffb4a9; --ok: #6fd48f; --empty-ink: #f0cf73; --empty-bg: #3a3014;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button, input, select { font: inherit; color: inherit; }

/* ---- header */
.top { background: var(--surface); border-bottom: 1px solid var(--rule); padding: 14px 0 12px; }
.top-inner { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--ink-2); }
.updated { margin: 0; color: var(--ink-3); font-size: 0.85rem; }

.status { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.status li { position: relative; background: var(--surface-2); border-radius: 8px; padding: 7px 10px 7px 14px; overflow: hidden; }
.status li::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--c, var(--line)); }
.status .name { display: block; font-weight: 600; font-size: 0.85rem; }
.status .st { font-size: 0.85rem; color: var(--ok); }
.status li.bad .st { color: var(--bad-ink); font-weight: 600; }
.status details summary { cursor: pointer; list-style: none; }
.status details summary::-webkit-details-marker { display: none; }
.status li:has(details[open]) { grid-column: 1 / -1; }
.status .why { margin: 6px 0 0; font-size: 0.85rem; color: var(--ink-2); }

/* ---- tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-top: 14px; padding-bottom: 2px; scrollbar-width: none; }
.tabs button { flex: none; border: 0; background: transparent; padding: 8px 12px; border-radius: 8px;
  color: var(--ink-2); cursor: pointer; font-weight: 500; }
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-current="page"] { background: var(--ink); color: var(--bg); }

/* ---- controls */
.controls { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 12px; margin: 12px 0; display: grid; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; }
.field { display: grid; gap: 5px; min-width: 0; }
.field.grow { flex: 1 1 260px; }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button { border: 1px solid var(--rule); background: var(--surface); border-radius: 999px; padding: 6px 12px 6px 10px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }
.pills button::before { content: ""; width: 11px; height: 11px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px rgb(0 0 0 / .15) inset; }
.pills button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-right: 1px solid var(--rule); background: var(--surface); padding: 6px 11px; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg .today::after { content: " •"; color: var(--accent); }
.seg button[aria-pressed="true"].today::after { color: inherit; }
.check { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.search { flex: 1 1 200px; }
input[type="search"], input[type="text"], select { width: 100%; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 8px; padding: 7px 10px; min-height: 36px; }
#train-no { width: 9em; font-family: var(--mono); }
.train-chips { display: flex; flex-wrap: wrap; gap: 4px; max-height: 5.6em; overflow-y: auto; }
.train-chips button { font-family: var(--mono); font-size: 0.82rem; border: 1px solid var(--rule); background: var(--surface-2);
  border-radius: 6px; padding: 2px 6px; cursor: pointer; }
.train-chips button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
[hidden] { display: none !important; }

/* ---- banners */
.banner { border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; font-size: 0.9rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.info { background: var(--surface-2); color: var(--ink-2); }
.banner strong { color: inherit; }

/* ---- tables */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); margin: 0 0 14px; overflow: hidden; }
.card > h2, .card > h3 { margin: 0; padding: 10px 12px; font-size: 1rem; border-bottom: 1px solid var(--rule);
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card h2 .meta, .card h3 .meta { font-weight: 400; color: var(--ink-3); font-size: 0.85rem; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.loc { font-weight: 600; min-width: 9em; }
td.loc.depot { font-weight: 500; color: var(--ink-2); }
td.loc .n { display: block; font-weight: 400; color: var(--ink-3); font-size: 0.78rem; }
.mv { display: grid; grid-template-columns: auto auto 1fr; gap: 0 8px; align-items: baseline; }
.time { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.time sup { font-size: 0.65em; color: var(--ink-3); font-weight: 500; margin-left: 1px; }
.tn { font-family: var(--mono); font-size: 0.85rem; background: var(--surface-2); border-radius: 5px; padding: 0 5px;
  border: 0; cursor: pointer; color: inherit; white-space: nowrap; }
.tn:hover { background: var(--ink); color: var(--bg); }
.route { color: var(--ink-2); font-size: 0.85rem; min-width: 0; }
.tag { display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 0 5px; border-radius: 4px; vertical-align: 1px; margin-left: 4px; }
.tag.empty { background: var(--empty-bg); color: var(--empty-ink); }
.tag.other { background: var(--surface-2); color: var(--ink-2); }
.tag.night { background: #1b2a6b; color: #fff; }
.dim { color: var(--ink-3); }
.empty { color: var(--ink-3); padding: 18px 12px; margin: 0; }

/* station view: day columns */
.days-grid td.day { font-weight: 600; white-space: nowrap; }
.dep { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.dep + .dep { margin-top: 3px; }
.dep .dest { color: var(--ink-2); font-size: 0.85rem; }

/* train view */
.trip { border-top: 1px solid var(--rule); }
.trip:first-of-type { border-top: 0; }
.trip summary { cursor: pointer; padding: 9px 12px; display: grid; grid-template-columns: 4.2em 1fr; gap: 2px 10px; list-style: none; }
.trip summary::-webkit-details-marker { display: none; }
.trip summary .tripno { color: var(--ink-3); font-size: 0.8rem; grid-row: span 2; padding-top: 2px; }
.trip summary .notes { color: var(--ink-3); font-size: 0.8rem; }
.calls { list-style: none; margin: 0; padding: 0 12px 10px 5.4em; columns: 2 16em; column-gap: 24px; }
.calls li { display: flex; gap: 10px; font-size: 0.87rem; padding: 1px 0; break-inside: avoid; }
.calls li .time { font-weight: 500; min-width: 4.2em; }
.calls li.e .time { color: var(--empty-ink); }

/* works view */
.works { list-style: none; margin: 0; padding: 0; }
.works li { padding: 10px 12px; border-top: 1px solid var(--rule); position: relative; padding-left: 18px; }
.works li:first-child { border-top: 0; }
.works li::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.works .when { font-weight: 600; font-size: 0.9rem; }
.works p { margin: 3px 0 0; color: var(--ink-2); font-size: 0.9rem; }
.numbering { font-size: 0.87rem; }
.numbering td:first-child { font-family: var(--mono); white-space: nowrap; color: var(--ink-2); }
.numbering tr.hd td { font-weight: 600; color: var(--ink); background: var(--surface-2); font-family: var(--sans); }
.prose { padding: 10px 14px; font-size: 0.92rem; }
.prose p { margin: 0 0 8px; }
.prose ul { margin: 0 0 8px; padding-left: 20px; }
.foot { color: var(--ink-3); font-size: 0.8rem; padding-top: 12px; padding-bottom: 28px; }
a { color: var(--accent); }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .controls { padding: 10px; }
  th, td { padding: 6px 8px; }
  /* First & last collapses to cards: location on top, first/last below */
  table.fl thead { display: none; }
  table.fl tr { display: grid; grid-template-columns: 1fr; border-bottom: 1px solid var(--rule); padding: 6px 0; }
  table.fl td { border: 0; padding: 3px 10px; }
  table.fl td[data-k]::before { content: attr(data-k); display: block; font-size: 0.68rem; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }
  .calls { padding-left: 12px; }
}
@media print {
  .top .status, .tabs, .controls, .foot { display: none; }
  body { background: #fff; }
}
