/* ==========================================================================
   PRODUCT FILTER MENU STYLES
   Scopes: .custom-filter, #desktop-filter, #popup-filter
   ========================================================================== */

/* ---------------------------------------- */
/* 1. BASE STRUCTURE & RESET */
/* ---------------------------------------- */

.custom-filter ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.custom-filter ul li {
    padding-left: 5px;
    margin-bottom: 10px;
}

/* Filter Groups (Containers for each attribute/price section) */
.custom-filter .filter-group {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd; /* Light gray line */
}

/* Remove border from the last filter group */
.custom-filter .filter-group:last-child {
    border-bottom: none;
}

/* Filter Headings (Toggle Titles) */
.custom-filter h4.filter-toggle {
    margin-bottom: 10px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ---------------------------------------- */
/* 2. SELECTED COUNT BUBBLES */
/* ---------------------------------------- */

.custom-filter .filter-group .selected-count {
    background: #eee;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.2;
    font-weight: bold;
    display: none; /* Hidden by default */
}

/* 🏆 CRITICAL FIX: Force visibility when active */
.custom-filter .filter-group .selected-count.is-active {
    display: inline-block !important;
}

/* ---------------------------------------- */
/* 3. CUSTOM CHECKBOX STYLING */
/* ---------------------------------------- */

.filter-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid #333;
    background-color: #fff;
    cursor: pointer;
    display: inline-block;
    vertical-align: middle;
    position: relative;
    border-radius: 0; /* Sharp edges */
    transition: background-color 0.2s ease;
}

.filter-checkbox:checked {
    background-color: #000;
}

.filter-checkbox:checked::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 14px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
    top: 40%;
    left: 50%;
}

.filter-checkbox + label,
.filter-checkbox + span,
.filter-checkbox + strong {
    font-size: 16px; /* Adjusted to match typical body text */
    font-weight: 500;
    vertical-align: middle;
    cursor: pointer;
}

/* ---------------------------------------- */
/* 4. LAYOUT & SCROLLING (DESKTOP) */
/* ---------------------------------------- */

/* Style for the filter menu when it's loading */
#desktop-filter.is-loading {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}

.custom-filter-scroll {
    max-height: 900px; /* Default height for desktop */
    overflow-y: auto;
    padding-right: 10px;
}

/* Tablet adjustments */
@media (max-width: 1384px) {
    .custom-filter-scroll {
        max-height: 400px;
    }
}

/* "Scroll to see more" fade effect */
.custom-filter-wrapper {
    position: relative;
}

.custom-filter-wrapper::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: linear-gradient(to bottom, transparent, white);
    pointer-events: none;
}

/* Custom Scrollbar Styling */
.custom-filter-scroll::-webkit-scrollbar {
    width: 7px;
}
.custom-filter-scroll::-webkit-scrollbar-track {
    background: #f0f0f0; 
    border-radius: 10px;
}
.custom-filter-scroll::-webkit-scrollbar-thumb {
    background: #888; 
    border-radius: 10px;
}
.custom-filter-scroll::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ---------------------------------------- */
/* 5. FILTER CHIPS (ACTIVE SELECTIONS) */
/* ---------------------------------------- */

#active-filter-chips {
    user-select: none;
    caret-color: transparent;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-behavior: smooth;
    gap: 10px;
    max-width: 100%;
    padding-bottom: 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#active-filter-chips::-webkit-scrollbar {
    height: 2px;
}

#active-filter-chips::-webkit-scrollbar-track {
    background: transparent;
}

#active-filter-chips::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.filter-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #f0f0f0;
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
    margin-bottom: 3px;
}

.filter-chip .remove-chip {
    cursor: pointer;
    font-weight: bold;
    color: #000;
    transition: color 0.2s ease;
}

.filter-chip .remove-chip:hover {
    color: #555;
}

/* ---------------------------------------- */
/* 6. PRICE SLIDER STYLES (SHARED) */
/* ---------------------------------------- */

