/* ============================================
   MOBILE RESPONSIVE DESIGN
   ============================================ */

/* Tablets and small laptops */
@media (max-width: 1024px) {
    .filters {
        gap: 12px;
    }
    
    .filter-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Mobile phones - controls at bottom */
@media (max-width: 768px) {
    body {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    /* Draggable bottom sheet for controls */
    .controls-panel {
        order: 2;
        padding: 0;
        max-height: 85vh;
        position: fixed;
        bottom: 60px; /* Account for bottom navigation bar */
        left: 0;
        right: 0;
        z-index: 1000;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    /* Hidden state - only drag handle visible (full map view) */
    .controls-panel.hidden {
        transform: translateY(calc(100% - 40px));
    }
    
    /* Expanded state - all filters visible (default) */
    /* No transform needed - this is the default expanded state */
    
    /* Map takes full height */
    #map {
        order: 1;
        height: 100vh !important;
        width: 100%;
    }
    
    /* Compact timeline with purple margins visible */
    .timeline-container {
        padding: 10px 12px;
        margin: 0 8px 8px 8px;
    }
    
    .timeline-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
    }
    
    .date-range {
        font-size: 13px;
        flex: 1;
    }
    
    .race-count {
        font-size: 11px;
        padding: 4px 10px;
    }
    
    /* My Races View - Mobile optimizations */
    .favorites-header {
        padding: 12px 16px;
    }
    
    .favorites-header h2 {
        font-size: 20px;
    }
    
    .favorites-count {
        font-size: 13px;
    }
    
    .list-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    /* Status filters - full width scroll */
    .status-filters-container {
        margin: 0 -16px;
        padding: 0 16px;
        gap: 8px;
    }
    
    .status-filters-label {
        font-size: 11px;
        padding-left: 0;
    }
    
    .status-filters {
        gap: 6px;
    }
    
    .status-filter-btn {
        flex-direction: column;
        padding: 6px 8px;
        font-size: 18px;
        min-height: 50px;
        min-width: 50px;
        gap: 2px;
    }
    
    /* Hide text labels on mobile, show only icons */
    .status-filter-btn .filter-text {
        display: none;
    }
    
    .status-filter-btn .filter-icon {
        display: inline;
    }
    
    .status-filter-btn .filter-count {
        font-size: 10px;
        padding: 2px 5px;
        min-width: 18px;
        margin-top: -2px;
    }
    
    /* Sort buttons - full width scroll */
    .list-sort {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
        gap: 6px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .list-sort::-webkit-scrollbar {
        display: none;
    }
    
    .list-sort span {
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .favorites-sort-btn {
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    /* Preset buttons - 3 per row */
    .preset-buttons {
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 12px;
    }
    
    .filter-label {
        width: 100%;
        margin-bottom: 6px;
    }
    
    .preset-btn, .custom-badge {
        padding: 8px 10px;
        font-size: 11px;
        flex: 1 1 calc(33.33% - 4px);
        min-width: calc(33.33% - 4px);
        text-align: center;
    }
    
    /* Bigger slider thumb for mobile touch */
    .slider-input::-webkit-slider-thumb {
        width: 32px;
        height: 32px;
        border-width: 4px;
    }
    
    .slider-input::-moz-range-thumb {
        width: 32px;
        height: 32px;
        border-width: 4px;
    }
    
    .timeline-slider {
        height: 55px;
        margin-bottom: 8px;
    }
    
    /* Month labels - show fewer */
    .month-labels {
        font-size: 9px;
        margin-top: 8px;
    }
    
    .month-labels span:nth-child(2n) {
        display: none; /* Hide every other month */
    }
    
    /* Stack filters vertically */
    .filters {
        flex-direction: column;
        gap: 12px;
        margin-top: 12px;
        padding: 0 12px;
    }
    
    .filter-group {
        flex-wrap: wrap;
        gap: 6px;
        align-items: flex-start;
    }
    
    .filter-label {
        font-size: 12px;
        font-weight: 600;
    }
    
    .filter-btn {
        padding: 10px 12px;
        font-size: 11px;
        flex: 1 1 calc(50% - 3px);
        min-width: calc(50% - 3px);
        text-align: center;
    }
    
    /* Distance buttons - 2 per row */
    .filter-group:has([data-distance]) .filter-btn {
        min-width: calc(50% - 3px);
    }
    
    /* Elevation buttons - 2 per row */
    .filter-group:has([data-elevation]) .filter-btn {
        min-width: calc(50% - 3px);
    }
    
    /* ITRA difficulty buttons - 3 per row (smaller) */
    .filter-group:has([data-effort]) .filter-btn {
        flex: 1 1 calc(33.33% - 4px);
        min-width: calc(33.33% - 4px);
        padding: 8px 8px;
    }
    
    /* Carbon slider full width */
    .filter-group:has(#carbonBudget) {
        flex-direction: column;
    }
    
    .filter-group:has(#carbonBudget) > div {
        width: 100%;
    }
    
    .carbon-slider {
        width: 100%;
    }
    
    .carbon-value {
        font-size: 11px;
        padding: 4px 10px;
        margin-top: 8px;
    }
    
    .carbon-status {
        font-size: 10px;
        margin-top: 6px;
    }
    
    /* Location button full width */
    .filter-group:has(#getUserLocation) {
        flex-direction: column;
    }
    
    #getUserLocation {
        width: 100%;
        padding: 12px;
        font-size: 13px;
    }
    
    .location-status {
        font-size: 10px;
        margin-left: 0;
        margin-top: 6px;
        width: 100%;
    }
    
    /* Custody buttons - 2 per row */
    .filter-group:has([data-custody]) .filter-btn {
        min-width: calc(50% - 3px);
    }
    
    /* Race popup adjustments */
    .race-popup {
        min-width: 200px;
        max-width: 280px;
    }
    
    .race-popup h3 {
        font-size: 14px;
    }
    
    .race-info {
        font-size: 11px;
    }
    
    .carbon-badge {
        font-size: 10px;
        padding: 3px 8px;
    }
}

/* Very small phones (iPhone SE, etc) */
@media (max-width: 375px) {
    .controls-panel {
        padding: 10px;
    }
    
    .preset-btn, .custom-badge {
        font-size: 10px;
        padding: 7px 8px;
    }
    
    .filter-btn {
        font-size: 10px;
        padding: 9px 10px;
    }
    
    .date-range {
        font-size: 12px;
    }
    
    .race-count {
        font-size: 10px;
        padding: 3px 8px;
    }
    
    .filter-label {
        font-size: 11px;
    }
    
    /* ITRA buttons even more compact */
    .filter-group:has([data-effort]) .filter-btn {
        padding: 7px 6px;
        font-size: 10px;
    }
}

/* Touch-friendly improvements for all mobile devices */
@media (hover: none) and (pointer: coarse) {
    /* Ensure minimum touch target sizes */
    .filter-btn {
        min-height: 44px; /* Apple's recommended touch target */
    }
    
    .preset-btn, .custom-badge {
        min-height: 40px;
    }
    
    #getUserLocation {
        min-height: 48px;
    }
    
    /* Bigger map controls for touch */
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out {
        width: 40px !important;
        height: 40px !important;
        line-height: 40px !important;
        font-size: 22px !important;
    }
    
    .leaflet-control-attribution {
        font-size: 9px !important;
        padding: 2px 5px !important;
    }
    
    /* Prevent text selection during dragging */
    .slider-range,
    .range-handle {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Mobile-friendly touch targets for status buttons */
    .race-status-star,
    .race-status-registered,
    .race-card-delete-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }
    
    .race-status-planned-wrapper {
        padding: 8px;
        min-height: 40px;
    }
    
    .race-status-planned-checkbox {
        width: 20px;
        height: 20px;
    }
    
    /* List view and My Races mobile buttons */
    .race-card-favorite,
    .race-card-map-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
        font-size: 22px;
    }
    
    /* Remove hover effects on mobile (use active instead) */
    .race-status-star:active,
    .race-status-registered:active:not(:disabled) {
        transform: scale(0.95);
        background: rgba(0, 0, 0, 0.1);
    }
    
    .race-card-delete-btn:active {
        transform: scale(0.95);
        background: rgba(220, 53, 69, 0.2);
    }
    
    .race-card-favorite:active {
        transform: scale(0.95);
        background: rgba(255, 215, 0, 0.15);
    }
    
    .race-card-map-btn:active {
        transform: scale(0.95);
        background: rgba(0, 0, 0, 0.15);
    }
    
    /* Empty state on mobile */
    .favorites-empty {
        padding: 30px 16px;
    }
    
    .favorites-empty-icon {
        font-size: 48px;
    }
    
    .favorites-empty-title {
        font-size: 18px;
    }
    
    .favorites-empty-text {
        font-size: 14px;
    }
    
    .favorites-empty-steps {
        gap: 12px;
    }
    
    .empty-step {
        padding: 10px;
    }
    
    .empty-step-icon {
        font-size: 20px;
    }
    
    .empty-step-text {
        font-size: 13px;
    }
    
    .favorites-empty-hint {
        font-size: 12px;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .controls-panel {
        max-height: 50vh; /* More space for controls in landscape */
    }
    
    .preset-buttons {
        gap: 4px;
    }
    
    .preset-btn, .custom-badge {
        font-size: 10px;
        padding: 6px 8px;
        min-height: 36px;
    }
}
