:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
    --sidebar-bg: rgba(15, 23, 42, 0.75);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --font-family: 'Inter', sans-serif;
    --transition-speed: 0.3s;
}

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

html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* Prevent bounce */
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    /* Fallback for browsers that don't support dvh */
    height: 100vh;
    /* Dynamic Viewport Height (solves the mobile address bar issue) */
    /* Dynamic Viewport Height (solves the mobile address bar issue) */
    height: 100dvh;
}

/* Station Search */
#station-search-container {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    right: 20px;
    width: 300px;
    z-index: 2000;
}

/* Mobile: Floating Centered Bar */
@media (max-width: 600px) {
    #station-search-container {
        top: calc(12px + env(safe-area-inset-top));
        left: 10px;
        right: 10px;
        width: auto;
        max-width: none;
    }

    #station-search-input {
        height: 50px;
        /* Larger touch target */
        font-size: 16px;
        /* Prevent IOS zoom */
        padding-left: 44px;
        /* Space for icon */
        background-repeat: no-repeat;
        background-position: 12px center;
        background-size: 24px;
    }

    /* Push Leaflet Controls down */
    .leaflet-top.leaflet-left {
        top: 70px;
        /* Clear the floating search bar */
    }
}

#station-search-input {
    width: 100%;
    background-color: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 24px;
    /* Pill shape */
    padding: 12px 20px;
    color: #fff;
    font-family: var(--font-family);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#station-search-input:focus {
    border-color: var(--accent-color);
    background-color: rgba(15, 23, 42, 0.95);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transform: translateY(-1px);
}

#station-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    max-height: 45vh;
    /* Limit relative to viewport */
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
}

#station-search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.search-name {
    font-size: 0.9rem;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* margin-right: 8px; Removed to allow inline flow */
}

.search-routes-inline {
    margin-left: 6px;
    display: inline-flex;
    gap: 4px;
    vertical-align: middle;
}

/* Force small badges in search */
.search-routes-inline .station-badge {
    font-size: 0.75rem !important;
    padding: 1px 4px !important;
    min-width: 18px !important;
    height: 18px !important;
    line-height: 1.2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: none !important;
    cursor: pointer;
    /* Inherit click */
}

/* Removed old .search-routes */

.no-results {
    color: #64748b;
    font-style: italic;
    cursor: default;
}

.no-results:hover {
    background: transparent;
}

#app {
    position: relative;
    height: 100%;
    width: 100%;
}

#map {
    height: 100%;
    width: 100%;
    z-index: 1;
    background: var(--bg-color);
}

/* Layer Fade Effects */
.leaflet-pane {
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.layer-hidden {
    opacity: 0 !important;
}

.layer-visible {
    opacity: 1 !important;
}

/* Sidebar - Glassmorphism */
.sidebar {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    left: 20px;
    width: 350px;
    max-height: calc(100vh - 40px);
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--sidebar-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    padding: 24px;
    transition: transform var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), opacity var(--transition-speed) ease;
    overflow-y: auto;
}

.sidebar.hidden {
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
}

#close-sidebar {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#close-sidebar:hover {
    opacity: 1;
}

/* Typography & Content */
h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.2;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.station-meta {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 24px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-color);
    display: block;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #cbd5e1;
    margin-top: 4px;
}

.ebike-highlight {
    color: #a3e635;
    /* Lime green for ebikes */
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.5s ease;
}

#loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Secondary Train Loader (Toast) */
.train-loader {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(56, 189, 248, 0.3);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 2000;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.train-loader.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -20px);
}

.mini-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.train-loader span {
    font-size: 0.85rem;
    font-weight: 500;
    color: #e2e8f0;
}

/* Leaflet Customizations */
/* Leaflet Controls (Zoom & Locate) Redesign */
.leaflet-bar {
    border: none !important;
    box-shadow: none !important;
}

.leaflet-bar a {
    background-color: var(--sidebar-bg) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--sidebar-border) !important;
    color: #fff !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    border-radius: 8px !important;
    margin-bottom: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease;
}

.leaflet-bar a:hover {
    background-color: rgba(56, 189, 248, 0.2) !important;
    border-color: var(--accent-color) !important;
    color: var(--accent-color) !important;
}

.leaflet-bar a.leaflet-disabled {
    opacity: 0.5;
    background-color: var(--sidebar-bg) !important;
    color: #888 !important;
}

