/* Mobile route workspace. Loaded after style.css so one module owns the
   phone layout instead of stacking competing breakpoint overrides. */
@media (max-width: 640px) {
    :root { --mobile-map-top: var(--header-height); }

    html, body { overflow-x: clip; }

    .line-detail {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    /* Remove the visual panel as a sticky containing block. Its children
       participate directly in .line-detail, allowing the map to remain
       sticky while the stop list scrolls below it. */
    .line-detail .visual-panel { display: contents; }

    .visual-header {
        order: 1;
        display: block;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: var(--surface-raised);
    }

    .visual-header > div:first-child { display: none; }

    .visual-controls {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 5px;
        width: 100%;
    }

    .quick-route-picker {
        grid-column: 1 / -1;
        grid-row: 1;
        width: 100%;
        min-width: 0;
        position: relative;
    }

    .quick-route-form {
        width: 100%;
        height: 36px;
        grid-template-columns: minmax(0, 1fr) 36px;
    }

    .quick-route-input { height: 36px; }

    .quick-route-results {
        position: fixed;
        top: calc(var(--header-height) + 8px);
        right: 10px;
        left: 10px;
        z-index: 3000;
        width: auto;
        max-height: min(48svh, 320px);
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: 14px;
        box-shadow: 0 20px 48px rgba(0, 0, 0, .38);
    }

    .quick-route-option {
        grid-template-columns: 42px minmax(0, 1fr);
        gap: 7px;
        padding: 9px;
    }

    .quick-route-pending {
        padding: 13px 12px;
        color: var(--muted);
        font-size: .72rem;
        text-align: center;
    }

    .view-tabs {
        grid-column: 1 / span 2;
        grid-row: 2;
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        min-width: 0;
        height: 34px;
        padding: 2px;
        border-radius: 10px;
    }

    .view-tab {
        min-width: 0;
        min-height: 28px;
        padding: 4px;
        justify-content: center;
        border-radius: 8px;
        font-size: .65rem;
    }

    .view-tab span { display: none; }

    .compare-add-btn {
        grid-column: 3;
        grid-row: 2;
        width: 100%;
        min-height: 34px;
        padding: 0;
        justify-content: center;
        border-radius: 10px;
    }

    .compare-add-btn span { display: none; }

    #removeRouteABtn,
    #removeRouteBBtn {
        display: inline-flex !important;
        grid-row: 2;
        width: 100%;
        height: 34px;
        align-items: center;
        justify-content: center;
        gap: 1px;
        padding: 0;
        border: 1px solid var(--border-strong);
        border-radius: 10px;
        background: var(--surface-solid);
        color: var(--muted);
        font-size: .61rem;
        font-weight: 900;
    }

    #removeRouteABtn { grid-column: 4; }
    #removeRouteBBtn { grid-column: 5; }
    #removeRouteABtn.hidden,
    #removeRouteBBtn.hidden { display: none !important; }

    .estimate-banner {
        order: 2;
        min-height: 24px;
        margin: 0;
        padding: 3px 8px;
        border: 0;
        background: transparent;
    }

    .estimate-icon,
    .estimate-copy strong { display: none; }

    .estimate-copy small {
        font-size: .57rem;
        line-height: 1;
    }

    .estimate-banner .confidence-pill {
        max-width: 40px;
        padding: 2px 4px;
        overflow: hidden;
        font-size: .5rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #diagramPanel {
        order: 3;
        margin: 0;
        padding: 8px;
        border-radius: 14px;
        background: var(--surface-raised);
    }

    #mapPanel {
        order: 3;
        position: sticky;
        top: var(--mobile-map-top);
        z-index: 600;
        margin: 0;
        padding: 0;
        background: var(--surface-raised);
    }

    .route-map {
        height: clamp(210px, 32svh, 280px);
        border-radius: 14px;
    }

    .map-toolbar {
        position: absolute;
        top: 7px;
        right: 7px;
        z-index: 1000;
        margin: 0;
    }

    .map-toolbar .secondary-btn {
        width: 32px;
        min-height: 32px;
        padding: 0;
    }

    .map-toolbar .secondary-btn span { display: none; }

    .confidence-legend,
    .map-caption,
    .route-comparison-summary,
    .app-footer { display: none !important; }

    .line-detail .stations-panel {
        order: 4;
        position: static;
        inset: auto;
        z-index: auto;
        display: flex;
        max-height: none;
        min-height: 0;
        flex-direction: column;
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
        padding: 0;
        box-shadow: none;
    }

    .line-detail .stations-panel .panel-heading {
        position: static;
        inset: auto;
        z-index: auto;
        margin: 0;
        padding: 7px 9px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface-raised);
        backdrop-filter: none;
    }

    .stations-panel .eyebrow { display: none; }
    .stations-panel .section-title { font-size: .78rem; }

    .station-route-switch {
        position: static;
        inset: auto;
        margin-left: auto;
        box-shadow: none;
    }

    .line-detail .stations-panel .station-list {
        max-height: none;
        overflow: visible;
        margin-top: 6px;
        padding: 0 1px 8px;
    }
}
