/* =============================================
   DESKTOP LAYOUT SYSTEM
   Petrolmate Desktop Experience Enhancement
   ============================================= */

/* =============================================
   BASE DESKTOP STYLES (1024px+)
   ============================================= */
@media (min-width: 1024px) {
    /* Remove mobile container constraint */
    body.desktop-mode {
        overflow-x: hidden;
    }

    body.desktop-mode .app {
        max-width: none;
        margin: 0;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    /* =============================================
       FULL-WIDTH HEADER - MATCHES REFERENCE STYLING
       ============================================= */
    body.desktop-mode .header {
        width: 100%;
        max-width: none;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: var(--spacing-lg) var(--spacing-xl);
        flex-shrink: 0;
        border-bottom: 1px solid var(--border-light);
        /* Soft grey background matching footer */
        background: rgb(250, 250, 248);
        position: relative;
        overflow: visible; /* Allow dropdown to overflow */
        z-index: 100; /* Ensure header dropdowns appear above main content */
    }

    /* Light glow effect - positioned at top right near dark/light toggle */
    body.desktop-mode .header::before {
        content: '';
        position: absolute;
        top: -20px;
        right: -40px;
        width: 180px;
        height: 180px;
        background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
        opacity: 0.2;
        border-radius: 50%;
        pointer-events: none;
    }

    /* Center logo in header for split-view layout */
    body.desktop-mode .header-title {
        display: flex;
        align-items: center;
        justify-content: center;
        /* Remove width: 100% to allow auth section to position absolutely */
    }

    /* Auth section in header - LEFT side */
    body.desktop-mode .header-auth-section {
        position: absolute;
        left: 32px;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        gap: 12px;
        z-index: 99999;
    }

    /* =============================================
       MAIN SPLIT LAYOUT CONTAINER
       ============================================= */
    body.desktop-mode main {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }

    body.desktop-mode .desktop-main {
        display: flex;
        flex: 1;
        height: calc(100vh - 140px);
        overflow: hidden;
    }

    /* =============================================
       LEFT SIDEBAR (35%) - Balance between space and map visibility
       ============================================= */
    body.desktop-mode .desktop-sidebar {
        width: 35%;
        min-width: 380px;
        max-width: 550px;
        display: flex;
        flex-direction: column;
        border-right: 1px solid var(--border);
        background: var(--surface);
        overflow: hidden;
        flex-shrink: 0;
    }

    /* Sidebar Controls Section - soft grey background */
    body.desktop-mode .sidebar-controls {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
        /* Soft grey matching header/footer */
        background: var(--surface);
    }

    /* Search section inside sidebar */
    body.desktop-mode .sidebar-controls .search-section {
        padding: 0;
        margin: 0;
        background: var(--surface);
    }

    /* Hide location toggle on desktop - both views always visible */
    body.desktop-mode .location-toggle {
        display: none !important;
    }

    /* Filter row in sidebar */
    body.desktop-mode .filter-row {
        display: flex !important;
        gap: var(--spacing-sm);
        margin-bottom: var(--spacing-md);
    }

    /* Fuel Type and Brand Type pickers - more padding for better touch targets */
    body.desktop-mode .filter-select {
        flex: 1;
        padding: 14px 16px !important;
        padding-right: 32px !important;
        font-size: 14px !important;
        min-height: 48px;
    }

    /* Desktop Search Button in Sidebar */
    body.desktop-mode .desktop-search-btn {
        width: 100%;
        margin-top: var(--spacing-md);
        padding: var(--spacing-md) var(--spacing-lg);
        background: var(--primary);
        color: var(--text-on-primary);
        border: none;
        border-radius: var(--radius-md);
        font-size: var(--font-size-md);
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s ease, transform 0.1s ease;
    }

    body.desktop-mode .desktop-search-btn:hover {
        background: var(--primary-dark);
        transform: translateY(-1px);
    }

    body.desktop-mode .desktop-search-btn:active {
        transform: translateY(0);
    }

    /* Hide the original search button (in map section) */
    body.desktop-mode #searchButton {
        display: none !important;
    }

    /* Sidebar Results Section */
    body.desktop-mode .sidebar-results {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* =============================================
       RIGHT MAP PANEL (70%)
       ============================================= */
    body.desktop-mode .desktop-map-panel {
        flex: 1;
        position: relative;
        overflow: hidden;
        background: var(--surface);
    }

    /* Map section always visible on desktop */
    body.desktop-mode .desktop-map-panel #map-section {
        display: block !important;
        height: 100% !important;
        width: 100% !important;
        position: relative;
    }

    body.desktop-mode .desktop-map-panel .map-container {
        height: 100% !important;
        width: 100% !important;
    }

    body.desktop-mode .desktop-map-panel .map-section {
        height: 100% !important;
    }

    /* =============================================
       STATION LIST ADJUSTMENTS - COMPACT LAYOUT
       ============================================= */
    body.desktop-mode .station-list {
        display: block !important;
        padding: 8px;
    }

    /* Compact station cards for desktop - show more content */
    body.desktop-mode .station {
        padding: 12px !important;
        margin: 0 8px 8px 8px !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    body.desktop-mode .station:hover {
        transform: translateY(-1px);
        box-shadow: var(--shadow-lg);
        cursor: pointer;
    }

    body.desktop-mode .station.highlighted {
        border: 2px solid var(--primary);
        box-shadow: 0 0 0 4px rgba(255, 183, 0, 0.2);
    }

    /* Show more of station name and address with wider sidebar */
    body.desktop-mode .station-name {
        font-size: 15px;
        font-weight: 600;
        line-height: 1.3;
        /* Allow text to show fully or wrap if needed */
        white-space: normal;
        word-wrap: break-word;
        max-width: 100%;
    }

    body.desktop-mode .station-address {
        font-size: 13px;
        line-height: 1.3;
        color: var(--text-secondary);
        /* Allow address to show fully */
        white-space: normal;
        word-wrap: break-word;
        max-width: 100%;
    }

    /* Smaller logo for more text space */
    body.desktop-mode .station-logo {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px;
        margin-right: 12px;
    }

    /* Compact station info section */
    body.desktop-mode .station-info {
        flex: 1;
        min-width: 0;
        padding-right: 8px;
    }

    /* Compact price display */
    body.desktop-mode .station-price {
        font-size: 16px;
        padding: 6px 10px;
    }

    /* =============================================
       RESULTS HEADER IN SIDEBAR
       ============================================= */
    body.desktop-mode .results-header,
    body.desktop-mode #resultsHeader {
        display: flex !important;
        /* Compact padding for results header area */
        padding: 8px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* Radius/Distance selector - compact */
    body.desktop-mode .distance-select,
    body.desktop-mode select[id*="radius"],
    body.desktop-mode select[id*="distance"] {
        padding: 8px 10px;
        font-size: 13px;
    }

    /* Sort buttons (Best|Price|Distance) - compact */
    body.desktop-mode .sort-buttons,
    body.desktop-mode .sort-btn,
    body.desktop-mode [class*="sort-"] button {
        padding: 6px 10px;
        font-size: 13px;
    }

    /* =============================================
       MAP MARKER HIGHLIGHT - Matching station card halo
       When user clicks station in list, highlight marker on map
       ============================================= */
    body.desktop-mode .pin-marker.highlighted {
        z-index: 10000 !important;
        transform: scale(1.15);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    body.desktop-mode .pin-marker.highlighted::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 70px;
        height: 70px;
        border-radius: 50%;
        background: rgba(255, 183, 0, 0.3);
        border: 3px solid var(--primary);
        box-shadow: 0 0 20px rgba(255, 183, 0, 0.5);
        animation: markerPulse 1.5s ease-in-out infinite;
        z-index: -1;
        pointer-events: none;
    }

    @keyframes markerPulse {
        0%, 100% {
            transform: translate(-50%, -50%) scale(1);
            opacity: 1;
        }
        50% {
            transform: translate(-50%, -50%) scale(1.2);
            opacity: 0.7;
        }
    }

    /* =============================================
       ABOUT SECTION - HIDE ON DESKTOP SPLIT VIEW
       Keep the interface clean, info available in footer
       ============================================= */
    body.desktop-mode .about-petrolmate-section,
    body.desktop-mode #aboutContent {
        display: none !important;
    }

    /* =============================================
       FOOTER - FULL WIDTH AT BOTTOM
       ============================================= */
    body.desktop-mode footer,
    body.desktop-mode .desktop-footer {
        display: flex !important;
        justify-content: center;
        align-items: center;
        gap: var(--spacing-sm);
        padding: var(--spacing-md) var(--spacing-xl);
        background: var(--surface);
        border-top: 1px solid var(--primary);
        flex-shrink: 0;
        width: 100%;
        font-size: 12px;
    }

    body.desktop-mode footer a,
    body.desktop-mode .desktop-footer a {
        color: var(--text-secondary);
        text-decoration: none;
        padding: 0 8px;
        transition: color 0.2s ease;
    }

    body.desktop-mode footer a:hover,
    body.desktop-mode .desktop-footer a:hover {
        color: var(--primary);
    }

    body.desktop-mode .footer-divider {
        color: #ccc;
    }

    /* =============================================
       MAP CONTROLS POSITIONING
       Align all buttons vertically (right: 10px matches zoom controls)
       ============================================= */
    body.desktop-mode .map-locate-btn,
    body.desktop-mode .map-navigate-btn,
    body.desktop-mode .map-filter-btn {
        /* Align with zoom controls at right: 10px */
        right: 10px !important;
    }

    /* =============================================
       LOADING AND ERROR STATES
       ============================================= */
    body.desktop-mode #loading,
    body.desktop-mode #error {
        padding: var(--spacing-xl);
        text-align: center;
    }

    /* =============================================
       MAP POPUP ADJUSTMENTS
       ============================================= */
    body.desktop-mode .maplibregl-popup {
        max-width: 340px !important;
    }

    /* =============================================
       ROUTE PANEL ON DESKTOP
       ============================================= */
    body.desktop-mode .route-panel {
        max-width: 400px;
        left: 16px;
        top: 16px;
    }

    /* =============================================
       POSTCODE ROW
       ============================================= */
    body.desktop-mode .postcode-row {
        margin-bottom: var(--spacing-md);
    }

    body.desktop-mode .postcode-row.active {
        display: block;
    }

    /* =============================================
       COUNTRY TOGGLE
       ============================================= */
    body.desktop-mode .country-toggle {
        margin-bottom: var(--spacing-md);
    }
}