/* Locate Icon Specifics */
.control-icon {
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.leaflet-control-locate:hover .control-icon {
    stroke: var(--accent-color);
}

/* Train Popup Styles */
.train-popup {
    min-width: 280px;
    font-family: var(--font-family);
}

.train-header {
    background: rgba(255, 255, 255, 0.02);
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    /* Align top if badges wrap */
}

.train-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.train-route-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.train-dest {
    padding: 16px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px 16px;
    align-items: center;
}

.train-info-label {
    font-size: 0.75em;
    color: #64748b;
    text-transform: uppercase;
    font-weight: 600;
}

.train-station-name {
    color: #f1f5f9;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.train-time {
    color: #fff;
    font-family: monospace;
    font-weight: 600;
    font-size: 1.0em;
}

.train-realtime-badge {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.5);
    color: #34d399;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 4px;
}

.blink-dot {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

/* Leaflet Customizations - General */
.leaflet-popup-content-wrapper {
    background: var(--sidebar-bg);
    /* Dark Glass */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--sidebar-border);
    color: var(--text-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    padding: 0;
    /* Remove default padding, handle in content */
}

.leaflet-popup-content {
    margin: 0;
    line-height: 1.4;
}

.leaflet-popup-tip {
    background: var(--sidebar-bg);
}

.leaflet-container a.leaflet-popup-close-button {
    color: #94a3b8;
    top: 12px;
    right: 12px;
    font: 20px/20px Tahoma, Verdana, sans-serif;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: #fff;
}

/* Station Popup Content */
.station-popup {
    min-width: 280px;
    font-family: var(--font-family);
}

.station-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.02);
}

.station-title {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #f1f5f9;
}

.station-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.station-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.8rem;
    display: inline-block;
    min-width: 24px;
    text-align: center;
}

/* Station Body: Unified Scroll Container */
.station-body {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    /* Unified scroll: Max height on body instead of lists */
    /* Only apply max-height if content is very long, or let Leaflet handle it? */
    /* User request: "Do not show scroll by default until load more is actioned" */
    /* We'll set a max-height but it won't trigger until expanded */
    max-height: 320px;
    overflow-y: auto;
}

/* Custom Scrollbar for Body */
.station-body::-webkit-scrollbar {
    width: 6px;
}

.station-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.station-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.station-scroll-list {
    /* Remove per-list scrolling */
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
    margin-right: 0;
}

.show-more-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    font-size: 0.75rem;
    padding: 6px;
    margin-top: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.show-more-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.hidden-train-row {
    display: none !important;
}

.departed-row {
    opacity: 0.4;
    font-style: italic;
    /* Make less prominent */
}

.status-departing {
    color: #f59e0b;
    /* Amber */
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

.dir-header {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #94a3b8;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    font-weight: 600;
}

.arrival-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.9em;
    flex-wrap: nowrap;
    /* Force single line */
}

.clickable-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
    padding: 4px 6px;
    margin: 0 -6px 6px -6px;
    /* Expand hit area without breaking layout */
    border-radius: 4px;
}

.clickable-row:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* Clickable station name in tooltip */
.station-link {
    cursor: pointer;
    text-decoration: none;
    color: #f1f5f9;
    border-bottom: 1px solid transparent;
    /* Reserve space */
    transition: all 0.2s;
    font-weight: 600;
}

.station-link:hover {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: transparent;
    /* Remove background on hover for cleaner look */
}

.arrival-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 1;
    /* Allow shrinking if absolutely needed, but prefer right side stable */
    white-space: nowrap;
    /* Prevent "Approaching" from breaking */
    overflow: hidden;
    text-overflow: ellipsis;
}

.arrival-right {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    /* Never shrink the time column */
    white-space: nowrap;
    /* Never wrap time */
    margin-left: 10px;
    /* Ensure gap */
}

.time-primary {
    color: #fff;
    font-weight: 600;
    font-family: monospace;
}

.status-badge {
    font-size: 0.75em;
    font-weight: 600;
}

.status-at-station {
    color: #ef4444;
    /* Red-500 */
}

.status-live {
    color: #22c55e;
    /* Green-500 */
}

.status-delayed {
    color: #f59e0b;
    /* Amber-500 */
}

.status-scheduled {
    color: #94a3b8;
    /* Slate-400 */
    font-style: italic;
    font-weight: 500;
}

