/* ================================================================
   Camptime.ca — Split Panel Layout
   Desktop: Panel LEFT | Map RIGHT
   Mobile:  MAP TOP | Panel BELOW (REVERSED!)
   ================================================================ */

:root {
    --c-primary: #2d5a3f;
    --c-accent: #D4863A;
    --c-accent-light: #e09a55;
    --c-bg: #faf8f5;
    --c-dark: #1a2e1f;
    --c-text: #2C2417;
    --c-muted: #6b5e52;
    --c-border: #e4ddd4;
    --c-card: #ffffff;
    --c-green: #3a8a3e;
    --c-red: #c44d3f;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(44,36,23,.08);
    --panel-w: 380px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: var(--font);
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ── */
.topbar {
    height: 48px;
    background: var(--c-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,.1);
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 600;
}
.topbar-brand svg { color: var(--c-accent); }
.topbar-brand b { color: var(--c-accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-tag {
    font-size: .75rem;
    color: rgba(255,255,255,.5);
    letter-spacing: .02em;
}

/* ── APP LAYOUT ── */
.app {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* ── LEFT PANEL ── */
.panel {
    width: var(--panel-w);
    flex-shrink: 0;
    background: var(--c-card);
    border-right: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}
.panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
}
.panel-scroll::-webkit-scrollbar { width: 4px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 2px; }

/* ── ROUTE INPUTS (From / To) ── */
.route-inputs {
    position: relative;
    margin-bottom: 12px;
}
.route-field {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}
.route-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid;
}
.dot-green { border-color: var(--c-green); background: rgba(58,138,62,.15); }
.dot-red { border-color: var(--c-red); background: rgba(196,77,63,.15); }

.route-line {
    width: 2px;
    height: 16px;
    background: var(--c-border);
    margin-left: 5px;
}

.route-input-wrap {
    flex: 1;
    position: relative;
}
.route-input-wrap input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius);
    font-size: .95rem;
    background: var(--c-bg);
    color: var(--c-text);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}
.route-input-wrap input:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(45,90,63,.15);
    background: #fff;
    outline: 2px solid transparent;
}
.route-input-wrap input::placeholder {
    color: var(--c-muted);
    font-weight: 400;
}

/* ── ADD STOP ── */
.btn-add-stop {
    background: none;
    border: none;
    color: var(--c-accent);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 12px;
    margin-bottom: 12px;
    transition: all .2s ease;
    border-radius: 6px;
    position: relative;
}
.btn-add-stop:hover { 
    color: var(--c-primary); 
    background: rgba(45,90,63,.05);
    transform: translateX(2px);
}
.btn-add-stop:focus {
    outline: 2px solid rgba(45,90,63,.3);
    outline-offset: 1px;
}

.waypoints-list {
    margin-bottom: 8px;
}

/* ── QUICK OPTIONS ── */
.quick-opts {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    padding: 16px;
    background: linear-gradient(135deg, var(--c-bg), #f5f2ed);
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    box-shadow: inset 0 1px 2px rgba(0,0,0,.02);
}
.opt-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.opt-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    width: 52px;
    flex-shrink: 0;
}
.opt-select, .opt-input {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid var(--c-border);
    border-radius: 7px;
    font-size: .85rem;
    background: var(--c-card);
    color: var(--c-text);
    outline: none;
    transition: all .2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,.02);
}
.opt-select:hover, .opt-input:hover {
    border-color: rgba(45,90,63,.4);
}
.opt-select:focus, .opt-input:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px rgba(45,90,63,.15);
    outline: 2px solid transparent;
}
.fuel-inline {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.fuel-inline input { width: 70px; flex: none; }

/* Combined fuel-economy + price row */
.opt-row-fuel {
    gap: 8px;
}
.opt-row-fuel .fuel-inline-price { justify-content: flex-end; }
.opt-row-fuel .fuel-inline-price input { width: 64px; }

/* Vehicle-aware fuel-economy hint */
.opt-hint-row {
    display: flex;
    justify-content: flex-end;
    margin-top: -4px;
    padding-right: 4px;
    min-height: 14px;
}
.opt-hint {
    font-size: .72rem;
    color: var(--c-muted);
    font-style: italic;
    line-height: 1;
}
.opt-hint:empty { display: none; }
.fuel-unit {
    font-size: .75rem;
    color: var(--c-muted);
    font-weight: 500;
}

/* ── GO BUTTON ── */
.btn-go {
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--c-primary) 0%, #3a6b4a 50%, var(--c-primary) 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all .2s ease;
    box-shadow: 0 4px 16px rgba(45,90,63,.3), inset 0 1px 0 rgba(255,255,255,.1);
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
}
.btn-go::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255,255,255,.1), transparent);
    transform: translateX(-100%);
    transition: transform .6s ease;
}
.btn-go:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(45,90,63,.4), inset 0 1px 0 rgba(255,255,255,.15);
}
.btn-go:hover::before {
    transform: translateX(100%);
}
.btn-go:focus {
    outline: 3px solid rgba(45,90,63,.3);
    outline-offset: 2px;
}
.btn-go:active { 
    transform: translateY(-1px); 
    box-shadow: 0 6px 20px rgba(45,90,63,.35);
}

