/**
 * BD Stock Bar — .espt-block-bd-stock-bar
 *
 * Vars set by the spec: --bar-height --track-radius --fill-radius --track-color
 * --fill-color --fill-color2 --fill-angle --knob-color --pct-color --grow-dur
 * --fx-dur --text-size --num-size --text-gap --left-color --num-color
 * --right-color --note-color. The fill percentage (--fill) is inline on .bds10
 * because it can be computed from live WooCommerce stock.
 *
 * Mobile-first: everything here is the ≤767px design; 768px and 1024px only
 * add breathing room.
 */

.espt-block-bd-stock-bar .bds10 {
	color: var(--bd-ink);
	min-width: 0;
}

/* ---------------------------------------------------------- the text row */

.espt-block-bd-stock-bar .bds10-row {
	display: flex;
	flex-wrap: wrap;
	font-size: var(--text-size, 14px);
	font-weight: 600;
	gap: 2px 12px;
	justify-content: flex-start;
	line-height: 1.4;
	margin: 0 0 var(--text-gap, 8px);
	min-width: 0;
}

.espt-block-bd-stock-bar.is-row-split .bds10-row { justify-content: space-between; }
.espt-block-bd-stock-bar.is-row-pos-below .bds10-row { margin: var(--text-gap, 8px) 0 0; }

.espt-block-bd-stock-bar .bds10-left {
	align-items: center;
	color: var(--left-color, var(--bd-ink));
	display: inline-flex;
	gap: 6px;
	min-width: 0;
	overflow-wrap: anywhere;
}

.espt-block-bd-stock-bar .bds10-left > span { min-width: 0; }

.espt-block-bd-stock-bar .bds10-ico {
	color: var(--num-color, var(--bd-danger));
	font-size: 1.15em;
}

.espt-block-bd-stock-bar .bds10-num {
	color: var(--num-color, var(--bd-danger));
	font-size: var(--num-size, 17px);
	font-weight: 800;
	line-height: 1;
}

.espt-block-bd-stock-bar .bds10-right {
	color: var(--right-color, var(--bd-muted));
	font-weight: 400;
	min-width: 0;
	overflow-wrap: anywhere;
}

/* -------------------------------------------------------------- the bar */

.espt-block-bd-stock-bar .bds10-barwrap {
	align-items: center;
	display: flex;
	gap: 10px;
	min-width: 0;
}

.espt-block-bd-stock-bar .bds10-bar {
	background: var(--track-color, var(--bd-line));
	border-radius: var(--track-radius, 99px);
	flex: 1 1 auto;
	height: var(--bar-height, 10px);
	min-width: 0;
	position: relative;
}

.espt-block-bd-stock-bar .bds10-fill {
	background: var(--fill-color, var(--bd-danger));
	border-radius: var(--fill-radius, 99px);
	display: block;
	height: 100%;
	max-width: 100%;
	overflow: hidden;
	position: relative;
	width: var(--fill, 18%);
}

.espt-block-bd-stock-bar.is-fill-type-gradient .bds10-fill {
	background: linear-gradient(var(--fill-angle, 90deg), var(--fill-color, var(--bd-danger)), var(--fill-color2, var(--bd-accent)));
}

/* --------------------------------------------------- percentage label */

