/* mobile.css — the phone layout (≤ 768 px) and the touch layer (coarse pointer, any width).
 *
 * Loaded after app.css / auth-modal.css: everything here overrides the desktop rules, nothing desktop moves. Shape
 * follows the "Mobile Planner" page of the Scenic design system (claude.ai/design, read 2026-10-28, tasks/todo-mobile-web.md):
 * the map fills the screen, the plan sidebar is a bottom sheet (peek / half / full), the ribbon is a drawer, the ribbon
 * screens are full-screen pages, every dialog is a bottom sheet. Colours only through the tokens.css aliases, so light
 * and dark come for free. Behaviour (snaps, drawer, long-press) lives in public/js/mobile.js.
 *
 * Sizes mobile.js writes: --sheet-h on #sidebar, --explore-h on #explore-panel (the sheet heights), --dock-h on <body>
 * (the visible sheet's height: what the map controls sit above); body.sheet-tall while a sheet is over 520 px.
 */

/* ===== Touch layer: any width, a finger instead of a pointer ================================================== */
/* The waypoint list's empty hint: the pointer wording by default, the finger wording on a coarse pointer */
.hint-touch { display: none; }
@media (pointer: coarse) {
    .hint-pointer { display: none; }
    .hint-touch { display: block; }
    * { -webkit-tap-highlight-color: transparent; }
    /* The My Data lists' selection checkbox shows on hover for a pointer: a finger has no hover */
    .location-check, .item-card-row > .location-check { visibility: visible; }
    /* Long-press opens our menus (mobile.js): no iOS callout / selection on the rows that have one */
    .waypoint-item, .via-row, .me-row, .location-row, .location-folder-head, .evomaps-canvas-container { -webkit-touch-callout: none; }
    /* Hover-only affordances are always there */
    .waypoints-container .waypoint-handle { color: var(--text-muted); width: 28px; touch-action: none; }   /* touch-action: the handle drags the row (app.js wireTouchReorder), not the page */
    .btn-icon, .tool-btn { min-width: 40px; min-height: 40px; }
    /* The side ribbon's hover tooltip is pointer-only (app.js checks pointerType); hover tints stay neutral */
    .waypoints-container .waypoint-item:not(.expanded):hover .waypoint-item-content,
    .waypoints-container .via-row:hover .waypoint-item-content { background: var(--card-bg); }
}

/* The long-press ring on the map (mobile.js initMapLongPress): grows while the finger holds still */
.long-press-ring { position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; box-sizing: border-box; border-radius: 50%; border: 3px solid var(--accent); background: var(--accent-soft); transform: scale(0.3); transition: transform 550ms linear; pointer-events: none; z-index: 5; }
.long-press-ring.is-on { transform: scale(1); }

/* ===== Get-the-app banner (phones and tablets, any width; mobile.js initAppBanner) ============================== */
/* Across the top of the map; everything that sits at the top edge moves down by its height while it shows (the class
   goes on <html>: --safe-top below is declared on :root and reads --app-banner-h there) */
