/* TrainTracker public site styles.
   Colour tokens live in common.css; everything else is here, one rule per
   selector. Sections: base · header · controls · search · home · board ·
   class/unit pages · service detail · modals · history/league · responsive. */

:root {
  --mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --r-sm: 8px;   /* controls */
  --r-md: 12px;  /* cards, lists, banners */
  --r-pill: 999px;
  --fs-xs: .78rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.2rem;
  --fs-time: 1.15rem;
  --cp-dot-size: clamp(1.1rem, 2.2vw, 1.6rem);
  --cp-name-fs: clamp(1rem, .9rem + .4cqi, 1.2rem);
  --cp-time-fs: clamp(1rem, .9rem + .4cqi, 1.15rem);
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; font-size: clamp(1rem, .7rem + .4vw, 1.75rem); -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); min-height: 100vh; overflow-x: hidden; -webkit-font-smoothing: antialiased; transition: background .2s ease, color .2s ease; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.view { display: none; }
.view.active { display: block; }
.page { max-width: min(94vw, 72rem); margin: 0 auto; padding: 1.5rem 1.25rem; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Header ── */
header { position: sticky; top: 0; z-index: 200; background: rgba(255,255,255,.72); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border); padding: 0 20px; height: 3.375rem; display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; overflow: visible; }
body.light header { background: rgba(28,28,30,.72); }
.logo { font-size: var(--fs-sm); font-weight: 600; letter-spacing: -.01em; color: var(--text); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.logo-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: blink 2s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }
.header-search-wrap { flex: 1; max-width: 28rem; min-width: 0; position: relative; }
.header-search-wrap input { width: 100%; background: var(--surface2); border: 1px solid transparent; border-radius: 10px; padding: 8px 12px 8px 34px; font: var(--fs-sm) var(--sans); color: var(--text); outline: none; transition: box-shadow .2s, background .2s; }
.header-search-wrap input:focus { background: var(--surface); box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
.header-search-wrap input::placeholder { color: var(--text-dim); }
.search-icon-hdr { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: var(--fs-sm); pointer-events: none; }
.header-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.nav-btn { font: 500 var(--fs-sm) var(--sans); color: var(--text-mid); background: none; border: 1px solid transparent; border-radius: var(--r-sm); padding: 6px 12px; cursor: pointer; transition: all .15s; text-decoration: none; white-space: nowrap; }
.nav-btn:hover, .nav-btn.active { color: var(--accent); background: var(--surface2); }
.board-header > .nav-btn { border-color: var(--border2); background: var(--surface); color: var(--text); font-weight: 600; }
.tf-sel { border: 1px solid var(--border2); background: var(--surface); color: var(--text); max-width: 13rem; }
#theme-btn { font-size: var(--fs-xs); }
.back-btn { font: 500 var(--fs-sm) var(--sans); background: none; border: none; color: var(--accent); padding: 0; cursor: pointer; transition: opacity .15s; margin-bottom: 1rem; display: inline-flex; align-items: center; gap: 6px; }
.back-btn:hover { opacity: .7; }

/* ── Controls ──
   .tab-btn is the one button style: a bordered button, accent-filled when
   active. Inside a segmented group (.board-tabs, .seg, .detail-toggle-row)
   it becomes a flat segment on a grey track. */
.tab-btn { font: 600 var(--fs-sm) var(--sans); background: var(--surface); border: 1px solid var(--border2); border-radius: var(--r-sm); color: var(--text); padding: .4rem .8rem; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.tab-btn:hover:not(.active) { background: var(--surface2); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.board-tabs, .seg, .detail-toggle-row { display: flex; gap: 2px; background: var(--surface2); border-radius: 10px; padding: 2px; }
.board-tabs .tab-btn, .seg .tab-btn { background: transparent; border-color: transparent; color: var(--text-dim); border-radius: var(--r-sm); }
.board-tabs .tab-btn:hover:not(.active), .seg .tab-btn:hover:not(.active) { background: transparent; color: var(--text); }
.board-tabs .tab-btn.active, .seg .tab-btn.active { background: var(--surface); border-color: transparent; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.detail-toggle-row { width: fit-content; margin-bottom: 14px; }
.toggle-chip { font: 600 var(--fs-sm) var(--sans); padding: 5px 12px; border-radius: var(--r-sm); cursor: pointer; color: var(--text-dim); background: transparent; transition: all .15s; }
.toggle-chip.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.field-input { background: var(--surface2); border: 1px solid transparent; border-radius: var(--r-sm); color: var(--text); padding: 9px 12px; font: var(--fs-sm) var(--sans); outline: none; transition: box-shadow .2s; cursor: pointer; }
.field-input:focus { box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
.field-input.date-sm { padding: .375rem .625rem; width: 9rem; }
.quick-chip { font: 500 var(--fs-sm) var(--sans); color: var(--text-mid); background: var(--surface2); border: 1px solid transparent; border-radius: 20px; padding: 7px 14px; cursor: pointer; transition: all .15s; }
.quick-chip:hover { color: #fff; background: var(--accent); }

/* ── Search dropdown ── */
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; z-index: 300; display: none; box-shadow: var(--shadow-md); }
.search-results.open { display: block; }
.search-result { display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer; transition: background .1s; border-bottom: 1px solid var(--border); }
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--surface2); }
.result-crs { font: var(--fs-xs) var(--mono); color: var(--accent); background: rgba(0,113,227,.1); border-radius: 6px; padding: 3px 7px; min-width: 38px; text-align: center; }
.result-name { font-size: var(--fs-sm); color: var(--text); }
.result-type { font: var(--fs-xs) var(--mono); color: var(--text-dim); margin-left: auto; }

/* ── Home ── */
#home { min-height: calc(100vh - 3.375rem); flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; position: relative; }
#home.active { display: flex; }
.hero-grid { position: absolute; inset: 0; background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px); background-size: 40px 40px; opacity: .5; mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black, transparent); }
body.light .hero-grid { opacity: .25; }
.hero { position: relative; text-align: center; max-width: 36rem; width: 100%; }
.hero-tag { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em; color: var(--accent); text-transform: uppercase; margin-bottom: 16px; opacity: .9; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 700; letter-spacing: -.02em; color: var(--text); line-height: 1.1; margin-bottom: 10px; }
.hero h1 span { color: var(--accent); }
.hero-sub { color: var(--text-mid); font-size: clamp(1rem, .95rem + .3vw, 1.2rem); margin-bottom: 36px; line-height: 1.6; }
.home-search-wrap { position: relative; width: 100%; max-width: 32rem; margin: 0 auto; }
.home-search-icon { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }
#home-search { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 16px 18px 16px 46px; font: 1.05rem var(--sans); color: var(--text); outline: none; box-shadow: var(--shadow-md); transition: box-shadow .3s ease, transform .3s ease; }
#home-search::placeholder { color: var(--text-dim); }
#home-search:focus { box-shadow: 0 12px 32px rgba(0,113,227,.16); transform: scale(1.01); }
.home-search-results { position: absolute; top: calc(100% + 8px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; z-index: 200; display: none; box-shadow: var(--shadow-lg); }
.home-search-results.open { display: block; }
.quick-links { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; justify-content: center; }

/* ── Alerts and operator status ── */
.banner-strip { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.alert-chip { display: flex; align-items: flex-start; gap: 8px; padding: 11px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.4; cursor: pointer; }
.alert-chip.disruption { background: rgba(255,59,48,.08); border: 1px solid rgba(255,59,48,.18); color: #c0332b; }
.alert-chip.info { background: rgba(0,113,227,.08); border: 1px solid rgba(0,113,227,.18); color: #0b5cab; }
.alert-chip.warning { background: rgba(255,159,10,.1); border: 1px solid rgba(255,159,10,.22); color: #a15c00; }
.nsi-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.nsi-chip { font: 600 var(--fs-xs) var(--sans); padding: 4px 10px; border-radius: 20px; cursor: pointer; color: #fff; white-space: nowrap; }
.nsi-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 4px; vertical-align: middle; }
.nsi-good { background: var(--green-fill); color: #fff; }

/* ── Board header, filters, time controls ── */
.board-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.board-title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.crs-badge { font: var(--fs-xs) var(--mono); color: var(--accent); background: rgba(0,113,227,.1); border-radius: 6px; padding: 3px 8px; }
.board-shift-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.board-shift-bar .seg { flex: 0 1 auto; }
.board-window, .refresh-indicator { font: var(--fs-xs) var(--mono); color: var(--text-dim); }
.refresh-group { display: flex; align-items: center; gap: 8px; margin-left: auto; }
#toc-filter { gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
#toc-filter .tab-btn { border-radius: var(--r-pill); padding: .25rem .7rem; font-size: var(--fs-xs); }
#toc-filter .tab-btn span { opacity: .6; }
.tf-note { font-size: var(--fs-xs); color: var(--text-dim); margin: 0 0 10px; }
.tf-note a, .board-empty a { color: var(--accent); }
.tf-custom { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.tf-custom label { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: var(--text-dim); }
.board-loading, .board-empty { text-align: center; padding: 50px 20px; color: var(--text-dim); font-size: var(--fs-sm); }
.board-loading::after { content: ''; display: block; width: 22px; height: 22px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; margin: 14px auto 0; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Service rows: one list, hairline dividers, operator colour on the left ── */
.services-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.service-row { display: grid; align-items: start; gap: .5rem; padding: .7rem 1rem .7rem 1.15rem; border-bottom: 1px solid var(--border); min-height: 3.75rem; cursor: pointer; position: relative; transition: background .12s; grid-template-columns: 4.5rem minmax(0,1fr) 12rem 2.25rem 5.5rem; column-gap: .75rem; }
.service-row:last-child { border-bottom: 0; }
.service-row::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--toc-col, var(--border2)); }
.service-row:hover { background: var(--surface2); }
.service-row.cancelled { opacity: .55; }
.service-row.cancelled::before { background: var(--red); }
.svc-time, .svc-status, .svc-plat, .svc-hc { align-self: center; }
.svc-time { font: 700 var(--fs-time) var(--mono); color: var(--text); white-space: nowrap; }
.svc-time-sched { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--text-dim); text-decoration: line-through; margin-top: 1px; }
.svc-body { display: flex; flex-direction: column; min-width: 0; }
.svc-main { font-size: var(--fs-md); color: var(--text); line-height: 1.25; overflow-wrap: break-word; }
.svc-sub { font-size: var(--fs-sm); color: var(--text-dim); line-height: 1.25; overflow-wrap: break-word; }
.svc-tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.svc-hc { font: var(--fs-sm) var(--mono); color: var(--text-dim); min-width: 0; overflow: hidden; }
.svc-toc-link { font-family: var(--sans); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.svc-toc-link:hover { color: var(--accent); text-decoration: underline dotted; }
.svc-plat { font: var(--fs-sm) var(--mono); text-align: center; color: var(--text-mid); }
.svc-plat span { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; }
.svc-status { font: var(--fs-sm) var(--mono); text-align: right; white-space: nowrap; }
.svc-status.sev-green, .cp-delay.sev-green { color: var(--green-ink); }
.svc-status.sev-amber, .cp-delay.sev-amber { color: var(--amber-ink); }
.svc-status.sev-red, .cp-delay.sev-red { color: var(--red-ink); }
.svc-status.predicted { color: var(--amber-ink); font-style: italic; }
.svc-status.cancelled, .cp-delay.cancelled { color: var(--red-ink); font-weight: 700; text-decoration: line-through; }
.tag { font: var(--fs-xs) var(--mono); letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; color: #fff; }
.tag.bus { background: var(--accent2); }
.tag.ecs { background: #37474F; }
.tag.freight { background: #8B4513; }
.tag.railtour { background: #7c3aed; }
.tag.ferry { background: #0891b2; }
.tag.split { background: #6d28d9; }
.tag.join { background: var(--green-fill); }
.tag.forms { background: #0b5cab; }
.tag.passing { background: #57575c; }
.tag.cancelled { background: var(--red-fill); }
.tag.var { background: var(--amber-fill); }

/* ── Class page: a grid of unit tiles ── */
.class-count { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: 10px; }
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr)); gap: .5rem; }
.class-unit { font: var(--fs-sm) var(--mono); color: var(--purple); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: .75rem .5rem; text-align: center; cursor: pointer; transition: background .12s; }
.class-unit:hover { background: var(--surface2); }

/* ── Unit diagram ── */
.diagram-list { display: flex; flex-direction: column; }
.diag-header { background: var(--surface2); border-radius: 10px; padding: 11px 15px; margin-top: 12px; margin-bottom: 2px; cursor: pointer; }
.diag-header:first-child { margin-top: 0; }
.diag-hc { font: 700 var(--fs-sm) var(--mono); color: var(--accent); }
.diag-route { font-size: var(--fs-sm); color: var(--text); margin-top: 2px; }
.diag-meta { font: var(--fs-xs) var(--mono); color: var(--text-dim); margin-top: 3px; }
.diag-gap { font: var(--fs-xs) var(--mono); color: var(--text-dim); padding: 6px 14px; letter-spacing: .06em; }
.diag-stops { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--r-sm) var(--r-sm); }
.diag-cp { display: grid; grid-template-columns: 1fr 3.25rem 4rem; gap: 8px; padding: 6px 14px; font-size: var(--fs-sm); border-bottom: 1px solid var(--border); }
.diag-cp:last-child { border-bottom: none; }
.diag-cp-name { color: var(--text-mid); }
.diag-cp-sched { font-family: var(--mono); color: var(--text-dim); text-align: right; }
.diag-cp .cp-actual { font-size: inherit; }

/* ── Service detail ── */
.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 18px 20px; margin-bottom: 16px; }
.detail-hc { font: 700 1.05rem var(--mono); color: var(--accent); letter-spacing: .02em; margin-bottom: 4px; }
.detail-route { font-size: var(--fs-sm); color: var(--text); margin-bottom: 4px; }
.detail-meta { font: var(--fs-xs) var(--mono); color: var(--text-dim); }
.detail-note { display: none; color: var(--text-dim); font: var(--fs-xs) var(--mono); margin-top: 4px; }
.detail-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.unit-chip { font: var(--fs-xs) var(--mono); letter-spacing: .03em; color: var(--purple); background: rgba(175,82,222,.1); border-radius: 6px; padding: 3px 8px; }
.coach-chip { font: var(--fs-xs) var(--mono); color: var(--text-mid); background: var(--surface2); border-radius: 6px; padding: 3px 8px; }
.unit-legs { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.unit-leg-route { font-size: var(--fs-sm); color: var(--text-mid); margin-bottom: 5px; }
.unit-leg-time { font: var(--fs-xs) var(--mono); color: var(--text-dim); }
.unit-leg-units { display: flex; gap: 6px; flex-wrap: wrap; }
.unit-leg-veh { font: var(--fs-xs) var(--mono); color: var(--text-dim); margin-top: 5px; line-height: 1.5; word-spacing: .4em; }
.cp-fork { margin: 2px 0 2px 24px; font-size: var(--fs-xs); color: var(--purple); display: flex; gap: 8px; align-items: center; }
.fork-icon { opacity: .7; }
.fork-link { cursor: pointer; text-decoration: underline dotted; }
.fork-link:hover { color: var(--text); }
.info-banner { border-radius: var(--r-md); padding: 10px 15px; margin-bottom: 10px; font-size: var(--fs-sm); cursor: pointer; }
.cancel-banner { background: rgba(255,59,48,.08); border: 1px solid rgba(255,59,48,.18); border-radius: var(--r-md); padding: 11px 15px; margin-bottom: 14px; font-size: var(--fs-sm); color: #c0332b; }
.split-banner { background: rgba(175,82,222,.07); border: 1px solid rgba(175,82,222,.18); color: #8c2fb5; }
.split-banner:hover { background: rgba(175,82,222,.13); }
.join-banner { background: rgba(52,199,89,.08); border: 1px solid rgba(52,199,89,.2); color: #1f7a3d; }
.forms-banner { background: rgba(0,113,227,.07); border: 1px solid rgba(0,113,227,.18); color: #0b5cab; }
.stock-banner { background: rgba(110,110,115,.06); border: 1px dashed rgba(110,110,115,.3); color: var(--text-dim); }
.stock-banner:hover { background: rgba(110,110,115,.12); }
body.light .cp-name.cancelled, body.light .cancel-banner { color: #ff8a80; }
body.light .split-banner { color: #dab6fb; }
body.light .join-banner { color: #8ff0ac; }
body.light .forms-banner { color: #8fcaff; }
body.light .cp-platform.unconfirmed { color: var(--amber); }

/* Calling points. Simple view: dot · name · arr · dep · delay.
   Detailed view: dot · name · scheduled arr/dep · actual arr/dep. */
.calling-list { position: relative; container-type: inline-size; --cp-detail-col: clamp(4rem, 9cqi, 6rem); --cp-simple-columns: var(--cp-dot-size) minmax(0,1fr) 4.5rem 4.5rem 3.5rem; }
.cp-row { display: grid; grid-template-columns: var(--cp-simple-columns); gap: 6px; padding: 8px 0; position: relative; align-items: start; }
.cp-row::before { content: ''; position: absolute; left: calc(var(--cp-dot-size) / 2); top: 0; bottom: 0; width: 1px; background: var(--border2); z-index: 0; }
.cp-row:first-child::before { top: 50%; }
.cp-row:last-child::before { bottom: 50%; }
.cp-row.cp-before-origin { opacity: .45; }
.cp-dot { width: var(--cp-dot-size); height: var(--cp-dot-size); border-radius: 50%; background: var(--bg); border: 2px solid var(--border3); flex-shrink: 0; position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; transition: background .2s; }
.cp-dot.passed { background: var(--green); border-color: var(--bg); }
.cp-dot.passed::after { content: '✓'; font-size: calc(var(--cp-dot-size) * .65); font-weight: 900; line-height: 1; color: #fff; }
.cp-dot.passed.inf::after, .cp-dot.passed.sched::after { content: none; }
.cp-dot.passed.sched { background: var(--border2); }
.cp-dot.current { background: var(--accent); border-color: var(--bg); box-shadow: 0 0 8px var(--accent); }
.cp-dot.current::after { content: '●'; font-size: calc(var(--cp-dot-size) * .4); line-height: 1; color: #fff; }
.cp-dot.cancelled { background: var(--red); border-color: var(--bg); }
.cp-dot.cancelled::after { content: '✕'; font-size: calc(var(--cp-dot-size) * .6); font-weight: 900; line-height: 1; color: #fff; }
.cp-name { min-width: 0; font-size: var(--cp-name-fs); color: var(--text); }
.cp-name.passed { color: var(--text-mid); }
.cp-name.cancelled { color: var(--red); text-decoration: line-through; }
.cp-pass-note { white-space: nowrap; font-size: .85em; }
.cp-crs { display: block; font: var(--fs-xs) var(--mono); color: var(--text-dim); margin-top: 1px; }
.cp-platform { display: inline-block; font: var(--fs-xs) var(--mono); color: var(--text-dim); margin-top: 1px; margin-left: 6px; padding: 1px 6px; border-radius: 5px; background: var(--surface2); }
.cp-platform.unconfirmed { color: #a15c00; background: rgba(255,159,10,.1); }
.cp-arrival, .cp-departure { font: var(--cp-time-fs) var(--mono); text-align: right; display: flex; flex-direction: column; line-height: 1.25; align-self: center; }
.cp-delay { font: var(--cp-time-fs) var(--mono); text-align: right; align-self: center; }
.cp-actual { font: var(--cp-time-fs) var(--mono); text-align: right; }
.cp-actual.confirmed { font-weight: 700; }
.cp-actual.unconfirmed { opacity: .6; }
.cp-sched-arr { color: var(--text-mid); }
.cp-sched-dep { color: var(--text-mid); opacity: .7; }
.cp-detail-actual { display: none; font: var(--cp-time-fs) var(--mono); text-align: right; }
.calling-list:not(.detailed) .cp-arrival { grid-column: 3; grid-row: 1; }
.calling-list:not(.detailed) .cp-departure { grid-column: 4; grid-row: 1; }
.calling-list:not(.detailed) .cp-delay { grid-column: 5; grid-row: 1; }
.calling-list:not(.detailed) .cp-sched-arr, .calling-list:not(.detailed) .cp-sched-dep { display: none; }
.calling-list:not(.detailed) .cp-actual { font-size: inherit; white-space: nowrap; }
.calling-list.detailed .cp-row, .calling-list.detailed .cp-detail-header { grid-template-columns: var(--cp-dot-size) minmax(0,1fr) repeat(4, var(--cp-detail-col)); }
.calling-list.detailed .cp-arrival, .calling-list.detailed .cp-departure { display: contents; }
.calling-list.detailed .cp-sched-arr { grid-column: 3; grid-row: 1; }
.calling-list.detailed .cp-sched-dep { grid-column: 4; grid-row: 1; }
.calling-list.detailed .cp-detail-arr { grid-column: 5; grid-row: 1; }
.calling-list.detailed .cp-detail-dep { grid-column: 6; grid-row: 1; }
.calling-list.detailed .cp-sched-arr, .calling-list.detailed .cp-sched-dep, .calling-list.detailed .cp-detail-arr, .calling-list.detailed .cp-detail-dep { align-self: center; font-size: var(--cp-time-fs); }
.calling-list.detailed .simple-actual { display: none; }
.calling-list.detailed .cp-detail-actual { display: block; }
.cp-header { display: none; }
.cp-simple-header { display: grid; grid-template-columns: var(--cp-simple-columns); align-items: end; gap: 6px; padding: 0 0 5px; margin-bottom: 2px; }
.cp-simple-header > div:nth-child(n+3) { text-align: right; font: var(--fs-xs) var(--mono); color: var(--text-dim); line-height: 1.1; }
.calling-list.detailed .cp-simple-header { display: none; }
.calling-list.detailed .cp-detail-header { display: grid; align-items: end; gap: 6px; padding: 0 0 5px; margin-bottom: 2px; }
.cp-header-group { text-align: center; font: 600 var(--fs-xs) var(--mono); color: var(--text-dim); line-height: 1.1; }
.cp-header-sub { text-align: right; font: var(--fs-xs) var(--mono); color: var(--text-dim); line-height: 1.1; }
.calling-list.detailed .cp-header-group.scheduled { grid-column: 3 / span 2; grid-row: 1; }
.calling-list.detailed .cp-header-group.actual { grid-column: 5 / span 2; grid-row: 1; }
.calling-list.detailed .cp-header-sub.scheduled-arr { grid-column: 3; grid-row: 2; }
.calling-list.detailed .cp-header-sub.scheduled-dep { grid-column: 4; grid-row: 2; }
.calling-list.detailed .cp-header-sub.actual-arr { grid-column: 5; grid-row: 2; }
.calling-list.detailed .cp-header-sub.actual-dep { grid-column: 6; grid-row: 2; }
/* Simple/Detailed visibility */
#cp-list .cp-row[data-passing="1"], #cp-list .split-banner-secondary, #cp-list .fork-detail { display: none; }
#cp-list.detailed .cp-row[data-passing="1"] { display: grid; }
#cp-list.detailed .split-banner-secondary { display: block; }
#cp-list.detailed .fork-detail { display: inline; }

/* ── Station info ── */
.info-section { margin-bottom: 18px; }
.info-section-title { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; }
.info-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.info-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 15px; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.info-row:last-child { border-bottom: none; }
.info-icon { flex-shrink: 0; width: 18px; text-align: center; margin-top: 1px; }
.info-text { color: var(--text); line-height: 1.5; flex: 1; }

/* ── Modal and bottom sheet ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 500; display: none; align-items: center; justify-content: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 22px; padding: 28px; width: 100%; max-width: 34rem; max-height: 85vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-lg); animation: modalIn .25s cubic-bezier(.175,.885,.32,1.275); }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.96) } to { opacity: 1; transform: translateY(0) scale(1) } }
.modal-close, .toc-sheet-close { position: absolute; top: 16px; right: 16px; background: var(--surface2); border: none; border-radius: 50%; width: 1.75rem; height: 1.75rem; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 1rem; cursor: pointer; transition: background .2s; }
.modal-close:hover, .toc-sheet-close:hover { background: var(--surface3); color: var(--text); }
.modal-title { font-size: var(--fs-xs); font-weight: 700; color: var(--accent); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
.modal-sub { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: 16px; }
.modal-body { font-size: var(--fs-sm); color: var(--text); line-height: 1.6; }
.toc-sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 500; display: none; align-items: flex-end; justify-content: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.toc-sheet-overlay.open { display: flex; }
.toc-sheet { background: var(--surface); border-radius: 20px 20px 0 0; padding: 10px 20px 28px; width: 100%; max-width: 34rem; max-height: 80vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-lg); transform: translateY(100%); transition: transform .28s cubic-bezier(.175,.885,.32,1.275); }
.toc-sheet-overlay.open .toc-sheet { transform: translateY(0); }
.toc-sheet-handle { width: 36px; height: 4px; background: var(--surface3); border-radius: 2px; margin: 8px auto 16px; }
.toc-sheet-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.toc-sheet-row { padding: 10px 0; border-top: 1px solid var(--surface2); font-size: var(--fs-sm); color: var(--text); }
.toc-sheet-row:first-of-type { border-top: none; }
.toc-sheet-row a { color: var(--accent); text-decoration: none; }
.toc-sheet-row a:hover { text-decoration: underline; }
.toc-sheet-label { font-size: var(--fs-xs); color: var(--text-dim); margin-bottom: 2px; }

/* ── 30-day history and punctuality ── */
.hist-summary { margin-top: 6px; font-size: var(--fs-xs); color: var(--accent); cursor: pointer; }
.hist-title { font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.hist-range { font-weight: 400; font-size: var(--fs-xs); color: var(--text-dim); margin-left: 6px; }
.hist-headline { font-size: var(--fs-sm); color: var(--text-mid); margin-bottom: 10px; }
.hist-empty { font-size: var(--fs-sm); color: var(--text-dim); }
.hist-bar { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; margin-bottom: 12px; background: var(--surface3); }
.hist-seg { min-width: 4px; }
.hist-rows { display: grid; gap: 4px; margin-bottom: 12px; }
.hist-row { display: grid; grid-template-columns: 12px 1fr auto 3rem; gap: 8px; align-items: center; font-size: var(--fs-sm); }
.hist-key { width: 10px; height: 10px; border-radius: 3px; }
.hist-lbl { color: var(--text); }
.hist-sub { color: var(--text-dim); font-size: var(--fs-xs); }
.hist-n { font-family: var(--mono); font-weight: 600; text-align: right; }
.hist-pct { font-family: var(--mono); color: var(--text-dim); text-align: right; }
.hist-days { display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px; margin-bottom: 8px; }
.hist-day { aspect-ratio: 1; border-radius: 3px; min-width: 0; display: flex; align-items: center; justify-content: center; font: 600 clamp(.55rem, .5rem + .2vw, .7rem) var(--mono); color: #fff; line-height: 1; user-select: none; }
.hist-day.h-none { color: var(--text-dim); font-weight: 400; }
.hist-day.h-ontime, .hist-day.h-late, .hist-day.h-part { color: rgba(0,0,0,.78); }
.hist-day.click { cursor: pointer; }
.hist-day.click:hover { outline: 2px solid var(--text-mid); outline-offset: 1px; }
.hist-note { font-size: var(--fs-xs); color: var(--text-dim); line-height: 1.4; }
.h-ontime { background: var(--green); }
.h-early { background: var(--accent); }
.h-late { background: var(--amber); }
.h-part { background: var(--orange); }
.h-canc { background: var(--red); }
.h-none { background: var(--surface3); }
.punct-card { margin-top: 16px; }

/* ── Operator league ── */
.league-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.league-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.league-row { display: grid; grid-template-columns: 2rem 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid; border-radius: 10px; cursor: pointer; }
.league-row:hover { background: var(--surface2); }
.league-rank { font: .9rem var(--mono); color: var(--text-dim); text-align: center; }
.league-main { min-width: 0; }
.league-name { font-weight: 600; font-size: .9rem; margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.league-bar { margin-bottom: 5px; height: 8px; }
.league-sub { font-size: var(--fs-xs); color: var(--text-dim); }
.league-score { font: 700 1.15rem var(--mono); min-width: 3.2rem; text-align: right; }
.league-score.good { color: var(--green); }
.league-score.fair { color: var(--amber); }
.league-score.poor { color: var(--red); }

/* ── Responsive ── */
@media (min-width: 75em) { .calling-list { max-width: 62rem; } }
@media (max-width: 48em) {
  header { flex-wrap: wrap; height: auto; min-height: 3.375rem; padding: .45rem 10px; row-gap: .45rem; }
  .logo { margin-right: auto; }
  .header-search-wrap { order: 10; flex: 1 1 100%; max-width: none; }
  .header-right { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 4px; min-width: 0; }
  .board-shift-bar .seg { flex: 1 1 100%; }
  .board-shift-bar .seg .tab-btn { flex: 1 1 0; text-align: center; padding-inline: .25rem; }
  .board-window { flex: 1 1 auto; }
  .refresh-group { flex: 0 0 auto; margin-left: auto; }
}
@media (max-width: 37.5em) {
  html { font-size: 100%; }
  header { padding: .45rem 10px; gap: 6px; }
  .board-shift-bar .seg .tab-btn { font-size: var(--fs-xs); white-space: nowrap; }
  .nav-btn { padding: 5px 8px; }
  .tf-sel { max-width: 6.5rem; padding: 4px; min-width: 0; }
  #theme-btn { display: none; }
  .page { padding: 1rem .75rem; }
  .board-header { gap: 7px; }
  .board-header .field-input.date-sm { flex: 1 1 8rem; width: auto; min-width: 0; }
  .service-row { grid-template-columns: 3.75rem minmax(0,1fr) 1.75rem 5rem; column-gap: .5rem; padding: .65rem .75rem .65rem 1rem; }
  .svc-hc { display: none; }
  :root { --cp-time-fs: .85rem; --cp-name-fs: .98rem; }
  .calling-list { --cp-detail-col: 2.75rem; --cp-simple-columns: var(--cp-dot-size) minmax(0,1fr) 3.25rem 3.25rem 2.75rem; }
  .calling-list.detailed .cp-row, .calling-list.detailed .cp-detail-header { gap: .15rem; }
  .cp-platform { margin-left: 0; margin-top: .2rem; }
  .hist-days { grid-template-columns: repeat(15, 1fr); }
}
@media (max-width: 26em) {
  :root { --cp-time-fs: .8rem; --cp-name-fs: .92rem; }
  .calling-list { --cp-detail-col: 2.55rem; }
  .cp-pass-note { display: block; margin-left: 0 !important; line-height: 1.2; }
}
@media (max-width: 25em) {
  .service-row { grid-template-columns: 3.75rem minmax(0,1fr) 5rem; }
  .svc-plat { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
