* { box-sizing: border-box; }
:root { --ink: #1f2328; --muted: #5b626a; --line: #e3e5e6; --accent: #6f42c1; --early: #3b82f6; --ontime: #1a9850; --late: #f5a300; --vlate: #d7191c; }
body { margin: 0; font-family: system-ui, sans-serif; color: var(--ink); background: #f6f6f8; }
main { max-width: 1000px; margin: 0 auto; padding: 20px 16px 48px; }
header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 28px 0 8px; }
.sub { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.back { color: var(--accent); text-decoration: none; font-weight: 600; white-space: nowrap; }
.back:hover { text-decoration: underline; }
.periods { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.periods button { font: inherit; padding: 7px 14px; border: 1px solid #c9ccd0; border-radius: 18px; background: #fff; cursor: pointer; }
.periods button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.periods[hidden] { display: none; }
.periods.lines { align-items: center; }
.periods.lines .lbl { color: var(--muted); font-size: .85rem; margin-right: 2px; }
.periods.lines button { padding: 5px 12px; font-size: .9rem; }
/* Provider buttons in the operators' own colours (dark text: both are light). Pressed ones keep the colour and gain a dark ring. */
.periods button[data-g="Arriva"] { --brand: #54C8D4; }
.periods button[data-g="Metro"] { --brand: #FBEF36; }
.periods button[data-g] { background: var(--brand, #fff); border-color: var(--brand, #c9ccd0); color: #1d2125; }
.periods button[data-g][aria-pressed="true"] { background: var(--brand, var(--accent)); border-color: #1d2125; box-shadow: 0 0 0 1px #1d2125; color: #1d2125; font-weight: 700; }
.prov { display: inline-block; padding: 2px 10px; border-radius: 12px; background: var(--brand, #e3e5e8); color: #1d2125; font-weight: 600; }
.prov[data-g="Arriva"] { --brand: #54C8D4; }
.prov[data-g="Metro"] { --brand: #FBEF36; }
.periods button:focus-visible, .back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#message { color: var(--muted); min-height: 1.2em; margin: 0 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tile .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tile .value { font-size: 2rem; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.tile .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.early { background: var(--early); } .sw.ontime { background: var(--ontime); } .sw.late { background: var(--late); } .sw.vlate { background: var(--vlate); }
.table-wrap { overflow-x: auto; background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.svc { font-weight: 700; }
.spread { display: flex; gap: 2px; width: 220px; min-width: 160px; height: 14px; }
.spread span { display: block; height: 100%; min-width: 0; }
.spread .early { background: var(--early); border-radius: 4px 0 0 4px; } .spread .ontime { background: var(--ontime); } .spread .late { background: var(--late); } .spread .vlate { background: var(--vlate); border-radius: 0 4px 4px 0; }
.chart { background: #fff; border-radius: 10px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: #8b9097; stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart rect.bar { fill: var(--accent); }
.chart rect.hit { fill: transparent; }
.chart g.col:hover rect.bar, .chart g.col:focus rect.bar { fill: #5a32a3; }
.chart g.col:focus { outline: none; }
#tip { position: fixed; z-index: 10; pointer-events: none; background: #1f2328; color: #fff; font-size: .82rem; padding: 6px 9px; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.notes ul { color: var(--muted); font-size: .88rem; padding-left: 20px; line-height: 1.5; }
@media (max-width: 600px) { h1 { font-size: 1.25rem; } .tile .value { font-size: 1.6rem; } }

.banner { background: #fff3cd; border: 1px solid #f0d58a; color: #5c4400; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: .92rem; }
.banner.bad { background: #fde8e8; border-color: #f2b8b8; color: #7a1c1c; }
.quality { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.quality li { background: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); display: flex; gap: 10px; align-items: baseline; font-size: .92rem; }
.quality .mark { font-weight: 700; flex: none; width: 1.2em; text-align: center; }
.quality .good .mark { color: var(--ontime); } .quality .warn .mark { color: #b45309; } .quality .bad .mark { color: var(--vlate); }
.quality small { display: block; color: var(--muted); }
h3 { font-size: .95rem; margin: 20px 0 8px; }
.kind { display: inline-flex; align-items: center; gap: 6px; }
a.bus-link { color: var(--accent); font-weight: 600; text-decoration: none; }
a.bus-link:hover { text-decoration: underline; }
td small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; }

/* ---- train stats page ---- */
.banner.info { background: #e8f0fe; border-color: #b8cdf5; color: #1f3a5f; }
.line-tag { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; }
td.wrap { white-space: normal; }

#slowMap { height: 360px; border-radius: 10px; margin: 0 0 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); background: #e9ecef; }
#slowList tbody tr { cursor: pointer; }
#slowList tbody tr:hover { background: #f4f5f7; }
.run-over { color: #b45309; font-weight: 600; }
.run-under { color: var(--ontime); }
#runTimes th small { display: block; font-weight: 400; color: var(--muted); }
.trends { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.trend { background: #fff; border-radius: 10px; padding: 10px 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.trend .t-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.trend .t-line { font-weight: 700; }
.trend .t-op { color: var(--muted); font-size: .75rem; }
.trend .t-now { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.trend .t-delta { font-size: .8rem; font-weight: 600; }
.trend .t-delta.up { color: var(--ontime); } .trend .t-delta.down { color: var(--vlate); } .trend .t-delta.flat { color: var(--muted); }
.trend svg { display: block; width: 100%; height: 44px; margin: 4px 0 2px; }
.trend svg polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.trend svg circle { fill: var(--accent); }
.trend .t-dates { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.qflag { display: inline-block; width: 1.25em; height: 1.25em; line-height: 1.25em; text-align: center; border-radius: 50%; font-size: .75rem; font-weight: 700; color: #fff; margin-left: 4px; cursor: help; }
.qflag.warn { background: #b45309; } .qflag.bad { background: var(--vlate); }
.cgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 8px; }
.cbox { background: #fff; border-radius: 10px; padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); min-width: 0; }
.cbox.cwide { grid-column: 1 / -1; }
.cbox h3, h3.clist { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 0 0 8px; font-weight: 600; }
h3.clist { margin-top: 16px; }
.cbars { display: grid; gap: 6px; }
.crow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: .88rem; }
.crow .cl { overflow-wrap: anywhere; } .crow .cl small { display: block; color: var(--muted); font-size: .75rem; }
.crow .cn { font-weight: 700; text-align: right; }
.cbar { grid-column: 1 / -1; display: flex; height: 7px; border-radius: 4px; background: #eef0f1; overflow: hidden; }
.cbar .sys, .sw.sys { background: #9aa3ab; } .cbar .op, .sw.op { background: var(--accent); }
.chours { display: flex; align-items: flex-end; gap: 3px; height: 96px; }
.chours .ch { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.chours .ch span { display: block; } .chours .ch .sys { background: #9aa3ab; } .chours .ch .op { background: var(--accent); }
.chours-axis { display: flex; gap: 3px; font-size: .7rem; color: var(--muted); margin-top: 2px; }
.chours-axis span { flex: 1; text-align: center; min-width: 0; }
.clegend .sw { margin-left: 12px; } .clegend .sw:first-child { margin-left: 0; }
.heat-wrap { overflow-x: auto; background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); padding: 10px 12px; }
.heat { display: grid; grid-template-columns: minmax(120px, 150px) repeat(24, minmax(26px, 1fr)); gap: 2px; min-width: 780px; font-size: .75rem; }
.heat .h-label { align-self: center; font-weight: 600; font-size: .8rem; padding-right: 6px; }
.heat .h-label small { display: block; font-weight: 400; color: var(--muted); font-size: .7rem; }
.heat .h-hour { text-align: center; color: var(--muted); font-size: .7rem; padding-bottom: 2px; }
.heat .h-cell { height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-weight: 600; background: #eceff1; color: #8a9199; cursor: default; }

.lazy-note { margin: 16px 0; min-height: 1.4em; color: #666; font-size: .9rem; }
.lazy-note[hidden] { display: none; }