.espt-block-bd-stock-bar .bds10-pct-inside {
	color: var(--pct-color, #fff);
	font-size: clamp(9px, calc(var(--bar-height, 10px) * 0.66), 15px);
	font-weight: 800;
	line-height: 1;
	padding-right: 6px;
	position: relative;
	white-space: nowrap;
	z-index: 1;
}

.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-inside .bds10-fill {
	align-items: center;
	display: flex;
	justify-content: flex-end;
}

.espt-block-bd-stock-bar .bds10-pct-right {
	color: var(--pct-color, var(--num-color, var(--bd-ink)));
	flex: 0 1 auto;
	font-size: var(--text-size, 14px);
	font-weight: 800;
	line-height: 1.2;
	max-width: 45%;
	min-width: 0;
	overflow-wrap: anywhere;
}

.espt-block-bd-stock-bar .bds10-pct-tip {
	background: var(--fill-color, var(--bd-danger));
	border-radius: 6px;
	bottom: calc(100% + 8px);
	color: var(--pct-color, #fff);
	font-size: 11px;
	font-weight: 800;
	left: var(--fill, 18%);
	line-height: 1;
	max-width: 100%;
	padding: 4px 6px;
	position: absolute;
	transform: translateX(-50%);
	white-space: nowrap;
	z-index: 4;
}

.espt-block-bd-stock-bar .bds10-pct-tip::after {
	border: 4px solid transparent;
	border-top-color: var(--fill-color, var(--bd-danger));
	content: "";
	left: 50%;
	position: absolute;
	top: 100%;
	transform: translateX(-50%);
}

.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-tip .bds10-barwrap { margin-top: 26px; }

/* ------------------------------------------------------------- the knob */

.espt-block-bd-stock-bar.is-fill-knob .bds10-bar::after {
	background: var(--knob-color, #fff);
	border-radius: 50%;
	box-shadow: 0 0 0 2px var(--fill-color, var(--bd-danger)), 0 1px 4px rgba(0, 0, 0, 0.3);
	content: "";
	height: calc(var(--bar-height, 10px) + 6px);
	left: var(--fill, 18%);
	position: absolute;
	top: 50%;
	transform: translate(-50%, -50%);
	width: calc(var(--bar-height, 10px) + 6px);
	z-index: 3;
}

/* ---------------------------------------------------------- the note line */

.espt-block-bd-stock-bar .bds10-note {
	align-items: flex-start;
	color: var(--note-color, var(--bd-muted));
	display: flex;
	font-size: calc(var(--text-size, 14px) * 0.92);
	gap: 6px;
	line-height: 1.45;
	margin-top: var(--text-gap, 8px);
	min-width: 0;
	overflow-wrap: anywhere;
}

.espt-block-bd-stock-bar .bds10-note > span { min-width: 0; }

.espt-block-bd-stock-bar .bds10-nico {
	color: var(--num-color, var(--bd-danger));
	margin-top: 0.15em;
}

/* -------------------------------------------------------- track designs */

.espt-block-bd-stock-bar.is-design-flat .bds10-bar,
.espt-block-bd-stock-bar.is-design-flat .bds10-fill { border-radius: min(var(--track-radius, 99px), 4px); }

.espt-block-bd-stock-bar.is-design-inset .bds10-bar { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.22); }
.espt-block-bd-stock-bar.is-design-inset .bds10-fill { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35); }

.espt-block-bd-stock-bar.is-design-segmented .bds10-bar,
.espt-block-bd-stock-bar.is-design-segmented .bds10-fill { border-radius: min(var(--track-radius, 99px), 4px); }

.espt-block-bd-stock-bar.is-design-segmented .bds10-bar::before {
	background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 4px), var(--bd-box-bg, #fff) calc(10% - 4px) 10%);
	border-radius: inherit;
	content: "";
	inset: 0;
	pointer-events: none;
	position: absolute;
	z-index: 2;
}

.espt-block-bd-stock-bar.is-design-dashed .bds10-bar {
	background: transparent;
	border: 1px dashed var(--track-color, var(--bd-muted));
	height: calc(var(--bar-height, 10px) + 8px);
	padding: 2px;
}

.espt-block-bd-stock-bar.is-design-neon .bds10-bar {
	background: var(--track-color, #0b1020);
	border: 1px solid color-mix(in srgb, var(--fill-color, var(--bd-danger)) 45%, transparent);
}

.espt-block-bd-stock-bar.is-design-neon .bds10-fill {
	box-shadow: 0 0 10px color-mix(in srgb, var(--fill-color, var(--bd-danger)) 75%, transparent), 0 0 24px color-mix(in srgb, var(--fill-color, var(--bd-danger)) 40%, transparent);
}

.espt-block-bd-stock-bar.is-design-panel .bds10-barwrap {
	background: var(--bd-soft);
	border: 1px solid var(--bd-soft-line);
	border-radius: 999px;
	padding: 8px 12px;
}

.espt-block-bd-stock-bar.is-design-glass .bds10-bar {
	backdrop-filter: blur(6px);
	background: var(--track-color, color-mix(in srgb, var(--bd-ink) 10%, transparent));
	border: 1px solid rgba(255, 255, 255, 0.4);
	box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.35);
}

/* The knob and the tip label hang over the ends of the track — reserve room
   so nothing can push past a 320px viewport. The knob reaches half its own
   width (bar-height / 2 + 3px) plus its 2px ring and 2px shadow blur. */
.espt-block-bd-stock-bar.is-fill-knob .bds10-barwrap { padding-inline: calc(var(--bar-height, 10px) / 2 + 7px); }
.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-tip .bds10-barwrap { padding-inline: 18px; }
.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-tip.is-fill-knob .bds10-barwrap { padding-inline: max(18px, calc(var(--bar-height, 10px) / 2 + 7px)); }

/* The soft panel draws its own border around the bar — give the tip label room
   inside it instead of letting it sit on top of that border. */
.espt-block-bd-stock-bar.is-design-panel.is-show-pct.is-pct-pos-tip .bds10-barwrap {
	border-radius: 16px;
	margin-top: 0;
	padding-top: 26px;
}

/* ------------------------------------------- grow-on-scroll (JS: .is-go) */

/* Only collapse the bar once the block's JS has taken over (the shared
   runtime stamps data-espt-ready), so a no-JS visitor still sees the fill. */
.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-fill { width: 0; }
.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-pct-tip,
.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-bar::after { left: 0; }

/* The transition belongs to the .is-go state only. The script boots after the
   first paint, so a transition that also covered the collapse would play a
   visible "full → empty → full" bounce; scoped here, only the run-up animates. */
.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-fill { transition: width var(--grow-dur, 1.2s) cubic-bezier(0.2, 0.7, 0.2, 1); }
.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-pct-tip,
.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-bar::after { transition: left var(--grow-dur, 1.2s) cubic-bezier(0.2, 0.7, 0.2, 1); }

/* ----------------------------------------------------- continuous effects */

.espt-block-bd-stock-bar.is-fill-effect-stripes .bds10-fill::after {
	animation: espt-bds10-stripes var(--fx-dur, 1s) linear infinite;
	background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.28) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.28) 50%, rgba(255, 255, 255, 0.28) 75%, transparent 75%, transparent);
	background-size: 1em 1em;
	content: "";
	inset: 0;
	position: absolute;
}

