/**
 * ZAI COFFEE — Coffee cup loader
 * -----------------------------------------------------------------------------
 * The single loading indicator for every theme-controlled front-end state:
 * card and single-product add-to-cart, variation lookup, cart updates, mini-cart
 * removal and fragment refresh, checkout processing, live search and the
 * contact form submit.
 *
 * Pure HTML + SVG + CSS. No image, no GIF, no external animation library, no
 * build step. One component, one animation — every state only changes
 * `--ldr-size`.
 *
 * LOAD ORDER
 * ----------
 * Enqueued last in the base stylesheet chain (inc/assets.php), so it can retire
 * the loaders this theme shipped earlier (16-interactive.css card spinner).
 * Page-scoped sheets that also style a loader (19-contact-form.css) are enqueued
 * after it and own their own visibility rules.
 *
 * SVG SAFETY
 * ----------
 * 02-reset.css deliberately sets `svg { fill: none }` and explains why a blanket
 * `svg { fill: currentColor }` must never be reintroduced. The steam SVG repeats
 * `fill: none` and strokes itself through the brand custom property, so it can
 * never inherit an icon fill and adds no weight to that global rule.
 *
 * @package zaicoffeetheme
 * @since   1.9.2
 */

/* ==========================================================================
   1. Component
   --------------------------------------------------------------------------
   Geometry is a direct ratio of the supplied reference. Every dimension is
   derived from --s, so the cup, handle, saucer and steam keep their relative
   proportions at any size.
   ========================================================================== */

