/* =========================================================================
   Belloro product filter
   Colours inherit the active theme (Adena) via CSS custom properties, with
   neutral-grey fallbacks so the plugin also looks fine on other themes.
   Nothing here touches theme files.
   ========================================================================= */

/* === General Filter Layout === */
#product-attribute-filter {
    display: flex;
    flex-direction: row;
    gap: 20px;
    flex-wrap: wrap;
    padding-inline: 3rem;
}

#product-attribute-filter button {
    display: none;
}

.filter-group {
    margin-bottom: 20px;
}

/* === Results wrapper === */
.bpf-results {
    margin-top: 8px;
    padding: 1.25rem 3rem 3rem;
    background: #fff;
}

.bpf-empty,
.products p {
    text-align: center;
    font-size: 16px;
    padding: 30px 0;
    color: var(--adena-muted, #777);
}

/* === Active filters === */
.bpf-active-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 0;
    margin-top: 14px;
    padding: 0 3rem;
    color: var(--adena-text, #333);
}

.bpf-active-filters:empty {
    display: none;
}

.bpf-active-filters__label {
    font-size: 13px;
    color: var(--adena-muted, #777);
}

/* Chips are <button>s: clicking one removes that filter. */
.bpf-active-filters__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 4px 10px;
    border: 1px solid var(--adena-border, #dee2e6);
    border-radius: 999px;
    background: var(--adena-bg, #f7f7f7);
    font-size: 13px;
    font-family: inherit;
    color: var(--adena-text, #333);
    cursor: pointer;
    line-height: 1.2;
}

.bpf-active-filters__item:hover {
    border-color: var(--adena-accent, #b7b7b7);
}

.bpf-active-filters__item:focus-visible {
    outline: 2px solid var(--adena-accent, #555);
    outline-offset: 2px;
}

.bpf-active-filters__remove {
    font-weight: 700;
    color: var(--adena-muted, #777);
}

.bpf-active-filters__item:hover .bpf-active-filters__remove {
    color: var(--adena-text, #333);
}

/* === Loading spinner === */
.bpf-loader {
    width: 34px;
    height: 34px;
    margin: 48px auto;
    border: 3px solid var(--adena-border, #e5e1dc);
    border-top-color: var(--adena-accent, #b7b7b7);
    border-radius: 50%;
    animation: bpf-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .bpf-loader { animation-duration: 1.6s; }
}

/* === Dropdown Styles === */
.bpf-custom-dropdown {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.bpf-dropdown-trigger {
    padding: 10px 32px 10px 20px;
    background: transparent;
    border: 1px solid var(--adena-border, #dee2e6);
    border-radius: 25px;
    font-size: 14px;
    color: var(--adena-text, #333);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Sortuj matches the outlined Filtruj pill. */
.bpf-custom-dropdown[data-name="orderby"] .bpf-dropdown-trigger {
    background-color: transparent;
    color: var(--adena-text, #333);
    border-color: var(--adena-border, #dee2e6);
}

.bpf-custom-dropdown[data-name="orderby"] .bpf-dropdown-trigger:hover {
    border-color: var(--adena-accent, #b7b7b7);
}

.bpf-dropdown-options {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--adena-surface, #fff);
    border: 1px solid var(--adena-border, #ccc);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    display: none;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    animation: bpf-fadeIn 0.2s ease-in-out;
}

.bpf-dropdown-options ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.bpf-dropdown-options li {
    padding: 10px 14px;
    border-bottom: 1px solid var(--adena-border, #eee);
    font-size: 14px;
    color: var(--adena-text, #555);
    transition: background 0.2s;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.bpf-dropdown-options li:hover {
    background: var(--adena-bg, #f7f7f7);
}

/* === Keyboard focus visibility (a11y) === */
.bpf-dropdown-trigger:focus-visible,
.bpf-dropdown-options li:focus-visible,
.clear-filter:focus-visible,
.bpf-pagination a.page-numbers:focus-visible,
.bpf-sort-option:focus-visible {
    outline: 2px solid var(--adena-accent, #555);
    outline-offset: 2px;
}

.bpf-dropdown-options li:focus-visible {
    background: var(--adena-bg, #f7f7f7);
    outline-offset: -2px;
}

.bpf-dropdown-options li:last-child {
    border-bottom: none;
}

.bpf-dropdown-options li.selected {
    background-color: var(--adena-bg, #f0f0f0);
    font-weight: bold !important;
    color: var(--adena-text, #000);
}

/* === Dropdown Icons === */
.bpf-dropdown-arrow {
    margin-left: 8px;
    transition: transform 0.3s ease;
    display: inline-block;
}

.bpf-custom-dropdown.open .bpf-dropdown-arrow {
    transform: rotate(180deg);
}

.bpf-dropdown-trigger img,
.bpf-dropdown-options li img {
    width: 20px;
    height: 20px;
    object-fit: cover;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    flex: 0 0 auto;
}

.bpf-dropdown-trigger .selected-indicator,
.bpf-dropdown-trigger .clear-filter {
    font-size: 12px;
    margin-left: 10px !important;
}

.bpf-dropdown-trigger .clear-filter {
    cursor: pointer;
    color: var(--adena-muted, #777);
    font-weight: 700;
}

/* === Headings (hidden inside dropdowns) === */
.filter-group h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--adena-text, #333);
    display: none !important;
}

/* === AJAX pagination === */
.bpf-pagination {
    margin-top: 28px;
    display: flex;
    justify-content: center;
}

.bpf-pagination ul.page-numbers {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
    border: none;
}

.bpf-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    height: 42px;
    padding: 0 8px;
    border: 1px solid var(--adena-border, #dee2e6);
    border-radius: 15px;
    background: var(--adena-surface, #fff);
    color: var(--adena-text, #333);
    text-decoration: none;
}

.bpf-pagination .page-numbers.current {
    background: var(--adena-accent, #b7b7b7);
    border-color: var(--adena-accent, #b7b7b7);
    color: #fff;
}

.bpf-pagination a.page-numbers:hover {
    border-color: var(--adena-accent, #b7b7b7);
}

.bpf-pagination .dots {
    border: none;
    background: transparent;
}

/* Fallback: the filter owns catalogue pagination. Hide Woo's native copy if a
   theme/plugin re-adds it after the filter results wrapper. */
.bpf-results + nav.woocommerce-pagination {
    display: none !important;
}

/* === Animations === */
@keyframes bpf-fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Mobile-Specific Styles === */
@media (max-width: 768px) {

    /* Slim mobile gutter. Note: the theme's .adena-shop container is absent on
       catalogue views (its hook never fires via woocommerce_content()), so this
       is the only side padding the grid gets — keep it small but non-zero. */
    #product-attribute-filter {
        padding-inline: 0.75rem;
    }

    #bpf-mobile-buttons {
        padding-inline: 0.75rem;
    }

    .bpf-results {
        margin-top: 4px;
        padding: 0.75rem 0.75rem 2rem;
    }

    .bpf-active-filters {
        padding: 0 0.75rem;
    }

    .bpf-dropdown-trigger {
        justify-content: flex-start;
    }

    .bpf-dropdown-arrow {
        margin-left: auto;
    }

    /* Hide filters unless in popup */
    #product-attribute-filter:not(.in-popup) > .filter-group {
        display: none !important;
    }

    /* Show mobile-only elements */
    .mobile-only {
        display: flex;
        gap: 10px;
        margin-bottom: 15px;
        justify-content: center;
    }

    .filter-group {
        width: 100%;
        margin-bottom: 0;
    }

    .bpf-dropdown-trigger {
        padding: 12px 16px;
        font-size: 16px;
    }

    .bpf-dropdown-options,
    .bpf-dropdown-options li {
        font-size: 16px;
    }

    .bpf-dropdown-options li {
        padding: 12px 16px;
    }

    .products p {
        font-size: 18px;
    }

    #product-attribute-filter.in-popup {
        display: flex;
        flex-direction: column;
        gap: 16px;
        padding-bottom: 20px;
    }

    #product-attribute-filter.in-popup .filter-group {
        width: 100%;
    }
}

/* === Mobile Buttons === */
#bpf-mobile-buttons button {
    width: 50%;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 16px;
}

#bpf-sort-btn {
    background-color: transparent;
    border: 1px solid var(--adena-border, #dee2e6);
    color: var(--adena-text, #333);
}

#bpf-filter-btn {
    background-color: transparent;
    border: 1px solid var(--adena-border, #dee2e6);
    color: var(--adena-text, #333);
}

/* === Mobile Popup === */
#bpf-mobile-popup {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    height: 70%;
    background: var(--adena-surface, #fff);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.2);
    transition: bottom 0.4s ease;
    z-index: 9999;
    overflow-y: auto;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

#bpf-mobile-popup.open {
    bottom: 0;
}

.popup-content {
    padding: 20px;
}

.popup-close {
    position: absolute;
    top: 12px;
    right: 18px;
    font-size: 26px;
    background: none;
    border: none;
    color: var(--adena-muted, #555);
    cursor: pointer;
}

.popup-header {
    text-align: center;
    font-size: 30px;
    padding: 30px;
}

/* === Mobile Overlay === */
#bpf-mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
    display: none;
}

#bpf-mobile-overlay.open {
    display: block;
}

@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
}

/* =========================================================================
   "Więcej opcji" (more options) — desktop right-hand drawer
   ========================================================================= */

/* Trigger. Beats the generic `#product-attribute-filter button { display:none }`
   via higher specificity (id + class > id + element). */
#product-attribute-filter .bpf-more-btn {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;   /* don't stretch to the row height */
    order: -1;                /* Filtruj sits first (left) in the strip */
    padding: 10px 20px;
    line-height: 1.2;
    /* Outlined pill: white/transparent with a thin border. */
    background: transparent;
    border: 1px solid var(--adena-border, #dee2e6);
    border-radius: 25px;
    font-size: 14px;
    color: var(--adena-text, #333);
    cursor: pointer;
    white-space: nowrap;
}

#product-attribute-filter .bpf-more-btn:hover {
    border-color: var(--adena-accent, #b7b7b7);
}

/* Funnel icon on Filtruj. */
#product-attribute-filter .bpf-more-btn::before,
#bpf-filter-btn::before {
    content: '';
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M3 5h18M7 12h10M10 19h4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Sort arrows icon on Sortuj. */
.bpf-custom-dropdown[data-name="orderby"] .bpf-dropdown-trigger::before,
#bpf-sort-btn::before {
    content: '';
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 4v16M4 8l4-4 4 4M16 20V4M12 16l4 4 4-4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Mobile bar buttons need flex so the icons align with the label. */
#bpf-mobile-buttons button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Count badge on Filtruj. */
#product-attribute-filter .bpf-more-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 8px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--adena-accent, #b7b7b7);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

#product-attribute-filter .bpf-more-count[hidden] {
    display: none;
}

/* The strip's only direct filter-group is Sortuj — push it to the far right.
   (The drawer's groups are nested deeper, so they're unaffected.) */
#product-attribute-filter > .filter-group {
    margin-left: auto;
    margin-bottom: 0;
}

/* Drawer: off-screen by default, slides in from the right. */
.bpf-more-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 30vw;
    min-width: 340px;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--adena-surface, #fff);
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.35s ease, visibility 0.35s ease;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bpf-more-panel.open {
    transform: translateX(0);
    visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
    .bpf-more-panel { transition: none; }
}

.bpf-more-panel__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--adena-border, #eee);
    flex: 0 0 auto;
}

.bpf-more-panel__title {
    flex: 1 1 auto;
    font-size: 18px;
    font-weight: 600;
    color: var(--adena-text, #333);
}

.bpf-more-back,
.bpf-more-close {
    background: none;
    border: none;
    color: var(--adena-muted, #555);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    flex: 0 0 auto;
}

/* These <button>s live inside the filter <form>, so their display rules must be
   id-prefixed to beat `#product-attribute-filter button { display:none }`. */
#product-attribute-filter .bpf-more-close {
    display: inline-flex;
    align-items: center;
    font-size: 26px;
}

/* Back arrow: only shown in the detail (sub-filter) view. */
#product-attribute-filter .bpf-more-back {
    display: none;
    align-items: center;
    font-size: 28px;
}

#product-attribute-filter .bpf-more-panel--detail .bpf-more-back {
    display: inline-flex;
}

.bpf-more-panel__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.bpf-more-panel__body .filter-group {
    width: 100%;
    margin: 0;
    border-bottom: 1px solid var(--adena-border, #eee);
}

/* --- Level 1: each attribute is a navigable row (label + count + chevron) --- */
.bpf-more-panel .bpf-dropdown-trigger {
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 18px 20px;
    font-size: 15px;
    justify-content: flex-start;
}

.bpf-more-panel .bpf-dropdown-arrow,
.bpf-more-panel .clear-filter {
    display: none;
}

.bpf-more-panel .bpf-dropdown-trigger::after {
    content: '\203A'; /* › */
    margin-left: auto;
    padding-left: 12px;
    font-size: 22px;
    line-height: 1;
    color: var(--adena-muted, #999);
}

.bpf-more-panel .selected-indicator {
    margin-left: 8px;
    color: var(--adena-muted, #777);
    font-weight: 600;
}

/* --- Level 2: the chosen attribute's options fill the panel body --- */
.bpf-more-panel .bpf-dropdown-options {
    position: static;
    width: 100%;
    max-height: none;
    overflow: visible;
    border: none;
    box-shadow: none;
    border-radius: 0;
    animation: none;
}

.bpf-more-panel--detail .filter-group {
    display: none;
    border-bottom: none;
}

.bpf-more-panel--detail .filter-group.is-active {
    display: block;
}

.bpf-more-panel--detail .filter-group.is-active .bpf-dropdown-trigger {
    display: none;
}

.bpf-more-panel--detail .filter-group.is-active .bpf-dropdown-options {
    display: block;
}

.bpf-more-panel .bpf-dropdown-options li {
    padding: 14px 20px;
    border-bottom: 1px solid var(--adena-border, #f0f0f0);
    font-size: 15px;
}

/* Checkbox affordance for the multi-select option lists. */
.bpf-more-panel .bpf-dropdown-options li::before {
    content: '';
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    margin-right: 12px;
    border: 1px solid var(--adena-border, #bbb);
    border-radius: 4px;
    background: #fff no-repeat center;
    background-size: 12px;
}

.bpf-more-panel .bpf-dropdown-options li.selected::before {
    border-color: var(--adena-accent, #333);
    background-color: var(--adena-accent, #333);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.5'%3E%3Cpath d='M3 8.5l3.5 3.5L13 4.5'/%3E%3C/svg%3E");
}

.bpf-more-panel .bpf-dropdown-options li.selected {
    font-weight: 600;
}

/* --- Footer: apply & close (results already update live) --- */
.bpf-more-panel__foot {
    flex: 0 0 auto;
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--adena-border, #eee);
}

#product-attribute-filter .bpf-more-apply {
    display: block;
    width: 100%;
    padding: 14px;
    border: 1px solid var(--adena-accent, #b7b7b7);
    border-radius: 6px;
    /* Site brand colour, matching the "Więcej opcji" / "Sortuj" pills. */
    background: var(--adena-accent, #b7b7b7);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

#product-attribute-filter .bpf-more-apply:hover {
    opacity: 0.9;
}

body.bpf-filter-open {
    overflow: hidden;
}

#bpf-more-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: none;
}

#bpf-more-overlay.open {
    display: block;
}

/* Mobile: full-width slide-out; the trigger becomes a full-width bar. */
@media (max-width: 768px) {
    .bpf-more-panel {
        width: 100vw;
        min-width: 0;
    }

    /* Mobile uses the dedicated Sortuj/Filtruj bar (#bpf-mobile-buttons). */
    #product-attribute-filter .bpf-more-btn {
        display: none;
    }
}

/* === Sort popup list === */
.bpf-sort-list {
    list-style: none;
    padding: 0;
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bpf-sort-option {
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--adena-border, #dee2e6);
    border-radius: 25px;
    font-size: 13px;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s;
}

.bpf-sort-option:hover {
    background: var(--adena-bg, #e2e2e2);
}

.bpf-sort-option.active {
    background-color: var(--adena-accent, #b7b7b7);
    color: var(--adena-text, #fff);
    font-weight: bold;
}
