/*
 * Product lists: the filter panel under the Genre / Terrain pills (inc/woo-filters.php).
 * Loaded after style.css and assets/css/woocommerce.css, on product lists only.
 *
 * Everything works as plain <details> and links. The rules under .crs-facets-js only apply once
 * assets/js/filters.js has taken over (off-canvas panel on small screens).
 */

/* ==========================================================================
   1. Layout: pills, then the toolbar, then the active choices
   ========================================================================== */

.crs-filters-area {
	clear: both;
	margin: 0 0 24px;
}

.crs-filters-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px 16px;
}

/* Without the script the panel opens in place: it needs the whole row. */
.crs-facets-nav {
	flex: 1 1 100%;
	min-width: 0;
}

.crs-facets-js .crs-facets-nav {
	flex: 0 0 auto;
}

/* The hidden attribute wins over the display values set below. */
.crs-facets-nav [hidden] {
	display: none !important;
}

/* Result count and sort select, as WooCommerce prints them, at the right of the toolbar. */
.crs-filters-tools {
	display: flex;
	flex: 1 1 auto;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 20px;
	min-width: 0;
}

.woocommerce .crs-filters-tools .woocommerce-result-count,
.woocommerce .crs-filters-tools .woocommerce-ordering {
	float: none;
	margin: 0;
}

.woocommerce .crs-filters-tools .woocommerce-result-count {
	padding: 0;
}

/* ==========================================================================
   2. Disclosure buttons
   ========================================================================== */

.crs-facets__toggle,
.crs-facet__toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 8px 16px;
	border: 1px solid var(--crs-border);
	border-radius: var(--crs-radius-sm);
	background: var(--crs-bg);
	color: var(--crs-text);
	font-size: .9375rem;
	font-weight: 600;
	line-height: 1.2;
	list-style: none;
	cursor: pointer;
	-webkit-user-select: none;
	user-select: none;
}

.crs-facets__toggle::-webkit-details-marker,
.crs-facet__toggle::-webkit-details-marker {
	display: none;
}

.crs-facets__toggle:hover,
.crs-facet__toggle:hover {
	border-color: var(--crs-accent);
	color: var(--crs-accent-hover);
}

/* Chevron, drawn with two borders. */
.crs-facets__toggle::after,
.crs-facet__toggle::after {
	content: "";
	flex: none;
	width: 8px;
	height: 8px;
	margin: -4px 2px 0 auto;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform .15s ease;
}

.crs-facets[open] > .crs-facets__toggle::after,
.crs-facet[open] > .crs-facet__toggle::after {
	margin-top: 4px;
	transform: rotate(-135deg);
}

.crs-facet[open] > .crs-facet__toggle {
	border-color: var(--crs-sage-600);
	background: var(--crs-sage-50);
}

/* Number of active values. */
.crs-facets__badge,
.crs-facet__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 999px;
	background: var(--crs-accent-soft);
	color: var(--crs-accent-hover);
	font-size: .8125rem;
	font-weight: 700;
	line-height: 1;
}

/* ==========================================================================
   3. Groups and their options
   ========================================================================== */

.crs-facets__groups {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px 0 0;
}

.crs-facet__toggle {
	display: flex;
	width: 100%;
}

.crs-facet__panel {
	padding: 12px 0 8px;
}

.crs-facet__options {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.crs-facet__options > li {
	display: flex;
	min-width: 0;
}

.crs-facet__option {
	display: flex;
	flex: 1 1 auto;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 6px 12px;
	border: 1px solid var(--crs-border);
	border-radius: var(--crs-radius-sm);
	background: var(--crs-bg);
	color: var(--crs-text);
	font-size: .9375rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
	text-decoration: none;
	white-space: nowrap;
}

a.crs-facet__option:hover {
	border-color: var(--crs-accent);
	color: var(--crs-accent-hover);
}

.crs-facet__option.is-active,
.crs-facet__option.is-active:hover {
	border-color: var(--crs-accent);
	background: var(--crs-accent-soft);
	box-shadow: 0 0 0 1px var(--crs-accent);
	color: var(--crs-text);
}

/* An option that would show no product: not a link. */
.crs-facet__option.is-disabled {
	border-style: dashed;
	background: var(--crs-surface);
	color: var(--crs-muted);
	opacity: .55;
	cursor: default;
}

/* Sizes: a compact grid. */
.crs-facet__options--grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
	gap: 6px;
}

