/**
 * Custom Elementor Product Grid — the Flavour Grid: live search + a grid of
 * pill buttons, used once an attribute has more options than comfortably
 * fit as plain pills (Card_Pills::render_flavour_grid(), PHP). Reuses
 * .cepg-pill/.cepg-pill-group from product-extras.css for the buttons
 * themselves — this file styles the grid's own chrome (header/preview/
 * search) PLUS (scoped to .cepg-single-picker and .cepg-quickview) the
 * larger two-column card treatment shared by the product page's own picker
 * and the Quick-Add drawer, so a shopper sees the same flavour grid either
 * way. No separate <select> dropdown control exists any more.
 *
 * Collapse-behind-trigger (with a search box inside, once open) is driven
 * by two data attributes Card_Pills::render_flavour_grid() computes
 * server-side, from two separate count thresholds, one per breakpoint —
 * applied identically everywhere this renders (product page, Quick View,
 * the grid), not a per-context special case:
 *   data-cepg-flavour-grid-collapse-desktop  "true" once count > desktop threshold (10)
 *   data-cepg-flavour-grid-collapse-mobile   "true" once count >= mobile threshold (5)
 * Below its breakpoint's threshold, the list just shows open — no trigger,
 * no search box, no scroll cap, everything visible at once. At/above it,
 * the list is collapsed by default; once expanded it caps at a clean 4 full
 * rows with its own scrollbar (so a long list can't make the page/modal
 * arbitrarily tall) and auto-closes again once a flavour is picked
 * (product-flavour-grid.js).
 */

/*
 * Larger rectangular cards (swatch above label, not side-by-side), fixed 2
 * columns — scoped to .cepg-single-picker (the standalone product-page
 * picker) and .cepg-quickview (the Quick-Add drawer, including the
 * "Customers Also Bought" popout), so both match. Only the plain grid/
 * carousel cards keep the compact default .cepg-pill sizing from
 * product-extras.css — that context is width-constrained per column, not
 * a full-width modal/page. Deliberately no viewport-specific overrides
 * here — same card size on mobile and desktop.
 */
:is(.cepg-single-picker, .cepg-quickview) .cepg-flavour-grid .cepg-pill-group {
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
}

:is(.cepg-single-picker, .cepg-quickview) .cepg-flavour-grid .cepg-pill {
	flex-direction: column;
	align-items: flex-start;
	justify-content: center;
	gap: 5px;
	min-height: 56px;
	padding: 9px;
	border-radius: 12px;
	text-align: left;
}

:is(.cepg-single-picker, .cepg-quickview) .cepg-flavour-grid .cepg-pill .cepg-swatch {
	width: 20px;
	height: 20px;
}

:is(.cepg-single-picker, .cepg-quickview) .cepg-flavour-grid .cepg-pill__label {
	font-size: 13px;
	font-weight: 600;
	line-height: 1.25;
}

/*
 * A notify-capable pill (see Card_Pills::render_pill_group()) shows this
 * label instead of relying on the greyed/struck-through card alone to
 * signal it's still clickable. Always in the DOM for a notify-capable pill,
 * shown only while .is-disabled — that class is toggled live by
 * product-variations.js as the shopper changes Size, so this stays correct
 * without any JS DOM changes needed. text-decoration: none stops the card's
 * .is-disabled strike-through line from crossing through it (CSS
 * text-decoration on an ancestor otherwise draws through descendant inline
 * boxes unless they set their own).
 */
