/**
 * Mobile Filter Styles
 * 
 * Touch-optimized interface with bottom sheet modal, gesture support,
 * and safe-area-inset handling for notched devices.
 *
 * @package Advanced_Woo_Filters
 * @since   1.1.0
 */

/* ============================================
   MOBILE TRIGGER BUTTON
   ============================================ */

.awf-mobile-trigger-wrapper {
    display: none;
    position: sticky;
    top: 0;
    z-index: 999;
    margin-bottom: 16px;
    background: #fff;
    padding: 12px 0;
    border-bottom: 1px solid #e0e0e0;
}

.awf-mobile-trigger-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    background: #007cba;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px; /* iOS touch target minimum */
}

.awf-mobile-trigger-button:active {
    transform: scale(0.98);
    background: #006ba1;
}

.awf-mobile-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.awf-mobile-trigger-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #fff;
    color: #007cba;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 700;
}

/* Show trigger on mobile */
@media (max-width: 768px) {
    .awf-mobile-trigger-wrapper {
        display: block;
    }
}

/* ============================================
   BOTTOM SHEET MODAL
   ============================================ */

.awf-mobile-bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.awf-mobile-bottom-sheet[aria-hidden="false"] {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.awf-mobile-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.awf-mobile-bottom-sheet[aria-hidden="false"] .awf-mobile-backdrop {
    opacity: 1;
}

/* ============================================
   SHEET CONTAINER
   ============================================ */

.awf-mobile-sheet-container {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    
    /* Safe area insets for notched devices */
    padding-bottom: env(safe-area-inset-bottom);
}

.awf-mobile-bottom-sheet[aria-hidden="false"] .awf-mobile-sheet-container {
    transform: translateY(0);
}

/* Expanded state (full height) */
.awf-mobile-sheet-container.awf-expanded {
    max-height: calc(100vh - 60px);
}

/* ============================================
   DRAG HANDLE
   ============================================ */

.awf-mobile-sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.awf-mobile-sheet-handle:active {
    cursor: grabbing;
}

.awf-mobile-handle-bar {
    width: 40px;
    height: 4px;
    background: #d0d0d0;
    border-radius: 2px;
    transition: background-color 0.2s ease;
}

.awf-mobile-sheet-handle:hover .awf-mobile-handle-bar,
.awf-mobile-sheet-handle:focus .awf-mobile-handle-bar {
    background: #a0a0a0;
}

/* ============================================
   HEADER
   ============================================ */

.awf-mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.awf-mobile-sheet-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #333;
}

.awf-mobile-sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    background: transparent;
    border: none;
    color: #666;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.awf-mobile-sheet-close:active {
    background: #f0f0f0;
}

/* ============================================
   CONTENT AREA
   ============================================ */

.awf-mobile-sheet-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Optimize filter groups for mobile */
.awf-mobile-sheet-content .awf-filter-group {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e0e0e0;
}

.awf-mobile-sheet-content .awf-filter-group:last-child {
    border-bottom: none;
}

.awf-mobile-sheet-content .awf-filter-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px 0;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.awf-mobile-sheet-content .awf-filter-title::after {
    content: '\25BC'; /* Down arrow */
    font-size: 12px;
    color: #999;
    transition: transform 0.2s ease;
}

.awf-mobile-sheet-content .awf-filter-group.awf-collapsed .awf-filter-title::after {
    transform: rotate(-90deg);
}

.awf-mobile-sheet-content .awf-filter-group.awf-collapsed .awf-filter-options {
    display: none;
}

/* Increase touch targets for mobile */
.awf-mobile-sheet-content input[type="checkbox"],
.awf-mobile-sheet-content input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
}

.awf-mobile-sheet-content label {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    font-size: 15px;
}

/* ============================================
   FOOTER WITH ACTION BUTTONS
   ============================================ */

.awf-mobile-sheet-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    background: #fff;
    flex-shrink: 0;
    
    /* Safe area inset for home indicator area */
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.awf-mobile-sheet-clear {
    flex: 0 0 auto;
    padding: 12px 16px;
    background: transparent;
    color: #666;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.awf-mobile-sheet-clear:active {
    background: #f0f0f0;
}

.awf-mobile-sheet-apply {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: #007cba;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.awf-mobile-sheet-apply:active {
    transform: scale(0.98);
    background: #006ba1;
}

.awf-mobile-apply-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
}

