/*
 * Product archive (woocommerce/archive-product.php, woocommerce/archive/*.php).
 *
 * Page rules are scoped under `.lp-archive`, filter rules under `.lp-filters`. Selectors that
 * compete with WooCommerce (result count, sorting, pagination) carry one more class than its rules.
 * JetSmartFilters markup is restyled under `.lp-filters .lp-filter__body`, repeating the structure
 * of JetSmartFilters' own selectors (e.g. `.jet-checkboxes-list__item`) so each override outranks
 * the rule it replaces in the plugin stylesheet.
 */

.lp-archive {
	--lp-sidebar-width: 17rem;
	--lp-archive-control-height: 44px;
	margin-bottom: 3rem;
	color: var(--lp-text);
}

/* Header */

.lp-archive .lp-archive__header {
	margin: 0.25rem 0 1.5rem;
}

.lp-archive .lp-archive__title {
	margin: 0;
	font-family: var(--lp-font-heading);
	font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
	font-weight: 600;
	line-height: 1.15;
	letter-spacing: normal;
	text-transform: none;
	color: var(--lp-text);
}

.lp-archive .term-description {
	max-width: 70ch;
	margin-top: 0.5rem;
	font-family: var(--lp-font-body);
	font-size: 0.95rem;
	line-height: 1.6;
	color: var(--lp-muted);
}

.lp-archive .term-description p {
	margin: 0;
}

/* Subcategory shortcuts: one scrollable row on mobile, wrapped on wider screens. */

.lp-archive .lp-archive__subcategories {
	margin-top: 1rem;
}

.lp-archive .lp-archive__subcategories-list {
	display: flex;
	gap: 0.5rem;
	margin: 0;
	padding: 0 0 0.25rem;
	overflow-x: auto;
	list-style: none;
	scroll-snap-type: x proximity;
	scrollbar-width: none;
}

.lp-archive .lp-archive__subcategories-list > li {
	flex: none;
	margin: 0;
	scroll-snap-align: start;
}

.lp-archive .lp-archive__subcategory {
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0.45rem 1rem;
	border: 1px solid var(--lp-border);
	border-radius: 999px;
	background: var(--lp-surface);
	font-family: var(--lp-font-body);
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	text-decoration: none;
	color: var(--lp-text);
	transition: border-color 0.2s, color 0.2s;
}

.lp-archive .lp-archive__subcategory:hover {
	border-color: var(--lp-teal);
	color: var(--lp-teal-text);
}

.lp-archive .lp-archive__subcategory:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

/* Results column */

.lp-archive .lp-archive__results {
	min-width: 0;
}

/* Toolbar */

.lp-archive .lp-archive__toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 1rem;
}

.lp-archive .lp-archive__filters-toggle {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: var(--lp-archive-control-height);
	margin: 0;
	padding: 0.5rem 1rem;
	border: 1px solid var(--lp-teal-text);
	border-radius: var(--lp-radius);
	background: var(--lp-surface);
	font-family: var(--lp-font-body);
	font-size: 0.9rem;
	font-weight: 700;
	line-height: 1.2;
	text-transform: none;
	color: var(--lp-teal-text);
	cursor: pointer;
}

.lp-archive .lp-archive__filters-toggle svg,
.lp-filters .lp-filters__close svg {
	width: 1.125rem;
	height: 1.125rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
}

.lp-archive .lp-archive__toolbar .woocommerce-ordering {
	flex: 1 1 0;
	float: none;
	margin: 0;
}

