@import url("https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css");
@import url("https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.css");
@import url("https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css");

:root {
  --bg: #0d0f12;
  --surface: #141820;
  --surface2: #1c2230;
  --border: #2a3348;
  --amber: #f0a500;
  --amber-dim: #8a5e00;
  --blue: #4a90d9;
  --red: #e04040;
  --green: #3ecf6a;
  --text: #d4dce8;
  --muted: #5a6a80;
  --text-strong: #ffffff;
  --map-bg: #0a0d11;
  --shadow-strong: rgba(0, 0, 0, 0.6);
  --shadow-soft: rgba(0, 0, 0, 0.5);
  --leaflet-attribution-bg: rgba(13, 15, 18, 0.8);
  --accent-soft: rgba(240, 165, 0, 0.06);
  --accent-strong: rgba(240, 165, 0, 0.85);
  --success-soft: rgba(62, 207, 106, 0.18);
  --success-border: rgba(62, 207, 106, 0.35);
  --danger-soft: rgba(224, 64, 64, 0.55);
  --danger-border: rgba(224, 64, 64, 0.8);
  --danger-solid: rgba(224, 64, 64, 0.8);
  --danger-stripe: rgba(224, 64, 64, 0.55);
  --danger-stripe-transparent: rgba(224, 64, 64, 0);
  --label-strong: rgba(255, 255, 255, 0.9);
  --loader-backdrop: rgba(13, 15, 18, 0.9);
  --timeline-divider: rgba(42, 51, 72, 0.5);
  --tooltip-shadow: rgba(0, 0, 0, 0.5);
  --green-muted: rgba(62, 207, 106, 0.15);
  --amber-muted: rgba(240, 165, 0, 0.15);
  --cluster-ring: rgba(240, 165, 0, 0.3);
  --cluster-fill: rgba(240, 165, 0, 0.85);
  --cluster-text: #0d0f12;
  --crossing-public: #f0a500;
  --crossing-private: #6b7280;
  --crossing-unknown: #4b5563;
  --crossing-stroke: #0d0f12;
  --selected-fill: #ffffff;
  --selected-stroke: #f0a500;
  --station-fill: #4a90d9;
  --station-selected-fill: #ffffff;
  --station-selected-stroke: #4a90d9;
  --station-cluster-soft: rgba(74, 144, 217, 0.3);
  --station-cluster-medium: rgba(74, 144, 217, 0.35);
  --station-cluster-strong: rgba(74, 144, 217, 0.4);
  --station-cluster-inner-soft: rgba(74, 144, 217, 0.6);
  --station-cluster-inner-medium: rgba(74, 144, 217, 0.7);
  --station-cluster-inner-strong: rgba(74, 144, 217, 0.8);
  --vehicle-stroke: #0d0f12;
  --vehicle-on-time: #3b82f6;
  --vehicle-minor-delay: #f97316;
  --vehicle-major-delay: #ef4444;
  --badge-os: #4a90d9;
  --badge-ic: #b980f0;
  --match-matched: #22c55e;
  --match-low-confidence: #f0a500;
  --match-unmatched: #5a6a80;
  --rail-usage-main: #f0a500;
  --rail-usage-branch: #d4890a;
  --rail-usage-unknown: #5a6a80;
  --rail-electrified: #22d3ee;
  --rail-tracks-1: #86efac;
  --rail-tracks-2: #22c55e;
  --rail-tracks-3: #15803d;
  --rail-speed-0: #3b82f6;
  --rail-speed-80: #22d3ee;
  --rail-speed-100: #fbbf24;
  --rail-speed-120: #f97316;
  --rail-speed-160: #ef4444;
  --rail-tunnel: #f8fafc;
  --empty-rail-stroke: #5a6a80;
  --empty-rail-dash: #e04040;
  --no-service-primary: #6b7280;
  --no-service-secondary: #4b5563;
  --theme-toggle-bg: rgba(28, 34, 48, 0.8);
  --theme-toggle-border: #2a3348;
  --theme-toggle-active-bg: #f0a500;
  --theme-toggle-active-text: #0d0f12;
  --theme-toggle-hover: rgba(240, 165, 0, 0.08);
  --mono: 'Datatype', monospace;
  --display: 'Oswald', sans-serif;
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #e8eaef;
  --border: #c4c9d4;
  --amber: #d97706;
  --amber-dim: #92400e;
  --blue: #2a6da8;
  --red: #b54242;
  --green: #1e7d4c;
  --text: #1e2a3a;
  --muted: #4d5c6c;
  --text-strong: #0c1420;
  --map-bg: #dde5ef;
  --shadow-strong: rgba(0, 0, 0, 0.15);
  --shadow-soft: rgba(0, 0, 0, 0.1);
  --leaflet-attribution-bg: rgba(240, 242, 245, 0.92);
  --accent-soft: rgba(217, 119, 6, 0.08);
  --accent-strong: rgba(217, 119, 6, 0.5);
  --success-soft: rgba(30, 125, 76, 0.22);
  --success-border: rgba(30, 125, 76, 0.35);
  --danger-soft: rgba(181, 66, 66, 0.2);
  --danger-border: rgba(181, 66, 66, 0.45);
  --danger-solid: rgba(181, 66, 66, 0.65);
  --danger-stripe: rgba(181, 66, 66, 0.26);
  --danger-stripe-transparent: rgba(181, 66, 66, 0.04);
  --label-strong: rgba(12, 20, 32, 0.9);
  --loader-backdrop: rgba(240, 242, 245, 0.92);
  --timeline-divider: rgba(196, 201, 212, 0.7);
  --tooltip-shadow: rgba(0, 0, 0, 0.1);
  --green-muted: rgba(34, 138, 85, 0.12);
  --amber-muted: rgba(198, 122, 0, 0.14);
  --cluster-ring: rgba(217, 119, 6, 0.2);
  --cluster-fill: rgba(217, 119, 6, 0.75);
  --cluster-text: #ffffff;
  --crossing-public: #d97706;
  --crossing-private: #8290a0;
  --crossing-unknown: #a5aeba;
  --crossing-stroke: #ffffff;
  --selected-fill: #ffffff;
  --selected-stroke: #d97706;
  --station-fill: #2a6da8;
  --station-selected-fill: #ffffff;
  --station-selected-stroke: #2a6da8;
  --station-cluster-soft: rgba(42, 109, 168, 0.16);
  --station-cluster-medium: rgba(42, 109, 168, 0.22);
  --station-cluster-strong: rgba(42, 109, 168, 0.28);
  --station-cluster-inner-soft: rgba(42, 109, 168, 0.46);
  --station-cluster-inner-medium: rgba(42, 109, 168, 0.56);
  --station-cluster-inner-strong: rgba(42, 109, 168, 0.66);
  --vehicle-stroke: #ffffff;
  --vehicle-on-time: #3a70b8;
  --vehicle-minor-delay: #c86e20;
  --vehicle-major-delay: #b54242;
  --badge-os: #2a6da8;
  --badge-ic: #7850b0;
  --match-matched: #298c55;
  --match-low-confidence: #d97706;
  --match-unmatched: #6e7a88;
  --rail-usage-main: #d97706;
  --rail-usage-branch: #c48e38;
  --rail-usage-unknown: #6e7a88;
  --rail-electrified: #2080a8;
  --rail-tracks-1: #56a876;
  --rail-tracks-2: #298c55;
  --rail-tracks-3: #1a6038;
  --rail-speed-0: #3a70b8;
  --rail-speed-80: #2298b8;
  --rail-speed-100: #d09520;
  --rail-speed-120: #c86e20;
  --rail-speed-160: #b54242;
  --rail-tunnel: #1e2a3a;
  --empty-rail-stroke: #7e8a98;
  --empty-rail-dash: #b54242;
  --no-service-primary: #6e7a88;
  --no-service-secondary: #8e98a6;
  --theme-toggle-bg: rgba(255, 255, 255, 0.9);
  --theme-toggle-border: #c4c9d4;
  --theme-toggle-active-bg: #d97706;
  --theme-toggle-active-text: #ffffff;
  --theme-toggle-hover: rgba(217, 119, 6, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 2px solid var(--amber);
  box-shadow: 0 2px 16px var(--shadow-soft);
  z-index: 3000;
  flex-shrink: 0;
}

.logo-icon { width: 36px; height: 36px; }
.logo-icon svg { width: 100%; height: 100%; }

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  color: var(--amber);
  text-transform: uppercase;
}
h1 span { color: var(--text); font-weight: 300; }

