:root {
    --bg: #09090B;
    --surface: #141417;
    --surface-elevated: #1E1E22;
    --border: #2C2C32;
    --text: #F4F4F5;
    --text-muted: #A1A1AA;
    --accent: #E4E4E7;
    --accent-hover: #FFFFFF;
    --due-bg: #10B981;
    --due-text: #04291E;
    --delay-bg: #EF4444;
    --delay-text: #FFFFFF;
    --warning-bg: rgba(245, 158, 11, 0.14);
    --warning-border: rgba(245, 158, 11, 0.45);
    --error-bg: rgba(239, 68, 68, 0.14);
    --error-border: rgba(239, 68, 68, 0.45);
    --radius: 14px;
    --radius-sm: 10px;
    --header-height: 62px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--header-height);
    background: rgba(9, 9, 11, 0.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.brand-icon {
    border-radius: 7px;
}

.brand-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    margin: 0;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1rem 1rem calc(5.75rem + env(safe-area-inset-bottom, 0px));
}

.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
    color: var(--text);
    background: var(--surface-elevated);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
}

.btn-primary {
    background: var(--accent);
    color: #09090B;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-elevated);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--accent);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--text-muted);
}

/* Sticky route controls */
.sticky-controls {
    position: sticky;
    top: var(--header-height);
    z-index: 20;
    background: var(--bg);
    padding: 0.25rem 0 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.search-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.search-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    color: var(--text);
    font-size: 0.95rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
}

.selection-summary {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* Route selection lists */
.routes-sections {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.7rem;
}

.group-header h2 {
    margin: 0;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.count-pill {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.12rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

.route-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.55rem;
}

.route-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-width: 0;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.75rem;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
    min-height: 48px;
}

.route-item:hover {
    border-color: var(--accent);
}

.route-item.selected {
    background: #222228;
    border-color: #D4D4D8;
    box-shadow: inset 0 0 0 1px #D4D4D8;
}

.route-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 0.25rem 0.45rem;
    border-radius: 7px;
    font-weight: 800;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
    flex-shrink: 0;
}

.route-name {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.25;
}

.route-check {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 800;
    flex-shrink: 0;
}

.route-item.selected .route-check {
    background: #F4F4F5;
    border-color: #F4F4F5;
    color: #09090B;
}

/* Board view */
.location-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.75rem;
}

.location-status {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.location-status > div {
    min-width: 0;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #F59E0B;
    flex-shrink: 0;
}

.status-dot.ready {
    background: #10B981;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18);
}

.status-dot.low-quality {
    background: #F59E0B;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22);
}

.status-dot.error {
    background: #EF4444;
}

.location-title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.location-title {
    font-size: 0.92rem;
    font-weight: 700;
}

.location-staleness {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.48rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.location-staleness.stale {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.14);
    color: #FCA5A5;
}

.location-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    word-break: break-word;
}

.selected-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.9rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.08s ease, background 0.15s ease;
}

.chip:active {
    transform: scale(0.96);
}

.chip.chip-hidden {
    background: var(--surface) !important;
    color: var(--text-muted) !important;
    border-color: var(--border);
    opacity: 0.6;
    text-decoration: line-through;
}

.chip-bulk-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.chip-action {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.24rem 0.55rem;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.chip-action:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--text);
}

.chip-action:disabled {
    opacity: 0.4;
    cursor: default;
}

.board-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    pointer-events: none;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
}

.board-footer-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: rgba(20, 20, 23, 0.94);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.45rem 0.5rem 0.45rem 0.85rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
}

.freshness-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 0;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.freshness-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.freshness-pill.fresh .freshness-dot {
    background: #10B981;
}

.freshness-pill.aging {
    border-color: rgba(245, 158, 11, 0.45);
    background: rgba(245, 158, 11, 0.1);
    color: #FCD34D;
}

.freshness-pill.aging .freshness-dot {
    background: #F59E0B;
}

.freshness-pill.stale {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.14);
    color: #FCA5A5;
}

.freshness-pill.stale .freshness-dot {
    background: #EF4444;
}

.freshness-pill.refreshing .freshness-dot {
    animation: pulse-dot 1s ease-in-out infinite;
}

.btn-refresh-fab {
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    flex-shrink: 0;
}

.refresh-icon {
    display: inline-block;
    font-size: 1rem;
    line-height: 1;
}