.no-trains {
    color: #64748b;
    font-style: italic;
    font-size: 0.8em;
}

.leaflet-popup-tip {
    background: var(--bg-color);
}

.neighborhood-label {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: #fff;
    border-radius: 4px;
    font-size: 0.8rem;
    padding: 2px 6px;
    box-shadow: none;
}

.subway-label {
    background: #fff;
    color: #000;
    border: none;
    font-weight: bold;
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 2px;
}

/* Legend FAB (Floating Action Button) */
.legend-fab {
    position: absolute;
    bottom: 25px;
    right: 25px;
    width: 56px;
    height: 56px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--sidebar-border);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s;
    color: var(--text-color);
}

.legend-fab:hover {
    transform: scale(1.05);
    background: rgba(30, 41, 59, 0.9);
}

.legend-fab:active {
    transform: scale(0.95);
}

.legend-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Legend Panel (Responsive) */
.legend-panel {
    position: absolute;
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--sidebar-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.legend-panel.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Desktop: Floating Popover */
@media (min-width: 601px) {
    .legend-panel {
        bottom: 30px;
        right: 25px;
        width: 300px;
        max-height: 70vh;
        border-radius: 16px;
        transform: translateY(20px) scale(0.95);
        transform-origin: bottom right;
    }

    .legend-panel.visible {
        transform: translateY(0) scale(1);
    }
}

/* Mobile: Bottom Sheet */
@media (max-width: 600px) {
    .legend-fab {
        bottom: 20px;
        right: 20px;
    }

    .legend-panel {
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 85dvh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        border-left: none;
        border-right: none;
        transform: translateY(100%);
    }

    .legend-panel.visible {
        transform: translateY(0);
    }
}

.legend-header-row {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.legend-title-main {
    font-weight: 700;
    font-size: 1.1rem;
    color: #f1f5f9;
}

.legend-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

.legend-scroll-area {
    overflow-y: auto;
    padding: 16px 20px;
}

.legend-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #94a3b8;
    letter-spacing: 0.1em;
    font-weight: 600;
    margin-bottom: 12px;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-section-title:first-child {
    margin-top: 0;
}

/* Custom Checkbox Row */
.legend-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.legend-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex: 1;
    /* Clicks anywhere on text/checkbox */
}

.legend-checkbox {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid #475569;
    border-radius: 4px;
    margin-right: 12px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.legend-checkbox:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.legend-checkbox:checked::after {
    content: '✔';
    font-size: 12px;
    color: #000;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 10px;
    display: inline-block;
}

.route-text {
    font-weight: 500;
    font-size: 0.95rem;
    color: #e2e8f0;
}

/* Focus Button */
.btn-focus {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.2s;
    opacity: 0;
    /* Hidden by default until hover */
    transform: translateX(5px);
}

.legend-row:hover .btn-focus {
    opacity: 1;
    transform: translateX(0);
}

/* Always show focus button on mobile (no hover state) */
@media (max-width: 600px) {
    .btn-focus {
        opacity: 1;
        transform: none;
        padding: 6px 10px;
        /* Larger hit area */
        background: rgba(255, 255, 255, 0.05);
    }
}

.btn-focus:hover {
    background: rgba(56, 189, 248, 0.2);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Master Toggle Button */
.btn-master-toggle {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
}

/* User Location Pulse */
.user-location-pulse {
    position: relative;
}

.user-dot {
    width: 12px;
    height: 12px;
    background-color: #3b82f6;
    border: 2px solid white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}

.pulse-ring {
    width: 100%;
    height: 100%;
    background-color: rgba(59, 130, 246, 0.5);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.5);
        opacity: 1;
    }

    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* Status Panel (Console Look) */
.status-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;

    /* On mobile, move it away from edge or keep small */
    @media (max-width: 600px) {
        bottom: 15px;
        left: 15px;
    }

    width: 280px;
    background: rgba(10, 10, 15, 0.9);
    border: 1px solid #333;
    border-radius: 6px;
    font-family: 'Monaco',
    'Consolas',
    monospace;
    font-size: 12px;
    color: #0f0;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    overflow: hidden;
    transition: width 0.3s ease,
    height 0.3s ease,
    background 0.3s ease;
}

.status-panel.collapsed {
    width: 40px;
    height: 40px;
    background: rgba(10, 10, 15, 0.6);
    border-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.status-header {
    background: #1a1a1a;
    padding: 6px 10px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    /* Click header to toggle */
}

/* Hide title in collapsed mode if we only want the icon */
.status-panel.collapsed .status-header {
    display: none;
}

/* Start with content hidden if logical, but CSS class handles main shape */
.status-panel.collapsed .status-content {
    display: none;
}

/* The floating toggle button when collapsed */
.status-panel.collapsed::after {
    content: '>';
    color: #0f0;
    font-size: 18px;
    font-weight: bold;
}

.status-title {
    font-weight: bold;
    color: #fff;
}

.status-toggle {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
}

.status-content {
    padding: 10px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.status-key {
    color: #666;
}

.status-value {
    color: #0f0;
    font-weight: bold;
}

.status-separator {
    color: #333;
    margin: 6px 0;
    text-align: center;
    letter-spacing: 2px;
}

.status-log {
    margin-top: 10px;
    height: 80px;
    overflow-y: auto;
    border-top: 1px dotted #333;
    padding-top: 6px;
    font-size: 11px;
    color: #888;
}

.status-log-line {
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Scrollbar for log */
.status-log::-webkit-scrollbar {
    width: 4px;
}

.status-log::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}

/* Realtime Error Banner */
.rt-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #ef4444;
    /* Red-500 */
    color: white;
    text-align: center;
    padding: 12px;
    font-weight: 600;
    font-family: var(--font-family);
    z-index: 3000;
    /* Above everything */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}

/* Push map content down when banner is visible */
body.rt-error .leaflet-control-container .leaflet-top {
    top: 50px;
    transition: top 0.3s ease;
}

/* Alerts Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 4000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 16px;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #f1f5f9;
}

#close-alerts {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 16px;
    overflow-y: auto;
}

.alert-item {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.alert-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.alert-routes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.route-badge {
    background: #334155;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.8rem;
}

.badge-A,
.badge-C,
.badge-E {
    background: #0062CF;
}

.badge-B,
.badge-D,
.badge-F,
.badge-M {
    background: #EB6800;
}

.badge-1,
.badge-2,
.badge-3 {
    background: #EE352E;
}

.badge-4,
.badge-5,
.badge-6 {
    background: #00933C;
}

.badge-N,
.badge-Q,
.badge-R,
.badge-W {
    background: #FCCC0A;
    color: black;
}

.badge-7 {
    background: #B933AD;
}

.badge-L {
    background: #A7A9AC;
    color: black;
}

.badge-G {
    background: #6CBE45;
}

.badge-J,
.badge-Z {
    background: #996633;
}

.alert-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #fca5a5;
    line-height: 1.3;
}

/* Train Tooltip Overhaul */
.train-dest-large {
    font-size: 0.9em;
    color: #e2e8f0;
    font-weight: 500;
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.train-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 10px 0;
    position: relative;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
    /* Space for scrollbar */
}

/* Vertical Line connecting dots */
.train-timeline::before {
    content: '';
    position: absolute;
    left: 9px;
    /* Centered on dots */
    top: 10px;
    bottom: 10px;
    width: 2px;
    background: rgba(255, 255, 255, 0.1);
    z-index: 0;
}

.train-stop-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
    /* Above timeline line */
}

.train-stop-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.stop-past {
    opacity: 0.5;
}

.stop-next {
    background: rgba(255, 255, 255, 0.08);
    /* Highlight next stop */
}

.train-stop-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    overflow: hidden;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid #555;
    background: #000;
    flex-shrink: 0;
    transition: all 0.2s;
}

