/**
 * CodeBold Smart Filters — the controls themselves.
 *
 * Split from filters.css, which holds the panel's skeleton, because this is the part a
 * shop is likely to want to restyle: swatches, size chips, the price slider, the applied
 * pills and the phone drawer. Everything still hangs off the same custom properties, so
 * setting four variables restyles both files at once.
 *
 * The shapes are the ones every clothes shop already teaches its customers: a dot for a
 * colour, a box for a size, pills for what you have chosen so far, and on a phone a
 * button that opens the lot rather than a wall of checkboxes above the products.
 */

.codebold-filters-wrap {
	--cbf-ink: var( --codebold-filters-ink, #1b2733 );
	--cbf-soft: var( --codebold-filters-soft, #5c6b79 );
	--cbf-faint: var( --codebold-filters-faint, #93a0ac );
	--cbf-line: var( --codebold-filters-line, #e2e7ec );
	--cbf-accent: var( --codebold-filters-accent, #2f6fed );
	--cbf-surface: var( --codebold-filters-surface, #fff );
	--cbf-radius: var( --codebold-filters-radius, 9px );
}

/* --------------------------------------------------------------- applied pills */

.codebold-pills {
	flex: 1 0 100%;
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	margin: 0 0 4px;
}

.codebold-pill {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	padding: 5px 10px 5px 12px;
	border: 1px solid var( --cbf-line );
	border-radius: 999px;
	background: var( --cbf-surface );
	font-size: 12.5px;
	font-weight: 600;
	line-height: 1.3;
	color: var( --cbf-ink );
	text-decoration: none;
	transition: border-color .12s ease, background .12s ease;
}

.codebold-pill:hover {
	border-color: var( --cbf-accent );
	background: rgba( 47, 111, 237, .06 );
	color: var( --cbf-ink );
}

.codebold-pill-x {
	font-size: 15px;
	line-height: 1;
	color: var( --cbf-faint );
}

.codebold-pill:hover .codebold-pill-x {
	color: var( --cbf-accent );
}

/* --------------------------------------------------------------- group headings */

/*
 * Every group heading, whichever element carries it.
 *
 * A collapsible group renders a <button>; one that cannot collapse renders an <h3>. Only
 * the button was styled, so on any theme that gives headings a size of their own — which
 * is every theme — the <h3> group stood out as several times the size of its neighbours.
 * The class is the thing being styled, so the class is what the rule names.
 *
 * Font size and weight are stated rather than inherited for the same reason: this markup
 * lands inside somebody else's stylesheet, and a heading that inherits is a heading that
 * looks different on every shop.
 */
.codebold-filters .codebold-filter-legend {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	margin: 0 0 9px;
	padding: 0;
	border: 0;
	background: none;
	font-size: 12px;
	font-weight: 700;
	line-height: 1.4;
	letter-spacing: .05em;
	text-transform: uppercase;
	color: var( --cbf-faint );
	text-align: left;
}

.codebold-filters button.codebold-filter-legend {
	cursor: pointer;
}

.codebold-legend-caret {
	width: 8px;
	height: 8px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: rotate( 45deg ) translate( -2px, -2px );
	transition: transform .15s ease;
}

.codebold-filter-group.is-closed .codebold-legend-caret {
	transform: rotate( -135deg ) translate( -2px, -2px );
}

.codebold-filter-group.is-closed .codebold-filter-list,
.codebold-filter-group.is-closed .codebold-price,
.codebold-filter-group.is-closed .codebold-filter-more {
	display: none;
}

/* Hidden until "show more" is pressed. A chosen option never gets this class, so
   nothing a shopper has picked can be hiding behind a button. */
.codebold-filter-item.is-extra {
	display: none;
}

.codebold-filter-group.is-open-all .codebold-filter-item.is-extra {
	display: block;
}

.codebold-filters .codebold-filter-more {
	margin-top: 8px;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	font-size: 12.5px;
	font-weight: 600;
	color: var( --cbf-accent );
}

.codebold-filter-more:hover {
	text-decoration: underline;
}

/* --------------------------------------------------------------- colour swatches */

.codebold-filter-list.is-swatch {
	gap: 4px;
}

.codebold-swatch {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 5px 8px 5px 5px;
	border-radius: var( --cbf-radius );
	text-decoration: none;
	color: var( --cbf-ink );
}

.codebold-swatch-dot {
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var( --codebold-swatch, #d8dde3 );
	box-shadow: inset 0 0 0 1px rgba( 23, 34, 46, .16 );
	position: relative;
}

.codebold-swatch.is-chosen .codebold-swatch-dot {
	box-shadow: inset 0 0 0 1px rgba( 23, 34, 46, .16 ), 0 0 0 2px var( --cbf-surface ), 0 0 0 4px var( --cbf-accent );
}

/* A tick as well as a ring, so a chosen swatch is never identified by colour alone. */
.codebold-swatch.is-chosen .codebold-swatch-dot::after {
	content: "";
	position: absolute;
	left: 7px;
	top: 3px;
	width: 4px;
	height: 9px;
	border: solid rgba( 255, 255, 255, .95 );
	border-width: 0 2px 2px 0;
	transform: rotate( 45deg );
	filter: drop-shadow( 0 0 1px rgba( 0, 0, 0, .55 ) );
}

.codebold-swatch-name {
	flex: 1;
}

.codebold-swatch.is-chosen .codebold-swatch-name {
	font-weight: 600;
}

/* --------------------------------------------------------------- size chips */

.codebold-filter-list.is-chip {
	flex-direction: row;
	flex-wrap: wrap;
	gap: 7px;
}

.codebold-chip {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	padding: 8px 11px;
	border: 1px solid var( --cbf-line );
	border-radius: var( --cbf-radius );
	background: var( --cbf-surface );
	font-size: 13px;
	font-weight: 600;
	line-height: 1;
	color: var( --cbf-ink );
	text-decoration: none;
	transition: border-color .12s ease, color .12s ease;
}

.codebold-chip:hover {
	border-color: var( --cbf-accent );
	color: var( --cbf-accent );
}

.codebold-chip.is-chosen {
	border-color: var( --cbf-accent );
	background: var( --cbf-accent );
	color: #fff;
}

/* Struck through rather than hidden: a shopper can see the size exists and that it is
   the stock, not the shop, that has run out. */
.codebold-chip.is-empty {
	opacity: .45;
	text-decoration: line-through;
	pointer-events: none;
}

/* --------------------------------------------------------------- price */

.codebold-price-readout {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-bottom: 10px;
	font-size: 13.5px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var( --cbf-ink );
}

.codebold-price-track {
	position: relative;
	height: 26px;
	margin: 0 0 12px;
}

.codebold-price-track::before {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	top: 11px;
	height: 4px;
	border-radius: 2px;
	background: var( --cbf-line );
}

.codebold-price-fill {
	position: absolute;
	top: 11px;
	height: 4px;
	border-radius: 2px;
	background: var( --cbf-accent );
}

/* Two range inputs sharing one rail. Only the thumbs accept pointer events, or the
   input drawn on top would swallow every grab meant for the other handle. */
.codebold-price-track input[type="range"] {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 26px;
	margin: 0;
	padding: 0;
	background: none;
	border: 0;
	outline: none;
	appearance: none;
	-webkit-appearance: none;
	pointer-events: none;
}

.codebold-price-track input[type="range"]::-webkit-slider-thumb {
	appearance: none;
	-webkit-appearance: none;
	pointer-events: auto;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: 2px solid var( --cbf-accent );
	background: #fff;
	box-shadow: 0 1px 3px rgba( 23, 34, 46, .25 );
	cursor: grab;
}

.codebold-price-track input[type="range"]::-moz-range-thumb {
	pointer-events: auto;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: 2px solid var( --cbf-accent );
	background: #fff;
	box-shadow: 0 1px 3px rgba( 23, 34, 46, .25 );
	cursor: grab;
}

.codebold-price-track input[type="range"]::-moz-range-track {
	background: none;
	border: 0;
}

.codebold-price-form {
	display: flex;
	align-items: center;
	gap: 5px;
	flex-wrap: wrap;
}

.codebold-price-form input[type="number"] {
	width: 70px;
	padding: 6px 7px;
	border: 1px solid var( --cbf-line );
	border-radius: var( --cbf-radius );
	background: var( --cbf-surface );
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	color: var( --cbf-ink );
}

.codebold-price-symbol {
	font-size: 13px;
	color: var( --cbf-faint );
}

.codebold-filters .codebold-price-go {
	padding: 7px 13px;
	border: 0;
	border-radius: var( --cbf-radius );
	background: var( --cbf-accent );
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}

.codebold-filters .codebold-price-go:hover {
	filter: brightness( 1.06 );
}

/* --------------------------------------------------------------- the phone */

.codebold-filters-wrap .codebold-filters-open {
	display: none;
	align-items: center;
	gap: 9px;
	padding: 11px 18px;
	border: 1px solid var( --cbf-line );
	border-radius: var( --cbf-radius );
	background: var( --cbf-surface );
	font-size: 14px;
	font-weight: 600;
	color: var( --cbf-ink );
	cursor: pointer;
}

.codebold-filters-wrap .codebold-filters-open-icon {
	width: 15px;
	height: 11px;
	border-top: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	position: relative;
}

.codebold-filters-wrap .codebold-filters-open-icon::after {
	content: "";
	position: absolute;
	left: 0;
	top: 4px;
	width: 9px;
	border-top: 2px solid currentColor;
}

.codebold-filters-wrap .codebold-filters-badge {
	min-width: 20px;
	padding: 2px 6px;
	border-radius: 999px;
	background: var( --cbf-accent );
	color: #fff;
	font-size: 11.5px;
	line-height: 1.5;
	text-align: center;
}

.codebold-filters .codebold-filters-close,
.codebold-filters .codebold-filters-apply {
	display: none;
}

@media screen and ( max-width: 782px ) {
	/* Only once the script has armed the drawer. Without JavaScript the panel stays
	   inline and usable, and a button that cannot open anything is not offered. */
	.codebold-filters-wrap.is-ready .codebold-filters-open {
		display: inline-flex;
	}

	/* Off-canvas until asked for. Measured on a 390px phone, the open panel used 497px
	   of height and pushed the first product a full screen down; behind a button, the
	   products start where the shop starts. */
	.codebold-filters.is-drawer {
		position: fixed;
		inset: 0;
		z-index: 99999;
		display: block;
		margin: 0;
		padding: 18px 20px 96px;
		background: var( --cbf-surface );
		overflow-y: auto;
		overscroll-behavior: contain;
		transform: translateX( -100% );
		visibility: hidden;
		transition: transform .22s ease, visibility .22s ease;
	}

	.codebold-filters.is-drawer.is-open {
		transform: none;
		visibility: visible;
	}

	.codebold-filters.is-drawer .codebold-filter-group {
		margin-bottom: 22px;
	}

	.codebold-filters.is-drawer .codebold-filters-head {
		position: sticky;
		top: -18px;
		z-index: 1;
		margin: -18px -20px 14px;
		padding: 16px 20px;
		background: var( --cbf-surface );
		border-bottom: 1px solid var( --cbf-line );
	}

	/* A full-screen panel with no way out is a trap. */
	.codebold-filters.is-drawer .codebold-filters-close {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 34px;
		height: 34px;
		border: 0;
		border-radius: 50%;
		background: transparent;
		font-size: 26px;
		line-height: 1;
		color: var( --cbf-ink );
		cursor: pointer;
	}

	/* Pinned to the bottom, where a thumb already is. */
	.codebold-filters.is-drawer.is-open .codebold-filters-apply {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 100000;
		display: block;
		padding: 12px 20px calc( 12px + env( safe-area-inset-bottom, 0px ) );
		border-top: 1px solid var( --cbf-line );
		background: var( --cbf-surface );
	}

	.codebold-filters.is-drawer .codebold-filters-apply button {
		width: 100%;
		padding: 13px;
		border: 0;
		border-radius: var( --cbf-radius );
		background: var( --cbf-accent );
		color: #fff;
		font-size: 15px;
		font-weight: 600;
		cursor: pointer;
	}

	body.codebold-filters-locked {
		overflow: hidden;
	}
}

/* ============================================================================
   Touch.

   Every target below is sized against the published guidelines rather than
   against how it looks on a desktop with a mouse: 44pt is Apple's minimum and
   48dp is Google's. The slider thumbs were 18px, which is under half of either,
   and a two-handle slider is the one control where that is unforgivable — the
   handles sit close together and a thumb covers both.

   Applied by pointer type, not by screen width. A tablet with a mouse keeps the
   small targets; a large phone gets the big ones.
   ============================================================================ */

@media ( pointer: coarse ) {
	.codebold-filters .codebold-price-track {
		height: 44px;
	}

	.codebold-filters .codebold-price-track::before,
	.codebold-filters .codebold-price-fill {
		top: 20px;
	}

	.codebold-filters .codebold-price-track input[type="range"] {
		height: 44px;
	}

	.codebold-filters .codebold-price-track input[type="range"]::-webkit-slider-thumb {
		width: 28px;
		height: 28px;
		border-width: 3px;
	}

	.codebold-filters .codebold-price-track input[type="range"]::-moz-range-thumb {
		width: 28px;
		height: 28px;
		border-width: 3px;
	}

	/* A swatch row is a link the width of the panel, but the dot is what people aim
	   at, so the row itself has to be tall enough to hit. */
	.codebold-filters .codebold-swatch,
	.codebold-filters .codebold-filter {
		min-height: 44px;
	}

	.codebold-filters .codebold-swatch-dot {
		width: 26px;
		height: 26px;
	}

	.codebold-filters .codebold-swatch.is-chosen .codebold-swatch-dot::after {
		left: 9px;
		top: 5px;
		width: 5px;
		height: 11px;
	}

	.codebold-filters .codebold-filter-box {
		width: 22px;
		height: 22px;
	}

	.codebold-filters .codebold-filter.is-chosen .codebold-filter-box::after {
		left: 7px;
		top: 3px;
		width: 5px;
		height: 11px;
	}

	.codebold-filters .codebold-chip {
		min-width: 52px;
		min-height: 44px;
		padding: 12px 14px;
	}

	.codebold-filters .codebold-pill {
		min-height: 40px;
		padding: 8px 14px 8px 16px;
	}

	.codebold-filters .codebold-price-form input[type="number"] {
		min-height: 44px;
		width: 84px;
	}

	.codebold-filters .codebold-price-go {
		min-height: 44px;
		padding: 10px 18px;
	}

	.codebold-filters button.codebold-filter-legend {
		min-height: 44px;
		margin-bottom: 4px;
	}

	.codebold-filters .codebold-filter-more {
		min-height: 44px;
	}

	/* The one way out of a full-screen panel, and it was 34px — the smallest thing
	   on the drawer and the one a shopper needs most when they want out. */
	.codebold-filters.is-drawer .codebold-filters-close {
		width: 44px;
		height: 44px;
		font-size: 30px;
	}
}