.cepg-pill__notify {
	display: none;
	margin-top: -2px;
	text-decoration: none;
	color: var(--cepg-orange);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

.cepg-pill.rf-notify-pill .cepg-pill__notify {
	display: block;
}

.cepg-flavour-grid__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

/* Default: no trigger, panel always open — below either breakpoint's collapse threshold. The two collapse media queries below override both when relevant. */
.cepg-flavour-grid__preview {
	display: none;
}

.cepg-flavour-grid__panel {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

/*
 * Confirmed live on supps.supplementsupply.co.uk: Hello Elementor's own
 * reset.css matches this <input> via `input[type="search"], ... , select,
 * textarea { border: 1px solid #666; border-radius: 3px; padding: .5rem
 * 1rem; }` — a multi-selector rule whose specificity beats a single class,
 * silently winning on border, border-radius AND padding regardless of what
 * this rule (or the --cepg-* vars) set. !important on exactly those three
 * properties is the deliberate, minimal fix (matches the same pattern
 * product-buttons.css already uses for this kind of theme conflict)
 * rather than chasing the theme's specificity with extra ancestor classes.
 */
.cepg-flavour-grid__search {
	width: 100%;
	height: 40px;
	padding: 0 14px !important;
	background: var(--cepg-neutral);
	border: 1px solid var(--cepg-flavour-grid-border, transparent) !important;
	border-radius: var(--cepg-search-radius, var(--cepg-pill-radius, 12px)) !important;
	color: var(--cepg-obsidian);
	font-family: var(--cepg-font);
	font-size: var(--cepg-flavour-grid-font-size, 14px);
}

.cepg-flavour-grid__search:focus-visible {
	border-color: var(--cepg-orange);
	outline: none;
}

/*
 * iOS Safari auto-zooms the whole page on focusing any text input under
 * 16px font-size — the base rule's 14px default triggers it. 16px is
 * Safari's own documented threshold to suppress that zoom; !important
 * since --cepg-flavour-grid-font-size can be set smaller by a merchant
 * and this needs to win regardless, on mobile specifically (desktop's
 * 14px is untouched — no zoom behavior to guard against there).
 */
@media (max-width: 640px) {
	.cepg-flavour-grid__search {
		font-size: 16px !important;
	}
}

/*
 * The search box (and the scroll cap below) are only relevant once this
 * field is actually collapsible on the CURRENT breakpoint. It's rendered in
 * the DOM whenever EITHER breakpoint's threshold wants it (server-side PHP
 * can't know the viewport — see Card_Pills::render_flavour_grid()), so a
 * mid-size list (e.g. 7 options: past the mobile threshold of 5, short of
 * the desktop one of 10) needs it hidden again specifically on the
 * breakpoint that doesn't need it.
 */
@media (min-width: 641px) {
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="false"] .cepg-flavour-grid__search {
		display: none;
	}
}

@media (max-width: 640px) {
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="false"] .cepg-flavour-grid__search {
		display: none;
	}
}

.cepg-flavour-grid__no-results {
	margin: 12px 0 0;
	color: var(--cepg-muted);
	font-size: 13px;
	text-align: center;
}

/* product-flavour-grid.js toggles this on a pill whose label doesn't match the live search query. */
.cepg-pill.is-search-hidden {
	display: none;
}

/*
 * Mobile collapse-behind-trigger — only once
 * data-cepg-flavour-grid-collapse-mobile="true" (count >= the mobile
 * threshold, 5 by default). Below that, the list stays open on mobile too
 * (the base rules above already do that by default). product-flavour-grid.js
 * reveals the panel (and hides the preview) by adding .is-expanded to the
 * field wrapper when the preview is tapped.
 */
