/* TNF sale badges 1.7.5. WooCommerce controls sale eligibility and accessible text.
 * Archive support includes classic product lists (with or without a .woocommerce
 * wrapper), Product Collection/Product Image blocks, and legacy product grids.
 */
body.tnf-sale-single .wp-block-woocommerce-product-image-gallery,
body.tnf-sale-single .woocommerce div.product {
    position: relative;
}

/* Keep each badge anchored to its product image/card, never to the viewport. */
body.tnf-sale-archive :is(
    ul.products li.product,
    .wc-block-product,
    .wc-block-grid__product,
    .wc-block-components-product-image,
    .wc-block-components-product-image > a,
    .wc-block-grid__product-image
) {
    position: relative;
}
body.tnf-sale-archive .wc-block-components-product-image__inner-container {
    position: static;
}

/* The WooCommerce block emits TWO elements: an outer .wp-block-woocommerce-
 * product-sale-badge wrapper and an inner .wc-block-components-product-sale-badge.
 * Position the wrapper once; the inner node supplies the decoration and label.
 * WooCommerce also absolutely positions the INNER badge in its Product Image CSS,
 * so override that rule to prevent competing offsets and a collapsed wrapper.
 */
body.tnf-sale-archive :is(
    .wc-block-product,
    .wc-block-components-product-image,
    .wp-block-woocommerce-product-collection,
    .wc-block-product-template
) .wp-block-woocommerce-product-sale-badge {
    position: absolute !important;
    top: var(--tnf-sale-inset) !important;
    width: var(--tnf-sale-size) !important;
    height: var(--tnf-sale-size) !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 9 !important;
    overflow: visible !important;
    line-height: normal;
}
body.tnf-sale-archive .wc-block-components-product-image .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge,
body.tnf-sale-archive .wc-block-product .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge,
body.tnf-sale-archive .wp-block-woocommerce-product-collection .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
}

/* Single-product native span badges may be direct OR nested gallery descendants.
 * The main gallery may also use a Sale Badge block with an outer wrapper.
 * Related-product archive badges are intentionally scoped to their own cards.
 */
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery,
    .woocommerce-product-gallery,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery)
) { position: relative; }
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery,
    .woocommerce-product-gallery
) .wp-block-woocommerce-product-sale-badge,
body.tnf-sale-single .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge {
    position: absolute !important;
    top: var(--tnf-sale-inset) !important;
    z-index: 20 !important;
    width: var(--tnf-sale-size) !important;
    height: var(--tnf-sale-size) !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
}
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery,
    .woocommerce-product-gallery
) .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge,
body.tnf-sale-single .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
}

/* Native badges in classic and block archives. Neither requires a div.woocommerce. */
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale
),
body.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale
) {
    position: absolute !important;
    z-index: 9 !important;
    top: var(--tnf-sale-inset) !important;
}

/* Badge SVG skin, attached to the label-bearing element exactly once. */
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
),
body.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
) {
    isolation: isolate;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: var(--tnf-sale-size) !important;
    height: var(--tnf-sale-size) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    background-image: none !important;
    color: var(--tnf-sale-color) !important;
    font-family: Arial, Helvetica, sans-serif !important;
    font-size: var(--tnf-sale-label-size, clamp(11px, calc(var(--tnf-sale-size) * .19), 27px)) !important;
    font-style: normal !important;
    font-weight: 800 !important;
    line-height: 1 !important;
    letter-spacing: -.02em !important;
    text-align: center !important;
    text-decoration: none !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
    float: none !important;
    transform: none !important;
}
body.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
)::before,
body.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
)::before {
    content: "" !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: -1;
    display: block !important;
    background: var(--tnf-sale-svg) center / contain no-repeat !important;
    pointer-events: none;
}
body.tnf-sale-archive .wc-block-components-product-sale-badge__text,
body.tnf-sale-archive .wc-block-grid__product-onsale > span:not(.screen-reader-text),
body.tnf-sale-single .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge__text,
body.tnf-sale-single .woocommerce-product-gallery .wc-block-components-product-sale-badge__text,
body.tnf-sale-single .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge__text {
    color: inherit !important;
    font: inherit !important;
    letter-spacing: inherit !important;
    text-transform: inherit !important;
    position: relative;
    z-index: 1;
}

