/* Store Weave Product Listing — presentation only; WooCommerce owns all query controls. */
body.sw-product-listing {
    --sw-pl-border: #e2e4e7;
    --sw-pl-toolbar-border: #e2e4e7;
    --sw-pl-text: #24262a;
    --sw-pl-muted: #73777d;
    --sw-pl-toolbar-bg: transparent;
    --sw-pl-button-bg: #fff;
    --sw-pl-button-text: var(--sw-pl-text);
    --sw-pl-button-radius: 2px;
    --sw-pl-button-border: var(--sw-pl-border);
}
body.sw-product-listing .shoptimizer-sorting .woocommerce-notices-wrapper:not(:empty) { grid-column: 1 / -1; }
body.sw-product-listing.sw-pl-toolbar-count-hidden .shoptimizer-sorting .woocommerce-result-count { display: none !important; }

/* Desktop archive columns. Keep the theme's archive wrapper and widgets intact. */
@media (min-width: 993px) {
    body.sw-product-listing .shoptimizer-archive > .col-full { display: flow-root; }
    body.sw-product-listing .shoptimizer-archive > .col-full > .content-area,
    body.sw-product-listing .shoptimizer-archive > .col-full > .secondary-wrapper {
        box-sizing: border-box;
        min-width: 0;
    }
    body.sw-product-listing.sw-pl-sidebar-left .shoptimizer-archive > .col-full > .secondary-wrapper {
        float: left;
        width: var(--sw-pl-sidebar-width, 280px);
        margin: 0 var(--sw-pl-sidebar-gap, 32px) 0 0;
    }
    body.sw-product-listing.sw-pl-sidebar-left .shoptimizer-archive > .col-full > .content-area {
        float: right;
        width: calc(100% - var(--sw-pl-sidebar-width, 280px) - var(--sw-pl-sidebar-gap, 32px));
    }
    body.sw-product-listing.sw-pl-sidebar-right .shoptimizer-archive > .col-full > .secondary-wrapper {
        float: right;
        width: var(--sw-pl-sidebar-width, 280px);
        margin: 0 0 0 var(--sw-pl-sidebar-gap, 32px);
    }
    body.sw-product-listing.sw-pl-sidebar-right .shoptimizer-archive > .col-full > .content-area {
        float: left;
        width: calc(100% - var(--sw-pl-sidebar-width, 280px) - var(--sw-pl-sidebar-gap, 32px));
    }
    body.sw-product-listing.sw-pl-sidebar-closed .shoptimizer-archive > .col-full > .secondary-wrapper { display: none !important; }
    body.sw-product-listing.sw-pl-sidebar-closed .shoptimizer-archive > .col-full > .content-area {
        float: none !important;
        width: 100% !important;
    }
}

