/* The light, arc detail and enamel finish are background layers. Theme icons
   and the product's accessible button label keep their original markup. */
:is(form.cart, form.wp-block-woocommerce-add-to-cart-with-options, form.wc-block-add-to-cart-with-options)
.single_add_to_cart_button[hidden] {
    display: none !important;
}

body:is(.caatc-button-maritime, .caatc-button-shimmer)
:is(form.cart, form.wp-block-woocommerce-add-to-cart-with-options, form.wc-block-add-to-cart-with-options)
button.single_add_to_cart_button:not([hidden]),
.caatc-button-examples :is(.caatc-example-maritime, .caatc-example-shimmer) {
    --caatc-enamel: linear-gradient(135deg, #205566, #103648 55%, #0a283a);
    --caatc-arcs: radial-gradient(circle at 100% 135%,
        transparent 28px, #eacb8d38 29px, transparent 30px 37px,
        #eacb8d38 38px, transparent 39px 46px, #eacb8d38 47px, transparent 48px);
    box-sizing: border-box;
    min-height: 46px;
    padding: .68em 1.25em;
    border: 1px solid #a78b5a;
    border-radius: .65rem;
    background-color: #103648;
    background-image: var(--caatc-arcs), var(--caatc-enamel);
    background-repeat: no-repeat;
    color: #fffaf0;
    box-shadow: inset 0 1px 0 #fff2, 0 2px 5px #092a3b29;
    font-weight: 650;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    text-transform: none;
    letter-spacing: normal;
    white-space: normal;

    &:focus-visible {
        outline: 3px solid #196a84;
        outline-offset: 3px;
        box-shadow: 0 0 0 3px #fffaf0;
    }

    @media (hover: hover) {
        &:hover {
            --caatc-enamel: linear-gradient(135deg, #266475, #16465a 55%, #103648);
            border-color: #c7a869;
        }
    }

    &:active {
        box-shadow: inset 0 2px 4px #061a2c55;
    }

    &:is(:disabled, .disabled, [aria-disabled="true"], .wc-variation-selection-needed, .wc-variation-is-unavailable) {
        background: #465860;
        border-color: #65747a;
        box-shadow: none;
        color: #fff;
        opacity: 1;
        cursor: not-allowed;
    }
}

/* One pass per six-second cycle, with the highlight parked offscreen
   between passes. Animating a background leaves WooCommerce's icons free. */
@media (prefers-reduced-motion: no-preference) {
    body.caatc-button-shimmer
    :is(form.cart, form.wp-block-woocommerce-add-to-cart-with-options, form.wc-block-add-to-cart-with-options)
    button.single_add_to_cart_button:not(:is([hidden], :disabled, .disabled, .loading, .custom_loading, [aria-busy="true"], [aria-disabled="true"], .wc-variation-selection-needed, .wc-variation-is-unavailable)),
    .caatc-button-examples .caatc-example-shimmer {
        background-image: linear-gradient(110deg,
            transparent 43%, #ffe0a514 47%, #ffe8ad40 50%, #fff3d914 53%, transparent 57%),
            var(--caatc-arcs), var(--caatc-enamel);
        background-size: 240% 100%, 100% 100%, 100% 100%;
        background-position: 145% 0, 0 0, 0 0;
        animation: caatc-product-shimmer 6s ease-in-out infinite;
    }
}

@keyframes caatc-product-shimmer {
    0%, 15% { background-position: 145% 0, 0 0, 0 0; }
    40%, 100% { background-position: -45% 0, 0 0, 0 0; }
}

/* The AJAX spinner stays inside the button, also when the popup is off. */
body form.cart button.single_add_to_cart_button.custom_loading:not([hidden]) {
    position: relative;
    padding-inline-end: 2rem;
    cursor: progress;
}
form.cart button.single_add_to_cart_button.custom_loading::after {
    content: "";
    position: absolute;
    inset-inline-end: .55rem;
    inset-block-start: 50%;
    margin: -.45rem 0 0;
    box-sizing: border-box;
    width: .9rem;
    height: .9rem;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: 50%;
}
@media (prefers-reduced-motion: no-preference) {
    form.cart button.single_add_to_cart_button.custom_loading::after {
        animation: caatc-product-spin .7s linear infinite;
    }
}
@keyframes caatc-product-spin {
    to { transform: rotate(360deg); }
}
/* Only the immediate parent of the two purchase controls becomes a row.
   Attribute tables and grouped-product quantity lists keep their own layout. */
@media (max-width: 768px) {
    :is(
        form.cart, form.cart :where(div, p),
        .wc-block-add-to-cart-with-options, .wc-block-add-to-cart-with-options .wp-block-group
    ):has(> :is(.quantity, .wc-block-add-to-cart-with-options__quantity-selector)):has(> :is(.single_add_to_cart_button, .wc-block-components-product-button, .wp-block-woocommerce-product-button)):not([hidden]) {
        display: flex;
        flex-flow: row wrap !important;
        align-items: center;
        justify-content: start;
        gap: .5rem;
        min-width: 0;

        /* Clearfix boxes from classic themes otherwise consume flex slots. */
        &::before, &::after {
            content: none;
        }

        /* Notices and fields inserted by WooCommerce hooks get a separate line. */
        & > * {
            flex: 0 0 100%;
            box-sizing: border-box;
        }

        & > :is(.quantity, .wc-block-add-to-cart-with-options__quantity-selector) {
            flex: 0 1 auto !important;
            width: fit-content !important;
            min-width: 0;
            max-width: 46%;
            margin: 0 !important;
        }

        & > :is(.quantity, .wc-block-add-to-cart-with-options__quantity-selector) input.qty {
            box-sizing: border-box;
            max-width: min(100%, 4.25rem);
        }

        /* Fixed quantities can be rendered as a label and a hidden field. */
        & > [hidden],
        & > .quantity:has(input.qty[type="hidden"]):not(:has(input:not([type="hidden"]), button, select)),
        & > .wc-block-add-to-cart-with-options__quantity-selector--hidden {
            display: none !important;
        }

        & > :is(.single_add_to_cart_button, .wc-block-components-product-button, .wp-block-woocommerce-product-button) {
            flex: 1 1 0% !important;
            width: auto !important;
            min-width: 0 !important;
            max-width: none;
            margin: 0 !important;
        }

        & > :is(.wc-block-components-product-button, .wp-block-woocommerce-product-button) .single_add_to_cart_button {
            width: 100%;
            min-width: 0;
            box-sizing: border-box;
        }

        & .single_add_to_cart_button {
            height: auto !important;
            white-space: normal;
            overflow-wrap: anywhere;
        }

        /* Keep the controls together if a hook inserts content between them. */
        & > :is(.quantity, .wc-block-add-to-cart-with-options__quantity-selector) ~ :not(.single_add_to_cart_button, .wc-block-components-product-button, .wp-block-woocommerce-product-button) {
            order: 1;
        }
    }
}
