/* ==========================================================================
   Mini cart loading: what the Elementor mini cart shows while "Add to basket" runs.

   add-to-cart.js sets .stbhh-cart-loading on the drawer (and the placeholder and
   toggle classes below), so this file loads with that script, whether or not the
   Mini Cart module is on. The shimmer colours and speed are the Design page's
   (Global style, Loading shimmer). The Mini Cart module's own lines have extra
   rules in mini-cart.css (section 10).
   ========================================================================== */

/* ---------- Mini cart loading: skeleton ----------
   The mini cart opens as soon as "Add to basket" is clicked and its content turns
   into shimmering placeholders until the basket is up to date (add-to-cart.js sets
   and removes the class). It is the same gradient as the "Total due" of the checkout
   while it recalculates.
   The class sits on the drawer's stable content area, not on .widget_shopping_cart_content,
   which WooCommerce replaces on every refresh. The selectors cover Elementor Pro's
   mini cart markup and WooCommerce's standard one. */

.stbhh-cart-loading {
	--stbhh-sk-a: var(--stbhh-set-sk-a, #E9ECF7);
	--stbhh-sk-b: var(--stbhh-set-sk-b, #F6F7FC);
	--stbhh-sk: linear-gradient(90deg, var(--stbhh-sk-a) 25%, var(--stbhh-sk-b) 50%, var(--stbhh-sk-a) 75%) 0 0 / 200% 100%;
}

/* The content is not clickable while it loads. This is set on the children, never on
   the drawer itself: a click on a drawer that ignores clicks would land on Elementor's
   backdrop behind it, and Elementor closes the mini cart on a click there. */
.stbhh-cart-loading > * {
	pointer-events: none;
}

/* Leaving remains possible while it loads. */
.stbhh-cart-loading > .elementor-menu-cart__close-button {
	pointer-events: auto;
}

/* Text and amounts: the words become a shimmering bar of their own size. */
.stbhh-cart-loading :is(
	.elementor-menu-cart__product-name a,
	.elementor-menu-cart__product-name .variation,
	.elementor-menu-cart__product-price .product-quantity,
	.elementor-menu-cart__product-price .woocommerce-Price-amount,
	.elementor-menu-cart__subtotal .woocommerce-Price-amount,
	.woocommerce-mini-cart-item .woocommerce-Price-amount,
	.woocommerce-mini-cart__total .woocommerce-Price-amount
) {
	border-radius: 6px;
	background: var(--stbhh-sk);
	color: transparent;
	animation: stbhh-cart-shimmer var(--stbhh-set-sk-speed, 1s) linear infinite;
	user-select: none;
}

/* Everything inside an amount (currency symbol, raised decimals) hides with it. */
.stbhh-cart-loading .woocommerce-Price-amount * {
	color: transparent;
}

/* Product photos: the picture hides and its wrapper shimmers in its place. */
.stbhh-cart-loading :has(> img) {
	border-radius: 10px;
	background: var(--stbhh-sk);
	animation: stbhh-cart-shimmer var(--stbhh-set-sk-speed, 1s) linear infinite;
}

.stbhh-cart-loading img {
	opacity: 0;
}

/* Buttons and remove links stay in place, softened. */
.stbhh-cart-loading :is(.elementor-menu-cart__footer-buttons, .woocommerce-mini-cart__buttons, .elementor-menu-cart__product-remove) {
	opacity: .55;
}

/* A basket with nothing in it yet has no rows to turn into placeholders, so the
   script adds one placeholder row, and hides the "empty" message, while it loads. */
.stbhh-cart-placeholder {
	display: grid;
	grid-template-columns: 48px minmax(0, 1fr) auto;
	align-items: center;
	gap: 12px;
	padding: 16px 20px;
}

.stbhh-cart-placeholder > *,
.stbhh-cart-placeholder i {
	display: block;
	border-radius: 8px;
	background: var(--stbhh-sk);
	animation: stbhh-cart-shimmer var(--stbhh-set-sk-speed, 1s) linear infinite;
}

.stbhh-cart-placeholder .stbhh-ph-thumb {
	width: 48px;
	height: 48px;
	border-radius: 10px;
}

.stbhh-cart-placeholder .stbhh-ph-lines {
	display: grid;
	gap: 8px;
	background: none;
	animation: none;
}

.stbhh-cart-placeholder .stbhh-ph-lines i:first-child {
	width: 80%;
	height: 12px;
}

.stbhh-cart-placeholder .stbhh-ph-lines i:last-child {
	width: 50%;
	height: 10px;
}

.stbhh-cart-placeholder .stbhh-ph-price {
	width: 54px;
	height: 14px;
}

/* Under the "Your basket" title (inside the mini cart's content): the same size and spacing as a real product row. */
.stbhh-cart-placeholder--inline {
	grid-template-columns: 84px minmax(0, 1fr) auto;
	gap: 14px;
	padding: 0;
}

.stbhh-cart-placeholder--inline .stbhh-ph-thumb {
	width: 84px;
	height: 84px;
	border-radius: 14px;
}

.stbhh-cart-has-placeholder :is(.elementor-menu-cart__empty-message, .woocommerce-mini-cart__empty-message) {
	display: none;
}

/* Once the real rows have arrived (before the second refresh ends), the placeholder goes. */
.stbhh-cart-loading:has(.elementor-menu-cart__product, .woocommerce-mini-cart-item) .stbhh-cart-placeholder {
	display: none;
}

@keyframes stbhh-cart-shimmer {
	from {
		background-position: 100% 0;
	}

	to {
		background-position: -100% 0;
	}
}

/* The toggle button: its amount and counter fade while the basket updates. */
.stbhh-cart-toggle-loading .elementor-button-text,
.stbhh-cart-toggle-loading .elementor-button-icon-qty {
	opacity: .55;
	transition: opacity .2s ease;
}

/* Heard by screen readers, never seen. */
.stbhh-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
	/* A slower shimmer, like the checkout's, and no fade animation. */
	.stbhh-cart-loading :is(
		.elementor-menu-cart__product-name a,
		.elementor-menu-cart__product-name .variation,
		.elementor-menu-cart__product-price .product-quantity,
		.elementor-menu-cart__product-price .woocommerce-Price-amount,
		.elementor-menu-cart__subtotal .woocommerce-Price-amount,
		.woocommerce-mini-cart-item .woocommerce-Price-amount,
		.woocommerce-mini-cart__total .woocommerce-Price-amount
	),
	.stbhh-cart-loading :has(> img),
	.stbhh-cart-placeholder > *,
	.stbhh-cart-placeholder i {
		animation-duration: 2.4s;
	}

	.stbhh-cart-toggle-loading .elementor-button-text,
	.stbhh-cart-toggle-loading .elementor-button-icon-qty {
		transition: none;
	}
}