@keyframes espt-bds10-stripes {
	from { background-position: 0 0; }
	to { background-position: 1em 0; }
}

.espt-block-bd-stock-bar.is-fill-effect-shimmer .bds10-fill::before {
	animation: espt-bds10-shimmer var(--fx-dur, 1s) linear infinite;
	background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.6) 50%, transparent 80%);
	content: "";
	inset: 0;
	position: absolute;
}

@keyframes espt-bds10-shimmer {
	from { transform: translateX(-100%); }
	to { transform: translateX(100%); }
}

.espt-block-bd-stock-bar.is-fill-effect-pulse .bds10-fill { animation: espt-bds10-pulse var(--fx-dur, 1s) ease-in-out infinite; }

@keyframes espt-bds10-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.6; }
}

.espt-block-bd-stock-bar.is-fill-effect-glow .bds10-fill {
	animation: espt-bds10-glow var(--fx-dur, 1s) ease-in-out infinite;
	box-shadow: 0 0 8px var(--fill-color, var(--bd-danger));
}

@keyframes espt-bds10-glow {
	0%, 100% { filter: brightness(1); }
	50% { filter: brightness(1.3); }
}

/* --------------------------------------------------------- urgent state */

.espt-block-bd-stock-bar .bds10.is-urgent .bds10-fill { background: var(--bd-danger); }
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-num,
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-ico,
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-nico { color: var(--bd-danger); }
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-bar { animation: espt-bds10-urgent 1.6s ease-in-out infinite; }

