/* Adaptive theme for UI surfaces only. Explicitly exclude #map, Leaflet
   internals, route-color badges, vehicle markers, station markers and logos. */
:root {
  --st-ui-bg: #f4f6f8;
  --st-ui-surface: #fff;
  --st-ui-raised: #fff;
  --st-ui-soft: #eef6ff;
  --st-ui-input: #fbfcff;
  --st-ui-text: #172329;
  --st-ui-muted: #536581;
  --st-ui-border: #dce5ef;
  --st-ui-shadow: 0 16px 50px #10205218;
  --st-ui-blue: #148ff5;
  --st-ui-blue-text: #105392;
  --st-ui-focus: #148ff5;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf5ff;
  --muted: #b5c5d7;
  --line: #344862;
  --paper: #15243a;
  --canvas: #0b1424;
  --shadow: 0 16px 50px #02091890;
  --st-ui-bg: #0b1424;
  --st-ui-surface: #15243a;
  --st-ui-raised: #1a2b44;
  --st-ui-soft: #243a57;
  --st-ui-input: #101f32;
  --st-ui-text: #edf5ff;
  --st-ui-muted: #b7c6d9;
  --st-ui-border: #344b67;
  --st-ui-shadow: 0 18px 50px #020918a8;
  --st-ui-blue: #79bcff;
  --st-ui-blue-text: #a8d5ff;
  --st-ui-focus: #86c8ff;
}

/* Entry points: desktop header and fourth mobile dock action. */
.st-brand-actions { display: flex; align-items: center; gap: 7px; }
.st-theme-trigger svg { display: block; width: 19px; height: 19px; }
.st-theme-trigger { flex: none; }
.st-theme-trigger:focus-visible,.st-dock-theme-trigger:focus-visible {
  outline: 3px solid var(--st-ui-focus) !important;
  outline-offset: 3px;
}

