/**
 * WhiteTip Fixed Bundle — front-end styles.
 *
 * Deliberately restrained. This runs inside somebody else's theme, so it sets
 * layout and state and leaves typography, colour and button styling to the theme.
 * Everything is scoped under .wtfxb- so nothing leaks.
 *
 * @package WhiteTip\FixedBundle
 * @since   1.0.0
 */

.wtfxb-bundle {
	margin: 0 0 1.5em;
}

.wtfxb-bundle__head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5em 1em;
	margin: 0 0 1em;
}

.wtfxb-bundle__instruction {
	margin: 0;
	font-weight: 600;
}

.wtfxb-bundle__counter {
	margin: 0;
	font-variant-numeric: tabular-nums;
	opacity: 0.7;
}

.wtfxb-bundle__hint {
	flex: 1 0 100%;
	margin: 0;
	font-size: 0.9em;
	opacity: 0.7;
}

.wtfxb-form.is-complete .wtfxb-bundle__counter {
	opacity: 1;
	font-weight: 600;
}

/* Choices
   ------------------------------------------------------------------------- */

.wtfxb-choices {
	/*
	 * The narrowest a choice may get before the grid drops a column. It is a custom
	 * property so a theme can retune the density with one declaration instead of
	 * rewriting the track list — and because the hardening block at the foot of this
	 * file marks grid-template-columns !important, which would otherwise make it
	 * unreachable. A custom property resolves whatever the importance of the
	 * declaration that reads it.
	 */
	--wtfxb-choice-min: 150px;

	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--wtfxb-choice-min, 150px), 1fr));
	gap: 1em;
	margin: 0 0 1.5em;
	padding: 0;
}

.wtfxb-choice {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 0.75em;
	border: 1px solid rgba(0, 0, 0, 0.12);
	border-radius: 4px;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.wtfxb-choice.is-selected {
	border-color: currentColor;
	box-shadow: inset 0 0 0 1px currentColor;
}

.wtfxb-choice__body {
	flex: 1 1 auto;
	margin: 0 0 0.6em;
}

/* Quantity stepper
   ------------------------------------------------------------------------- */

.wtfxb-qty {
	display: flex;
	align-items: stretch;
	align-self: flex-start;
	border: 1px solid rgba(0, 0, 0, 0.18);
	border-radius: 3px;
	overflow: hidden;
}

.wtfxb-qty__step {
	min-width: 2em;
	margin: 0;
	padding: 0.25em 0.5em;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	line-height: 1.4;
	cursor: pointer;
}

.wtfxb-qty__step:hover:not([disabled]) {
	background: rgba(0, 0, 0, 0.06);
}

/*
 * Dimmed, not hidden. A control that disappears at the limit makes the interface look
 * broken; one that is visibly unavailable explains itself.
 */
.wtfxb-qty__step[disabled] {
	opacity: 0.35;
	cursor: not-allowed;
}

.wtfxb-qty__input {
	width: 3em;
	margin: 0;
	padding: 0.25em;
	border: 0;
	border-left: 1px solid rgba(0, 0, 0, 0.18);
	border-right: 1px solid rgba(0, 0, 0, 0.18);
	border-radius: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	text-align: center;
	font-variant-numeric: tabular-nums;
	-moz-appearance: textfield;
	appearance: textfield;
}

/*
 * The native spinners are removed because the two buttons already do that job, and a
 * spinner inside a 3em box is a target nobody hits on a phone. The input keeps its
 * keyboard behaviour: arrow keys still step it.
 */
.wtfxb-qty__input::-webkit-outer-spin-button,
.wtfxb-qty__input::-webkit-inner-spin-button {
	margin: 0;
	-webkit-appearance: none;
	appearance: none;
}

.wtfxb-choice__media {
	display: block;
	margin: 0 0 0.6em;
}

.wtfxb-choice__media img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: 2px;
}

.wtfxb-choice__title {
	display: block;
	font-size: 0.9em;
	line-height: 1.35;
}

/* Actions
   ------------------------------------------------------------------------- */

.wtfxb-bundle__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75em;
}

.wtfxb-submit[disabled],
.wtfxb-submit[aria-disabled="true"] {
	opacity: 0.5;
	cursor: not-allowed;
}

/* Cart and checkout
   ------------------------------------------------------------------------- */

.wtfxb-cart-selection {
	margin: 0;
	padding: 0 0 0 1em;
}

.wtfxb-cart-selection li {
	margin: 0;
	list-style: disc;
}

/* The focus ring is never removed. It is the only thing a keyboard user has. */
.wtfxb-qty__input:focus-visible,
.wtfxb-qty__step:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: -2px;
}

/* Theme hardening
   -------------------------------------------------------------------------
 * Everything above is ordinary CSS and a theme is welcome to win against it:
 * colour, spacing, typography and borders are the theme's business, and a
 * plugin that fought for them would look foreign on every site it ran on.
 *
 * This block is different. It covers the handful of declarations that are not
 * decoration but *structure* — if a theme wins these, the control stops working
 * rather than merely looking different, and the customer gets one product per
 * row and a quantity box the width of the page.
 *
 * `!important` is used deliberately and only here. Raising specificity would not
 * do: page-builder themes build their selectors around an id, and an id outranks
 * any number of classes. `#Content ul` is 1-0-1 and beats
 * `.wtfxb-form .wtfxb-bundle .wtfxb-choices` at 0-3-0 — and would still beat it
 * with ten more classes bolted on. Against an id there are two answers, our own
 * id or this, and an id in a plugin's markup is worse.
 *
 * A site that wants full control can dequeue the `wtfxb-frontend` handle and
 * style the markup from scratch; every element carries a `wtfxb-` class.
 */