.stop-next .timeline-dot {
    width: 12px;
    height: 12px;
    border-width: 2px;
    /* Color set inline */
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.train-stop-name {
    color: #f1f5f9;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.train-stop-time {
    font-family: monospace;
    font-size: 0.9em;
    color: #94a3b8;
    margin-left: 8px;
    flex-shrink: 0;
}

.stop-next .train-stop-time {
    color: #fff;
    font-weight: 600;
}

/* Scrollbar tweaks for timeline */
.train-timeline::-webkit-scrollbar {
    width: 4px;
}

.train-timeline::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 2px;
}

.alert-desc {
    font-size: 0.9rem;
    color: #cbd5e1;
    line-height: 1.5;
}

/* Train footer tweaks */
.train-footer {
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85em;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
}

/* Geolocation Animations */
.animate-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.location-pulse {
    animation: location-pulse 2s ease-out infinite;
    transform-origin: center;
}

@keyframes location-pulse {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    100% {
        transform: scale(3.5);
        opacity: 0;
    }
}

/* Train Hover Tooltips */
.train-label {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    white-space: nowrap;
    z-index: 10000 !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
}

.train-label::before {
    display: none;
    /* Hide default arrow */
}

/* Enhanced Map Labels (Trains & Stations) */
.train-label {
    background: rgba(15, 23, 42, 0.9) !important;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
    padding: 0 !important;
    /* Managed by content div */
    overflow: hidden;
}

