/*
 * Conector O.P. — product configurator styles.
 *
 * Namespaced BEM under `.opc-` (ARCHITECTURE §1, §13). This stylesheet must look
 * native in an unstyled theme and must NOT depend on, or restyle, any theme class.
 * Everything is expressed through CSS custom properties so a theme can retune the
 * palette by overriding a handful of `--opc-*` tokens without touching selectors.
 *
 * Colours are contrast-safe and light/dark-agnostic: the token block below sets a
 * light default and a `prefers-color-scheme: dark` override, plus an explicit
 * `[data-opc-theme]` escape hatch. No framework, no build step — shipped as authored.
 *
 * ## Every selector here matches something the templates render
 *
 * The class names below are exactly those emitted by `templates/configurator/*.php`,
 * plus the four state modifiers the JavaScript toggles (`.opc-option--checked`,
 * `.opc-option--disabled`, `.opc-summary--loading`, `.opc-summary--error`). A rule for a
 * class no template writes is dead weight that reads as coverage, so there are none.
 *
 * ## Why the layout rules are scoped to `.opc-configurator[data-opc-root]`
 *
 * The configurator renders INSIDE the WooCommerce add-to-cart form, so a theme rule like
 * `.woocommerce div.product form.cart label { display:block; margin:0 0 .5em; }`
 * (specificity 0,3,3) applies to every option tile. A bare `.opc-option` (0,1,0) — and
 * even `.opc-configurator .opc-option` (0,2,0) — loses that cascade and the tile grid
 * collapses into stacked labels, in precisely the themes merchants actually run.
 *
 * Rules that own geometry are therefore written against the mount point plus the group
 * container: `.opc-configurator[data-opc-root] .opc-group__options .opc-option` scores
 * (0,4,0) and wins outright, without a single `!important`. Purely cosmetic rules stay at
 * one or two classes so a theme can still retune colour and type.
 *
 * ## The two things this file buys the shopper
 *
 * 1. **Every option group is a `<details>` disclosure.** A product with eight groups is
 *    eight one-line rows, each stating its own answer, until one is opened. The controls
 *    inside are the same real radios they always were — only the container changed.
 * 2. **The price panel is sticky.** It is the same `[data-opc-summary]` element, given
 *    `position: sticky` and a compact two-row bar layout, so there is still exactly one
 *    price node in the document. It pins to the top, never the bottom, because
 *    WooCommerce's add-to-cart button is directly below the configurator.
 *
 * Both degrade to the previous layout rather than to a broken one: a browser without
 * `<details>` support shows every group expanded, and an ancestor that cancels sticky
 * positioning leaves the panel in flow at the top of the configurator.
 *
 * ## Themes style `details`, `summary`, `fieldset` and `legend` hard
 *
 * The default disclosure triangle is suppressed three ways over (`list-style`,
 * `::-webkit-details-marker`, and a flex `<summary>`) because each covers a different
 * engine, and the `<fieldset>` carries `min-width: 0` because a fieldset's default
 * `min-inline-size: min-content` otherwise stops the tile grid shrinking on a phone.
 */

.opc-configurator {
	/* Palette + geometry tokens. Override these, not the rules. */

	/*
	 * The configurator's own unit, used everywhere a size would otherwise be in `rem`.
	 * Some themes shrink the page's root font — OceanWP sets `html { font-size: 62.5% }` —
	 * and a configurator measured in `rem` shrank with it to 10 px type. This unit is the
	 * root font when that is a normal size, and never less than 16 px, so a visitor who
	 * enlarged their browser's text still gets larger text and a theme cannot make it tiny.
	 */
	--opc-rem: max(1rem, 16px);

	--opc-bg: #ffffff;
	--opc-surface: #f6f7f9;
	--opc-surface-hover: #eceef1;
	--opc-border: #cdd2d9;
	--opc-border-strong: #9aa2ad;
	--opc-text: #1d2733;
	--opc-text-muted: #5b6672;
	--opc-accent: #1f5eff;
	--opc-accent-contrast: #ffffff;
	--opc-accent-soft: rgba(31, 94, 255, 0.10);
	--opc-danger: #b42318;
	--opc-danger-soft: rgba(180, 35, 24, 0.10);
	--opc-focus: #1f5eff;
	--opc-radius: 10px;
	--opc-radius-sm: 7px;
	--opc-gap: calc(0.75 * var(--opc-rem, 1rem));
	--opc-tile-min: calc(6.5 * var(--opc-rem, 1rem));

	/* How far below the viewport top the sticky total bar parks. A theme with its own
	   fixed header overrides this one value instead of unsticking the bar. */
	--opc-sticky-top: 0px;

	color: var(--opc-text);
	/*
	 * Block, deliberately NOT grid. `position: sticky` can only move a box inside its own
	 * containing block, and a grid item's containing block is its grid area — which, in an
	 * auto-sized row, is exactly the item's own height. As a grid item the price bar would
	 * have nowhere to travel and would never pin. In normal flow its containing block is
	 * this whole element, so it rides the full height of the option groups below it.
	 */
	display: block;
	max-width: calc(46 * var(--opc-rem, 1rem));
	font-size: calc(1 * var(--opc-rem, 1rem));
	line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
	.opc-configurator {
		--opc-bg: #14181d;
		--opc-surface: #1c222a;
		--opc-surface-hover: #232b35;
		--opc-border: #39424e;
		--opc-border-strong: #596573;
		--opc-text: #eef1f5;
		--opc-text-muted: #a7b0bc;
		--opc-accent: #6f9bff;
		--opc-accent-contrast: #0b1017;
		--opc-accent-soft: rgba(111, 155, 255, 0.16);
		--opc-danger: #ff9a8f;
		--opc-danger-soft: rgba(255, 154, 143, 0.14);
		--opc-focus: #6f9bff;
	}
}

