/* ============================================================
   Scottish Railway Map — map-first design system (TransportForge)
   Full-bleed map · floating glass panels · progressive disclosure
   ============================================================ */
:root {
  --app-bg: #eef2f7;
  --panel: #ffffff;
  --panel-glass: #ffffff;
  --surface-input: #f3f6fa;
  --surface-2: #f1f5f9;
  --surface-3: #e7edf4;
  --border: #e4eaf1;
  --border-strong: #d3dde8;
  --hairline: rgba(20, 33, 51, .07);
  --text: #131c2b;
  --text-dim: #34425a;
  --text-muted: #667486;
  --text-faint: #68778a;
  --on-accent: #ffffff;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eaf1fe;
  --success: #14875a;
  --success-bg: #e6f7ef;
  --danger: #d5273f;
  --danger-bg: #fcecee;
  --warning: #9f6206;
  --warning-bg: #fbf1de;
  --shadow-panel: 0 12px 24px -14px rgba(15, 23, 42, .42), 0 2px 5px rgba(15, 23, 42, .08);
  --shadow-soft: 0 3px 10px rgba(30, 41, 59, .1);
  --shadow-chip: 0 8px 18px rgba(15, 23, 42, .18);
  --radius: 8px;
  --radius-lg: 10px;
  --font: "Overpass", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: "Overpass Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --type-micro: .6875rem;
  --type-caption: .75rem;
  --type-control: .8125rem;
  --type-body: .875rem;
  --type-title: 1.0625rem;
  --hud-w: 372px;
}
:root[data-theme="dark"] {
  --app-bg: #0c0e12;
  --panel: #181b21;
  --panel-glass: #181b21;
  --surface-input: #12151b;
  --surface-2: #222831;
  --surface-3: #2b323d;
  --border: #2c323d;
  --border-strong: #3a414d;
  --hairline: rgba(255, 255, 255, .06);
  --text: #eef2f7;
  --text-dim: #bcc5d1;
  --text-muted: #8b95a4;
  --text-faint: #7f8b9c;
  --accent: #5ca4f7;
  --accent-strong: #7bb6f9;
  --accent-soft: #1b2a3e;
  --success: #56cfa0;
  --success-bg: #16261f;
  --danger: #ff5f7d;
  --danger-bg: #3a222a;
  --warning: #ffcf8a;
  --warning-bg: #302617;
  --shadow-panel: 0 16px 44px -8px rgba(0, 0, 0, .62), 0 2px 10px rgba(0, 0, 0, .4);
  --shadow-soft: 0 4px 18px rgba(0, 0, 0, .4);
  --shadow-chip: 0 10px 28px rgba(0, 0, 0, .6);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); color: var(--text); background: var(--app-bg); -webkit-font-smoothing: antialiased; line-height: 1.35; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.lucide, [data-lucide] { width: 16px; height: 16px; stroke-width: 2; vertical-align: -3px; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

/* ---------------- Top bar ---------------- */
#topbar { flex-shrink: 0; height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-soft); z-index: 50; position: relative; }
.tb-brand { display: flex; align-items: center; gap: 11px; color: inherit; }
.tb-text { display: flex; flex-direction: column; line-height: 1.15; }
.tb-title { font-size: 15px; font-weight: 750; letter-spacing: -.2px; }
.tb-tag { font-size: var(--type-micro); color: var(--text-muted); font-weight: 500; }
.tb-tag b { color: var(--accent); font-weight: 650; }
.tb-right { display: flex; align-items: center; gap: 6px; }
.tb-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 13px; border: 0; border-radius: 6px; background: transparent; color: var(--text-dim); font-size: 13px; font-weight: 600; transition: background .14s, color .14s; }
.tb-btn:hover { background: var(--surface-2); color: var(--text); }
.tb-btn.active { background: var(--accent-soft); color: var(--accent); }
.tb-btn.icon-only { padding: 0; width: 38px; justify-content: center; }
#mobile-dock { display: none; }

/* ---------------- Stage (map + overlays) ---------------- */
#stage { flex: 1; min-height: 0; position: relative; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-bottom-right { margin-bottom: 4px; }
.maplibregl-ctrl-attrib { font-size: 10px; background: var(--panel-glass) !important; }
.maplibregl-ctrl-attrib a { color: var(--text-muted); }
.maplibregl-ctrl-group { border-radius: 7px !important; overflow: hidden; box-shadow: var(--shadow-panel) !important; border: 1px solid var(--border) !important; }
.maplibregl-ctrl-group button { background: var(--panel) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.maplibregl-ctrl-icon { filter: var(--ctrl-filter, none); }
:root[data-theme="dark"] .maplibregl-ctrl-group button span { filter: invert(1) hue-rotate(180deg) brightness(1.1); }

/* ---------------- Shared glass panel ---------------- */
.glass {
  background: var(--panel-glass);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  border-radius: var(--radius);
}
.pop-in { animation: popIn .2s cubic-bezier(.2, .9, .3, 1.1); }
@keyframes popIn { from { opacity: 0; transform: translateY(-6px) scale(.99); } to { opacity: 1; transform: none; } }

/* ---------------- Top-left HUD ---------------- */
#hud-left { position: absolute; top: 16px; left: 16px; width: var(--hud-w); max-width: calc(100vw - 32px); z-index: 30; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
#hud-left > * { pointer-events: auto; }

#searchbar { display: flex; align-items: center; gap: 8px; padding: 7px 7px 7px 8px; border-radius: 8px;
  background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  border: 1px solid var(--border); box-shadow: var(--shadow-panel); }
