/*
 * KNEAD. — product image shimmer skeleton.
 *
 * Reproduces the loading treatment from the legacy ProductCard: a dark panel
 * over the image well with a single soft highlight sweeping across it, 1.6s,
 * eased, on a loop. Legacy used #141414 with a 4% white highlight; the same
 * value in the brand palette is surface #111111 with a #1E1E1E highlight, so
 * that is what is used here.
 *
 * Two rules matter more than the look:
 *
 *   1. The skeleton is an OVERLAY, never a replacement. Nothing in this file
 *      hides, fades or shrinks the product image. If the JavaScript never runs
 *      — blocked, errored, old browser — no element is ever inserted and the
 *      image is simply visible, unchanged. There is no state in which a
 *      failure leaves a blank card.
 *   2. It is driven by the real load event, not a timer. See knead-skeleton.js.
 *
 * Every class in here is added by knead-skeleton.js at runtime; none of it
 * appears in the rendered markup or in the editor.
 */

/*
 * The positioning context for the overlay. Both frames WooCommerce gives us are
 * already position:relative in its own stylesheets
 * (`.wc-block-components-product-image` in product-image.css,
 * `.wc-block-grid__product-image` in wc-blocks.css), so in practice this is a
 * no-op; it is here so the panel cannot escape its frame if a future markup
 * change drops that.
 *
 * Nothing here changes the frame's `display`. An earlier version forced
 * `a.knead-skeleton-frame { display: block }` — the All Products frame is an
 * anchor — which mutated its layout for the duration of the load and reflowed
 * the card when the class came off again. knead-skeleton.js now declines any
 * frame whose computed display is plain `inline` instead, so the panel never
 * changes the page's layout.
 */
.knead-skeleton-frame {
	position: relative;
}

/*
 * The panel. Sits over the image, takes no pointer events (the whole card is a
 * link and must stay clickable while it loads), and inherits any corner radius
 * so it never sticks out past the image it is covering.
 */
.knead-skeleton {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow: hidden;
	pointer-events: none;
	border-radius: inherit;
	background-color: #111111;
	opacity: 0;
	transition: opacity 260ms ease;
}

/*
 * Added a beat after insertion, and removed the moment the image lands. An
 * image that arrives straight from cache is settled before this class is ever
 * applied, so a warm reload shows no skeleton at all rather than a flicker.
 */
.knead-skeleton.is-shown {
	opacity: 1;
}

/* The sweep. Geometry and timing are the legacy values: -100% → 200%, 1.6s ease. */
.knead-skeleton::after {
	content: "";
	position: absolute;
	inset: 0;
	/*
	 * rgba(30, 30, 30, 0) rather than `transparent` on purpose: it keeps the
	 * fade in the same hue as the highlight instead of dipping toward black.
	 */
	background-image: linear-gradient(
		90deg,
		rgba(30, 30, 30, 0) 0%,
		#1E1E1E 50%,
		rgba(30, 30, 30, 0) 100%
	);
	animation: knead-skeleton-sweep 1.6s ease infinite;
}

/*
 * Whatever WooCommerce paints on top of the image well stays on top of the
 * panel while the image loads, exactly as it did on the legacy card.
 *
 * Only the inner container needs help, and it needs it for a stated reason:
 * it holds any inner blocks added to the Product Image block, WooCommerce's
 * product-image.css makes it `position: absolute` with all four offsets at 0,
 * and gives it no z-index — so on tree order alone the panel, which is
 * inserted after the anchor, would paint over it.
 *
 * The sale badge deliberately gets NO rule here. Measured rather than assumed,
 * in a browser on /shop/ with WooCommerce's own badge markup injected into the
 * anchor: product-image.css gives `.wc-block-components-product-sale-badge`
 * z-index 9 in its base rule and the `--align-*` variants add
 * `position: absolute`, so getComputedStyle reports the badge at z-index 9
 * against this panel's 1 with no help from us. An earlier version of this file
 * listed the badge alongside the inner container, which did not lift it — it
 * LOWERED WooCommerce's 9 to 2. Still above the panel, so nothing was visibly
 * wrong, but it was an override of a value that never needed overriding,
 * justified by a comment claiming the badge had "no z-index at all", which the
 * stylesheet flatly contradicts. The other two badge shapes were checked in the
 * same stylesheets and need nothing either: `.wc-block-grid__product-onsale`
 * inside a grid image is absolute at z-index 9 (wc-blocks.css), and the classic
 * loop's span.onsale is absolute at z-index 9 (woocommerce.css) — and classic
 * loops now get no panel at all, see knead-skeleton.js.
 */
.knead-skeleton-frame .wc-block-components-product-image__inner-container {
	z-index: 2;
}

@keyframes knead-skeleton-sweep {
	0%   { transform: translateX(-100%); }
	100% { transform: translateX(200%); }
}

/*
 * No sweep for visitors who asked for less motion, and none when an editor has
 * turned motion off in KNEAD. → Site settings (knead-skeleton.js adds
 * .knead-skeleton--still for that case). The panel itself stays: the loading
 * state is the panel, not the animation, so nothing is lost — it just holds
 * still, as a flat #111 panel.
 *
 * `display: none` on the sweep rather than `animation: none`, for two reasons,
 * both checked rather than reasoned about:
 *
 *   • style.css's global reduced-motion block sets
 *     `animation-duration: .001ms !important` and
 *     `animation-iteration-count: 1 !important` on *, *::before, *::after.
 *     That !important beats a plain `animation: none` declared here, so the
 *     sweep still runs — once, instantly — and with no fill mode it then snaps
 *     back to translateX(0).
 *   • translateX(0) parks the highlight in the middle of the panel, so the
 *     "still" state was not a flat panel at all: it was a permanent pale
 *     vertical band down the centre of every loading image well. Confirmed in
 *     the browser — getComputedStyle(panel, '::after') reported
 *     animation-name "none" with transform "none", and the band was visible in
 *     a screenshot.
 *
 * The opacity transition goes with it, so a still panel appears and clears
 * instantly instead of cross-fading.
 */
@media (prefers-reduced-motion: reduce) {
	.knead-skeleton {
		transition: none;
	}

	.knead-skeleton::after {
		display: none;
	}
}

.knead-skeleton--still {
	transition: none;
}

.knead-skeleton--still::after {
	display: none;
}

@media print {
	.knead-skeleton {
		display: none;
	}
}