body.tnf-sale-style-balloon.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
),
body.tnf-sale-style-balloon.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
) { padding-bottom: calc(var(--tnf-sale-size) * .18) !important; }
body.tnf-sale-style-ribbon.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
),
body.tnf-sale-style-ribbon.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
) { padding-bottom: calc(var(--tnf-sale-size) * .07) !important; }
body.tnf-sale-style-price-tag.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
),
body.tnf-sale-style-price-tag.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
) { padding-right: calc(var(--tnf-sale-size) * .15) !important; }

body.tnf-sale-motion.tnf-sale-single :is(
    .wp-block-woocommerce-product-image-gallery span.onsale,
    .woocommerce div.product > span.onsale,
    .woocommerce-product-gallery span.onsale,
    .wp-block-woocommerce-product-image-gallery .wc-block-components-product-sale-badge,
    .woocommerce-product-gallery .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-image-gallery .wc-block-grid__product-onsale,
    .wp-block-column:has(> .wp-block-woocommerce-product-image-gallery) > .wp-block-woocommerce-product-sale-badge .wc-block-components-product-sale-badge
)::before,
body.tnf-sale-motion.tnf-sale-archive :is(
    ul.products li.product .onsale,
    .wc-block-grid__product .wc-block-grid__product-onsale,
    .wc-block-components-product-image .wc-block-components-product-sale-badge,
    .wc-block-product .wc-block-components-product-sale-badge,
    .wp-block-woocommerce-product-collection .wc-block-components-product-sale-badge
)::before {
    transform-origin: 50% 45%;
    animation: tnf-sale-breathe 2.7s ease-in-out infinite;
}
@keyframes tnf-sale-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.045); }
}
@media (prefers-reduced-motion: reduce) {
    body.tnf-sale-motion :is(.onsale, .wc-block-grid__product-onsale, .wc-block-components-product-sale-badge)::before {
        animation: none !important;
    }
}

/* Sale-price typography: discount prices only. Regular prices, crossed-out
 * original prices, cart totals and checkout totals keep their theme styles.
 * Target product listings by product-item containers as well as price blocks.
 * This covers classic WooCommerce archives, Product Collection blocks,
 * legacy product grids, and single-product Price blocks.
 */
