/* Loading feedback for add-to-cart buttons and the mini-cart drawer.
 * Driven by assets/js/cart-loading.js (body.hypro-cart-busy) and by the
 * classes WooCommerce / product-detail.js put on the buttons themselves
 * (.loading on ajax_add_to_cart buttons, .is-adding on the product page). */

@keyframes hypro-spin {
	to {
		transform: rotate(360deg);
	}
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
body a.add_to_cart_button.lp-btn.loading,
body .pd-atc-btn.is-adding {
	position: relative;
	pointer-events: none; /* no double-adds while the request is in flight */
	opacity: 0.85;
}

/* Replaces WooCommerce's icon-font spinner with a plain CSS one. */
body a.add_to_cart_button.lp-btn.loading::after,
body .pd-atc-btn.is-adding::after {
	content: '';
	position: static;
	display: inline-block;
	width: 14px;
	height: 14px;
	margin-left: 8px;
	vertical-align: -2px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	font-family: inherit;
	animation: hypro-spin 0.7s linear infinite;
}

/* ── Mini-cart drawer ─────────────────────────────────────────────────── */
/* While an add / remove is in flight: spinner over the drawer content, and
 * the "empty cart" message hidden so it can't flash before items arrive. */
body.hypro-cart-busy .wc-block-mini-cart__drawer .wc-block-components-drawer__content {
	position: relative;
}

body.hypro-cart-busy .wc-block-mini-cart__drawer .wc-block-components-drawer__content::before {
	content: '';
	position: absolute;
	inset: 0;
	z-index: 5;
	background: rgba(255, 255, 255, 0.78);
}

body.hypro-cart-busy .wc-block-mini-cart__drawer .wc-block-components-drawer__content::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 6;
	width: 32px;
	height: 32px;
	margin: -16px 0 0 -16px;
	border: 3px solid var(--hypro-blue, #1526be);
	border-right-color: transparent;
	border-radius: 50%;
	animation: hypro-spin 0.7s linear infinite;
}

/* Keep the close button usable above the overlay. */
body.hypro-cart-busy .wc-block-mini-cart__drawer .wc-block-components-drawer__close {
	z-index: 7;
}

body.hypro-cart-busy .wp-block-woocommerce-empty-mini-cart-contents-block {
	visibility: hidden;
}

/* Header bag icon pulses while the cart updates. */
body.hypro-cart-busy .hypro-header .wc-block-mini-cart__button {
	animation: hypro-cart-pulse 0.8s ease-in-out infinite;
}

@keyframes hypro-cart-pulse {
	50% {
		opacity: 0.45;
	}
}

@media (prefers-reduced-motion: reduce) {
	body a.add_to_cart_button.lp-btn.loading::after,
	body .pd-atc-btn.is-adding::after,
	body.hypro-cart-busy .wc-block-mini-cart__drawer .wc-block-components-drawer__content::after,
	body.hypro-cart-busy .hypro-header .wc-block-mini-cart__button {
		animation-duration: 2s;
	}
}