/* Stable desktop toolbar: Filter at the real left edge, count beside it, Sort at right. */
@media (min-width: 993px) {
    body.sw-product-listing .shoptimizer-sorting {
        box-sizing: border-box;
        display: grid !important;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "filter count sort";
        align-items: center;
        justify-content: stretch;
        justify-items: stretch;
        gap: 8px 16px;
        width: 100%;
        min-width: 0;
        min-height: 0;
        margin-top: var(--sw-pl-toolbar-top-margin-top, 0px) !important;
        margin-right: 0 !important;
        margin-bottom: var(--sw-pl-toolbar-top-margin-bottom, 14px) !important;
        margin-left: 0 !important;
        padding-top: var(--sw-pl-toolbar-top-padding-top, 8px) !important;
        padding-right: 0 !important;
        padding-bottom: var(--sw-pl-toolbar-top-padding-bottom, 8px) !important;
        padding-left: 0 !important;
        border-top: 1px solid var(--sw-pl-toolbar-border, var(--sw-pl-border));
        border-bottom: 1px solid var(--sw-pl-toolbar-border, var(--sw-pl-border));
        background: var(--sw-pl-toolbar-bg);
        color: var(--sw-pl-text);
        float: none;
    }
    body.sw-product-listing .shoptimizer-sorting .sw-pl-filter-toggle {
        grid-area: filter;
        justify-self: start;
        box-sizing: border-box;
        display: inline-flex;
        flex: none;
        align-items: center;
        justify-content: center;
        gap: 10px;
        min-width: 0;
        min-height: 42px;
        margin: 0 !important;
        padding: 0 14px;
        border: 1px solid var(--sw-pl-button-border);
        border-radius: var(--sw-pl-button-radius);
        background: var(--sw-pl-button-bg);
        color: var(--sw-pl-button-text);
        font: inherit;
        font-size: 15px;
        font-weight: 600;
        line-height: 1.2;
        text-align: center;
        cursor: pointer;
        transition: background-color .16s ease, border-color .16s ease, color .16s ease;
    }
    body.sw-product-listing .shoptimizer-sorting .sw-pl-filter-toggle:hover { border-color: var(--sw-pl-text); }
    body.sw-product-listing .shoptimizer-sorting .sw-pl-filter-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
    body.sw-product-listing .sw-pl-filter-toggle__icon { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; }
    body.sw-product-listing .sw-pl-filter-toggle__icon svg { display: block; width: 20px; height: 20px; }
    body.sw-product-listing.sw-pl-button-icon-only .sw-pl-filter-toggle { width: 44px; min-width: 44px; padding: 0; }
    body.sw-product-listing.sw-pl-button-icon-only .sw-pl-filter-toggle__label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-result-count {
        grid-area: count;
        justify-self: start;
        min-width: 0;
        margin: 0 !important;
        color: var(--sw-pl-muted);
        line-height: 1.2;
        align-self: center;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-ordering {
        grid-area: sort;
        justify-self: end;
        display: block;
        width: auto;
        min-width: 0;
        margin: 0 !important;
        float: none;
        align-self: center;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-ordering select.orderby {
        box-sizing: border-box;
        min-height: 40px;
        padding-right: 36px !important;
        background-position: right 12px center !important;
        line-height: 1.2;
    }
    body.sw-product-listing .shoptimizer-sorting .mobile-filter { display: none !important; }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-pagination { grid-column: 1 / -1; width: 100%; justify-self: stretch; margin: 10px 0 0 !important; }
    body.sw-product-listing.sw-pl-desktop-fixed .shoptimizer-sorting {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "count sort";
    }
    body.sw-product-listing #secondary { box-sizing: border-box; width: 100%; float: none; }
}

/* Mode 1 is server-rendered after breadcrumbs and before both archive columns.
   The native mobile trigger is rendered inside this same row; no duplicate toolbar. */
body.sw-product-listing.sw-pl-filter-layout-left_top .sw-pl-server-toolbar {
    clear: both !important;
    float: none !important;
    position: relative;
    display: grid !important;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}
/* Hide the duplicate native top toolbar before JS. It can sit directly
   before the products or wrap the inner WooCommerce products container. */
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(.products):not(:has(.woocommerce-pagination)),
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ .products):not(:has(.woocommerce-pagination)),
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ * .products):not(:has(.woocommerce-pagination)),
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting.sw-pl-sorting-top:not(:has(.woocommerce-pagination)) {
    display: none !important;
}
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(.products):has(.woocommerce-pagination) .woocommerce-result-count,
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(.products):has(.woocommerce-pagination) .woocommerce-ordering,
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ .products):has(.woocommerce-pagination) .woocommerce-result-count,
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ .products):has(.woocommerce-pagination) .woocommerce-ordering,
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ * .products):has(.woocommerce-pagination) .woocommerce-result-count,
body.sw-product-listing.sw-pl-filter-layout-left_top .content-area .shoptimizer-sorting:has(~ * .products):has(.woocommerce-pagination) .woocommerce-ordering {
    display: none !important;
}
@media (min-width: 993px) {
    body.sw-product-listing.sw-pl-filter-layout-left_top.sw-pl-desktop-fixed .sw-pl-server-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "count sort";
    }
}


/* Desktop drawer mode reuses Shoptimizer's existing #secondary and body.filter-open
   state. Keep the drawer edge deterministic: transform-only motion avoids the
   one-pixel paint seam produced by animating left on a scrollable fixed panel. */
