/**
 * BCS Filtres SEO - Frontend CSS v5.6
 * Compatible Astra off-canvas sidebar
 * Pas de système mobile propre - le thème gère l'affichage mobile
 *
 * Couleurs : par défaut celles du thème (classe .wchf-theme) : palette globale Astra
 * (--ast-global-color-*), sinon palette d'un thème blocs (--wp--preset--color--*).
 * Avec .wchf-custom, les couleurs de l'onglet Style arrivent en variables dans l'attribut style.
 *
 * Hiérarchie : 1. titre de section (PRIX, TRI, groupe) en capitales
 *              2. nom de l'attribut (Marque, Taille d'écran…) en gras, couleur des titres
 *              3. valeurs en texte normal
 */

/* === VARIABLES === */
#wchf-wrapper {
    --wchf-bg: #ffffff;
    --wchf-text: #333333;
    --wchf-heading: var(--wchf-text);
    --wchf-border: #e5e5e5;
    --wchf-accent: #0073aa;
    --wchf-track: #e5e5e5;
    --wchf-handle: #0073aa;
    --wchf-btn-bg: #c0392b;
    --wchf-btn-text: #ffffff;
    --wchf-padding: 20px;
    --wchf-radius: 8px;
    --wchf-font: 14px;
}

/* Couleurs du thème : rien à régler, suit aussi le mode sombre d'Astra */
#wchf-wrapper.wchf-theme,
.wchf-active-filters.wchf-theme {
    --wchf-accent: var(--ast-global-color-0, var(--wp--preset--color--primary, var(--wp--preset--color--accent-1, var(--wp--preset--color--accent, #0073aa))));
    --wchf-heading: var(--ast-global-color-2, var(--wp--preset--color--contrast, currentColor));
    --wchf-text: currentColor;
    --wchf-bg: transparent;
    --wchf-border: #e5e5e5;
    --wchf-border: color-mix(in srgb, currentColor 14%, transparent);
    --wchf-track: #e5e5e5;
    --wchf-track: color-mix(in srgb, currentColor 14%, transparent);
    --wchf-handle: var(--wchf-accent);
}

/* === WRAPPER === */
#wchf-wrapper {
    background: var(--wchf-bg);
    color: var(--wchf-text);
    padding: var(--wchf-padding);
    border-radius: var(--wchf-radius);
    font-size: var(--wchf-font);
    line-height: 1.5;
    box-sizing: border-box;
}

#wchf-wrapper *, #wchf-wrapper *::before, #wchf-wrapper *::after {
    box-sizing: border-box;
}

/* === SECTIONS (niveau 1) === */
#wchf-wrapper .wchf-section {
    margin-bottom: 18px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--wchf-border);
}

#wchf-wrapper .wchf-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}

#wchf-wrapper .wchf-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
    border-radius: 4px;
}

#wchf-wrapper .wchf-section-header:focus-visible {
    outline: 2px solid var(--wchf-accent);
    outline-offset: 3px;
}

#wchf-wrapper .wchf-section-title {
    color: var(--wchf-heading);
    font-weight: 700;
    font-size: 0.93em;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Chevron dessiné en CSS : vers le haut quand la section est ouverte */
#wchf-wrapper .wchf-section-arrow {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-right: 3px;
    border-right: 2px solid var(--wchf-heading);
    border-bottom: 2px solid var(--wchf-heading);
    transform: translateY(2px) rotate(-135deg);
    opacity: 0.6;
    transition: transform 0.2s, opacity 0.2s;
}

#wchf-wrapper .wchf-section-header:hover .wchf-section-arrow {
    opacity: 1;
}

#wchf-wrapper .wchf-section.collapsed .wchf-section-arrow {
    transform: translateY(-2px) rotate(45deg);
}

#wchf-wrapper .wchf-section-body {
    padding-top: 14px;
}

/* === FILTER ITEMS (niveau 2) === */
#wchf-wrapper .wchf-filter-item {
    margin-bottom: 22px;
}

#wchf-wrapper .wchf-filter-item:last-child {
    margin-bottom: 0;
}

#wchf-wrapper .wchf-filter-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--wchf-heading);
    font-size: 1em;
    font-weight: 700;
    line-height: 1.3;
}

/* Petite barre d'accent devant le nom de l'attribut */
#wchf-wrapper .wchf-filter-label::before {
    content: "";
    flex-shrink: 0;
    width: 3px;
    height: 1em;
    border-radius: 2px;
    background: var(--wchf-accent);
}