.header-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-stats { display: flex; gap: 24px; align-items: center; }

.alert-wrapper { position: relative; }

.alert-indicator {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 4px;
  background: rgba(240, 165, 0, 0.1);
  border: 1px solid rgba(240, 165, 0, 0.3);
  font-size: 0.7rem; letter-spacing: 0.06em;
  color: var(--amber); cursor: pointer;
  white-space: nowrap; position: relative;
  user-select: none;
}
.alert-indicator:hover { background: rgba(240, 165, 0, 0.2); }
.alert-indicator.hidden { display: none; }
.alert-indicator-icon {
  font-weight: 700; font-size: 0.75rem;
  width: 16px; height: 16px; line-height: 16px;
  text-align: center; border-radius: 50%;
  background: var(--amber); color: var(--bg);
}
.alert-indicator-text { color: var(--amber); }

.alert-dropdown {
  position: absolute; top: 100%; right: 0;
  margin-top: 8px; min-width: 320px; max-width: 400px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow-strong);
  z-index: 10000; overflow: hidden;
}
.alert-dropdown.hidden { display: none; }
.alert-dropdown-header {
  padding: 10px 14px; font-size: 0.7rem; letter-spacing: 0.08em;
  color: var(--muted); border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}
.alert-dropdown-list { max-height: 360px; overflow-y: auto; }
.alert-dropdown-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.alert-dropdown-item:last-child { border-bottom: none; }
.alert-dropdown-item--clickable { cursor: pointer; }
.alert-dropdown-item--clickable:hover { background: rgba(240, 165, 0, 0.06); }
.alert-dropdown-item-header {
  font-size: 0.8rem; font-weight: 600; color: var(--text);
  margin-bottom: 4px;
}
.alert-dropdown-item-desc {
  font-size: 0.7rem; color: var(--muted); line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.alert-dropdown-item-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.alert-dropdown-effect {
  font-size: 0.6rem; letter-spacing: 0.06em;
  padding: 1px 6px; border-radius: 3px;
  color: var(--amber); background: rgba(240, 165, 0, 0.15);
}
.alert-dropdown-map-link {
  font-size: 0.6rem; letter-spacing: 0.04em;
  color: var(--blue); cursor: pointer;
}
.alert-dropdown-map-link:hover { text-decoration: underline; }

.alert-effect-tag .meta-tag-value { color: var(--amber); font-weight: 600; }
.alert-panel-section { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.alert-panel-section:last-child { border-bottom: none; }
.alert-panel-section-title {
  font-size: 0.65rem; letter-spacing: 0.08em; color: var(--muted);
  text-transform: uppercase; margin-bottom: 6px;
}
.alert-panel-description { font-size: 0.8rem; color: var(--text); line-height: 1.5; }
.alert-panel-routes { display: flex; gap: 6px; flex-wrap: wrap; }
.alert-panel-route-tag {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 3px;
  background: rgba(240, 165, 0, 0.15); color: var(--amber);
}
.alert-panel-stops { display: flex; gap: 6px; flex-wrap: wrap; }
.alert-panel-stop {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 3px;
  background: var(--surface); color: var(--text);
}
.alert-panel-footer { display: flex; gap: 12px; }

.stat { text-align: right; font-size: 0.7rem; color: var(--muted); letter-spacing: 0.08em; }
.stat strong {
  display: block; font-size: 1.1rem; color: var(--amber);
  font-family: var(--display); font-weight: 400; line-height: 1;
}

.stat-clock {
  font-family: var(--mono);
  font-size: 0.95rem;
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-switch-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: color 0.15s ease, opacity 0.15s ease;
}

.theme-switch-icon svg {
  width: 100%;
  height: 100%;
}

.theme-switch-icon.is-resolved {
  color: var(--amber);
}

.theme-switch-track {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--theme-toggle-border);
  border-radius: 999px;
  background: var(--theme-toggle-bg);
  backdrop-filter: blur(10px);
}

.theme-switch-option {
  border: none;
  background: transparent;
  color: var(--muted);
  min-width: 46px;
  padding: 7px 10px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.theme-switch-option:hover {
  background: var(--theme-toggle-hover);
  color: var(--text);
}

.theme-switch-option:active {
  transform: scale(0.94);
}

.theme-switch-option:focus-visible {
  outline-offset: -1px;
}

.theme-switch-option.is-active {
  background: var(--theme-toggle-active-bg);
  color: var(--theme-toggle-active-text);
}

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 8px var(--green);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity:1; box-shadow:0 0 8px var(--green); }
  50%      { opacity:0.5; box-shadow:0 0 3px var(--green); }
}

