/* static/css/main/index-mobile.css - Mobile responsive styles for index page */

/* Mobile: width <= 768px OR height <= 768px (includes mobile landscape) */
@media screen and (max-width: 768px), screen and (max-height: 768px) {
    /* ===== MOBILE LAYOUT RESTRUCTURING ===== */
    #container {
        flex-direction: column;
        /* Body has padding-top: 50px (navbar) via global.css */
        /* margin-top removed - testing if body padding alone is enough */
        height: calc(100vh - 116px); /* Total: 50px navbar + 6px gap + 60px button row = 116px */
        overflow: hidden;
        position: relative;
        padding: 0;
        gap: 0;
    }

    /* Prevent body scroll when mobile drawers are open */
    body.mobile-drawer-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    /* ===== COUNTY INFO DRAWER (Left Panel) ===== */
    #county-info-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        z-index: 2500; /* MOBILE_DRAWER - ZIndexManager (above navbar and buttons) */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        overflow-x: hidden;
        background-color: var(--white);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        border-right: none;
        padding: 0;
        display: flex;
        flex-direction: column;
    }

    #county-info-container.open {
        transform: translateX(0);
    }

    /* ===== SHARED MOBILE CLOSE BUTTON STYLES ===== */
    .county-info-close-btn,
    .sidebar-close-btn,
    .mobile-map-controls-close {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
        background: none;
        border: none;
        color: var(--primary-dark);
        cursor: pointer;
        padding: 8px;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s ease;
    }

    .county-info-close-btn,
    .mobile-map-controls-close {
        font-size: 28px;
    }

    .sidebar-close-btn {
        font-size: 24px;
    }

    .county-info-close-btn:hover,
    .county-info-close-btn:active,
    .mobile-map-controls-close:hover,
    .mobile-map-controls-close:active {
        background-color: var(--background-light-shade);
    }

    .sidebar-close-btn:hover,
    .sidebar-close-btn:active {
        background-color: var(--background);
    }

    /* ===== SHARED MOBILE HEADER STYLES ===== */
    .county-info-header,
    .sidebar-header-mobile,
    .mobile-map-controls-header {
        position: sticky;
        top: 0;
        border-bottom: 2px solid var(--primary-dark);
        display: flex;
        align-items: center;
        z-index: 10;
        flex-shrink: 0;
    }

    /* Specific header overrides */
    .county-info-header {
        background: var(--white);
        padding: 8px 12px;
        justify-content: flex-end;
        min-height: 48px;
    }

    .sidebar-header-mobile {
        background: var(--background-light-shade);
        padding: 12px 20px;
        justify-content: space-between;
    }

    .mobile-map-controls-header {
        background: var(--white);
        padding: 16px 20px;
        justify-content: space-between;
    }

    .county-info-header h2 {
        display: none;
    }

    /* ===== SHARED MOBILE CONTENT AREA STYLES ===== */
    .county-info-content,
    .sidebar-content-mobile,
    .mobile-map-controls-content {
        padding: 20px;
        -webkit-overflow-scrolling: touch;
    }
    
    .county-info-content {
        -webkit-overflow-scrolling: touch;
    }

    /* Move existing county-info styles into content area */
    #county-info {
        width: 100%;
        margin-top: 0;
    }

    .county-info h2 {
        font-size: 1.3em;
        text-align: center;
    }

    /* Hide drop zone on mobile - no drag and drop needed */
    #advanced-report-drop-zone {
        display: none !important;
    }

    /* Hide save selection section on mobile - no chip workflow */
    .save-selection-section {
        display: none !important;
    }

    /* ===== SHARED MOBILE BOTTOM SHEET STYLES ===== */
    #sidebar,
    .mobile-map-controls-drawer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2500; /* MOBILE_DRAWER - ZIndexManager (above navbar and buttons) */
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
    }

    #sidebar.open,
    .mobile-map-controls-drawer.open {
        transform: translateY(0);
    }

    /* Specific bottom sheet overrides */
    #sidebar {
        max-height: 75vh;
        border-left: none;
        padding: 0;
    }

    .mobile-map-controls-drawer {
        max-height: 70vh;
        background: var(--white);
    }

    /* Sidebar Header with Drag Handle */

    .sidebar-drag-handle {
        width: 40px;
        height: 4px;
        background: var(--primary-dark);
        border-radius: 2px;
        margin: 0 auto;
        cursor: grab;
        flex-shrink: 0;
    }

    .sidebar-drag-handle:active {
        cursor: grabbing;
    }


    /* Remove any gaps in sidebar content */
    .sidebar-content-mobile > * {
        margin-top: 0;
    }

    /* ===== OVERLAY BACKDROP ===== */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 2400; /* MOBILE_OVERLAY_BACKDROP - ZIndexManager (above navbar) */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .mobile-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    /* ===== MAP CONTAINER (Full Screen on Mobile) ===== */
    #map-container {
        flex: 1;
        height: 100%;
        min-height: 0;
        position: relative;
        width: 100%;
        z-index: 5;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    #map {
        width: 100% !important;
        height: 100% !important;
        touch-action: pan-x pan-y pinch-zoom;
        margin: 0;
        padding: 0;
    }

    /* ===== MOBILE TOGGLE BUTTONS ===== */
    .mobile-toggle-button-row {
        position: fixed;
        top: 56px; /* Right below navbar (50px) + 6px gap to prevent overlap */
        left: 0;
        right: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 8px;
        padding: 10px 15px;
        background: var(--white);
        border-bottom: none;
        z-index: 1500; /* MOBILE_BUTTON_ROW - ZIndexManager (above navbar) */
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        height: 60px; /* Fixed height for button row */
    }

    .mobile-toggle-btn {
        position: static;
        flex: 1;
        max-width: 120px;
        background-color: var(--primary-dark);
        color: var(--white);
        border: none;
        border-radius: 8px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
        transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
        padding: 10px 12px;
    }

    .mobile-toggle-btn:active {
        transform: scale(0.98);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        background-color: var(--primary-light);
    }

    .mobile-toggle-btn svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .mobile-toggle-btn .button-text {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Gradient border animation for "Select Data" button state */
    .mobile-toggle-sidebar.needs-dataset-selection {
        position: relative;
        overflow: visible;
    }

    .mobile-toggle-sidebar.needs-dataset-selection::before {
        content: '';
        position: absolute;
        top: -3px;
        left: -3px;
        right: -3px;
        bottom: -3px;
        border-radius: 8px;
        background: linear-gradient(90deg, var(--info-blue, #17a2b8) 0%, var(--accent, #FFB81C) 25%, var(--info-blue, #17a2b8) 50%, var(--accent, #FFB81C) 75%, var(--info-blue, #17a2b8) 100%);
        background-size: 300% 100%;
        animation: gradientBorderScroll 4s linear infinite;
        z-index: -1;
        box-shadow: 0 0 12px rgba(23, 162, 184, 0.4);
    }

    @keyframes gradientBorderScroll {
        0% {
            background-position: 0% 50%;
        }
        100% {
            background-position: 300% 50%;
        }
    }

    /* Show mobile-specific elements on mobile */
    .county-info-header,
    .sidebar-header-mobile,
    .mobile-toggle-button-row,
    .mobile-overlay,
    .mobile-map-controls-drawer {
        display: flex !important;
    }

    /* ===== EXISTING MOBILE STYLES (Preserved) ===== */
    .filters {
        padding: 0;
        margin: 0;
        gap: 0;
    }

    .filter-group {
        padding: 15px;
        margin-bottom: 15px;
        margin-top: 0;
    }
    
    .filter-group:first-child {
        margin-top: 0;
    }

    .select-dropdown {
        width: calc(100% - 4px);
        font-size: 16px; /* Prevent iOS zoom on focus */
        padding: 12px 16px;
        min-height: 48px; /* Better touch target */
    }

    .reset-button {
        bottom: 25px;
        right: 15px;
        padding: 12px 16px;
        font-size: 0.9rem;
        min-height: 44px; /* Better touch target */
        min-width: 44px; /* Better touch target */
    }

    .tooltip {
        padding: 8px 12px;
        font-size: 13px;
        min-width: auto;
        max-width: 200px;
        border-radius: 6px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        white-space: nowrap;
    }

    /* Hide map type toggle on mobile - it's in the controls drawer */
    .map-type-toggle {
        display: none !important;
    }
    
    /* Hide legend on mobile - it's in the controls drawer */
    #legend {
        display: none !important;
    }

    /* ===== MOBILE-SPECIFIC ADJUSTMENTS ===== */
    /* Ensure all interactive elements meet touch target standards */
    .toggle-button,
    .download-button,
    .save-selection-button {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    /* County touch targets - ensure they're tappable */
    .county {
        cursor: pointer;
        /* Allow pinch zoom but prevent other touch actions */
        touch-action: pan-x pan-y pinch-zoom;
        -webkit-tap-highlight-color: rgba(111, 82, 193, 0.3); /* Visual feedback on tap */
    }
    
    /* City touch targets */
    .city {
        min-width: 44px;
        min-height: 44px;
        cursor: pointer;
        touch-action: pan-x pan-y pinch-zoom;
        -webkit-tap-highlight-color: rgba(111, 82, 193, 0.3);
    }
    
    /* Active touch feedback */
    .county:active,
    .city:active {
        opacity: 0.7;
    }

    /* Dataset selector mobile adjustments */
    #dataset-selector {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    /* ===== MOBILE MAP CONTROLS DRAWER ===== */
    
    
    .mobile-map-controls-header h3 {
        margin: 0;
        font-size: 1.2rem;
        font-weight: 900;
        text-transform: uppercase;
        color: var(--primary-dark);
        flex: 1;
    }
    
    
    
    /* Map Type Toggle in Mobile Drawer */
    .mobile-map-controls-content .map-type-toggle {
        display: block !important;
        position: static;
        bottom: auto;
        left: auto;
        transform: none;
        max-width: 100%;
        width: 100%;
        background: none;
        padding: 2px;
        border: none;
        box-shadow: none;
        margin-bottom: 30px;
    }
    
    .mobile-map-controls-content .map-type-toggle .toggle-container {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .mobile-map-controls-content .map-type-toggle .toggle-button {
        width: 100%;
        padding: 14px 16px;
        font-size: 14px;
        min-height: 48px;
        border-radius: 6px;
        text-align: center;
        border: 2px solid var(--primary-dark);
        margin: 0;
        transition: all 0.3s ease;
    }
    
    .mobile-map-controls-content .map-type-toggle .toggle-button.active {
        background-color: var(--primary-dark);
        color: var(--white);
        border-color: var(--primary-dark);
        font-weight: 600;
    }
    
    .mobile-map-controls-content .map-type-toggle .toggle-button:not(.active) {
        background-color: var(--white);
        color: var(--primary-dark);
        border-color: var(--primary-dark);
    }
}

