/* ==========================================================================
 * Everything below is inside @layer upline.
 *
 * This is the ownership line made structural rather than habitual. By the
 * cascade specification, a normal declaration in ANY layer loses to an
 * unlayered one, whatever the selectors say -- so a theme's plain
 * `.upline-menu__link { color: red }` beats anything in here without needing
 * to out-specify it, and a theme author never has to count our classes or
 * reach for !important to restyle a surface.
 *
 * The reverse holds for important declarations: layered !important beats
 * unlayered !important. So the few guards that genuinely must not lose --
 * the breakpoint that keeps navigation off a click, the visually-hidden
 * utility, reduced motion -- get *stronger* here, not weaker. That asymmetry
 * is the reason this is the right mechanism and not merely a tidy one: it
 * makes feel a theme's to take and mechanics ours to keep, by construction
 * rather than by everybody remembering.
 *
 * Browser floor: @layer is Safari 15.4+, Chrome/Edge 99+, Firefox 97+ (all
 * March 2022). Below that the whole block is dropped as an unknown at-rule
 * and the surface renders unstyled -- which is why the floor is stated in the
 * release notes rather than left to be discovered.
 * ========================================================================== */

@layer upline {

/* ------------------------------------------------------------------------
 * The motion gate: one place, so reduced motion cannot drift.
 *
 * These three are internal plumbing, not tokens -- they are not in
 * docs/theme-tokens.md and a theme has no business setting them. They exist
 * because the reduced-motion guard used to be a second copy of the component
 * selector list, and the two copies had already drifted: the base motion
 * declaration covered ten selectors, the guard covered three, so seven
 * surfaces kept moving for someone who had asked their operating system for
 * stillness. That is the doc's strongest promise broken by a list nobody
 * remembered to grow.
 *
 * A gate declared once at :root and consumed by every component declaration
 * cannot drift, because there is no second list to forget. Adding a surface
 * gets reduced motion for free.
 *
 * :root works here precisely because nothing re-declares these -- the same
 * inheritance rule that makes a shop's `:root { --upline-* }` override fail is
 * what makes this reach every surface.
 * ------------------------------------------------------------------------ */

:root {
	--upline-motion-permitted: var(--wp--custom--upline--motion-duration, 0s);
	--upline-menu-transform-permitted: var(--wp--custom--upline--menu-hidden-transform, translateY(-8px));
	--upline-drawer-transform-permitted: var(--wp--custom--upline--drawer-hidden-transform, translateY(-4px));
}

@media (prefers-reduced-motion: reduce) {
	/*
	 * !important audit: stays. A shop that has asked for less movement gets it
	 * whatever theme it wears, and a theme cannot opt out. Three declarations
	 * in one place, replacing six spread across two files and two selector
	 * lists.
	 */
	:root {
		--upline-motion-permitted: 0s !important;
		--upline-menu-transform-permitted: none !important;
		--upline-drawer-transform-permitted: none !important;
	}
}
/**
 * Upline Facets.
 *
 * Deliberately quiet: the rail borrows the theme's font and colours through
 * currentColor and inherited type, and only asserts layout and state. Themes
 * vary wildly and a filter rail that fights them looks worse than one that
 * blends in.
 *
 * The mobile collapse is a checkbox, not JavaScript, so it works before the
 * script loads and if the script never loads.
 */

/**
 * Theme inheritance.
 *
 * Nothing here sets a font, a text colour or a background. Type is inherited,
 * and every line, muted label and accent is derived from the colour the theme
 * has already put on the page (currentColor), so the rail reads as part of a
 * light theme and a dark one without knowing which it is in.
 *
 * Where a block theme has published its global palette we use it. Override any
 * of these variables from a child theme to take over.
 */
/*
 * The rail reads the same theme.json tokens as every other surface.
 *
 * It did not until 1.13.0: this block hard-coded its values and read no
 * settings.custom.upline.* at all, so "set the tokens once and every Upline
 * component follows" was false for the largest surface a theme has. A theme
 * that set `accent` got it on the menu, the tiles and the chips, and not on
 * the rail -- which reads as the plugin ignoring the theme, and whose only
 * remedy was the selector fight the tokens exist to prevent.
 *
 * The rail's own numbers stay as its defaults. They are denser than the shared
 * ones on purpose -- a filter rail carries more in less room than a menu does
 * -- so what changes is only that a theme can now say otherwise.
 */
.upline-facets,
.upline-facets-layout {
	--upline-gap: var(--wp--custom--upline--gap, 1.25rem);
	--upline-column: var(--wp--custom--upline--column, 16rem);

	/* rgba first as the fallback for browsers without color-mix. */
	--upline-rule: rgba(128, 128, 128, 0.32);
	--upline-rule: var(--wp--custom--upline--rule, color-mix(in srgb, currentColor 22%, transparent));

	--upline-muted: rgba(128, 128, 128, 0.9);
	--upline-muted: var(--wp--custom--upline--muted, color-mix(in srgb, currentColor 65%, transparent));

	--upline-accent: var(--wp--custom--upline--accent, var(--wp--preset--color--primary, var(--wp--preset--color--contrast, currentColor)));
	--upline-radius: var(--wp--custom--upline--radius, var(--wp--custom--border--radius, 4px));

	/* Never smaller than a fingertip; the rail is mostly tap targets. */
	--upline-tap: var(--wp--custom--upline--tap, 44px);

	/* Motion; see components.css for why the duration defaults to zero. */
	--upline-motion-duration: var(--upline-motion-permitted, 0s);
	--upline-motion-easing: var(--wp--custom--upline--motion-easing, ease-out);
	--upline-drawer-hidden-transform: var(--upline-drawer-transform-permitted, translateY(-4px));
}

.upline-facets {
	margin: 0 0 var(--upline-gap);

	/* Inherited deliberately: font family, weight and colour all come from the
	   theme. Only the scale is nudged, so a filter list does not shout. */
	font-size: 0.95em;
	color: inherit;
}

/* Let the theme's own accent colour drive the native controls. */
.upline-facets input[type="checkbox"] {
	accent-color: var(--upline-accent);
}

.upline-facets *,
.upline-facets *::before,
.upline-facets *::after {
	box-sizing: border-box;
}

/* Two-column layout ------------------------------------------------------ */

.upline-facets-layout {
	display: flex;
	align-items: flex-start;
	gap: clamp(1.5rem, 4vw, 2.5rem);
	width: 100%;
}

.upline-facets-layout--right {
	flex-direction: row-reverse;
}

.upline-facets-layout__rail {
	flex: 0 0 clamp(13rem, 22%, var(--upline-column));
	max-width: 100%;
	position: sticky;
	top: var(--wp-admin--admin-bar--height, 0px);
	padding-top: 1rem;
	margin-top: -1rem;
}

/* min-width:0 is what stops a product grid from forcing the rail off the page. */
.upline-facets-layout > .upline-facets-results {
	flex: 1 1 auto;
	min-width: 0;
}

.upline-facets-layout .upline-facets {
	margin-bottom: 0;
}

/* Themes commonly float or centre the loop; inside a flex column neither is
   wanted, and a floated grid would escape the column entirely. */
.upline-facets-layout > .upline-facets-results::after {
	content: "";
	display: table;
	clear: both;
}

/* The mobile switch itself is never visible and never submitted (it has no name). */
.upline-facets__switch {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.upline-facets__mobile-toggle {
	display: none;
	align-items: center;
	gap: 0.5rem;
	padding: 0.7rem 1rem;
	border: 1px solid var(--upline-rule);
	border-radius: 4px;
	cursor: pointer;
	font-weight: 600;
}

.upline-facets__mobile-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 1.6em;
	height: 1.6em;
	padding: 0 0.4em;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-size: 0.75em;
	font-variant-numeric: tabular-nums;
}

.upline-facets__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.75rem;
}