/* APP LAYOUT WRAPPER */
.app-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* MAIN LAYOUT */
.main-area { display: flex; flex: 1; overflow: hidden; }

/* MAP */
#map-container { flex: 1; position: relative; outline: none; }

/* Leaflet overrides */
.leaflet-container { background: var(--map-bg) !important; font-family: var(--mono); outline: none; }
.leaflet-popup-content-wrapper {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; box-shadow: 0 8px 32px var(--shadow-strong); color: var(--text);
}
.leaflet-popup-tip { background: var(--surface2); }
.leaflet-popup-content { margin: 10px 14px; font-family: var(--mono); font-size: 0.75rem; }
.leaflet-control-zoom { border: 1px solid var(--border) !important; border-radius: 6px !important; overflow: hidden; box-shadow: 0 2px 8px var(--shadow-soft) !important; }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--amber) !important; border-color: var(--border) !important; width: 32px !important; height: 32px !important; line-height: 32px !important; font-size: 16px !important; transition: background 0.15s ease; }
.leaflet-control-zoom a:hover { background: var(--surface2) !important; }
.leaflet-control-attribution { background: var(--leaflet-attribution-bg) !important; color: var(--muted) !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.4; } }

/* SIDEBAR PANEL — always visible, fixed width */
#panel-container {
  width: clamp(300px, 28vw, 440px);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 2px solid var(--amber);
  box-shadow: -4px 0 20px var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.25s ease;
}