/* ── DISCOVER BAR (Chip-based POI selection) ── */
.discover-bar {
    margin: 12px 0 8px;
}
.discover-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}
.chip-scroll {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }
@media (max-width: 768px) {
    .chip-scroll {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    .chip { white-space: nowrap; }
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    background: var(--c-surface);
    border: 1.5px solid var(--c-border);
    color: var(--c-text);
    transition: all 0.2s;
    user-select: none;
}
.chip:hover {
    border-color: var(--c-primary);
    background: rgba(45, 90, 63, 0.08);
}
.chip-active, .chip:has(input:checked) {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}

/* ── TRIP SUMMARY ── */
.trip-summary {
    background: var(--c-bg);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--c-border);
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0,0,0,.04);
}
.summary-row:last-child { border-bottom: none; }
.summary-label { font-size: .85rem; color: var(--c-muted); }
.summary-value { font-size: .85rem; font-weight: 700; color: var(--c-primary); }

/* ── STOPS LIST ── */
.stops-list { margin-bottom: 16px; }
.stops-heading {
    font-size: .9rem;
    font-weight: 700;
    color: var(--c-primary);
    margin-bottom: 8px;
}

/* ── NAV ACTIONS (Waze / Google Maps) ── */
.nav-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.btn-nav {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius);
    font-size: .8rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all .2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,.1);
}
.btn-nav:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.btn-nav:focus {
    outline: 2px solid rgba(0,0,0,.3);
    outline-offset: 2px;
}
.btn-waze {
    background: #33ccff;
    color: #000;
}
.btn-gmaps {
    background: #4285f4;
    color: #fff;
}

/* ── MAP AREA ── */
.map-area {
    flex: 1;
    position: relative;
}
#map {
    width: 100%;
    height: 100%;
}

/* ── MOBILE STOPS (below map) ── */
.mobile-stops {
    display: none;
}

/* ── FOOTER ── */
.app-footer {
    display: none; /* Hidden in app mode — shown in scroll */
}