/* Explicit override wins over the media query in both directions. */
.opc-configurator[data-opc-theme="light"] {
	--opc-bg: #ffffff;
	--opc-surface: #f6f7f9;
	--opc-surface-hover: #eceef1;
	--opc-border: #cdd2d9;
	--opc-text: #1d2733;
	--opc-text-muted: #5b6672;
	--opc-accent: #1f5eff;
	--opc-accent-contrast: #ffffff;
	--opc-accent-soft: rgba(31, 94, 255, 0.10);
}

.opc-configurator[data-opc-theme="dark"] {
	--opc-bg: #14181d;
	--opc-surface: #1c222a;
	--opc-surface-hover: #232b35;
	--opc-border: #39424e;
	--opc-text: #eef1f5;
	--opc-text-muted: #a7b0bc;
	--opc-accent: #6f9bff;
	--opc-accent-contrast: #0b1017;
	--opc-accent-soft: rgba(111, 155, 255, 0.16);
}

/* ---- Wrapper furniture --------------------------------------------------- */

.opc-configurator[data-opc-root] .opc-configurator__groups {
	display: grid;
	/* Collapsed groups are single rows; a wide gap would make eight of them look like
	   eight unrelated panels instead of one list. */
	gap: calc(0.5 * var(--opc-rem, 1rem));
	margin-top: calc(0.85 * var(--opc-rem, 1rem));
}

/* Shown when `article_options` could not be reached: the shopper is seeing fewer
   choices than the product really has, and must be told so. */
.opc-configurator[data-opc-root] .opc-configurator__notice {
	margin: 0 0 calc(0.85 * var(--opc-rem, 1rem));
	padding: calc(0.6 * var(--opc-rem, 1rem)) calc(0.8 * var(--opc-rem, 1rem));
	font-size: calc(0.88 * var(--opc-rem, 1rem));
	color: var(--opc-text);
	background: var(--opc-surface);
	border: 1px dashed var(--opc-border-strong);
	border-radius: var(--opc-radius-sm);
}