/* PANEL COMPONENTS */
.panel-header { padding: 16px; border-bottom: 1px solid var(--border); background: var(--surface2); transition: background-color 0.25s ease; }
.panel-title {
  font-family: var(--display); font-size: 0.7rem;
  letter-spacing: 0.2em; color: var(--muted); text-transform: uppercase; margin-bottom: 4px;
}
.crossing-name {
  font-family: var(--display); font-size: 1.1rem; font-weight: 600;
  color: var(--amber); letter-spacing: 0.05em; line-height: 1.2;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.crossing-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.meta-tag {
  font-size: 0.7rem; color: var(--muted); letter-spacing: 0.06em;
  background: var(--bg); padding: 2px 8px; border: 1px solid var(--border);
}
.meta-tag-label { color: var(--muted); font-size: 0.65rem; }
.meta-tag-value { color: var(--text); margin-left: 3px; font-weight: 500; }

/* CLOCK */
.clock-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg);
  flex-shrink: 0; gap: 12px; overflow: hidden;
}
.clock { font-size: 1.5rem; letter-spacing: 0.1em; color: var(--amber); font-variant-numeric: tabular-nums; }
.clock-seconds { font-size: 0.7em; opacity: 0.5; }
.clock-label { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.15em; }
.clock-date { font-size: 0.8rem; color: var(--muted); }
.clock-bar-right { text-align: right; }

/* NEXT TRAIN */
.next-train-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.next-train-label { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.1em; flex-shrink: 0; }
.next-train-time  { font-family: var(--display); font-size: 1.3rem; font-weight: 400; color: var(--text-strong); }
.next-train-in    { margin-left: auto; text-align: right; }
.countdown        { font-size: 0.9rem; color: var(--green); }
.countdown.soon   { color: var(--red); animation: blink 1s infinite; }

/* GATE TIMELINE */
.gate-timeline {
  display: flex;
  flex-direction: column;
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.timeline-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; border-left: 2px solid var(--amber); padding-left: 8px; }
.timeline-title  { font-size: 0.65rem; letter-spacing: 0.2em; color: var(--muted); text-transform: uppercase; }
.gate-status-badge { font-size: 0.65rem; letter-spacing: 0.1em; padding: 2px 8px; border: 1px solid; border-radius: 2px; }
.gate-status-badge.open   { border-color: var(--green); color: var(--green); }
.gate-status-badge.closed { border-color: var(--red);   color: var(--red); animation: blink 0.8s ease-in-out infinite; }

/* SCHEDULE SECTION HEADER */
.schedule-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; padding-left: 14px;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid var(--amber);
}
.schedule-title {
  font-size: 0.65rem; letter-spacing: 0.2em; color: var(--muted); text-transform: uppercase;
}
.schedule-freshness {
  font-size: 0.6rem; letter-spacing: 0.08em;
  display: flex; align-items: center; gap: 5px;
}
.schedule-live { color: var(--green); }
.schedule-timetable { color: var(--muted); cursor: help; }
.live-dot-sm {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--green); box-shadow: 0 0 6px var(--green);
  animation: pulse 2s ease-in-out infinite;
}
.rt-updating { color: var(--amber); }