.lp-archive .lp-archive__toolbar .woocommerce-ordering select {
	width: 100%;
	min-height: var(--lp-archive-control-height);
	margin: 0;
	padding: 0.5rem 2rem 0.5rem 0.6rem;
	border: 1px solid var(--lp-border);
	border-radius: var(--lp-radius);
	background: var(--lp-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a3344' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.6rem center / 1rem;
	font-family: var(--lp-font-body);
	font-size: 0.875rem;
	color: var(--lp-text);
	appearance: none;
	cursor: pointer;
}

.lp-archive .lp-archive__toolbar .woocommerce-ordering select:focus-visible,
.lp-archive .lp-archive__filters-toggle:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

.lp-archive .lp-archive__toolbar .woocommerce-result-count {
	order: 3;
	flex-basis: 100%;
	float: none;
	margin: 0;
	font-family: var(--lp-font-body);
	font-size: 0.875rem;
	color: var(--lp-muted);
}

/* Active filters, as removable tags. */

.lp-archive .lp-archive__active-filters:not(:has(.jet-active-tag)) {
	display: none;
}

.lp-archive .lp-archive__active-filters {
	margin-bottom: 1rem;
}

.lp-archive .lp-archive__active-filters .jet-active-tags__list {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.lp-archive .lp-archive__active-filters .jet-active-tag {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0;
	padding: 0.35rem 0.5rem 0.35rem 0.75rem;
	border: 1px solid var(--lp-teal-text);
	border-radius: 999px;
	background: var(--lp-bg-light);
	font-family: var(--lp-font-body);
	font-size: 0.8rem;
	font-weight: 600;
	line-height: 1.2;
	color: var(--lp-teal-text);
	cursor: pointer;
}

/* JetSmartFilters renders "clear all" first: it is moved after the active filters. */
.lp-archive .lp-archive__active-filters .jet-active-tag--clear {
	order: 1;
	border-color: var(--lp-border);
	background: var(--lp-surface);
	color: var(--lp-text);
}

/* JetSmartFilters pins the remove mark to the tag's corner, over the text. */
.lp-archive .lp-archive__active-filters .jet-active-tag__remove {
	position: static;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.1rem;
	height: 1.1rem;
	font-size: 0.9rem;
	line-height: 1;
}

/* Product grid: empty state returned by AJAX filtering inside the list. */

.lp-archive .lp-card-grid > .woocommerce-no-products-found {
	grid-column: 1 / -1;
}

.lp-archive .woocommerce-no-products-found .woocommerce-info,
.lp-archive .lp-archive__results > .woocommerce-info {
	margin: 0;
	padding: 1.25rem;
	border: 1px solid var(--lp-border);
	border-radius: var(--lp-radius);
	background: var(--lp-bg-light);
	font-family: var(--lp-font-body);
	color: var(--lp-text);
}

.lp-archive .woocommerce-no-products-found .woocommerce-info::before,
.lp-archive .lp-archive__results > .woocommerce-info::before {
	content: none;
}

/* Pagination */

.lp-archive .woocommerce-pagination {
	margin-top: 2rem;
	text-align: center;
}

.lp-archive .woocommerce-pagination ul.page-numbers {
	display: inline-flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.4rem;
	margin: 0;
	padding: 0;
	border: 0;
}

.lp-archive .woocommerce-pagination ul.page-numbers > li {
	float: none;
	margin: 0;
	border: 0;
	overflow: visible;
}

.lp-archive .woocommerce-pagination ul.page-numbers .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 40px;
	height: 40px;
	padding: 0 0.6rem;
	border: 1px solid var(--lp-border);
	border-radius: var(--lp-radius);
	background: var(--lp-surface);
	font-family: var(--lp-font-body);
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	color: var(--lp-text);
}

.lp-archive .woocommerce-pagination ul.page-numbers a.page-numbers:hover {
	border-color: var(--lp-teal);
	background: var(--lp-surface);
	color: var(--lp-teal-text);
}

.lp-archive .woocommerce-pagination ul.page-numbers .page-numbers.current {
	border-color: var(--lp-teal-text);
	background: var(--lp-teal-text);
	color: var(--lp-on-teal);
}

.lp-archive .woocommerce-pagination ul.page-numbers .page-numbers.dots {
	border-color: transparent;
	background: none;
}

.lp-archive .woocommerce-pagination ul.page-numbers a.page-numbers:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

/* Filters */

.lp-filters .lp-filters__title {
	margin: 0;
	font-family: var(--lp-font-heading);
	font-size: 1.25rem;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: normal;
	text-transform: none;
	color: var(--lp-text);
}

.lp-filters .lp-filters__close {
	display: none;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--lp-radius);
	background: none;
	color: var(--lp-text);
	cursor: pointer;
	/* The parent theme transitions `all` on buttons, visibility included: inside the panel, that
	   would keep them hidden for a moment after opening and block moving focus into it. */
	transition: background-color 0.2s;
}

.lp-filters .lp-filters__close:hover {
	background: var(--lp-bg-light);
	color: var(--lp-text);
}

.lp-filters .lp-filters__footer,
.lp-filters__backdrop {
	display: none;
}

/* Collapsible group around each JetSmartFilters filter. */

.lp-filters .lp-filter {
	border-bottom: 1px solid var(--lp-border);
}