/* ── PREDICTIVE SEARCH overrides for this layout ── */
.ps-dropdown {
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ================================================================
   RESPONSIVE — MOBILE PORTRAIT (CRITICAL CHANGES)
   ================================================================ */
@media (max-width: 768px) {
    .app {
        flex-direction: column;
        height: calc(100vh - 48px);
    }

    /* When the map is expanded, let .app grow so the map can fill the
       viewport. The panel slides off-screen below. */
    .app:has(.map-area.map-expanded) {
        height: auto;
        overflow: visible;
    }
    
    /* MAP = 2/3 of screen by default. Expand button = full 100vh for route
       inspection. Panel below gets the remaining 1/3 and scrolls. */
    .map-area {
        order: -1;
        height: 78vh;
        min-height: 360px;
        flex-shrink: 0;
        position: relative; /* anchors absolute expand button + sponsor overlay */
    }
    
    /* PANEL SCROLLS BELOW with remaining space */
    .panel {
        width: 100%;
        border-right: none;
        border-top: 2px solid var(--c-primary);
        flex: 1;
        overflow-y: auto;
    }
    
    .panel-scroll {
        padding: 10px 12px;
        /* Bottom space so the last button clears the mobile browser URL bar + iOS home indicator */
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        height: 100%;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-stops {
        display: block;
        background: var(--c-card);
        border-top: 1px solid var(--c-border);
        padding: 12px;
        max-height: 35vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Mobile optimizations */
    .quick-opts {
        padding: 8px 10px;
    }
    
    .opt-row {
        flex-wrap: wrap;
    }
    
    .topbar-tag {
        display: none;
    }
    
    .route-input-wrap input {
        padding: 8px 12px;
        font-size: .9rem;
    }
    
    .btn-go {
        padding: 12px;
        font-size: .95rem;
        width: 100%;
    }
    
    .nav-actions {
        flex-direction: column;
        gap: 6px;
    }
    
    /* Trip summary cards - horizontal scroll */
    .trip-summary {
        min-width: max-content;
    }
}

/* Small phones */
@media (max-width: 380px) {
    .topbar { height: 42px; padding: 0 10px; }
    .topbar-brand { font-size: .95rem; }
    .app { height: calc(100vh - 42px); }
    .panel-scroll {
        padding: 8px 8px;
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }
    .route-input-wrap input { padding: 8px 10px; }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .app { flex-direction: row; }
    .panel { 
        width: 320px; 
        border-right: 1px solid var(--c-border); 
        border-top: none;
        order: 0;
    }
    .map-area { 
        order: 0;
        height: auto;
        min-height: auto;
        max-height: none;
    }
    .panel-scroll { overflow-y: auto; }
    .mobile-stops { display: none; }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(250,246,240,.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.loading-inner { text-align: center; }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { color: var(--c-primary); font-weight: 600; font-size: .9rem; }
/* ================================================================
   AFFILIATE RIGHT-SIDE PANEL (desktop) + MOBILE STACK + MAP EXPAND
   Added 2026-05-06 — Robbie asked for affiliate cards on the RIGHT
   on desktop, and a way to expand the map on mobile.
   ================================================================ */

:root {
    --aff-panel-w: 340px;
}

/* Desktop: render affRecommendations as a third right-side column. */
.aff-side {
    width: var(--aff-panel-w);
    flex-shrink: 0;
    background: var(--c-card);
    border-left: 1px solid var(--c-border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 14px;
    /* Match panel scroll height so it doesn't blow out the layout. */
    max-height: 100%;
}
.aff-side::-webkit-scrollbar { width: 4px; }
.aff-side::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 2px; }

/* The map-expand button is hidden by default — shown only on mobile. */
.map-expand-btn {
    display: none;
}

/* ── MOBILE: ≤768px ───────────────────────────────── */
@media (max-width: 768px) {
    /* Affiliate gear panel is a desktop-only right column. On mobile the
       67vh map + route panel already fill the viewport — there's no room
       for a third flex sibling without crushing the panel to 0px.
       Gear recommendations still appear inline in route results. */
    .aff-side {
        display: none !important;
    }

    /* Show the expand button on mobile, anchored to .map-area's bottom-right. */
    .map-expand-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        position: absolute;
        right: 10px;
        bottom: 10px;
        z-index: 8;
        background: rgba(26, 46, 31, 0.92); /* --c-dark + alpha */
        color: #fff;
        border: 1px solid rgba(255,255,255,0.18);
        border-radius: 999px;
        padding: 8px 12px 8px 10px;
        font-size: 0.78rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25);
        -webkit-appearance: none;
        appearance: none;
        line-height: 1;
        /* Avoid covering bottom POI markers — small, translucent. */
        opacity: 0.94;
    }
    .map-expand-btn:active { transform: translateY(1px); }
    .map-expand-btn svg { display: block; }

    /* When expanded, fill the entire viewport. */
    /* Expanded: fill viewport minus the topbar so the panel still peeks up
       below the map and the stops list remains reachable. */
    /* Expanded: fill viewport minus topbar, accounting for Safari's
       bottom nav bar via safe-area-inset-bottom. */
    .map-area.map-expanded {
        height: calc(100vh - 48px - env(safe-area-inset-bottom, 160px)) !important;
        max-height: none !important;
    }
    /* Lift the collapse button well clear of Safari toolbar + home indicator. */
    .map-area.map-expanded .map-expand-btn {
        bottom: calc(24px + env(safe-area-inset-bottom, 160px));
    }
    .map-area.map-expanded .map-expand-label::before {
        content: "Collapse";
        font-size: 0.78rem;
    }
    .map-area.map-expanded .map-expand-label {
        font-size: 0; /* hide original "Expand map" label */
    }
}

/* Tiny phones — keep the button small. */
@media (max-width: 380px) {
    .map-expand-btn {
        padding: 6px 10px 6px 8px;
        font-size: 0.72rem;
    }
}

/* Landscape mobile already uses a flex row; aff-side comes after .map-area. */
@media (max-height: 500px) and (orientation: landscape) {
    .aff-side {
        width: 280px;
        border-left: 1px solid var(--c-border);
        border-top: none;
        max-height: 100%;
    }
    /* Don't let the expand button hijack landscape — the side panel is enough. */
    .map-expand-btn { display: none; }
}