.timeline-wrap { position: relative; height: 60px; }
.timeline-bar {
  position: absolute; top: 10px; left: 0; right: 0; height: 20px;
  background: var(--success-soft); border: 1px solid var(--success-border);
  border-radius: 3px;
}
.gate-seg {
  position: absolute; top: -1px; height: calc(100% + 2px);
  background: var(--danger-soft); border: 1px solid var(--danger-border);
  border-radius: 2px; cursor: pointer; transition: background 0.1s; z-index: 2;
}
.gate-seg:hover { background: var(--danger-solid); }
.gate-seg:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.gate-seg.low-confidence {
  background: repeating-linear-gradient(
    -45deg,
    var(--danger-stripe),
    var(--danger-stripe) 4px,
    var(--danger-stripe-transparent) 4px,
    var(--danger-stripe-transparent) 8px
  );
  border: 1px solid var(--danger-border);
}
.gate-seg-label {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 0.55rem; color: var(--label-strong); white-space: nowrap; pointer-events: none;
}
.timeline-now-needle {
  position: absolute; top: 0; width: 2px; height: 48px;
  background: var(--amber); box-shadow: 0 0 6px var(--accent-strong);
  z-index: 10; left: 0;
}
.timeline-now-needle::after {
  content: 'TEĎ'; position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 0.6rem; color: var(--amber); letter-spacing: 0.1em; white-space: nowrap;
}
.timeline-ticks { position: absolute; bottom: 0; left: 0; right: 0; height: 14px; }
.timeline-tick  { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.timeline-tick-mark  { width: 1px; height: 5px; background: var(--border); }
.timeline-tick-label { font-size: 0.6rem; color: var(--muted); }

/* GATE TOOLTIP */
.gate-tooltip {
  display: none; position: fixed;
  background: var(--surface2); border: 1px solid var(--red);
  padding: 7px 10px; font-size: 0.65rem; line-height: 1.6;
  z-index: 9999; pointer-events: none; box-shadow: 0 4px 16px var(--shadow-soft); max-width: 220px;
}
.gate-tooltip .tt-train { color: var(--amber); font-size: 0.7rem; margin-bottom: 2px; }
.gate-tooltip .tt-row   { color: var(--text); }
.gate-tooltip .tt-muted { color: var(--muted); }

.timeline-legend { display: flex; gap: 14px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 0.6rem; color: var(--muted); }
.legend-dot  { width: 10px; height: 10px; border-radius: 1px; }
.legend-dot.red   { background: var(--danger-soft);  border: 1px solid var(--danger-border); }
.legend-dot.green { background: var(--success-soft); border: 1px solid var(--success-border); }
.legend-dot.red.striped {
  background: repeating-linear-gradient(
    -45deg,
    var(--danger-stripe),
    var(--danger-stripe) 3px,
    var(--danger-stripe-transparent) 3px,
    var(--danger-stripe-transparent) 6px
  );
  border: 1px solid var(--danger-border);
}

/* SCHEDULE LIST */
.schedule-scroll { flex: 1; overflow-y: auto; padding: 8px 0; scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }
.schedule-scroll::-webkit-scrollbar { width: 4px; }
.schedule-scroll::-webkit-scrollbar-track { background: var(--bg); }
.schedule-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.train-row {
  display: grid; grid-template-columns: 72px 1fr;
  align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--timeline-divider);
  cursor: pointer; transition: background 0.1s; position: relative;
}
.train-time-col { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; }
.train-info-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.train-meta { display: flex; align-items: center; gap: 6px; }
.train-row:hover   { background: var(--surface2); }
.train-row:active  { background: var(--surface2); transform: scale(0.995); }
.train-row.passed  { opacity: 0.35; }
.train-row.next-up { background: var(--accent-soft); border-left: 3px solid var(--amber); }
.train-row.next-up::before { content:'\25B6'; position:absolute; left:5px; color:var(--amber); font-size:0.7rem; }
.train-row:focus-visible { background: var(--accent-soft); border-left: 3px solid var(--amber); outline: none; }
.train-row.low-confidence { opacity: 0.5; }