.train-label-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
}

.train-label .route-badge {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.train-label .dest-text,
.station-hover-label {
    color: white !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.station-hover-label {
    padding: 4px 10px !important;
}

.leaflet-tooltip-top.train-label::before {
    border-top-color: rgba(15, 23, 42, 0.9) !important;
}

/* Hide default subway-label if any left */
.subway-label {
    display: none !important;
}

/* --- Legend Polish (Button Colors & Layout) --- */

.btn-master-toggle {
    background: transparent;
    border: none;
    /* Muted default color */
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-master-toggle:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

/* Specific override for the "Hide Tracks" button to be less neon */


/* Fix Header Layout Shift */
.legend-section-title {
    /* Ensure flex items don't jump around */
    min-height: 24px;
}

/* --- Round 2 Polish (Dimensions & Layout) --- */

@media (min-width: 601px) {
    .legend-panel {
        /* Increase vertical height to avoid scroll */
        max-height: 90vh;
    }
}

/* Smaller Master Toggle Buttons */
.btn-master-toggle {
    font-size: 0.65rem;
    /* Smaller font */
    padding: 2px 6px;
    /* Tighter padding */
    letter-spacing: 0.05em;
}

/* Header Single Line Fix */
.legend-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    /* Force single line */
    gap: 8px;
    flex-wrap: nowrap;
}

.legend-section-title>div {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- FAB Visibility Logic --- */
.legend-fab {
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    pointer-events: auto;
}

.legend-fab.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* Update Banner */
.update-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(16, 185, 129, 0.95);
    /* Green-500 */
    color: white;
    padding: 12px 24px;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    display: none;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
    animation: slideUp 0.3s ease-out;
}

.update-banner button {
    background: white;
    color: #059669;
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.8rem;
    transition: transform 0.1s;
}

.update-banner button:active {
    transform: scale(0.95);
}

to {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* Debug Control Icon */
.leaflet-control-debug {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: monospace;
    width: 30px;
    /* Standard Leaflet dimension */
    height: 30px;
    text-decoration: none !important;
    background-color: #fff;
    /* Ensure white background so it's visible on dark map */
    color: #000;
    font-weight: bold;
    font-size: 14px;
    border-radius: 2px;
    /* Match standard leaflet radius */
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    z-index: 1000;
    /* Ensure visibility */
}

/* Status Panel Position Update */
.status-panel {
    bottom: 90px !important;
    /* Above controls (30+30+30 approx + margins) */
    left: 10px !important;
}

/* Fix Overlay Icon Spacing (FAB) - Reduced */
/* Fix Overlay Icon Spacing (FAB) - Tighten to border */
.legend-fab {
    margin-right: -5px !important;
    /* Force it right to edge */
    margin-bottom: 25px;
}

/* Adjust Left Controls Spacing - Reduced */
.leaflet-left .leaflet-control {
    margin-left: 10px;
}

.leaflet-bottom .leaflet-control {
    margin-bottom: 10px;
}

/* Fix Overlay Icon Spacing (FAB) */
.legend-fab {
    margin-right: 15px;
    /* Add more space from right edge */
    margin-bottom: 15px;
    /* Add more space from bottom edge */
}

/* Adjust Left Controls Spacing if needed */
.leaflet-left .leaflet-control {
    margin-left: 15px;
    /* More space from left edge */
}

.leaflet-bottom .leaflet-control {
    margin-bottom: 15px;
}

/* Fix overlap in Train Popup specifically */
.train-realtime-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid;
    margin-right: 35px !important;
    /* Increased to clear the Close button */
    white-space: nowrap;
}

.blink-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: blink 1.5s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}