/* Prix, Tri, Catégories : le titre de section suffit, pas de libellé en doublon */
#wchf-wrapper .wchf-section-single .wchf-filter-label {
    display: none;
}

/* === SLIDERS (petits handles) === */
#wchf-wrapper .wchf-slider-wrap {
    padding: 8px 6px 0;
}

#wchf-wrapper .wchf-slider {
    height: 4px;
}

/* noUiSlider overrides */
#wchf-wrapper .noUi-target {
    background: var(--wchf-track);
    border: none;
    box-shadow: none;
    border-radius: 2px;
}

#wchf-wrapper .noUi-connect {
    background: var(--wchf-handle);
}

#wchf-wrapper .noUi-handle {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--wchf-handle);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    cursor: pointer;
    top: -5px;
    right: -7px;
}

#wchf-wrapper .noUi-handle::before,
#wchf-wrapper .noUi-handle::after {
    display: none;
}

#wchf-wrapper .noUi-handle:focus {
    outline: none;
}

#wchf-wrapper .noUi-handle:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--wchf-handle) 35%, transparent);
}

#wchf-wrapper .wchf-slider-values {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 0.9em;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* === CHECKLISTS (niveau 3 : les valeurs) === */
#wchf-wrapper .wchf-checklist {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 180px;
    overflow-y: auto;
}

#wchf-wrapper .wchf-checklist li {
    margin-bottom: 6px;
}

#wchf-wrapper .wchf-checklist li::before {
    display: none;
}

#wchf-wrapper .wchf-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

#wchf-wrapper .wchf-check input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

#wchf-wrapper .wchf-checkmark {
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 2px solid var(--wchf-border);
    border-color: color-mix(in srgb, currentColor 35%, transparent);
    border-radius: 3px;
    position: relative;
    transition: all 0.15s;
}

#wchf-wrapper .wchf-checkmark::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    transition: transform 0.15s;
}

#wchf-wrapper .wchf-check:hover .wchf-checkmark,
#wchf-wrapper .wchf-check input:focus-visible + .wchf-checkmark {
    border-color: var(--wchf-accent);
}

#wchf-wrapper .wchf-check input:focus-visible + .wchf-checkmark {
    outline: 2px solid var(--wchf-accent);
    outline-offset: 2px;
}

#wchf-wrapper .wchf-check input:checked + .wchf-checkmark {
    background: var(--wchf-accent);
    border-color: var(--wchf-accent);
}

#wchf-wrapper .wchf-check input:checked + .wchf-checkmark::after {
    transform: rotate(45deg) scale(1);
}

#wchf-wrapper .wchf-check-text {
    flex: 1;
    font-size: 0.95em;
    font-weight: 400;
}

#wchf-wrapper .wchf-check input:checked ~ .wchf-check-text {
    font-weight: 600;
}

#wchf-wrapper .wchf-check-count {
    opacity: 0.55;
    font-size: 0.85em;
    font-variant-numeric: tabular-nums;
}

#wchf-wrapper .wchf-single-check {
    padding: 8px 0;
}

/* === SELECT === */
#wchf-wrapper .wchf-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--wchf-border);
    border-radius: 4px;
    font-size: 13px;
    color: var(--wchf-text);
    background: #fff;
    cursor: pointer;
}

#wchf-wrapper.wchf-theme .wchf-select {
    background: transparent;
    border-color: color-mix(in srgb, currentColor 25%, transparent);
}

#wchf-wrapper .wchf-select:focus {
    outline: none;
    border-color: var(--wchf-accent);
}

/* === ACTIONS === */
#wchf-wrapper .wchf-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--wchf-border);
}

#wchf-wrapper .wchf-reset-btn {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 4px;
    background: var(--wchf-btn-bg);
    color: var(--wchf-btn-text);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s;
}

#wchf-wrapper .wchf-reset-btn:hover {
    opacity: 0.9;
}

/* Couleurs du thème : action secondaire, en contour */
#wchf-wrapper.wchf-theme .wchf-reset-btn {
    border: 1.5px solid var(--wchf-accent);
    border-radius: 999px;
    background: transparent;
    color: var(--wchf-accent);
    letter-spacing: 0.04em;
    transition: background 0.2s, color 0.2s;
}