/* =============================================
   TABLET BREAKPOINT (768px - 1023px)
   Stacked layout for tablets
   ============================================= */
@media (min-width: 768px) and (max-width: 1023px) {
    body.desktop-mode .app {
        max-width: none;
    }

    body.desktop-mode .header {
        /* Solid background matching reference - no gradient */
        background: var(--background);
    }

    /* Center logo on tablet too */
    body.desktop-mode .header-title {
        justify-content: center;
    }

    body.desktop-mode .desktop-main {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 140px);
    }

    body.desktop-mode .desktop-sidebar {
        width: 100%;
        max-width: none;
        height: 45%;
        min-height: 320px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    body.desktop-mode .desktop-map-panel {
        height: 55%;
        min-height: 300px;
    }

    body.desktop-mode .location-toggle {
        display: none !important;
    }

    body.desktop-mode .desktop-search-btn {
        display: block !important;
    }

    body.desktop-mode #searchButton {
        display: none !important;
    }

    body.desktop-mode footer {
        display: flex !important;
    }

    body.desktop-mode .about-petrolmate-section {
        display: none !important;
    }
}

/* =============================================
   WIDESCREEN ADJUSTMENTS (1440px+)
   ============================================= */
@media (min-width: 1440px) {
    body.desktop-mode .desktop-sidebar {
        max-width: 580px;
    }

    body.desktop-mode .header-title {
        padding: 0 var(--spacing-2xl);
    }

    /* Keep compact station cards on widescreen too */
    body.desktop-mode .station {
        padding: 14px !important;
    }
}

