/**
 * Boutique Filtres — Styles
 * @version 1.0.0
 *
 * Desktop : dropdowns classiques
 * Mobile  : chips horizontaux scrollables + bottom sheet
 *
 * Préfixe : bfiltres- (évite tout conflit avec spa-filtres)
 */

/* ============================================
   VARIABLES
   ============================================ */

:root {
    --bf-primary: #E8792B;
    --bf-primary-hover: #F4AF51;
    --bf-primary-light: rgba(232, 121, 43, 0.08);
    --bf-text: #1a1a1a;
    --bf-text-light: #555555;
    --bf-text-muted: #999999;
    --bf-bg: #ffffff;
    --bf-bg-light: #f8f8f8;
    --bf-border: #e0e0e0;
    --bf-border-light: #eeeeee;
}

/* ============================================
   BASE
   ============================================ */

.bfiltres-wrapper {
    position: relative;
    margin: 0 0 40px 0;
    font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.bfiltres-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

/* ============================================
   DROPDOWNS (Desktop)
   ============================================ */

.bfiltres-dropdown {
    position: relative;
}

.bfiltres-trigger {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    color: var(--bf-text);
    background-color: var(--bf-bg);
    border: 2px solid var(--bf-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.bfiltres-trigger:hover {
    border-color: var(--bf-primary-hover);
    background-color: rgba(244, 175, 81, 0.1);
}

.bfiltres-trigger.active {
    border-color: var(--bf-primary);
    background-color: var(--bf-primary);
    color: #ffffff;
}

/* Disabled state (sous-catégorie non encore disponible) */
.bfiltres-disabled .bfiltres-trigger {
    opacity: 0.45;
    cursor: not-allowed;
    border-style: dashed;
}

.bfiltres-disabled .bfiltres-trigger:hover {
    border-color: var(--bf-border);
    background-color: var(--bf-bg);
}

.bfiltres-trigger-label {
    font-weight: 600;
    letter-spacing: -0.01em;
}

.bfiltres-trigger-count {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--bf-primary);
    background-color: #ffffff;
    border-radius: 12px;
}

.bfiltres-trigger-count.has-selection {
    display: inline-flex;
}

.bfiltres-trigger.active .bfiltres-trigger-count {
    color: var(--bf-primary);
    background-color: #ffffff;
}

.bfiltres-chevron {
    transition: transform 0.2s ease;
    opacity: 0.5;
}

.bfiltres-dropdown.open .bfiltres-chevron {
    transform: rotate(180deg);
    opacity: 1;
}

/* ============================================
   DROPDOWN PANELS (Desktop)
   ============================================ */

.bfiltres-panel {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    min-width: 280px;
    max-height: 400px;
    background-color: var(--bf-bg);
    border: 1px solid var(--bf-border);
    border-radius: 16px;
    z-index: 1000;
    overflow: hidden;
}

.bfiltres-dropdown.open .bfiltres-panel {
    display: block;
    animation: bfSlideDown 0.15s ease forwards;
}

@keyframes bfSlideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.bfiltres-options {
    max-height: 360px;
    padding: 12px;
    overflow-y: auto;
}

/* ============================================
   OPTIONS
   ============================================ */

.bfiltres-option {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    margin: 4px 0;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.15s ease;
    border: 2px solid transparent;
}

.bfiltres-option:hover {
    background-color: rgba(244, 175, 81, 0.1);
    border-color: rgba(244, 175, 81, 0.3);
}

.bfiltres-option:has(input:checked) {
    background-color: var(--bf-primary-light);
    border-color: var(--bf-primary);
}

.bfiltres-option input[type="radio"],
.bfiltres-option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0 14px 0 0;
    cursor: pointer;
    accent-color: var(--bf-primary);
    flex-shrink: 0;
}

.bfiltres-option-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--bf-text);
    user-select: none;
    flex: 1;
    transition: color 0.15s ease;
}

.bfiltres-option input:checked + .bfiltres-option-text {
    color: var(--bf-primary);
    font-weight: 600;
}

/* Compteur de produits par option */
.bfiltres-option-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--bf-text-muted);
    background: var(--bf-bg-light);
    padding: 2px 8px;
    border-radius: 8px;
    margin-left: 8px;
    flex-shrink: 0;
}

.bfiltres-option:has(input:checked) .bfiltres-option-count {
    color: var(--bf-primary);
    background: rgba(232, 121, 43, 0.12);
}

.bfiltres-no-options {
    padding: 24px;
    text-align: center;
    color: var(--bf-text-light);
    font-size: 14px;
}

