:root {
    /* SBB Core Colors */
    --sbb-red: #EB0000;
    --sbb-red-dark: #C60000;
    --sbb-black: #000000;
    --sbb-anthracite: #444444;
    --sbb-grey: #686868;
    --sbb-cloud: #DCDCDC;
    --sbb-milk: #FFFFFF;
    
    /* Semantic Colors */
    --color-success: #008A27;  /* SBB Green */
    --color-info: #006FB4;     /* SBB Blue */
    --color-warning: #FFC000;  /* SBB Yellow */
    --color-danger: #EB0000;   /* SBB Red */
    
    /* UI Structure */
    --bg-main: #F6F6F6;
    --bg-card: #FFFFFF;
    --bg-sidebar: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #444444;
    --text-muted: #686868;
    --border-color: #DCDCDC;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.12);
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    background-color: var(--sbb-red);
    color: white;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 1px;
    padding: 6px 10px;
    border-radius: 4px;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.nav-links {
    list-style: none;
    padding: 24px 12px;
    flex-grow: 1;
}

.nav-item {
    margin-bottom: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background-color: var(--bg-main);
    color: var(--sbb-red);
}

.nav-link.active {
    background-color: rgba(235, 0, 0, 0.08);
    color: var(--sbb-red);
}

.sidebar-footer {
    padding: 24px 20px;
    border-top: 1px solid var(--border-color);
}

.route-selector label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.route-selector select {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 20px;
    cursor: pointer;
}

.route-selector select:focus {
    outline: none;
    border-color: var(--sbb-red);
}

.system-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(0, 138, 39, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 138, 39, 0.4); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(0, 138, 39, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 138, 39, 0); }
}

/* Main Content */
.main-content {
    flex-grow: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 72px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 90;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.route-subtitle {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
    border-left: 1px solid var(--border-color);
    padding-left: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.content-wrapper {
    padding: 32px;
    flex-grow: 1;
}

/* Grid System */
.grid {
    display: grid;
    gap: 24px;
}

.cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    margin-bottom: 24px;
}

.dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
}

.span-2 {
    grid-column: span 2;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

.card-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.card-body {
    padding: 24px;
}

/* KPI Cards */
.kpi-card {
    display: flex;
    align-items: center;
    padding: 24px;
    gap: 20px;
}

.kpi-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-main);
}

.kpi-content {
    flex-grow: 1;
}