/* The tip bubble and the knob ring both echo the fill colour — follow it into
   the urgent state too, or a custom fill colour leaves them mismatched. */
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-pct-tip { background: var(--bd-danger); }
.espt-block-bd-stock-bar .bds10.is-urgent .bds10-pct-tip::after { border-top-color: var(--bd-danger); }
.espt-block-bd-stock-bar.is-fill-knob .bds10.is-urgent .bds10-bar::after { box-shadow: 0 0 0 2px var(--bd-danger), 0 1px 4px rgba(0, 0, 0, 0.3); }
.espt-block-bd-stock-bar.is-design-neon .bds10.is-urgent .bds10-fill { box-shadow: 0 0 10px color-mix(in srgb, var(--bd-danger) 75%, transparent), 0 0 24px color-mix(in srgb, var(--bd-danger) 40%, transparent); }

@keyframes espt-bds10-urgent {
	0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bd-danger) 40%, transparent); }
	50% { box-shadow: 0 0 0 6px transparent; }
}

/* ------------------------------------------------------------ alignment */

/* "Push the right text to the far end" with no left text at all: space-between
   has nothing to space, so pin the lone span to the end itself. */
.espt-block-bd-stock-bar.is-row-split.is-text-align-left .bds10-row > .bds10-right:only-child { margin-inline-start: auto; }

.espt-block-bd-stock-bar.is-text-align-center .bds10-row { justify-content: center; text-align: center; }
.espt-block-bd-stock-bar.is-text-align-right .bds10-row { justify-content: flex-end; text-align: right; }
.espt-block-bd-stock-bar.is-text-align-center .bds10-note { justify-content: center; text-align: center; }
.espt-block-bd-stock-bar.is-text-align-right .bds10-note { justify-content: flex-end; text-align: right; }

/* Phones: optionally put the two texts on their own lines. */
.espt-block-bd-stock-bar.is-stack-mobile .bds10-row { flex-direction: column; }
.espt-block-bd-stock-bar.is-stack-mobile.is-text-align-center .bds10-row { align-items: center; }
.espt-block-bd-stock-bar.is-stack-mobile.is-text-align-right .bds10-row { align-items: flex-end; }

@media (min-width: 768px) {
	.espt-block-bd-stock-bar.is-stack-mobile .bds10-row { align-items: center; flex-direction: row; }
	.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-tip .bds10-barwrap { padding-inline: 22px; }
	.espt-block-bd-stock-bar.is-show-pct.is-pct-pos-tip.is-fill-knob .bds10-barwrap { padding-inline: max(22px, calc(var(--bar-height, 10px) / 2 + 7px)); }
	.espt-block-bd-stock-bar .bds10-pct-tip { font-size: 12px; }
}

@media (min-width: 1024px) {
	.espt-block-bd-stock-bar .bds10-barwrap { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
	/* These repeat the full selector of every animated rule above so they win
	   on specificity, not just on order (.is-urgent and .is-go are heavier). */
	.espt-block-bd-stock-bar .bds10-fill,
	.espt-block-bd-stock-bar .bds10-fill::before,
	.espt-block-bd-stock-bar .bds10-fill::after,
	.espt-block-bd-stock-bar .bds10-bar,
	.espt-block-bd-stock-bar .bds10-bar::after,
	.espt-block-bd-stock-bar .bds10-pct-tip,
	.espt-block-bd-stock-bar .bds10.is-urgent .bds10-bar,
	.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-fill,
	.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-pct-tip,
	.espt-block-bd-stock-bar.is-fill-grow .bds10.is-go .bds10-bar::after {
		animation: none;
		transition: none;
	}

	.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-fill { width: var(--fill, 18%); }
	.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-pct-tip,
	.espt-block-bd-stock-bar[data-espt-ready].is-fill-grow .bds10:not(.is-go) .bds10-bar::after { left: var(--fill, 18%); }
}