#wchf-wrapper.wchf-theme .wchf-reset-btn:hover,
#wchf-wrapper.wchf-theme .wchf-reset-btn:focus-visible {
    opacity: 1;
    background: var(--wchf-accent);
    color: #fff;
}

/* === COUNT === */
#wchf-wrapper .wchf-count-wrap {
    margin-top: 12px;
    text-align: center;
    font-size: 12px;
    opacity: 0.7;
}

#wchf-wrapper .wchf-count-num {
    font-weight: 600;
}

/* === LOADING === */
#wchf-wrapper.wchf-loading {
    position: relative;
    pointer-events: none;
}

#wchf-wrapper.wchf-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 10;
}

#wchf-wrapper.wchf-theme.wchf-loading::after {
    background: transparent;
    backdrop-filter: blur(1px);
    opacity: 0.6;
}

/* === VALEURS SANS RÉSULTAT (grisées) === */
#wchf-wrapper .wchf-check.wchf-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#wchf-wrapper .wchf-select option:disabled {
    color: #aaa;
}

/* === LISTES LONGUES : "VOIR PLUS" === */
#wchf-wrapper .wchf-checklist.wchf-has-more {
    max-height: none;
    overflow: visible;
}

#wchf-wrapper .wchf-checklist .wchf-more-item {
    display: none;
}

#wchf-wrapper .wchf-show-all .wchf-checklist .wchf-more-item,
#wchf-wrapper .wchf-checklist .wchf-more-item.wchf-force-show {
    display: block;
}

#wchf-wrapper .wchf-show-all .wchf-checklist.wchf-has-more {
    max-height: 320px;
    overflow-y: auto;
}

#wchf-wrapper .wchf-more-btn {
    display: inline-block;
    margin: 6px 0 0;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    color: var(--wchf-accent);
    font-size: 12px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
    text-decoration: underline;
    cursor: pointer;
}

/* === FILTRES ACTIFS (au-dessus des produits) === */
.wchf-active-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px;
}

.wchf-active-filters button.wchf-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 5px 10px;
    border: 1px solid var(--wchf-accent, #0073aa);
    border-radius: 999px;
    background: transparent;
    box-shadow: none;
    color: var(--wchf-accent, #0073aa);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
}

.wchf-active-filters button.wchf-chip:hover,
.wchf-active-filters button.wchf-chip:focus-visible {
    background: var(--wchf-accent, #0073aa);
    color: #fff;
}

.wchf-active-filters .wchf-chip-x {
    font-size: 15px;
    line-height: 1;
}

.wchf-active-filters button.wchf-chip-clear {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 5px 4px;
    border: none;
    background: none;
    box-shadow: none;
    color: inherit;
    font-size: 13px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    text-decoration: underline;
    cursor: pointer;
}

/* === BOUTON « FILTRER » DU THÈME (volet latéral Astra) === */
.astra-shop-filter-button {
    --wchf-btn-accent: var(--ast-global-color-0, var(--wp--preset--color--primary, #0073aa));
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    padding: 8px 18px !important;
    border: 0;
    border-radius: 999px;
    background: var(--wchf-btn-accent);
    color: #fff !important;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.astra-shop-filter-button:hover,
.astra-shop-filter-button:focus-visible {
    color: #fff !important;
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.astra-shop-filter-button:focus-visible {
    outline: 2px solid var(--wchf-btn-accent);
    outline-offset: 3px;
}

.astra-shop-filter-button .astra-woo-filter-icon,
.astra-shop-filter-button .astra-woo-filter-icon svg {
    display: inline-flex;
    width: 15px;
    height: 15px;
    fill: currentColor;
    color: inherit;
}

/* Nombre de filtres actifs (ajouté par filter.js) */
.astra-shop-filter-button .wchf-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #fff;
    color: var(--wchf-btn-accent);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

/* CSS spécial dans page : uniquement pour la page ID 2563 */
.page-id-2563 #wchf-wrapper .wchf-section-body {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.page-id-2563 #wchf-wrapper .wchf-section-body .wchf-filter-item {
    flex: 1 1 100%;
    box-sizing: border-box;
}

/* Desktop : 2 colonnes */
@media (min-width: 768px) {
    .page-id-2563 #wchf-wrapper .wchf-section-body .wchf-filter-item {
        flex: 1 1 calc(50% - 20px);
    }
}

.page-id-2563 #wchf-wrapper .wchf-filter-label {
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--wchf-accent);
    text-align: center;
}