/* ============================================
   RESET BUTTON
   ============================================ */

.bfiltres-reset-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: var(--bf-text-light);
    background-color: transparent;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bfiltres-reset-btn:hover {
    color: #dc2626;
    background-color: #fef2f2;
    border-color: #fecaca;
}

.bfiltres-reset-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
}

.bfiltres-reset-btn:hover svg {
    transform: rotate(90deg);
}

/* ============================================
   RESULTS COUNT
   ============================================ */

.bfiltres-results-count {
    margin-left: auto;
    font-size: 14px;
    font-weight: 500;
    color: var(--bf-text);
}

.bfiltres-results-count #bfiltres-count-number {
    font-weight: 700;
    color: var(--bf-primary);
}

.bfiltres-results-count-mobile {
    display: none;
}

/* ============================================
   NO RESULTS
   ============================================ */

.bfiltres-no-results {
    text-align: center;
    padding: 60px 20px;
    background: var(--bf-bg-light);
    border-radius: 16px;
    margin-top: 20px;
}

.bfiltres-no-results svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.bfiltres-no-results p {
    font-size: 17px;
    font-weight: 500;
    color: var(--bf-text);
    margin: 0;
}

/* ============================================
   HIDDEN PRODUCTS
   ============================================ */

.e-loop-item.bfiltres-hidden,
.product.bfiltres-hidden {
    display: none !important;
}

/* ============================================
   BODY SCROLL LOCK
   ============================================ */

body.bfiltres-sheet-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    left: 0;
}

/* ============================================
   BOTTOM SHEET & OVERLAY (hidden on desktop)
   ============================================ */

.bfiltres-sheet-overlay {
    display: none;
}

.bfiltres-bottom-sheet {
    display: none;
}

/* ============================================
   ============================================
   MOBILE — max-width: 768px
   ============================================
   ============================================ */