/* =============================================
   ULTRA-WIDE ADJUSTMENTS (1920px+)
   ============================================= */
@media (min-width: 1920px) {
    body.desktop-mode .desktop-sidebar {
        width: 32%;
        max-width: 650px;
    }

    body.desktop-mode .header-title {
        max-width: 2200px;
    }
}

/* =============================================
   SMOOTH TRANSITIONS
   ============================================= */
body.desktop-mode .desktop-sidebar,
body.desktop-mode .desktop-map-panel {
    transition: width 0.3s ease, height 0.3s ease;
}

/* =============================================
   DARK MODE ADJUSTMENTS
   ============================================= */
:root[data-theme="dark"] body.desktop-mode .header {
    /* Solid dark grey background matching footer */
    background: var(--surface);
}

:root[data-theme="dark"] body.desktop-mode .desktop-sidebar {
    border-right-color: var(--border);
    background: var(--surface);
}

/* Dark grey background for controls in dark mode */
:root[data-theme="dark"] body.desktop-mode .sidebar-controls {
    background: var(--surface);
}

:root[data-theme="dark"] body.desktop-mode .station:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

:root[data-theme="dark"] body.desktop-mode footer {
    background: var(--surface);
}

/* =============================================
   MOBILE FALLBACK
   On screens < 768px, show mobile layout
   ============================================= */
