/**
 * Pack Builder — product page selector.
 *
 * Theme-neutral. Restyle from a theme by overriding the custom properties on
 * .pkb; the accent and savings colours are also settings, printed inline.
 */

.pkb,
.pkb-set-card {
	--pkb-accent: #111111;
	--pkb-save: #1a7f37;
	--pkb-ink: #1c1c1c;
	--pkb-muted: #6b6b6b;
	--pkb-line: #dcdcdc;
	--pkb-bg: #ffffff;
	--pkb-radius: 10px;
	--pkb-error: #b3261e;
}

.pkb {
	margin: 0 0 22px;
	color: var(--pkb-ink);
}

.pkb__heading {
	margin: 0 0 18px;
	font-weight: 600;
	font-size: 15px;
}

/* Tiles --------------------------------------------------------------- */

.pkb__tiers {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
	gap: 16px 10px;
}

.pkb-tier {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	min-height: 66px;
	padding: 14px 8px 12px;
	border: 1px solid var(--pkb-line);
	border-radius: var(--pkb-radius);
	background: var(--pkb-bg);
	text-align: center;
	line-height: 1.25;
	cursor: pointer;
	transition: border-color .15s ease, box-shadow .15s ease;
}

.pkb-tier input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.pkb-tier:hover {
	border-color: var(--pkb-accent);
}

.pkb-tier.is-selected {
	border-color: var(--pkb-accent);
	box-shadow: inset 0 0 0 1px var(--pkb-accent);
}

/* Focus rings for the keyboard only: a mouse click must not look like a
   second selection. Older browsers without :has() ring on any focus. */
.pkb-tier:has(input:focus-visible) {
	outline: 2px solid var(--pkb-accent);
	outline-offset: 2px;
}

@supports not selector(:has(*)) {
	.pkb-tier:focus-within {
		outline: 2px solid var(--pkb-accent);
		outline-offset: 2px;
	}
}

.pkb-tier__badge {
	position: absolute;
	top: 0;
	left: 50%;
	transform: translate(-50%, -55%);
	padding: 2px 9px;
	border-radius: 999px;
	background: var(--pkb-save);
	color: #fff;
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: .05em;
	text-transform: uppercase;
	white-space: nowrap;
}

.pkb-tier__label {
	font-weight: 600;
	font-size: 15px;
}

.pkb-tier__save {
	font-size: 13px;
	font-weight: 600;
	color: var(--pkb-save);
}

.pkb-tier__sub {
	font-size: 13px;
	color: var(--pkb-muted);
}

/* Crossed out when the pack cannot be assembled from the stock left. */
.pkb-tier.is-oos {
	cursor: not-allowed;
	color: var(--pkb-muted);
	border-color: var(--pkb-line);
	box-shadow: none;
	background: #fafafa;
}

.pkb-tier.is-oos::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: linear-gradient(to top right, transparent calc(50% - .75px), var(--pkb-line) 50%, transparent calc(50% + .75px));
	pointer-events: none;
}

.pkb-tier.is-oos .pkb-tier__badge {
	background: var(--pkb-muted);
}

.pkb-tier__oos {
	font-size: 11.5px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
}

/* A tile that runs out after an add keeps its markup; only the label swaps. */
.pkb-tier.is-oos .pkb-tier__save,
.pkb-tier.is-oos .pkb-tier__sub {
	display: none;
}

/* Per-item pickers ------------------------------------------------------ */

.pkb__builder {
	margin-top: 16px;
	padding: 4px 14px;
	border: 1px solid var(--pkb-line);
	border-radius: var(--pkb-radius);
}

.pkb__builder[hidden] {
	display: none;
}

.pkb__builder-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 10px 0 6px;
	font-size: 13px;
	font-weight: 600;
}

.pkb__same {
	padding: 0;
	border: 0;
	background: none;
	color: var(--pkb-ink);
	font: inherit;
	font-weight: 500;
	text-decoration: underline;
	text-underline-offset: 2px;
	cursor: pointer;
}

.pkb__same[disabled] {
	color: var(--pkb-muted);
	text-decoration: none;
	cursor: default;
}

.pkb-unit {
	display: grid;
	grid-template-columns: 26px 1fr;
	gap: 10px;
	align-items: start;
	padding: 10px 0;
	border-top: 1px solid var(--pkb-line);
}

.pkb-unit__n {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	margin-top: 4px;
	border-radius: 50%;
	background: #f2f2f1;
	font-size: 12px;
	font-weight: 700;
}

/* Add was pressed with this item still unchosen. */
.pkb-unit.is-missing .pkb-unit__n {
	background: var(--pkb-error);
	color: #fff;
}

.pkb-unit.is-missing .pkb-chip:not(.is-disabled) {
	border-color: var(--pkb-error);
}

.pkb-unit__attrs {
	display: grid;
	gap: 6px;
	min-width: 0;
}

