/* Base Styles & Resets */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./assets/fonts/inter-latin-400-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('./assets/fonts/inter-latin-500-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('./assets/fonts/inter-latin-600-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('./assets/fonts/inter-latin-700-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url('./assets/fonts/inter-latin-800-normal.woff2') format('woff2');
}

:root {
    --transit-blue: #357ABD;
    --transit-dark-blue: #2a6198;
    --bg-color: #ffffff;
    --bg-secondary: #f7f9fa;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --border-color: #e5e5ea;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.16);

    /* Desktop Panel */
    --panel-width: 380px;

    /* Mobile Bottom Sheet */
    --sheet-peek-height: 80px;
    --sheet-full-height: 85dvh;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    /* Prevent scrolling on main body */
    height: 100vh;
    width: 100vw;
}

.app-container {
    position: relative;
    height: 100%;
    width: 100%;
}

/* Map Container */
.map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #F7F7F5;
    /* Target muted background */
}

#map {
    width: 100%;
    height: 100%;
}

/* UI Panel (Responsive) */
.ui-panel {
    position: absolute;
    background: var(--bg-color);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background-color: var(--transit-blue);
    color: white;
    border-radius: inherit;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-text {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background-color 0.2s, transform 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.05);
}

.header-btn.loading {
    opacity: 0.6;
    pointer-events: none;
    animation: spin 1s linear infinite;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: #666;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    z-index: 10;
}

.close-btn:hover {
    color: #333;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 24px;
}

