/* ---------------------------------------------------------------------------
 * Bundle & Save multiselect dropdown (Extra Product Options checkbox group)
 *
 * Scoped by the EPO builder "Element class name" `bundle-multiselect`, which
 * renders as `.bundle-multiselect-div` on the element wrapper and
 * `.bundle-multiselect-ul` on the option list (tm-builder-element-start.php
 * appends -div / -ul to each class token).
 *
 * The EPO markup is never altered: js/epo-bundle-multiselect.js prepends a
 * single `.bms-trigger` into `.tc-element-container` (which otherwise only
 * holds the `ul`), and the `ul` itself becomes the overlay panel. Open/close
 * is driven purely by `:focus-within` on the wrapper — the native checkboxes
 * stay in the tab order and are never cloned or moved.
 *
 * Visual target: the Warranty <select> (app.css `.tm-epo-field.tmcp-select`)
 * — 44px height, 1px border, 8px radius, 16px inset, right chevron.
 *
 * @package SpinfireSport
 */

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

.tm-extra-product-options .bundle-multiselect-div .tc-element-container {
	display: block; /* trigger stacks above; the ul positions against this box */
	position: relative; /* belt & braces — .tc-cell/.tc-expand already set it */
}

/* --- Trigger (injected; collapsed state) --------------------------------- */

.tm-extra-product-options .bundle-multiselect-div .bms-trigger {
	position: relative;
	display: flex;
	align-items: center;
	width: 100%;
	height: 44px;
	padding: 0 44px 0 16px; /* right inset clears the 14px chevron at right:16px */
	box-sizing: border-box;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	background: #fff;
	color: var(--black); /* "Please select" + collapsed count (was inherit) */
	font: inherit;
	text-align: left;
	cursor: pointer;
	-webkit-user-select: none;
	user-select: none;
}

.tm-extra-product-options .bundle-multiselect-div .bms-trigger:focus-visible {
	outline: 2px solid var(--violet);
	outline-offset: 2px;
}