.pkb-unit__attr {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.pkb-chip {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 42px;
	height: 34px;
	padding: 0 10px;
	border: 1px solid var(--pkb-line);
	border-radius: 8px;
	background: var(--pkb-bg);
	font-size: 13px;
	cursor: pointer;
	user-select: none;
}

.pkb-chip input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.pkb-chip:hover {
	border-color: var(--pkb-accent);
}

.pkb-chip.is-selected {
	background: var(--pkb-accent);
	border-color: var(--pkb-accent);
	color: #fff;
}

.pkb-chip:has(input:focus-visible) {
	outline: 2px solid var(--pkb-accent);
	outline-offset: 1px;
}

@supports not selector(:has(*)) {
	.pkb-chip:focus-within {
		outline: 2px solid var(--pkb-accent);
		outline-offset: 1px;
	}
}

.pkb-chip.is-disabled {
	opacity: .4;
	text-decoration: line-through;
	cursor: not-allowed;
}

.pkb-chip.is-disabled:hover {
	border-color: var(--pkb-line);
}

/* Kept from the product form while a pack is chosen (e.g. a size guide). */
.pkb__extras {
	margin-top: 12px;
}

.pkb__extras[hidden] {
	display: none;
}

/* Summary and button ---------------------------------------------------- */

.pkb__summary {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 6px 12px;
	margin-top: 16px;
}

.pkb__summary[hidden] {
	display: none;
}

.pkb__price {
	display: flex;
	align-items: baseline;
	gap: 4px;
}

.pkb__unit-price {
	font-size: 24px;
	font-weight: 700;
	color: var(--pkb-save);
}

.pkb__per {
	font-size: 14px;
	color: var(--pkb-muted);
}

.pkb__totals {
	font-size: 18px;
}

.pkb__totals del {
	margin-right: 4px;
	color: var(--pkb-muted);
	font-size: 15px;
}

.pkb__totals ins {
	text-decoration: none;
	font-weight: 700;
}

.pkb__saving {
	flex-basis: 100%;
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--pkb-save);
}

.pkb__add {
	display: block;
	width: 100%;
	min-height: 52px;
	margin-top: 16px;
	padding: 0 20px;
	border: 0;
	border-radius: var(--pkb-radius);
	background: var(--pkb-accent);
	color: #fff;
	font: inherit;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: opacity .15s ease;
}

.pkb__add[hidden] {
	display: none;
}

.pkb__add:hover {
	opacity: .9;
}

.pkb__add:focus-visible {
	outline: 2px solid var(--pkb-accent);
	outline-offset: 3px;
}

.pkb__add[disabled] {
	opacity: .5;
	cursor: not-allowed;
}

.pkb__add.is-loading {
	cursor: progress;
}

.pkb__status {
	margin: 10px 0 0;
	font-size: 13.5px;
	min-height: 1em;
}

.pkb__status:empty {
	margin: 0;
	min-height: 0;
}

.pkb__status.is-error {
	color: var(--pkb-error);
}

.pkb__status a {
	color: inherit;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* Mix & match sets ------------------------------------------------------- */

.pkb-set-card {
	margin: 22px 0;
	padding: 16px;
	border: 1px solid var(--pkb-line);
	border-radius: var(--pkb-radius);
	background: var(--pkb-bg);
	color: var(--pkb-ink);
}

.pkb-set-card__title {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
}

.pkb-set-card__sub {
	margin: 2px 0 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--pkb-save);
}

.pkb-set-card__items {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 16px;
	margin: 12px 0 14px;
	padding: 0;
	list-style: none;
}

.pkb-set-card__item {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	font-size: 13px;
}

.pkb-set-card__item img {
	width: 44px;
	height: 44px;
	object-fit: contain;
	border-radius: 8px;
	background: #f2f2f1;
}

.pkb-set-card__toggle {
	display: block;
	width: 100%;
	min-height: 44px;
	padding: 0 16px;
	border: 1px solid var(--pkb-accent);
	border-radius: var(--pkb-radius);
	background: var(--pkb-bg);
	color: var(--pkb-accent);
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
}

.pkb-set-card__toggle:focus-visible {
	outline: 2px solid var(--pkb-accent);
	outline-offset: 3px;
}

.pkb-set-card > .pkb--set {
	margin: 16px 0 0;
}

/* The card already frames the builder: no second frame inside it. */
.pkb-set-card .pkb__builder {
	padding: 0;
	border: 0;
}

.pkb--set[hidden],
.pkb-unit__attr[hidden] {
	display: none;
}

.pkb-slot + .pkb-slot {
	margin-top: 4px;
	border-top: 1px solid var(--pkb-line);
}

/* Product names are longer than sizes: let them wrap. */
.pkb-chip--product {
	height: auto;
	min-height: 34px;
	padding: 6px 10px;
	white-space: normal;
	text-align: left;
}

/* Pack mode: the single-unit form steps aside ---------------------------- */

.pkb.is-pack ~ form.cart,
form.cart.pkb-form-hidden {
	display: none !important;
}

@media (prefers-reduced-motion: reduce) {
	.pkb-tier,
	.pkb__add {
		transition: none;
	}
}

@media (max-width: 480px) {
	.pkb__tiers {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	/* Six sizes (XS–XXL) on one line per item at 375px. */
	.pkb__builder {
		padding: 4px 12px;
	}

	.pkb-set-card {
		padding: 12px;
	}

	.pkb-unit {
		grid-template-columns: 24px 1fr;
		gap: 8px;
	}

	.pkb-unit__n {
		width: 24px;
		height: 24px;
		margin-top: 5px;
	}

	.pkb-unit__attr {
		gap: 5px;
	}

	.pkb-chip {
		min-width: 36px;
		padding: 0 7px;
	}

	.pkb__unit-price {
		font-size: 21px;
	}
}
