/**
 * Consolidated Mobile Optimizations CSS
 * Combines: mobile-touch-fix.css, filter-label-fix.css, mobile-map-optimizations.css, filter-accessibility.css
 * Architecture: Phase 1A CSS consolidation - preserves all mobile optimizations
 */

/* ===== MOBILE TOUCH OPTIMIZATIONS ===== */

/* Fix touch responsiveness on mobile filters */
@media (max-width: 768px) {
    /* Remove touch delays on all interactive elements */
    #filters-panel,
    #filters-panel *,
    .filters,
    .filters *,
    .filter-group,
    .filter-group * {
        /* Disable touch delay */
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-touch-callout: none !important;
    }
    
    /* Make labels more touch-friendly */
    #filters-panel label,
    .filters label,
    .filter-group label {
        /* Increase touch target size */
        min-height: 48px !important;
        padding: 12px 12px 12px 45px !important;
        
        /* Improve touch feedback */
        transition: background-color 0.1s ease !important;
        cursor: pointer !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }
    
    /* Add active state for immediate feedback */
    #filters-panel label:active,
    .filters label:active,
    .filter-group label:active {
        background-color: #f0f0f0 !important;
    }
    
    /* Make checkboxes larger and easier to tap */
    #filters-panel input[type="checkbox"],
    .filters input[type="checkbox"],
    .filter-group input[type="checkbox"] {
        /* Increase size for easier tapping */
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        
        /* Improve positioning */
        position: absolute !important;
        left: 10px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        
        /* Remove any margins that might interfere */
        margin: 0 !important;
        
        /* Ensure it's clickable */
        cursor: pointer !important;
        pointer-events: auto !important;
        z-index: 1 !important;
    }
    
    /* Fix for iOS touch issues */
    @supports (-webkit-touch-callout: none) {
        #filters-panel label,
        .filters label,
        .filter-group label {
            /* iOS-specific fixes */
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
        }
        
        /* Prevent iOS zoom on form inputs */
        #filters-panel input,
        .filters input {
            font-size: 16px !important;
        }
    }
    
    /* Ensure proper hit areas */
    .filter-group {
        /* Add spacing between filter groups */
        margin-bottom: 10px !important;
    }
    
    /* Remove any overlapping elements */
    #filters-panel label::before,
    #filters-panel label::after,
    .filters label::before,
    .filters label::after {
        pointer-events: none !important;
    }
    
    /* Fix for mobile filter panel specifically */
    #mobile-filter-panel-new label,
    #mobile-cloned-filters label {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* Ensure search input is also touch-friendly */
    #search-input,
    .search-input {
        min-height: 48px !important;
        font-size: 16px !important;
        padding: 12px !important;
        touch-action: manipulation !important;
    }
    
    /* Fix any z-index issues that might block touches */
    #filters-panel,
    .filters {
        position: relative !important;
        z-index: 1 !important;
    }
    
    #filters-panel > *,
    .filters > * {
        position: relative !important;
        z-index: auto !important;
    }
}

