/*
 * KNEAD. scarcity meter — "12 LEFT / 250 TOTAL"
 *
 * Two lines: the caption in the KNEAD. eyebrow treatment (11px / 700 / .3em /
 * uppercase) in cream, and a 2px track beneath it. Rebuilt from the legacy
 * StockBar component; the proportions are the design and are not up for
 * reinterpretation.
 *
 * Colours are declared once as custom properties on the root element so a
 * variant only has to swap a value, never restate a rule.
 *
 * Rendered by includes/class-scarcity.php. If no real stock figure exists the
 * PHP prints nothing, so there is no "empty" state to style here.
 */

.knead-scarcity {
	--knead-scarcity-track: #1e1e1e;
	--knead-scarcity-fill: #1b4fbf;
	--knead-scarcity-low: #8b1a2a;
	--knead-scarcity-caption: #f5f0e8;

	/*
	 * How full the bar is, 0-1. Set inline by PHP from the real stock figures;
	 * an empty bar until then, never a full one.
	 */
	--knead-scarcity-scale: 0;

	display: block;
	width: 100%;
}

/* ---------- caption ---------- */

.knead-scarcity__caption {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75em;
	margin: 0 0 0.6rem;
	padding: 0;
	font-size: 0.6875rem;
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: 0.3em;
	text-transform: uppercase;
	color: var(--knead-scarcity-caption);
}

/*
 * The trailing letter-space of the last character pushes the right-hand number
 * visually inwards; pulling it back keeps both ends flush with the track.
 */
/*
 * Both halves of the caption are the same cream at the same weight, as in the
 * legacy component. Burgundy is reserved for the bar: the caption must not
 * change colour when stock runs low, or the alarm reads as two separate signals.
 */
.knead-scarcity__total {
	margin-right: -0.3em;
	text-align: right;
}

/* ---------- track and fill ---------- */

.knead-scarcity__track {
	position: relative;
	overflow: hidden;
	width: 100%;
	height: 2px;
	border-radius: 999px;
	background: var(--knead-scarcity-track);
}

.knead-scarcity__fill {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: inherit;
	background: linear-gradient(
		90deg,
		color-mix(in srgb, var(--knead-scarcity-fill) 60%, transparent),
		var(--knead-scarcity-fill)
	);

	/*
	 * scaleX rather than an animated width: identical visually, but composited
	 * instead of re-laying out the row on every frame.
	 */
	transform: scaleX(var(--knead-scarcity-scale));
	transform-origin: left center;
	animation: knead-scarcity-grow 1.1s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@supports not (background: color-mix(in srgb, red, blue)) {
	.knead-scarcity__fill {
		background: var(--knead-scarcity-fill);
	}
}

@keyframes knead-scarcity-grow {
	from {
		transform: scaleX(0);
	}

	to {
		transform: scaleX(var(--knead-scarcity-scale));
	}
}

/* ---------- nearly gone ---------- */

.knead-scarcity.is-low {
	--knead-scarcity-fill: var(--knead-scarcity-low);
}

/*
 * Sold out: the fill is zero-width and therefore invisible, so the burgundy has
 * to come from the track itself or the row would read as an ordinary empty bar.
 */
.knead-scarcity.is-sold-out .knead-scarcity__track {
	background: rgba(139, 26, 42, 0.4);
}

/* ---------- placement variants ---------- */

/* Product page: sits under the price, above the size picker. */
.knead-scarcity--single {
	margin-block: 1.5rem 2.25rem;
	max-width: 26rem;
}

/* Shop card: tighter, and narrower tracking so it never wraps in a grid cell. */
.knead-scarcity--card {
	margin-block: 0.625rem 0;
}

.knead-scarcity--card .knead-scarcity__caption {
	margin-bottom: 0.45rem;
	font-size: 0.625rem;
	letter-spacing: 0.22em;
}

/* ---------- reduced motion ---------- */

/*
 * A bar sweeping out from zero is the whole point of the animation, and equally
 * the whole reason it has to be skippable. The end state is identical either
 * way, so nothing is lost.
 */
@media (prefers-reduced-motion: reduce) {
	.knead-scarcity__fill {
		animation: none;
	}
}

/* ---------- narrow screens ---------- */

@media (max-width: 480px) {
	.knead-scarcity--single {
		margin-block: 1.25rem 1.75rem;
	}

	.knead-scarcity__caption {
		letter-spacing: 0.22em;
	}
}