.upline-facets__heading {
	margin: 0;
	font-size: 1.1em;
}

.upline-facets__clear {
	font-size: 0.85em;
}

.upline-facets__hint {
	margin: 1rem 0 0;
	color: var(--upline-muted);
	font-size: 0.8em;
	line-height: 1.4;
}

/* Active filter chips ---------------------------------------------------- */

.upline-facets__active {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin: 0 0 1rem;
	padding: 0;
	list-style: none;
}

.upline-facets__chip {
	margin: 0;
}

.upline-facets__chip a {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	padding: 0.25em 0.6em;
	border: 1px solid var(--upline-rule);
	border-radius: 999px;
	font-size: 0.85em;
	line-height: 1.6;
	text-decoration: none;
}

.upline-facets__chip a:hover,
.upline-facets__chip a:focus {
	border-color: currentColor;
}

.upline-facets__chip-x {
	font-size: 1.15em;
	line-height: 1;
	opacity: 0.7;
}

/* Facets ----------------------------------------------------------------- */

.upline-facet {
	margin: 0 0 var(--upline-gap);
	padding: 0 0 var(--upline-gap);
	border: 0;
	border-bottom: 1px solid var(--upline-rule);
}

.upline-facet:last-of-type {
	border-bottom: 0;
	padding-bottom: 0;
}

