/* ==========================================================================
   WooCommerce Filter Bar – LNH
   Optimized for Flatsome theme
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@400;500;600;700&display=swap');

/* ---------- Variables ---------- */
:root {
    --wfl-primary: #333;
    --wfl-primary-hover: #000;
    --wfl-border: #d5d5d5;
    --wfl-border-hover: #999;
    --wfl-bg: #fff;
    --wfl-bg-hover: #f7f7f7;
    --wfl-tag-bg: #f0f0f0;
    --wfl-tag-text: #333;
    --wfl-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    --wfl-radius: 4px;
    --wfl-font: 'Quicksand', sans-serif;
    --wfl-font-size: 13px;
    --wfl-transition: 0.2s ease;
    --wfl-accent: #2b6cb0;
    --wfl-clear-bg: #333;
    --wfl-clear-text: #fff;
}

/* ---------- Wrapper ---------- */
.wfl-filter-wrap {
    width: 100%;
    margin-bottom: 16px;
    font-family: var(--wfl-font);
    font-size: var(--wfl-font-size);
    line-height: 1.5;
    position: relative;
    z-index: 100;
    transition: box-shadow 0.3s ease;
}

/* Ensure filter wrap stays above backdrop when a dropdown is open */
.wfl-filter-wrap.wfl-dropdown-active {
    z-index: 10001;
    /* Higher than backdrop (9999) */
}

/* Sticky state – applied via JS on scroll down */
.wfl-filter-wrap.wfl-sticky {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    background: var(--wfl-bg);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    padding: 0 15px;
    animation: wfl-slide-down 0.3s ease;
}

/* Placeholder to prevent content jump when filter becomes fixed */
.wfl-sticky-placeholder {
    display: none;
}

.wfl-sticky-placeholder.wfl-active {
    display: block;
}

@keyframes wfl-slide-down {
    from {
        transform: translateY(-100%);
    }

    to {
        transform: translateY(0);
    }
}

/* Hide Flatsome sticky header when filter is sticky */
.wfl-header-hidden .header-wrapper.stuck {
    transform: translateY(-100%) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: transform 0.3s ease, opacity 0.3s ease !important;
}

/* ---------- Filter Bar ---------- */
.wfl-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--wfl-border);
}

.wfl-filter-bar-mobile-header {
    display: none;
}

.wfl-filter-bar-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.wfl-filter-bar-right {
    display: flex;
    align-items: center;
}

.wfl-filter-label,
.wfl-sort-label {
    font-size: var(--wfl-font-size);
    color: #666;
    white-space: nowrap;
    font-weight: 400;
}

/* ---------- Dropdown ---------- */
.wfl-dropdown {
    position: relative;
    display: inline-block;
}

.wfl-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--wfl-border);
    border-radius: var(--wfl-radius);
    background: var(--wfl-bg);
    color: var(--wfl-primary);
    font-size: var(--wfl-font-size);
    font-family: var(--wfl-font);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color var(--wfl-transition), background var(--wfl-transition);
    line-height: 1.4;
    outline: none;
}

.wfl-dropdown-toggle:hover {
    border-color: var(--wfl-border-hover);
    background: var(--wfl-bg-hover);
}

.wfl-dropdown-toggle.wfl-has-active {
    border-color: var(--wfl-accent);
    color: var(--wfl-accent);
}

.wfl-dropdown.wfl-open .wfl-dropdown-toggle {
    border-color: var(--wfl-border-hover);
    background: var(--wfl-bg-hover);
}

.wfl-chevron {
    width: 10px;
    height: 6px;
    transition: transform var(--wfl-transition);
    flex-shrink: 0;
}

.wfl-dropdown.wfl-open .wfl-chevron {
    transform: rotate(180deg);
}

.wfl-dropdown-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.wfl-count {
    font-weight: 600;
    font-size: 12px;
}

/* ---------- Dropdown Panel ---------- */
.wfl-dropdown-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--wfl-bg);
    border: 1px solid var(--wfl-border);
    border-radius: var(--wfl-radius);
    box-shadow: var(--wfl-shadow);
    z-index: 1000;
    padding: 6px 0;
}

.wfl-dropdown.wfl-open .wfl-dropdown-panel {
    display: block;
    animation: wfl-fade-in 0.15s ease;
}

