/**
 * BW Product Filters
 *
 * Deliberately low-specificity and mostly variable-driven so the theme can
 * restyle it without fighting !important.
 */

.bw-pf {
	--bw-pf-border: #e2e2e2;
	--bw-pf-text: inherit;
	--bw-pf-muted: #767676;
	--bw-pf-accent: #1f1f1f;
	--bw-pf-radius: 3px;
	--bw-pf-swatch-size: 30px;
	--bw-pf-columns: 1;
	--bw-pf-gap: 8px;
	position: relative;
	font-size: 15px;
	line-height: 1.4;
}

.bw-pf.is-loading {
	opacity: 0.6;
	pointer-events: none;
}

/* Header ----------------------------------------------------------------- */

.bw-pf__header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.bw-pf__heading {
	margin: 0;
	font-size: 1.05em;
}

.bw-pf__clear,
.bw-pf__clear-mobile {
	font-size: 0.85em;
	color: var(--bw-pf-muted);
	text-decoration: underline;
}

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

.bw-pf__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0 0 16px;
	padding: 0;
	list-style: none;
}

.bw-pf__chips li {
	margin: 0;
	list-style: none;
}

.bw-pf__chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 8px;
	border: 1px solid var(--bw-pf-border);
	border-radius: var(--bw-pf-radius);
	background: #f6f6f6;
	font-size: 0.8em;
	line-height: 1.2;
	cursor: pointer;
}

.bw-pf__chip:hover {
	border-color: var(--bw-pf-accent);
}

.bw-pf__chip span {
	font-size: 1.15em;
	color: var(--bw-pf-muted);
}

/* Facet -------------------------------------------------------------------*/

.bw-pf__facet {
	padding: 0 0 14px;
	margin: 0 0 14px;
	border-bottom: 1px solid var(--bw-pf-border);
}

.bw-pf__facet:last-child {
	border-bottom: 0;
}

.bw-pf__facet-title {
	margin: 0;
	font-size: 1em;
}

.bw-pf__facet-toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 4px 0;
	border: 0;
	background: none;
	font: inherit;
	font-weight: 600;
	text-align: left;
	cursor: pointer;
	color: var(--bw-pf-text);
}

.bw-pf__facet-arrow {
	width: 8px;
	height: 8px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.15s ease;
	flex: 0 0 auto;
	margin-left: 8px;
}

.bw-pf__facet.is-collapsed .bw-pf__facet-arrow {
	transform: rotate(-45deg);
}

.bw-pf__facet-body {
	padding-top: 8px;
}

/* Option lists ----------------------------------------------------------- */

.bw-pf__options {
	margin: 0;
	padding: 0;
	list-style: none;
	display: grid;
	grid-template-columns: repeat(var(--bw-pf-columns), minmax(0, 1fr));
	gap: var(--bw-pf-gap);
}

.bw-pf__options li {
	margin: 0;
	list-style: none;
}

.bw-pf__option.is-overflow {
	display: none;
}

.bw-pf__options.is-expanded .bw-pf__option.is-overflow {
	display: block;
}

.bw-pf__option label {
	display: block;
	margin: 0;
	cursor: pointer;
}

.bw-pf__option-inner {
	display: flex;
	align-items: center;
	gap: 8px;
}

.bw-pf__option-label {
	flex: 1 1 auto;
}

.bw-pf__count {
	flex: 0 0 auto;
	color: var(--bw-pf-muted);
	font-size: 0.82em;
}

.bw-pf__count::before {
	content: "(";
}

.bw-pf__count::after {
	content: ")";
}

.bw-pf__option.is-empty label {
	opacity: 0.45;
}

.bw-pf__more {
	margin-top: 10px;
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	font-size: 0.85em;
	color: var(--bw-pf-muted);
	text-decoration: underline;
	cursor: pointer;
}

/* Checkbox / radio ------------------------------------------------------- */

/**
 * The label has to be the flex row, not the span inside it.
 *
 * `.bw-pf__option-inner` is `display: flex`, which makes it a *block-level* flex
 * container. Left as the only flex box, it forces a line break after the input
 * and the text drops onto the line below the control. Promoting the label to the
 * flex row puts the input and the text on one line, with the count still pushed
 * right by `.bw-pf__option-label`'s flex-grow.
 *
 * Scoped to these two display types: swatches and buttons visually hide the
 * input and rely on `.bw-pf__option-inner` being the sized box.
 */
.bw-pf__options--checkbox .bw-pf__option label,
.bw-pf__options--radio .bw-pf__option label {
	display: flex;
	align-items: center;
	gap: 8px;
}

.bw-pf__options--checkbox .bw-pf__option-inner,
.bw-pf__options--radio .bw-pf__option-inner {
	flex: 1 1 auto;
	/* Let long option names wrap instead of overflowing the row. */
	min-width: 0;
}

.bw-pf__options--checkbox input,
.bw-pf__options--radio input {
	flex: 0 0 auto;
	width: auto;
	max-width: none;
	margin: 0;
}

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

