/**
 * Ajax Add to Cart Button for Bricks
 *
 * BEM: block `ajax-cart-btn`
 *  - elements:  __label, __state, __spinner, __icon
 *  - modifiers: --busy, --loading, --success, --error
 *
 * All defaults below are intentionally low-specificity (single class) so the
 * Bricks style tab (padding, background, typography, border ...) wins.
 */

.ajax-cart-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5em;
	padding: 0.75em 1.5em;
	background-color: #1f2937;
	color: #ffffff;
	font: inherit;
	line-height: 1.2;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	text-align: center;
	transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.ajax-cart-btn:hover {
	opacity: 0.92;
}

/* While busy the button must not be clickable. */
.ajax-cart-btn--busy,
.ajax-cart-btn[disabled] {
	pointer-events: none;
	cursor: not-allowed;
}

/* Label keeps its space (visibility, not display) so the button never resizes. */
.ajax-cart-btn__label {
	transition: opacity 0.15s ease;
}

.ajax-cart-btn--busy .ajax-cart-btn__label {
	opacity: 0;
	visibility: hidden;
}

/* State layers: centered over the whole button, hidden by default. */
.ajax-cart-btn__state {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	display: none;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

.ajax-cart-btn--loading .ajax-cart-btn__state--loading,
.ajax-cart-btn--success .ajax-cart-btn__state--success,
.ajax-cart-btn--error .ajax-cart-btn__state--error {
	display: inline-flex;
}

/* Icons inherit the state color (overridable via element controls). */
.ajax-cart-btn__icon {
	display: inline-block;
	width: 1em;
	height: 1em;
	font-size: inherit;
	line-height: 1;
}

svg.ajax-cart-btn__icon {
	stroke: currentColor;
}

/* Built-in CSS spinner (used when no loading icon is chosen). */
.ajax-cart-btn__spinner {
	display: inline-block;
	width: 1.1em;
	height: 1.1em;
	border: 2px solid currentColor;
	border-bottom-color: transparent;
	border-radius: 50%;
	animation: bacb-spin 0.7s linear infinite;
}

/* A chosen loading icon rotates. */
.ajax-cart-btn__icon--spin {
	animation: bacb-spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
	.ajax-cart-btn__spinner,
	.ajax-cart-btn__icon--spin {
		animation-duration: 1.6s;
	}
}

/* Defensive: WooCommerce (or a theme/plugin listening to added_to_cart) must
   never inject its native "View cart" link next to this button - the button
   manages its own success feedback. */
.ajax-cart-btn + .added_to_cart {
	display: none;
}

/* Screen-reader-only state announcements. */
.bacb-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
