/**
 * The bundle builder.
 *
 * Deliberately restrained: it inherits the theme's typography and colour rather
 * than imposing its own, so it looks like part of the shop instead of a widget
 * dropped into it. Custom properties below can be overridden by a theme.
 *
 * @package TPL_Bundle_Builder
 */

.tpl-bb {
	--tpl-bb-gap: 20px;
	--tpl-bb-radius: 10px;

	/* One height for the Add button and the stepper that replaces it. They swap
	   in place, so a difference of even two pixels makes the card nudge. */
	--tpl-bb-control-h: 46px;
	--tpl-bb-line: #e3e3e6;
	--tpl-bb-muted: #55555c;  /* 4.4:1 on the tinted notice was under AA */

	/*
	 * Take the shop's own accent where the theme publishes one, and fall back to
	 * a neutral warm tone only if it does not. Blocksy exposes its palette as
	 * --theme-palette-color-1; other themes commonly expose --wp--preset--color--primary.
	 * A builder in a colour the shop never chose looks like something bolted on,
	 * which is exactly what it should not look like.
	 *
	 * To pin it deliberately, put this in Appearance > Customise > Additional CSS:
	 *     .tpl-bb { --tpl-bb-accent: #yourcolour; }
	 */
	--tpl-bb-accent: var(--theme-palette-color-1, var(--wp--preset--color--primary, #b8763a));
	--tpl-bb-accent-soft: color-mix(in srgb, var(--tpl-bb-accent) 10%, #ffffff);

	--tpl-bb-good: #2f7d4f;
	--tpl-bb-warn: #b32d2e;
	--tpl-bb-surface: #ffffff;

	position: relative;
}

/*
 * color-mix() is widely supported but not universally. Where it is missing the
 * soft tint above resolves to nothing, so state a plain fallback first and let
 * the modern value win where it works.
 */
@supports not (color: color-mix(in srgb, red 10%, white)) {
	.tpl-bb {
		--tpl-bb-accent-soft: #f6f6f7;
	}
}

/* Scrolling over the backdrop scrolled the page behind it. Set while a sheet
   is open, cleared when it closes. */
body.tpl-bb-scroll-locked {
	overflow: hidden;
}

.tpl-bb *,
.tpl-bb *::before,
.tpl-bb *::after {
	box-sizing: border-box;
}

/*
 * THIS RULE IS LOAD-BEARING. Do not remove it, and do not set `display` on an
 * element that is ever toggled with the `hidden` attribute without it.
 *
 * `[hidden] { display: none }` is a USER-AGENT rule, and any author rule that
 * sets `display` on the same element beats it whatever the specificity. Because
 * this file sets display on cards, steppers and totals rows — all of which are
 * hidden and shown by script — every one of them rendered regardless of state
 * in 0.4.1. The JavaScript was correct throughout; the browser simply declined
 * to act on it.
 *
 * What that looked like: a "− 0 +" stepper on every card beside its Add button,
 * "Nothing matches that search" above a full grid of products, a stale "Set
 * discount" under a ₹0.00 subtotal, and pagination that changed nothing.
 */
.tpl-bb [hidden] {
	display: none !important;
}

/*
 * The page must never scroll sideways. Anything that would push it wide is a
 * bug, so this is stated once rather than fixed case by case.
 *
 * `clip`, NOT `hidden`. An ancestor with `overflow: hidden` becomes the scroll
 * container for any `position: sticky` descendant, so the summary panel stuck
 * inside a short box instead of the viewport — which looks precisely like not
 * sticking at all. `clip` does the same clipping without creating a scroll
 * container, so the sticky summary survives.
 *
 * Browsers without `overflow: clip` ignore this and simply do not clip, which
 * is harmless: nothing here actually overflows, this is only a guarantee.
 */
.tpl-bb,
.tpl-bb__layout,
.tpl-bb__catalog,
.tpl-bb__summary {
	max-width: 100%;
	overflow-x: clip;
}

.tpl-bb__intro {
	margin: 0 0 var(--tpl-bb-gap);
	color: var(--tpl-bb-muted);
}

.tpl-bb__notice {
	/* Stated explicitly. Inheriting the theme's grey put this at 4.38:1 on
	   the tint - under AA - while the <small> beneath it passed, because only
	   that line used the plugin's own muted colour. */
	color: #1f1f24;
	padding: 14px 16px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent-soft);
}

.tpl-bb__notice small {
	display: block;
	margin-top: 6px;
	color: var(--tpl-bb-muted);
}

/* Search's Clear button. Without this it renders as bare browser chrome jammed
   against the input. */
.tpl-bb__search .tpl-bb__search-clear {
	flex: 0 0 auto;
	padding: 10px 14px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-surface);
	color: var(--tpl-bb-muted);
	font: inherit;
	cursor: pointer;
}

.tpl-bb__search .tpl-bb__search-clear:hover {
	border-color: var(--tpl-bb-accent);
	color: var(--tpl-bb-accent);
}

/* Skip past the grid. With a link, an Add and a stepper on every card, reaching
   the summary by keyboard otherwise takes dozens of presses. */
.tpl-bb__skip {
	position: absolute;
	left: -9999px;
	z-index: 70;
	padding: 10px 14px;
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent);
	color: #fff;
	text-decoration: none;
}