.upline-facet__title {
	margin: 0 0 0.6rem;
	padding: 0;
	font-size: 0.8em;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.upline-facet__options {
	margin: 0;
	padding: 0;
	list-style: none;
}

.upline-facet__option {
	position: relative;
	margin: 0 0 0.15rem;
	padding: 0;
	list-style: none;
}

.upline-facet__input {
	position: absolute;
	top: 0.55em;
	left: 0;
	margin: 0;
}

.upline-facet__label {
	display: flex;
	align-items: center;
	gap: 0.5em;
	padding: 0.25em 0 0.25em 1.65em;
	cursor: pointer;
	line-height: 1.4;
}

.upline-facet__name {
	flex: 1 1 auto;
}

.upline-facet__count {
	flex: 0 0 auto;
	color: var(--upline-muted);
	font-size: 0.85em;
	font-variant-numeric: tabular-nums;
}

/* Zero-result options: visible but plainly unavailable. Nobody should be able
   to click their way into an empty result set. */
.upline-facet__option.is-disabled .upline-facet__label {
	cursor: not-allowed;
	opacity: 0.45;
}

/* Overflow --------------------------------------------------------------- */

.upline-facet__option--overflow {
	display: none;
}

.upline-facet.is-expanded .upline-facet__option--overflow {
	display: block;
}

.upline-facet__more {
	margin-top: 0.35rem;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: 0.85em;
	text-decoration: underline;
}

.upline-facet__more-hide {
	display: none;
}

.upline-facet.is-expanded .upline-facet__more-show {
	display: none;
}

.upline-facet.is-expanded .upline-facet__more-hide {
	display: inline;
}

/* Swatches --------------------------------------------------------------- */

.upline-facet__options--swatch {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.upline-facet__options--swatch .upline-facet__option {
	margin: 0;
}

.upline-facet__options--swatch .upline-facet__input {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.upline-facet__options--swatch .upline-facet__label {
	flex-direction: column;
	gap: 0.25em;
	width: 3.25rem;
	padding: 0.25rem;
	border: 1px solid transparent;
	border-radius: 4px;
	text-align: center;
}

.upline-facet__options--swatch .upline-facet__name {
	flex: 0 0 auto;
	font-size: 0.72em;
	line-height: 1.2;
	overflow-wrap: anywhere;
}

.upline-facet__options--swatch .upline-facet__count {
	font-size: 0.7em;
}

.upline-facet__swatch {
	display: block;
	width: 2rem;
	height: 2rem;
	border: 1px solid var(--upline-rule);
	border-radius: 50%;
	background-color: transparent;
}

/*
 * A colour we could not resolve gets a neutral disc, never a wrong one.
 *
 * Derived from currentColor rather than drawn in light greys: the hard
 * #e6e6e6 / #cfcfcf it used to carry was the only real light-ground assumption
 * in the storefront stylesheets, and on a dark theme it rendered as a bright
 * patch on the rail. rgba first, for browsers without color-mix.
 */
.upline-facet__swatch--unknown {
	background-image: linear-gradient(135deg, rgba(128, 128, 128, 0.22) 0 50%, rgba(128, 128, 128, 0.38) 50% 100%);
	background-image: linear-gradient(
		135deg,
		color-mix(in srgb, currentColor 14%, transparent) 0 50%,
		color-mix(in srgb, currentColor 26%, transparent) 50% 100%
	);
}

.upline-facet__input:checked + .upline-facet__label {
	border-color: currentColor;
	font-weight: 600;
}

.upline-facet__input:focus-visible + .upline-facet__label {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* Range ------------------------------------------------------------------ */

.upline-facet__range {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	flex-wrap: wrap;
}

.upline-facet__range-field {
	display: inline-flex;
	align-items: center;
	gap: 0.2em;
	flex: 1 1 5rem;
	min-width: 0;
}

.upline-facet__currency {
	color: var(--upline-muted);
	font-size: 0.9em;
}

.upline-facet__number {
	width: 100%;
	min-width: 0;
	padding: 0.35em 0.4em;
	border: 1px solid var(--upline-rule);
	border-radius: 3px;
	font: inherit;
	font-size: 0.9em;
}

.upline-facet__range-sep {
	color: var(--upline-muted);
}

.upline-facet__range-go {
	flex: 0 0 auto;
	padding: 0.35em 0.7em;
	border: 1px solid var(--upline-rule);
	border-radius: 3px;
	background: none;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: 0.85em;
}

/* Apply button: only needed when the script is not driving things. */
.upline-facets__actions {
	margin-top: 1rem;
}

.upline-facets.is-enhanced:not(.is-manual) .upline-facets__actions,
.upline-facets.is-enhanced .upline-facet__range-go {
	display: none;
}

/* Loading ---------------------------------------------------------------- */

.upline-facets.is-loading .upline-facets__panel,
.upline-facets-results.is-loading {
	opacity: 0.55;
	transition: opacity 120ms ease-out;
}

.upline-facets-results.is-loading {
	pointer-events: none;
}

/* Desktop: always visible, no exceptions ---------------------------------- */

/*
 * Exposed filtering is the entire product. The brief is explicit that the rail
 * is always visible on desktop and collapsible only on mobile, so this is
 * stated as a rule that cannot lose rather than left to the cascade: themes
 * that carry declarations like `.woocommerce label { display: inline-block
 * !important }` will otherwise reveal the mobile toggle on a full-width screen
 * and put the filters behind a click.
 *
 * !important audit: stays, for the reason above -- a breakpoint defended
 * against a third party's !important. The drawer's open and close state below
 * carries none.
 */
@media (min-width: 783px) {
	.upline-facets__mobile-toggle {
		display: none !important;
	}

	.upline-facets__panel {
		display: block;
	}
}

/* Mobile ----------------------------------------------------------------- */

@media (max-width: 782px) {
	.upline-facets-layout,
	.upline-facets-layout--right {
		display: block;
	}

	.upline-facets-layout__rail {
		position: static;
		margin: 0 0 1.5rem;
		padding-top: 0;
	}

	.upline-facets__mobile-toggle {
		display: inline-flex;
	}

	/*
	 * The filter drawer is the same shape of problem as the menu drawer and
	 * gets the same treatment: in flow, so it collapses with grid rows rather
	 * than merely fading, and animatable so a theme can give it the same feel
	 * it gives the menu. It shares the motion tokens deliberately -- a shop
	 * whose menu and filters open differently looks broken, not characterful.
	 */
	.upline-facets__panel {
		display: grid;
		grid-template-rows: 0fr;
		margin-top: 1rem;

		opacity: 0;
		visibility: hidden;
		pointer-events: none;
		transform: var(--upline-drawer-hidden-transform, translateY(-4px));

		transition:
			grid-template-rows var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			opacity var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			transform var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			visibility 0s linear var(--upline-motion-duration, 0s);
	}

	.upline-facets__panel > .upline-facets__panel-inner {
		min-height: 0;
		overflow: hidden;
	}

	.upline-facets__switch:checked ~ .upline-facets__form .upline-facets__panel,
	.upline-facets__panel[data-upline-open] {
		grid-template-rows: 1fr;
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
		transform: none;
		transition:
			grid-template-rows var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			opacity var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			transform var(--upline-motion-duration, 0s) var(--upline-motion-easing, ease-out),
			visibility 0s linear 0s;
	}

	.upline-facets__switch:checked ~ .upline-facets__form .upline-facets__panel > .upline-facets__panel-inner {
		overflow: visible;
	}

	.upline-facets__options--swatch {
		gap: 0.75rem;
	}
}

/*
 * Provide the utility ourselves; not every theme ships it.
 *
 * !important audit: this one stays. A visually-hidden label that a theme's
 * `position: relative` wins against stops being visually hidden, and dumps
 * screen-reader text into the middle of the page. It is defending a rule
 * against being broken, not winning a stylistic argument, and there is no
 * specificity that survives an incoming `!important` from a theme.
 */
.upline-facets .screen-reader-text,
.upline-facets-results .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}


/* ------------------------------------------------------------------------
 * Reduced motion is the plugin's job, not the theme's
 *
 * A shop that has asked its operating system for less movement must get it
 * whatever theme it is wearing, and accessibility that depends on every theme
 * author remembering is accessibility that fails. So this is stated as a rule
 * that cannot lose.
 *
 * It neutralises the token rather than each animated property: every
 * transition in this file reads --upline-motion-duration, so zeroing it once
 * stops all of them, including any added later. That is one !important
 * instead of a list that would need maintaining, and it still leaves a theme
 * free to choose the motion that shoppers who have not asked for less will
 * see. `!important` on a custom property is the only way to make it something
 * a theme cannot outrank, which is the point.
 * ------------------------------------------------------------------------ */

}