.train-time { font-size: 1rem; letter-spacing: 0.05em; font-variant-numeric: tabular-nums; color: var(--text); }
.train-row.passed  .train-time { text-decoration: line-through; }
.train-row.next-up .train-time { color: var(--amber); font-weight: bold; }
.train-number { font-size: 0.7rem; color: var(--amber-dim); letter-spacing: 0.06em; line-height: 1; }
.train-route  { font-size: 0.8rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.train-type-badge {
  font-size: 0.6rem; padding: 2px 6px; border: none;
  letter-spacing: 0.08em; border-radius: 2px; white-space: nowrap;
  line-height: 1; font-weight: 600;
}
.badge-os { background: var(--badge-os); color: var(--bg); }
.badge-sp { background: var(--green); color: var(--bg); }
.badge-r  { background: var(--amber); color: var(--bg); }
.badge-ex { background: var(--red);   color: var(--bg); }
.badge-ic { background: var(--badge-ic); color: var(--bg); }

.est-label { font-size: 0.6rem; color: var(--muted); opacity: 0.5; margin-left: 4px; }

/* DELAY BADGES */
.delay-badge {
  font-size: 0.7rem; letter-spacing: 0.06em; white-space: nowrap;
  line-height: 1; margin-left: 4px;
  animation: delay-badge-in 0.3s ease forwards;
}
@keyframes delay-badge-in { from { opacity: 0; } to { opacity: 1; } }
.delay-badge-amber { color: var(--amber); }
.delay-badge-red   { color: var(--red); }
.delay-badge-green { color: var(--green); }
.delay-badge.fading { animation: delay-badge-out 0.3s ease forwards; }
@keyframes delay-badge-out { from { opacity: 1; } to { opacity: 0; } }

/* ALERT BADGES */
.alert-badge {
  font-size: 0.65rem; letter-spacing: 0.06em; white-space: nowrap;
  line-height: 1; margin-left: 4px;
  color: var(--amber); background: rgba(240, 165, 0, 0.15);
  padding: 1px 5px; border-radius: 3px;
  cursor: help;
}

/* EMPTY STATE */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px; padding: 48px 32px; color: var(--muted); text-align: center;
  min-height: 300px;
}
.empty-state svg { opacity: 0.35; width: 80px; height: 80px; transition: opacity 0.3s ease; }
.empty-state:hover svg { opacity: 0.5; }
.empty-state p   { font-size: 0.8rem; letter-spacing: 0.08em; line-height: 1.6; max-width: 240px; }

/* LOADING OVERLAY */
#loading {
  position: absolute; inset: 0; background: var(--loader-backdrop);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; z-index: 2000;
}
.loader-track { width: 200px; height: 4px; background: var(--border); position: relative; overflow: hidden; }
.loader-train { position: absolute; height: 100%; width: 60px; background: var(--amber); animation: trainMove 1.4s ease-in-out infinite; }
@keyframes trainMove { 0% { left: -60px; } 100% { left: 200px; } }
.loader-text  { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.2em; text-transform: uppercase; }

/* COORD BAR */
.coord-bar {
  padding: 8px 16px; border-top: 1px solid var(--border);
  font-size: 0.65rem; color: var(--muted); letter-spacing: 0.08em;
  background: var(--bg); display: flex; justify-content: space-between; flex-shrink: 0;
  transition: background-color 0.25s ease;
}
.coord-val { color: var(--text); font-variant-numeric: tabular-nums; }

/* Skeleton loading — visible while turbo-frame is fetching */
turbo-frame[busy]::after {
  content: '';
  display: block;
  width: 340px;
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface2) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Panel content entrance animation */
@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
turbo-frame#crossing-panel > div {
  animation: panel-in 0.2s ease-out;
}

/* Classification badge */
.classification-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  vertical-align: middle;
  letter-spacing: 0.04em;
}