@media (max-width: 767px) {
    body.desktop-mode .desktop-main {
        display: block;
    }

    body.desktop-mode .desktop-sidebar {
        width: 100%;
        max-width: none;
        height: auto;
        border-right: none;
    }

    body.desktop-mode .desktop-map-panel {
        display: none;
    }

    body.desktop-mode .location-toggle {
        display: flex !important;
    }

    /* Show Find Stations button prominently on mobile */
    body.desktop-mode .desktop-search-btn {
        display: block !important;
        width: calc(100% - 32px) !important;
        margin: 16px auto !important;
        padding: 16px !important;
        background: linear-gradient(135deg, var(--primary) 0%, #e5a500 100%) !important;
        color: #000 !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        border: none !important;
        border-radius: 12px !important;
        cursor: pointer !important;
    }

    /* Hide the searchButton in map panel since we show desktop-search-btn */
    body.desktop-mode #searchButton {
        display: none !important;
    }

    body.desktop-mode footer {
        display: block;
    }

    body.desktop-mode .about-petrolmate-section {
        display: block !important;
    }
}

/* =============================================
   SCROLLBAR STYLING FOR SIDEBAR
   ============================================= */
body.desktop-mode .sidebar-results::-webkit-scrollbar {
    width: 8px;
}

body.desktop-mode .sidebar-results::-webkit-scrollbar-track {
    background: var(--surface);
}

body.desktop-mode .sidebar-results::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

body.desktop-mode .sidebar-results::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* =============================================
   DESKTOP POSTCODE SEARCH SECTION
   ============================================= */
body.desktop-mode .desktop-postcode-toggle {
    text-align: center;
    margin-top: 4px;
}

body.desktop-mode .postcode-toggle-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s ease;
}

body.desktop-mode .postcode-toggle-link:hover {
    color: var(--primary);
}

body.desktop-mode .postcode-toggle-link i {
    margin-right: 5px;
    font-size: 11px;
}

