/**
 * PPServis Catalog - Mobile Filters
 * Responsive filter drawer and sort modal for mobile devices
 */

/* =============================================================================
   Mobile Filter Bar - Sticky Top Buttons
   ============================================================================= */

.mobile-filter-bar {
    display: none; /* Hidden on desktop */
}

@media (max-width: 767px) {
    /* Show mobile filter bar */
    .mobile-filter-bar {
        display: flex;
        gap: 8px;
        padding: 8px 0;
        position: sticky;
        top: 0;
        z-index: 999;
    }

    /* Mobile buttons */
    .mobile-btn {
        flex: 1;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #fff !important;
        border: 1px solid #EAEAEA !important;
        border-radius: 5px !important;
        padding: 16px 20px !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        color: #636363 !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        min-height: 48px !important; /* Touch-friendly */
    }

    .mobile-btn:hover,
    .mobile-btn:active {
        background: #f9f9f9;
        border-color: #d0d0d0;
    }

    .mobile-btn-content {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-btn-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 16px;
        height: 16px;
    }

    .mobile-btn-icon svg {
        width: 100%;
        height: 100%;
        color: #636363;
    }

    .mobile-btn-text {
        position: relative;
    }

    /* Filter badge */
    .filter-badge {
        display: inline-block;
        min-width: 18px;
        height: 18px;
        line-height: 18px;
        padding: 0 5px;
        margin-left: 6px;
        background: #FF4444;
        color: #fff;
        font-size: 11px;
        font-weight: 600;
        border-radius: 9px;
        text-align: center;
    }

    /* Hide desktop filters and ordering in their original location */
    body > .ppservis-filters,
    .elementor-widget-container > .ppservis-filters,
    aside .ppservis-filters {
        display: none !important;
    }

    body > .wpd-ordering,
    .elementor-widget-container > .wpd-ordering {
        display: none !important;
    }

    /* Show filters when moved inside drawer/modal - override ALL positioning */
    .filter-drawer .ppservis-filters {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        max-height: none !important;
        position: static !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: 100% !important;
        max-width: none !important;
        transform: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        background: transparent !important;
        z-index: auto !important;
        overflow: visible !important;
    }

    .sort-modal .wpd-ordering {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        transform: none !important;
    }
}

/* =============================================================================
   Filter Drawer - Bottom Slide-up Panel
   ============================================================================= */

@media (max-width: 767px) {
    .filter-drawer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 85vh;
        max-height: 85vh;
        background: #fff;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s ease-out;
        z-index: 10001;
        display: flex;
        flex-direction: column;
    }

    .filter-drawer.open {
        transform: translateY(0);
    }

    /* Drawer header */
    .filter-drawer.open .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px;
        border-bottom: 1px solid #EAEAEA;
        flex-shrink: 0;
    }

    .filter-drawer.open .drawer-header h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: #333;
    }

    .filter-drawer.open .close-drawer {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 32px;
        padding: 0;
        background: transparent;
        border: none;
        cursor: pointer;
        color: #666;
        transition: color 0.2s ease;
    }

    .filter-drawer.open .close-drawer:hover {
        color: #333;
    }

    .filter-drawer.open .close-drawer svg {
        width: 20px;
        height: 20px;
    }

    /* Drawer content - scrollable */
    .drawer-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
    }

    /* Make filters more touch-friendly in drawer */
    .drawer-content .ppservis-filters {
        display: block !important;
    }

    .drawer-content .filter-section {
        margin-bottom: 24px;
    }

    .drawer-content .filter-section h4 {
        font-size: 15px;
        font-weight: 600;
        color: #333;
        margin-bottom: 12px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .drawer-content label {
        min-height: 44px; /* Touch-friendly */
        display: flex;
        align-items: center;
        padding: 8px 0;
    }

    .drawer-content input[type="checkbox"] {
        width: 20px;
        height: 20px;
        margin-right: 12px;
        cursor: pointer;
    }

    /* Price slider adjustments for drawer */
    .drawer-content .price-slider-handle-min,
    .drawer-content .price-slider-handle-max {
        width: 24px;
        height: 24px;
        margin-left: -12px;
    }

    /* Drawer footer - sticky buttons */
    .drawer-footer {
        display: flex;
        gap: 12px;
        padding: 16px 20px;
        border-top: 1px solid #EAEAEA;
        background: #fff;
        flex-shrink: 0;
    }

    .drawer-footer button {
        flex: 1;
        height: 48px;
        border: none;
        border-radius: 5px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .filter-drawer.open .clear-filters-btn {
        background: #fff;
        color: #00688D;
        border: 1px solid #EAEAEA !important;
    }

    .filter-drawer.open .clear-filters-btn:hover {
        background: #fff;
    }

    .filter-drawer.open .apply-filters-btn {
            background: white;
            color: #8ab822 !important;
            padding: 8px 20px !important;
            border: 2px solid #8ab822 !important;
            border-radius: 4px !important;
            width: 100px;
            text-decoration: none;
            font-weight: bold;
            font-size: 1rem !important;
            text-transform: uppercase;
    }

    .filter-drawer.open .apply-filters-btn:hover {
        background: #3a7bc8;
    }

    /* Drawer overlay */
    .drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 10000;
    }

    .drawer-overlay.open {
        opacity: 1;
        visibility: visible;
    }

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

/* =============================================================================
   Sort Modal - Bottom Sheet for Ordering
   ============================================================================= */

@media (max-width: 767px) {
    .sort-modal {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s ease-out;
        z-index: 10001;
        max-height: 50vh;
    }

    .sort-modal.open {
        transform: translateY(0);
    }

    /* Modal header */
    .sort-modal.open .modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px;
        border-bottom: 1px solid #EAEAEA;
    }

    .sort-modal.open .modal-header h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: #333;
    }

    .sort-modal.open .close-modal {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 32px;
        padding: 0;
        background: transparent;
        border: none;
        cursor: pointer;
        color: #666;
        transition: color 0.2s ease;
    }

    .sort-modal.open .close-modal:hover {
        color: #333;
    }

    .sort-modal.open .close-modal svg {
        width: 20px;
        height: 20px;
    }

    /* Modal content */
    .modal-content {
        padding: 20px;
    }

    .modal-content .wpd-ordering {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
    }

    .modal-content .order-btn {
        width: 100%;
        min-height: 48px;
        padding: 12px 20px;
        background: #fff;
        border: 1px solid #EAEAEA;
        border-radius: 5px;
        color: #636363;
        font-size: 15px;
        font-weight: 500;
        text-align: left;
        cursor: pointer;
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
    }

    .modal-content .order-btn:hover {
        background: #f9f9f9;
        border-color: #d0d0d0;
    }

    .modal-content .order-btn.active {
        background: #4A90E2;
        color: #fff;
        border-color: #4A90E2;
    }

    .modal-content .order-btn.active::before {
        content: '✓ ';
        margin-right: 8px;
        font-weight: 700;
    }

    /* Modal overlay */
    .modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 10000;
    }

    .modal-overlay.open {
        opacity: 1;
        visibility: visible;
    }

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