.kpi-label {
    font-size: 13px;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.kpi-subtext {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Containers for visual libs */
.map-view {
    height: 400px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.plotly-view {
    height: 350px;
    width: 100%;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--sbb-red);
    color: white;
}

.btn-primary:hover {
    background-color: var(--sbb-red-dark);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--sbb-red);
    color: var(--sbb-red);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

/* Forms */
.modern-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-flex {
    display: flex;
    gap: 20px;
}

.flex-1 {
    flex: 1;
}

.modern-form label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.custom-select select {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23444444%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat, repeat;
    background-position: right .7em top 50%, 0 0;
    background-size: .65em auto, 100%;
}

.custom-select select:focus {
    outline: none;
    border-color: var(--sbb-red);
    box-shadow: 0 0 0 3px rgba(235, 0, 0, 0.1);
}

/* Prediction Results */
.predictions-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 1000px;
    margin: 0 auto;
}

.result-header {
    text-align: center;
    margin-bottom: 32px;
}

.result-badge {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    color: white;
}

.confidence-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.conf-bar-container {
    width: 200px;
    height: 8px;
    background-color: var(--bg-main);
    border-radius: 4px;
    overflow: hidden;
}

.conf-bar {
    height: 100%;
    background-color: var(--color-info);
    border-radius: 4px;
    transition: width 0.5s ease-out;
}

.conf-text {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.prob-breakdown {
    background-color: var(--bg-main);
    padding: 24px;
    border-radius: var(--radius-md);
}

.breakdown-title {
    font-size: 14px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-weight: 600;
}

.prob-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.prob-row:last-child {
    margin-bottom: 0;
}

.prob-label {
    width: 140px;
    font-size: 14px;
    color: var(--text-secondary);
}

.prob-track {
    flex-grow: 1;
    height: 8px;
    background-color: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}

.prob-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease-out;
}

.prob-value {
    width: 40px;
    text-align: right;
    font-weight: 600;
    font-size: 14px;
}

/* Utility Colors */
.text-success { color: var(--color-success) !important; }
.text-info { color: var(--color-info) !important; }
.text-warning { color: var(--color-warning) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-muted { color: var(--text-muted) !important; }

.bg-success { background-color: var(--color-success) !important; }
.bg-info { background-color: var(--color-info) !important; }
.bg-warning { background-color: var(--color-warning) !important; }
.bg-danger { background-color: var(--color-danger) !important; }

.mt-4 { margin-top: 24px; }
.text-sm { font-size: 12px; }

/* Map custom styles */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 4px;
}
.leaflet-popup-content {
    margin: 8px 12px;
    font-family: var(--font-family);
}
.leaflet-popup-content h4 {
    margin: 0 0 4px 0;
    font-size: 14px;
    color: #444;
}
.leaflet-popup-content p {
    margin: 0;
    font-size: 13px;
    color: #686868;
}

/* ═══════════════════════════════════════════════════════════════
   COMMUTER PAGE COMPONENTS
   ═══════════════════════════════════════════════════════════════ */

/* Setup card */
.commute-setup {
    max-width: 520px;
    margin: 0 auto;
}

.setup-card {
    padding: 32px;
}

.setup-header {
    margin-bottom: 24px;
}

.setup-header h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.station-picker {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.station-picker .form-group {
    flex: 1;
}

.swap-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-bottom: 0;
}

.swap-btn:hover {
    border-color: var(--sbb-red);
    color: var(--sbb-red);
    background: rgba(235, 0, 0, 0.05);
}

/* Route header */
.commute-route-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.route-display {
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.route-arrow {
    color: var(--text-muted);
    font-weight: 400;
}

.route-actions {
    display: flex;
    gap: 8px;
}

/* Status card — "Am I fucked?" meter */
.status-card {
    text-align: center;
    padding: 32px 24px;
    margin-bottom: 20px;
    border-radius: var(--radius-lg);
    transition: all 0.4s ease;
}

.status-card:hover {
    transform: none;
}

.status-emoji {
    font-size: 48px;
    margin-bottom: 12px;
    line-height: 1;
}

.status-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 6px;
}

.status-subtitle {
    font-size: 15px;
    color: var(--text-muted);
}

.status-loading {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.status-ok {
    background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
    border: 1px solid #A5D6A7;
}

.status-ok .status-title { color: #2E7D32; }

.status-warn {
    background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    border: 1px solid #FFD54F;
}

.status-warn .status-title { color: #F57F17; }

.status-bad {
    background: linear-gradient(135deg, #FFEBEE 0%, #FFCDD2 100%);
    border: 1px solid #EF9A9A;
}

.status-bad .status-title { color: #C62828; }

.status-neutral {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

/* Departures card */
.departures-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.live-badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--color-success);
    background: rgba(0, 138, 39, 0.1);
    padding: 4px 10px;
    border-radius: 50px;
    animation: pulse 2s infinite;
}

.departure-row {
    display: flex;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
}

.departure-row:last-child {
    border-bottom: none;
}

.dep-times {
    width: 90px;
    flex-shrink: 0;
}

.dep-time-main {
    font-size: 18px;
    font-weight: 700;
    display: block;
    line-height: 1.2;
}

.dep-time-arr {
    font-size: 13px;
    color: var(--text-muted);
}

.dep-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.dep-line {
    font-weight: 600;
    font-size: 14px;
    background: var(--bg-main);
    padding: 2px 8px;
    border-radius: 4px;
}

.dep-platform {
    font-size: 13px;
    color: var(--text-muted);
}

.dep-transfers {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-main);
    padding: 2px 6px;
    border-radius: 4px;
}

.dep-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.dep-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 50px;
    white-space: nowrap;
}

.badge-green {
    background: #E8F5E9;
    color: #2E7D32;
}

.badge-yellow {
    background: #FFF8E1;
    color: #F57F17;
}

.badge-orange {
    background: #FFF3E0;
    color: #E65100;
}

.badge-red {
    background: #FFEBEE;
    color: #C62828;
}

.badge-green-subtle {
    background: rgba(0, 138, 39, 0.08);
    color: #2E7D32;
}

.badge-yellow-subtle {
    background: rgba(255, 192, 0, 0.15);
    color: #F57F17;
}

.badge-red-subtle {
    background: rgba(235, 0, 0, 0.08);
    color: #C62828;
}

.badge-loading {
    background: var(--bg-main);
    color: var(--text-muted);
}

/* Outlook card */
.outlook-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    text-align: center;
}

.outlook-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.outlook-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.outlook-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.outlook-footnote {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* Page links */
.page-links {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 20px;
}

.page-link-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
}

.page-link-card:hover {
    border-color: var(--sbb-red);
}

.page-link-icon {
    font-size: 24px;
}

.page-link-text {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.page-link-arrow {
    color: var(--text-muted);
    font-size: 18px;
}

/* Utility */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 14px;
}

.loading-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 14px;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAV (mobile)
   ═══════════════════════════════════════════════════════════════ */

.bottom-nav {
    display: none; /* hidden on desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    z-index: 200;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.bottom-nav-item.active {
    color: var(--sbb-red);
}

.bottom-nav-item:hover {
    color: var(--sbb-red);
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .span-2 {
        grid-column: span 1;
    }
    .predictions-grid {
        grid-template-columns: 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Hide sidebar, show bottom nav */
    .sidebar {
        display: none;
    }

    .bottom-nav {
        display: flex;
    }

    .main-content {
        margin-left: 0;
    }

    /* Adjust content for bottom nav safe area */
    .content-wrapper {
        padding: 16px;
        padding-bottom: 80px; /* space for bottom nav */
    }

    /* Topbar adjustments */
    .topbar {
        padding: 0 16px;
        height: 56px;
    }

    .page-title {
        font-size: 16px;
    }

    .route-subtitle {
        display: none; /* hide on mobile, too long */
    }

    /* KPI cards stack to 2 columns */
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .kpi-card {
        padding: 16px;
        gap: 12px;
    }

    .kpi-icon {
        width: 40px;
        height: 40px;
        border-radius: 8px;
    }

    .kpi-icon svg {
        width: 18px;
        height: 18px;
    }

    .kpi-value {
        font-size: 20px;
    }

    .kpi-label {
        font-size: 11px;
    }

    /* Charts full width */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .map-view {
        height: 280px;
    }

    .plotly-view {
        height: 250px;
    }

    /* Commute page */
    .commute-route-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .route-display {
        font-size: 18px;
    }

    .status-card {
        padding: 24px 16px;
    }

    .status-emoji {
        font-size: 40px;
    }

    .status-title {
        font-size: 20px;
    }

    .departure-row {
        padding: 12px 0;
        gap: 10px;
    }

    .dep-times {
        width: 75px;
    }

    .dep-time-main {
        font-size: 16px;
    }

    .outlook-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .outlook-value {
        font-size: 20px;
    }

    .page-links {
        grid-template-columns: 1fr;
    }

    .station-picker {
        flex-direction: column;
        align-items: stretch;
    }

    .swap-btn {
        align-self: center;
        transform: rotate(90deg);
    }

    /* Predictions form */
    .form-flex {
        flex-direction: column;
    }
}