/* Arrival sub-time (station panel: smaller time above main) */
.train-arrival-sub {
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

/* Terminus arrival label */
.train-terminus-label {
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-top: 1px;
}

/* Vehicle delay display override */
.vehicle-delay-display {
  font-size: 1.1rem;
}

/* Amber cluster marker overrides */
.marker-cluster-small {
  background-color: var(--cluster-ring);
}
.marker-cluster-small div {
  width: 30px;
  height: 30px;
  margin-left: 5px;
  margin-top: 5px;
  background-color: var(--cluster-fill);
  color: var(--cluster-text);
  font-weight: 600;
  border-radius: 15px;
  line-height: 30px;
  font-size: 12px;
}

.marker-cluster-medium {
  background-color: var(--cluster-ring);
}
.marker-cluster-medium div {
  width: 36px;
  height: 36px;
  margin-left: 5px;
  margin-top: 5px;
  background-color: var(--cluster-fill);
  color: var(--cluster-text);
  font-weight: 600;
  border-radius: 18px;
  line-height: 36px;
  font-size: 13px;
}

.marker-cluster-large {
  background-color: var(--cluster-ring);
}
.marker-cluster-large div {
  width: 44px;
  height: 44px;
  margin-left: 5px;
  margin-top: 5px;
  background-color: var(--cluster-fill);
  color: var(--cluster-text);
  font-weight: 600;
  border-radius: 22px;
  line-height: 44px;
  font-size: 14px;
}

.hidden { display: none; }

/* Vehicle markers */
.vehicle-marker { background: none !important; border: none !important; }
.vehicle-chevron { width: 16px; height: 20px; display: flex; align-items: center; justify-content: center; }
.vehicle-chevron svg { transition: transform 0.8s ease; }

/* Smooth position animation for DOM-based markers (L.marker with DivIcon) */
/* Does NOT affect L.circleMarker (canvas-rendered crossings) */
.leaflet-marker-pane > * {
  transition: transform 1s linear;
}

/* Fade-in for new vehicle markers */
@keyframes vehicle-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.vehicle-marker {
  animation: vehicle-fade-in 0.5s ease forwards;
}

.vehicle-panel { padding: 0; }
.stop-adjusted-time {
  display: block;
  font-size: 0.7rem;
  color: var(--amber);
  font-family: var(--mono);
}

@media (max-width: 767px) {
  /* Header: simplify for mobile */
  header {
    padding: 8px 12px;
    gap: 8px;
  }
  header h1 { font-size: 1rem; }
  .header-controls { gap: 12px; }
  .header-stats { display: none; }
  .alert-indicator .alert-indicator-text { display: none; }
  .theme-switch-track { padding: 2px; }
  .theme-switch-option {
    min-width: 38px;
    padding: 6px 8px;
    font-size: 0.55rem;
  }

  /* Layout: stack vertically, map fills all */
  .main-area {
    flex-direction: column;
    position: relative;
  }
  #map-container {
    flex: 1;
    width: 100%;
    position: absolute;
    inset: 0;
  }

  /* Panel becomes bottom sheet */
  #panel-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100vh;
    width: 100%;
    border-left: none;
    border-top: 2px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 1000;
    will-change: transform;
    display: flex;
    flex-direction: column;
  }

  .sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 16px 6px;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
  }
  .sheet-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--muted);
    margin-bottom: 8px;
    transition: background 0.15s ease;
  }
  .sheet-handle:hover .sheet-handle-bar { background: var(--amber); }
  .sheet-blank-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.08em;
  }
  .sheet-hint {
    display: none;
  }

  .sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile empty state: horizontal two-column layout */
  .empty-state {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 16px;
    padding: 12px 20px;
    min-height: auto;
  }
  .empty-state svg {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    padding: 4px;
  }
  .empty-state p {
    flex: 1;
    margin: 0;
  }

  /* Hide schedule label on mobile collapsed */
  .desktop-only { display: none; }

  /* Tooltip on mobile: tap to show */
  .gate-tooltip {
    bottom: auto;
  }
}

/* Hide sheet handle on desktop */
@media (min-width: 768px) {
  .sheet-handle { display: none; }
  .sheet-content { display: contents; }
  .desktop-only { display: block; }
}

/* ADMIN IMPORTS PAGE */
.admin-imports {
  padding: 24px 32px;
  max-width: 960px;
}
.admin-imports h2 {
  font-family: var(--display);
  color: var(--amber);
  font-size: 1.4rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}