.crs-facet__options--grid .crs-facet__option {
	padding: 6px 4px;
}

/* Model lines and price ranges: one per line, with a tick box. */
.crs-facet__options--list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	gap: 4px 8px;
}

.crs-facet__options--list .crs-facet__option {
	justify-content: flex-start;
	gap: 10px;
	border-color: transparent;
	text-align: left;
	white-space: normal;
}

.crs-facet__options--list .crs-facet__option::before {
	content: "";
	flex: none;
	width: 18px;
	height: 18px;
	border: 1.5px solid var(--crs-sage-600);
	border-radius: 5px;
	background: var(--crs-bg);
}

.crs-facet__options--list a.crs-facet__option:hover {
	border-color: var(--crs-border);
	background: var(--crs-surface);
}

.crs-facet__options--list .crs-facet__option.is-active,
.crs-facet__options--list .crs-facet__option.is-active:hover {
	border-color: transparent;
	background: var(--crs-accent-soft);
	box-shadow: none;
}

/* Ticked: the box filled with the accent colour inside a white margin, without any image. */
.crs-facet__options--list .crs-facet__option.is-active::before {
	border-color: var(--crs-accent);
	background: var(--crs-accent);
	box-shadow: inset 0 0 0 3px var(--crs-bg);
}

.crs-facet__options--list .crs-facet__option.is-disabled {
	border-color: transparent;
	background: none;
}

/* Colours: round chips. */
.crs-facet__options--swatches {
	gap: 6px;
}

.crs-facet__options--swatches > li {
	flex: none;
}

.crs-facet__option--swatch {
	flex: none;
	width: 44px;
	height: 44px;
	min-height: 0;
	padding: 0;
	border-color: transparent;
	border-radius: 50%;
	background: none;
}

.crs-facet__chip {
	display: block;
	width: 30px;
	height: 30px;
	border: 1px solid var(--crs-muted);
	border-radius: 50%;
}

/* "Multicolore": soft hues side by side. */
.crs-facet__chip--multi {
	background: conic-gradient(#e8b84a 0 20%, #e07a5f 0 40%, #b98bd0 0 60%, #6ea8dc 0 80%, #7fbf8e 0);
}

a.crs-facet__option--swatch:hover {
	border-color: var(--crs-sage-600);
}

.crs-facet__option--swatch.is-active,
.crs-facet__option--swatch.is-active:hover {
	border-color: var(--crs-accent);
	background: var(--crs-bg);
}

.crs-facet__option--swatch.is-disabled {
	border-color: transparent;
	background: none;
	opacity: .3;
}

/* ==========================================================================
   4. Active choices
   ========================================================================== */

.crs-filters-active {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 16px;
	padding: 14px 0 0;
}

.crs-filters-active__list {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}

.crs-filters-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 6px 10px 6px 14px;
	border: 1px solid var(--crs-sage-100);
	border-radius: 999px;
	background: var(--crs-sage-50);
	color: var(--crs-text);
	font-size: .875rem;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
}

.crs-filters-chip .crs-icon {
	flex: none;
	color: var(--crs-muted);
}

.crs-filters-chip:hover {
	border-color: var(--crs-accent);
	color: var(--crs-accent-hover);
}

.crs-filters-chip:hover .crs-icon {
	color: inherit;
}

.crs-filters-active__clear {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	color: var(--crs-muted);
	font-size: .875rem;
}

.crs-filters-active__clear:hover {
	color: var(--crs-accent-hover);
}

/* ==========================================================================
   5. From 900px: four buttons on the toolbar, each opening a panel under it
   ========================================================================== */