/* Additional touch improvements for the mobile panel */
.mobile-filter-panel label {
    /* Ensure full width is clickable */
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.mobile-filter-panel input[type="checkbox"] {
    /* Prevent checkbox from blocking label clicks */
    pointer-events: none !important;
}

.mobile-filter-panel label:hover {
    /* No hover effects on mobile to avoid delays */
    background-color: transparent !important;
}

/* ===== FILTER LABEL VISIBILITY FIXES ===== */

/* CRITICAL FIX: Force filter label text to be visible on mobile */
@media (max-width: 768px) {
    /* Reset all label styles to ensure text is visible */
    #filters-panel label,
    .filters label,
    .filter-group label,
    label.category-filter,
    label.age-filter,
    label.activity-filter,
    label.region-filter,
    [class*="filter"] label {
        /* Force display and positioning */
        display: block !important;
        position: relative !important;
        
        /* Force text color and visibility */
        color: #000000 !important;
        -webkit-text-fill-color: #000000 !important;
        opacity: 1 !important;
        visibility: visible !important;
        
        /* Force readable text size */
        font-size: 16px !important;
        line-height: 1.5 !important;
        font-weight: normal !important;
        
        /* Ensure proper spacing */
        padding: 10px 10px 10px 40px !important;
        margin: 5px 0 !important;
        
        /* Remove any text hiding properties */
        text-indent: 0 !important;
        overflow: visible !important;
        white-space: normal !important;
        
        /* Ensure clickable area */
        cursor: pointer !important;
        min-height: 44px !important;
        
        /* Remove any filters or transforms */
        filter: none !important;
        transform: none !important;
        
        /* Force background to ensure contrast */
        background: white !important;
        
        /* Add border for debugging */
        border: 1px solid #e0e0e0 !important;
    }
    
    /* Target text nodes and inline elements within labels */
    #filters-panel label *,
    .filters label *,
    .filter-group label * {
        color: inherit !important;
        -webkit-text-fill-color: inherit !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Specific fix for checkbox + text pattern */
    #filters-panel input[type="checkbox"],
    .filters input[type="checkbox"],
    .filter-group input[type="checkbox"] {
        /* Position checkbox absolutely */
        position: absolute !important;
        left: 10px !important;
        top: 12px !important;
        margin: 0 !important;
        
        /* Ensure checkbox is visible */
        opacity: 1 !important;
        width: 20px !important;
        height: 20px !important;
        cursor: pointer !important;
    }
    
    /* If labels use ::before or ::after for text, force them visible */
    #filters-panel label::before,
    #filters-panel label::after,
    .filters label::before,
    .filters label::after,
    .filter-group label::before,
    .filter-group label::after {
        color: #000000 !important;
        -webkit-text-fill-color: #000000 !important;
        opacity: 1 !important;
    }
    
    /* Target specific filter containers */
    #category-filters label,
    #age-filters label,
    #activity-filters label,
    #region-filters label {
        color: #000000 !important;
        -webkit-text-fill-color: #000000 !important;
    }
    
    /* Force any spans or text elements to be visible */
    #filters-panel label span,
    #filters-panel label em,
    #filters-panel label strong,
    #filters-panel label i,
    .filters label span,
    .filters label em,
    .filters label strong,
    .filters label i {
        display: inline !important;
        color: inherit !important;
        -webkit-text-fill-color: inherit !important;
        font-size: inherit !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Remove any CSS that might hide text */
    #filters-panel label {
        clip: auto !important;
        clip-path: none !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
    }
}

/* Nuclear option - inline text nodes */
@media (max-width: 768px) {
    /* Target the label text directly using attribute selectors */
    label[for*="category-"],
    label[for*="age-"],
    label[for*="activity-"],
    label[for*="region-"] {
        color: black !important;
        -webkit-text-fill-color: black !important;
    }
}

/* Super specific overrides for mobile */
@media screen and (max-width: 768px) {
    body #filters-panel label,
    body .filters label,
    body .filter-group label,
    html body #filters-panel label,
    html body .filters label {
        color: #000 !important;
        -webkit-text-fill-color: #000 !important;
        -webkit-text-stroke: 0 !important;
        text-shadow: none !important;
    }
}

/* ===== MAP TOUCH OPTIMIZATIONS ===== */

/* Fix Leaflet popup scrolling on mobile */
.leaflet-popup-content-wrapper {
    touch-action: pan-y pinch-zoom !important;
}

.leaflet-popup-content {
    /* Allow scrolling within popup content */
    touch-action: pan-y !important;
    overflow-y: auto !important;
    max-height: 60vh !important; /* Prevent popups from being too tall on mobile */
}

/* Ensure popup close button is easily tappable */
.leaflet-popup-close-button {
    touch-action: manipulation !important;
    width: 44px !important;
    height: 44px !important;
    line-height: 44px !important;
    font-size: 24px !important;
    padding: 0 !important;
    top: 0 !important;
    right: 0 !important;
}

/* Map container optimizations */
.leaflet-container {
    /* Allow pinch-zoom and panning */
    touch-action: pinch-zoom !important;
}

/* Disable touch-action restrictions on map panes */
.leaflet-map-pane,
.leaflet-tile-pane,
.leaflet-overlay-pane,
.leaflet-marker-pane {
    touch-action: none !important; /* Let Leaflet handle touch events */
}

/* Marker optimizations */
.leaflet-marker-icon,
.custom-marker {
    touch-action: manipulation !important;
    cursor: pointer !important;
}

/* Control optimizations */
.leaflet-control-container {
    touch-action: manipulation !important;
}

.leaflet-control-zoom a,
.leaflet-control-layers-toggle {
    touch-action: manipulation !important;
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Filter panel scrolling fix */
#filters-panel,
.filters-panel {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
}

/* Mobile-specific overrides */
@media (max-width: 768px) {
    /* Ensure popups are scrollable on mobile */
    .leaflet-popup {
        max-height: 70vh !important;
    }
    
    .leaflet-popup-content-wrapper {
        max-width: 90vw !important;
    }
    
    /* Make all interactive elements easier to tap */
    .leaflet-control-zoom a {
        width: 50px !important;
        height: 50px !important;
        line-height: 50px !important;
        font-size: 20px !important;
    }
    
    /* Ensure markers have adequate touch targets */
    .custom-marker,
    .leaflet-marker-icon {
        min-width: 44px !important;
        min-height: 44px !important;
    }
}

/* Fix any conflicting touch-action: none rules */
.map-container {
    touch-action: pinch-zoom !important;
}

/* Popup content specific fixes */
.popup-content {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Attraction cards within popups */
.popup-content .attraction-info {
    touch-action: pan-y !important;
}

/* Buttons and links within popups */
.leaflet-popup-content button,
.leaflet-popup-content a,
.leaflet-popup-content .btn {
    touch-action: manipulation !important;
}

/* Z-index hierarchy fix for mobile portrait mode */
@media (max-width: 768px) and (orientation: portrait) {
    /* Ensure Leaflet controls stay on top */
    .leaflet-control-container {
        z-index: 2000 !important;
    }
    
    .leaflet-control-zoom,
    .leaflet-control-attribution {
        z-index: 2000 !important;
    }
    
    /* Map legend should be below Leaflet controls */
    .map-legend {
        z-index: 1500 !important;
    }
    
    /* Markers should be below controls but above map tiles */
    .leaflet-marker-pane {
        z-index: 1000 !important;
    }
    
    /* Popups should be above everything except controls */
    .leaflet-popup-pane {
        z-index: 1800 !important;
    }
    
    /* Ensure map container doesn't interfere */
    #map {
        z-index: 1 !important;
    }
}

/* Cookie banner on mobile */
.cookie-banner {
    touch-action: pan-y !important;
}

/* Mobile drawer/panel touch optimizations */
.mobile-drawer,
.mobile-panel {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* Enhanced focus indicators for all filter controls */
.filter-group input[type="checkbox"]:focus,
.filter-group button:focus,
#search-input:focus,
#distance-slider:focus,
.quick-filter-btn:focus {
    outline: 3px solid #003DA5;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(6, 95, 70, 0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .filter-group input[type="checkbox"]:focus,
    .filter-group button:focus {
        outline: 4px solid currentColor;
        outline-offset: 2px;
    }
}

/* Visual indication for active filters */
.filter-group.has-active-filters {
    position: relative;
}

.filter-group.has-active-filters::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: #003DA5;
    border-radius: 2px;
}

/* Skip link for keyboard navigation */
.filter-skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    padding: 0.5rem 1rem;
    background: #003DA5;
    color: white;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}

.filter-skip-link:focus {
    left: 0;
}

/* Improved checkbox styling for better visibility */
.filter-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    cursor: pointer;
}