.wtfxb-bundle,
.wtfxb-bundle *,
.wtfxb-bundle *::before,
.wtfxb-bundle *::after {
	box-sizing: border-box;
}

/*
 * The form lays itself out. Measured on the client's site, not guessed: the grid was
 * computing a single 269px track inside a 580px product summary, and 269px is exactly
 * one column when the minimum is 150px and the gap is 1em. The grid was right; its
 * container was not.
 *
 * The cause is that page-builder themes make `form.cart` a flex row, which is correct
 * for a simple product — quantity and button on one line — and wrong here, because our
 * form holds one block that owns its own internal layout. Worse, other plugins inject
 * their own children into the add-to-cart form: a honeypot field and an admin-only
 * notice were sitting beside the bundle as flex siblings and taking half its width.
 *
 * `display: block` is therefore not a preference but a correction, and it is scoped to
 * `.wtfxb-form` — no other form on the site is touched.
 */
:is(#wtfxb, .wtfxb-form) {
	display: block !important;
}

/*
 * And the block itself takes the full width whatever the form turns out to be, for the
 * day a plugin wraps the form in a grid instead. `grid-column` is inert outside a grid
 * and `flex` is inert outside a flex container, so all three can be stated at once.
 */
:is(#wtfxb, .wtfxb-form) :is(#wtfxb, .wtfxb-bundle) {
	display: block !important;
	width: 100% !important;
	max-width: 100% !important;
	min-width: 0 !important;
	flex: 1 1 100% !important;
	grid-column: 1 / -1 !important;
}

/*
 * The two structural rules are written through :is(), and the reason is arithmetic.
 *
 * :is() takes the specificity of its most specific argument, so :is(#wtfxb, .wtfxb-choices)
 * counts as an id while still matching on the class alone. Chained, these selectors compute
 * as 2-0-0 — enough to outrank a theme rule carrying one id, which is what a page builder
 * writes. Without it, `#Content ul { display: block !important }` wins on specificity even
 * though both declarations are important, and the grid collapses to a single column.
 *
 * `#wtfxb` is a lever, not a selector. No element in this plugin has an id and none needs
 * one; putting a real id in the markup would be the worse way to buy the same rank, because
 * an id has to be unique and this form can legitimately appear twice on a page.
 *
 * Belt and braces with the markup: the choices are divs with role="list", so the ul rules
 * that caused this do not match in the first place. Either fix alone would do. Together
 * they mean a theme has to target our own class names on purpose to break the layout, and
 * a theme that does that has made a decision rather than an accident.
 */
:is(#wtfxb, .wtfxb-bundle) :is(#wtfxb, .wtfxb-choices) {
	display: grid !important;
	grid-template-columns: repeat(auto-fill, minmax(var(--wtfxb-choice-min, 150px), 1fr)) !important;
	margin-left: 0 !important;
	padding-left: 0 !important;
}

:is(#wtfxb, .wtfxb-bundle) :is(#wtfxb, .wtfxb-choice) {
	display: flex !important;
	flex-direction: column !important;
	float: none !important;
	clear: none !important;
	width: auto !important;
	max-width: none !important;
	margin: 0 !important;

	/*
	 * A grid item's automatic minimum size is its min-content size, not zero. An
	 * oversized image inside the card therefore props the card open against its own
	 * track instead of scaling down inside it. `min-width: 0` is the standard release
	 * valve and it is needed on every grid and flex item that can contain media.
	 */
	min-width: 0 !important;
}

/*
 * The image is the single biggest layout hazard in the card, and on a real shop it is
 * routinely not the size it claims to be.
 *
 * Observed on the client's site: every choice carries
 * `<img width="800" height="800" class="attachment-woocommerce_thumbnail">` pointing at
 * the *full* file, with no srcset. That happens when the `woocommerce_thumbnail` size
 * has never been generated for those attachments — WordPress falls back to the original
 * and keeps the class name, so the markup claims a thumbnail and delivers 800 pixels.
 *
 * Constraining it here is not cosmetic. An image wider than its grid cell overflows the
 * card, and with the automatic minimum size above it can drag the whole track list with
 * it. The base rule already said `width: 100%`; it needs to be unloseable.
 */
:is(#wtfxb, .wtfxb-bundle) :is(#wtfxb, .wtfxb-choice__media) img {
	display: block !important;
	width: 100% !important;
	max-width: 100% !important;
	height: auto !important;
}

.wtfxb-qty {
	display: flex !important;
	align-self: flex-start !important;
	width: auto !important;
	max-width: 100% !important;
	float: none !important;
}

/*
 * `input[type="number"] { width: 100% }` is close to universal in themes built
 * for forms, and it is what turns a three-character box into a full-width one.
 */
.wtfxb-qty__input {
	flex: 0 0 auto !important;
	width: 3em !important;
	min-width: 0 !important;
	max-width: 3em !important;
	height: auto !important;
	margin: 0 !important;
	text-align: center !important;
	float: none !important;
}

.wtfxb-qty__step {
	flex: 0 0 auto !important;
	width: auto !important;
	min-width: 2em !important;
	max-width: none !important;
	height: auto !important;
	margin: 0 !important;
	float: none !important;
	text-transform: none !important;
	letter-spacing: normal !important;
}