.bw-pf__options--swatch {
	--bw-pf-columns: none;
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.bw-pf__options--swatch input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.bw-pf__options--swatch .bw-pf__option-inner {
	display: block;
	position: relative;
}

.bw-pf__options--swatch .bw-pf__option-label,
.bw-pf__options--swatch .bw-pf__count {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.bw-pf__swatch {
	display: block;
	width: var(--bw-pf-swatch-size);
	height: var(--bw-pf-swatch-size);
	border: 1px solid var(--bw-pf-border);
	border-radius: 50%;
	background-color: #fff;
	background-size: cover;
	background-position: center;
	box-shadow: inset 0 0 0 2px #fff;
	transition: box-shadow 0.12s ease, border-color 0.12s ease;
}

.bw-pf__options--square .bw-pf__swatch {
	border-radius: var(--bw-pf-radius);
}

.bw-pf__option:hover .bw-pf__swatch {
	border-color: var(--bw-pf-accent);
}

.bw-pf__options--swatch .bw-pf__option.is-selected .bw-pf__swatch,
.bw-pf__options--swatch input:focus-visible + .bw-pf__option-inner .bw-pf__swatch {
	border-color: var(--bw-pf-accent);
	box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--bw-pf-accent);
}

.bw-pf__options--swatch .bw-pf__option.is-empty {
	opacity: 0.35;
}

/* Buttons / labels ------------------------------------------------------- */

.bw-pf__options--button {
	--bw-pf-columns: none;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.bw-pf__options--button input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.bw-pf__options--button .bw-pf__option-inner {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	/* Short size codes stay square-ish; longer labels such as
	   "Traceable British Wool" grow naturally and wrap onto the next row. */
	min-width: 38px;
	padding: 6px 11px;
	border: 1px solid var(--bw-pf-border);
	border-radius: var(--bw-pf-radius);
	justify-content: center;
	font-size: 0.9em;
	line-height: 1.25;
	text-align: center;
	transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.bw-pf__options--button .bw-pf__option:hover .bw-pf__option-inner {
	border-color: var(--bw-pf-accent);
}

/* Keyboard focus, since the real input is visually hidden. */
.bw-pf__options--button input:focus-visible + .bw-pf__option-inner {
	outline: 2px solid var(--bw-pf-accent);
	outline-offset: 2px;
}

.bw-pf__options--button .bw-pf__option.is-selected .bw-pf__option-inner {
	border-color: var(--bw-pf-accent);
	background: var(--bw-pf-accent);
	color: #fff;
}

.bw-pf__options--button .bw-pf__option.is-selected .bw-pf__count {
	color: rgba(255, 255, 255, 0.75);
}

/* Nothing to click through to, so make that legible rather than just faint. */
.bw-pf__options--button .bw-pf__option.is-empty .bw-pf__option-inner {
	opacity: 0.4;
	text-decoration: line-through;
}

/* Dropdown --------------------------------------------------------------- */

.bw-pf__select {
	width: 100%;
	max-width: 100%;
}

/* Price ------------------------------------------------------------------ */

.bw-pf__price-track {
	position: relative;
	height: 30px;
	margin: 4px 0 2px;
}

.bw-pf__price-track::before {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	top: 13px;
	height: 4px;
	border-radius: 2px;
	background: var(--bw-pf-border);
}

.bw-pf__price-fill {
	position: absolute;
	top: 13px;
	height: 4px;
	border-radius: 2px;
	background: var(--bw-pf-accent);
}

.bw-pf__price-range {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 30px;
	margin: 0;
	background: none;
	appearance: none;
	-webkit-appearance: none;
	pointer-events: none;
}

.bw-pf__price-range::-webkit-slider-thumb {
	appearance: none;
	-webkit-appearance: none;
	width: 16px;
	height: 16px;
	border: 1px solid var(--bw-pf-accent);
	border-radius: 50%;
	background: #fff;
	cursor: pointer;
	pointer-events: auto;
}

.bw-pf__price-range::-moz-range-thumb {
	width: 16px;
	height: 16px;
	border: 1px solid var(--bw-pf-accent);
	border-radius: 50%;
	background: #fff;
	cursor: pointer;
	pointer-events: auto;
}

.bw-pf__price-readout {
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: 0.88em;
	color: var(--bw-pf-muted);
}

.bw-pf__price-inputs {
	display: flex;
	align-items: center;
	gap: 6px;
}

.bw-pf__price-inputs input {
	width: 5.5em;
	min-width: 0;
}

/* Stock ------------------------------------------------------------------ */

.bw-pf__stock {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	cursor: pointer;
}

.bw-pf__stock--toggle input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.bw-pf__stock--toggle .bw-pf__stock-visual {
	position: relative;
	flex: 0 0 auto;
	width: 34px;
	height: 20px;
	border-radius: 10px;
	background: var(--bw-pf-border);
	transition: background 0.15s ease;
}

.bw-pf__stock--toggle .bw-pf__stock-visual::after {
	content: "";
	position: absolute;
	top: 2px;
	left: 2px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #fff;
	transition: transform 0.15s ease;
}

.bw-pf__stock--toggle input:checked + .bw-pf__stock-visual {
	background: var(--bw-pf-accent);
}

.bw-pf__stock--toggle input:checked + .bw-pf__stock-visual::after {
	transform: translateX(14px);
}

.bw-pf__stock:not(.bw-pf__stock--toggle) .bw-pf__stock-visual {
	display: none;
}

/* Results ---------------------------------------------------------------- */

.bw-pf-results {
	position: relative;
	min-height: 120px;
	transition: opacity 0.15s ease;
}

.bw-pf-results--loading {
	opacity: 0.45;
}

.bw-pf-results--loading::after {
	content: "";
	position: absolute;
	top: 40px;
	left: 50%;
	width: 28px;
	height: 28px;
	margin-left: -14px;
	border: 2px solid rgba(0, 0, 0, 0.15);
	border-top-color: rgba(0, 0, 0, 0.6);
	border-radius: 50%;
	animation: bw-pf-spin 0.7s linear infinite;
}

@keyframes bw-pf-spin {
	to {
		transform: rotate(360deg);
	}
}

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

.bw-pf__drawer-open,
.bw-pf__drawer-close,
.bw-pf__drawer-actions {
	display: none;
}

@media (max-width: 900px) {
	.bw-pf__drawer-open {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		width: 100%;
		justify-content: center;
		padding: 11px 14px;
		border: 1px solid var(--bw-pf-accent);
		border-radius: var(--bw-pf-radius);
		background: none;
		font: inherit;
		font-weight: 600;
		cursor: pointer;
	}

	.bw-pf__drawer-count {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		min-width: 20px;
		height: 20px;
		padding: 0 5px;
		border-radius: 10px;
		background: var(--bw-pf-accent);
		color: #fff;
		font-size: 0.75em;
	}

	/**
	 * The drawer is a three-row grid: fixed header, scrolling facet list, fixed
	 * action bar.
	 *
	 * The action bar used to be position:absolute with bottom:0 inside a
	 * scrolling form. An absolutely positioned box resolves against its
	 * containing block's padding box, not the visible scrollport, so it sat at
	 * the bottom of the *content* and drifted up over the facets as soon as the
	 * list was scrolled. Laying the panel out as flex rows keeps it pinned
	 * without taking it out of flow.
	 */
	.bw-pf .bw-pf__form {
		display: flex;
		flex-direction: column;
		position: fixed;
		z-index: 100000;
		top: 0;
		right: 0;
		bottom: 0;
		width: min(360px, 90vw);
		max-width: 100vw;
		padding: 0;
		background: #fff;
		box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
		/* Scrolling belongs to the facet list, not the whole panel. */
		overflow: hidden;
		transform: translateX(100%);
		transition: transform 0.22s ease;
		visibility: hidden;
	}

	.bw-pf.is-open .bw-pf__form {
		transform: none;
		visibility: visible;
	}

	.bw-pf.is-open::before {
		content: "";
		position: fixed;
		inset: 0;
		z-index: 99999;
		background: rgba(0, 0, 0, 0.4);
	}

	/* Row 1: header stays put, so "Filter By:" and Clear are always reachable. */
	.bw-pf .bw-pf__header {
		flex: 0 0 auto;
		align-items: center;
		margin: 0;
		padding: 14px 16px;
		border-bottom: 1px solid var(--bw-pf-border);
	}

	.bw-pf .bw-pf__chips {
		flex: 0 0 auto;
		margin: 12px 16px 0;
	}

	/* Row 2: the only scrolling region. min-height:0 is required — a flex item
	   defaults to min-height:auto, which refuses to shrink below its content and
	   would push the action bar off the bottom of the screen. */
	.bw-pf .bw-pf__facets {
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		/* Stop the page behind scrolling once the list hits its end. */
		overscroll-behavior: contain;
		padding: 14px 16px;
	}

	.bw-pf__drawer-close {
		display: block;
		flex: 0 0 auto;
		margin-left: auto;
		padding: 0 4px;
		border: 0;
		background: none;
		font-size: 26px;
		line-height: 1;
		cursor: pointer;
	}

	/* Row 3: action bar, now a normal flex row rather than absolutely placed. */
	.bw-pf .bw-pf__drawer-actions {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		flex: 0 0 auto;
		padding: 12px 16px;
		/* Clear the iOS home indicator. */
		padding-bottom: calc( 12px + env( safe-area-inset-bottom, 0px ) );
		background: #fff;
		border-top: 1px solid var(--bw-pf-border);
	}

	.bw-pf__drawer-apply {
		flex: 1 1 auto;
		padding: 12px 14px;
		border: 0;
		border-radius: var(--bw-pf-radius);
		background: var(--bw-pf-accent);
		color: #fff;
		font: inherit;
		font-weight: 600;
		cursor: pointer;
	}

	/* The desktop "Clear filters" link is redundant next to the drawer's own. */
	.bw-pf .bw-pf__header .bw-pf__clear {
		display: none;
	}

	/* Roomier tap targets on touch. */
	.bw-pf__option-inner {
		min-height: 32px;
	}

	.bw-pf__options--button .bw-pf__option-inner {
		padding: 8px 12px;
	}

	body.bw-pf-drawer-open {
		overflow: hidden;
	}
}