@media (max-width: 768px) {

    .bfiltres-wrapper {
        margin: 0 0 20px 0;
    }

    /* --- Sticky horizontal chip bar --- */

    .bfiltres-container {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 10px;
        align-items: center;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 14px 20px;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bf-bg);
        border-bottom: 1px solid var(--bf-border-light);
    }

    .bfiltres-container::-webkit-scrollbar {
        display: none;
    }

    /* --- Chips --- */

    .bfiltres-dropdown {
        position: static;
        flex-shrink: 0;
    }

    .bfiltres-trigger {
        padding: 10px 16px;
        font-size: 14px;
        gap: 8px;
        border-radius: 50px;
        border-width: 1.5px;
        border-color: var(--bf-border);
        background: var(--bf-bg-light);
        -webkit-tap-highlight-color: transparent;
    }

    .bfiltres-trigger:hover {
        background-color: var(--bf-bg-light);
        border-color: var(--bf-border);
    }

    .bfiltres-trigger:active {
        transform: scale(0.96);
    }

    .bfiltres-trigger.active {
        background-color: var(--bf-primary);
        border-color: var(--bf-primary);
        color: #fff;
    }

    /* Disabled chip */
    .bfiltres-disabled .bfiltres-trigger {
        opacity: 0.4;
        border-style: dashed;
    }

    .bfiltres-trigger-count {
        min-width: 20px;
        height: 20px;
        padding: 0 6px;
        font-size: 11px;
        border-radius: 50%;
    }

    .bfiltres-chevron {
        display: none;
    }

    /* Hide desktop dropdown panels */
    .bfiltres-panel {
        display: none !important;
    }

    /* --- Reset compact circulaire --- */

    .bfiltres-reset-btn {
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        padding: 0;
        border-radius: 50%;
        border: 1.5px solid var(--bf-border);
        background: var(--bf-bg-light);
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }

    .bfiltres-reset-btn span {
        display: none;
    }

    .bfiltres-reset-btn:hover {
        background-color: var(--bf-bg-light);
        border-color: var(--bf-border);
        color: var(--bf-text-light);
    }

    .bfiltres-reset-btn:active {
        transform: scale(0.92);
        background: #fef2f2;
        border-color: #fecaca;
        color: #dc2626;
    }

    /* --- Results count --- */

    .bfiltres-results-count {
        display: none;
    }

    .bfiltres-results-count-mobile {
        display: block;
        padding: 10px 20px 6px;
        font-size: 13px;
        font-weight: 500;
        color: var(--bf-text-light);
    }

    .bfiltres-results-count-mobile #bfiltres-count-number-mobile {
        font-weight: 700;
        color: var(--bf-primary);
    }

    /* --- No results --- */

    .bfiltres-no-results {
        margin: 12px 16px 0;
        padding: 48px 20px;
        border-radius: 12px;
    }

    .bfiltres-no-results svg {
        width: 48px;
        height: 48px;
    }

    .bfiltres-no-results p {
        font-size: 15px;
    }

    /* ========================================
       BOTTOM SHEET
       ======================================== */

    .bfiltres-sheet-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 9998;
        transition: opacity 0.25s ease;
    }

    .bfiltres-sheet-overlay.bfiltres-sheet-visible {
        display: block;
    }

    .bfiltres-bottom-sheet {
        display: none;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bf-bg);
        border-radius: 24px 24px 0 0;
        z-index: 9999;
        max-height: 70vh;
        max-height: 70dvh;
        flex-direction: column;
        overflow: hidden;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.12);
        transition: transform 0.3s cubic-bezier(0.22, 0.68, 0, 1.04);
    }

    .bfiltres-bottom-sheet.bfiltres-sheet-visible {
        display: flex;
    }

    .bfiltres-sheet-handle {
        width: 36px;
        height: 4px;
        background: #d4d4d4;
        border-radius: 4px;
        margin: 12px auto 0;
        flex-shrink: 0;
    }

    .bfiltres-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px 12px;
        flex-shrink: 0;
    }

    .bfiltres-sheet-title {
        font-size: 17px;
        font-weight: 700;
        color: var(--bf-text);
        margin: 0;
        line-height: 1;
    }

    .bfiltres-sheet-close {
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: var(--bf-bg-light);
        border-radius: 50%;
        cursor: pointer;
        color: var(--bf-text-light);
        -webkit-tap-highlight-color: transparent;
    }

    .bfiltres-sheet-close:active {
        background: #eee;
        transform: scale(0.92);
    }

    .bfiltres-sheet-options {
        padding: 4px 16px 8px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
    }

    .bfiltres-sheet-options .bfiltres-option {
        padding: 14px 16px;
        border-width: 1.5px;
        -webkit-tap-highlight-color: transparent;
    }

    .bfiltres-sheet-options .bfiltres-option:active {
        transform: scale(0.98);
    }

    .bfiltres-sheet-options .bfiltres-option:hover {
        background-color: transparent;
        border-color: transparent;
    }

    .bfiltres-sheet-options .bfiltres-option:has(input:checked) {
        background-color: var(--bf-primary-light);
        border-color: var(--bf-primary);
    }

    .bfiltres-sheet-options .bfiltres-option input[type="radio"],
    .bfiltres-sheet-options .bfiltres-option input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    .bfiltres-sheet-apply {
        display: block;
        width: calc(100% - 32px);
        margin: 8px 16px 20px;
        padding: 14px;
        font-size: 15px;
        font-weight: 700;
        font-family: inherit;
        color: #fff;
        background: var(--bf-primary);
        border: none;
        border-radius: 14px;
        cursor: pointer;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        transition: all 0.2s ease;
    }

    .bfiltres-sheet-apply:active {
        transform: scale(0.97);
        background: #d5691f;
    }

    /* Safe area iPhone */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .bfiltres-sheet-apply {
            margin-bottom: calc(20px + env(safe-area-inset-bottom));
        }
    }
}

/* ============================================
   LOADING OVERLAY (AJAX)
   ============================================ */

.bfiltres-loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.bfiltres-loading.active {
    display: flex;
}

.bfiltres-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bf-border-light);
    border-top-color: var(--bf-primary);
    border-radius: 50%;
    animation: bfSpin 0.7s linear infinite;
}

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

/* ============================================
   AJAX NO RESULTS (inside loop container)
   ============================================ */

.bfiltres-ajax-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--bf-text-light);
}

.bfiltres-ajax-no-results svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.bfiltres-ajax-no-results p {
    font-size: 17px;
    font-weight: 500;
    color: var(--bf-text);
    margin: 0;
}

/* ============================================
   BOUTON "VOIR PLUS" (pagination AJAX)
   ============================================ */

.bfiltres-load-more-wrapper {
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px 0 10px;
}

.bfiltres-load-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 220px;
    padding: 14px 32px;
    font-family: "Raleway", sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--bf-primary);
    background: var(--bf-bg);
    border: 2px solid var(--bf-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bfiltres-load-more-btn:hover {
    color: #fff;
    background: var(--bf-primary);
}

.bfiltres-load-more-btn:active {
    transform: scale(0.97);
}

.bfiltres-load-more-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--bf-border-light);
    border-top-color: var(--bf-primary);
    border-radius: 50%;
    animation: bfSpin 0.6s linear infinite;
}