/* Loading state */
.awf-mobile-sheet-apply.awf-loading {
    pointer-events: none;
    opacity: 0.7;
}

.awf-mobile-sheet-apply.awf-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: awf-spin 0.6s linear infinite;
}

@keyframes awf-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   GESTURE INDICATORS
   ============================================ */

.awf-mobile-sheet-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #007cba, #0096dc);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.awf-mobile-sheet-container.awf-dragging::before {
    transform: scaleX(1);
}

/* ============================================
   ANIMATIONS
   ============================================ */

/* Slide up animation */
@keyframes awf-slide-up {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Fade in backdrop */
@keyframes awf-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
.awf-mobile-trigger-button:focus-visible,
.awf-mobile-sheet-close:focus-visible,
.awf-mobile-sheet-clear:focus-visible,
.awf-mobile-sheet-apply:focus-visible {
    outline: 3px solid #007cba;
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .awf-mobile-bottom-sheet,
    .awf-mobile-backdrop,
    .awf-mobile-sheet-container,
    .awf-mobile-trigger-button,
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .awf-mobile-trigger-wrapper,
    .awf-mobile-sheet-container,
    .awf-mobile-sheet-header,
    .awf-mobile-sheet-footer {
        background: #1a1a1a;
        color: #fff;
        border-color: #333;
    }
    
    .awf-mobile-sheet-title,
    .awf-mobile-sheet-content .awf-filter-title {
        color: #fff;
    }
    
    .awf-mobile-backdrop {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .awf-mobile-handle-bar {
        background: #555;
    }
    
    .awf-mobile-sheet-close {
        color: #aaa;
    }
    
    .awf-mobile-sheet-close:active,
    .awf-mobile-sheet-clear:active {
        background: #2a2a2a;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    .awf-mobile-sheet-container {
        max-height: 90vh;
    }
    
    .awf-mobile-sheet-content {
        padding: 16px 20px;
    }
    
    .awf-mobile-sheet-footer {
        padding: 12px 20px;
    }
}

/* ============================================
   SMALL DEVICES
   ============================================ */

@media (max-width: 480px) {
    .awf-mobile-sheet-header,
    .awf-mobile-sheet-footer,
    .awf-mobile-sheet-content {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .awf-mobile-sheet-title {
        font-size: 18px;
    }
}

/* ============================================
   HIDE ON DESKTOP
   ============================================ */

@media (min-width: 769px) {
    .awf-mobile-trigger-wrapper,
    .awf-mobile-bottom-sheet {
        display: none !important;
    }
}

/* ============================================
   MOBILE RANGE SLIDER ENHANCEMENTS
   ============================================ */

@media (max-width: 768px) {
    
    .awf-mobile-sheet-content .awf-range-slider-wrapper {
        padding: 16px;
        margin: 16px 0;
    }
    
    .awf-mobile-sheet-content .awf-range-slider-container {
        height: 48px;
        padding: 0 8px;
    }
    
    .awf-mobile-sheet-content .awf-range-thumb {
        height: 48px;
        touch-action: pan-y;
        -webkit-tap-highlight-color: transparent;
    }
    
    .awf-mobile-sheet-content .awf-range-track {
        height: 8px;
        border-radius: 4px;
    }
    
    /* Larger thumbs for mobile */
    .awf-mobile-sheet-content .awf-range-thumb::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
        border: 4px solid #fff;
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    
    .awf-mobile-sheet-content .awf-range-thumb::-moz-range-thumb {
        width: 28px;
        height: 28px;
        border: 4px solid #fff;
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    
    /* Touch feedback */
    .awf-mobile-sheet-content .awf-range-thumb:active::-webkit-slider-thumb {
        transform: scale(1.15);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        background: #006ba1;
    }
    
    .awf-mobile-sheet-content .awf-range-thumb:active::-moz-range-thumb {
        transform: scale(1.15);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        background: #006ba1;
    }
    
    /* GPU acceleration */
    .awf-mobile-sheet-content .awf-range-thumb,
    .awf-mobile-sheet-content .awf-range-track-fill {
        will-change: transform;
        transform: translateZ(0);
    }
}

@media (max-width: 480px) {
    .awf-mobile-sheet-content .awf-range-thumb::-webkit-slider-thumb {
        width: 32px;
        height: 32px;
    }
    
    .awf-mobile-sheet-content .awf-range-thumb::-moz-range-thumb {
        width: 32px;
        height: 32px;
    }
}