/* =============================================================
   SHELFA — COMPACT SHOP TOOLBAR FIRST-PAINT GUARD
   Only active while the Stock Labels toolbar is initializing.
   It does not hide breadcrumbs, sorting, or enhanced controls.
   ============================================================= */
html.shelfa-toolbar-hydrating body.woocommerce .shop-loop-head
    :is(.wd-products-per-page, .woodmart-products-per-page):not(.shelfa-rail-enhanced) {
    visibility: hidden !important;
    pointer-events: none !important;
    inline-size: 124px !important;
    max-inline-size: 124px !important;
    min-block-size: 36px !important;
    max-block-size: 36px !important;
    overflow: hidden !important;
    flex: 0 0 124px !important;
}

html.shelfa-toolbar-hydrating body.woocommerce .shop-loop-head
    :is(.wd-products-shop-view, .woodmart-products-shop-view):not(.shelfa-rail-enhanced) {
    visibility: hidden !important;
    pointer-events: none !important;
    inline-size: 42px !important;
    max-inline-size: 42px !important;
    min-block-size: 36px !important;
    max-block-size: 36px !important;
    overflow: hidden !important;
    flex: 0 0 42px !important;
}

/* Stock badges: retain WoodMart's placement but use Shelfa's typography and outline. */
body .product-labels .product-label.shelfa-stock-badge {
    --shelfa-badge-ink: #e96666;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 5px 10px;
    border: 2px solid var(--shelfa-badge-ink);
    border-radius: 999px;
    background: #fff;
    color: var(--shelfa-badge-ink);
    font-size: clamp(14px, 0.6vw + 10px, 17px);
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    white-space: normal;
    box-sizing: border-box;
}

body .product-labels .product-label.shelfa-stock-badge--soon {
    --shelfa-badge-ink: #123f46;
}

body .product-labels .product-label.shelfa-stock-badge--restocking {
    --shelfa-badge-ink: #28735f;
    background: #eef9f3;
}

/* The WoodMart row that contains breadcrumbs, count, layout and ordering. */
body.woocommerce .shop-loop-head {
    --shelfa-toolbar-ink: #1c5350;
    --shelfa-toolbar-active: #123f46;
    --shelfa-toolbar-mint: #eef8f3;
    --wd-text-color: var(--shelfa-toolbar-ink);
    --wd-title-color: var(--shelfa-toolbar-active);
    --color-gray-400: var(--shelfa-toolbar-ink);
    --color-gray-500: var(--shelfa-toolbar-ink);
    --color-gray-600: var(--shelfa-toolbar-ink);
    --color-gray-700: var(--shelfa-toolbar-active);
    --color-gray-800: var(--shelfa-toolbar-active);
    --color-gray-900: var(--shelfa-toolbar-active);
    padding: 10px 14px;
    border: 1px solid #deeee5;
    border-radius: 12px;
    background: var(--shelfa-toolbar-mint);
    color: var(--shelfa-toolbar-ink);
    box-sizing: border-box;
}

body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb, .woocommerce-result-count, .woocommerce-ordering select),
body.woocommerce .shop-loop-head a {
    color: var(--shelfa-toolbar-ink);
}

body.woocommerce .shop-loop-head :is(.wd-products-shop-view, .woodmart-products-shop-view) a svg {
    fill: currentColor;
}

body.woocommerce .shop-loop-head :is(.wd-products-per-page, .woodmart-products-per-page) {
    color: var(--shelfa-toolbar-ink);
    font-size: 12px;
    font-weight: 400;
    gap: 4px;
}

body.woocommerce .shop-loop-head :is(.wd-products-per-page, .woodmart-products-per-page) :is(.per-page-title, .per-page-variation) {
    color: var(--shelfa-toolbar-ink);
    font-size: inherit;
}

body.woocommerce .shop-loop-head .woocommerce-ordering select {
    color: var(--shelfa-toolbar-active);
    border-color: #bad7ce;
}

body.woocommerce .shop-loop-head :is(.wd-products-per-page, .woodmart-products-per-page) :is(.current-variation, .current, .wd-active, [aria-current]):not([aria-current="false"]),
body.woocommerce .shop-loop-head :is(.wd-products-shop-view, .woodmart-products-shop-view) :is(.current-view, .shop-view-current, .current, .wd-active, [aria-current]):not([aria-current="false"]),
body.woocommerce .shop-loop-head :is(.current-variation, .current-view, .shop-view-current, .wd-active, [aria-current="true"], [aria-current="page"]),
body.woocommerce .shop-loop-head :is(a, .per-page-variation):is(:hover, :focus-visible) {
    color: var(--shelfa-toolbar-active);
    font-weight: 700;
}

body.woocommerce .shop-loop-head :is(a, select, button):focus-visible {
    outline: 2px solid var(--shelfa-toolbar-active);
    outline-offset: 2px;
}

/* Keep ancestor links quieter than the current breadcrumb. */
body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) {
    --shelfa-crumb-size: 14px;
    --shelfa-current-crumb-size: 15px;
}