/* Theme picker: a compact accessible dialog, not a map overlay or Leaflet control. */
.st-theme-dialog {
  width: min(420px, calc(100vw - 24px));
  max-height: min(82dvh, 580px);
  padding: 0;
  border: 1px solid var(--st-ui-border);
  border-radius: 23px;
  background: var(--st-ui-surface);
  color: var(--st-ui-text);
  box-shadow: 0 24px 80px #06152b70;
  overflow: auto;
}
.st-theme-dialog::backdrop { background: #06152b9c; backdrop-filter: blur(3px); }
.st-theme-dialog-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; padding:22px 20px 15px; }
.st-theme-eyebrow { display:block; margin-bottom:6px; color:var(--st-ui-blue-text); font-size:10px; letter-spacing:.11em; font-weight:850; }
.st-theme-dialog h2 { margin:0; font-size:21px; letter-spacing:-.5px; }
.st-theme-dialog p { margin:6px 0 0; color:var(--st-ui-muted); font-size:12px; line-height:1.5; }
.st-theme-close { width:42px; height:42px; flex:none; border:1px solid var(--st-ui-border); border-radius:12px; background:var(--st-ui-soft); color:var(--st-ui-text); font-size:24px; }
.st-theme-options { display:grid; gap:9px; padding:0 20px 22px; }
.st-theme-option { display:flex; align-items:center; text-align:left; gap:13px; min-height:66px; padding:11px 13px; border:1px solid var(--st-ui-border); border-radius:15px; background:var(--st-ui-raised); color:var(--st-ui-text); transition: background .2s ease,border-color .2s ease,transform .16s ease; }
.st-theme-option:hover { border-color:var(--st-ui-blue); background:var(--st-ui-soft); }
.st-theme-option:active { transform:scale(.99); }
.st-theme-option[aria-pressed="true"] { border:2px solid var(--st-ui-blue); padding:10px 12px; background:var(--st-ui-soft); }
.st-theme-option-icon { display:grid; place-items:center; width:38px; height:38px; flex:none; border-radius:12px; background:var(--st-ui-soft); color:var(--st-ui-blue-text); font-size:22px; }
.st-theme-option-copy { flex:1; min-width:0; display:grid; gap:2px; }
.st-theme-option-copy strong { font-size:13px; font-weight:800; }
.st-theme-option-copy small { font-size:11px; color:var(--st-ui-muted); }
.st-theme-option-check { display:grid; place-items:center; width:24px; height:24px; border-radius:50%; color:transparent; background:transparent; font-weight:900; }
.st-theme-option[aria-pressed="true"] .st-theme-option-check { background:var(--st-ui-blue); color:#061629; }
.st-theme-dialog button:focus-visible { outline:3px solid var(--st-ui-focus); outline-offset:3px; }

/* Dark palette applies strictly to app controls and text, NOT the map canvas. */
:root[data-theme="dark"] body { color:var(--st-ui-text); background:var(--st-ui-bg); }
:root[data-theme="dark"] .app .sidebar {
  background:var(--st-ui-surface); border-color:var(--st-ui-border); box-shadow:var(--st-ui-shadow);
  --st-control-ink: #eaf4ff;
  --st-control-blue: #79bcff;
  --st-control-muted: #a9b9ce;
  --st-control-surface: #1a2b44;
  --st-control-soft: #243a57;
  --st-control-border: #405774;
}
:root[data-theme="dark"] .brand-name { color:var(--st-ui-text); }
:root[data-theme="dark"] .brand-sub { color:var(--st-ui-muted) !important; }
:root[data-theme="dark"] .sidebar .nav-tabs { background:var(--st-ui-input); }
:root[data-theme="dark"] .sidebar .nav-tab { color:var(--st-ui-muted); }
:root[data-theme="dark"] .sidebar .nav-tab.active { color:var(--st-ui-text); background:var(--st-ui-raised); box-shadow: inset 0 -2px 0 var(--st-ui-blue); }
:root[data-theme="dark"] .sidebar .nav-tab:not(.active):hover { color:var(--st-ui-text); background:var(--st-ui-soft); }
:root[data-theme="dark"] .sidebar .content-scroll { scrollbar-color:#536680 transparent; }
:root[data-theme="dark"] .sidebar :is(.hero-copy h1,.count-row strong,.route-title,.stage2-search-feedback strong) { color:var(--st-ui-text); }
:root[data-theme="dark"] .sidebar :is(.hero-copy p,.section-kicker,.count-row,.route-desc,.route-detail-note,.stage2-route-cue,.plan-hint,.stage2-search-feedback,.empty,.plan-field label) { color:var(--st-ui-muted); }
:root[data-theme="dark"] .sidebar .search-wrap input { color:var(--st-ui-text); background:var(--st-ui-input); border-color:var(--st-ui-border); box-shadow:none; }
:root[data-theme="dark"] .sidebar .search-wrap input::placeholder { color:#a1b3c9; opacity:1; }
:root[data-theme="dark"] .sidebar .search-wrap input:hover { border-color:#5b7191; }
:root[data-theme="dark"] .sidebar .search-wrap input:focus { border-color:var(--st-ui-focus); box-shadow:0 0 0 3px #79bcff3b; }
:root[data-theme="dark"] .sidebar .search-icon { color:var(--st-ui-muted); }
:root[data-theme="dark"] .sidebar .stage2-search-clear,
:root[data-theme="dark"] .sidebar .stage2-filter-arrow,
:root[data-theme="dark"] .sidebar .round-btn { color:var(--st-ui-text); background:var(--st-ui-raised); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .sidebar :is(.stage2-search-clear,.stage2-filter-arrow,.round-btn):hover:not(:disabled) { color:var(--st-ui-text); background:var(--st-ui-soft); border-color:var(--st-ui-blue); }
:root[data-theme="dark"] .sidebar .stage2-filter-arrow:disabled { background:#1a2a3e; color:#8498af; }
:root[data-theme="dark"] .sidebar .filter-chip:not(.active) { color:var(--st-ui-text); background:var(--st-ui-raised); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .sidebar .filter-chip:not(.active):hover { background:var(--st-ui-soft); }
:root[data-theme="dark"] .sidebar .filter-chip.active { color:var(--st-ui-text); background:color-mix(in srgb,var(--mode-accent,#148ff5) 18%,var(--st-ui-surface)); border-color:var(--mode-accent,#79bcff); }
:root[data-theme="dark"] .sidebar .route-card { background:var(--st-ui-raised); border-top-color:var(--st-ui-border); border-right-color:var(--st-ui-border); border-bottom-color:var(--st-ui-border); box-shadow:0 2px 9px #050d1c30; }
:root[data-theme="dark"] .sidebar .route-card:hover { background:#233751; border-top-color:#5a7290; border-right-color:#5a7290; border-bottom-color:#5a7290; }
:root[data-theme="dark"] .sidebar .route-card.selected { background:color-mix(in srgb,var(--route-accent,#148ff5) 11%,#1a2b44); border-top-color:#60738c; border-right-color:#60738c; border-bottom-color:#60738c; }
:root[data-theme="dark"] .sidebar .meta-pill { color:#c8d6e7; background:#2d3d55; }
:root[data-theme="dark"] .sidebar .meta-pill.est { color:#f9d99d; background:#544128; }
:root[data-theme="dark"] .sidebar .divider { background:var(--st-ui-border); }
:root[data-theme="dark"] .sidebar .plan-field { background:var(--st-ui-input); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .sidebar .plan-field select { background:transparent; color:var(--st-ui-text); }
:root[data-theme="dark"] .sidebar .plan-field select option { background:var(--st-ui-surface); color:var(--st-ui-text); }
:root[data-theme="dark"] .sidebar .plan-submit { background:#79bcff; color:#081827; box-shadow:0 5px 13px #07101f70; }
:root[data-theme="dark"] .sidebar .plan-submit:hover:not(:disabled) { background:#a8d5ff; }
:root[data-theme="dark"] .sidebar .stage3-sheet-grip { background:var(--st-ui-surface); color:var(--st-ui-muted); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .sidebar .stage3-sheet-handle { background:#6584a4; }
:root[data-theme="dark"] .sidebar .stage2-search-feedback strong { color:var(--st-ui-blue-text); }
:root[data-theme="dark"] .stage3-loading-route { background:var(--st-ui-raised); border-color:var(--st-ui-border); color:var(--st-ui-text); }
:root[data-theme="dark"] .stage3-loading-spinner { border-color:#445a76; border-top-color:#79bcff; }

/* Floating UI controls over the unchanged cartographic basemap. */
:root[data-theme="dark"] .app .map-shell { border-color:#334863; }
:root[data-theme="dark"] .app .mobile-brand,
:root[data-theme="dark"] .app .weather,
:root[data-theme="dark"] .app .map-search-info,
:root[data-theme="dark"] .app .mobile-panel-toggle,
:root[data-theme="dark"] .app .map-shell > .map-credits { background:#15243af0; border-color:var(--st-ui-border); color:var(--st-ui-text); box-shadow:var(--st-ui-shadow); }
:root[data-theme="dark"] .app .map-search-info .sub { color:var(--st-ui-muted); }
:root[data-theme="dark"] .app .map-shell > .map-credits summary { color:var(--st-ui-text); }
:root[data-theme="dark"] .app .map-shell > .map-credits .map-credits-content a { color:var(--st-ui-blue-text); }
:root[data-theme="dark"] .app .map-shell > .map-controls button { color:var(--st-ui-text); background:#1a2b44f2; box-shadow:0 4px 14px #07101f70; }
:root[data-theme="dark"] .app .map-shell > .map-controls button:hover:not(:disabled) { color:var(--st-ui-text); background:var(--st-ui-soft); }
:root[data-theme="dark"] .app .map-shell > .map-controls button#layerToggle[aria-expanded="true"] { color:var(--st-ui-blue-text); background:var(--st-ui-soft); outline-color:#79bcff; }
:root[data-theme="dark"] .app .map-layer-panel,
:root[data-theme="dark"] .app .selected-route-panel { background:#15243af0; border-color:var(--st-ui-border); color:var(--st-ui-text); box-shadow:var(--st-ui-shadow); }
:root[data-theme="dark"] .app .map-layer-title,
:root[data-theme="dark"] .app .route-focus-title,
:root[data-theme="dark"] .app .route-focus-category { color:var(--st-ui-text); }
:root[data-theme="dark"] .app .map-layer-title small,
:root[data-theme="dark"] .app .route-focus-category small,
:root[data-theme="dark"] .app .route-focus-operator,
:root[data-theme="dark"] .app .stage2-detail-subtitle { color:var(--st-ui-muted); }
:root[data-theme="dark"] .app .map-layer-option { color:var(--st-ui-text); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .app .selected-route-panel :is(.route-focus-data > div,.stage2-detail-cell,.stage2-operational-details) { color:var(--st-ui-text); background:var(--st-ui-raised); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .app .selected-route-panel :is(.route-focus-data strong,.stage2-detail-cell strong,.stage2-operational-details summary) { color:var(--st-ui-text); }
:root[data-theme="dark"] .app .selected-route-panel :is(.route-focus-data small,.stage2-detail-cell small,.stage2-operational-details p) { color:var(--st-ui-muted); }
:root[data-theme="dark"] .app .stage2-detail-divider { background:var(--st-ui-border); }
:root[data-theme="dark"] .app .route-focus-disclaimer,
:root[data-theme="dark"] .app .stage2-detail-status { background:#45361e; border-color:#806334; color:#ffe1a8; }
:root[data-theme="dark"] .app .selected-route-panel :is(.route-focus-close,.route-focus-center,.stage2-route-back) { color:var(--st-ui-text); background:var(--st-ui-raised); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .app .selected-route-panel :is(.route-focus-close,.route-focus-center,.stage2-route-back):hover { background:var(--st-ui-soft); }
:root[data-theme="dark"] .app .mobile-glass-dock { background:#15243af2; border-color:#3e536f; box-shadow:0 10px 32px #0209168c; }
:root[data-theme="dark"] .app .mobile-glass-dock-item { color:#c0d0e4; }
:root[data-theme="dark"] .app .mobile-glass-dock-item.is-active { color:#c3e3ff; border-color:#3c668a; background:linear-gradient(160deg,#223e5f,#253852); box-shadow:inset 0 1px 0 #ffffff0e; }
:root[data-theme="dark"] .app .mobile-glass-dock-item:not(.is-active):hover { color:#fff; background:#243a57; }
:root[data-theme="dark"] .quick-wins-help-dialog { color:var(--st-ui-text); background:var(--st-ui-surface); border-color:var(--st-ui-border); }
:root[data-theme="dark"] .quick-wins-help-head { border-color:var(--st-ui-border); }
:root[data-theme="dark"] .quick-wins-help-head p,
:root[data-theme="dark"] .quick-wins-help-body p { color:var(--st-ui-muted); }
:root[data-theme="dark"] .quick-wins-help-dialog .quick-wins-help-close { color:var(--st-ui-text); background:var(--st-ui-soft); border-color:var(--st-ui-border); }

@media (max-width:820px) and (orientation:portrait) {
  .st-theme-dialog { position:fixed; inset:auto auto calc(94px + env(safe-area-inset-bottom,0px)) 50%; margin:0; width:min(390px,calc(100vw - 24px)); max-height:calc(100dvh - 128px); transform:translateX(-50%); border-radius:21px; }
  .st-theme-dialog-head { padding:18px 17px 13px; }
  .st-theme-options { padding:0 17px 18px; }
}
@media (prefers-reduced-motion:reduce) {
  .st-theme-option,.st-theme-close,.st-theme-trigger,.st-dock-theme-trigger { transition:none !important; animation:none !important; }
  .st-theme-dialog::backdrop { backdrop-filter:none; }
}