/* Shared styles for both #desktop-filter and #popup-filter */
.price-slider-wrapper {
    position: relative;
    height: 40px;
    margin-bottom: 10px;
}

.range-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    -webkit-appearance: none;
    background: none;
}

.range-slider::-webkit-slider-thumb {
    pointer-events: auto;
    position: relative;
    z-index: 2;
    height: 16px;
    width: 16px;
    background: #dd0000;
    border-radius: 50%;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
}

.range-slider::-moz-range-thumb {
    pointer-events: auto;
    position: relative;
    z-index: 2;
    height: 16px;
    width: 16px;
    background: #dd0000;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.range-slider::-webkit-slider-runnable-track {
    height: 4px;
    background: #ccc;
    border-radius: 3px;
}

.range-slider::-moz-range-track {
    height: 4px;
    background: #ccc;
    border-radius: 3px;
}

.slider-track-fill {
    position: absolute;
    height: 4px;
    background: #dd0000;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    border-radius: 3px;
}

.slider-thumb-value {
    position: absolute;
    top: -30px;
    transform: translateX(-50%);
    font-size: 13px;
    background: #222;
    color: #fff;
    padding: 4px 6px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 4;
}

.slider-thumb-value.right-align {
    transform: none;
    right: 0;
    left: auto;
}

.slider-thumb-value::after {
    content: "";
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px 4px 0 4px;
    border-style: solid;
    border-color: #222 transparent transparent transparent;
}

/* ---------------------------------------- */
/* 7. MOBILE POPUP & BUTTONS */
/* ---------------------------------------- */

/* Filter Button (Trigger) */
.custom-mobile-filter-btn {
    display: none;
    width: 100%;
    background-color: #fff;
    color: #000;
    font-size: 15px;
    font-weight: bold;
    border: 2px solid #000;
    border-radius: 1px;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.custom-mobile-filter-btn:active {
    background-color: #000;
    color: #fff;
    border: 2px solid #000;
}

@media (max-width: 1384px) {
    .custom-mobile-filter-btn {
        display: inline-flex;
    }
}

.custom-mobile-filter-btn .filter-icon {
    width: 20px;
    height: 20px;
}

/* Popup Overlay */
body.popup-open {
    overflow: hidden;
    touch-action: none;
    height: 100vh;
}

.custom-popup-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    justify-content: center;
    align-items: center;
}

/* Popup Content Box */
.custom-popup-content {
    position: fixed;
    top: var(--popup-top-offset, 150px);
    bottom: 60px; /* Space for sticky buttons */
    left: 0;
    width: 100vw;
    background: #fff;
    padding: 20px;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    z-index: 9999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

.custom-popup-content::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: linear-gradient(to bottom, transparent, white);
    pointer-events: none;
}

/* Close Button (X) */
.close-button-wrapper {
    padding-bottom: 80px;
}

#close-popup {
    display: block !important;
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 22px;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10000;
    color: #000;
}

/* Sticky Bottom Buttons (Apply / Clear) */
.filter-buttons-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    background-color: #fff;
    padding: 10px 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.filter-buttons-fixed button {
    flex: 1;
    padding: 10px 16px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 1px;
    cursor: pointer;
    border: 2px solid black;
    transition: all 0.3s ease-in-out;
}

#clear-filters {
    background-color: white;
    color: black;
}
#apply-filters {
    background-color: black;
    color: white;
}

/* Loading Spinner */
#apply-filters .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-top-color: #000;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

/* Disabled States */
#apply-filters.disabled,
#clear-filters.disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

#popup-filter.disabled {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#popup-filter.disabled * {
    cursor: not-allowed !important;
}

/* Hide Popup on Desktop */
@media (min-width: 1385px) {
    #custom-filter-popup {
        display: none !important;
        visibility: hidden;
        pointer-events: none;
        height: 0;
        overflow: hidden;
    }
}