.btn-refresh-fab.is-refreshing .refresh-icon {
    animation: spin 0.8s linear infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.stops-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    transition: opacity 0.2s ease;
}

.stops-list.is-stale {
    opacity: 0.72;
}

.stop-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.stop-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.45rem 0.75rem;
    padding: 0.8rem 1rem;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border);
}

.stop-title-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.55rem;
    min-width: 0;
}

.stop-type-badge {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.14rem 0.52rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.stop-route-pill {
    padding: 0.25rem 0.5rem;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 800;
    flex-shrink: 0;
}

.stop-name {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.25;
}

.stop-meta {
    margin: 0.2rem 0 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.track-section {
    border-top: 1px solid var(--border);
}

.track-section:first-of-type {
    border-top: none;
}

.track-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 1rem;
    background: #18181C;
    border-bottom: 1px solid rgba(63, 63, 70, 0.55);
}

.track-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #D4D4D8;
}

.track-dir-tag {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    white-space: nowrap;
}

.track-routes {
    display: flex;
    flex-direction: column;
}

.route-subcard {
    border-left: 3px solid #3B82F6;
    border-top: 1px solid rgba(63, 63, 70, 0.5);
    padding-top: 0.25rem;
}

.route-subcard:first-child {
    border-top: none;
}

.route-subcard-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem 0.25rem 0.85rem;
}

.route-subcard-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
}

.stop-header-badges {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
    gap: 0.4rem;
}

.distance-badge {
    background: #27272A;
    border: 1px solid #3F3F46;
    color: #E4E4E7;
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.arrivals-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.arrival-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid rgba(63, 63, 70, 0.55);
}

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

.arrival-dest {
    font-size: 0.94rem;
    font-weight: 600;
}

.arrival-sub {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.45rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.tag {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 5px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.tag-scheduled {
    background: rgba(161, 161, 170, 0.16);
    color: var(--text-muted);
}

.tag-delayed {
    background: var(--delay-bg);
    color: var(--delay-text);
}

.eta-pill {
    min-width: 68px;
    text-align: center;
    padding: 0.32rem 0.6rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 800;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.eta-pill.due {
    background: var(--due-bg);
    color: var(--due-text);
    border-color: var(--due-bg);
}

.eta-pill.delayed {
    background: var(--delay-bg);
    color: var(--delay-text);
    border-color: var(--delay-bg);
}

.no-arrivals {
    padding: 0.85rem 1rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.stop-error {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: #FCA5A5;
    background: var(--error-bg);
}

/* Alerts & Loading */
.alert {
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    margin-bottom: 0.9rem;
    font-size: 0.9rem;
}

.alert p {
    margin: 0 0 0.55rem;
}

.alert-warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: #FECACA;
}

.fallback-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.loading-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    gap: 0.75rem;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

.toast {
    position: fixed;
    bottom: 5.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: #27272A;
    color: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.55rem 1.1rem;
    font-size: 0.86rem;
    font-weight: 600;
    z-index: 50;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.consent-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.consent-banner-inner {
    pointer-events: auto;
    width: 100%;
    max-width: 640px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.consent-text {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.45;
    flex: 1 1 240px;
}

.consent-text a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.consent-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.cta-attribution {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin: 1.25rem 0 0;
    opacity: 0.8;
}

.brand-link {
    color: inherit;
    text-decoration: none;
}

.legal-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0.45rem 0 0;
    opacity: 0.85;
}

.legal-links a,
.legal-card a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.legal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.35rem;
    line-height: 1.6;
}

.legal-card h2 {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
}

.legal-meta {
    margin: 0 0 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legal-card h3 {
    margin: 1.25rem 0 0.4rem;
    font-size: 1rem;
}

.legal-card p,
.legal-card ul {
    margin: 0 0 0.75rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.legal-card ul {
    padding-left: 1.25rem;
}

.legal-card li + li {
    margin-top: 0.4rem;
}

.legal-card strong,
.legal-card code {
    color: var(--text);
}

@media (max-width: 720px) {
    .header-inner {
        padding: 0.65rem 0.85rem;
    }

    .header-actions {
        flex-wrap: nowrap;
    }

    .sticky-controls {
        top: var(--header-height);
    }

    .selection-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .route-grid {
        grid-template-columns: 1fr;
    }
}