@media (min-width: 993px) {
    body.sw-product-listing.sw-pl-desktop-filter-drawer .shoptimizer-archive > .col-full > .secondary-wrapper {
        position: static !important;
        float: none !important;
        box-sizing: border-box;
        width: 0 !important;
        height: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        outline: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
        z-index: auto !important;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer .shoptimizer-archive > .col-full > .content-area {
        position: relative;
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer #secondary {
        position: fixed !important;
        top: 0 !important;
        right: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        box-sizing: border-box !important;
        width: min(var(--sw-pl-sidebar-width, 280px), calc(100vw - 48px)) !important;
        max-width: calc(100vw - 48px) !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 28px 22px 24px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        /* Momentum scrolling is a mobile-only behavior. On desktop it can
           promote the scroll layer and leave a transient one-pixel edge seam. */
        -webkit-overflow-scrolling: auto !important;
        scrollbar-gutter: stable;
        z-index: 100002 !important;
        background: #fff !important;
        background-clip: padding-box !important;
        border: 0 !important;
        outline: 0 !important;
        box-shadow: 8px 0 32px rgba(0,0,0,.16) !important;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        transform: translate3d(-100%, 0, 0) !important;
        visibility: hidden;
        pointer-events: none;
        transition: transform .28s ease, visibility 0s linear .28s;
    }
    /* Remove only the scrollbar track's separator/border. The native thumb and
       scrolling remain enabled; this is not a scrollbar-hiding rule. */
    body.sw-product-listing.sw-pl-desktop-filter-drawer #secondary::-webkit-scrollbar-track,
    body.sw-product-listing.sw-pl-desktop-filter-drawer #secondary::-webkit-scrollbar-track-piece {
        border: 0 !important;
        box-shadow: none !important;
        background-color: #fff !important;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open #secondary {
        transform: translate3d(0, 0, 0) !important;
        visibility: visible;
        pointer-events: auto;
        transition: transform .28s ease, visibility 0s;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open::before {
        position: fixed;
        inset: 0;
        z-index: 100001;
        background: rgba(0,0,0,.42);
        content: "";
        cursor: pointer;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open {
        overflow: hidden !important;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer .filters.close-drawer {
        display: none !important;
        border: 0 !important;
        outline: 0 !important;
        box-shadow: none !important;
    }
    body.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open .filters.close-drawer {
        position: fixed !important;
        top: 50% !important;
        right: auto !important;
        bottom: auto !important;
        left: calc(min(var(--sw-pl-sidebar-width, 280px), 100vw - 48px) - 1px) !important;
        z-index: 100003 !important;
        display: flex !important;
        transform: translateY(-50%);
    }
    body.rtl.sw-product-listing.sw-pl-desktop-filter-drawer #secondary {
        right: 0 !important;
        left: auto !important;
        transform: translate3d(100%, 0, 0) !important;
    }
    body.rtl.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open #secondary {
        right: 0 !important;
        left: auto !important;
        transform: translate3d(0, 0, 0) !important;
        visibility: visible;
        pointer-events: auto;
        transition: transform .28s ease, visibility 0s;
        box-shadow: -8px 0 32px rgba(0,0,0,.16) !important;
    }
    body.rtl.sw-product-listing.sw-pl-desktop-filter-drawer.filter-open .filters.close-drawer {
        right: calc(min(var(--sw-pl-sidebar-width, 280px), 100vw - 48px) - 1px) !important;
        left: auto !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.sw-product-listing.sw-pl-desktop-filter-drawer #secondary,
    body.rtl.sw-product-listing.sw-pl-desktop-filter-drawer #secondary { transition: none !important; }
}

/* Tablet and phone share the same predictable two-row toolbar. Mode 1 places the
   native Shoptimizer mobile trigger in the server toolbar; mode 2 keeps it in place. */
@media (max-width: 992px) {
    body.sw-product-listing .shoptimizer-sorting {
        box-sizing: border-box;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "filter sort" "count count";
        align-items: center;
        justify-content: stretch;
        justify-items: stretch;
        gap: 8px 12px;
        width: 100%;
        min-width: 0;
        min-height: 0;
        margin-top: var(--sw-pl-toolbar-top-margin-top, 0px) !important;
        margin-right: 0 !important;
        margin-bottom: var(--sw-pl-toolbar-top-margin-bottom, 12px) !important;
        margin-left: 0 !important;
        padding-top: var(--sw-pl-toolbar-top-padding-top, 8px) !important;
        padding-right: 0 !important;
        padding-bottom: var(--sw-pl-toolbar-top-padding-bottom, 8px) !important;
        padding-left: 0 !important;
        border-top: 1px solid var(--sw-pl-toolbar-border, var(--sw-pl-border));
        border-bottom: 1px solid var(--sw-pl-toolbar-border, var(--sw-pl-border));
        background: var(--sw-pl-toolbar-bg);
        color: var(--sw-pl-text);
        float: none;
    }
    body.sw-product-listing .shoptimizer-sorting .sw-pl-filter-toggle { display: none !important; }
    body.sw-product-listing .shoptimizer-sorting .mobile-filter {
        grid-area: filter;
        justify-self: start;
        position: relative !important;
        top: auto !important;
        z-index: 1;
        box-sizing: border-box;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: auto !important;
        max-width: 100%;
        min-width: 0;
        height: 42px;
        min-height: 42px;
        margin: 0 !important;
        padding: 0 14px 0 38px !important;
        border: 1px solid var(--sw-pl-button-border);
        border-radius: var(--sw-pl-button-radius);
        background: var(--sw-pl-button-bg);
        box-shadow: none;
        color: var(--sw-pl-button-text);
        font: inherit;
        font-size: 14px;
        font-weight: 600;
        letter-spacing: 0;
        line-height: 40px;
        text-align: center;
        text-transform: none;
        white-space: nowrap;
        float: none;
    }
    body.sw-product-listing .shoptimizer-sorting .mobile-filter svg {
        position: absolute;
        top: 50%;
        left: 13px;
        display: block;
        width: 18px;
        height: 18px;
        margin: 0;
        transform: translateY(-50%);
        pointer-events: none;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-ordering {
        grid-area: sort;
        justify-self: end;
        display: block;
        box-sizing: border-box;
        width: clamp(104px, 42vw, 152px) !important;
        min-width: 0;
        max-width: 100%;
        margin: 0 !important;
        float: none;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-ordering select.orderby {
        box-sizing: border-box;
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        height: 42px;
        margin: 0;
        padding: 0 36px 0 10px;
        background-position: right 12px center !important;
        font-size: 13px;
        line-height: 1.2;
    }
    body.sw-product-listing .shoptimizer-sorting .woocommerce-result-count {
        grid-area: count;
        justify-self: start;
        display: block;
        width: 100%;
        min-width: 0;
        margin: 0 !important;
        color: var(--sw-pl-muted);
        font-size: 13px;
        line-height: 1.25;
        text-align: left;
        align-self: center;
    }
    body.sw-product-listing.sw-pl-pagination-layout-theme-toolbar .shoptimizer-sorting .woocommerce-pagination {
        grid-column: 1 / -1;
        width: 100%;
        margin: 12px 0 0;
    }
}


/* A second Shoptimizer sorting wrapper can be emitted after the product grid.
   Keep it compact and allow it to be hidden without touching standalone pagination. */
body.sw-product-listing .shoptimizer-sorting.sw-pl-sorting-bottom {
    box-sizing: border-box;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "count sort";
    min-height: 0 !important;
    margin-top: var(--sw-pl-toolbar-bottom-margin-top, 14px) !important;
    margin-right: 0 !important;
    margin-bottom: var(--sw-pl-toolbar-bottom-margin-bottom, 0px) !important;
    margin-left: 0 !important;
    padding-top: var(--sw-pl-toolbar-bottom-padding-top, 8px) !important;
    padding-right: 0 !important;
    padding-bottom: var(--sw-pl-toolbar-bottom-padding-bottom, 8px) !important;
    padding-left: 0 !important;
    align-items: center !important;
}
body.sw-product-listing .shoptimizer-sorting.sw-pl-sorting-bottom .woocommerce-result-count { grid-area: count; justify-self: start; }
body.sw-product-listing .shoptimizer-sorting.sw-pl-sorting-bottom .woocommerce-ordering { grid-area: sort; justify-self: end; }
body.sw-product-listing .shoptimizer-sorting.sw-pl-sorting-bottom .woocommerce-result-count,
body.sw-product-listing .shoptimizer-sorting.sw-pl-sorting-bottom .woocommerce-ordering {
    align-self: center;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
body.sw-product-listing.sw-pl-hide-bottom-toolbar .shoptimizer-sorting.sw-pl-sorting-bottom:not(.sw-pl-sorting-has-pagination) {
    display: none !important;
}
body.sw-product-listing.sw-pl-hide-bottom-toolbar .shoptimizer-sorting.sw-pl-sorting-bottom.sw-pl-sorting-has-pagination .woocommerce-result-count,
body.sw-product-listing.sw-pl-hide-bottom-toolbar .shoptimizer-sorting.sw-pl-sorting-bottom.sw-pl-sorting-has-pagination .woocommerce-ordering,
body.sw-product-listing.sw-pl-hide-bottom-toolbar .shoptimizer-sorting.sw-pl-sorting-bottom.sw-pl-sorting-has-pagination .mobile-filter,
body.sw-product-listing.sw-pl-hide-bottom-toolbar .shoptimizer-sorting.sw-pl-sorting-bottom.sw-pl-sorting-has-pagination .sw-pl-filter-toggle {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    body.sw-product-listing .sw-pl-filter-toggle { transition: none; }
}
