/* Category listing controls scale between 320px and 1920px viewports. */
html body.tax-product_cat {
    --cie-category-vertical-space: clamp(24px, calc(21.6px + 0.75vw), 36px);
    --cie-category-control-width: clamp(108px, calc(104.8px + 1vw), 124px);
    --cie-category-control-height: clamp(44px, calc(43.6px + 0.125vw), 46px);
    --cie-category-control-font: clamp(12px, calc(11.6px + 0.125vw), 14px);
    --cie-category-control-padding-block: clamp(8px, calc(7.6px + 0.125vw), 10px);
    --cie-category-control-padding-inline: clamp(14px, calc(13.2px + 0.25vw), 18px);
    --cie-category-search-font: clamp(13px, calc(12.8px + 0.0625vw), 14px);
}

/* One shared toolbar layout for Elementor and AJAX category product grids.
 * Override the filter adapter's wrapping flex row and full-width search basis.
 */
html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls {
    display: grid !important;
    grid-template-columns: repeat(2, var(--cie-category-control-width)) minmax(0, 1fr) !important;
    gap: var(--cie-category-vertical-space) clamp(16px, calc(14.4px + 0.5vw), 24px) !important;
    align-items: center !important;
    width: 100%;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls > :is(.cie-category-product-grid__filter, .cie-category-product-grid__sort, .cie-category-product-grid__search),
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > :is(.s3i-apf-dropdown-wrap, .s3i-apf-search-wrap) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls :is(.cie-category-product-grid__filter, .cie-category-product-grid__sort) .elementor-button,
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top .s3i-apf-btn {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls > .cie-category-product-grid__search,
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-search-wrap {
    grid-column: auto !important;
    order: 0 !important;
}

/* Keep the search input inside its flexible grid track on narrower tablets. */
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-search {
    min-width: 0;
}

@media (max-width: 767px) {
    html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls > .cie-category-product-grid__search,
    html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-search-wrap {
        grid-column: 1 / -1 !important;
    }
}

/* The shortcode can optionally include a third brand control. Flex keeps its
 * search track fluid without assuming a fixed number of dropdowns. */
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top {
    display: flex !important;
    flex-wrap: nowrap;
    gap: var(--cie-category-vertical-space) clamp(16px, calc(14.4px + 0.5vw), 24px);
    align-items: center;
}

html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-dropdown-wrap {
    flex: 0 0 auto;
    width: auto !important;
}

html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-search-wrap {
    flex: 1 1 0;
    width: auto !important;
}

@media (max-width: 767px) {
    html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top {
        flex-wrap: wrap;
    }

    html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-dropdown-wrap {
        flex: 1 1 var(--cie-category-control-width);
    }

    html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-search-wrap {
        flex: 1 0 100%;
    }
}

/* Scope typography and sizing to listing controls; other buttons keep the site defaults. */
html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__heading-row .elementor-heading-title,
html body.tax-product_cat .s3i-apf-wrap > .s3i-apf-heading {
    font-size: clamp(18px, calc(17.2px + 0.25vw), 22px) !important;
    line-height: 1.25 !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls :is(.cie-category-product-grid__filter, .cie-category-product-grid__sort) .elementor-button,
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top .s3i-apf-btn {
    box-sizing: border-box;
    height: auto !important;
    min-height: var(--cie-category-control-height) !important;
    padding: var(--cie-category-control-padding-block) var(--cie-category-control-padding-inline) !important;
    font-size: var(--cie-category-control-font) !important;
    line-height: 1.2 !important;
}

html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-dropdown-wrap {
    min-width: var(--cie-category-control-width) !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__search .elementor-search-form__container,
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top > .s3i-apf-search-wrap {
    box-sizing: border-box;
    height: auto !important;
    min-height: var(--cie-category-control-height) !important;
    padding: var(--cie-category-control-padding-block) var(--cie-category-control-padding-inline) !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__search .elementor-search-form__input,
html body.tax-product_cat .s3i-apf-wrap .s3i-apf-top .s3i-apf-search {
    height: auto !important;
    min-height: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    font-size: var(--cie-category-search-font) !important;
    line-height: 1.2 !important;
}

/* Match the listing's vertical rhythm to the compact category hero. */
html body.tax-product_cat .elementor .cie-category-product-grid,
html body.tax-product_cat .elementor-location-archive .e-con.e-parent:has(> .e-con-inner > .elementor-widget-shortcode .s3i-apf-wrap) > .e-con-inner {
    --padding-top: var(--cie-category-vertical-space) !important;
    --padding-bottom: var(--cie-category-vertical-space) !important;
    padding-block: var(--cie-category-vertical-space) !important;
}

html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__heading-row,
html body.tax-product_cat .s3i-apf-wrap > .s3i-apf-heading,
html body.tax-product_cat .elementor .cie-category-product-grid .cie-category-product-grid__controls {
    margin-block: 0 var(--cie-category-vertical-space) !important;
}

html body.tax-product_cat .s3i-apf-wrap > .s3i-apf-results {
    margin-top: var(--cie-category-vertical-space) !important;
}