:root { --app-banner-h: 0px; }
:root.has-app-banner { --app-banner-h: 56px; }
.app-banner {
    position: absolute; top: 0; left: 0; right: 0; height: calc(var(--app-banner-h) + env(safe-area-inset-top, 0px)); z-index: 1002;
    display: flex; align-items: center; gap: 10px; padding: env(safe-area-inset-top, 0px) 6px 0 12px;
    background: var(--card-bg); color: var(--text); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.app-banner[hidden] { display: none; }
.app-banner img { width: 40px; height: 40px; border-radius: 9px; flex: none; }
.app-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; line-height: 1.2; }
.app-banner-text strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-banner-text span { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-banner-get { flex: none; height: 32px; padding: 0 12px; display: inline-flex; align-items: center; border-radius: var(--radius-pill); background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 600; letter-spacing: var(--track-caps); text-transform: uppercase; text-decoration: none; }
.app-banner-close { flex: none; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; }
/* Desktop layout (a tablet): the top-edge pieces step down under the banner */
@media (min-width: 769px) {
    :root.has-app-banner .map-search-container, :root.has-app-banner .explore-btn, :root.has-app-banner .explore-panel, :root.has-app-banner .explore-chips { top: calc(20px + var(--app-banner-h)); }
    :root.has-app-banner .search-results-panel { top: calc(80px + var(--app-banner-h)); }
    :root.has-app-banner .beta-badge { top: var(--app-banner-h); }
    :root.has-app-banner .map-container .evomaps-ctrl-top-right { top: calc(10px + var(--app-banner-h)); }
}

/* ===== Phone layout ============================================================================================== */
@media (max-width: 768px) {
    :root {
        --safe-top: calc(env(safe-area-inset-top, 0px) + var(--app-banner-h));   /* the top bar sits under the Get-the-app banner while it shows */
        --safe-bottom: env(safe-area-inset-bottom, 0px);
        --dock-h: 240px;            /* mobile.js keeps it current */
        --topbar-h: 44px;
        --sheet-shadow: 0 -8px 24px rgba(17, 22, 17, 0.25);
    }
    :root[data-theme="dark"] { --sheet-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5); }

    /* iOS zooms the page into a focused field under 16 px */
    input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea { font-size: 16px; }

    body { height: 100dvh; }
    .site-footer { display: none; }   /* its links live in the drawer's Scenic panel */
    .main-content { display: block; position: relative; height: 100%; }
    #map.map-container { position: absolute; inset: 0; height: auto; }   /* the id: the SDK's own stylesheet (injected later) positions the container too */

    /* ---- Side ribbon → drawer from the left (design 1a-06): slides over the map behind a scrim -------------------- */
    .side-ribbon, .side-ribbon.expanded {
        position: fixed; top: 0; bottom: 0; left: 0; width: min(316px, 86vw); z-index: 3000;
        padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
        transform: translateX(-105%); transition: transform 320ms var(--ease-out);
        border-right: 1px solid var(--rail-line);
    }
    body.drawer-open .side-ribbon { transform: none; box-shadow: var(--shadow-lg); }
    .drawer-scrim { position: fixed; inset: 0; z-index: 2999; background: var(--backdrop-bg); opacity: 0; pointer-events: none; transition: opacity 220ms var(--ease-out); }
    .drawer-scrim[hidden] { display: block; }
    body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
    .ribbon-toggle { display: none; }           /* always expanded in the drawer (mobile.js adds .expanded) */
    /* The labels never fade in the drawer, whatever .expanded says (app.js initSideRibbon re-applies the desktop state after the map loads) */
    .side-ribbon .ribbon-item span, .side-ribbon .ribbon-nickname, .side-ribbon .ribbon-wordmark { opacity: 1 !important; }
    .ribbon-item, .ribbon-logo { height: 48px; }
    .ribbon-mini-label { display: none; }     /* the collapsed rail's small "Get App" caption: the drawer has the label */
    .ribbon-header { height: 76px; }

    /* ---- Side columns: no grab borders, a collapsed column is simply gone ---------------------------------------- */
    .panel-grip { display: none !important; }
    .sidebar.is-collapsed, .ribbon-panel.is-collapsed { display: none; }

    /* ---- Plan sidebar → bottom sheet (design 1a): handle on top, tabs, the plan; the action row pinned ------------- */
    .sidebar {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        width: 100% !important; min-width: 0; height: var(--sheet-h, 240px); max-height: calc(100dvh - var(--safe-top) - 6px);
        z-index: 1200; border-right: none; border-top: 1px solid var(--line-soft); border-radius: 16px 16px 0 0;
        box-shadow: var(--sheet-shadow); overflow: hidden; display: flex; flex-direction: column;
        transition: height 320ms var(--ease-out);
    }
    .sidebar.is-dragging, .explore-panel.is-dragging { transition: none; }
    .sheet-handle { display: flex; flex: none; height: 28px; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
    .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); }
    .sidebar .sidebar-tabs { margin: 0 16px 6px; }
    .sidebar-tab { height: 34px; }
    .sidebar-tab-panel.active { flex: 1; min-height: 0; overflow-y: auto; }
    .plan-save { position: sticky; bottom: 0; z-index: 2; padding-bottom: calc(12px + var(--safe-bottom)); }
    /* Save keeps its label, Share / Export / Print are 44 px icon buttons (design: primary + three solid icons) */
    .plan-save .route-actions, .actions-compact .plan-save .route-actions { grid-template-columns: 1fr 44px 44px 44px; gap: 8px; }
    .plan-save .route-actions .btn-primary, .plan-save .route-actions .btn-secondary { height: 44px; font-size: 13px; }
    .plan-save .route-actions .btn-primary span { display: inline; }
    .plan-save .route-actions .btn-secondary span { display: none; }
    .plan-save .route-actions .btn-secondary i { font-size: 16px; }
    .waypoint-item-content { min-height: 52px; }
    /* The room goes to the waypoint list: Route info is one line (distance · time, the tolls / ferries note under it),
       Route mode one line that opens its sheet, Directions one line that opens its sheet (mobile.js initSectionSheets) */
    .plan-section-toggle { padding: 9px 0; }
    .plan-section-head { flex-direction: row; align-items: center; gap: 10px; }
    .plan-section-toggle .plan-section-subtitle:not(:empty) { display: flex; flex: 1; min-width: 0; justify-content: flex-end; }
    #route-info-toggle { pointer-events: none; }
    #route-info-toggle i { display: none; }
    #route-info-body { max-height: none; opacity: 1; visibility: visible; padding: 0; }
    #route-info-body .plan-stats, #route-info-body .plan-title { display: none; }
    #route-info-body .plan-sections { margin: 0 0 8px; }
    #routing-options-toggle i, #directions-toggle i { transform: none; }   /* › : the row opens a sheet, nothing unfolds */
    #routing-options-content:not(.in-mobile-sheet) { display: none; }
    .directions-toggle { padding: 9px 16px; }

    /* ---- The section sheet (Route mode / Directions, design 2a-04 / 2a-05) ----------------------------------------- */
    .mobile-sheet-scrim { position: fixed; inset: 0; z-index: 1900; background: var(--backdrop-bg); }
    .mobile-sheet {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1901; max-height: calc(100dvh - 51px - var(--safe-top));
        display: flex; flex-direction: column; background: var(--panel-bg); color: var(--text);
        border-radius: 16px 16px 0 0; box-shadow: var(--sheet-shadow); animation: mobile-sheet-up 320ms var(--ease-out);
    }
    .mobile-sheet[hidden], .mobile-sheet-scrim[hidden] { display: none; }
    .mobile-sheet-head { display: flex; align-items: center; gap: 8px; padding: 0 8px 6px 16px; }
    .mobile-sheet-title { flex: 1; margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text); }
    .mobile-sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px calc(16px + var(--safe-bottom)); }
    /* The moved body shows whatever its collapsed state says (wireCollapsible's classes stay on it) */
    .in-mobile-sheet, .in-mobile-sheet.collapsed { display: block; max-height: none !important; opacity: 1 !important; visibility: visible !important; overflow: visible !important; padding: 0 0 8px !important; transition: none !important; }
    .in-mobile-sheet.directions-list { padding: 0 !important; }

    /* ---- Ribbon screens (Me, My Routes, …) → full-screen pages (design 2c): slide in from the right ---------------- */
    .ribbon-panel {
        position: fixed; inset: 0; width: 100% !important; min-width: 0; height: auto; z-index: 2500;
        padding-top: var(--safe-top); transition: transform 320ms var(--ease-out);
    }
    .ribbon-panel.is-animating { transition: transform 320ms var(--ease-out); }
    .ribbon-panel.is-closed { width: 100% !important; transform: translateX(100%); }
    .ribbon-panel.is-animating .app-sheet { right: 0; width: auto; }
    .app-sheet-foot { padding-bottom: calc(10px + var(--safe-bottom)); }

    /* ---- Top bar: menu button + search field, the User routes pill and BETA under it (design) ---------------------- */
    .mobile-menu-btn {
        display: flex; position: absolute; top: calc(12px + var(--safe-top)); left: 12px; width: var(--topbar-h); height: var(--topbar-h); z-index: 1001;
        align-items: center; justify-content: center; padding: 0; border: 1px solid var(--line-card); border-radius: var(--radius-control);
        background: var(--card-bg); color: var(--text); box-shadow: var(--shadow-map); font-size: 18px; cursor: pointer;
    }
    .map-search-container, .map-search-container.expanded { top: calc(12px + var(--safe-top)); left: calc(12px + var(--topbar-h) + 8px); right: 12px; width: auto; max-width: none; }
    .map-search-wrapper { height: var(--topbar-h); border-radius: var(--radius-control); border: 1px solid var(--line-card); box-shadow: var(--shadow-map); }
    .map-search-input { padding: 0 40px 0 44px; height: 100%; border-radius: var(--radius-control); }
    .map-search-icon { left: 14px; }
    .search-results-panel { left: 0; right: 0; top: calc(12px + var(--safe-top) + var(--topbar-h) + 8px); bottom: 0; width: auto; max-width: none; border-radius: 16px 16px 0 0; z-index: 1300; }
    .explore-btn, .map-search-container.expanded + .explore-btn { top: calc(12px + var(--safe-top) + var(--topbar-h) + 8px); left: 12px; height: 36px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-control); }
    .beta-badge { top: calc(12px + var(--safe-top) + var(--topbar-h) + 8px); left: auto; right: 12px; transform: none; height: 22px; border-radius: var(--radius-sm); }
    /* A focused search field: the suggestions need the room under it — the pill and the badge step aside */
    .map-search-container.expanded ~ .explore-btn, #map:has(.map-search-container.expanded) .beta-badge { opacity: 0; visibility: hidden; pointer-events: none; }
    .map-search-suggestions { max-height: calc(100dvh - var(--dock-h) - var(--topbar-h) - 40px); overflow-y: auto; }
    /* With User routes open the top bar stays (the pill shows the state); the panel is a sheet at the bottom */
    .map-container.explore-open .map-search-container, .map-container.explore-open .explore-btn, .map-container.explore-open .beta-badge { opacity: 1; visibility: visible; pointer-events: auto; }
    .map-container .evomaps-ctrl-top-right { top: calc(12px + var(--safe-top) + var(--topbar-h) + 8px + 36px + 8px); }
    .verification-banner { top: calc(12px + var(--safe-top) + var(--topbar-h) + 8px); }

    /* ---- Map controls sit above whichever sheet shows; zoom buttons go (pinch); all fade behind a tall sheet -------- */
    .map-container .evomaps-ctrl-bottom-right, .map-container .evomaps-ctrl-bottom-left { bottom: var(--dock-h); transition: bottom 320ms var(--ease-out), opacity 220ms; }
    .zoom-control { display: none !important; }
    #map .evomaps-chart { bottom: calc(var(--dock-h) + 8px); right: 60px; transition: bottom 320ms var(--ease-out); }
    .route-map-edit { bottom: calc(var(--dock-h) + 10px); }
    body.sheet-tall .evomaps-ctrl-bottom-right, body.sheet-tall .evomaps-ctrl-top-right, body.sheet-tall .route-map-edit, body.sheet-tall #map .evomaps-chart { opacity: 0; pointer-events: none; }

    /* ---- User routes → its own bottom sheet (design 2a): handle, title row, search, chips, list, pager --------------- */
    .explore-panel {
        position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-width: none;
        height: var(--explore-h, 476px); max-height: calc(100dvh - var(--safe-top) - 6px);
        border-radius: 16px 16px 0 0; box-shadow: var(--sheet-shadow); z-index: 1250;
        transform: translateY(24px); transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s, height 320ms var(--ease-out);
    }
    .explore-panel.is-open { transform: none; }
    .explore-panel .sheet-handle { height: 24px; }
    .discover-head { padding-top: 4px; }
    /* The filter chips move into the panel head on mobile (mobile.js) as one scrolling row */
    .discover-head .explore-chips { position: static; display: flex; flex-wrap: nowrap; gap: 8px; margin: 0 -16px 10px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; opacity: 1; visibility: visible; transform: none; pointer-events: auto; transition: none; }
    .discover-head .explore-chips::-webkit-scrollbar { display: none; }
    .discover-head .explore-chips .discover-chip { flex: none; height: 34px; box-shadow: none; }
    .discover-pager { padding-bottom: calc(8px + var(--safe-bottom)); }

    /* ---- Dialogs → bottom sheets (design): full width, handle, rounded top, safe-area bottom ---------------------- */
    .plan-modal, .custom-alert-overlay, .auth-modal, .get-app-modal { align-items: flex-end; }
    .plan-modal-card, .custom-alert-content, .auth-modal-content, .get-app-card {
        width: 100%; max-width: none; max-height: calc(100dvh - 51px - var(--safe-top)); overflow-y: auto;
        border-radius: 16px 16px 0 0; padding-bottom: calc(24px + var(--safe-bottom));
        animation: mobile-sheet-up 320ms var(--ease-out);
    }
    .plan-modal-card::before, .custom-alert-content::before, .auth-modal-content::before, .get-app-card::before {
        content: ''; display: block; width: 40px; height: 4px; margin: -10px auto 14px; border-radius: 2px; background: var(--line-strong);
    }
    @keyframes mobile-sheet-up { from { transform: translateY(48px); opacity: 0.6; } to { transform: none; opacity: 1; } }
    .form-actions, .custom-alert-buttons { flex-wrap: wrap; }
    .form-actions button, .custom-alert-buttons button { min-height: 44px; }
    .consent-banner { bottom: calc(var(--dock-h) + 12px); z-index: 1190; }

    /* ---- Map menu (right-click / long-press) → action sheet at the bottom; the SDK's popup transform is overridden -- */
    .map-context-popup {
        position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important;
        transform: none !important; max-width: none !important; width: 100%; z-index: 2000; flex-direction: column; pointer-events: auto;
    }
    .map-context-popup .evomaps-popup-tip { display: none; }
    .map-context-popup .evomaps-popup-content { width: 100%; border-radius: 16px 16px 0 0; padding-bottom: var(--safe-bottom); box-shadow: var(--sheet-shadow); }
    .map-click-menu { width: 100%; }
    .map-menu-address-container { border-radius: 16px 16px 0 0; }
    .map-menu-option { min-height: 48px; font-size: 15px; }

    /* ---- The waypoint list's ⋯ menu → action sheet at the bottom ------------------------------------------------- */
    .waypoints-more-menu.open { position: fixed; top: auto; left: 0 !important; right: 0 !important; bottom: 0; width: auto; max-width: none; min-width: 0; padding: 8px 8px calc(12px + var(--safe-bottom)); border-radius: 16px 16px 0 0; box-shadow: var(--sheet-shadow); z-index: 3500; }
    .waypoints-more-menu .dropdown-option { min-height: 48px; }

    /* ---- GPX import panel → full screen page --------------------------------------------------------------------- */
    .gpx-import-panel.active { position: fixed; inset: 0; width: 100% !important; max-width: none; min-width: 0; z-index: 1400; padding-top: var(--safe-top); }
    .gpx-panel-resize-handle { display: none; }

    /* ---- Kept from the old 768 block in app.css ------------------------------------------------------------------- */
    .radio-grid.vehicle-grid { grid-template-columns: repeat(2, 1fr); }
    .route-summary-bottom { flex-direction: column; align-items: stretch; gap: 12px; }
    .summary-actions { flex-direction: column; }
    .route-name-compact { width: 100%; }
    .me-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