/* =============================================================================
   Tablet Adjustments (768px - 1024px)
   ============================================================================= */

@media (min-width: 768px) and (max-width: 1024px) {
    /* On tablet, keep desktop layout but make it more compact */
    .ppservis-filters {
        font-size: 14px;
    }

    .filter-section label {
        min-height: 36px;
    }

    .wpd-ordering .order-btn {
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* =============================================================================
   Accessibility & Touch Improvements
   ============================================================================= */

@media (max-width: 767px) {
    /* Larger touch targets */
    .mobile-btn,
    .drawer-content label,
    .modal-content .order-btn {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
    }

    /* Smooth scrolling */
    .drawer-content,
    .modal-content {
        scroll-behavior: smooth;
    }

    /* Focus states for keyboard navigation */
    .filter-drawer.open .mobile-btn:focus,
    .filter-drawer.open .close-drawer:focus,
    .filter-drawer.open .close-modal:focus,
    .filter-drawer.open .apply-filters-btn:focus,
    .filter-drawer.open .clear-filters-btn:focus {
        outline: 2px solid #4A90E2;
        outline-offset: 2px;
    }

    /* Loading state */
    .drawer-content.loading::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 40px;
        height: 40px;
        margin: -20px 0 0 -20px;
        border: 3px solid #f3f3f3;
        border-top: 3px solid #4A90E2;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
}

/* =============================================================================
   Small Mobile (< 375px)
   ============================================================================= */

@media (max-width: 374px) {
    .mobile-btn {
        padding: 14px 16px;
        font-size: 13px;
    }

    .mobile-btn-icon {
        width: 14px;
        height: 14px;
    }

    .drawer-header h3,
    .modal-header h3 {
        font-size: 16px;
    }
}


/* =============================================================================
   Pagination - Mobile Optimizations
   ============================================================================= */

@media (max-width: 767px) {
    /* Make pagination more compact on mobile */
    .ppservis-pagination {
        margin: 1rem 0 !important;
    }

    .ppservis-pagination .page-numbers {
        gap: 0 !important;
    }

    .ppservis-pagination .page-numbers a,
    .ppservis-pagination .page-numbers span {
        min-width: 32px !important;
        height: 32px !important;
        font-size: 13px !important;
        padding: 0 4px !important;
    }

    /* Make arrows more prominent */
    .ppservis-pagination .pagination-prev,
    .ppservis-pagination .pagination-next {
        min-width: 36px !important;
        font-size: 16px !important;
        font-weight: bold;
    }
}

@media (max-width: 374px) {
    /* Extra small screens - even more compact */
    .ppservis-pagination .page-numbers a,
    .ppservis-pagination .page-numbers span {
        min-width: 28px !important;
        height: 28px !important;
        font-size: 12px !important;
    }

    .ppservis-pagination .pagination-prev,
    .ppservis-pagination .pagination-next {
        min-width: 32px !important;
        font-size: 14px !important;
    }
}