body.desktop-mode .desktop-postcode-section {
    margin-top: 10px;
    padding: 10px;
    background: var(--surface-alt, #f8f9fa);
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--border-light, #e9ecef);
}

:root[data-theme="dark"] body.desktop-mode .desktop-postcode-section {
    background: var(--surface-elevated, #2a2a2a);
    border-color: var(--border, #3a3a3a);
}

body.desktop-mode .desktop-postcode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

body.desktop-mode .postcode-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 13px;
    line-height: 1;
    transition: color 0.2s ease;
}

body.desktop-mode .postcode-close-btn:hover {
    color: var(--text-primary);
}

body.desktop-mode .desktop-country-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
    border-radius: var(--radius-sm, 6px);
    overflow: hidden;
    border: 1px solid var(--border, #ddd);
}

body.desktop-mode .desktop-country-option {
    flex: 1;
    padding: 6px 10px;
    border: none;
    background: var(--surface, #fff);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

body.desktop-mode .desktop-country-option:first-child {
    border-right: 1px solid var(--border, #ddd);
}

body.desktop-mode .desktop-country-option.active {
    background: var(--primary);
    color: #1a1a1a;
    font-weight: 600;
}

/* Dark mode: inactive country buttons need light text */
:root[data-theme="dark"] body.desktop-mode .desktop-country-option {
    background: var(--surface-elevated, #2a2a2a);
    color: var(--text-primary, #fff);
    border-color: var(--border, #444);
}

:root[data-theme="dark"] body.desktop-mode .desktop-country-option:first-child {
    border-right-color: var(--border, #444);
}

:root[data-theme="dark"] body.desktop-mode .desktop-country-option.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

:root[data-theme="dark"] body.desktop-mode .desktop-country-option:not(.active):hover {
    background: var(--surface-hover, #3a3a3a);
}

body.desktop-mode .desktop-country-option:not(.active):hover {
    background: var(--surface-hover, #f0f0f0);
}

body.desktop-mode .desktop-postcode-input-row {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

body.desktop-mode .desktop-postcode-input {
    width: 90px;
    flex: none;
    padding: 8px 10px;
    border: 1px solid var(--border, #ddd);
    border-radius: var(--radius-sm, 6px);
    font-size: 14px;
    font-family: inherit;
    text-align: center;
    letter-spacing: 1px;
    background: var(--surface, #fff);
    color: var(--text-primary);
}

body.desktop-mode .desktop-postcode-input::placeholder {
    letter-spacing: 0;
    font-size: 12px;
}

body.desktop-mode .desktop-postcode-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light, rgba(255, 183, 0, 0.2));
}

:root[data-theme="dark"] body.desktop-mode .desktop-postcode-input {
    background: var(--surface-elevated, #2a2a2a);
    border-color: var(--border, #444);
    color: var(--text-primary, #fff);
}

body.desktop-mode .desktop-postcode-search-btn {
    padding: 8px 14px;
    background: var(--primary);
    color: #1a1a1a;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.1s ease;
}

body.desktop-mode .desktop-postcode-search-btn:hover {
    background: var(--primary-dark, #e5a500);
}

body.desktop-mode .desktop-postcode-search-btn:active {
    transform: scale(0.98);
}

:root[data-theme="dark"] body.desktop-mode .desktop-postcode-search-btn {
    color: #fff;
    font-weight: 600;
}

/* Empty State with Postcode Option */
body.desktop-mode .empty-postcode-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light, #e9ecef);
}

body.desktop-mode .empty-postcode-prompt {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

body.desktop-mode .empty-postcode-row {
    display: flex;
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
}

body.desktop-mode .empty-postcode-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border, #ddd);
    border-radius: var(--radius-sm, 6px);
    font-size: 14px;
    text-align: center;
    background: var(--surface, #fff);
    color: var(--text-primary);
}

body.desktop-mode .empty-postcode-input:focus {
    outline: none;
    border-color: var(--primary);
}

body.desktop-mode .empty-postcode-btn {
    padding: 10px 16px;
    background: var(--primary);
    color: var(--text-on-primary, #fff);
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s ease;
}

body.desktop-mode .empty-postcode-btn:hover {
    background: var(--primary-dark, #e5a500);
}

/* =============================================
   PRINT STYLES - HIDE MAP
   ============================================= */
@media print {
    body.desktop-mode .desktop-map-panel {
        display: none;
    }

    body.desktop-mode .desktop-sidebar {
        width: 100%;
        max-width: none;
    }
}