body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) a[href]:not(:is(.wd-last-link, .breadcrumb-last, [aria-current="page"], [aria-current="true"])) {
    display: inline-block;
    color: var(--shelfa-toolbar-ink);
    font-size: var(--shelfa-crumb-size) !important;
    font-weight: 500 !important;
    transform: none;
    transform-origin: center;
    transition: color 160ms ease, transform 160ms ease;
}

body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) a[href]:not(:is(.wd-last-link, .breadcrumb-last, [aria-current="page"], [aria-current="true"])):is(:hover, :focus-visible) {
    color: var(--shelfa-toolbar-active);
    transform: scale(1.07);
}

body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) :is(.wd-last-link, .breadcrumb-last, [aria-current="page"], [aria-current="true"]),
body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) > span:last-child:not(:is(.wd-delimiter, .breadcrumb-separator, .separator)) {
    color: var(--shelfa-toolbar-active);
    font-size: var(--shelfa-current-crumb-size) !important;
    font-weight: 650 !important;
    transform: none;
    transition: none;
}

@media (prefers-reduced-motion: reduce) {
    body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) a[href]:not(:is(.wd-last-link, .breadcrumb-last, [aria-current="page"], [aria-current="true"])) {
        transition: none;
    }
}

@media (max-width: 767px) {
    body.woocommerce .shop-loop-head {
        padding: 8px 10px;
    }

    body.woocommerce .shop-loop-head :is(.wd-breadcrumbs, .woocommerce-breadcrumb) {
        --shelfa-crumb-size: 13px;
        --shelfa-current-crumb-size: 14px;
    }

    body.woocommerce .shop-loop-head :is(.wd-shop-tools, .woodmart-shop-tools, .woodmart-woo-breadcrumbs) {
        min-width: 0;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    body .product-labels .product-label.shelfa-stock-badge {
        padding: 4px 7px;
    }
}

/* Row one is the breadcrumb; row two holds the catalog controls. */
body.woocommerce .shop-loop-head {
    display: flex;
    flex-flow: column nowrap;
    align-items: stretch;
    gap: 8px;
    overflow: visible;
}
body.woocommerce .shop-loop-head > :is(.wd-shop-tools,.woodmart-shop-tools,.woodmart-woo-breadcrumbs) {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
    overflow: visible;
}
body.woocommerce .shop-loop-head :is(.wd-breadcrumbs,.woocommerce-breadcrumb) a :is(strong,b,span) {
    font-size: inherit !important;
    font-weight: inherit !important;
    color: inherit !important;
}

.shop-loop-head .shelfa-rail-enhanced { overflow: visible; }
.shop-loop-head .shelfa-rail-control {
    --shelfa-row: 36px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}
.shop-loop-head .shelfa-rail-caption { font-size: 13px; }
.shop-loop-head .shelfa-rail-stack {
    position: relative;
    display: inline-flex;
    isolation: isolate;
}
.shop-loop-head .shelfa-rail-open .shelfa-rail-stack { z-index: 25; }
body.woocommerce .shop-loop-head .shelfa-rail-button {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    min-height: 0;
    height: var(--shelfa-row);
    padding: 0;
    background: #fff;
    border: 1px solid #bad7ce;
    border-radius: 7px;
    color: #123f46;
    font-size: 14px;
    font-weight: 700;
    box-shadow: none;
    cursor: pointer;
}
.shop-loop-head .shelfa-choice-rail {
    position: absolute;
    z-index: 1;
    inset-inline: 0;
    top: calc(-1 * var(--shelfa-row) * var(--shelfa-active-row));
    display: grid;
    grid-auto-rows: var(--shelfa-row);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 0 0 1px #bad7ce, 0 6px 18px #123f4633;
}
.shop-loop-head .shelfa-choice-rail[hidden] { display: none !important; }
.shop-loop-head .shelfa-rail-row {
    display: grid;
    place-items: stretch;
    min-width: 0;
}
body.woocommerce .shop-loop-head .shelfa-rail-row a[href] {
    display: grid;
    place-items: center;
    padding: 0;
    margin: 0;
    border-radius: 7px;
    background: #fff;
    color: #123f46;
    opacity: 1;
}
body.woocommerce .shop-loop-head .shelfa-rail-row a[href]:is(:hover,:focus-visible),
body.woocommerce .shop-loop-head .shelfa-rail-button:is(:hover,[aria-expanded="true"]) {
    background: #e2f1eb;
}
.shop-loop-head :is(.shelfa-rail-button,.shelfa-rail-row) svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}
body.woocommerce .shop-loop-head:has(.shelfa-rail-open) {
    position: relative;
    z-index: 30;
}
@media (max-width: 767px) {
    body.woocommerce .shop-loop-head > :is(.wd-shop-tools,.woodmart-shop-tools):has(.shelfa-rail-enhanced) {
        gap: 6px 9px;
    }
    body.woocommerce .shop-loop-head .woocommerce-ordering {
        min-width: 0;
        max-width: 100%;
    }
    body.woocommerce .shop-loop-head .woocommerce-ordering select {
        max-width: 100%;
    }
}