.brand { flex-shrink: 0; }
.brand-mark { width: 62px; height: 42px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: transparent; color: #fff; overflow: hidden; }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 58%; transform: scale(1.12); }
.search-field { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
.search-field .s-icon { position: absolute; left: 2px; color: var(--text-faint); display: flex; pointer-events: none; }
.search-field input { width: 100%; border: 0; background: transparent; outline: none; color: var(--text); font-size: 14px; font-family: inherit; padding: 8px 22px 8px 24px; }
.search-field input::placeholder { color: var(--text-faint); }
.s-clear { position: absolute; right: -3px; width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: var(--text-faint); display: none; align-items: center; justify-content: center; }
.s-clear:hover { background: var(--surface-2); color: var(--text); }
.s-clear.show { display: flex; }
.sb-plan { flex-shrink: 0; height: 40px; border: 0; border-radius: 7px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 0 12px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .16); transition: filter .15s; }
.sb-plan:hover { filter: brightness(1.08); }
.sb-plan.active { background: var(--accent-strong); }
.sb-plan i { width: 18px; height: 18px; flex-shrink: 0; }
.sb-plan-label { white-space: nowrap; font-size: var(--type-body); font-weight: 650; }

/* Sheet wrapper (draggable bottom sheet on mobile; plain column on desktop) */
#hud-sheet { display: flex; flex-direction: column; min-height: 0; }
#sheet-handle { display: none; }
/* Contextual body column (search results / planner / station card / journey results) */
#hud-body { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 116px); overflow-y: auto; overflow-x: hidden; padding: 2px; margin: -2px; }
/* don't let a tall card get flex-shrunk to the body height — it must overflow so the body scrolls */
#hud-body > * { flex-shrink: 0; }
#hud-body:empty { display: none; }
.card { border-radius: var(--radius); background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none; border: 1px solid var(--border); box-shadow: var(--shadow-panel); overflow: hidden; }

/* search results list */
.results-list { padding: 6px; }
.results-list .s-group { font-size: var(--type-caption); letter-spacing: 0; color: var(--text-faint); font-weight: 650; padding: 8px 10px 4px; }
.s-item { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 11px; border: 0; border-radius: 5px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.s-item:hover { background: var(--surface-2); }
.s-item .s-name { font-size: 13.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-item .s-name .s-sub { display: block; font-size: var(--type-micro); color: var(--text-faint); font-weight: 500; }
.s-item .crs { font-family: var(--font-data); font-size: var(--type-micro); font-weight: 650; color: var(--text-faint); letter-spacing: 0; flex-shrink: 0; }

/* ---------------- Card scaffolding ---------------- */
.card-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 14px 0; }
.card-head .ch-main { flex: 1; min-width: 0; }
.card-head h3 { font-size: var(--type-title); font-weight: 750; letter-spacing: -.3px; line-height: 1.15; }
.card-head .ch-sub { font-size: var(--type-caption); color: var(--text-muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 5px 9px; }
.card-x { flex-shrink: 0; width: 32px; height: 32px; border: 0; border-radius: 5px; background: var(--surface-2); color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.card-x:hover { background: var(--surface-3); color: var(--text); }
.card-pad { padding: 12px 14px 14px; }
.eyebrow { font-size: var(--type-caption); font-weight: 700; letter-spacing: 0; color: var(--accent); padding: 13px 14px 0; }
.card-hint { font-size: var(--type-caption); color: var(--text-muted); display: flex; align-items: center; gap: 7px; }

/* section title */
.section-title { font-size: var(--type-caption); font-weight: 700; letter-spacing: 0; color: var(--text-muted); margin: 15px 0 8px; }
.section-title:first-child { margin-top: 0; }

/* ---------------- Station compact card ---------------- */
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 12px 14px 0; }
.mini-stat { background: var(--surface-2); border-radius: 6px; padding: 9px 6px; text-align: center; }
.mini-stat .v { font-family: var(--font-data); font-size: 14px; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; }
.mini-stat .l { font-size: var(--type-micro); text-transform: uppercase; letter-spacing: .35px; color: var(--text-muted); margin-top: 3px; }
.next-list { margin-top: 4px; }
.next-row { display: grid; grid-template-columns: 42px 1fr auto; gap: 9px; align-items: center; padding: 7px 4px; font-size: 12.5px; border-top: 1px solid var(--hairline); }
.next-row:first-child { border-top: 0; }
.next-row .t { font-family: var(--font-data); font-weight: 650; }
.next-row .dst { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.next-row .st { font-size: var(--type-micro); font-weight: 650; }
.st.ontime { color: var(--success); } .st.late { color: var(--warning); } .st.canc { color: var(--danger); } .st.sched { color: var(--text-faint); }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-top: 12px; }
.qa { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-input); color: var(--text-dim); font-size: 11px; font-weight: 600; transition: border-color .14s, background .14s; }
.qa:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.qa i { width: 17px; height: 17px; }
.qa.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.qa.primary:hover { filter: brightness(1.07); }

/* ---------------- Journey planner card ---------------- */
.pl-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px 0; }
.pl-head .eyebrow { padding: 0; }
.pl-od { display: grid; grid-template-columns: 1fr 40px; gap: 8px; align-items: center; }
.pl-fields { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pl-field { position: relative; display: flex; align-items: center; gap: 9px; background: var(--surface-input); border: 1px solid var(--border); border-radius: 7px; padding: 9px 11px; transition: border-color .14s; min-width: 0; }
.pl-field:focus-within { border-color: var(--accent); }
.pl-field .dot-o, .pl-field .dot-d { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.pl-field .dot-o { background: #fff; border: 3px solid #1a9641; }
.pl-field .dot-d { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pl-field input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--text); font-size: 13.5px; font-family: inherit; }
.pl-field input::placeholder { color: var(--text-faint); }
.pl-swap { width: 40px; height: 40px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel); color: var(--text-muted); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-soft); }
.pl-swap:hover { color: var(--accent); border-color: var(--accent); }
/* absolute overlay so suggestions never push the planner layout apart */
.pl-ac { display: none; position: absolute; top: calc(100% + 5px); left: 0; right: 0; z-index: 30; max-height: 264px; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); box-shadow: var(--shadow-panel); }
.pl-ac.open { display: block; }
.pl-ac .ac-item { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; font-size: 13px; cursor: pointer; border: 0; border-top: 1px solid var(--hairline); background: transparent; color: var(--text); text-align: left; }
.pl-ac .ac-item:first-child { border-top: 0; }
.pl-ac .ac-item:hover { background: var(--surface-2); }
.pl-ac .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-ac .ac-item .crs { font-family: var(--font-data); font-size: var(--type-micro); font-weight: 650; color: var(--text-faint); flex-shrink: 0; }
.pl-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.pl-2col .pl-field { padding: 8px 10px; }
.pl-2col input { font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 11px 14px; font-size: 13.5px; font-weight: 650; border-radius: 7px; border: 1px solid transparent; background: var(--accent); color: var(--on-accent); transition: filter .15s; margin-top: 10px; }
.btn:hover { filter: brightness(1.07); }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-3); filter: none; }
.btn:disabled { opacity: .55; cursor: default; filter: none; }

