/**
 * 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.
 */
.upline-facets,
.upline-facets-layout {
	--upline-gap: 1.25rem;
	--upline-column: 16rem;

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

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

	--upline-accent: var(--wp--preset--color--primary, var(--wp--preset--color--contrast, currentColor));
	--upline-radius: var(--wp--custom--border--radius, 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. */
.upline-facet__swatch--unknown {
	background-image: linear-gradient(135deg, #e6e6e6 0 50%, #cfcfcf 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.
 */
@media (min-width: 783px) {
	.upline-facets__mobile-toggle {
		display: none !important;
	}

	.upline-facets__panel {
		display: block !important;
	}
}

/* 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;
	}

	.upline-facets__panel {
		display: none;
		margin-top: 1rem;
	}

	.upline-facets__switch:checked ~ .upline-facets__form .upline-facets__panel {
		display: block;
	}

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

/* Provide the utility ourselves; not every theme ships it. */
.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;
}
