/*
 * Shared add-to-cart button states: loading, and the "View cart" link shown once added.
 *
 * WooCommerce's loading state fades the button to 25 % and pins an icon-font glyph near its
 * right edge, off-centre on full-width buttons. Here the label is hidden and a spinner is drawn
 * in the exact centre, keeping the button's size and colour.
 *
 * Consumers: product card button, product page button, mobile sticky bar button. Each selector
 * repeats its component's own scope so it outranks WooCommerce's `.woocommerce a.button.loading`.
 */

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

:is(
	.lp-card-grid.products .lp-card .lp-card__actions .button,
	.single-product div.product form.cart .single_add_to_cart_button.button.alt,
	.single-product .lp-sticky-cart .lp-sticky-cart__button.button.alt
).loading {
	position: relative;
	color: transparent;
	opacity: 1;
	pointer-events: none;
}

:is(
	.lp-card-grid.products .lp-card .lp-card__actions .button,
	.single-product div.product form.cart .single_add_to_cart_button.button.alt,
	.single-product .lp-sticky-cart .lp-sticky-cart__button.button.alt
).loading::after {
	content: "";
	position: absolute;
	inset: 0;
	width: 1.125rem;
	height: 1.125rem;
	margin: auto;
	border: 2px solid var(--lp-on-teal);
	border-top-color: transparent;
	border-radius: 50%;
	font-family: inherit;
	animation: lp-spin 0.7s linear infinite;
}

/*
 * "View cart" link shown once a product is added: WooCommerce's own link (cards, product page),
 * which it appends as bare text next to the button, and the mobile sticky bar's link.
 * Rendered as a full-width secondary button with a check mark; each context places it.
 * Plain selector lists (not :is()) so each context keeps its own specificity for overrides.
 */
.lp-card-grid.products .lp-card .lp-card__actions .added_to_cart,
.single-product div.product form.cart .added_to_cart,
.lp-sticky-cart .lp-sticky-cart__view-cart {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	width: 100%;
	min-height: 44px;
	margin: 0;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--lp-teal-text);
	border-radius: var(--lp-radius);
	background: var(--lp-surface);
	font-family: var(--lp-font-body);
	font-size: 0.875rem;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	color: var(--lp-teal-text);
	transition: background 0.2s;
}

.lp-card-grid.products .lp-card .lp-card__actions .added_to_cart:hover,
.single-product div.product form.cart .added_to_cart:hover,
.lp-sticky-cart .lp-sticky-cart__view-cart:hover {
	background: var(--lp-bg-light);
	color: var(--lp-teal-text);
}

.lp-card-grid.products .lp-card .lp-card__actions .added_to_cart:focus-visible,
.single-product div.product form.cart .added_to_cart:focus-visible,
.lp-sticky-cart .lp-sticky-cart__view-cart:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

/* Check mark drawn in the text colour. */
.lp-card-grid.products .lp-card .lp-card__actions .added_to_cart::before,
.single-product div.product form.cart .added_to_cart::before,
.lp-sticky-cart .lp-sticky-cart__view-cart::before {
	content: "";
	flex: none;
	width: 1rem;
	height: 1rem;
	background: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

@media (prefers-reduced-motion: reduce) {
	:is(
		.lp-card-grid.products .lp-card .lp-card__actions .button,
		.single-product div.product form.cart .single_add_to_cart_button.button.alt,
		.single-product .lp-sticky-cart .lp-sticky-cart__button.button.alt
	).loading::after {
		animation-duration: 2s;
	}
}