.tm-extra-product-options .bundle-multiselect-div .bms-trigger__text {
	flex: 1 1 auto;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Chevron — same technique as the Warranty select chevron (app.css) */
.tm-extra-product-options .bundle-multiselect-div .bms-trigger::after {
	content: '';
	position: absolute;
	top: 50%;
	right: 16px;
	transform: translateY(-50%) rotate(90deg); /* pointing down while collapsed */
	display: inline-block;
	width: 14px;
	height: 14px;
	mask-image: url(../images/chevron-right.svg);
	mask-repeat: no-repeat;
	mask-position: center;
	mask-size: contain;
	background: var(--black);
	color: transparent;
	pointer-events: none;
	transition: transform 0.15s ease;
}

/* --- Panel (the EPO ul): closed by default ------------------------------- */

.tm-extra-product-options .bundle-multiselect-div .tc-element-container ul.bundle-multiselect-ul {
	display: none;
}

/* --- Panel: open while the wrapper contains focus ------------------------ */

.tm-extra-product-options
	.bundle-multiselect-div
	.tc-element-container:focus-within
	ul.bundle-multiselect-ul {
	position: absolute;
	top: 100%;
	left: 0;
	z-index: 100;
	display: block;
	width: 100%;
	margin: 0;
	padding: 6px 0;
	box-sizing: border-box;
	background: #fff;
	border: 1px solid var(--border-color);
	border-top: 0; /* shared line = the trigger's bottom border */
	border-radius: 0 0 8px 8px;
	max-height: min(60vh, 320px);
	overflow-x: hidden;
	overflow-y: auto;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* Open trigger: square bottom corners so field + panel read as one box, and a
 * black border matching the native select's :active/:focus outline
 * (app.css: outline: 1px solid var(--black)) so both controls signal the
 * active state the same way. */
.tm-extra-product-options .bundle-multiselect-div .tc-element-container:focus-within .bms-trigger {
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
	border-color: var(--black);
}

/* Open panel continues the black outline; border-top stays transparent — the
 * trigger's bottom border is the shared seam (matches border-top:0 above). */
.tm-extra-product-options .bundle-multiselect-div .tc-element-container:focus-within ul.bundle-multiselect-ul {
	border-color: var(--black);
	border-top-color: transparent;
}

/* --- Rows ---------------------------------------------------------------- */

.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul li.tmcp-field-wrap {
	display: flex;
	width: 100%;
	box-sizing: border-box;
	align-items: center;
	justify-content: flex-start; /* plugin centres rows — we left-align */
	gap: var(--tcinnergap);
	margin: 0;
	cursor: pointer;
	transition: background-color 0.12s ease;
	/* min-height + padding live on the <label> below: the whole row —
	 * padding included — must be the label, so any click inside it activates
	 * the checkbox and keeps :focus-within (the panel) open. The li box
	 * still equals the label box, so the hover/selected tint stays
	 * edge-to-edge. */
}

.tm-extra-product-options
	.bundle-multiselect-div
	ul.bundle-multiselect-ul
	li.tmcp-field-wrap
	.tmcp-field-wrap-inner {
	display: flex;
	flex: 1 1 auto;
	min-width: 0;
	max-width: 100%;
	align-items: center;
	justify-content: flex-start;
	gap: var(--tcinnergap);
}

.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul .tc-field-label-wrap,
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul .tc-label {
	flex: 1 1 auto;
	min-width: 0;
}

/* The label owns the row metrics (moved off the li): it fills the row via
 * the flex chain, so its padding/min-height cover the entire clickable
 * area. display:flex keeps the content vertically centred in the 44px box
 * (the li's align-items:center no longer centres *within* the label). */
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul label.tm-epo-field-label {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	min-height: 44px; /* ≥44px touch target */
	padding: 0 16px;
}

/* Name left, price right (overrides the plugin's auto/auto/1fr grid) */
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul .tc-label-inner {
	display: flex;
	width: 100%;
	align-items: center;
	justify-content: space-between;
	gap: var(--tcinnergap);
}

.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul .tc-label-text {
	flex: 1 1 auto;
	min-width: 0;
}

.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul .tc-price-wrap {
	flex: 0 0 auto;
	margin-left: auto;
	padding-left: 8px;
}

/* Hover first; the selected rules below win on equal specificity */
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul li.tmcp-field-wrap:hover {
	background: rgb(0 0 0 / 0.04);
}

/* Selected rows — target the li: the plugin forces background:none on
 * .tc-label for checked rows, and EPO maintains .tc-active on the li. */
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul li.tmcp-field-wrap:has(input:checked),
.tm-extra-product-options .bundle-multiselect-div ul.bundle-multiselect-ul li.tmcp-field-wrap.tc-active {
	background: var(--dark-gray);
	background: color-mix(in srgb, var(--violet) 8%, transparent);
}

/* --- Single-product colour + font parity ----------------------------------
 * Only on single-product.php: body.single-product scope (belt) on top of the
 * asset group's is_product() enqueue gate (braces).
 *
 * 1. The native <select> (Warranty + Bundle & Save) must show its selected
 *    value in --black. WooCommerce sets color: var(--wc-form-color-text,#000)
 *    but the theme never defines that var, and iOS ignores it in favour of
 *    the system blue tint — -webkit-text-fill-color overrides that.
 * 2. Custom trigger and native select must be the same size, following the
 *    custom select. Both declare font-size: inherit, so both track the EPO
 *    chain up to body { font-size:10pt } and stay equal by construction. */
body.single-product .tm-extra-product-options .bundle-multiselect-div .bms-trigger {
	font-size: inherit;
}

body.single-product .tm-extra-product-options .tm-epo-field.tmcp-select {
	color: var(--black);
	-webkit-text-fill-color: var(--black);
	font-size: inherit;
}

/* iOS: gravity-form.css has an @supports (-webkit-touch-callout: none) block
 * forcing select { font-size: 16px !important } on WebKit only, which beats
 * the font-size: inherit above and leaves the native select 16px while the
 * custom trigger stays 10pt. Match it on the trigger so both controls are the
 * same size on iOS; 16px also keeps the select above iOS's focus-zoom
 * threshold (that is why gravity-form.css does it). !important is required
 * to win against its !important. Desktop never matches this @supports, so it
 * is unaffected. */
@supports (-webkit-touch-callout: none) {
	body.single-product .tm-extra-product-options .bundle-multiselect-div .bms-trigger,
	body.single-product .tm-extra-product-options .tm-epo-field.tmcp-select {
		font-size: 16px !important;
	}
}