body.tnf-sale-price-custom .wp-block-woocommerce-product-price .wc-block-components-product-price ins,
body.tnf-sale-price-custom .wp-block-woocommerce-product-price .wc-block-components-product-price .wc-block-components-product-price__value.is-discounted,
body.tnf-sale-price-custom .wc-block-grid__product-price ins,
body.tnf-sale-price-custom .woocommerce div.product .summary p.price ins,
body.tnf-sale-price-custom .woocommerce div.product .summary span.price ins,
body.tnf-sale-price-custom .woocommerce div.product .woocommerce-variation-price .price ins,
body.tnf-sale-price-custom .woocommerce ul.products li.product .price ins,
body.tnf-sale-price-custom .woocommerce-page ul.products li.product .price ins,
/* Archive variants: a product card may not have a .woocommerce wrapper. */
body.tnf-sale-price-custom ul.products li.product .price ins,
body.tnf-sale-price-custom .wc-block-product .wc-block-components-product-price ins,
body.tnf-sale-price-custom .wc-block-product .wc-block-components-product-price__value.is-discounted,
body.tnf-sale-price-custom .wc-block-grid__product .wc-block-components-product-price ins,
body.tnf-sale-price-custom .wc-block-grid__product .wc-block-components-product-price__value.is-discounted,
body.tnf-sale-price-custom .wp-block-woocommerce-product-collection .wc-block-components-product-price ins,
body.tnf-sale-price-custom .wp-block-woocommerce-product-collection .wc-block-components-product-price__value.is-discounted,
body.tnf-sale-price-custom .wp-block-woocommerce-product-template .wc-block-components-product-price ins,
body.tnf-sale-price-custom .wp-block-woocommerce-product-template .wc-block-components-product-price__value.is-discounted {
    color: var(--tnf-sale-price-color, #16803d) !important;
    font-size: var(--tnf-sale-price-size, 120%) !important;
}

/* Some themes directly color WooCommerce amount and currency descendants.
 * Keep every part of the discounted price green and inherit its font scale.
 * Exclude .screen-reader-text so native WooCommerce announcements stay intact.
 */
body.tnf-sale-price-custom :is(
    .wp-block-woocommerce-product-price,
    .wc-block-product,
    .wc-block-grid__product,
    .wp-block-woocommerce-product-collection,
    .wp-block-woocommerce-product-template,
    ul.products li.product,
    .woocommerce div.product .summary,
    .woocommerce div.product .woocommerce-variation-price
) :is(.price, .wc-block-components-product-price, .wc-block-grid__product-price) ins :is(.woocommerce-Price-amount, bdi, .woocommerce-Price-currencySymbol) {
    color: inherit !important;
    font-size: inherit !important;
}

/* 1.7.6: Primary-product badge does not depend on the gallery's native badge
 * element or markup. The JS placement runs ONLY for the queried sale product.
 * Native archive/related product badges retain the proven 1.7.3 rules.
 */
body.tnf-sale-primary-on-sale .tnf-sale-primary-anchor {
    position: relative !important;
    isolation: isolate;
}
body.tnf-sale-primary-on-sale .tnf-sale-primary-anchor > .tnf-sale-badge-overlay {
    box-sizing: border-box !important;
    display: flex !important;
    position: absolute !important;
    z-index: 99 !important;
    top: var(--tnf-sale-inset, 8px) !important;
    width: var(--tnf-sale-size, 88px) !important;
    height: var(--tnf-sale-size, 88px) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--tnf-sale-color, #fff) !important;
    font-family: Arial, Helvetica, sans-serif !important;
    font-size: var(--tnf-sale-label-size, clamp(11px, calc(var(--tnf-sale-size) * .19), 27px)) !important;
    font-style: normal !important;
    font-weight: 800 !important;
    line-height: 1 !important;
    letter-spacing: -.02em !important;
    text-align: center !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
    float: none !important;
    transform: none !important;
    pointer-events: none !important;
}
body.tnf-sale-primary-on-sale .tnf-sale-primary-anchor > .tnf-sale-badge-overlay::before {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 0 !important;
    background: var(--tnf-sale-svg) center / contain no-repeat !important;
    pointer-events: none !important;
}
body.tnf-sale-primary-on-sale .tnf-sale-primary-anchor > .tnf-sale-badge-overlay > .tnf-sale-badge-overlay__text {
    position: relative !important;
    z-index: 1 !important;
    color: inherit !important;
    font: inherit !important;
    text-align: center !important;
}
body.tnf-sale-primary-on-sale.tnf-sale-style-balloon .tnf-sale-primary-anchor > .tnf-sale-badge-overlay {
    padding-bottom: calc(var(--tnf-sale-size) * .18) !important;
}
body.tnf-sale-primary-on-sale.tnf-sale-style-ribbon .tnf-sale-primary-anchor > .tnf-sale-badge-overlay {
    padding-bottom: calc(var(--tnf-sale-size) * .07) !important;
}
body.tnf-sale-primary-on-sale.tnf-sale-style-price-tag .tnf-sale-primary-anchor > .tnf-sale-badge-overlay {
    padding-right: calc(var(--tnf-sale-size) * .15) !important;
}
/* Prevent two badges showing on the same MAIN gallery. */
body.tnf-sale-primary-on-sale .tnf-sale-main-gallery :is(
    span.onsale,
    .wc-block-grid__product-onsale,
    .wp-block-woocommerce-product-sale-badge,
    .wc-block-components-product-sale-badge
):not(.tnf-sale-badge-overlay) {
    visibility: hidden !important;
}
body.tnf-sale-primary-on-sale.tnf-sale-motion .tnf-sale-primary-anchor > .tnf-sale-badge-overlay::before {
    transform-origin: 50% 45%;
    animation: tnf-sale-breathe 2.7s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
    body.tnf-sale-primary-on-sale.tnf-sale-motion .tnf-sale-primary-anchor > .tnf-sale-badge-overlay::before {
        animation: none !important;
    }
}
