/*
 * All Products page styles — NPM Refinery
 *
 * Same design tokens as npm-single-product.css. The product grid reuses
 * the .npm-grid[data-post-type="product"] rules already defined there —
 * this file only needs the page's own layout (sidebar + results) and
 * the filter form itself.
 */

/* ---- Layout ---- */

.npm-all-products {
	position: relative; /* anchors .npm-all-products__loading */
	display: grid;
	grid-template-columns: 260px 1fr;
	gap: 3rem;
	max-width: var(--wp--style--global--wide-size, 1240px);
	margin: 0 auto;
	padding: 3rem 1.5rem 4rem;
	align-items: start;
}

@media (max-width: 782px) {
	.npm-all-products {
		grid-template-columns: 1fr;
		padding: 2rem 1rem 3rem;
		gap: 1.25rem;
	}
}

/* ---- Filter sidebar ---- */

.npm-filters {
	background-color: var(--wp--preset--color--base);
	border: 1px solid rgba(23, 38, 17, 0.12); /* same border as .card in style.css */
	border-radius: 6px; /* matches .card's existing radius in style.css */
	padding: 1.5rem;
	position: sticky;
	top: 1.5rem;
}

@media (max-width: 782px) {
	.npm-filters {
		/* Sticky made sense when the sidebar sat beside a tall results
		   column; stacked on mobile it's just the first row on the
		   page, so there's nothing for it to stick past. Slightly
		   tighter padding too, now that it's a compact collapsed bar
		   most of the time instead of a full card. */
		position: static;
		padding: 1rem 1.25rem;
	}
}

/* ---- Collapsible wrapper (mobile) ----
   <details>/<summary> gives a real disclosure widget, and the actual
   open/closed state is now set by JS (npm-all-products-tablet-open.js
   — merge into npm-all-products.js) based on a matchMedia(min-width:
   601px) check, not by CSS alone.

   Earlier version of this rule tried to force the panel open on
   larger screens purely with `.npm-filters__body { display: block
   !important }`, overriding the browser's default "hide everything
   but <summary> when not open" behavior. That works in older <details>
   implementations, but current Chrome (the "smooth details expand"
   rendering rewrite, 2024+) hides collapsed content via
   content-visibility on an internal ::details-content box the browser
   generates around it, not via a plain display:none on the child —
   so overriding display on .npm-filters__body directly no longer
   reaches far enough up to un-hide it. Actually setting/removing the
   `open` attribute via JS is the only approach that works correctly
   across both the old and new rendering models. See
   npm-all-products-tablet-open.js for the actual toggle logic — this
   file only keeps the *visual* styling for each state below. */

.npm-filters__summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	list-style: none; /* remove Firefox's default disclosure triangle */
	cursor: pointer;
}

.npm-filters__summary::-webkit-details-marker {
	display: none; /* remove Chrome/Safari's default disclosure triangle */
}

.npm-filters__summary:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

.npm-filters__chevron {
	flex: 0 0 auto;
	color: var(--wp--preset--color--accent);
	transition: transform ease 0.25s;
}

.npm-filters__details[open] .npm-filters__chevron {
	transform: rotate(180deg);
}

.npm-filters__body {
	margin-top: 1rem;
}

.npm-filters__title {
	font-family: var(--wp--preset--font-family--body);
	color: var(--wp--preset--color--primary);
	font-size: var(--wp--preset--font-size--medium);
	margin: 0;
	font-weight: 400;
}

/* Sits below the Apply Filters button now (see template-all-products.php) —
   centered, with room above it, rather than the inline top-of-header
   placement it used to have. */
.npm-filters__clear {
	display: block;
	text-align: center;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--accent);
	text-decoration: none;
	margin-top: 1rem;
}

.npm-filters__clear:hover {
	color: var(--wp--preset--color--primary);
}

/* Tablet and up — npm-all-products-tablet-open.js keeps the `open`
   attribute set at this width, so the panel is already showing; this
   just makes the summary read as a static header instead of a toggle
   button, since there's nothing to toggle here (no pointer cursor, no
   chevron, clicks don't do anything). Starts at the project's tablet
   breakpoint (601px), not the 783px point where .npm-all-products
   itself switches back to the two-column sidebar layout — the filter
   panel should read as open well before that, for the whole tablet
   range where it's still stacked above the results. */
@media (min-width: 601px) {
	.npm-filters__summary {
		cursor: default;
		pointer-events: none;
	}

	.npm-filters__chevron {
		display: none;
	}
}

.npm-filters__group {
	border: none;
	/* border-top: 1px solid var(--wp--preset--color--secondary); */
	margin: 0 0 1.25rem;
	padding: 1rem 0 0;
}