.tpl-bb__skip:focus {
	left: 0;
}

/* Utility ---------------------------------------------------------------- */

.tpl-bb .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.tpl-bb__link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--tpl-bb-accent);
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}

/*
 * Every interactive element must show where the keyboard is.
 *
 * Two rings, not one, and neither of them the shop's accent. P2: the accent on
 * this shop is rgb(16, 180, 142), which against a white card is about 2.7:1 -
 * under the 3:1 WCAG asks of a focus indicator. Inheriting any shop's accent
 * means inheriting whatever contrast it happens to have. A dark outer ring with
 * a light ring inside it holds against a white card, against the accent-coloured
 * bar, and against whatever palette the next theme brings: one of the two is
 * always far from the background.
 */
.tpl-bb button:focus-visible,
.tpl-bb input:focus-visible,
.tpl-bb a:focus-visible,
.tpl-bb [tabindex]:focus-visible {
	outline: 2px solid #1d1d1f;
	outline-offset: 2px;
	box-shadow: 0 0 0 2px #fff;
}

/*
 * Where the browser scrolls a focused control to.
 *
 * P8: a browser scrolls a newly focused control just into view, which on this
 * theme is underneath the sticky header - Shift+Tab onto Update left it half
 * hidden. The header's height is already measured for the plugin's own
 * scrolling; this applies the same measurement to scrolling the browser does.
 * The bottom margin keeps focus clear of the fixed bar on a phone.
 */
.tpl-bb button,
.tpl-bb input,
.tpl-bb a,
.tpl-bb [tabindex] {
	scroll-margin-top: calc(var(--tpl-bb-sticky-top, var(--tpl-bb-sticky-measured, 24px)) + 12px);
	scroll-margin-bottom: 96px;
}

/* Present to a screen reader, invisible on screen. Clipped rather than
   display:none, because display:none takes it out of hearing too. */
.tpl-bb__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Layout ----------------------------------------------------------------- */

.tpl-bb__layout {
	display: grid;
	gap: calc(var(--tpl-bb-gap) * 1.5);
}

@media (min-width: 900px) {
	.tpl-bb__layout {
		grid-template-columns: minmax(0, 1fr) 320px;
		align-items: start;
	}

	/* The only part of the panel that may shrink, so the totals and the button
	   are always visible. */
	.tpl-bb__summary > * {
		flex: 0 0 auto;
	}

	.tpl-bb__summary .tpl-bb__tray {
		flex: 1 1 auto;
		min-height: 54px;
	}
}

/* Search ----------------------------------------------------------------- */

.tpl-bb__search {
	display: flex;
	gap: 8px;
	margin-bottom: var(--tpl-bb-gap);
}

.tpl-bb__search-input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 10px 12px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	font: inherit;
}

.tpl-bb__empty-results {
	padding: 20px;
	border: 1px dashed var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	color: var(--tpl-bb-muted);
	text-align: center;
}

/* Grid ------------------------------------------------------------------- */