@media (min-width: 900px) {
	.crs-facets-nav,
	.crs-facets-js .crs-facets-nav {
		flex: 0 1 auto;
	}

	.crs-filters-tools {
		flex: 0 1 auto;
		justify-content: flex-end;
		margin-left: auto;
	}

	/* The script keeps the outer disclosure open here: its own button is not needed. */
	.crs-facets-js .crs-facets > .crs-facets__toggle {
		display: none;
	}

	/* Without the script, browsers that can style the content of a closed <details> show it too;
	   the others keep the "Filtrer" button, which opens the groups in place. */
	@supports selector(::details-content) {
		.crs-facets::details-content {
			display: block;
			content-visibility: visible;
		}

		.crs-facets > .crs-facets__toggle {
			display: none;
		}
	}

	.crs-facets__groups {
		flex-direction: row;
		flex-wrap: wrap;
		padding: 0;
	}

	.crs-facet {
		position: relative;
	}

	.crs-facet__toggle {
		display: inline-flex;
		width: auto;
	}

	.crs-facet__panel {
		position: absolute;
		top: calc(100% + 8px);
		left: 0;
		z-index: 30;
		width: max-content;
		min-width: 220px;
		max-width: min(460px, calc(100vw - 48px));
		max-height: min(70vh, 520px);
		padding: 16px;
		overflow-y: auto;
		border: 1px solid var(--crs-border);
		border-radius: var(--crs-radius);
		background: var(--crs-bg);
		box-shadow: var(--crs-shadow);
	}

	.crs-facet__options--grid {
		grid-template-columns: repeat(6, minmax(58px, 1fr));
	}

	.crs-facet__options--list {
		grid-template-columns: minmax(200px, 1fr);
	}

	/* Model lines, brands and clothing sizes are many: two columns. */
	.crs-facet--gamme .crs-facet__options--list,
	.crs-facet--marque .crs-facet__options--list,
	.crs-facet--taille .crs-facet__options--list {
		grid-template-columns: repeat(2, minmax(170px, 1fr));
	}

	.crs-facet__options--swatches {
		width: 294px;
		max-width: 100%;
	}
}

/* ==========================================================================
   6. Below 900px with the script: one "Filtrer" button, panel sliding in from the right
   ========================================================================== */

@media (max-width: 899.98px) {
	.crs-facets-js .crs-facets__panel {
		position: fixed;
		top: var(--wp-admin--admin-bar--height, 0px);
		right: 0;
		bottom: 0;
		z-index: 1001;
		display: flex;
		flex-direction: column;
		width: min(88vw, 400px);
		border-left: 1px solid var(--crs-border);
		background: var(--crs-bg);
		box-shadow: var(--crs-shadow);
	}

	.crs-facets-js .crs-facets__head {
		display: flex;
		flex: none;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		padding: 10px 10px 10px 20px;
		border-bottom: 1px solid var(--crs-border);
	}

	.crs-facets__title {
		font-size: 1.125rem;
		font-weight: 800;
	}

	.crs-facets__close {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
		border: 0;
		border-radius: 50%;
		background: none;
		color: var(--crs-text);
		cursor: pointer;
	}

	.crs-facets__close:hover {
		background: var(--crs-surface);
		color: var(--crs-accent-hover);
	}

	.crs-facets-js .crs-facets__groups {
		flex: 1 1 auto;
		min-height: 0;
		padding: 16px 20px;
		overflow-y: auto;
		overscroll-behavior: contain;
	}

	.crs-facets-js .crs-facets__foot {
		flex: none;
		padding: 12px 20px;
		border-top: 1px solid var(--crs-border);
	}

	.crs-facets__done {
		width: 100%;
	}

	/* A light veil: the page stays visible behind the panel. */
	.crs-facets__backdrop {
		position: fixed;
		inset: 0;
		z-index: 1000;
		background: rgba(247, 247, 244, .82);
		background: color-mix(in srgb, var(--crs-surface) 82%, transparent);
	}

	/* The page behind does not scroll while the panel is open. */
	.crs-facets-lock,
	.crs-facets-lock body {
		overflow: hidden;
	}
}

@media (max-width: 899.98px) and (prefers-reduced-motion: no-preference) {
	.crs-facets-js .crs-facets[open] > .crs-facets__panel {
		animation: crs-facets-in .22s ease-out;
	}

	.crs-facets__backdrop {
		animation: crs-facets-veil .22s ease-out;
	}
}

@keyframes crs-facets-in {
	from {
		transform: translateX(100%);
	}

	to {
		transform: none;
	}
}

@keyframes crs-facets-veil {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

/* ==========================================================================
   7. Forced colours, print
   ========================================================================== */

@media (forced-colors: active) {
	.crs-facet__option.is-active {
		outline: 2px solid Highlight;
		outline-offset: -2px;
	}

	.crs-facet__chip,
	.crs-facet__options--list .crs-facet__option::before {
		forced-color-adjust: none;
	}
}

@media print {
	.crs-filters-bar,
	.crs-filters-active {
		display: none;
	}
}