.ldr-coffee-cup {
	/* Mandatory default size. Every child below derives from it. */
	--ldr-size: 48px;

	/*
	 * ZAI Green. `--zai-green` resolves to #447350 (01-tokens.css); the literal
	 * fallback is the same brand colour, never the reference loader's original
	 * blue, so the cup cannot regress to a foreign palette.
	 */
	--ldr-color: var(--zai-green, #447350);

	--s: var(--ldr-size);
	--c: var(--ldr-color);

	position: relative;
	display: block;
	flex: 0 0 auto;
	box-sizing: border-box;
	width: var(--s);
	height: var(--s);
}

/* Cup body. */
.ldr-coffee-cup::before {
	content: "";
	position: absolute;
	inset-inline-start: 14%;
	inset-block-end: 16%;
	width: 56%;
	height: 40%;
	border-radius: 6% 6% 45% 45% / 8% 8% 60% 60%;
	background-color: var(--c);
}

/* Handle: a ring clipped by the cup body, exactly as in the reference. */
.ldr-coffee-cup::after {
	content: "";
	position: absolute;
	inset-inline-start: 60%;
	inset-block-end: 28%;
	width: 26%;
	height: 24%;
	box-sizing: border-box;
	border: calc(var(--s) / 14) solid var(--c);
	border-radius: 50%;
}

.ldr-coffee-cup-saucer {
	position: absolute;
	inset-inline-start: 6%;
	inset-block-end: 9%;
	width: 72%;
	height: calc(var(--s) / 14);
	border-radius: var(--s);
	background-color: var(--c);
}

/* --- Steam ---------------------------------------------------------------- */

.ldr-coffee-cup-steam {
	position: absolute;
	inset-inline-start: 14%;
	inset-block-start: 0;
	width: 56%;
	height: 44%;
	fill: none;
	stroke: var(--c);
	stroke-width: 2.6;
	stroke-linecap: round;
	overflow: visible;
	pointer-events: none;
}

.ldr-coffee-cup-steam path {
	fill: none;
	stroke: inherit;
	stroke-dasharray: 7 10;
	stroke-dashoffset: 7;
	animation: ldr-coffee-cup-rise 2.2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* The three wisps curl in turn, not in unison. */
.ldr-coffee-cup-steam path:nth-child(2) {
	animation-delay: -0.4s;
}

.ldr-coffee-cup-steam path:nth-child(3) {
	animation-delay: -0.15s;
}

@keyframes ldr-coffee-cup-rise {

	0% {
		stroke-dashoffset: 7;
		opacity: 0;
	}

	25% {
		opacity: 1;
	}

	60% {
		opacity: 0.9;
	}

	100% {
		stroke-dashoffset: -10;
		opacity: 0;
	}
}

/* ==========================================================================
   2. Reduced motion
   --------------------------------------------------------------------------
   The steam stops completely and the loader settles into a calm, static cup
   with the wisps drawn at a low opacity. This is a different resting state, not
   the same movement played slower, so nothing keeps moving on request.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

	.ldr-coffee-cup,
	.ldr-coffee-cup *,
	.ldr-coffee-cup::before,
	.ldr-coffee-cup::after {
		animation: none !important;
		transition: none !important;
	}

	.ldr-coffee-cup .ldr-coffee-cup-steam path {
		stroke-dashoffset: 0;
		opacity: 0.55;
	}
}

/* ==========================================================================
   3. Inline use inside a button or link
   --------------------------------------------------------------------------
   The cup is inserted as the first child of the control, so it sits beside the
   label and never changes the control's own height: the theme's controls are at
   least 48px tall and the inline cup is 24–26px. The control keeps its padding,
   its width and its text, so nothing jumps when the request starts or ends.
   ========================================================================== */

.zai-btn-loader {
	/*
	 * `inline-block` rather than the component's `block`. `.zai-btn` is already an
	 * inline-flex row with a `gap`, so the cup needs no margin there; this rule
	 * exists for controls that are NOT flex (WooCommerce's own links and inputs),
	 * where a block child would force a line break and change the height.
	 */
	display: inline-block;
	vertical-align: middle;
	pointer-events: none;
}

/*
 * Spacing is taken from the control rather than added to it: `.zai-btn` already
 * spaces its children with `gap`, and the card action and single-product button
 * get an explicit gap here so the cup and label never touch.
 *
 * NOTE — no `:last-child` reset. The label inside these controls is a bare text
 * node, not an element, so the cup IS the last element child and a
 * `:last-child { margin-inline-end: 0 }` rule would collapse this gap and push
 * the cup against the text.
 */
.zai-product-card__action .zai-btn-loader,
.single_add_to_cart_button .zai-btn-loader {
	margin-inline-end: var(--zai-space-2);
}

/*
 * BRAND-FILLED CONTROLS.
 *
 * The default cup colour is ZAI Green, which is correct on a light surface but
 * invisible on a green fill. The add-to-cart buttons and the contact form submit
 * are filled with --zai-green and labelled in --zai-text-inverse, so inside them
 * the cup follows the label colour instead. This is a scoped override of the
 * single --ldr-color variable — not a second component and not a second
 * animation.
 */
.zai-product-card__action--add .ldr-coffee-cup,
.single_add_to_cart_button .ldr-coffee-cup,
.zai-cform__submit .ldr-coffee-cup,
.zai-btn--primary .ldr-coffee-cup {
	--ldr-color: currentColor;
}

/* ==========================================================================
   4. Retiring the previous loaders
   --------------------------------------------------------------------------
   WooCommerce draws its own spinner with `::after` on `.button.loading` and
   reserves `padding-right: 2.618em` for it. The theme's own card spinner is
   gone from 16-interactive.css. Both are switched off here.

   No `!important`: the selectors below are scoped tightly enough to outrank
   core's `.woocommerce … a.button.loading::after` (0,3,2).
   ========================================================================== */

.zai-has-woocommerce .woocommerce a.zai-product-card__action.loading::after,
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.loading::after,
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.is-loading::after,
.zai-has-woocommerce .woocommerce input.single_add_to_cart_button.loading::after {
	content: none;
}

/*
 * SPECIFICITY — measured, not assumed.
 *
 * WooCommerce ships:
 *   .woocommerce:where(body:not(.woocommerce-block-theme-has-button-styles))
 *     button.button.loading::after
 * The `:where()` adds nothing, so that selector scores (0,3,2). An earlier
 * attempt used `.woocommerce .single_add_to_cart_button.loading::after`
 * (0,3,1) and LOST — the grey spinner kept rendering beside the coffee cup in a
 * real browser. `button.single_add_to_cart_button.loading` scores (0,3,2), and
 * with `.zai-has-woocommerce .woocommerce` in front it scores (0,4,2), which
 * wins outright regardless of source order.
 *
 * Scope is still exactly the theme's own add-to-cart control: these classes are
 * only ever on that button.
 */
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.loading::after,
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.is-loading::after,
.zai-has-woocommerce .woocommerce input.single_add_to_cart_button.loading::after,
.woocommerce button.single_add_to_cart_button.loading::after,
.woocommerce button.single_add_to_cart_button.is-loading::after,
button.single_add_to_cart_button.loading::after,
button.single_add_to_cart_button.is-loading::after {
	content: none;
	animation: none;
	background: none;
}

/*
 * Core also dims a loading button to 25% opacity and reserves extra right padding
 * for its spinner. The coffee cup is the indicator now, so the control stays fully
 * legible and keeps the padding the theme gives it.
 */
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.loading,
.zai-has-woocommerce .woocommerce button.single_add_to_cart_button.is-loading {
	opacity: 1;
}

/* ==========================================================================
   5. Region overlay
   --------------------------------------------------------------------------
   Used for a local content region that refreshes itself in place — currently
   the mini-cart drawer body during a fragment refresh. The overlay is visual
   only (`pointer-events: none`), so it can never intercept a click the region
   would otherwise receive and no behaviour changes.
   ========================================================================== */

[data-zai-loading-region="1"] {
	position: relative;
}

.zai-loader-region {
	position: absolute;
	inset: 0;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

/* The veil is its own layer so the cup itself stays fully opaque. */
.zai-loader-region::before {
	content: "";
	position: absolute;
	inset: 0;
	background-color: var(--zai-bg, #fff);
	opacity: 0.82;
}

.zai-loader-region .ldr-coffee-cup {
	position: relative;
	z-index: 1;
}

/* ==========================================================================
   6. WooCommerce BlockUI overlays
   --------------------------------------------------------------------------
   WooCommerce blocks a REGION per target, not per operation: a single cart
   update blocks `form.woocommerce-cart-form` AND `.cart_totals`, producing two
   overlays. The cup therefore does NOT live inside an overlay — it lives in one
   shared container (see syncOperation() in loader.js), so one operation shows
   exactly one cup across the cart content.

   ROOT CAUSE OF THE GREY CIRCLES
   WooCommerce ships, in its own stylesheet:

     .woocommerce .blockUI.blockOverlay::before {
       content: ""; height: 1em; width: 1em; position: absolute;
       top: 50%; left: 50%; margin: -.5em 0 0 -.5em;
       animation: spin 1s ease-in-out infinite;
       background: url("../images/icons/loader.svg") center center;
     }

   That is the grey spinner seen next to the cup. WooCommerce loads its
   stylesheet AFTER the theme, and its selector has the same (0,3,1) specificity
   as `.blockUI.blockOverlay[data-zai-loader="overlay"]::before`, so a plain
   override would lose. The suppression below is scoped to the overlay attribute
   this component sets itself, which is why it cannot affect any other loader or
   icon on the site.
   ========================================================================== */

/* The blocked region needs to be a positioning context for nothing more than the
   shared cup; blockUI already sets position:relative, this only guarantees it. */
[data-zai-op-loading="1"] {
	position: relative;
}

/* --- Suppress WooCommerce's own spinner inside a marked overlay ------------ */

.woocommerce .blockUI.blockOverlay[data-zai-loader="overlay"]::before,
.blockUI.blockOverlay[data-zai-loader="overlay"]::before {
	content: none;
	background: none;
	animation: none;
}

/* The overlay keeps blockUI's veil untouched; no re-layering is needed now that
   the cup is not a child of it. */
.woocommerce .blockUI.blockOverlay[data-zai-loader="overlay"] {
	background-color: rgb(255 255 255 / 62%);
}

/* --- The single shared operation cup ------------------------------------- */

[data-zai-loader="operation"] {
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	z-index: 10;
	transform: translate(-50%, -50%);
	pointer-events: none;
}
