:root {
  color-scheme: dark;
  --bg: #08110f;
  --surface: #0d1a17;
  --raised: #12231f;
  --soft: #172b26;
  --line: #213b34;
  --line-hi: #33574d;
  --text: #f0faf6;
  --muted: #91aaa2;
  --faint: #627a73;
  --mint: #51e0b7;
  --mint-deep: #13b98a;
  --mint-ink: #04261d;
  --amber: #ffbb55;
  --red: #ff6472;
  --shadow: 0 24px 75px rgba(0,0,0,.48), 0 4px 16px rgba(0,0,0,.24);
  --radius: 20px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e8f0ed;
  --surface: #f8fbfa;
  --raised: #fff;
  --soft: #eaf3f0;
  --line: #d1e0db;
  --line-hi: #b8cec6;
  --text: #10241f;
  --muted: #60766f;
  --faint: #81968f;
  --mint: #087c60;
  --mint-deep: #08644f;
  --mint-ink: #fff;
  --amber: #a85f00;
  --red: #d63c4a;
  --shadow: 0 24px 70px rgba(25,60,50,.2), 0 4px 14px rgba(25,60,50,.09);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--text); background: var(--bg); font: 14px/1.35 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input { color: inherit; font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
#map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(.93) hue-rotate(180deg) brightness(.54) saturate(.58) contrast(1.18); }
.leaflet-tile-pane { transition: filter .2s ease; }
.leaflet-control-zoom { overflow: hidden; border: 1px solid var(--line-hi) !important; border-radius: 13px !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { color: var(--text) !important; background: color-mix(in srgb,var(--surface) 94%,transparent) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { color: var(--muted); background: color-mix(in srgb,var(--surface) 88%,transparent) !important; }
.leaflet-control-attribution a { color: var(--mint); }

@keyframes pulse { 50% { opacity: .35; transform: scale(.75); } }
@keyframes spin { to { transform: rotate(360deg); } }

.floating-panel { position: fixed; z-index: 1200; color: var(--text); background: color-mix(in srgb,var(--surface) 96%,transparent); border: 1px solid var(--line-hi); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(24px) saturate(125%); -webkit-backdrop-filter: blur(24px) saturate(125%); }
.search-panel { top: 14px; left: 50%; width: min(430px,calc(100vw - 28px)); min-width: 330px; padding: 7px; transform: translateX(-50%); }
.search-panel:focus-within { border-color: var(--mint); box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb,var(--mint) 12%,transparent); }
.search-field { position: relative; display: flex; height: 43px; align-items: center; }
.search-field > svg { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--muted); }
.search-field input { width: 100%; height: 100%; padding: 0 41px 0 38px; color: var(--text); background: transparent; border: 0; border-radius: 0; font-size: 12px; }
.search-field input::placeholder { color: var(--faint); }
.search-field input:focus { outline: none; }
.search-field kbd { position: absolute; right: 10px; padding: 2px 6px; color: var(--faint); background: var(--soft); border: 1px solid var(--line); border-radius: 6px; font: 10px inherit; pointer-events: none; }
.panel-caption { display: none; padding: 11px 10px 5px; color: var(--faint); font-size: 9px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.search-panel:focus-within .panel-caption, .search-panel:focus-within .result-list:not(:empty) { display: block; }
.search-panel .result-list { display: none; max-height: 420px; overflow: hidden auto; }
.panel-head { display: flex; min-height: 52px; padding: 4px 4px 12px; align-items: center; border-bottom: 1px solid var(--line); }
.panel-head > div { display: grid; min-width: 0; flex: 1; }
.panel-head small { color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .14em; }
.panel-head strong { margin-top: 3px; font-size: 14px; }
.panel-close { display: grid; width: 36px; height: 36px; padding: 0; place-items: center; cursor: pointer; color: var(--muted); background: transparent; border: 0; border-radius: 11px; font-size: 21px; }
.panel-close:hover { color: var(--text); background: var(--soft); }
.mobile-only { display: none; }
.tray { bottom: 88px; left: 50%; display: none; width: 390px; max-height: min(610px,calc(100vh - 120px)); padding: 13px; transform: translateX(-50%); overflow: hidden auto; }
.tray.open { display: block; animation: trayIn .2s ease-out; }
@keyframes trayIn { from { opacity: 0; transform: translate(-50%,8px); } }
.result-list { overflow: auto; }
.result-item { display: flex; width: 100%; min-height: 57px; padding: 9px 8px; align-items: center; gap: 10px; cursor: pointer; color: var(--text); background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.result-item:last-child { border-bottom: 0; }
.result-item:hover { background: var(--soft); }
.result-source { width: 11px; height: 11px; flex: 0 0 auto; background: var(--delay); border: 2px solid var(--mint); border-radius: 3px; }
.result-source.emma { border-color: var(--text); border-radius: 50%; }
.result-copy { display: grid; min-width: 0; flex: 1; }
.result-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.result-copy small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.result-delay { color: var(--delay); font-size: 10px; font-weight: 750; white-space: nowrap; }
.result-remove { display: grid; width: 31px; height: 31px; padding: 0; place-items: center; cursor: pointer; color: var(--red); background: transparent; border: 0; border-radius: 9px; font-size: 18px; }
.follow-row { display: flex; min-height: 57px; padding: 9px 8px; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.follow-row:last-child { border-bottom: 0; }
.follow-main { min-width: 0; min-height: 42px; padding: 0; flex: 1; border-bottom: 0; }
.empty-state { padding: 30px 18px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; color: var(--text); font-size: 13px; }
.empty-state small { display: block; margin-top: 6px; font-size: 10px; line-height: 1.5; }

.tool-section { padding: 15px 1px 0; }
.tool-section > label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.segmented { display: grid; padding: 3px; grid-template-columns: repeat(3,1fr); background: var(--raised); border: 1px solid var(--line); border-radius: 12px; }
.segmented button { min-height: 34px; cursor: pointer; color: var(--muted); background: transparent; border: 0; border-radius: 9px; font-size: 10px; font-weight: 700; }
.segmented button.active { color: var(--mint-ink); background: var(--mint); }
.toggle-list { margin-top: 15px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; }
.toggle-row { display: flex; width: 100%; min-height: 56px; padding: 9px 11px; align-items: center; cursor: pointer; color: var(--text); background: var(--raised); border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row:hover { background: var(--soft); }
.toggle-row > span { display: grid; min-width: 0; flex: 1; }
.toggle-row strong { font-size: 11px; }
.toggle-row small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.toggle-row i { position: relative; width: 34px; height: 20px; background: var(--line-hi); border-radius: 20px; transition: background .15s ease; }
.toggle-row i::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; content: ""; background: #fff; border-radius: 50%; transition: transform .15s ease; }
.toggle-row.active i { background: var(--mint-deep); }
.toggle-row.active i::after { transform: translateX(14px); }
.mode-list { margin-top: 10px; padding: 3px 11px; overflow: hidden; background: var(--raised); border: 1px solid var(--line); border-radius: 14px; }
.mode-row { display: grid; min-height: 50px; grid-template-columns: 1fr 154px; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.mode-row:last-child { border-bottom: 0; }
.mode-row > strong { font-size: 11px; }
.choice-switch { display: grid; padding: 3px; grid-template-columns: 1fr 1fr; background: var(--soft); border: 1px solid var(--line); border-radius: 11px; }
.choice-switch button { min-height: 30px; padding: 0 8px; cursor: pointer; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 9px; font-weight: 750; }
.choice-switch button.active { color: var(--mint-ink); background: var(--mint); box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.tool-actions { display: grid; margin-top: 10px; grid-template-columns: repeat(3,1fr); gap: 7px; }
.tool-actions button { min-height: 38px; cursor: pointer; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 11px; font-size: 10px; font-weight: 700; }
.tool-actions button:hover { color: var(--text); background: var(--soft); }
#refresh-action.loading { color: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
.source-health { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.source-health > div { display: flex; min-height: 38px; align-items: center; gap: 8px; }
.source-mark { width: 8px; height: 8px; background: var(--text); border-radius: 50%; }
.source-mark.emig { background: var(--mint); border-radius: 2px; }
.source-health span:nth-child(2) { display: grid; flex: 1; }
.source-health strong { font-size: 10px; }
.source-health small { color: var(--muted); font-size: 8px; }
.source-health time { color: var(--text); font-size: 10px; font-variant-numeric: tabular-nums; }

.action-dock { position: fixed; z-index: 1150; bottom: 14px; left: 50%; display: flex; height: 64px; padding: 6px; align-items: stretch; gap: 3px; transform: translateX(-50%); background: color-mix(in srgb,var(--surface) 95%,transparent); border: 1px solid var(--line-hi); border-radius: 20px; box-shadow: var(--shadow); backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px); }
.network-summary { display: grid; min-width: 104px; padding: 4px 12px 4px 7px; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; align-items: center; column-gap: 5px; color: var(--muted); border-right: 1px solid var(--line); font-size: 9px; white-space: nowrap; }
.network-summary strong { color: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; }
.network-summary small { color: var(--muted); }
.network-summary #delay-count { color: var(--amber); }
#train-count, #train-unit { grid-row: 1; }
#delay-count, #delay-unit { grid-row: 2; }
#train-count, #delay-count { grid-column: 1; text-align: right; }
#train-unit, #delay-unit { grid-column: 2; }
.dock-action { position: relative; display: grid; min-width: 72px; padding: 6px 10px; place-items: center; cursor: pointer; color: var(--muted); background: transparent; border: 0; border-radius: 14px; font-size: 9px; font-weight: 700; }
.dock-action:hover, .dock-action.active { color: var(--mint); background: var(--soft); }
.dock-action svg { width: 20px; height: 20px; }
.dock-action b { position: absolute; top: 5px; right: 10px; display: grid; min-width: 16px; height: 16px; padding: 0 4px; place-items: center; color: var(--mint-ink); background: var(--mint); border-radius: 9px; font-size: 8px; }

.detail-drawer { position: fixed; z-index: 1400; top: 14px; right: 14px; bottom: 14px; display: flex; width: 420px; overflow: hidden; flex-direction: column; transform: translateX(calc(100% + 30px)); color: var(--text); background: color-mix(in srgb,var(--surface) 97%,transparent); border: 1px solid var(--line-hi); border-radius: 22px; box-shadow: var(--shadow); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.detail-drawer.open { transform: translateX(0); }
.drawer-grab { display: none; }
.drawer-head { display: flex; min-height: 66px; padding: 11px 11px 11px 18px; align-items: center; border-bottom: 1px solid var(--line); }
.drawer-head > div { display: grid; min-width: 0; flex: 1; }
.drawer-head small { color: var(--mint); font-size: 8px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.drawer-head strong { margin-top: 4px; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.drawer-head button { display: grid; width: 40px; height: 40px; padding: 0; place-items: center; cursor: pointer; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 12px; font-size: 22px; }
.drawer-body { padding: 16px 18px 24px; flex: 1; overflow: hidden auto; }
.drawer-actions { display: grid; padding: 11px; grid-template-columns: 1fr auto; gap: 7px; background: var(--surface); border-top: 1px solid var(--line); }
.drawer-actions button { min-height: 42px; padding: 0 15px; cursor: pointer; border-radius: 12px; font-size: 11px; font-weight: 750; }
.primary-action { color: var(--mint-ink); background: var(--mint); border: 0; }
.primary-action.following { color: var(--amber); background: color-mix(in srgb,var(--amber) 10%,var(--raised)); border: 1px solid color-mix(in srgb,var(--amber) 35%,transparent); }
.secondary-action { color: var(--text); background: var(--raised); border: 1px solid var(--line); }
.detail-hero h2 { margin: 2px 0 4px; font-size: 21px; letter-spacing: -.03em; }
.detail-hero p { margin: 0; color: var(--muted); font-size: 12px; }
.detail-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 10px; color: var(--muted); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.data-row { display: grid; min-height: 30px; grid-template-columns: minmax(105px,.8fr) minmax(0,1.2fr); align-items: baseline; gap: 12px; font-size: 11px; }
.data-row span { color: var(--muted); }
.data-row strong { color: var(--text); font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.source-comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.position-card { padding: 11px; background: var(--raised); border: 1px solid var(--line); border-radius: 13px; }
.position-card header { display: flex; align-items: center; gap: 6px; }
.position-card header i { width: 8px; height: 8px; background: var(--text); border-radius: 50%; }
.position-card.emig header i { background: var(--mint); border-radius: 2px; }
.position-card header strong { font-size: 10px; }
.position-card b { display: block; margin-top: 8px; color: var(--text); font-size: 13px; }
.position-card small { color: var(--muted); font-size: 9px; }
.distance-row { display: flex; margin-top: 8px; padding: 9px 11px; align-items: center; background: color-mix(in srgb,var(--amber) 7%,var(--raised)); border: 1px solid color-mix(in srgb,var(--amber) 22%,var(--line)); border-radius: 11px; font-size: 10px; }
.distance-row span { flex: 1; color: var(--muted); }
.distance-row strong { color: var(--amber); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; color: var(--text); font-size: 10px; }
th, td { padding: 8px 7px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
th:first-child, td:first-child { text-align: left; }
th:last-child, td:last-child { border-right: 0; }
th { position: sticky; top: 0; color: var(--muted); background: var(--raised); font-size: 8px; letter-spacing: .05em; text-transform: uppercase; }
td small { display: block; margin-top: 2px; color: var(--muted); font-size: 8px; }
tr.passed { opacity: .48; }
td small.late { color: var(--red); }
.alert-card { margin-top: 8px; padding: 10px; color: var(--amber); background: color-mix(in srgb,var(--amber) 8%,var(--raised)); border: 1px solid color-mix(in srgb,var(--amber) 22%,var(--line)); border-radius: 11px; font-size: 10px; }

.train-canvas { pointer-events: none; }
#map-tooltip { position: fixed; z-index: 1050; max-width: 260px; padding: 9px 11px; pointer-events: none; color: var(--text); background: var(--surface); border: 1px solid var(--line-hi); border-radius: 10px; box-shadow: var(--shadow); font-size: 10px; }
#map-tooltip strong { display: block; margin-bottom: 2px; font-size: 11px; }
#map-tooltip span { color: var(--muted); }
.toast { position: fixed; z-index: 2000; bottom: 92px; left: 50%; padding: 10px 14px; transform: translateX(-50%); color: var(--text); background: var(--raised); border: 1px solid var(--line-hi); border-radius: 11px; box-shadow: var(--shadow); font-size: 10px; }

@media (max-width: 900px) {
  .search-panel { top: auto; right: 8px; bottom: 84px; left: 8px; display: none; width: auto; min-width: 0; max-height: min(66dvh,570px); padding: 12px; transform: none; overflow: hidden auto; }
  .search-panel.open { display: block; animation: mobileTrayIn .22s ease-out; }
  .search-panel:focus-within .panel-caption, .search-panel .result-list:not(:empty) { display: block; }
  .mobile-only { display: flex; }
  .search-field { margin-top: 10px; }
  .tray { right: 8px; bottom: 84px; left: 8px; width: auto; max-height: min(70dvh,610px); transform: none; }
  .tray.open { animation: mobileTrayIn .22s ease-out; }
  @keyframes mobileTrayIn { from { opacity: 0; transform: translateY(10px); } }
  .action-dock { right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); left: 8px; width: auto; height: 66px; transform: none; justify-content: space-around; border-radius: 19px; }
  .network-summary { min-width: 0; width: 96px; padding: 4px 7px 4px 4px; flex: 0 0 96px; column-gap: 4px; }
  .dock-action { min-width: 0; flex: 1; padding: 6px 3px; }
  .leaflet-top.leaflet-right { top: 3px; right: 3px; }
  .leaflet-bottom.leaflet-right { bottom: 72px; }
  .detail-drawer { top: auto; right: 0; bottom: 0; left: 0; width: auto; max-height: min(62dvh,570px); transform: translateY(calc(100% + 16px)); border-right: 0; border-bottom: 0; border-left: 0; border-radius: 24px 24px 0 0; }
  .detail-drawer.open { transform: translateY(0); }
  .detail-drawer.open.minimized { transform: translateY(calc(100% - 160px)); }
  .detail-drawer.dragging { transition: none; }
  .drawer-grab { display: grid; width: 100%; height: 30px; padding: 0; flex: 0 0 auto; place-items: center; cursor: grab; color: var(--muted); background: transparent; border: 0; touch-action: none; }
  .drawer-grab:active { cursor: grabbing; }
  .drawer-grab span { width: 44px; height: 4px; background: var(--line-hi); border-radius: 4px; }
  .drawer-head { min-height: 55px; padding-top: 6px; touch-action: none; }
  .drawer-body { padding: 13px 14px 20px; }
  .drawer-actions { padding-bottom: calc(11px + env(safe-area-inset-bottom)); }
  body.detail-open .action-dock { transform: translateY(calc(100% + 20px)); transition: transform .2s ease; }
  body.detail-minimized .action-dock { z-index: 1450; transform: none; }
  body.detail-open .leaflet-bottom.leaflet-right { display: none; }
  #map-tooltip { display: none !important; }
}

@media (max-width: 420px) {
  .network-summary { width: 62px; flex-basis: 62px; grid-template-columns: 1fr; }
  .network-summary small { display: none; }
  #train-count, #delay-count { text-align: center; }
  .source-comparison { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