@media (max-width: 640px) {
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__preview {
		display: flex;
		align-items: center;
		gap: 8px;
		width: 100%;
		height: var(--cepg-pill-min-height, 44px);
		padding: 0 14px;
		background: var(--cepg-neutral);
		border: 1.5px solid transparent;
		border-radius: var(--cepg-pill-radius, 12px);
		color: var(--cepg-obsidian);
		font-family: var(--cepg-font);
		font-size: var(--cepg-pill-font-size, 13px);
		font-weight: 600;
		cursor: pointer;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__preview[aria-expanded="true"] {
		border-color: var(--cepg-orange);
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__preview [data-cepg-flavour-grid-preview-label] {
		flex: 1 1 auto;
		min-width: 0;
		overflow: hidden;
		text-align: left;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__chevron {
		flex: 0 0 auto;
		width: 16px;
		height: 16px;
		fill: none;
		stroke: var(--cepg-obsidian);
		stroke-width: 2;
		stroke-linecap: round;
		stroke-linejoin: round;
		transition: transform 0.2s ease;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__preview[aria-expanded="true"] .cepg-flavour-grid__chevron {
		transform: rotate(180deg);
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__panel {
		display: none;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"].is-expanded .cepg-flavour-grid__panel {
		display: flex;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"].is-expanded .cepg-flavour-grid__preview {
		display: none;
	}

	/*
	 * Capped + scrollable once actually expanded — an uncapped 40+ item grid
	 * would make the page/modal extremely long. Reveals a clean 4 full rows
	 * (no partial cut-off row) at whichever card height is active in this
	 * context; overflow-y: auto reaches everything beyond that by scrolling,
	 * so the last item is always reachable, never permanently clipped.
	 */
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"].is-expanded .cepg-flavour-grid__scroll {
		max-height: calc( 4 * ( var(--cepg-pill-min-height, 44px) + var(--cepg-pill-gap, 10px) ) - var(--cepg-pill-gap, 10px) );
		overflow-y: auto;
		overscroll-behavior: contain;
	}

	:is(.cepg-single-picker, .cepg-quickview) .cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"].is-expanded .cepg-flavour-grid__scroll {
		max-height: calc( 4 * ( 56px + 10px ) - 10px );
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-mobile="true"] .cepg-flavour-grid__header {
		flex-direction: column;
		align-items: stretch;
	}
}

/*
 * Desktop collapse-behind-trigger — same mechanism as mobile above, own
 * threshold (data-cepg-flavour-grid-collapse-desktop="true", count > the
 * desktop threshold, 10 by default). Below that, the list stays open on
 * desktop too (the base rules above already do that by default).
 */
@media (min-width: 641px) {
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__preview {
		display: flex;
		align-items: center;
		gap: 8px;
		width: 100%;
		height: var(--cepg-pill-min-height, 44px);
		padding: 0 14px;
		background: var(--cepg-neutral);
		border: 1.5px solid transparent;
		border-radius: var(--cepg-pill-radius, 12px);
		color: var(--cepg-obsidian);
		font-family: var(--cepg-font);
		font-size: var(--cepg-pill-font-size, 13px);
		font-weight: 600;
		cursor: pointer;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__preview[aria-expanded="true"] {
		border-color: var(--cepg-orange);
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__preview [data-cepg-flavour-grid-preview-label] {
		flex: 1 1 auto;
		min-width: 0;
		overflow: hidden;
		text-align: left;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__chevron {
		flex: 0 0 auto;
		width: 16px;
		height: 16px;
		fill: none;
		stroke: var(--cepg-obsidian);
		stroke-width: 2;
		stroke-linecap: round;
		stroke-linejoin: round;
		transition: transform 0.2s ease;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__preview[aria-expanded="true"] .cepg-flavour-grid__chevron {
		transform: rotate(180deg);
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__panel {
		display: none;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"].is-expanded .cepg-flavour-grid__panel {
		display: flex;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"].is-expanded .cepg-flavour-grid__preview {
		display: none;
	}

	/*
	 * Capped + scrollable once actually expanded — an uncapped 40+ item grid
	 * would make the page/modal extremely long. Reveals a clean 4 full rows
	 * (no partial cut-off row) at whichever card height is active in this
	 * context; overflow-y: auto reaches everything beyond that by scrolling,
	 * so the last item is always reachable, never permanently clipped.
	 */
	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"].is-expanded .cepg-flavour-grid__scroll {
		max-height: calc( 4 * ( var(--cepg-pill-min-height, 44px) + var(--cepg-pill-gap, 10px) ) - var(--cepg-pill-gap, 10px) );
		overflow-y: auto;
		overscroll-behavior: contain;
	}

	/*
	 * 82px per row, not the base 56px — a notify-capable pill (out-of-stock
	 * flavour, .rf-notify-pill/cwg_popup_submit, added later) renders a
	 * second "Notify Me" line under the flavour name, so a row containing
	 * one is taller than a plain in-stock pill. Sized for that taller case
	 * so a row of notify pills doesn't get clipped, confirmed live at
	 * 80.6px actual rendered pill height.
	 */
	.cepg-single-picker .cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"].is-expanded .cepg-flavour-grid__scroll {
		max-height: calc( 4 * ( 82px + 10px ) - 10px );
	}

	/*
	 * The Quick-Add drawer (.cepg-quickview) now fills the full viewport
	 * height (.cepg-modal__panel above) instead of hugging its content, and
	 * .cepg-quickview > .cepg-variations is already the drawer's one
	 * scrollable region (flex: 1 1 auto; overflow-y: auto — product-
	 * quickview.css) covering Size pills and the Flavour grid together. A
	 * second, independently-capped scrollbar nested inside that would just
	 * be a redundant/confusing double-scroll, so here the list has no cap
	 * of its own — it renders at full natural height and lets the drawer's
	 * one outer scroll region reach every flavour instead.
	 */
	.cepg-quickview .cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"].is-expanded .cepg-flavour-grid__scroll {
		max-height: none;
		overflow-y: visible;
	}

	.cepg-flavour-grid[data-cepg-flavour-grid-collapse-desktop="true"] .cepg-flavour-grid__header {
		flex-direction: column;
		align-items: stretch;
	}
}

/* Give the stock notifier the foreground when it opens from a flavour sheet. */
body .swal2-container:has(.cwginstock-subscribe-form) {
	z-index: 100050 !important;
}

:is(.cepg-modal, .rf-product-page) .cepg-flavour-grid .cepg-pill:not(.rf-notify-pill) .cepg-pill__notify {
	display: none !important;
}

html body :is(.cepg-modal, .rf-product-page) .rf-fl-inline .cepg-pill.is-disabled:not(.is-search-hidden) {
	display: flex !important;
}
html body .rf-product-page .rf-fl-inline .rf-fl-sold {
	display: none !important;
}
html body :is(.cepg-modal, .rf-product-page) .rf-fl-inline .cepg-pill.rf-notify-pill:not(.is-search-hidden) {
	display: grid !important;
	grid-template-columns: auto minmax(0, 1fr);
	gap: 4px 9px;
}
html body :is(.cepg-modal, .rf-product-page) .rf-fl-inline .cepg-pill.rf-notify-pill .cepg-pill__notify {
	grid-column: 2;
	margin: 0;
}
html body :is(.cepg-modal, .rf-product-page) .cepg-pill.rf-notify-pill {
	opacity: 1;
	cursor: pointer;
}
html body :is(.cepg-modal, .rf-product-page) .cepg-pill.rf-notify-pill .cepg-pill__notify {
	color: #a44100 !important;
}
html body :is(.cepg-modal, .rf-product-page) .cepg-pill.rf-notify-pill:focus-visible {
	outline: 2px solid #ff6b00 !important;
	outline-offset: 2px;
}

/* The existing product panel still supplies the sold-out status and explanation. */
.rf-oos-box:has(+ .cepg-stock-alerts) .rf-oos-box__btn {
	display: none;
}

.cepg-stock-alerts {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 0;
	padding: 0;
}
.cepg-stock-alerts li {
	margin: 0;
}
.cepg-quickview .cepg-stock-alerts {
	padding-bottom: 14px;
	min-height: 0;
	overflow-y: auto;
}
.cepg-stock-alerts .cepg-stock-alert {
	width: 100%;
	min-height: 48px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	padding: 10px 14px;
	border: 1px solid #e0e2e5;
	border-radius: 10px;
	background: #fff;
	color: #101214;
	font: 400 15px/1.3 Outfit, sans-serif;
	text-align: left;
}
.cepg-stock-alert strong {
	flex: 0 0 auto;
	color: #a44100;
	font-size: 12px;
	font-weight: 600;
}
.cepg-stock-alerts .cepg-stock-alert:hover,
.cepg-stock-alerts .cepg-stock-alert:focus-visible {
	border-color: #ff6b00;
}