.import-reports-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.import-reports-table th {
  text-align: left;
  padding: 6px 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.import-reports-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.import-reports-table .no-data {
  color: var(--muted);
  text-align: center;
  padding: 20px;
}
.import-type {
  color: var(--amber);
  font-weight: bold;
}
.status-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.status-badge.status-completed { background: var(--green-muted); color: var(--green); }
.status-badge.status-running   { background: var(--amber-muted);  color: var(--amber); }
.status-badge.status-failed    { background: var(--danger-soft);  color: var(--red); }

/* Station markers */
.station-marker { background: transparent; border: none; transition: transform 0.15s ease, filter 0.15s ease; }
.station-marker:hover { transform: scale(1.3); filter: drop-shadow(0 0 3px var(--station-fill)); }
.station-marker--selected rect { fill: var(--station-selected-fill); stroke: var(--station-selected-stroke); stroke-width: 1.5; }

/* Station cluster overrides (blue theme) */
.station-cluster { background-color: var(--station-cluster-soft); }
.station-cluster.marker-cluster-small { background-color: var(--station-cluster-soft); }
.station-cluster.marker-cluster-medium { background-color: var(--station-cluster-medium); }
.station-cluster.marker-cluster-large { background-color: var(--station-cluster-strong); }
.station-cluster div { background-color: var(--station-cluster-inner-soft); }
.station-cluster.marker-cluster-small div { background-color: var(--station-cluster-inner-soft); }
.station-cluster.marker-cluster-medium div { background-color: var(--station-cluster-inner-medium); }
.station-cluster.marker-cluster-large div { background-color: var(--station-cluster-inner-strong); }

/* Match status badges for station panel */
.match-badge-matched { color: var(--match-matched); }
.match-badge-low_confidence { color: var(--match-low-confidence); }
.match-badge-unmatched { color: var(--match-unmatched); }

.no-service-state {
  padding: 1.5rem 1rem;
  text-align: center;
}

.no-service-title {
  color: var(--no-service-primary);
  font-size: 0.9rem;
  font-weight: 500;
  margin: 0 0 0.5rem 0;
}

.no-service-line {
  color: var(--no-service-secondary);
  font-size: 0.75rem;
  margin: 0.25rem 0;
}

/* Layer toggle panel */
.layer-toggle-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text);
  min-width: 140px;
}
.layer-toggle-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  font-size: 0.85rem;
}
.layer-toggle-body { padding: 0 12px 8px; }
.layer-toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  transition: background 0.1s;
}
.layer-toggle-item:hover { background: var(--accent-soft); }
.layer-toggle-item input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; flex-shrink: 0;
  border: 1.5px solid var(--border); border-radius: 3px;
  background: transparent; cursor: pointer;
  position: relative; transition: border-color 0.15s ease, background 0.15s ease;
}
.layer-toggle-item input[type="checkbox"]:checked {
  background: var(--amber); border-color: var(--amber);
}
.layer-toggle-item input[type="checkbox"]:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid var(--bg); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.layer-toggle-item input[type="checkbox"]:indeterminate {
  border-color: var(--amber);
}
.layer-toggle-item input[type="checkbox"]:indeterminate::after {
  content: ''; position: absolute; left: 3px; top: 6px;
  width: 8px; height: 2px; background: var(--amber);
}
.layer-toggle-icon { display: inline-flex; align-items: center; justify-content: center; width: 12px; height: 12px; pointer-events: none; }
.layer-toggle-item span { pointer-events: none; }
.layer-toggle-children { padding-left: 16px; }
.layer-toggle-group-header { font-weight: 500; }
.railways-mode-fieldset {
  border: none;
  margin: 0;
  padding: 0;
}
.railways-mode-item input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; flex-shrink: 0;
  border: 1.5px solid var(--border); border-radius: 50%;
  background: transparent; cursor: pointer;
  position: relative; transition: border-color 0.15s ease;
}
.railways-mode-item input[type="radio"]:checked {
  border-color: var(--amber);
}
.railways-mode-item input[type="radio"]:checked::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
}
.railways-infrastructure-hint {
  padding: 8px 0 4px;
  font-size: 0.72rem;
  color: var(--muted);
}
.railways-infrastructure-copy {
  margin: 0 0 4px;
  opacity: 0.8;
}
.railways-infrastructure-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.railways-infrastructure-swatch {
  position: relative;
  display: inline-block;
  width: 22px;
  height: 8px;
  flex-shrink: 0;
}
.railways-infrastructure-swatch::before,
.railways-infrastructure-swatch::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 999px;
}
.railways-infrastructure-swatch::before {
  height: 3px;
  background: var(--railways-infrastructure-base, var(--rail-usage-branch));
  opacity: 0.55;
}
.railways-infrastructure-swatch-bridge::after {
  height: 5px;
  background: var(--railways-infrastructure-overlay, var(--amber));
}
.railways-infrastructure-swatch-tunnel::after {
  height: 5px;
  background: repeating-linear-gradient(
    to right,
    var(--rail-tunnel) 0 8px,
    transparent 8px 12px
  );
}
.railways-legend {
  padding: 4px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}
.railways-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}
.railways-legend-swatch {
  display: inline-block;
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}
.railways-legend-gradient {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.railways-legend-gradient-bar {
  width: 80px;
  height: 6px;
  border-radius: 3px;
  flex-shrink: 0;
}
.railways-legend-coverage {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.7;
  padding-top: 2px;
}

@media (max-width: 768px) {
  .layer-toggle-body { display: none; }
  .layer-toggle-panel.expanded .layer-toggle-body { display: block; }
  .layer-toggle-label { display: none; }
  .layer-toggle-header:hover { background: var(--surface2); }
  .layer-toggle-header:active { background: var(--surface2); }
}

@media (min-width: 769px) {
  .layer-toggle-header { cursor: default; }
}