.section-title {
    font-size: 13px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

/* Route State Details */
.route-header {
    display: flex;
    align-items: center;
    margin-bottom: 32px;
    padding-right: 40px;
}

.route-badge {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 22px;
    margin-right: 16px;
    flex-shrink: 0;
}

.route-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.route-name {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
}

.route-dest {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Timeline Stop List */
.stop-list {
    list-style: none;
    position: relative;
    padding-left: 20px;
}

.stop-list::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 23px;
    width: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
}

.stop-list li {
    position: relative;
    padding: 16px 0 16px 24px;
    display: flex;
    align-items: center;
}

.stop-dot {
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background: white;
    border: 4px solid;
    border-radius: 50%;
    z-index: 2;
}

.stop-name {
    font-size: 15px;
    font-weight: 500;
}

.route-stop-button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.route-stop-button:focus-visible,
.route-service-button:focus-visible {
    outline: 3px solid var(--transit-blue);
    outline-offset: 2px;
}

.small-route-badge.route-service-button {
    min-width: 44px;
    min-height: 44px;
    width: auto;
    height: auto;
    padding: 0 6px;
    border: 0;
    font: inherit;
    cursor: pointer;
}

/* --- Media Queries for Responsive Layout --- */

/* Desktop (Sidebar) */
@media (min-width: 769px) {
    .ui-panel {
        top: 24px;
        left: 24px;
        width: var(--panel-width);
        background: transparent;
        box-shadow: none;
        filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.12));

        display: flex;
        flex-direction: column;
    }

    .panel-header {
        border-radius: 16px !important;
        box-shadow: none !important;
        position: relative;
        z-index: 2;
    }

    .panel-content {
        background: var(--bg-color);
        box-shadow: none !important;
        border-radius: 16px;
        margin-top: 12px;
        position: relative;
        z-index: 1;
        max-height: calc(100dvh - 48px - 76px);
        padding-bottom: env(safe-area-inset-bottom);
        transition: visibility 0s 0.35s, opacity 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .ui-panel:not(.visible) .panel-content {
        visibility: hidden;
        opacity: 0;
        transform: translateX(-20px);
        pointer-events: none;
    }

    .ui-panel.visible .panel-content {
        visibility: visible;
        opacity: 1;
        transform: translateX(0);
        transition: visibility 0s 0s, opacity 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .panel-handle {
        display: none;
    }
}

/* Mobile (Bottom Sheet) */
@media (max-width: 768px) {
    .ui-panel {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: var(--sheet-full-height);
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        transform: translateY(calc(100% - var(--sheet-peek-height)));
    }

    .ui-panel:not(.visible) {
        --sheet-peek-height: 0px;
    }

    .ui-panel:not(.visible) .panel-handle {
        display: none;
    }

    .ui-panel.expanded {
        transform: translateY(0);
    }

    .panel-handle {
        width: 100%;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: 0;
        font: inherit;
        cursor: grab;
        touch-action: none;
        user-select: none;
        background-color: var(--transit-blue);
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
    }

    .panel-handle:active {
        cursor: grabbing;
    }

    .panel-handle:focus-visible {
        outline: 3px solid #ffffff;
        outline-offset: -5px;
    }

    .panel-handle::after {
        content: '';
        width: 40px;
        height: 5px;
        background-color: rgba(255, 255, 255, 0.5);
        border-radius: 3px;
    }

    .panel-header {
        border-radius: 0;
        padding-top: 8px;
    }
}

.selected-stop-marker {
    width: 42px;
    height: 56px;
    display: block;
    pointer-events: none; /* Let clicks pass through */
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Stop State Details */
.stop-state-header {
    margin-bottom: 24px;
    padding-right: 40px;
}

.stop-name-title {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stop-section {
    margin-bottom: 24px;
}

.routes-badges-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.small-route-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 14px;
}

.departures-list {
    list-style: none;
}

.is-hidden {
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.noscript-warning {
    padding: 20px;
    background: #ef4444;
    color: #fff;
    text-align: center;
    font-family: sans-serif;
}

.stop-actions-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.stop-favorite-btn {
    padding: 4px;
    margin-left: 0;
}

.close-panel-icon {
    display: block;
}

.no-routes-message,
.no-search-results {
    color: var(--text-secondary);
    font-size: 14px;
    cursor: default;
}

.departure-live-icon,
.search-icon {
    flex-shrink: 0;
}

.departure-live-icon {
    width: 14px;
    height: 14px;
    margin-left: 6px;
    vertical-align: middle;
    fill: #357abd;
}

.departure-route-badge {
    flex-shrink: 0;
}

.departures-status,
.departure-empty {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.45;
    padding: 6px 12px;
}

.departures-status:empty {
    display: none;
}

.departure-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
}

.departure-route {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    padding-right: 12px;
}

.departure-headsign {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.departure-time-info {
    text-align: right;
    flex-shrink: 0;
}

.departure-time {
    font-size: 16px;
    font-weight: 700;
}

.departure-eta {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.2;
    margin: 2px 0 2px 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.departure-scheduled-strikethrough {
    text-decoration: line-through;
    color: var(--text-secondary);
    opacity: 0.65;
    font-weight: 500;
    font-size: 12px;
}

.departure-eta-live {
    font-weight: 600;
}

.departure-status {
    font-size: 12px;
    font-weight: 600;
}

.status-ontime {
    color: #28a745;
}

.status-delayed {
    color: #dc3545;
}

.status-scheduled {
    color: var(--text-secondary);
}

.loading-departures {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

/* Top Controls & Search */
.top-controls {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2000;
    width: 90%;
    max-width: 400px;
}

@media (min-width: 769px) and (max-width: 1250px) {
    .top-controls {
        left: calc(var(--panel-width) + 48px);
        transform: none;
        width: calc(100% - var(--panel-width) - 72px);
    }
}

.search-container {
    flex: 1;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 14px 20px;
    border-radius: 28px;
    border: none;
    box-shadow: var(--shadow-md);
    font-size: 16px;
    outline: none;
    transition: box-shadow 0.2s;
}

#search-input:focus {
    box-shadow: var(--shadow-lg);
}

.search-results {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-height: 350px;
    overflow-y: auto;
    z-index: 2001;
}

.search-result-item {
    width: 100%;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus-visible {
    background-color: var(--bg-secondary);
}

.search-result-item:focus-visible {
    outline: 3px solid var(--transit-blue);
    outline-offset: -3px;
}

.search-result-item .route-badge, 
.search-result-item .small-route-badge {
    flex-shrink: 0;
}

.search-result-title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-result-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Locate Me Floating Action Button */
.fab-locate {
    /* Updated for top-controls flex layout */
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    background-color: var(--transit-blue);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s, opacity 0.3s, visibility 0.3s;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.fab-locate:hover {
    background-color: var(--transit-dark-blue);
    transform: scale(1.05);
}

.fab-locate.loading {
    opacity: 0.7;
    pointer-events: none;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); opacity: 0.8; }
    100% { transform: scale(1); }
}

/* Hide the native mapbox locate button since we use a custom one */
.maplibregl-ctrl-geolocate {
    display: none !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .top-controls {
        top: 16px;
        width: calc(100% - 32px);
    }
}

/* Custom Map Attribution */
.map-attribution {
    position: absolute;
    bottom: 5px;
    left: 5px;
    font-size: 10px;
    color: #555;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 2px 6px;
    border-radius: 3px;
    z-index: 10;
    pointer-events: auto;
}

.map-attribution a {
    color: var(--transit-blue);
    text-decoration: none;
}

.map-attribution a:hover {
    text-decoration: underline;
}

/* Offline Banner */
.offline-banner {
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    background-color: #f59e0b;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.search-result-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

body.network-notice-visible .top-controls {
    top: calc(64px + env(safe-area-inset-top, 0px));
}

.fab-locate.active {
    background-color: #ffffff;
    color: var(--transit-blue);
    outline: 2px solid var(--transit-blue);
}

.location-notice {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    padding: 12px 16px;
    border-radius: 12px;
    background: #fff;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    font-size: 14px;
    line-height: 1.4;
}

.location-notice[hidden] {
    display: none;
}

.user-location-marker {
    width: 20px;
    height: 20px;
    border: 3px solid #fff;
    border-radius: 50%;
    background: #2878ff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.static-data-error {
    position: fixed;
    top: 48px;
    left: 12px;
    right: 12px;
    z-index: 10000;
    padding: 12px 16px;
    border-radius: 8px;
    background: #991b1b;
    color: #fff;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.static-data-error[hidden] {
    display: none;
}

/* Favorites UI */

.favorite-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    color: var(--text-secondary);
}
.favorite-btn:hover {
    background-color: var(--bg-secondary);
}
.favorite-btn:active {
    transform: scale(0.9);
}