/* Staff-only supplier-cost diagnostic; never rendered for a shopper (§7.3). */
.opc-configurator[data-opc-root] .opc-configurator__diagnostics {
	margin: calc(0.85 * var(--opc-rem, 1rem)) 0 0;
	font-size: calc(0.82 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator__cost {
	font-variant-numeric: tabular-nums;
}

/* ---- Print file ---------------------------------------------------------- */

/*
 * Where the shopper attaches the artwork. It sits between the options and WooCommerce's
 * buy button — the last decision before paying — and is styled as one more panel of the
 * configurator rather than a bare browser file input, which every OS renders differently
 * and none render like the rest of this form.
 */
.opc-configurator[data-opc-root] .opc-artwork {
	margin-top: calc(0.85 * var(--opc-rem, 1rem));
	padding: calc(0.8 * var(--opc-rem, 1rem)) calc(0.9 * var(--opc-rem, 1rem));
	background: var(--opc-surface);
	border: 1px solid var(--opc-border);
	border-radius: var(--opc-radius-sm);
}

.opc-configurator[data-opc-root] .opc-artwork__label {
	display: block;
	font-weight: 600;
	color: var(--opc-text);
}

.opc-configurator[data-opc-root] .opc-artwork__optional {
	margin-left: calc(0.35 * var(--opc-rem, 1rem));
	font-weight: 400;
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-artwork__input {
	display: block;
	width: 100%;
	margin-top: calc(0.55 * var(--opc-rem, 1rem));
	/* A file input cannot be restyled inside, so the box around it is what carries the
	   configurator's look; `max-width` keeps a long file name from widening the panel. */
	max-width: 100%;
	font-size: calc(0.92 * var(--opc-rem, 1rem));
	color: var(--opc-text);
}

.opc-configurator[data-opc-root] .opc-artwork__input::file-selector-button {
	margin-right: calc(0.6 * var(--opc-rem, 1rem));
	padding: calc(0.4 * var(--opc-rem, 1rem)) calc(0.75 * var(--opc-rem, 1rem));
	font: inherit;
	color: var(--opc-text);
	background: var(--opc-bg);
	border: 1px solid var(--opc-border-strong);
	border-radius: var(--opc-radius-sm);
	cursor: pointer;
}

.opc-configurator[data-opc-root] .opc-artwork__input::file-selector-button:hover {
	background: var(--opc-surface-hover);
}

.opc-configurator[data-opc-root] .opc-artwork__input:focus-visible {
	outline: 2px solid var(--opc-accent);
	outline-offset: 2px;
}

.opc-configurator[data-opc-root] .opc-artwork__hint {
	margin: calc(0.5 * var(--opc-rem, 1rem)) 0 0;
	font-size: calc(0.82 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

/* ---- Option groups: one collapsible disclosure each ---------------------- */

/*
 * Each group is a `<details>` whose `<summary>` states the group's own answer, so a
 * product with eight groups is eight lines until one is opened. `overflow: hidden` is
 * load-bearing, not cosmetic: it clips the summary's square hover background to the
 * group's rounded corners, which saves computing a second radius for the open state.
 */
.opc-configurator[data-opc-root] .opc-configurator__groups .opc-group {
	margin: 0;
	padding: 0;
	overflow: hidden;
	/*
	 * Opening a group with the keyboard scrolls it into view, and the browser has no idea
	 * the total bar is pinned over the top of the viewport. Without this the group the
	 * shopper just opened lands underneath it.
	 */
	scroll-margin-top: calc(var(--opc-sticky-top) + calc(5 * var(--opc-rem, 1rem)));
	background: var(--opc-surface);
	border: 1px solid var(--opc-border);
	border-radius: var(--opc-radius-sm);
}

.opc-configurator[data-opc-root] .opc-configurator__groups .opc-group[open] {
	background: var(--opc-bg);
	border-color: var(--opc-border-strong);
}

/*
 * `<summary>` is already a button: it is keyboard-focusable and toggles on Enter and
 * Space for free, which is why nothing interactive is ever nested inside it. Only the
 * default disclosure triangle is replaced — `list-style` covers modern Chrome and
 * Firefox, `::-webkit-details-marker` covers Safari before 17, and `display: flex`
 * suppresses the marker box outright in the engines that honour it.
 */
.opc-configurator[data-opc-root] .opc-group .opc-group__summary {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	column-gap: calc(0.6 * var(--opc-rem, 1rem));
	row-gap: calc(0.1 * var(--opc-rem, 1rem));
	box-sizing: border-box;
	margin: 0;
	padding: calc(0.65 * var(--opc-rem, 1rem)) calc(0.85 * var(--opc-rem, 1rem));
	/* A 44px row: the whole line is the tap target, not just the words. */
	min-height: calc(2.75 * var(--opc-rem, 1rem));
	color: var(--opc-text);
	list-style: none;
	cursor: pointer;
}

.opc-configurator[data-opc-root] .opc-group .opc-group__summary::-webkit-details-marker {
	display: none;
}

.opc-configurator[data-opc-root] .opc-group .opc-group__summary::marker {
	content: "";
}

.opc-configurator[data-opc-root] .opc-group .opc-group__summary:hover {
	background: var(--opc-surface-hover);
}

/* Inset, so the ring follows the group's rounded border instead of boxing it. */
.opc-configurator[data-opc-root] .opc-group .opc-group__summary:focus-visible {
	outline: 3px solid var(--opc-focus);
	outline-offset: -3px;
}

.opc-configurator[data-opc-root] .opc-group__name {
	flex: 0 0 auto;
	font-weight: 600;
	font-size: calc(0.95 * var(--opc-rem, 1rem));
	color: var(--opc-text);
}

/* The answer, right-aligned against the chevron. It is the prominent half of the line
   while the group is closed — it is the only thing the row is telling the shopper — and
   steps back once the tiles below are showing the same thing. */
.opc-configurator[data-opc-root] .opc-group__chosen {
	flex: 1 1 calc(8 * var(--opc-rem, 1rem));
	min-width: 0;
	text-align: right;
	font-size: calc(0.92 * var(--opc-rem, 1rem));
	font-weight: 500;
	color: var(--opc-text);
	overflow-wrap: anywhere;
}

.opc-configurator[data-opc-root] .opc-group[open] .opc-group__chosen {
	font-weight: 400;
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-group__chosen-suffix {
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-group__marker {
	flex: 0 0 auto;
	align-self: center;
	box-sizing: border-box;
	width: calc(0.5 * var(--opc-rem, 1rem));
	height: calc(0.5 * var(--opc-rem, 1rem));
	margin-bottom: calc(0.15 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.15s ease;
}

.opc-configurator[data-opc-root] .opc-group[open] .opc-group__marker {
	margin-top: calc(0.15 * var(--opc-rem, 1rem));
	margin-bottom: 0;
	transform: rotate(-135deg);
}

/*
 * `min-width: 0` is required, not defensive: a `<fieldset>` defaults to
 * `min-inline-size: min-content`, so without it the tile grid refuses to shrink below
 * its widest tile and the group overflows its own card on a narrow screen.
 */
.opc-configurator[data-opc-root] .opc-group .opc-group__fieldset {
	display: block;
	min-width: 0;
	margin: 0;
	padding: 0 calc(0.85 * var(--opc-rem, 1rem)) calc(0.85 * var(--opc-rem, 1rem));
	background: none;
	border: 0;
}

/*
 * Option tiles wrap; they are not columns of a grid.
 *
 * A fixed grid track gives every tile the same width whatever its label says, so
 * "214 × 320 mm 128 páginas" — a perfectly ordinary format name in this catalogue — broke
 * over three lines inside a calc(6.5 * var(--opc-rem, 1rem)) column while the rest of the row sat empty. Flex with a
 * flex-basis of `--opc-tile-min` keeps the same minimum, and then lets a tile take the width
 * it actually needs: two options share the row, six wrap into rows of three or four.
 *
 * `min-width: 0` on the tile is what allows a long single word to shrink rather than push the
 * row wider than the group, and `overflow-wrap` breaks that word only when it genuinely
 * cannot fit — never mid-word on a label that had room, which is what a blanket
 * `word-break: break-all` would do.
 */
.opc-configurator[data-opc-root] .opc-group__options {
	display: flex;
	flex-wrap: wrap;
	gap: var(--opc-gap);
}

/* The run grid stays a grid: the values are short, equal-width numbers, and a ragged row of
   differently-sized run tiles is harder to scan than a table of them. */
.opc-configurator[data-opc-root] .opc-group--quantity .opc-group__options {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--opc-tile-min), 1fr));
}

.opc-configurator[data-opc-root] .opc-group--quantity {
	--opc-tile-min: calc(6 * var(--opc-rem, 1rem));
}

/* ---- Option tiles -------------------------------------------------------- */

.opc-configurator[data-opc-root] .opc-group__options .opc-option {
	position: relative;
	/* As on the group: tabbing to a tile must not park it under the pinned bar. */
	scroll-margin-top: calc(var(--opc-sticky-top) + calc(5 * var(--opc-rem, 1rem)));
	display: flex;
	flex-direction: column;
	gap: calc(0.2 * var(--opc-rem, 1rem));
	/* Grow into the row, but never force it wider than the group. */
	flex: 1 1 var(--opc-tile-min);
	min-width: 0;
	max-width: 100%;
	overflow-wrap: break-word;
	float: none;
	width: auto;
	margin: 0;
	padding: calc(0.7 * var(--opc-rem, 1rem)) calc(0.85 * var(--opc-rem, 1rem));
	background: var(--opc-surface);
	border: 1px solid var(--opc-border);
	border-radius: var(--opc-radius-sm);
	cursor: pointer;
	transition: border-color 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
	min-height: calc(2.75 * var(--opc-rem, 1rem));
}

.opc-configurator[data-opc-root] .opc-group__options .opc-option:hover {
	background: var(--opc-surface-hover);
	border-color: var(--opc-border-strong);
}

/*
 * The real radio is visually hidden but remains in the a11y + focus tree.
 *
 * `appearance: none` is the load-bearing line, not a tidy-up: it is what removes the native
 * control's *painted parts* — the disc, its ring and, in several engines, a focus or
 * high-contrast outline drawn outside the element's own box. `clip`/`clip-path` shrink the
 * box, and every engine that draws a widget decoration beyond that box paints it anyway, one
 * small dark mark per tile at the tile's top edge. With nothing to draw, there is nothing
 * that can escape the clip, in any engine. The control stays focusable and announced: that
 * is `display: none`'s failure mode, not this one.
 */
.opc-configurator[data-opc-root] .opc-option__input {
	position: absolute;
	appearance: none;
	-webkit-appearance: none;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

.opc-configurator[data-opc-root] .opc-option__label {
	display: block;
	font-weight: 500;
	font-size: calc(0.92 * var(--opc-rem, 1rem));
	color: var(--opc-text);
}

.opc-configurator[data-opc-root] .opc-option__delta {
	display: block;
	font-size: calc(0.82 * var(--opc-rem, 1rem));
	font-variant-numeric: tabular-nums;
	color: var(--opc-text-muted);
}

/*
 * Carries the mount point so it outscores the `display: block` rule above (0,3,0). Written
 * as a bare `.opc-option__delta[hidden]` it scored (0,2,0) and *lost*, so `hidden` was a
 * no-op: a badge that had shown "+6,90 €" kept its row after the surcharge stopped applying,
 * and every tile paid the flex `gap` for an empty box.
 */
.opc-configurator[data-opc-root] .opc-option__delta[hidden] {
	display: none;
}

/* Checked state — driven by :checked AND the JS-applied modifier, so it holds
   even before scripts run and while the store patches. */
.opc-configurator .opc-option__input:checked ~ .opc-option__label,
.opc-configurator .opc-option--checked .opc-option__label {
	color: var(--opc-accent);
}

.opc-configurator[data-opc-root] .opc-group__options .opc-option:has(.opc-option__input:checked),
.opc-configurator[data-opc-root] .opc-group__options .opc-option--checked {
	border-color: var(--opc-accent);
	background: var(--opc-accent-soft);
	box-shadow: inset 0 0 0 1px var(--opc-accent);
}

/* Visible, high-contrast focus ring — keyboard operability is a v1 requirement.
   The :has() rule rings the whole tile; the direct rule is the fallback for
   engines without :has(), where the ring lands on the (hidden) input box. */
.opc-configurator[data-opc-root] .opc-group__options .opc-option:has(.opc-option__input:focus-visible) {
	outline: 3px solid var(--opc-focus);
	outline-offset: 2px;
}

.opc-configurator[data-opc-root] .opc-option__input:focus-visible {
	outline: 3px solid var(--opc-focus);
	outline-offset: 2px;
}

/* Disabled / impossible combinations. */
.opc-configurator[data-opc-root] .opc-group__options .opc-option--disabled,
.opc-configurator[data-opc-root] .opc-group__options .opc-option:has(.opc-option__input:disabled) {
	cursor: not-allowed;
	opacity: 0.45;
	background: var(--opc-surface);
	border-style: dashed;
	box-shadow: none;
}

.opc-configurator[data-opc-root] .opc-group__options .opc-option--disabled:hover {
	background: var(--opc-surface);
	border-color: var(--opc-border);
}

/* ---- Quantity tiles ------------------------------------------------------ */

/* A print run is a number, not prose: centre it, keep the digits aligned and let the
   tile be shorter than a full option tile. The run is the printed quantity, never the
   cart quantity (ARCHITECTURE §8.1). */
.opc-configurator[data-opc-root] .opc-group__options .opc-qty-tile {
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: calc(0.6 * var(--opc-rem, 1rem)) calc(0.5 * var(--opc-rem, 1rem));
	min-height: calc(2.5 * var(--opc-rem, 1rem));
}

.opc-configurator[data-opc-root] .opc-qty-tile__value {
	font-size: calc(1 * var(--opc-rem, 1rem));
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/*
 * What the run costs, under the run and in smaller type — the shop owner's request, and the
 * reason a shopper can compare runs without selecting each one in turn.
 *
 * Every figure here is the server's: the selected run's tile is handed the same `Money` the
 * total panel is rendering, and `view-groups.js` keeps it that way after each quote settles
 * (`ConfiguratorRenderer::runPrices()` records why no other source was acceptable). It is
 * deliberately quieter than the run itself — the run is the choice, the price is the
 * consequence — but it stays at the muted token, which is contrast-safe in both schemes.
 *
 * `:empty` rather than `[hidden]`: the node is always rendered so the browser has somewhere
 * to write, and a run with no price must cost the tile no height at all. The template emits
 * it with no whitespace inside, which is what makes `:empty` match.
 */
.opc-configurator[data-opc-root] .opc-qty-tile__price {
	display: block;
	font-size: calc(0.8 * var(--opc-rem, 1rem));
	font-weight: 500;
	line-height: 1.25;
	font-variant-numeric: tabular-nums;
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-qty-tile__price:empty {
	display: none;
}

/* The chosen run's price is the number in the total bar; say so by giving it the same
   emphasis the rest of the checked tile has. */
.opc-configurator[data-opc-root] .opc-option:has(.opc-option__input:checked) .opc-qty-tile__price,
.opc-configurator[data-opc-root] .opc-option--checked .opc-qty-tile__price {
	color: var(--opc-accent);
}

/* ---- Single-value groups: a fact, not a disclosure ----------------------- */

/*
 * A group offering one value has nothing to choose, so it renders as one plain row rather
 * than a `<details>` that opens onto a single already-checked tile. The control is unchanged
 * — same `<fieldset>`, same hook, same real radio, still submitted — only the disclosure is
 * gone, so the page loses a row that invited a click and answered with nothing.
 *
 * The visible label is a `<span>`, exactly as in the collapsible case, and the `<legend>`
 * stays visually hidden beside it. A `<legend>` is laid out by rules of its own inside a
 * `<fieldset>` and is not reliably a flex item across engines, so making it the visible half
 * of a flex row would have put the label somewhere different in every browser.
 */
.opc-configurator[data-opc-root] .opc-configurator__groups .opc-group--fixed {
	padding: 0;
	background: var(--opc-surface);
}

/* `box-sizing: border-box` so `min-height` is the row's real height, exactly as on a
   `<summary>`: without it the padding is added on top and a fact line stands a fifth taller
   than the collapsed rows it sits between. */
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__fieldset {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	column-gap: calc(0.6 * var(--opc-rem, 1rem));
	row-gap: calc(0.1 * var(--opc-rem, 1rem));
	box-sizing: border-box;
	min-height: calc(2.75 * var(--opc-rem, 1rem));
	padding: calc(0.65 * var(--opc-rem, 1rem)) calc(0.85 * var(--opc-rem, 1rem));
}

/* The value sits where a collapsed group's answer sits: right-aligned, quiet, on the
   same line — so a fixed row and a closed row read as the same kind of statement. */
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options {
	flex: 1 1 calc(8 * var(--opc-rem, 1rem));
	justify-content: flex-end;
	min-width: 0;
}

/*
 * The one tile is not a tile: it is the sentence's second half. It keeps the real radio, so
 * it keeps a focus ring — which is honest, because it is still the control.
 *
 * The checked selectors are repeated here on purpose. `…​.opc-option:has(.opc-option__input:checked)`
 * scores (0,6,0) because `:has()` contributes its argument's specificity, so a plain
 * `.opc-group--fixed …​ .opc-option` at (0,5,0) loses and the row's one always-checked value
 * came out wearing the full selected-tile chrome — a blue box drawn around a fact.
 */
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option,
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option:hover,
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option:has(.opc-option__input:checked),
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option--checked {
	flex: 0 1 auto;
	padding: 0;
	min-height: 0;
	text-align: right;
	font-size: calc(0.92 * var(--opc-rem, 1rem));
	background: none;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	cursor: default;
}

.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option .opc-option__label,
.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option__input:checked ~ .opc-option__label {
	font-weight: 400;
	color: var(--opc-text-muted);
}

/* ---- The sticky total bar (the one and only price panel) ---------------- */

/*
 * This is `[data-opc-summary]` itself, not a second bar with a second copy of the price.
 * `view-summary.js` patches `root.querySelector( '[data-opc-summary]' )` — exactly one
 * node — so a duplicate would drift out of step with the real total the first time a
 * quote settled. Making the existing panel sticky keeps one price and one seam.
 *
 * It pins to the TOP, not the bottom. WooCommerce renders its quantity field and
 * add-to-cart button immediately after the configurator, so a bottom-pinned bar would
 * sit over the buy button on a phone. Pinned to the top it cannot, and because its
 * containing block runs to the end of the configurator it is still on screen at the
 * moment the shopper reaches that button.
 *
 * Degradation is built in: an ancestor with `overflow: hidden` or a `transform` (which
 * some themes put on `form.cart`) cancels stickiness, and the bar simply stays in flow
 * at the top of the configurator — still the right layout, just not pinned.
 *
 * The geometry rules carry `[data-opc-summary]` alongside the class to score (0,4,0), so
 * a theme rule like `.woocommerce div.product form.cart div` (0,3,3) cannot take the
 * layout over.
 */
.opc-configurator[data-opc-root] .opc-summary[data-opc-summary] {
	position: sticky;
	top: var(--opc-sticky-top);
	z-index: 3;
	display: grid;
	/*
	 * A two-row bar, not a stacked card: it is pinned, so every line it occupies is a
	 * line of the shopper's screen it takes away.
	 *
	 *   PRECIO TOTAL          0,22 € / ud
	 *   110,70 €              calculando…
	 *
	 * The status shares a row with the big price instead of reserving a line of its own,
	 * so the bar does not change height when a quote starts.
	 */
	grid-template-columns: auto minmax(0, 1fr);
	grid-template-areas:
		"label unit"
		"price status"
		"retry retry";
	align-items: baseline;
	column-gap: calc(0.75 * var(--opc-rem, 1rem));
	row-gap: calc(0.1 * var(--opc-rem, 1rem));
	margin: 0;
	padding: calc(0.65 * var(--opc-rem, 1rem)) calc(0.9 * var(--opc-rem, 1rem));
	/* Opaque: it scrolls over the option groups. */
	background: var(--opc-bg);
	border: 1px solid var(--opc-border);
	border-radius: var(--opc-radius);
	box-shadow: 0 6px 14px -10px rgba(0, 0, 0, 0.45);
}

.opc-configurator[data-opc-root] .opc-summary:focus-visible {
	outline: 3px solid var(--opc-focus);
	outline-offset: 2px;
}

.opc-configurator[data-opc-root] .opc-summary__label {
	grid-area: label;
	font-size: calc(0.8 * var(--opc-rem, 1rem));
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-summary__price {
	grid-area: price;
	font-size: calc(1.6 * var(--opc-rem, 1rem));
	font-weight: 700;
	line-height: 1.1;
	color: var(--opc-text);
	font-variant-numeric: tabular-nums;
}

.opc-configurator[data-opc-root] .opc-summary__unit {
	grid-area: unit;
	justify-self: end;
	text-align: right;
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
	font-variant-numeric: tabular-nums;
}

.opc-configurator .opc-summary__unit-label {
	opacity: 0.75;
	margin-inline-start: 0.25em;
}

.opc-summary__unit[hidden] {
	display: none;
}

.opc-configurator[data-opc-root] .opc-summary__status {
	grid-area: status;
	justify-self: end;
	margin: 0;
	padding: 0;
	text-align: right;
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

/* Loading: the last good price dims slightly but stays on screen — never hidden,
   never replaced by 0,00 €. */
.opc-configurator .opc-summary--loading .opc-summary__price {
	opacity: 0.55;
}

.opc-configurator .opc-summary--loading .opc-summary__status::before {
	content: "";
	display: inline-block;
	width: 0.7em;
	height: 0.7em;
	margin-right: 0.45em;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	vertical-align: -0.05em;
	animation: opc-spin 0.7s linear infinite;
}

.opc-configurator[data-opc-root] .opc-summary--error {
	border-color: var(--opc-danger);
	background: var(--opc-danger-soft);
}

.opc-configurator .opc-summary--error .opc-summary__status {
	color: var(--opc-danger);
	font-weight: 600;
}

/* A free-format product before its size is typed: an instruction, so it reads as text, not as
   a failure. */
.opc-configurator .opc-summary--prompt .opc-summary__status {
	color: var(--opc-text);
	font-weight: 500;
}

/* The retry button lives inside `form.cart`, where themes style buttons hard. */
.opc-configurator[data-opc-root] .opc-summary .opc-summary__retry[data-opc-retry] {
	grid-area: retry;
	justify-self: start;
	width: auto;
	margin-top: calc(0.35 * var(--opc-rem, 1rem));
	padding: calc(0.45 * var(--opc-rem, 1rem)) calc(0.9 * var(--opc-rem, 1rem));
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	color: var(--opc-accent-contrast);
	background: var(--opc-accent);
	border: 1px solid var(--opc-accent);
	border-radius: var(--opc-radius-sm);
	cursor: pointer;
}

.opc-configurator[data-opc-root] .opc-summary .opc-summary__retry[data-opc-retry]:hover {
	filter: brightness(1.05);
}

.opc-configurator[data-opc-root] .opc-summary .opc-summary__retry[data-opc-retry]:focus-visible {
	outline: 3px solid var(--opc-focus);
	outline-offset: 2px;
}

.opc-summary__retry[hidden] {
	display: none;
}

@keyframes opc-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.opc-configurator .opc-summary--loading .opc-summary__status::before {
		animation: none;
	}

	.opc-configurator[data-opc-root] .opc-group__options .opc-option {
		transition: none;
	}

	.opc-configurator[data-opc-root] .opc-group__marker {
		transition: none;
	}
}

/* ---- Visually-hidden a11y live region ----------------------------------- */

.opc-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 30rem) {
	/*
	 * On a phone an option label is the long half of the tile, so option tiles get the whole
	 * width and wrap one per row. The run grid keeps three columns: run values are short, and
	 * a column of twelve full-width runs would be most of the screen.
	 */
	.opc-configurator[data-opc-root] .opc-group__options .opc-option {
		flex-basis: 100%;
	}

	.opc-configurator[data-opc-root] .opc-group--quantity .opc-group__options {
		grid-template-columns: 1fr 1fr 1fr;
	}

	/* A fact line stays a line: its value must not be pushed onto a row of its own. */
	.opc-configurator[data-opc-root] .opc-group--fixed .opc-group__options .opc-option {
		flex-basis: auto;
	}

	/* The bar keeps its two-row shape on a phone — stacking it would make the pinned
	   element four lines tall, which is most of a small screen. Only the type shrinks. */
	.opc-configurator[data-opc-root] .opc-summary__price {
		font-size: calc(1.35 * var(--opc-rem, 1rem));
	}

	.opc-configurator[data-opc-root] .opc-summary__label {
		font-size: calc(0.7 * var(--opc-rem, 1rem));
	}

	.opc-configurator[data-opc-root] .opc-summary__unit,
	.opc-configurator[data-opc-root] .opc-summary__status {
		font-size: calc(0.78 * var(--opc-rem, 1rem));
	}
}

/* ---------------------------------------------------------------------------
 * Free-format size (templates/configurator/size.php)
 *
 * Two short fields, side by side with a "×" between them, then the range the product
 * accepts and, when there is one, the problem with what was typed. The fields are text
 * inputs with a decimal keyboard, so they are styled here rather than left to the theme's
 * number-input chrome.
 * ------------------------------------------------------------------------- */
.opc-configurator[data-opc-root] .opc-group--size .opc-size {
	display: block;
	box-sizing: border-box;
	padding: calc(0.75 * var(--opc-rem, 1rem)) calc(0.85 * var(--opc-rem, 1rem)) calc(0.8 * var(--opc-rem, 1rem));
	margin: 0;
	border: 0;
	min-width: 0;
}

.opc-configurator[data-opc-root] .opc-size__legend {
	float: left;
	width: 100%;
	padding: 0;
	margin: 0 0 calc(0.55 * var(--opc-rem, 1rem));
}

.opc-configurator[data-opc-root] .opc-size__fields {
	clear: both;
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: calc(0.5 * var(--opc-rem, 1rem)) calc(0.75 * var(--opc-rem, 1rem));
}

.opc-configurator[data-opc-root] .opc-size__field {
	display: flex;
	flex-direction: column;
	gap: calc(0.25 * var(--opc-rem, 1rem));
	flex: 1 1 calc(7 * var(--opc-rem, 1rem));
	max-width: calc(11 * var(--opc-rem, 1rem));
	margin: 0;
}

.opc-configurator[data-opc-root] .opc-size__label {
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-size__control {
	display: flex;
	align-items: center;
	gap: calc(0.4 * var(--opc-rem, 1rem));
}

.opc-configurator[data-opc-root] .opc-size__input {
	box-sizing: border-box;
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	min-height: calc(2.75 * var(--opc-rem, 1rem));
	padding: calc(0.5 * var(--opc-rem, 1rem)) calc(0.65 * var(--opc-rem, 1rem));
	font: inherit;
	font-size: calc(1 * var(--opc-rem, 1rem));
	color: var(--opc-text);
	background: var(--opc-bg);
	border: 1px solid var(--opc-border-strong);
	border-radius: var(--opc-radius-sm);
	box-shadow: none;
}

.opc-configurator[data-opc-root] .opc-size__input:focus-visible {
	outline: 3px solid var(--opc-focus);
	outline-offset: 1px;
	border-color: var(--opc-accent);
}

.opc-configurator[data-opc-root] .opc-size__input[aria-invalid="true"] {
	border-color: var(--opc-danger);
	background: var(--opc-danger-soft);
}

.opc-configurator[data-opc-root] .opc-size__unit {
	flex: 0 0 auto;
	white-space: nowrap;
	font-size: calc(0.9 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-size__times {
	padding-bottom: calc(0.7 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-size__hint {
	margin: calc(0.55 * var(--opc-rem, 1rem)) 0 0;
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	color: var(--opc-text-muted);
}

.opc-configurator[data-opc-root] .opc-size__error {
	margin: calc(0.35 * var(--opc-rem, 1rem)) 0 0;
	font-size: calc(0.85 * var(--opc-rem, 1rem));
	font-weight: 500;
	color: var(--opc-danger);
}

.opc-configurator[data-opc-root] .opc-size__error[hidden] {
	display: none;
}

/*
 * A landscape phone has almost no vertical room, and a pinned bar there would cover the
 * choices it is meant to price. Below that height it goes back into the flow.
 */
@media (max-height: 26rem) {
	.opc-configurator[data-opc-root] .opc-summary[data-opc-summary] {
		position: static;
		box-shadow: none;
	}
}
