/* One stable feedback state for WooCommerce and Ganjeh Kala purchase controls.
 * This does not modify the button's label, dimensions or selected Elementor styles.
 * An overlay hides competing third-party icons while Ajax is pending.
 */
:is(a.ajax_add_to_cart, button.single_add_to_cart_button).loading,
.gk-cart-widget .gk-cart-add.is-loading,
.gk-cart-widget.is-busy .gk-cart-add:not([hidden]) {
    position: relative !important;
    isolation: isolate;
    overflow: hidden !important;
    pointer-events: none;
    opacity: 1 !important;
    box-sizing: border-box;
    /* Prevent hover-lift or click transforms from shifting the loader. */
    transform: none !important;
    filter: none !important;
    transition: none !important;
}

/* An opaque copy of the button background conceals its text, embedded icon,
 * WooCommerce loading glyph and any Elementor icon. The original content still
 * occupies exactly the same space, so there is no reflow or label jump. */
:is(a.ajax_add_to_cart, button.single_add_to_cart_button).loading::before,
.gk-cart-widget .gk-cart-add.is-loading::before,
.gk-cart-widget.is-busy .gk-cart-add:not([hidden])::before {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: inherit !important;
    background: inherit !important;
    /* Measurement Pricing draws a cart icon by masking ::before. That mask
     * must never clip the loading overlay on native or Elementor buttons. */
    -webkit-mask: none !important;
    mask: none !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
    clip-path: none !important;
    box-shadow: none !important;
    transform: none !important;
    animation: none !important;
    opacity: 1 !important;
    z-index: 2;
    pointer-events: none;
}

/* Only one spinner, centered over the existing button without inserting a node
 * or modifying padding. Explicit longhands neutralize WooCommerce icon-font
 * animations and relative positioning, including on RTL pages. */
:is(a.ajax_add_to_cart, button.single_add_to_cart_button).loading::after,
.gk-cart-widget .gk-cart-add.is-loading::after,
.gk-cart-widget.is-busy .gk-cart-add:not([hidden])::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    inset: auto !important;
    top: calc(50% - 9px) !important;
    left: calc(50% - 9px) !important;
    right: auto !important;
    bottom: auto !important;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    border: 2px solid currentColor !important;
    border-inline-start-color: transparent !important;
    border-radius: 50% !important;
    background: none !important;
    -webkit-mask: none !important;
    mask: none !important;
    clip-path: none !important;
    box-shadow: none !important;
    font-size: 0 !important;
    line-height: 0 !important;
    opacity: 1 !important;
    transform: rotate(0deg);
    animation: gk-atc-feedback-spin .75s linear infinite !important;
    z-index: 3;
    pointer-events: none;
}

/* WooCommerce adds extra right padding when its Ajax loop link is loading.
 * Neutralize that at the same specificity while leaving the rest of the
 * theme's button design (including user-configured Elementor sizing) intact. */
.woocommerce a.button.ajax_add_to_cart.loading,
a.button.ajax_add_to_cart.loading {
    padding-left: 1em !important;
    padding-right: 1em !important;
}

/* The separate success toast / updated cart already confirms the action.
 * Suppress WooCommerce's icon-font tick rather than showing two confirmations. */
:is(a.ajax_add_to_cart, button.single_add_to_cart_button).added:not(.loading)::after {
    content: none !important;
    display: none !important;
    animation: none !important;
}

/* Quantity-edit requests should not append an additional pseudo-element to
 * the flex row (which changed its width); the same overlay is used in place. */
.gk-cart-widget .gk-cart-qty:is(.is-loading, .is-pending) {
    position: relative;
    isolation: isolate;
    overflow: hidden;
}
.gk-cart-widget .gk-cart-qty:is(.is-loading, .is-pending)::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    background: var(--gk-cart-surface, #fff);
    border-radius: inherit;
    pointer-events: none;
}
.gk-cart-widget .gk-cart-qty:is(.is-loading, .is-pending)::after {
    content: "";
    position: absolute;
    top: calc(50% - 9px);
    left: calc(50% - 9px);
    width: 18px;
    height: 18px;
    box-sizing: border-box;
    border: 2px solid var(--gk-cart-primary, currentColor);
    border-inline-start-color: transparent;
    border-radius: 50%;
    background: none;
    margin: 0;
    z-index: 3;
    animation: gk-atc-feedback-spin .75s linear infinite;
    pointer-events: none;
}

@keyframes gk-atc-feedback-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    :is(a.ajax_add_to_cart, button.single_add_to_cart_button).loading::after,
    .gk-cart-widget .gk-cart-add.is-loading::after,
    .gk-cart-widget.is-busy .gk-cart-add:not([hidden])::after,
    .gk-cart-widget .gk-cart-qty:is(.is-loading, .is-pending)::after {
        animation: none !important;
        border-block-start-color: transparent !important;
    }
}