.tpl-bb__grid {
	display: grid;
	gap: var(--tpl-bb-gap);
	grid-template-columns: repeat(2, minmax(0, 1fr));
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (min-width: 560px) {
	.tpl-bb__grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

@media (min-width: 900px) {
	.tpl-bb__grid {
		grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	}
}

.tpl-bb__card {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-surface);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tpl-bb__card.is-chosen {
	border-color: var(--tpl-bb-accent);
	box-shadow: 0 0 0 1px var(--tpl-bb-accent);
}

.tpl-bb__card.is-unavailable {
	opacity: 0.55;
}

.tpl-bb__card-image {
	position: relative;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	border-radius: calc(var(--tpl-bb-radius) - 4px);
	background: #f5f5f6;
}

.tpl-bb__card-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.tpl-bb__sold-out {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	padding: 4px 6px;
	background: rgba(0, 0, 0, 0.72);
	color: #fff;
	font-size: 0.72rem;
	text-align: center;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.tpl-bb__card-name {
	margin: 0;
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.3;
}

.tpl-bb__card-price {
	margin-top: auto;
	font-size: 0.88rem;
	color: var(--tpl-bb-muted);
}

.tpl-bb__card-price del {
	opacity: 0.6;
}

/* Card controls ---------------------------------------------------------- */

/* font:inherit must come BEFORE line-height, or it resets it - which it was
   doing, leaving the heights matching only by virtue of the minimum. */
.tpl-bb__add {
	/*
	 * `font` is a SHORTHAND and resets line-height, so it has to come first and
	 * appear once. 0.4.5 added one at the top and left the original below it,
	 * which promptly reset the line-height again - so the button and the stepper
	 * still matched only by virtue of the shared minimum height, and a label
	 * long enough to wrap would have nudged the card exactly as before.
	 */
	font: inherit;
	font-weight: 600;
	line-height: 1.2;

	width: 100%;
	min-height: var(--tpl-bb-control-h);
	padding: 8px 12px;
	border: 1px solid var(--tpl-bb-accent);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent);
	color: #fff;
	cursor: pointer;
}

.tpl-bb__add:disabled {
	border-color: var(--tpl-bb-line);
	background: #f0f0f1;
	color: var(--tpl-bb-muted);
	cursor: not-allowed;
}

.tpl-bb__stepper {
	display: grid;
	grid-template-columns: 44px 1fr 44px;
	min-height: var(--tpl-bb-control-h);
	align-items: center;
	border: 1px solid var(--tpl-bb-accent);
	border-radius: var(--tpl-bb-radius);
	overflow: hidden;
}

/* 44px is the smallest target that is reliably comfortable with a thumb.
   Criterion 9 depends on it, so it is a floor, not a suggestion. */
.tpl-bb__step {
	min-width: 44px;
	min-height: 44px;
	border: 0;
	background: var(--tpl-bb-accent-soft);
	color: var(--tpl-bb-accent);
	font-size: 1.15rem;
	line-height: 1;
	cursor: pointer;
}

.tpl-bb__step:disabled {
	background: #f4f4f5;
	color: #b6b6bb;
	cursor: not-allowed;
}

/* Duplicates off: no quantity to step through, so the control becomes one
   plain Remove rather than a stepper whose "+" can never work. */
.tpl-bb__stepper.is-single {
	grid-template-columns: 1fr;
}

.tpl-bb__stepper.is-single .tpl-bb__step-count {
	display: none;
}

.tpl-bb__stepper.is-single .tpl-bb__step {
	font-size: 0.9rem;
	font-weight: 600;
}

.tpl-bb__step-count {
	text-align: center;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

/* Pager ------------------------------------------------------------------ */

.tpl-bb__pager {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	margin-top: var(--tpl-bb-gap);
}

.tpl-bb__page {
	min-width: 40px;
	min-height: 40px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: 8px;
	background: var(--tpl-bb-surface);
	font: inherit;
	cursor: pointer;
}

.tpl-bb__page.is-current {
	border-color: var(--tpl-bb-accent);
	background: var(--tpl-bb-accent);
	color: #fff;
	font-weight: 700;
}

/* Summary ---------------------------------------------------------------- */

.tpl-bb__summary {
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 18px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-surface);
}

@media (min-width: 900px) {
	.tpl-bb__summary {
		/*
		 * Never taller than what is left of the viewport. On a 700px-high
		 * window the panel was 750px tall, so "Add set to cart" sat below the
		 * fold the entire time it was stuck - the primary action, permanently
		 * out of reach. The list gives up its space instead.
		 */
		display: flex;
		flex-direction: column;
		max-height: calc( 100vh - var(--tpl-bb-sticky-top, var(--tpl-bb-sticky-measured, 24px)) - 24px );

		position: sticky;

		/*
		 * Clear whatever is pinned to the top of the viewport. A flat 24px put
		 * the heading under this theme's fixed header once the panel actually
		 * started sticking. The script measures the real header and sets the
		 * variable; 24px is the answer when nothing is pinned.
		 *
		 * To pin it yourself:  .tpl-bb { --tpl-bb-sticky-top: 120px; }
		 */
		top: var(--tpl-bb-sticky-top, var(--tpl-bb-sticky-measured, 24px));
	}
}

.tpl-bb__summary-heading {
	margin: 0;
	font-size: 1.05rem;
}

.tpl-bb__guidance {
	margin: 0;
	padding: 10px 12px;
	border-radius: 8px;
	background: var(--tpl-bb-accent-soft);
	color: #7a4a1c;
	font-size: 0.9rem;

	/*
	 * Two lines reserved from the start, a single line centred in them. P6:
	 * reaching the minimum turns one line ("Add 1 more...") into two ("Nice -
	 * you have saved...", "Add 1 more to save..."), and on a desktop the panel
	 * grows with its content - so the extra 27px pushed "Add set to cart" down
	 * onto the place "Start over" had just been. Content-box, so the
	 * reservation is the text's own and a theme's box-sizing cannot take the
	 * padding out of it.
	 */
	box-sizing: content-box;
	display: flex;
	flex-direction: column;
	justify-content: center;
	line-height: 1.45;
	min-height: calc(2 * 1.45em + 3px);
}

.tpl-bb__dropped {
	margin: 0;
	padding: 10px 12px;
	border-radius: var(--tpl-bb-radius);
	border: 1px solid currentColor;
	color: #8a2b06;
	background: #fdf4f0;
	font-size: 0.88em;
}

.tpl-bb__editing-note {
	margin: 0;
	padding: 10px 12px;
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent-soft);
	font-size: 0.88em;
}

.tpl-bb__guidance span {
	display: block;
}

.tpl-bb__guidance span + span {
	margin-top: 3px;
}

.tpl-bb__guidance.is-warning {
	background: #fdecec;
	color: var(--tpl-bb-warn);
}

/* Tier ladder ------------------------------------------------------------
   Wraps. Never scrolls. The reference implementation hid its largest saving
   behind a sideways scroll on an ordinary laptop, which is the one mistake
   this component exists not to repeat. */

.tpl-bb__ladder {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.tpl-bb__tier {
	flex: 1 1 84px;
	min-width: 0;
	padding: 8px 6px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: 8px;
	text-align: center;
	font-size: 0.76rem;
	line-height: 1.35;
	transition: background-color 0.2s ease, border-color 0.2s ease;
}

.tpl-bb__tier-qty {
	display: block;
	color: var(--tpl-bb-muted);
}

.tpl-bb__tier-value {
	display: block;
	font-weight: 700;
}

.tpl-bb__tier.is-reached {
	border-color: var(--tpl-bb-good);
	background: #eaf5ee;
	color: var(--tpl-bb-good);
}

.tpl-bb__tier.is-reached .tpl-bb__tier-qty {
	color: var(--tpl-bb-good);
}

.tpl-bb__tier.is-just-reached {
	animation: tpl-bb-pop 0.45s ease;
}

@keyframes tpl-bb-pop {
	0% { transform: scale(1); }
	40% { transform: scale(1.07); }
	100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.tpl-bb__tier,
	.tpl-bb__tier.is-just-reached {
		animation: none;
		transition: none;
	}
}

.tpl-bb__progress {
	height: 6px;
	border-radius: 999px;
	background: #eeeeef;
	overflow: hidden;
}

.tpl-bb__progress-fill {
	height: 100%;
	width: 0;
	border-radius: inherit;
	background: var(--tpl-bb-good);
	transition: width 0.25s ease;
}

/* Chosen items ----------------------------------------------------------- */

.tpl-bb__tray {
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-height: 260px;
	margin: 0;
	padding: 0;
	overflow-y: auto;
	list-style: none;
}

.tpl-bb__tray-empty {
	padding: 16px 12px;
	border: 1px dashed var(--tpl-bb-line);
	border-radius: 8px;
	color: var(--tpl-bb-muted);
	font-size: 0.86rem;
	text-align: center;
}

/*
 * The last column is the remove button's, and must match it. 0.9.0 grew the
 * button to 44px for P20 and left this column at 32, so every row overflowed
 * sideways by the difference and the list grew a horizontal scrollbar - found
 * by the watch round, not by the change. minmax(0, 1fr) lets the name give
 * way instead.
 */
.tpl-bb__tray-item {
	display: grid;
	grid-template-columns: 40px minmax(0, 1fr) 44px;
	gap: 10px;
	align-items: center;
}

.tpl-bb__tray-item.is-unavailable {
	opacity: 0.6;
}

.tpl-bb__tray-item img {
	width: 40px;
	height: 40px;
	border-radius: 6px;
	object-fit: cover;
}

.tpl-bb__tray-body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.tpl-bb__tray-name {
	font-size: 0.84rem;
	font-weight: 600;
	line-height: 1.3;

	/* Two lines rather than one truncated one. A set of bookmarks whose names
	   all begin the same way is unreadable cut at a fixed width. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.tpl-bb__tray-meta {
	font-size: 0.78rem;
	color: var(--tpl-bb-muted);
}

/* 44px: P20. At 32 it was the smallest thing in the sheet that removes money
   from a set, and the easiest to miss on a phone. The glyph stays the same
   size; only the area that answers a tap grows. */
.tpl-bb__tray-remove {
	flex: 0 0 auto;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: 6px;
	background: none;
	color: var(--tpl-bb-muted);
	font-size: 1.1rem;
	line-height: 1;
	cursor: pointer;
}

.tpl-bb__tray-remove:hover {
	background: #fdecec;
	color: var(--tpl-bb-warn);
}

/* Totals ----------------------------------------------------------------- */

.tpl-bb__totals {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	padding-top: 12px;
	border-top: 1px solid var(--tpl-bb-line);
	font-size: 0.88rem;
}

.tpl-bb__total-row {
	display: flex;
	justify-content: space-between;
	gap: 12px;
}

.tpl-bb__total-row dt,
.tpl-bb__total-row dd {
	margin: 0;
}

.tpl-bb__total-row dd {
	font-variant-numeric: tabular-nums;
}

.tpl-bb__total-row--saving {
	color: var(--tpl-bb-good);
	font-weight: 600;
}

/*
 * No saving yet: the row keeps its place and shows nothing. P6 - it used to
 * appear at the first tier, 23px above the button, at the same moment as the
 * guidance's second line. visibility rather than display, so the space stays
 * and a screen reader still skips it.
 */
.tpl-bb__total-row--saving.is-empty {
	visibility: hidden;
}

.tpl-bb__total-row--total {
	padding-top: 6px;
	border-top: 1px solid var(--tpl-bb-line);
	font-size: 1.05rem;
	font-weight: 700;
}

/* Submit ----------------------------------------------------------------- */

.tpl-bb__submit {
	width: 100%;
	min-height: 50px;
	padding: 12px 16px;
	border: 0;
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent);
	color: #fff;
	font: inherit;
	font-size: 1rem;
	font-weight: 700;
	cursor: pointer;
}

.tpl-bb__submit:disabled {
	background: #e6e6e8;
	color: #97979d;
	cursor: not-allowed;
}

/*
 * A refused add is a wall at the end of the whole journey, so it has to read
 * as one. In 0.5.1 the only signal was this line turning from grey to grey:
 * is-warning was styled on the guidance element, never on this one, so every
 * failure message rendered in the ordinary muted colour.
 */
.tpl-bb__submit-hint.is-warning {
	padding: 10px 12px;
	border: 1px solid var(--tpl-bb-warn);
	border-radius: var(--tpl-bb-radius);
	background: #fdf2f2;
	color: var(--tpl-bb-warn);
	font-weight: 600;
}

.tpl-bb__submit-hint {
	/*
	 * One line reserved whether or not there is anything to say. P6: the hint
	 * was removed from the flow when empty, so crossing the minimum moved
	 * "Start over" by a line of text at exactly the moment somebody was
	 * reaching for it - and a click aimed at it landed on "Add set to cart".
	 */
	min-height: 1.4em;
	margin: 0;
	color: var(--tpl-bb-muted);
	font-size: 0.82rem;

	/*
	 * The line the text sits on must be the line reserved for it. The theme's
	 * line-height made a line 21.65px against 18.37px reserved, so the hint
	 * appearing grew the block by 3.28px - and on a phone, where the block
	 * is pinned by its bottom edge, the button above it moved by exactly that.
	 */
	line-height: 1.4;
	text-align: center;
}

.tpl-bb__submit-hint.is-empty {
	visibility: hidden;
}

.tpl-bb__actions {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

/*
 * Pinned only in the phone's sheet, which scrolls, and where the block stays
 * at its bottom edge while it does. The negative margins carry the block's
 * background over the sheet's own padding, so nothing scrolls visibly
 * underneath the button.
 *
 * Not on a desktop. 0.9.0 pinned it there too, and at the top of the page -
 * before the panel has scrolled into place - the pinned block sat over the
 * Subtotal, Set discount and Total rows (the 8.5 round measured the overlap).
 * On a desktop the panel does not scroll; it grows with its content, and
 * the space reserved above the button (P6) is what keeps the button still.
 */
@media (max-width: 899px) {
	.tpl-bb__actions {
		position: sticky;
		bottom: -18px;
		z-index: 1;
		margin: 0 -18px -18px;
		padding: 12px 18px 18px;
		background: var(--tpl-bb-surface);
		box-shadow: 0 -10px 12px -10px rgba(0, 0, 0, 0.18);
	}
}

.tpl-bb__undo {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 4px 8px;
	margin: 0;
	font-size: 0.85rem;
}

.tpl-bb__undo-btn {
	min-height: 44px;
	padding-inline: 12px;
	font-weight: 600;
}

/* The text stays small; the target does not. At 22px tall it was the
   smallest control in the sheet and the one that empties the whole set. */
.tpl-bb__reset {
	align-self: center;
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding-inline: 12px;
	font-size: 0.82rem;
}

/* Mobile bar ------------------------------------------------------------- */

/*
 * --tpl-bb-bar-inset-start: room at the bar's left for another plugin's
 * floating button. P20: an accessibility widget at bottom left sat over the
 * bar and hid "Your". Its position belongs to that plugin and cannot be known
 * from here, and covering it instead would hide a tool some visitors need. So
 * the room is the shop's to give, in one line of CSS:
 *
 *     .tpl-bb { --tpl-bb-bar-inset-start: 64px; }
 */
/*
 * z-index 9000 rather than "above everything" on purpose: a cookie-consent
 * banner must stay answerable, and P20 chose not to cover the accessibility
 * widget. env(safe-area-inset-bottom) keeps the buttons above an iPhone's
 * home bar.
 */
.tpl-bb__bar {
	position: fixed;
	inset-inline: 0;
	bottom: 0;
	z-index: 9000;
	padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
	padding-inline-start: var(--tpl-bb-bar-inset-start, 12px);
	border-top: 1px solid var(--tpl-bb-line);
	background: var(--tpl-bb-surface);
	box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.08);
}

/*
 * How far the next saving is, or why the set cannot be added. One line is
 * reserved even when empty, so the line arriving does not move the buttons;
 * a longer message grows the bar upwards, since the bar is pinned by its
 * bottom edge, and the buttons stay where the thumb is.
 */
.tpl-bb__bar-line {
	min-height: 1.35em;
	margin: 0 0 8px;
	color: #7a4a1c;
	font-size: 0.85rem;
	font-weight: 600;
	line-height: 1.35;
	text-align: center;
}

.tpl-bb__bar-line.is-warning {
	color: var(--tpl-bb-warn);
}

.tpl-bb__bar-row {
	display: flex;
	align-items: stretch;
	gap: 8px;
}

/*
 * The left half opens the sheet. Quieter than the button beside it, which is
 * the one thing on the bar that buys; until 1.0.1 the whole bar was this
 * toggle, in the accent.
 */
.tpl-bb__bar-toggle {
	display: flex;
	flex: 1 1 auto;
	min-width: 0;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	min-height: 52px;
	padding: 6px 12px;
	border: 1px solid var(--tpl-bb-line);
	border-radius: var(--tpl-bb-radius);
	background: var(--tpl-bb-accent-soft);
	color: #1f1f24;
	font: inherit;
	text-align: start;
	cursor: pointer;
}

.tpl-bb__bar-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
	line-height: 1.3;
}

/* Wraps rather than truncates: cut short at 320px it lost the total. */
.tpl-bb__bar-count {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

/* Its line is held when empty, so the first discount does not grow the bar. */
.tpl-bb__bar-saving {
	min-height: 1.3em;
	color: var(--tpl-bb-good);
	font-size: 0.8rem;
	font-weight: 600;
}

.tpl-bb__bar-saving.is-empty {
	visibility: hidden;
}

.tpl-bb__bar-caret {
	flex: 0 0 auto;
	color: var(--tpl-bb-muted);
}

.tpl-bb__bar-caret::after {
	content: "▲";
	font-size: 0.7em;
}

/*
 * Inherits .tpl-bb__submit - the accent, the grey when disabled - and gives
 * up its full width. Capped so a long merchant label wraps onto two lines
 * instead of squeezing the count and total out.
 */
.tpl-bb__bar-submit {
	flex: 0 0 auto;
	width: auto;
	max-width: 52%;
	min-height: 52px;
	padding: 6px 14px;
	font-size: 0.95rem;
	line-height: 1.2;
}

/* A pick lands: the toggle rings once in the accent, and the count pops. */
.tpl-bb__bar-toggle.is-bumped {
	animation: tpl-bb-bump 0.6s ease;
}

.tpl-bb__bar-toggle.is-bumped .tpl-bb__bar-count {
	animation: tpl-bb-pop 0.45s ease;
}

@keyframes tpl-bb-bump {
	0% { box-shadow: 0 0 0 3px var(--tpl-bb-accent); }
	100% { box-shadow: 0 0 0 3px transparent; }
}

/* No movement for anyone who asked for none. The ring is a colour, not a
   motion, so it stays. */
@media (prefers-reduced-motion: reduce) {
	.tpl-bb__bar-toggle.is-bumped .tpl-bb__bar-count {
		animation: none;
	}
}

.tpl-bb.is-summary-open .tpl-bb__bar-caret::after {
	content: "▼";
}

/* On a phone the summary is a sheet the bar opens, not a column. Below 900px
   it is out of the flow until asked for; from 900px the bar disappears and the
   sticky column takes over. */
/*
 * The way out of the sheet.
 *
 * The sheet sits at the bottom edge at a higher z-index than the bar that opens
 * it, so once open it covers its own toggle. In 0.4.1 there was genuinely no way
 * to close it. Two routes now: a close control in the sheet header, and tapping
 * the scrim behind it — which is what most people try first.
 */
.tpl-bb__sheet-close {
	display: none;
	position: absolute;
	top: 10px;
	inset-inline-end: 10px;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: 50%;
	background: #f1f1f2;
	color: var(--tpl-bb-muted);
	font-size: 1.2rem;
	line-height: 1;
	cursor: pointer;
}

.tpl-bb__scrim {
	position: fixed;
	inset: 0;
	z-index: 8999;
	background: rgba(0, 0, 0, 0.4);
	border: 0;
	padding: 0;
}

@media (max-width: 899px) {
	.tpl-bb__summary {
		position: fixed;
		inset-inline: 0;
		bottom: 0;
		z-index: 9001;
		max-height: 85vh;
		overflow-y: auto;

		/* Scrolling past the end of the sheet was scrolling the page behind it. */
		overscroll-behavior: contain;
		border-radius: var(--tpl-bb-radius) var(--tpl-bb-radius) 0 0;
		transform: translateY(101%);

		/*
		 * Off-screen is not the same as gone. A closed sheet was still in the
		 * tab order, so reaching the bar meant passing through six invisible
		 * stops, and Shift+Tab from the bar landed on a Close button nobody
		 * could see. visibility takes it out of the order; the delayed
		 * transition keeps it on screen while it slides away.
		 */
		visibility: hidden;
		transition: transform 0.25s ease, visibility 0s linear 0.25s;

		/*
		 * No room reserved at the bottom for the bar. The sheet sits ON TOP of
		 * the bar, so holding 84px clear for it only squeezed the contents —
		 * which is what made the item list smaller in 0.4.2 than it had been
		 * before the sheet gained a close button.
		 */
		padding-bottom: calc(18px + env(safe-area-inset-bottom));
	}

	.tpl-bb.is-summary-open .tpl-bb__summary {
		transform: translateY(0);
		visibility: visible;
		transition: transform 0.25s ease, visibility 0s linear 0s;
	}

	/* The bar is a tap away, and the skip link's target lives inside the
	   closed sheet - so it pointed at something invisible. */
	.tpl-bb__skip {
		display: none;
	}

	.tpl-bb__sheet-close {
		display: block;
	}

	/* Keep the heading clear of the close button rather than pushing the whole
	   sheet down by a row to make space for it. */
	.tpl-bb__summary-heading {
		padding-inline-end: 44px;
	}

	/*
	 * The chosen items are the reason the sheet was opened, so they take their
	 * natural height and the sheet scrolls as one thing. Without the explicit
	 * flex-shrink they compress to whatever is left over — 43px with three
	 * items chosen, which showed one line of a list.
	 */
	.tpl-bb__tray {
		max-height: none;
		flex: 0 0 auto;
		overflow: visible;
	}

	/*
	 * Once the tray stopped shrinking, the guidance became the only child
	 * that could — so it took all the squeeze instead: a 20px box holding
	 * 61px of text, with the second line behind the tier chips. Nothing in
	 * the sheet shrinks; the sheet scrolls.
	 */
	.tpl-bb__summary > * {
		flex: 0 0 auto;
	}

	/* Stays reachable while the sheet scrolls, rather than scrolling away
	   with the content it is meant to dismiss. */
	.tpl-bb__sheet-close {
		position: sticky;
		top: 0;
		align-self: flex-end;
		margin-bottom: -44px;
	}

	/*
	 * Room for the fixed bar, so the last row of the grid is never behind it.
	 * --tpl-bb-bar-h is the bar's own measured height, set by the script
	 * (measureBar), because since 1.0.1 that height depends on what the bar
	 * says. 112px stands in until it has been measured.
	 */
	.tpl-bb__catalog {
		padding-bottom: calc(var(--tpl-bb-bar-h, 112px) + 16px);
	}

	/* And the browser's own scrolling to a focused control clears it too. */
	.tpl-bb button,
	.tpl-bb input,
	.tpl-bb a,
	.tpl-bb [tabindex] {
		scroll-margin-bottom: calc(var(--tpl-bb-bar-h, 112px) + 12px);
	}
}

@media (min-width: 900px) {
	.tpl-bb__bar {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tpl-bb__summary,
	.tpl-bb__progress-fill {
		transition: none;
	}
}

/* Until the script runs there is nothing to summarise, so the panel and the bar
   stay hidden and the grid simply reads as a list of products. */
/*
 * Shown until the script says otherwise, which covers scripts being blocked
 * AND the script failing. A <noscript> block only handles the first, so a
 * shopper whose JavaScript errored got a grid with no controls and no
 * explanation at all.
 */
.tpl-bb.is-ready .tpl-bb__fallback {
	display: none;
}

/* No summary means no column to reserve for it. */
.tpl-bb:not(.is-ready) .tpl-bb__layout {
	grid-template-columns: minmax(0, 1fr);
}

.tpl-bb:not(.is-ready) .tpl-bb__skip,
.tpl-bb:not(.is-ready) .tpl-bb__summary,
.tpl-bb:not(.is-ready) .tpl-bb__bar,
.tpl-bb:not(.is-ready) .tpl-bb__scrim,
.tpl-bb:not(.is-ready) .tpl-bb__search,
.tpl-bb:not(.is-ready) .tpl-bb__add,
.tpl-bb:not(.is-ready) .tpl-bb__stepper {
	display: none;
}

/* The set, as it appears in the cart and at checkout ---------------------- */

/*
 * Not scoped under .tpl-bb: these render inside WooCommerce's own cart and
 * checkout templates, where that wrapper does not exist.
 */
.tpl-bb-cart__contents {
	margin: 6px 0 0;
	padding: 0;
	list-style: none;
	font-size: 0.86em;
	line-height: 1.5;
	opacity: 0.85;
}

.tpl-bb-cart__totals {
	margin: 6px 0 0;
	font-size: 0.82em;
	opacity: 0.75;
}

.tpl-bb-cart__edit {
	display: inline-block;
	margin-top: 6px;
	font-size: 0.86em;
}

/* "2" in a quantity box must never read as two items. */
.tpl-bb-cart__qty-note {
	display: block;
	margin-top: 4px;
	font-size: 0.78em;
	opacity: 0.7;
}

/* The promo block on a product page ------------------------------------- */

/*
 * Scoped to its own class rather than .tpl-bb, because this renders inside a
 * theme's product page rather than inside our own. R5: it has to sit beside
 * whatever else the shop puts there - a shipping nudge, a badge - without
 * either of them assuming it is alone.
 */
.tpl-bb-promo {
	/*
	 * A width of its own, in case a theme renders this somewhere unconstrained.
	 * Inside the product summary it will never reach this figure; outside one,
	 * it stops the block spanning the whole window, which is what it did on
	 * this shop before it moved.
	 */
	max-width: 640px;
	margin: 24px 0;
	padding: 16px 18px;
	border: 1px solid var(--tpl-bb-line, rgba(0, 0, 0, 0.12));
	border-radius: var(--tpl-bb-radius, 10px);
	background: var(--tpl-bb-accent-soft, rgba(0, 0, 0, 0.03));
}

.tpl-bb-promo__heading {
	margin: 0 0 6px;
	font-size: 1.05rem;
	line-height: 1.3;
}

.tpl-bb-promo__intro {
	margin: 0 0 10px;
	font-size: 0.92em;
}

.tpl-bb-promo__tiers {
	margin: 0 0 12px;
	padding: 0;
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: 6px 10px;
	font-size: 0.9em;
}

.tpl-bb-promo__tier {
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.75);
	white-space: nowrap;
}

.tpl-bb-promo__go {
	margin: 0;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px 14px;
}

.tpl-bb-promo__min {
	font-size: 0.88em;
	opacity: 0.85;
}