/* ---------------- Journey result cards ---------------- */
.results-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px; }
.results-head .rh-title { font-size: 13px; font-weight: 700; }
.results-head .rh-sub { font-size: 11px; color: var(--text-muted); }
.route-card { display: block; width: calc(100% - 20px); border: 1px solid var(--border); border-radius: 8px; padding: 12px 13px; margin: 8px 10px 0; color: var(--text); text-align: left; cursor: pointer; background: var(--panel); transition: border-color .15s, box-shadow .15s, transform .1s; }
.route-card:last-child { margin-bottom: 10px; }
.route-card:hover { border-color: var(--border-strong); }
.route-card.active { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.route-badges { display: flex; gap: 6px; margin-bottom: 8px; }
.badge { font-size: var(--type-micro); font-weight: 700; text-transform: uppercase; letter-spacing: .35px; padding: 3px 8px; border-radius: 20px; }
.badge.rec { background: var(--accent); color: var(--on-accent); }
.badge.fast { background: var(--success-bg); color: var(--success); }
.route-top { display: flex; justify-content: space-between; align-items: baseline; }
.route-top .time { font-family: var(--font-data); font-size: 16px; font-weight: 650; letter-spacing: -.04em; }
.route-top .time .arrow { color: var(--text-faint); margin: 0 6px; font-weight: 400; }
.route-top .dur { font-size: 12px; color: var(--text-muted); font-weight: 650; }
.route-meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.route-ops { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.op-chip { font-size: var(--type-micro); font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); }
.route-dots { display: flex; align-items: center; gap: 3px; margin-top: 9px; }
.route-dots .rd { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.route-dots .rl { flex: 1; height: 2px; background: var(--border-strong); border-radius: 2px; }
.route-dots .rl.on { background: var(--accent); }

/* ---------------- Map layers menu (in top bar) ---------------- */
.settings-wrap { position: relative; }
#settings-menu { display: none; position: absolute; top: calc(100% + 12px); right: -6px; width: min(330px, calc(100vw - 24px)); max-height: min(720px, calc(100vh - 96px)); overflow-y: auto; padding: 8px; border-radius: var(--radius);
  background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  border: 1px solid var(--border); box-shadow: var(--shadow-panel); }
#settings-menu.open { display: block; }
.menu-title { font-size: var(--type-caption); font-weight: 700; color: var(--text-faint); padding: 8px 10px 6px; }
.layer-opt { display: flex; width: 100%; min-height: 48px; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.layer-opt:hover { background: var(--surface-2); }
.layer-opt .lo-radio { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; position: relative; }
.layer-opt.on .lo-radio { border-color: var(--accent); }
.layer-opt.on .lo-radio::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); }
.layer-opt .lo-main { flex: 1; }
.layer-opt .lo-name { font-size: var(--type-control); font-weight: 600; }
.layer-opt .lo-desc { font-size: var(--type-caption); line-height: 1.35; color: var(--text-muted); margin-top: 1px; }
.menu-sep { height: 1px; background: var(--border); margin: 7px 8px; }
.menu-about { display: none; }  /* only shown on mobile, where About leaves the top bar */
.menu-theme { display: none; }
a.menu-about { text-decoration: none; }
.live-toggle-row .lo-radio { border-radius: 5px; }
.live-toggle-row.on .lo-radio { background: var(--accent); border-color: var(--accent); }
.live-toggle-row.on .lo-radio::after { content: ""; position: absolute; inset: 0; }
.tracking-filter { margin: 2px 0 4px 26px; padding-left: 9px; border-left: 1px solid var(--border); }
.tracking-state-row { min-height: 42px; padding-block: 6px; }
.tracking-state-row .lo-name { font-size: var(--type-caption); }
.tracking-state-row .lo-desc { font-size: var(--type-micro); }
.tracking-mark { width: 12px; height: 12px; flex: 0 0 12px; border: 2px solid var(--border-strong); border-radius: 50%; background: var(--panel); }
.tracking-state-row.on .tracking-mark.state-confirmed { border-color: #16a34a; background: #16a34a; box-shadow: inset 0 0 0 2px var(--panel); }
.tracking-state-row.on .tracking-mark.state-estimated { border-color: #2563eb; background: #dbeafe; }
.tracking-state-row.on .tracking-mark.state-predicted { border-color: #d97706; background: #fef3c7; }
.tracking-state-row.on .tracking-mark.state-lost { border-color: #64748b; background: transparent; }
.lo-count { min-width: 2ch; color: var(--text-faint); font-family: var(--font-data); font-size: var(--type-micro); text-align: right; }
.live-popup .maplibregl-popup-content { padding: 0; border-radius: 8px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow-panel); }
.live-popup .maplibregl-popup-tip { border-top-color: var(--panel); border-bottom-color: var(--panel); }
.ltp { width: 222px; font-family: var(--font); }
.ltp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; color: #fff; }
.ltp-op { font-size: 13px; font-weight: 750; letter-spacing: -.2px; }
.ltp-status { font-family: var(--font-data); font-size: var(--type-micro); font-weight: 650; background: rgba(255, 255, 255, .18); padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.ltp-body { padding: 11px 12px 12px; }
.ltp-dest, .ltp-next, .ltp-estimate { display: flex; align-items: center; gap: 7px; }
.ltp-dest { font-size: 13.5px; color: var(--text-dim); }
.ltp-dest b { color: var(--text); font-weight: 700; }
.ltp-next { font-size: 12px; color: var(--text-muted); margin-top: 7px; }
.ltp-estimate { font-size: var(--type-caption); line-height: 1.35; color: var(--text-muted); margin-top: 7px; padding: 7px 8px; border-radius: 6px; background: var(--surface-2); }
.ltp-estimate b { display: block; color: var(--text); font-weight: 700; }
.ltp-estimate small { display: block; margin-top: 1px; color: var(--text-muted); font-size: var(--type-micro); }
.ltp-estimate .tracking-mark, .ls-live .tracking-mark { width: 10px; height: 10px; flex-basis: 10px; }
.ltp-estimate .state-confirmed, .ls-live .state-confirmed { border-color: #16a34a; background: #16a34a; }
.ltp-estimate .state-estimated, .ls-live .state-estimated { border-color: #2563eb; background: #dbeafe; }
.ltp-estimate .state-predicted, .ls-live .state-predicted { border-color: #d97706; background: #fef3c7; }
.ltp-estimate .state-lost, .ls-live .state-lost { border-color: #64748b; background: transparent; }
.ltp-dest i, .ltp-next i, .ltp-estimate i, .ltp-coach i { width: 15px; height: 15px; color: var(--text-faint); flex-shrink: 0; }
.ltp-coach { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); margin-top: 7px; }
.ltp-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: 100%; margin-top: 11px; padding: 8px 12px; font-size: 12.5px; font-weight: 650; color: var(--accent); background: var(--accent-soft); border: 0; border-radius: 5px; cursor: pointer; }
.ltp-btn:hover { filter: brightness(1.04); }
.ltp-btn i { width: 15px; height: 15px; }
/* live service (calling points) drill-down */
.ls-live { display: inline-flex; align-items: center; gap: 6px; font-size: var(--type-micro); font-weight: 800; letter-spacing: .55px; margin-bottom: 6px; }
.ls-live .pip { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulseDot 1.6s ease-in-out infinite; }
.ls-live.delayed .pip { animation: none; opacity: .75; }
.ls-freshness { display: inline-flex; margin-top: 7px; padding: 3px 7px; border-radius: 4px; font-family: var(--font-data); font-size: var(--type-micro); font-variant-numeric: tabular-nums; color: #fff; background: rgba(0, 0, 0, .24); }
.cp-plat { font-size: var(--type-micro); font-weight: 650; color: var(--text-muted); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; margin-left: 7px; }
.cp.passed .nm { color: var(--text-muted); }
.cp.current .nm { font-weight: 750; color: var(--accent); }

/* ---------------- Live trains pill (top bar) ---------------- */
.live-btn { gap: 8px; padding: 0 13px 0 12px; }
.lb-ico { display: none; }  /* desktop shows dot+label+count; the icon is the mobile treatment */
.live-btn .lb-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.live-btn.on { color: var(--text); background: var(--surface-2); }
.live-btn.on .lb-dot { background: #e11d48; animation: livePulse 1.8s ease-out infinite; }
.live-btn.on.is-delayed .lb-dot, .live-btn.on.is-starting .lb-dot { background: var(--warning); animation: none; }
.live-btn.on.is-stale .lb-dot, .live-btn.on.is-reconnecting .lb-dot { background: var(--danger); animation: none; }
.live-btn.on.is-not_configured .lb-dot { background: var(--text-faint); animation: none; }
.live-btn .lb-count { color: var(--text-muted); font-family: var(--font-data); font-weight: 600; font-variant-numeric: tabular-nums; }
.live-btn.on .lb-count { color: var(--text-muted); }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(225, 29, 72, .5); } 70% { box-shadow: 0 0 0 6px rgba(225, 29, 72, 0); } 100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0); } }

/* ---------------- Legend chip ---------------- */
#layer-legend { position: absolute; left: 16px; bottom: 22px; z-index: 20; display: none; padding: 10px 13px; border-radius: 8px;
  background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  border: 1px solid var(--border); box-shadow: var(--shadow-panel); }
#layer-legend.show { display: block; }
#layer-legend .ll-title { font-size: var(--type-caption); font-weight: 700; color: var(--text-muted); margin-bottom: 7px; }
#layer-legend .item { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-dim); padding: 2px 0; }
#layer-legend .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ---------------- Hover chip ---------------- */
#hover-chip { position: absolute; display: none; z-index: 18; transform: translate(-50%, -142%); padding: 7px 11px; border-radius: 6px; pointer-events: none;
  background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  border: 1px solid var(--border); box-shadow: var(--shadow-chip); white-space: nowrap; }
#hover-chip .h { font-size: 12.5px; font-weight: 700; }
#hover-chip .s { font-size: var(--type-micro); color: var(--text-muted); margin-top: 1px; display: flex; align-items: center; gap: 5px; }
#hover-chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------------- Expanded station window ---------------- */
#window-scrim { position: absolute; inset: 0; z-index: 40; background: rgba(12, 16, 24, .28); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); display: none; }
#window-scrim.show { display: block; }
#station-window { position: absolute; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 40px)); max-height: min(80vh, 760px); display: none; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-panel); overflow: hidden; }
#station-window.show { display: flex; animation: popIn .22s cubic-bezier(.2, .9, .3, 1.1); }
.win-hero { padding: 18px 20px 15px; color: #fff; position: relative; flex-shrink: 0; }
.win-hero h2 { font-size: 21px; font-weight: 750; letter-spacing: -.4px; }
.win-hero .meta { font-size: 12.5px; opacity: .95; margin-top: 4px; }
.win-x { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border: 0; border-radius: 5px; background: rgba(255, 255, 255, .2); color: #fff; display: flex; align-items: center; justify-content: center; }
.win-x:hover { background: rgba(255, 255, 255, .32); }
.win-tabs { display: flex; gap: 3px; padding: 10px 16px 0; flex-shrink: 0; }
.win-tabs button { flex: 1; padding: 10px 6px; font-size: 13px; font-weight: 650; border: 0; background: transparent; color: var(--text-muted); border-bottom: 2px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.win-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.win-body { flex: 1; overflow-y: auto; padding: 16px 20px 22px; }
.win-panel { display: none; } .win-panel.active { display: block; }

/* board controls */
.board-controls { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.segmented { display: flex; gap: 3px; background: var(--surface-2); border-radius: 6px; padding: 3px; flex: 1; }
.segmented button { flex: 1; border: 0; background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 600; padding: 8px 10px; border-radius: 4px; }
.segmented button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-soft); }
.mini-input { padding: 9px 11px; font-size: 12.5px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-input); color: var(--text); font-family: inherit; }
.live-flag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; color: var(--danger); }
.live-flag .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: pulseDot 1.6s ease-in-out infinite; }
.live-pip { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulseDot 1.6s ease-in-out infinite; }
@keyframes pulseDot { 50% { opacity: .35; } }

/* service rows */
.svc-head { font-size: var(--type-micro); font-weight: 700; color: var(--text-muted); display: grid; grid-template-columns: 46px 1fr 34px 66px; gap: 8px; padding: 3px 8px; }
.svc-row { display: grid; width: 100%; grid-template-columns: 46px 1fr 34px 66px; gap: 8px; padding: 10px 8px; font-size: 13px; border: 0; border-radius: 5px; background: transparent; color: var(--text); text-align: left; cursor: pointer; align-items: center; border-top: 1px solid var(--hairline); }
.svc-row:hover { background: var(--surface-2); }
.svc-row .t { font-family: var(--font-data); font-weight: 650; }
.svc-row .p { text-align: center; color: var(--text-muted); }
.svc-row .dest { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-row .op { display: block; font-size: var(--type-micro); color: var(--text-faint); }
.svc-plan-source { display: inline-block; margin-left: 5px; color: var(--accent); font-weight: 650; }
.svc-row .exp { text-align: right; font-weight: 650; font-size: 12px; }
.exp.ontime { color: var(--success); } .exp.late { color: var(--warning); } .exp.canc { color: var(--danger); } .exp.sched { color: var(--text-faint); }
.muted { color: var(--text-muted); font-size: 12.5px; text-align: center; padding: 18px 4px; }
.board-daybreak { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: var(--type-micro); font-weight: 700; color: var(--text-muted); margin: 12px 0 2px; }
.board-daybreak i { width: 14px; height: 14px; }
.next-row .t .nd, .svc-row .t .nd { font-size: var(--type-micro); font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 0 4px; border-radius: 5px; margin-left: 3px; vertical-align: 1px; }

/* calling points / service sequence */
.cp-back { display: inline-flex; align-items: center; gap: 6px; padding: 2px; border: 0; background: transparent; font-size: 12.5px; color: var(--accent); font-weight: 600; margin-bottom: 12px; cursor: pointer; }
.cp-hero { border-radius: 8px; padding: 13px 15px; margin-bottom: 12px; color: #fff; background: var(--accent-strong); }
.cp-hero.live { background: var(--accent-strong); }
.cp-hero.live.ontime { background: #14875a; }
.cp-hero.live.late { background: #9f6206; }
.cp-hero.live.canc { background: #d5273f; }
.cp-hero .h { font-size: 15px; font-weight: 700; }
.cp-hero .s { font-size: 12px; opacity: .92; margin-top: 3px; display: flex; align-items: center; gap: 8px; }
.cp-list { background: var(--surface-2); border-radius: 8px; padding: 11px 14px; }
.cp { display: flex; gap: 11px; align-items: stretch; }
.cp .rail { display: flex; flex-direction: column; align-items: center; width: 14px; flex-shrink: 0; }
.cp .rail .d { font-size: 12px; line-height: 17px; }
.cp .rail .ln { width: 2px; flex: 1; min-height: 10px; }
.cp .body { flex: 1; min-width: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 1px 0 9px; font-size: 13px; }
.cp .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp .tail { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; flex-shrink: 0; }
.cp .tm { color: var(--text-muted); font-size: 12px; }
.cp-badge { font-size: 11px; font-weight: 650; }
.cp-badge.ontime { color: var(--success); }
.cp-badge.late { color: var(--warning); }
.cp-badge.canc { color: var(--danger); }
.cp-badge.sched { color: var(--text-faint); }
.cp-reason { font-size: var(--type-caption); line-height: 1.4; margin: -4px 0 12px; padding: 9px 12px; border-radius: 6px; display: flex; gap: 8px; align-items: flex-start; }
.cp-reason.late { background: var(--warning-bg); color: var(--warning); }
.cp-reason.canc { background: var(--danger-bg); color: var(--danger); }
.cp-reason i { flex-shrink: 0; width: 15px; height: 15px; margin-top: 1px; }

/* analytics */
.analytics-context { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.analytics-source { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: var(--type-micro); font-weight: 700; }
.analytics-source i { width: 14px; height: 14px; color: var(--accent); }
.analytics-period { color: var(--text-dim); font-family: var(--font-data); font-size: var(--type-micro); font-weight: 650; text-align: right; }
.metric-strip { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.station-metric { position: relative; z-index: 1; min-width: 0; min-height: 116px; padding: 14px 12px 12px; text-align: left; }
.station-metric::before { content: ""; position: absolute; top: 0; left: 12px; right: 12px; height: 3px; background: var(--accent); }
.station-metric + .station-metric { border-left: 1px solid var(--hairline); }
.station-metric.punctuality { background: var(--panel); }
.station-metric.punctuality::before, .station-metric.cancellations::before { background: var(--metric-tone); }
.station-metric .v { overflow: hidden; color: var(--text); font-family: var(--font-data); font-size: 21px; font-weight: 700; line-height: 1.1; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.station-metric.punctuality .v, .station-metric.cancellations .v { color: var(--metric-tone); }
.station-metric .l { margin-top: 12px; color: var(--text-dim); font-size: var(--type-micro); font-weight: 700; }
.metric-change, .metric-unavailable { display: block; margin-top: 3px; font-size: var(--type-micro); line-height: 1.25; color: var(--text-muted); }
.metric-change.good { color: var(--success); }
.metric-change.bad { color: var(--danger); }
.performance-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 9px 0 22px; color: var(--text-muted); font-size: var(--type-micro); line-height: 1.4; }
.coverage-caution { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; color: var(--warning); font-style: normal; font-weight: 700; }
.coverage-caution i { width: 12px; height: 12px; }
.analytics-benchmark { flex-shrink: 0; }
.analytics-benchmark strong { color: var(--text); }
.analytics-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 8px; }
.analytics-heading h3 { font-size: 15px; font-weight: 750; letter-spacing: -.2px; }
.analytics-heading span { color: var(--text-muted); font-size: var(--type-micro); }
.analytics-source-tag { display: inline-flex; align-items: center; gap: 5px; }
.source-pip { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.today-performance { display: grid; gap: 11px; min-height: 72px; padding: 13px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.today-performance:has(.spinner) { grid-template-columns: auto 1fr; align-items: center; color: var(--text-muted); }
.today-empty { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: var(--type-control); }
.today-empty i { width: 15px; height: 15px; }
.today-empty strong { color: var(--text-dim); font-weight: 600; }
.today-empty.reporting-limited { align-items: flex-start; }
.today-empty.reporting-limited > i { width: 19px; height: 19px; margin-top: 1px; color: var(--accent); }
.today-empty.reporting-limited span, .today-empty.reporting-limited small { display: block; }
.today-empty.reporting-limited small { margin-top: 3px; color: var(--text-muted); font-size: var(--type-micro); line-height: 1.35; }
.today-measures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.today-measures span { color: var(--text-muted); font-size: var(--type-micro); line-height: 1.35; }
.today-measures span + span { border-left: 1px solid var(--hairline); padding-left: 11px; }
.today-measures strong { display: block; margin-bottom: 2px; color: var(--text); font-family: var(--font-data); font-size: 15px; white-space: nowrap; }
.today-measures small { display: block; margin-top: 3px; color: var(--text-faint); font-size: 10px; line-height: 1.25; }
.coverage-rails { display: grid; gap: 6px; padding-top: 2px; }
.coverage-rails > span { display: grid; grid-template-columns: 58px 1fr 42px; align-items: center; gap: 8px; color: var(--text-muted); font-size: var(--type-micro); }
.coverage-rails b { color: var(--text-dim); font-weight: 650; }
.coverage-rails i { height: 4px; overflow: hidden; background: var(--border-strong); border-radius: 2px; }
.coverage-rails em { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.coverage-rails > span:nth-child(2) em { background: var(--success); }
.coverage-rails strong { color: var(--text-dim); font-family: var(--font-data); font-weight: 650; text-align: right; }
.today-note { color: var(--text-muted); font-size: var(--type-micro); line-height: 1.45; }
.history-performance { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); min-height: 82px; padding: 13px 14px; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 8px; }
.history-performance:has(.spinner) { grid-template-columns: auto 1fr; align-items: center; gap: 9px; color: var(--text-muted); }
.history-performance > span:not(.history-empty) { position: relative; z-index: 1; min-width: 0; }
.history-performance > span + span:not(.history-empty) { border-left: 1px solid var(--hairline); padding-left: 12px; }
.history-performance strong, .history-performance b, .history-performance small { display: block; }
.history-performance strong { color: var(--accent-strong); font-family: var(--font-data); font-size: 15px; line-height: 1.2; }
.history-performance b { position: relative; margin-top: 7px; color: var(--text-dim); font-size: var(--type-micro); font-weight: 700; }
.history-performance small, .history-empty { margin-top: 2px; color: var(--text-muted); font-size: var(--type-micro); line-height: 1.35; }
.history-empty { grid-column: 1 / -1; align-self: center; }
.history-performance.history-is-new { grid-template-columns: minmax(94px, .7fr) 2fr; align-items: center; gap: 16px; background: linear-gradient(112deg, var(--accent-soft), var(--surface-2)); }
.history-new-value { padding-right: 15px; border-right: 1px solid var(--border-strong); }
.history-new-value strong { display: block; font-size: 21px; }
.history-new-value span { color: var(--text-muted); font-size: var(--type-micro); }
.history-new-copy b, .history-new-copy span { display: block; }
.history-new-copy b { color: var(--text); font-size: var(--type-control); }
.history-new-copy span { margin-top: 3px; color: var(--text-muted); font-size: var(--type-micro); line-height: 1.4; }
.route-reliability { margin-top: 7px; color: var(--text-muted); font-size: var(--type-micro); text-align: left; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 14px 8px; text-align: center; }
.stat .v { font-family: var(--font-data); font-size: 17px; font-weight: 650; line-height: 1.1; letter-spacing: -.04em; }
.stat .l { font-size: var(--type-micro); text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-top: 4px; }
.kv { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--hairline); font-size: 13px; }
.kv .k { color: var(--text-muted); }
.kv .val { font-weight: 600; text-align: right; }
.trend-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.trend + .trend { border-left: 1px solid var(--border); padding-left: 18px; }
.trend-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--text-muted); font-size: var(--type-micro); }
.trend-label strong { color: var(--text); font-family: var(--font-data); font-size: 15px; }
.spark-wrap { position: relative; margin: 8px 0 5px; }
.spark-wrap svg { display: block; width: 100%; }
.spark-tip { display: none; position: absolute; top: -4px; transform: translateX(-50%); background: var(--text); color: var(--panel); font-size: var(--type-micro); padding: 3px 6px; border-radius: 5px; white-space: nowrap; pointer-events: none; z-index: 4; }
.spark-cross { display: none; position: absolute; top: 0; width: 1px; height: 100%; background: var(--border-strong); pointer-events: none; }
.spark-range { display: flex; justify-content: space-between; gap: 12px; margin-top: 3px; font-size: var(--type-micro); color: var(--text-muted); }

/* ---------------- Journey timeline (bottom) ---------------- */
#timeline-panel { position: absolute; left: calc(var(--hud-w) + 40px); right: 40px; bottom: 20px; z-index: 25; max-width: 1040px; display: none;
  background: var(--panel-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  border: 1px solid var(--border); box-shadow: var(--shadow-panel); border-radius: var(--radius-lg); }
#timeline-panel.show { display: block; animation: popIn .24s cubic-bezier(.2, .9, .3, 1.1); }
.tp-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px 10px; }
.tp-summary { display: flex; align-items: baseline; gap: 10px; }
.tp-summary .tp-time { font-family: var(--font-data); font-size: 16px; font-weight: 650; letter-spacing: -.04em; }
.tp-summary .tp-time .arrow { color: var(--text-faint); margin: 0 5px; font-weight: 400; }
.tp-summary .tp-meta { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.tp-badges { display: flex; gap: 6px; }
.tp-toggle { margin-left: auto; min-height: 32px; display: inline-flex; align-items: center; gap: 6px; font-size: var(--type-caption); font-weight: 650; color: var(--accent); background: var(--accent-soft); border: 0; padding: 7px 11px; border-radius: 5px; }
.tp-toggle:hover { filter: brightness(1.03); }
.tp-toggle i { width: 14px; height: 14px; }
.tp-x { width: 32px; height: 32px; border: 0; border-radius: 5px; background: var(--surface-2); color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.tp-x:hover { background: var(--surface-3); color: var(--text); }
.tp-track-wrap { overflow-x: auto; padding: 8px 22px 14px; }
/* width:100% lets few stops spread across the panel; min-content lets many overflow+scroll */
.tp-track { display: flex; align-items: flex-start; width: 100%; min-width: min-content; }
.tp-stop { position: relative; flex: 1 1 0; min-width: 96px; min-height: 128px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.tp-stop.mini { min-width: 80px; }
/* one continuous line at a fixed centre (5..8px) that every node's centre lines up to */
.tp-stop::before, .tp-stop::after { content: ""; position: absolute; top: 5px; height: 3px; background: var(--accent); z-index: 1; }
.tp-stop::before { right: 50%; left: 0; }
.tp-stop::after { left: 50%; right: 0; }
.tp-stop:first-child::before { display: none; }
.tp-stop:last-child::after { display: none; }
.tp-node { position: relative; z-index: 2; width: 13px; height: 13px; border-radius: 50%; background: var(--panel); border: 3px solid var(--accent); margin-bottom: 9px; }
.tp-stop.end .tp-node { background: var(--accent); }
.tp-stop.change .tp-node { border-style: dashed; border-color: var(--warning); background: var(--warning-bg); }
/* mini dot (9px) is nudged down 2px so its centre matches the 13px dots on the same line */
.tp-stop.mini .tp-node { width: 9px; height: 9px; border-width: 2px; margin-top: 2px; margin-bottom: 11px; }
.tp-name { font-size: var(--type-caption); font-weight: 650; line-height: 1.25; max-width: 108px; }
.tp-stop.mini .tp-name { font-size: var(--type-micro); font-weight: 550; color: var(--text-muted); }
.tp-t { font-size: var(--type-micro); color: var(--text-muted); margin-top: 3px; font-weight: 600; }
.tp-stop.mini .tp-t { font-size: var(--type-micro); }
.tp-t .arr { color: var(--text-faint); font-weight: 500; }
.tp-sub { font-size: var(--type-micro); font-weight: 700; text-transform: uppercase; letter-spacing: .35px; color: var(--warning); margin-top: 2px; }
/* operator / status / note label centred on the segment — fixed top so all labels align */
.tp-seglabel { position: absolute; top: 66px; left: 100%; transform: translateX(-50%); width: 138px; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tp-seglabel .tp-op { font-size: var(--type-micro); font-weight: 650; color: var(--text-muted); white-space: nowrap; }
.tp-status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--type-micro); font-weight: 700; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.tp-status.ontime { color: var(--success); background: var(--success-bg); }
.tp-status.late { color: var(--warning); background: var(--warning-bg); }
.tp-status.sched { color: var(--text-muted); background: var(--surface-2); }
.tp-livedot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulseDot 1.4s ease-in-out infinite; }
.tp-seglabel .tp-note { font-size: var(--type-micro); color: var(--warning); line-height: 1.3; max-width: 134px; }

/* Operational numbers should not shift as live values update. */
.next-row .t, .next-row .st, .svc-row .t, .svc-row .exp, .cp .tm, .cp-badge,
.route-top .time, .route-top .dur, .tp-time, .tp-t, .mj-dt, .mj-time,
.mini-stat .v, .stat .v, .ls-freshness {
  font-variant-numeric: tabular-nums;
}
.svc-row .t, .svc-row .exp, .cp .tm, .route-top .dur, .tp-time, .tp-t,
.mj-dt, .mj-time {
  font-family: var(--font-data);
}

/* on-map journey markers */
.jmark { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .5); box-sizing: border-box; display: flex; align-items: center; justify-content: center; }
.jmark.origin { background: #1a9641; }
.jmark.dest { background: #2563eb; }
.jmark.mid { background: #fff; border-color: #2563eb; width: 13px; height: 13px; }
.jmark.split { background: #f4a742; width: 20px; height: 20px; }
:root[data-theme="dark"] .jmark { border-color: #12151b; }
.jmark.pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid; border-color: inherit; opacity: .6; animation: jpulse 1.8s ease-out infinite; }
.jmark.origin.pulse::after { border-color: #1a9641; } .jmark.dest.pulse::after { border-color: #2563eb; }
@keyframes jpulse { 0% { transform: scale(.75); opacity: .55; } 100% { transform: scale(2.3); opacity: 0; } }

/* spinner */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { text-align: center; padding: 18px; color: var(--text-muted); font-size: 12.5px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 780px) {
  :root { --hud-w: 100%; }
  #topbar { height: 56px; padding: 0 12px; gap: 10px; box-shadow: 0 2px 8px rgba(15, 23, 42, .09); }
  .tb-brand { gap: 9px; min-width: 0; }
  .brand-mark { width: 56px; height: 36px; flex-shrink: 0; }
  .brand-mark img { width: 100%; height: 100%; }
  .tb-text { min-width: 0; }
  .tb-title { font-size: 14px; white-space: nowrap; letter-spacing: -.3px; }
  .tb-tag { font-size: 11px; white-space: nowrap; }
  .tb-right > #theme-toggle, .tb-right > a.tb-btn[href="/about"] { display: none; }
  .tb-right { margin-left: auto; }

  /* Thumb-first navigation: the existing Plan/Live/Layers controls move here in JS,
     preserving their state, events and accessible names instead of creating duplicates. */
  #mobile-dock {
    position: fixed; z-index: 48; left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
    min-height: 62px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch; padding: 5px; border: 1px solid var(--border);
    border-radius: 14px; background: var(--panel);
    box-shadow: 0 14px 34px -16px rgba(15, 23, 42, .48), 0 4px 12px rgba(15, 23, 42, .12);
    transition: opacity .18s ease-out, transform .22s cubic-bezier(.2,.8,.2,1);
  }
  body.sheet-open #mobile-dock, body.searching #mobile-dock,
  body.plan-focus #mobile-dock, body.dialog-open #mobile-dock {
    opacity: 0; pointer-events: none; transform: translateY(calc(100% + 24px));
  }
  #mobile-dock > .mobile-action, #mobile-dock > .sb-plan,
  #mobile-dock > .live-btn, #mobile-dock > .settings-wrap > .tb-btn {
    min-width: 0; width: 100% !important; height: 52px; margin: 0; padding: 5px 2px 4px !important;
    border: 0; border-radius: 9px; box-shadow: none; background: transparent; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 10px; font-weight: 650; line-height: 1.1;
  }
  #mobile-dock > .settings-wrap { position: static; min-width: 0; }
  #mobile-dock .mobile-action { font-family: inherit; cursor: pointer; }
  #mobile-dock i, #mobile-dock .mobile-action i { width: 20px; height: 20px; }
  #mobile-dock .sb-plan-label, #mobile-dock .tb-btn > span { display: block; font-size: 10px; }
  #mobile-dock .settings-wrap .tb-btn > span { font-size: 0; }
  #mobile-dock .settings-wrap .tb-btn > span::after { content: "Layers"; font-size: 10px; }
  #mobile-dock .mobile-action:active, #mobile-dock .sb-plan:active,
  #mobile-dock .live-btn:active, #mobile-dock .settings-wrap > .tb-btn:active {
    background: var(--surface-2); color: var(--text);
  }
  #mobile-dock .sb-plan.active, #mobile-dock .live-btn.on,
  #mobile-dock .settings-wrap > .tb-btn.active, #mobile-search.active {
    background: var(--accent-soft); color: var(--accent);
  }

  /* Live status remains explicit in the dock: signal glyph, label and count badge. */
  .live-btn { position: relative; }
  .live-btn .lb-dot, .live-btn .lb-label { display: none !important; }
  .live-btn .lb-ico { display: inline-flex; align-items: center; justify-content: center; color: var(--text-dim); }
  .live-btn .lb-ico svg { width: 21px; height: 21px; }
  #mobile-dock .live-btn::after { content: "Live"; display: block; font-size: 10px; }
  .live-btn.on .lb-ico { color: #e11d48; }
  .live-btn.on.is-delayed .lb-ico, .live-btn.on.is-starting .lb-ico { color: var(--warning); }
  .live-btn.on.is-stale .lb-ico, .live-btn.on.is-reconnecting .lb-ico { color: var(--danger); }
  .live-btn.on.is-not_configured .lb-ico { color: var(--text-faint); }
  .live-btn .lb-count { display: none; position: absolute; top: 0; right: 8px; min-width: 17px; height: 17px; padding: 0 4px;
    box-sizing: border-box; background: #e11d48; color: #fff; border-radius: 9px; font-size: 10px; line-height: 15px;
    font-weight: 700; text-align: center; border: 1.5px solid var(--panel); font-variant-numeric: tabular-nums; }
  .live-btn.on .lb-count:not(:empty) { display: block; }
  .menu-about { display: flex; }  /* revealed only on mobile, where About left the top bar */
  .menu-theme { display: flex; }
  .menu-sep.menu-theme { display: block; }
  #settings-menu {
    position: fixed; z-index: 58; left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right)); top: auto;
    bottom: calc(82px + env(safe-area-inset-bottom)); width: auto; max-height: min(68vh, 540px);
    overflow-y: auto; border-radius: 12px; padding: 8px;
  }
  #hud-left { top: calc(12px + env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); width: auto; }
  #searchbar {
    min-height: 50px; padding: 5px 9px; border-radius: 12px;
    opacity: 0; visibility: hidden; pointer-events: none;
    transform: translateY(-8px);
    transition: opacity .16s ease-out, transform .2s cubic-bezier(.2,.8,.2,1), visibility 0s linear .2s;
  }

  /* 16px inputs stop iOS Safari zooming on focus — the accessible fix, not user-scalable=no */
  .search-field input, .pl-field input, .pl-2col input, .mini-input,
  #board-time, input[type="date"], input[type="time"] { font-size: 16px; }

  /* Safe areas: Dynamic Island / status bar up top, home indicator below */
  #topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); box-sizing: border-box; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .maplibregl-ctrl-bottom-right { margin-bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Keyboard-aware SEARCH: results anchor under the fixed search bar (whose input stays put). */
  body.searching #hud-left { z-index: 60; }
  body.searching #searchbar {
    opacity: 1; visibility: visible; pointer-events: auto; transform: none;
    transition-delay: 0s;
  }
  body.searching #hud-sheet {
    top: var(--search-top, 84px); bottom: initial !important; height: fit-content; min-height: 0; z-index: 55;
    max-height: calc(var(--vvh, 100vh) - var(--search-top, 84px) - 12px);
    display: block; transform: none; transition: none; border-radius: 12px;
    border: 1px solid var(--border); box-shadow: var(--shadow-panel); overflow: hidden;
  }
  /* Keyboard-aware PLANNER: its inputs live inside the sheet, so anchor the sheet to the keyboard
     (bottom) using only the visualViewport-derived --kbd/--vvh — never a fixed element's measured
     position, which iOS skews on focus and which sent the sheet off the top of the screen. If the
     keyboard height is unknown it falls back to the screen bottom, so it can never vanish upward. */
  body.plan-focus #hud-sheet {
    top: auto; bottom: var(--kbd, 0); height: auto; z-index: 55;
    max-height: calc(var(--vvh, 100vh) - 72px);
    transform: none; transition: bottom .2s ease; border-radius: 12px 12px 0 0;
    border: 1px solid var(--border); box-shadow: var(--shadow-panel); overflow: hidden;
  }
  body.searching #sheet-handle, body.plan-focus #sheet-handle { display: none; }
  body.searching #hud-body, body.plan-focus #hud-body { padding-top: 6px; }
  body.searching #hud-body {
    flex: 0 0 auto; height: auto; min-height: 0;
    max-height: calc(var(--vvh, 100vh) - var(--search-top, 84px) - 12px);
    overflow-y: auto; padding-bottom: 6px;
  }
  /* Span suggestions the full card width (over the 40px swap column) so date/time/Find don't peek out beside them */
  .pl-ac { right: -48px; }

  /* Draggable bottom sheet — sized by its top edge so content always scrolls in-view */
  #hud-sheet { position: fixed; left: 0; right: 0; top: var(--sheet-top, 100vh); bottom: var(--kbd, 0); z-index: 45; display: flex; flex-direction: column;
    background: var(--panel); border-radius: 12px 12px 0 0; border-top: 1px solid var(--border); box-shadow: 0 -12px 34px -12px rgba(15,23,42,.38);
    transition: top .32s cubic-bezier(.32,.72,0,1), bottom .22s ease; will-change: top; }
  #hud-sheet.dragging { transition: bottom .22s ease; }
  #sheet-handle { display: block; width: 100%; height: 32px; border: 0; background: transparent; position: relative; flex-shrink: 0; touch-action: none; cursor: grab; }
  #sheet-handle::before { content: ""; position: absolute; top: 13px; left: 50%; transform: translateX(-50%); width: 44px; height: 5px; border-radius: 3px; background: var(--border-strong); }
  #sheet-handle:active { cursor: grabbing; }
  /* Generous bottom padding so the last stop/departure clears iOS Safari's bottom toolbar + home indicator */
  #hud-body { position: static; display: block; flex: 1; min-height: 0; max-height: none; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 0 14px calc(56px + env(safe-area-inset-bottom)); margin: 0; }
  #hud-body .card { border: 0; border-radius: 0; box-shadow: none; background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .card-head, .eyebrow, .pl-head { padding-left: 0; padding-right: 0; }
  .card-pad, .mini-stats, .results-head, .route-card { margin-left: 0; margin-right: 0; }
  .route-card { width: 100%; }
  .card-x, .win-x, .tp-x { width: 44px; height: 44px; }
  .win-x { top: 10px; right: 10px; }

  /* Vertical journey timeline (mobile) */
  .mj-head { display: flex; align-items: center; justify-content: space-between; padding-top: 2px; }
  .mj-head .back-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--accent); font-size: 13px; font-weight: 650; padding: 6px 8px 6px 0; border-radius: 8px; }
  .mj-head .back-btn:active { color: var(--accent-strong); }
  .mj-head .back-btn i { width: 17px; height: 17px; }
  .mj-seg .tp-status { font-size: 11px; padding: 2px 9px; }
  .mj-seg .tp-livedot { width: 7px; height: 7px; }
  .mj-summary { display: flex; align-items: baseline; gap: 10px; margin-top: 12px; }
  .mj-dt { font-size: 19px; font-weight: 750; letter-spacing: -.3px; }
  .mj-meta { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
  .mj-badges { display: flex; gap: 6px; margin-top: 9px; }
  .mj-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--accent); background: var(--accent-soft); border: 0; padding: 8px 12px; border-radius: 5px; margin: 14px 0 6px; }
  .mj-toggle i { width: 14px; height: 14px; }
  .mj-stop { display: flex; gap: 12px; }
  .mj-rail { display: flex; flex-direction: column; align-items: center; width: 14px; flex-shrink: 0; }
  .mj-dot { width: 13px; height: 13px; border-radius: 50%; border: 3px solid var(--accent); background: var(--panel); flex-shrink: 0; margin-top: 3px; }
  .mj-stop.end .mj-dot { background: var(--accent); }
  .mj-stop.change .mj-dot { border-style: dashed; border-color: var(--warning); background: var(--warning-bg); }
  .mj-stop.mini .mj-dot { width: 9px; height: 9px; border-width: 2px; }
  .mj-line { width: 2px; flex: 1; min-height: 20px; background: var(--accent); margin: 2px 0; border-radius: 2px; }
  .mj-main { flex: 1; min-width: 0; padding-bottom: 14px; }
  .mj-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
  .mj-name { font-size: 14px; font-weight: 650; }
  .mj-stop.mini .mj-name { font-size: 12.5px; font-weight: 500; color: var(--text-dim); }
  .mj-time { font-size: 12.5px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
  .mj-time .arr { color: var(--text-faint); font-weight: 500; }
  .mj-change { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--warning); margin-top: 3px; }
  .mj-seg { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 7px 0 3px; }
  .mj-op { font-size: 11.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 9px; border-radius: 20px; }
  .mj-live { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
  .mj-live.ontime { color: var(--success); background: var(--success-bg); }
  .mj-live.late { color: var(--warning); background: var(--warning-bg); }
  .mj-note { flex-basis: 100%; font-size: 11.5px; color: var(--warning); background: var(--warning-bg); padding: 6px 10px; border-radius: 8px; }

  #station-window { width: 100%; max-width: 100%; max-height: calc(100dvh - 68px); top: auto; bottom: 0; left: 0; transform: none; border-radius: 12px 12px 0 0; }
  #station-window.show { animation: sheetUp .26s cubic-bezier(.2, .9, .3, 1.05); }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
  /* Match the sheet: last departure/calling-point must clear Safari's toolbar + home indicator */
  .win-body { padding-inline: 16px; padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .analytics-context { align-items: flex-start; }
  .analytics-period { max-width: 48%; }
  .station-metric { min-height: 112px; padding-inline: 8px; }
  .station-metric .v { font-size: 18px; }
  .performance-meta { align-items: flex-start; flex-direction: column; gap: 3px; }
  .today-measures { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 0; }
  .today-measures span:nth-child(3) { border-left: 0; padding-left: 0; }
  .coverage-rails > span { grid-template-columns: 54px 1fr 38px; }
  .trend-grid { grid-template-columns: 1fr; gap: 16px; }
  .trend + .trend { border-left: 0; border-top: 1px solid var(--hairline); padding: 14px 0 0; }

  /* horizontal timeline duplicates the route card + drawn line on a phone — hide it */
  #timeline-panel.show { display: none; }
  #layer-legend { bottom: calc(90px + env(safe-area-inset-bottom)); left: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .pop-in, #station-window.show, .jmark.pulse::after, .spinner,
  .live-btn.on .lb-dot, .ls-live .pip, .live-pip, .tp-livedot {
    animation: none !important;
  }
  #hud-sheet { transition: none; }
}