/* Sort dropdown align right */
.wfl-dropdown-sort .wfl-dropdown-panel {
    left: auto;
    right: 0;
    min-width: 220px;
}

@keyframes wfl-fade-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar */
.wfl-dropdown-panel::-webkit-scrollbar {
    width: 5px;
}

.wfl-dropdown-panel::-webkit-scrollbar-track {
    background: transparent;
}

.wfl-dropdown-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ---------- Option List ---------- */
.wfl-option-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.wfl-option-item {
    margin: 0;
    padding: 0;
}

.wfl-checkbox-label,
.wfl-radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    transition: background var(--wfl-transition);
    font-size: var(--wfl-font-size);
    color: var(--wfl-primary);
    line-height: 1.4;
    user-select: none;
}

.wfl-checkbox-label:hover,
.wfl-radio-label:hover {
    background: var(--wfl-bg-hover);
}

/* Hide native checkbox/radio */
.wfl-filter-checkbox,
.wfl-filter-price,
.wfl-sort-radio {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* Custom checkmark */
.wfl-checkmark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 1.5px solid var(--wfl-border);
    border-radius: 3px;
    background: var(--wfl-bg);
    transition: all var(--wfl-transition);
    flex-shrink: 0;
}

.wfl-filter-checkbox:checked~.wfl-checkmark,
.wfl-filter-price:checked~.wfl-checkmark,
.wfl-sort-radio:checked~.wfl-checkmark {
    background: var(--wfl-accent);
    border-color: var(--wfl-accent);
}

.wfl-filter-checkbox:checked~.wfl-checkmark::after,
.wfl-filter-price:checked~.wfl-checkmark::after,
.wfl-sort-radio:checked~.wfl-checkmark::after {
    content: '';
    display: block;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -1px;
}

/* Radio variant – circle */
.wfl-radio-label .wfl-checkmark,
.wfl-filter-price~.wfl-checkmark {
    border-radius: 50%;
}

.wfl-sort-radio:checked~.wfl-checkmark::after,
.wfl-filter-price:checked~.wfl-checkmark::after {
    width: 6px;
    height: 6px;
    border: none;
    border-radius: 50%;
    background: #fff;
    transform: none;
    margin-top: 0;
}

.wfl-option-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wfl-option-count {
    color: #999;
    font-size: 12px;
    flex-shrink: 0;
}

/* ---------- Clear All Button ---------- */
.wfl-clear-all {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: none;
    border-radius: var(--wfl-radius);
    background: var(--wfl-clear-bg);
    color: var(--wfl-clear-text);
    font-size: var(--wfl-font-size);
    font-family: var(--wfl-font);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity var(--wfl-transition), background var(--wfl-transition);
    letter-spacing: 0.3px;
    line-height: 1.4;
}

.wfl-clear-all:hover {
    background: var(--wfl-primary-hover);
}

/* ---------- Active Tags ---------- */
.wfl-active-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
}

.wfl-active-label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.wfl-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--wfl-border);
    border-radius: 20px;
    background: var(--wfl-tag-bg);
    color: var(--wfl-tag-text);
    font-size: 12px;
    line-height: 1.4;
    white-space: nowrap;
}

.wfl-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #999;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: color var(--wfl-transition), background var(--wfl-transition);
}

.wfl-tag-remove:hover {
    color: #333;
    background: rgba(0, 0, 0, 0.08);
}

/* ---------- Hidden utility ---------- */
.wfl-hidden {
    display: none !important;
}

/* ---------- Loading overlay ---------- */
.wfl-loading-overlay {
    position: relative;
    pointer-events: none;
}

.wfl-loading-overlay::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 50;
}

.wfl-loading-overlay::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid var(--wfl-border);
    border-top-color: var(--wfl-accent);
    border-radius: 50%;
    z-index: 51;
    animation: wfl-spin 0.6s linear infinite;
}

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

/* ---------- No products ---------- */
.wfl-no-products {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}

/* ---------- Responsive ---------- */

/* Mobile Toggle Bar */
.wfl-mobile-toggle-bar {
    display: none;
    align-items: center;
    gap: 20px;
    padding: 10px 0;
    width: 100%;
}