/* The JetSmartFilters indexer flags each value without matching products: a group left without
   any visible value is hidden, on load and after each AJAX filtering. */
.lp-filters .lp-filter:has(.jet-filter-row):not(:has(.jet-filter-row:not(.jet-filter-row-hide))) {
	display: none;
}

.lp-filters .lp-filter__title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.85rem 0;
	font-family: var(--lp-font-body);
	font-size: 0.95rem;
	font-weight: 700;
	line-height: 1.3;
	color: var(--lp-text);
	list-style: none;
	cursor: pointer;
}

.lp-filters .lp-filter__title::-webkit-details-marker {
	display: none;
}

.lp-filters .lp-filter__title::after {
	content: "";
	flex: none;
	width: 1rem;
	height: 1rem;
	background: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
	transition: transform 0.2s;
}

.lp-filters .lp-filter[open] > .lp-filter__title::after {
	transform: rotate(180deg);
}

.lp-filters .lp-filter__title:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

.lp-filters .lp-filter__body {
	padding-bottom: 0.85rem;
}

/* Checkboxes */

.lp-filters .lp-filter__body .jet-checkboxes-list__row {
	margin: 0;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item {
	position: relative;
	display: block;
	margin: 0;
}

/* Visually hidden but focusable: the decorator below shows its state. */
.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	opacity: 0;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__button {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.3rem 0;
	font-family: var(--lp-font-body);
	font-size: 0.9rem;
	line-height: 1.3;
	color: var(--lp-text);
	cursor: pointer;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__decorator {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 1.125rem;
	min-width: 1.125rem;
	height: 1.125rem;
	min-height: 1.125rem;
	margin: 0;
	border: 1.5px solid var(--lp-muted);
	border-radius: 4px;
	background: var(--lp-surface);
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__checked-icon {
	line-height: 0;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__checked-icon svg {
	width: 0.7rem;
	height: 0.7rem;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__checked-icon svg path {
	fill: var(--lp-on-teal);
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__input:checked + .jet-checkboxes-list__button .jet-checkboxes-list__decorator {
	border-color: var(--lp-teal-text);
	background: var(--lp-teal-text);
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__input:focus-visible + .jet-checkboxes-list__button .jet-checkboxes-list__decorator {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__button:hover .jet-checkboxes-list__decorator {
	border-color: var(--lp-teal-text);
}

.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__label {
	flex: 1;
	min-width: 0;
	font-size: inherit;
	color: inherit;
}

/* Number of matching products, without JetSmartFilters' parentheses. */
.lp-filters .lp-filter__body .jet-filters-counter {
	flex: none;
	margin-left: auto;
	font-size: 0.75rem;
	color: var(--lp-muted);
}

.lp-filters .lp-filter__body .jet-filters-counter :is(.counter-prefix, .counter-suffix) {
	display: none;
}

/* A ticked value needs no count (JetSmartFilters may even report it as 0). */
.lp-filters .lp-filter__body .jet-checkboxes-list__item .jet-checkboxes-list__input:checked + .jet-checkboxes-list__button .jet-filters-counter {
	visibility: hidden;
}

.lp-filters .lp-filter__body .jet-list-tree__children {
	padding-left: 1.7rem;
}

.lp-filters .lp-filter__body .jet-filter-items-moreless__toggle {
	display: inline-flex;
	margin-top: 0.35rem;
	padding: 0.25rem 0;
	font-family: var(--lp-font-body);
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--lp-teal-text);
	cursor: pointer;
}

.lp-filters .lp-filter__body .jet-filter-items-moreless__toggle:focus-visible {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

/* Price range */

.lp-filters .lp-filter__body .jet-range__slider {
	margin: 0.5rem 0 0.75rem;
	padding: 0;
	border: 0;
}

.lp-filters .lp-filter__body .jet-range__slider__track {
	height: 4px;
	border-radius: 2px;
	background: var(--lp-border);
	color: var(--lp-teal);
}

.lp-filters .lp-filter__body .jet-range__slider__input::-webkit-slider-thumb {
	width: 20px;
	height: 20px;
	border: 2px solid var(--lp-teal-text);
	border-radius: 50%;
	background: var(--lp-surface);
	cursor: pointer;
}

.lp-filters .lp-filter__body .jet-range__slider__input::-moz-range-thumb {
	width: 16px;
	height: 16px;
	border: 2px solid var(--lp-teal-text);
	border-radius: 50%;
	background: var(--lp-surface);
	cursor: pointer;
}

.lp-filters .lp-filter__body .jet-range__slider__input:focus-visible::-webkit-slider-thumb {
	outline: 2px solid var(--lp-text);
	outline-offset: 2px;
}

.lp-filters .lp-filter__body .jet-range__values {
	font-family: var(--lp-font-body);
	font-size: 0.875rem;
	font-weight: 600;
	text-align: center;
	color: var(--lp-text);
}

/* Mobile: the filters become a modal panel (js/product-archive.js). Must match the script's breakpoint. */
@media (max-width: 991px) {
	.lp-filters {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 1000;
		display: flex;
		flex-direction: column;
		width: min(88vw, 24rem);
		background: var(--lp-surface);
		box-shadow: var(--lp-shadow-hover);
		visibility: hidden;
		transform: translateX(-100%);
		/* Hidden only once slid out, so the closing slide stays visible. */
		transition: transform 0.25s, visibility 0s 0.25s;
	}

	/* Visible at once when opening, so the script can move focus into the panel. */
	.lp-filters-open .lp-filters {
		visibility: visible;
		transform: none;
		transition: transform 0.25s, visibility 0s;
	}

	.lp-filters-open {
		overflow: hidden;
	}

	.lp-filters .lp-filters__header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0.5rem 0.5rem 0.5rem 1rem;
		border-bottom: 1px solid var(--lp-border);
	}

	.lp-filters .lp-filters__close {
		display: inline-flex;
	}

	.lp-filters .lp-filters__groups {
		flex: 1;
		padding: 0 1rem;
		overflow-y: auto;
		overscroll-behavior: contain;
	}

	.lp-filters .lp-filters__footer {
		display: block;
		padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
		border-top: 1px solid var(--lp-border);
	}

	.lp-filters .lp-filters__submit {
		width: 100%;
		min-height: 48px;
		margin: 0;
		padding: 0.75rem 1rem;
		border: 0;
		border-radius: var(--lp-radius);
		background: var(--lp-teal);
		font-family: var(--lp-font-body);
		font-size: 1rem;
		font-weight: 700;
		text-transform: none;
		color: var(--lp-on-teal);
		cursor: pointer;
		transition: background-color 0.2s;
	}

	.lp-filters .lp-filters__submit:hover {
		background: var(--lp-teal-dark);
		color: var(--lp-on-teal);
	}

	.lp-filters .lp-filters__submit:focus-visible,
	.lp-filters .lp-filters__close:focus-visible {
		outline: 2px solid var(--lp-text);
		outline-offset: 2px;
	}

	.lp-filters__backdrop:not([hidden]) {
		position: fixed;
		inset: 0;
		z-index: 999;
		display: block;
		background: var(--lp-overlay);
	}
}

/* Desktop: sidebar next to the results, sticky while the products scroll. */
@media (min-width: 992px) {
	.lp-archive .lp-archive__layout:has(> .lp-filters) {
		display: grid;
		grid-template-columns: var(--lp-sidebar-width) minmax(0, 1fr);
		gap: 2rem;
		align-items: start;
	}

	.lp-archive .lp-archive__subcategories-list {
		flex-wrap: wrap;
		overflow: visible;
	}

	.lp-archive .lp-archive__filters-toggle {
		display: none;
	}

	.lp-archive .lp-archive__toolbar .woocommerce-result-count {
		order: 0;
		flex: 1 1 auto;
	}

	.lp-archive .lp-archive__toolbar .woocommerce-ordering {
		flex: 0 0 15rem;
	}

	.lp-filters {
		position: sticky;
		top: 1rem;
		max-height: calc(100vh - 2rem);
		/* Left gutter: overflow-y clips the checkboxes and their focus outline on the left too. */
		padding-left: 0.375rem;
		padding-right: 0.5rem;
		overflow-y: auto;
		overscroll-behavior: contain;
		scrollbar-width: thin;
	}

	.lp-filters .lp-filters__header {
		padding-bottom: 0.5rem;
		border-bottom: 1px solid var(--lp-border);
	}
}

@media (prefers-reduced-motion: reduce) {
	.lp-filters,
	.lp-filters .lp-filter__title::after,
	.lp-archive .lp-archive__subcategory {
		transition: none;
	}
}
