/* Typography, text colour and corners join the -set channel that the
   colours use, so a design panel drives the whole component and not just its
   accent. The default expressions stay as the fallback when there is no
   panel.

   =========================================================================
   WPS Progress Bar — component styles (shared by the block and classic themes).

   Token-based (WPS convention): a couple of base tokens that fall back to the
   theme's --color-* tokens and then to a tasteful default; every other shade is
   derived with color-mix(). Settings write --wps-pb-*-set (highest priority).
   ========================================================================= */
.wps-pb {
	/* The portfolio chain: the WPS Design bridge (`-set`), then the bar's own
	   value (`-own`, a seam for a theme), then the default. Manual mode
	   writes the `-set` slots itself on `body.wps-pb-manual`, above the
	   bridge (Blocks\Registrar). */
	--wps-pb-accent: var(--wps-pb-accent-set, var(--wps-pb-accent-own, var(--color-primary, #1d9e75)));
	--wps-pb-accent-contrast: var(--wps-pb-accent-contrast-set, var(--wps-pb-accent-contrast-own, var(--color-primary-contrast, #ffffff)));
	--wps-pb-track: var(--wps-pb-track-set, var(--wps-pb-track-own, color-mix(in srgb, var(--wps-pb-accent) 14%, transparent)));
	--wps-pb-text: var(--wps-pb-text-set, var(--color-text, inherit));
	--wps-pb-muted: var(--wps-pb-muted-set, var(--color-text-muted, color-mix(in srgb, currentColor 60%, transparent)));
	--wps-pb-radius: var(--wps-pb-radius-set, var(--radius-pill, 999px));
	--wps-pb-font: var(--wps-pb-font-set, var(--font-sans, inherit));
	--wps-pb-weight: var(--wps-pb-weight-set, 600);
	--wps-pb-weight-strong: var(--wps-pb-weight-strong-set, 700);

	display: grid;
	gap: var(--wps-pb-gap-set, var(--wps-pb-gap, 8px));
	width: 100%;
	margin-block: var(--wps-pb-margin-set, var(--wps-pb-margin, 12px));
	font-family: var(--wps-pb-font);
	color: var(--wps-pb-text);
}

/* Лента без видима стъпка се крие с `hidden` заедно с обвивката си; класовото `display` иначе бие UA правилото. */
.wps-pb[hidden],
:is(.wps-pb-fixed, .wps-pb-placed):has(.wps-pb[hidden]) {
	display: none;
}

/* Reward lines: each unlocked reward keeps its own line + icon; the current
   goal is the last line. */
.wps-pb__lines {
	display: flex;
	flex-direction: column;
	gap: var(--wps-pb-lines-gap-set, var(--wps-pb-lines-gap, 4px));
}

.wps-pb__line {
	display: flex;
	align-items: center;
	gap: 0.5em;
	font-size: 0.95em;
	line-height: 1.3;
}

.wps-pb__icon-wrap {
	display: inline-flex;
	flex: 0 0 auto;
	color: var(--wps-pb-accent);
	font-size: 1.15em;
}

.wps-pb__icon {
	display: block;
	width: 1em;
	height: 1em;
}

.wps-pb__line-text {
	flex: 1 1 auto;
	min-width: 0;
	font-weight: var(--wps-pb-weight);
}

.wps-pb__check {
	color: var(--wps-pb-accent);
	font-weight: var(--wps-pb-weight-strong);
	margin-inline-end: 0.33em;
}

.wps-pb__num {
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.wps-pb__pct {
	flex: 0 0 auto;
	margin-inline-start: auto;
	font-variant-numeric: tabular-nums;
	font-weight: var(--wps-pb-weight);
	color: var(--wps-pb-muted);
}

/* Already-unlocked lines read as "done". */
.wps-pb__line--done {
	/* No darkening of its own: a darker shade comes from the panel. */
	color: var(--wps-pb-accent);
}

.wps-pb__track {
	position: relative;
	width: 100%;
	height: var(--wps-pb-height-set, var(--wps-pb-height, 10px));
	background: var(--wps-pb-track);
	border-radius: var(--wps-pb-radius);
	overflow: hidden;
}

.wps-pb__fill {
	position: relative;
	overflow: hidden;
	height: 100%;
	width: 0;
	background: var(--wps-pb-accent);
	border-radius: inherit;
	transition: width 0.4s ease;
}

/* Compact layout (drawer / tight spaces). */
.wps-pb--compact {
	margin-block: var(--wps-pb-compact-margin-set, var(--wps-pb-compact-margin, 8px));
}

.wps-pb--compact .wps-pb__track {
	height: var(--wps-pb-compact-height-set, var(--wps-pb-compact-height, 6px));
}

.wps-pb--compact .wps-pb__line {
	font-size: 0.85em;
}

.wps-pb--compact .wps-pb__pct {
	display: none;
}

/* ------------------------------------------------------------------
   Looks of the full bar ("Look" setting). The class sits on <body> on the
   site and on the preview wrapper in the settings. The compact bar and a
   bar in the mini-cart drawer keep the plain line. Colours, weight, gap and
   track height keep the bar's own chains, so WPS Design and the colour
   settings drive every look.
   ------------------------------------------------------------------ */
:is(.wps-pb-look-card, .wps-pb-look-tint, .wps-pb-look-inside) .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	--wps-pb-surface-look: var(--wps-pb-surface-set, var(--wps-pb-surface, var(--wps-surface, var(--color-surface, #ffffff))));
	--wps-pb-look-size: var(--wps-pb-look-size-set, var(--wps-pb-look-size-own, 1rem));
	--wps-pb-look-radius: var(--wps-pb-look-radius-set, var(--wps-pb-look-radius-own, var(--radius-card, 12px)));
	--wps-pb-look-pad-block: var(--wps-pb-look-pad-block-set, var(--wps-pb-look-pad-block-own, 14px));
	--wps-pb-look-pad-inline: var(--wps-pb-look-pad-inline-set, var(--wps-pb-look-pad-inline-own, 18px));
	--wps-pb-look-height: var(--wps-pb-look-height-set, var(--wps-pb-height-set, var(--wps-pb-look-height-own, 12px)));
	--wps-pb-inside-height: var(--wps-pb-inside-height-set, var(--wps-pb-inside-height-own, 44px));
	--wps-pb-weight: var(--wps-pb-look-weight-set, var(--wps-pb-weight-set, 600));
}

:is(.wps-pb-look-card, .wps-pb-look-tint, .wps-pb-look-inside) .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line {
	font-size: var(--wps-pb-look-size);
}

:is(.wps-pb-look-card, .wps-pb-look-tint, .wps-pb-look-inside) .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__icon-wrap {
	font-size: 1.35em;
}

:is(.wps-pb-look-card, .wps-pb-look-tint) .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	box-sizing: border-box;
	gap: var(--wps-pb-look-gap-set, var(--wps-pb-gap-set, var(--wps-pb-look-gap-own, 10px)));
	padding: var(--wps-pb-look-pad-block) var(--wps-pb-look-pad-inline);
	border-radius: var(--wps-pb-look-radius);
}

:is(.wps-pb-look-card, .wps-pb-look-tint) .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__track {
	height: var(--wps-pb-look-height);
}

/* Pinned to a screen edge the wrapper already brings the surface and the
   air; the card does not add its own. The tinted strip keeps its padding:
   its colour is on the bar itself. */
.wps-pb-look-card .wps-pb-fixed .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	padding-inline: 0;
	border: 0;
}

/* A. Card: as the cards of the checkout steps; the amount in the accent. */
.wps-pb-look-card .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	background: var(--wps-pb-surface-look);
	border: 1px solid var(--wps-pb-border-set, var(--wps-pb-border, var(--wps-border, var(--color-border, rgba(0, 0, 0, 0.12)))));
}

.wps-pb-look-card .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__num {
	color: var(--wps-pb-accent);
}

/* B. Tint: the strip in a light tint of the accent (its own chain: the
   bridge gives the track a neutral surface), the icon in an accent circle;
   reached, the whole strip is the accent and the bar is gone. Text on the
   tint stays the text colour. */
.wps-pb-look-tint .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	background: var(--wps-pb-tint-set, var(--wps-pb-tint-own, color-mix(in srgb, var(--wps-pb-accent) 14%, transparent)));
}

.wps-pb-look-tint .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) :is(.wps-pb__line--done, .wps-pb__check) {
	color: var(--wps-pb-text);
}

.wps-pb-look-tint .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__track {
	background: var(--wps-pb-surface-look);
}

.wps-pb-look-tint .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__icon-wrap {
	display: inline-grid;
	place-items: center;
	inline-size: 1.9em;
	block-size: 1.9em;
	font-size: 1.1em;
	color: var(--wps-pb-accent-contrast);
	background: var(--wps-pb-accent);
	border-radius: 50%;
}

.wps-pb-look-tint .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__icon {
	inline-size: 1.05em;
	block-size: 1.05em;
}

.wps-pb-look-tint .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	color: var(--wps-pb-accent-contrast);
	background: var(--wps-pb-accent);
}

.wps-pb-look-tint .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) :is(.wps-pb__line--done, .wps-pb__check) {
	color: var(--wps-pb-accent-contrast);
}

.wps-pb-look-tint .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__icon-wrap {
	color: var(--wps-pb-accent);
	background: var(--wps-pb-accent-contrast);
}

.wps-pb-look-tint .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__track {
	display: none;
}

/* C. Inside: one thick bar, the last line written on it on one row (a
   longer text ends in an ellipsis); the lines of the rewards already
   unlocked stay above it. */
.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) {
	position: relative;
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__lines {
	display: contents;
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__track {
	height: var(--wps-pb-inside-height);
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child {
	position: absolute;
	inset-inline: 0;
	inset-block-end: 0;
	z-index: 1;
	box-sizing: border-box;
	height: var(--wps-pb-inside-height);
	padding-inline: var(--wps-pb-look-pad-inline);
	color: var(--wps-pb-text);
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child .wps-pb__line-text {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child .wps-pb__pct {
	color: inherit;
}

.wps-pb-look-inside .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child,
.wps-pb-look-inside .wps-pb.is-reached:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child :is(.wps-pb__check, .wps-pb__icon-wrap) {
	color: var(--wps-pb-accent-contrast);
}

.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child .wps-pb__icon-wrap {
	color: inherit;
}

/* On a phone the line keeps to one row on the thick bar. */
@media (max-width: 480px) {
	.wps-pb-look-inside .wps-pb:not(.wps-pb--compact, .wc-block-mini-cart__drawer .wps-pb) .wps-pb__line:last-child {
		gap: 0.4em;
		font-size: var(--wps-pb-inside-size-mobile-set, var(--wps-pb-inside-size-mobile-own, 0.875rem));
		padding-inline: var(--wps-pb-inside-pad-mobile-set, var(--wps-pb-inside-pad-mobile-own, 12px));
	}
}

/* "Almost there": a clear pulse (brightness + glow) + a subtle icon nudge. */
.wps-pb.is-near .wps-pb__fill {
	animation: wps-pb-near 1.4s ease-in-out infinite;
}

.wps-pb.is-near .wps-pb__line--current .wps-pb__icon-wrap {
	animation: wps-pb-near-icon 1.4s ease-in-out infinite;
}

@keyframes wps-pb-near {
	0%, 100% { filter: brightness( 1 ); box-shadow: 0 0 0 0 transparent; }
	50%      { filter: brightness( 1.25 ); box-shadow: 0 0 7px 0 color-mix( in srgb, var(--wps-pb-accent) 55%, transparent ); }
}

@keyframes wps-pb-near-icon {
	0%, 100% { transform: scale( 1 ); }
	50%      { transform: scale( 1.14 ); }
}

/* Reached = a one-time light sweep across the bar + a pop of the newest icon. */
.wps-pb.is-just-reached .wps-pb__fill::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient( 90deg, transparent, rgba( 255, 255, 255, 0.65 ), transparent );
	transform: translateX( -120% );
	animation: wps-pb-sweep 0.7s ease;
}

.wps-pb.is-just-reached .wps-pb__lines .wps-pb__line:last-of-type .wps-pb__icon-wrap {
	animation: wps-pb-pop 0.6s ease;
	transform-origin: center;
}

@keyframes wps-pb-sweep {
	to { transform: translateX( 120% ); }
}

@keyframes wps-pb-pop {
	0%   { transform: scale( 0.6 ); }
	60%  { transform: scale( 1.2 ); }
	100% { transform: scale( 1 ); }
}

/* Accessibility. */
@media (prefers-contrast: more) {
	.wps-pb__track { outline: 1px solid color-mix( in srgb, currentColor 45%, transparent ); }
	.wps-pb__line-text { font-weight: var(--wps-pb-weight-strong); }
}

@media (forced-colors: active) {
	.wps-pb__track { border: 1px solid CanvasText; background: Canvas; }
	.wps-pb__fill { background: Highlight; }
	.wps-pb__icon-wrap,
	.wps-pb__check,
	.wps-pb__line--done { color: CanvasText; forced-color-adjust: none; }
}

@media (prefers-reduced-motion: reduce) {
	.wps-pb__fill { transition: none; }
	.wps-pb.is-near .wps-pb__fill,
	.wps-pb.is-near .wps-pb__line--current .wps-pb__icon-wrap,
	.wps-pb.is-just-reached .wps-pb__lines .wps-pb__line:last-of-type .wps-pb__icon-wrap { animation: none; }
	.wps-pb.is-just-reached .wps-pb__fill::after { animation: none; opacity: 0; }
}

/* ------------------------------------------------------------------
   Placement inside the Cart / Checkout blocks
   ------------------------------------------------------------------
   Dropped into the order summary the bar would sit flush against the block
   below it. It gets the same vertical rhythm as the content column instead of a
   number of its own, so the two columns keep the same beat.
   ------------------------------------------------------------------ */
.wps-pb-placed {
	margin-block: var(--wps-pb-placed-gap, var(--wps-block-gap, 24px));
}

/* Above the whole cart/checkout: the air belongs below the bar only — the
   page title above it already brought its own. (A block theme's own layout
   rule usually wins here; this is the fallback for themes without one.) */
.wps-pb-placed--before {
	margin-block-start: 0;
}

/* ------------------------------------------------------------------
   Pinned to a screen edge
   ------------------------------------------------------------------
   Printed at body level, so `position: fixed` is never trapped by a
   transformed ancestor inside the WooCommerce blocks.

   The space the bar takes is handed back to the page: <body> carries a
   wps-pb-fixed-top / -bottom class and gets that much padding, measured live
   into --wps-pb-fixed-h by the updater (the bar grows a line every time a
   reward unlocks). That is what keeps it from covering any content.

   --wps-pb-fixed-offset is the seam for a theme with its own fixed header:
   push the bar below it instead of under it.
   ------------------------------------------------------------------ */
.wps-pb-fixed {
	position: fixed;
	inset-inline: 0;
	z-index: var(--wps-z-sticky, 200);
	background: var(--wps-pb-surface-set, var(--wps-pb-surface, var(--wps-surface, var(--color-surface, #ffffff))));
	padding-block: var(--wps-pb-fixed-padding-block-set, var(--wps-pb-fixed-padding-block, 10px));
	padding-inline: var(--wps-pb-fixed-padding-inline-set, var(--wps-pb-fixed-padding-inline, 16px));
}

.wps-pb-fixed__inner {
	margin-inline: auto;
	max-inline-size: var(--wps-pb-fixed-width, var(--wp--style--global--wide-size, 1200px));
}

/* The bar brings its own air here; the wrapper already has the padding. */
.wps-pb-fixed .wps-pb {
	margin-block: 0;
}

.wps-pb-fixed--top {
	inset-block-start: var(--wps-pb-fixed-offset, 0px);
	border-block-end: 1px solid color-mix( in srgb, currentColor 12%, transparent );
}

.wps-pb-fixed--bottom {
	inset-block-end: 0;
	padding-block-end: calc( var(--wps-pb-fixed-padding-block-set, var(--wps-pb-fixed-padding-block, 10px)) + var(--wps-safe-bottom, 0px) );
	border-block-start: 1px solid color-mix( in srgb, currentColor 12%, transparent );
}

body.wps-pb-fixed-top {
	padding-block-start: var(--wps-pb-fixed-h, 0px);
}

body.wps-pb-fixed-bottom {
	padding-block-end: var(--wps-pb-fixed-h, 0px);
}

/* ------------------------------------------------------------------
   Autoscroll clearance under a pinned bar
   ------------------------------------------------------------------
   The checkout scrolls the customer to the next step, to a field, to an
   error banner. Every one of those lands under a bar pinned to the top
   unless the scroll container is told to keep that much clear.

   `scroll-padding` on the scrolling box is honoured by scrollIntoView() and
   by anchor jumps, so this covers WooCommerce's own error scrolling and
   every other caller at once — no script has to know about them.
   The 12px matches the breathing room wps-checkout uses by default.

   Callers that compute the offset by hand (window.scrollTo with their own
   maths) cannot see scroll-padding; those are served by --wpsc-scroll-offset,
   which the updater sets from the measured height.
   ------------------------------------------------------------------ */
html:has(> body.wps-pb-fixed-top) {
	scroll-padding-block-start: calc( var(--wps-pb-fixed-h, 0px) + var(--wps-pb-scroll-gap-set, var(--wps-pb-scroll-gap, 12px)) );
}

html:has(> body.wps-pb-fixed-bottom) {
	scroll-padding-block-end: calc( var(--wps-pb-fixed-h, 0px) + var(--wps-pb-scroll-gap-set, var(--wps-pb-scroll-gap, 12px)) );
}

/* A theme that lays the classic cart out as a grid (cart table and totals
   side by side) would give the bar the first cell; it takes the whole row. */
.woocommerce > .wps-pb {
	grid-column: 1 / -1;
}
