:root {
    --ambitemp-catalog-text: #111111;
    --ambitemp-sale-red: #e74c3c;
    --ambitemp-catalog-blue: #3395c6;
}

/* Important declarations in this shared layer take precedence over the old
   unlayered Elementor/page-specific card rules, without changing their data. */
@layer ambitemp-catalog-cards {
    body ul.products:has(> li.product > .woocommerce-loop-product__link) {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        gap: 24px 16px !important;
        align-items: stretch !important;
        margin: 0 !important;
        padding: 0 !important;
        list-style: none !important;
    }
    /* Retain the existing six-product promotion row on the home page. */
    body.home ul.products.columns-6:has(> li.product > .woocommerce-loop-product__link) {
        grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    }
    /* Keep the existing related row full-width when WooCommerce returns
       fewer recommendations; this stylesheet does not change that query. */
    .single-product .related.products ul.products {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)) !important;
    }
    body ul.products:has(> li.product > .woocommerce-loop-product__link)::before,
    body ul.products:has(> li.product > .woocommerce-loop-product__link)::after {
        display: none !important;
    }
    body ul.products > li.product:has(> .woocommerce-loop-product__link) {
        position: relative !important;
        display: flex !important;
        flex-direction: column !important;
        float: none !important;
        clear: none !important;
        width: auto !important;
        min-width: 0 !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 12px !important;
        background: #fff !important;
        border: 1px solid #d3d7db !important;
        transition: border-color .18s ease;
        border-radius: 20px !important;
        box-sizing: border-box !important;
        box-shadow: none !important;
        font-family: 'Montserrat', sans-serif !important;
        container-type: inline-size;
    }
    body ul.products > li.product:has(> .woocommerce-loop-product__link):is(:hover, :focus-within) {
        border-color: #454b50 !important;
    }
    body ul.products > li.product > .ambp-related-availability {
        margin-top: 8px; min-height: 44px; font-size: 11px; line-height: 1.5;
    }
    body ul.products .ambp-related-stock-row {
        display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
    }
    body ul.products .ambp-related-stock-label { white-space: nowrap; text-align: left; }
    body ul.products .ambp-related-stock-status { text-align: right; }
    @container (max-width: 180px) {
        body ul.products .ambp-related-stock-row {
            display: grid; grid-template-columns: 1fr; gap: 0; min-height: 34px;
        }
        body ul.products .ambp-related-stock-status { text-align: left; white-space: nowrap; }
    }
    body ul.products .ambp-status-dot {
        display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px;
    }
    body ul.products .ambp-status-dot--stock { background: #26b76c; }
    body ul.products .ambp-status-dot--poucas { background: #efc84a; }
    body ul.products .ambp-status-dot--encomenda { background: #459fdf; }
    body ul.products .ambp-status-dot--indisponivel { background: #c63b2c; }
    body ul.products > li.product > .woocommerce-loop-product__link {
        position: relative !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        min-width: 0 !important;
        color: var(--ambitemp-catalog-text) !important;
        text-decoration: none !important;
    }
    body ul.products > li.product > .woocommerce-loop-product__link > img {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 !important;
        max-height: 220px !important;
        object-fit: contain !important;
        margin: 0 0 10px !important;
        background: #fff !important;
    }
    body ul.products > li.product .woocommerce-loop-product__title {
        margin: 0 !important;
        padding: 6px 0 !important;
        min-height: 0 !important;
        color: var(--ambitemp-catalog-text) !important;
        font-family: 'Montserrat', sans-serif !important;
        font-size: 13px !important;
        font-weight: 500 !important;
        line-height: 1.4 !important;
        text-align: center !important;
        text-transform: uppercase !important;
        text-decoration: none !important;
        overflow-wrap: anywhere !important;
    }
    body ul.products > li.product .price {
        display: block !important;
        margin: auto 0 0 !important;
        padding: 8px 0 0 !important;
        min-height: 50px !important;
        box-sizing: border-box !important;
        color: var(--ambitemp-catalog-text) !important;
        font-family: 'Montserrat', sans-serif !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        line-height: 1.4 !important;
        text-align: center !important;
    }
    body ul.products > li.product .price :is(.amount, bdi, .woocommerce-Price-currencySymbol) {
        display: inline !important;
        margin: 0 !important;
        color: inherit !important;
        font: inherit !important;
        white-space: nowrap !important;
    }
    body ul.products > li.product .price :is(del, ins) {
        display: inline !important;
        background: transparent !important;
        color: inherit !important;
        font: inherit !important;
    }
    body ul.products > li.product .price del {
        opacity: .65 !important;
    }
    body ul.products > li.product .amb-stock-indicator {
        min-height: 22px !important;
        margin: 6px 0 0 !important;
        font-family: 'Montserrat', sans-serif !important;
        font-size: 11px !important;
        line-height: 1.45 !important;
        text-align: left !important;
    }
    /* Related products retain their existing online/store availability rows. */
    body ul.products > li.product:has(> .ambp-related-availability) .amb-stock-indicator {
        display: none !important;
    }
    body ul.products > li.product > .button {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        align-self: stretch !important;
        flex-shrink: 0 !important;
        width: 100% !important;
        min-height: 40px !important;
        margin: 12px 0 0 !important;
        padding: 10px 8px !important;
        box-sizing: border-box !important;
        border: 1px solid var(--ambitemp-catalog-blue) !important;
        border-radius: 10px !important;
        background: var(--ambitemp-catalog-blue) !important;
        color: #fff !important;
        font-family: 'Montserrat', sans-serif !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        line-height: 1.3 !important;
        text-decoration: none !important;
        box-shadow: none !important;
    }
    body ul.products > li.product > .button:hover {
        background: #237da7 !important;
        border-color: #237da7 !important;
    }
    /* WooCommerce appends this secondary action after an AJAX add. The same
       rule covers the home page, shop, archives and related products. */
    body ul.products > li.product > a.added_to_cart.wc-forward {
        display:inline-flex!important;
        align-items:center!important;
        justify-content:center!important;
        align-self:stretch!important;
        width:100%!important;
        min-height:38px!important;
        margin:8px 0 0!important;
        padding:8px!important;
        box-sizing:border-box!important;
        border:1px solid var(--ambitemp-catalog-blue)!important;
        border-radius:10px!important;
        background:#fff!important;
        color:#267da7!important;
        font-family:Montserrat,Arial,sans-serif!important;
        font-size:12px!important;
        font-weight:600!important;
        line-height:1.4!important;
        text-align:center!important;
        text-transform:none!important;
        text-decoration:none!important;
        box-shadow:none!important;
    }
    body ul.products > li.product > a.added_to_cart.wc-forward:hover { background:#edf8fd!important; }
    body ul.products > li.product > a.added_to_cart.wc-forward:focus-visible { outline:2px solid #267da7!important; outline-offset:3px!important; }
    body ul.products > li.product > .button:focus-visible,
    body ul.products > li.product > .woocommerce-loop-product__link:focus-visible {
        outline: 2px solid #237da7 !important;
        outline-offset: 3px !important;
    }
    body ul.products > li.product > .amb-favorite-button--loop {
        top: 12px !important;
        right: 12px !important;
        width: 40px !important;
        height: 40px !important;
    }
    body ul.products > li.product .onsale {
        position: absolute !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        top: 0 !important;
        /* Keep the existing link gutter and inset the promotion badge 8px from its previous position. */
        left: -4px !important;
        right: auto !important;
        width: 72px !important;
        min-width: 72px !important;
        height: 36px !important;
        min-height: 36px !important;
        margin: 0 !important;
        padding: 0 6px !important;
        box-sizing: border-box !important;
        border: 0 !important;
        border-radius: 999px !important;
        background: var(--ambitemp-sale-red) !important;
        color: #fff !important;
        font-family: 'Montserrat', sans-serif !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        line-height: 1 !important;
        text-align: center !important;
    }
    @media (max-width: 1024px) {
        body ul.products:has(> li.product > .woocommerce-loop-product__link),
        body.home ul.products.columns-6:has(> li.product > .woocommerce-loop-product__link) {
            grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        }
        .single-product .related.products ul.products {
            grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)) !important;
        }
    }
    @media (max-width: 767px) {
        body ul.products:has(> li.product > .woocommerce-loop-product__link),
        body.home ul.products.columns-6:has(> li.product > .woocommerce-loop-product__link) {
            grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
            column-gap: 12px !important;
        }
        .single-product .related.products ul.products {
            grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)) !important;
        }
        body ul.products > li.product > .amb-favorite-button--loop {
            width: 36px !important;
            height: 36px !important;
        }
        body ul.products > li.product .onsale {
            min-width: 64px !important;
            width: 64px !important;
            height: 34px !important;
            min-height: 34px !important;
            font-size: 10px !important;
        }
    }

    /* Approved shared card refresh: data and native actions remain unchanged. */
    body ul.products:has(> li.product > .woocommerce-loop-product__link) {
        gap: 24px 22px !important;
        padding: 4px !important;
        box-sizing: border-box !important;
        background: #fff !important;
    }
    body .elementor-widget-woocommerce-products > .elementor-widget-container:has(ul.products > li.product > .woocommerce-loop-product__link) {
        background: #fff !important;
    }
    body ul.products > li.product:has(> .woocommerce-loop-product__link) {
        padding: 16px !important;
        border-color: #e1e5e8 !important;
        border-radius: 14px !important;
        box-shadow: 0 3px 10px rgba(20, 30, 40, .08) !important;
        transition: border-color .18s ease, box-shadow .18s ease;
    }
    body ul.products > li.product:has(> .woocommerce-loop-product__link):is(:hover, :focus-within) {
        border-color: #c6cdd3 !important;
        box-shadow: 0 6px 18px rgba(20, 30, 40, .13) !important;
    }
    body ul.products > li.product > .woocommerce-loop-product__link > img {
        height: 170px !important;
        aspect-ratio: auto !important;
        margin: 28px 0 12px !important;
    }
    body ul.products > li.product .ambp-product-flags--loop { min-height: 28px !important; }
    body ul.products > li.product .woocommerce-loop-product__title {
        min-height: 5.6em !important;
        font-size: 14px !important;
        text-transform: none !important;
    }
    body ul.products > li.product .price {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 0 !important;
        font-size: 18px !important;
    }
    body ul.products > li.product .price del {
        opacity: 1 !important;
        color: #6b7278 !important;
        font-size: 12px !important;
        font-weight: 500 !important;
    }
    body ul.products > li.product .price ins {
        text-decoration: none !important;
        font-weight: 700 !important;
    }
    body ul.products > li.product > .ambp-related-availability {
        margin-top: 12px;
        min-height: 72px;
        font-size: 12px;
        line-height: 1.45;
        color: #26313b;
    }
    body ul.products .ambp-related-stock-row {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
        min-height: 36px;
    }
    body ul.products .ambp-related-stock-label { color: #626b73; }
    body ul.products .ambp-related-stock-status { text-align: left; }
    body ul.products > li.product > .button {
        min-height: 42px !important;
        border-radius: 8px !important;
    }
    body ul.products > li.product > .amb-favorite-button--loop {
        width: 34px !important;
        height: 34px !important;
    }
    body ul.products > li.product .onsale {
        width: 66px !important;
        min-width: 66px !important;
        height: 28px !important;
        min-height: 28px !important;
    }
    @media (prefers-reduced-motion: no-preference) {
        body ul.products > li.product:has(> .woocommerce-loop-product__link) {
            transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
        }
        body ul.products > li.product:has(> .woocommerce-loop-product__link):hover { transform: translateY(-2px); }
    }
    @media (prefers-reduced-motion: reduce) {
        body ul.products > li.product:has(> .woocommerce-loop-product__link) { transition: none; }
    }
    @media (max-width: 767px) {
        body ul.products:has(> li.product > .woocommerce-loop-product__link),
        body.home ul.products.columns-6:has(> li.product > .woocommerce-loop-product__link) { column-gap: 14px !important; }
        body ul.products > li.product:has(> .woocommerce-loop-product__link) { padding: 12px !important; }
        body ul.products > li.product > .woocommerce-loop-product__link > img { height: 136px !important; }
        body ul.products > li.product .woocommerce-loop-product__title { font-size: 12px !important; }
        body ul.products > li.product .price { font-size: 16px !important; }
        body ul.products > li.product .price del { font-size: 11px !important; }
        body ul.products > li.product > .ambp-related-availability { font-size: 11px; }
        body ul.products > li.product > .amb-favorite-button--loop { width: 30px !important; height: 30px !important; }
        body ul.products > li.product .onsale { width: 60px !important; min-width: 60px !important; height: 26px !important; min-height: 26px !important; font-size: 10px !important; }
    }
}