.filter-group label {
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 6px 0;
    transition: background-color 0.2s ease;
}

.filter-group label:hover {
    background-color: rgba(6, 95, 70, 0.05);
    margin-left: -8px;
    margin-right: -8px;
    padding-left: 8px;
    padding-right: 8px;
    border-radius: 4px;
}

/* Clear visual state for toggle buttons */
.quick-filter-btn[aria-pressed="true"] {
    background-color: #003DA5;
    color: white;
    font-weight: 600;
}

.quick-filter-btn[aria-pressed="false"] {
    background-color: #f3f4f6;
    color: #374151;
}

/* Loading states for filters */
.filter-group.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.filter-group.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #003DA5;
    border-top-color: transparent;
    border-radius: 50%;
    animation: filter-spin 0.8s linear infinite;
}

@keyframes filter-spin {
    to { transform: rotate(360deg); }
}

/* Error states */
.filter-error {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.filter-error::before {
    content: '⚠️';
}

/* Success feedback */
.filter-success {
    color: #8B5CF6;
    font-size: 0.875rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.filter-success::before {
    content: '✓';
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .filter-group label,
    .quick-filter-btn {
        transition: none;
    }
    
    @keyframes filter-spin {
        to { transform: none; }
    }
}

/* Touch target improvements for mobile */
@media (max-width: 768px) {
    .filter-group label {
        min-height: 44px; /* iOS recommended touch target */
        padding: 10px 0;
    }
    
    .quick-filter-btn {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    .filter-group input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible polyfill for better browser support */
.js-focus-visible :focus:not(.focus-visible) {
    outline: none;
}

.js-focus-visible .focus-visible {
    outline: 3px solid #003DA5;
    outline-offset: 2px;
}

/* ===== LEGACY CLEANUP ===== */
/* Legacy System .filter-drawer removed - Enhanced System now handles mobile filtering */