.npm-filters__group:first-child {
	padding-top: 0;
}

.npm-filters__group-label {
	font-family: var(--wp--preset--font-family--body);
	font-weight: 400;
	color: var(--wp--preset--color--primary);
	font-size: var(--wp--preset--font-size--small);
	padding: 0;
	/* margin-bottom: 0.6rem; */
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.npm-filters__option {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--contrast);
	padding: 0.35rem 0;
	cursor: pointer;
}

/* Custom checkbox — the browser's default checkbox is replaced entirely
   (appearance: none) with a plain square drawn in CSS, filled solid on
   :checked with a checkmark drawn from two rotated borders (no image
   asset needed). Modeled on the reference screenshot's filter sidebar
   (small square, light border when empty, solid fill + white check when
   selected). */

.npm-filters__option input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	width: 18px;
	height: 18px;
	margin: 0;
	flex: 0 0 auto;
	position: relative;
	border: 1.5px solid rgba(23, 38, 17, 0.25);
	border-radius: 4px;
	background-color: var(--wp--preset--color--base);
	cursor: pointer;
	transition: all ease 0.2s;
}

.npm-filters__option:hover input[type="checkbox"] {
	border-color: var(--wp--preset--color--accent);
}

.npm-filters__option input[type="checkbox"]:checked {
	background-color: var(--wp--preset--color--accent);
	border-color: var(--wp--preset--color--accent);
}

.npm-filters__option input[type="checkbox"]:checked::after {
	content: "";
	position: absolute;
	left: 5px;
	top: 1px;
	width: 5px;
	height: 9px;
	border: solid var(--wp--preset--color--base);
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
}

.npm-filters__option input[type="checkbox"]:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

.npm-filters__submit {
	display: block;
	width: 100%;
	background-color: var(--wp--preset--color--accent);
	color: var(--wp--preset--color--base);
	font-family: var(--wp--preset--font-family--body);
	font-weight: 400;
	font-size: var(--wp--preset--font-size--small);
	text-align: center;
	border: none;
	padding: 0.8em 1em;
	border-radius: 5px;
	cursor: pointer;
	transition: all ease 0.25s;
}

.npm-filters__submit:hover {
	background-color: var(--wp--preset--color--primary);
}

/* Progressive enhancement (npm-all-products.js) auto-submits on checkbox
   change, so the button mainly matters with JS disabled — hide it once
   JS is confirmed running rather than showing a redundant control. */
.npm-filters.is-auto-submitting .npm-filters__submit {
	display: none;
}

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

.npm-all-products__count {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--contrast);
	margin: 0 0 1.5rem;
}

.npm-all-products__empty {
	font-family: var(--wp--preset--font-family--body);
	color: var(--wp--preset--color--contrast);
	text-align: center;
	padding: 3rem 1.5rem;
	border: 1px dashed rgba(23, 38, 17, 0.2);
	border-radius: 6px;
}

.npm-all-products__empty .npm-filters__clear {
	display: inline-block;
	margin-top: 0.75rem;
}

/* ---- Pagination ---- */

.npm-all-products__pagination {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: center;
	margin-top: 2.5rem;
}

.npm-all-products__pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2.25rem;
	height: 2.25rem;
	padding: 0 0.6rem;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--primary);
	text-decoration: none;
	border: 1px solid rgba(23, 38, 17, 0.12);
	border-radius: 5px;
	transition: all ease 0.25s;
}

.npm-all-products__pagination .page-numbers:hover {
	border-color: var(--wp--preset--color--accent);
	color: var(--wp--preset--color--accent);
}

.npm-all-products__pagination .page-numbers.current {
	background-color: var(--wp--preset--color--accent);
	border-color: var(--wp--preset--color--accent);
	color: var(--wp--preset--color--base);
}

.npm-all-products__pagination .page-numbers.dots {
	border-color: transparent;
}

/* ---- Loading overlay ---- */

.npm-all-products__loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: rgba(237, 237, 235, 0.85); /* --wp--preset--color--background with opacity */
	opacity: 0;
	visibility: hidden;
	transition: opacity ease 0.2s;
	z-index: 10;
}

.npm-all-products.is-loading .npm-all-products__loading {
	opacity: 1;
	visibility: visible;
}

.npm-spinner {
	width: 40px;
	height: 40px;
	border: 3px solid rgba(23, 38, 17, 0.15);
	border-top-color: var(--wp--preset--color--accent);
	border-radius: 50%;
	animation: npm-spin 0.7s linear infinite;
}

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