.wfl-mobile-filter-open,
.wfl-mobile-sort-open {
    flex: 1;
    width: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 10px 15px;
    border: 1px solid var(--wfl-border);
    border-radius: var(--wfl-radius);
    background: var(--wfl-bg);
    color: var(--wfl-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--wfl-transition);
}

.wfl-mobile-filter-open:hover,
.wfl-mobile-sort-open:hover {
    border-color: var(--wfl-border-hover);
    background: var(--wfl-bg-hover);
}

@media (max-width: 768px) {
    .wfl-mobile-toggle-bar {
        display: flex;
    }

    .wfl-filter-label {
        display: none;
    }

    /* Ensure wrap is above backdrop on mobile */
    .wfl-drawer-active .wfl-filter-wrap {
        z-index: 1000000 !important;
    }

    .wfl-filter-bar {
        position: fixed;
        top: 0;
        bottom: 0;
        right: -320px;
        width: 300px;
        background: var(--wfl-bg);
        z-index: 100001;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 0;
        margin: 0;
        border: none;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
        transition: right 0.3s ease-in-out;
        overflow-y: auto;
    }

    body.wfl-drawer-active {
        overflow: hidden !important;
    }

    .wfl-filter-bar.wfl-open {
        right: 0 !important;
    }

    /* Drawer Header */
    .wfl-filter-bar-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px;
        border-bottom: 1px solid var(--wfl-border);
        background: var(--wfl-bg);
    }

    .wfl-mobile-drawer-title {
        font-size: 18px;
        font-weight: 600;
        margin: 0;
    }

    .wfl-mobile-drawer-close {
        background: none;
        border: none;
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
        padding: 0;
        color: #333;
    }

    .wfl-filter-bar-left {
        padding: 15px;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    /* Dropdown inside drawer */
    .wfl-dropdown {
        width: 100%;
        border-bottom: 1px solid #f0f0f0;
    }

    .wfl-dropdown-toggle {
        width: 100%;
        justify-content: space-between;
        border: none;
        padding: 15px 0;
        border-radius: 0;
        background: none !important;
    }

    .wfl-dropdown-panel {
        position: static;
        width: 100% !important;
        box-shadow: none;
        border: none;
        padding: 0 0 15px 10px;
        background: none;
        max-height: none;
    }

    .wfl-dropdown.wfl-open .wfl-dropdown-panel {
        display: block;
    }

    /* Desktop sort container hidden on mobile, but allowed to show its children when active */
    .wfl-filter-bar-right {
        position: absolute;
        width: 0;
        height: 0;
        overflow: visible;
        pointer-events: none;
    }

    .wfl-filter-bar-right .wfl-dropdown-toggle {
        display: none !important;
    }

    .wfl-dropdown-sort.wfl-mobile-active {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--wfl-bg);
        z-index: 100001;
        pointer-events: auto;
        border-radius: 12px 12px 0 0;
        border-top: 1px solid var(--wfl-border);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .wfl-dropdown-sort.wfl-mobile-active .wfl-dropdown-panel {
        display: block !important;
        position: static;
        max-height: 60vh;
        overflow-y: auto;
    }

    .wfl-dropdown-sort.wfl-mobile-active .wfl-dropdown-toggle {
        display: none;
    }

    /* Backdrop for mobile */
    .wfl-mobile-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99999;
    }
}

/* ---------- Flatsome compatibility ---------- */
.shop-page-title+.wfl-filter-wrap,
.category-page-title+.wfl-filter-wrap {
    margin-top: 0;
}

/* Fix Flatsome grid z-index */
.wfl-filter-wrap .wfl-dropdown-panel {
    z-index: 1000;
}

/* Ensure Flatsome product row transitions smoothly */
.products .row,
.products .row-special {
    transition: opacity 0.3s ease;
}

/* Flatsome pagination overrides */
.woocommerce-pagination .page-numbers {
    transition: none;
}

/* Flatsome header smooth restore */
.header-wrapper.stuck {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Theme compatibility & layout refinements */
button.wfl-dropdown-toggle,
.wfl-clear-all {
    margin: 0;
    font-weight: 500;
}

.wfl-sticky .wfl-active-tags {
    display: none !important;
}

button.wfl-tag-remove {
    margin: 0;
}

@media (min-width: 769px) {
    .wfl-filter-bar {
        max-width: 1250px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 0 auto;
    }
}