/* ==========================================================================
   Product archive — sidebar filters, results toolbar, pills, pagination, and
   the mobile filter drawer. Conditionally enqueued on product archives only
   (inc/integrations/woocommerce-archive.php).

   Layout lives in the template's Tailwind utilities; this file owns what
   utilities can't cleanly express: native form controls, the off-canvas drawer
   (pattern ported from cart.css), pill/pagination states, and the AJAX loading
   state. All colours map to theme.json presets with literal fallbacks.
   ========================================================================== */

:root {
	--nomon-archive-border: var(--wp--preset--color--border, #dbdbdb);
	--nomon-archive-border-subtle: var(--wp--preset--color--border-subtle, #efefef);
	--nomon-archive-surface: var(--wp--preset--color--surface, #f1f3f8);
	--nomon-archive-text: var(--wp--preset--color--foreground, #000000);
	--nomon-archive-muted: var(--wp--preset--color--muted, #6c6c6c);
	--nomon-archive-accent: var(--wp--preset--color--accent, #0032cc);
	--nomon-archive-accent-dark: var(--wp--preset--color--ink, #001e7a);
	--nomon-archive-skew: var(--skew-angle, -12deg); /* Theme-wide slant, set in main.css. */
	--nomon-archive-transition: 0.25s ease;
	--nomon-archive-drawer-width: 320px;
	--nomon-archive-z: 1000000;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.nomon-archive__header {
	margin-bottom: 3.125rem; /* 50px — the page-header band's padding-block */
}

/*
 * Header → form is one page unit, not two sections: cancel the root
 * section-rhythm owl in main.css (`.has-global-padding > [class*="nomon-"] +
 * [class*="nomon-"]`) that would otherwise wedge --section-space (~75px) here.
 * `main.` lifts specificity above the owl (0,3,1 > 0,3,0) so stylesheet load
 * order doesn't matter. The header's margin-bottom sets the actual gap.
 */
main.has-global-padding > .nomon-archive__header + .nomon-archive {
	margin-top: 0;
}

/* --------------------------------------------------------------------------
   Mobile filter toggle (hidden ≥lg via the template's `lg:hidden`)
   -------------------------------------------------------------------------- */
/* Uppercase Barlow Condensed, as every other button in the theme (the grouped
   rule in main.css); archive.css carries it because it owns these surfaces. */
.nomon-archive__filter-toggle,
.nomon-archive-results__sort-go {
	font-family: var(--wp--preset--font-family--barlow-condensed);
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.nomon-archive__filter-toggle {
	margin-bottom: 16px;
	cursor: pointer;
	transition: border-color var(--nomon-archive-transition);
}

.nomon-archive__filter-toggle:hover {
	border-color: var(--nomon-archive-accent);
}

.nomon-archive__filter-toggle:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 2px;
}

.nomon-archive__filter-count {
	display: inline-grid;
	place-items: center;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	background: var(--nomon-archive-accent);
	color: #fff;
	font-size: 12px;
	line-height: 1;
}

/* Descendant selector (0,2,0) beats the layout display utility regardless of
   stylesheet order — mirrors the cart trigger's count-bubble hide rule. */
.nomon-archive__filter-toggle .nomon-archive__filter-count--hidden {
	display: none;
}

/* --------------------------------------------------------------------------
   Two-column layout ≥lg (kept out of Tailwind: the `minmax(0,1fr)` arbitrary
   value trips the class scanner). Below lg the form is normal block flow and the
   sidebar becomes the off-canvas drawer.
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
	.nomon-archive {
		display: grid;
		grid-template-columns: 260px minmax(0, 1fr);
		align-items: start;
		gap: 2.5rem;
	}

	.nomon-archive__sidebar {
		position: sticky;
		top: 1rem;
		align-self: start;
	}
}

@media (max-width: 1023.98px) {
	.nomon-archive__sidebar {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		width: min(var(--nomon-archive-drawer-width), 90vw);
		z-index: calc(var(--nomon-archive-z) + 1);
		padding: 16px;
		background: #fff;
		overflow-y: auto;
		overscroll-behavior: contain;
		box-shadow: 0 0 40px rgb(0 0 0 / 0.15);
		transform: translateX(-100%);
		visibility: hidden;
		transition: transform var(--nomon-archive-transition), visibility 0s var(--nomon-archive-transition);
	}

	.nomon-archive.is-filters-open .nomon-archive__sidebar {
		transform: translateX(0);
		visibility: visible;
		transition: transform var(--nomon-archive-transition);
	}

	.nomon-archive__backdrop {
		position: fixed;
		inset: 0;
		z-index: var(--nomon-archive-z);
		background: rgb(0 0 0 / 0.45);
		opacity: 0;
		transition: opacity var(--nomon-archive-transition);
	}

	.nomon-archive.is-filters-open .nomon-archive__backdrop {
		opacity: 1;
	}
}

body.nomon-archive-filters-open {
	overflow: hidden;
}

/* --------------------------------------------------------------------------
   Filter groups
   -------------------------------------------------------------------------- */
.nomon-archive-filters__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 8px;
	padding-bottom: 12px;
	border-bottom: 1px solid var(--nomon-archive-border-subtle);
}

/* The drawer header (Suodata title + close X) is a mobile-only affordance: on
   desktop the sidebar is permanently visible with its own labelled groups, so
   the title is redundant and there's nothing to close. Hidden in real CSS, not
   a `lg:hidden` utility — Tailwind's layered utilities lose to this stylesheet's
   unlayered display rule (cascade-layer precedence). Must come *after* the
   display:flex rule above: media queries add no specificity, so source order
   decides. */
@media (min-width: 1024px) {
	.nomon-archive-filters__head {
		display: none;
	}
}

.nomon-archive-filters__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--nomon-archive-muted);
	cursor: pointer;
	transition: color var(--nomon-archive-transition);
}

.nomon-archive-filters__close:hover {
	color: var(--nomon-archive-text);
}

.nomon-archive-filters__close:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 2px;
}

/* Only the bottom space belongs to the fieldset. The 20px under the divider rule
   rides the legend instead (below): a <legend> is laid out in the fieldset's border
   area, outside its padding box, so `padding-top` here would land between the legend
   and its controls rather than above the legend. */
.nomon-archive-filters__group {
	margin: 0;
	padding: 0 0 20px;
	border: 0;
	border-top: 1px solid var(--nomon-archive-border-subtle);
}

/* No top rule on the first group (it abuts the header on mobile, the column top
   on desktop), and no space above its legend either. */
.nomon-archive-filters__head + .nomon-archive-filters__group,
.nomon-archive-filters__group:first-child {
	border-top: 0;
}

.nomon-archive-filters__head + .nomon-archive-filters__group > .nomon-archive-filters__legend,
.nomon-archive-filters__group:first-child > .nomon-archive-filters__legend {
	padding-top: 0;
}

.nomon-archive-filters__legend {
	margin: 0 0 12px;
	padding: 20px 0 0;
	font-size: 1rem;
	font-weight: 700;
	color: var(--nomon-archive-text);
}

.nomon-archive-filters__options {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.nomon-archive-filters__options--scroll {
	max-height: 220px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding-right: 4px;
}

.nomon-archive-filters__option {
	display: flex;
	align-items: center;
	gap: 10px;
	cursor: pointer;
	font-size: 0.9375rem;
	color: var(--nomon-archive-text);
}

.nomon-archive-filters__label {
	min-width: 0;
}

.nomon-archive-filters__count {
	margin-left: auto;
	flex-shrink: 0;
	color: var(--nomon-archive-muted);
	font-size: 0.8125rem;
}

/* Local mode: a brand with no matches under the other active filters is dimmed
   (archive.js toggles .is-empty live). Still clickable. */
.nomon-archive-filters__option.is-empty {
	opacity: 0.4;
}

/* Custom checkbox */
.nomon-archive-filters__option input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	width: 18px;
	height: 18px;
	flex-shrink: 0;
	margin: 0;
	border: 1px solid var(--nomon-archive-border);
	background: #fff;
	background-repeat: no-repeat;
	background-position: center;
	background-size: 12px;
	cursor: pointer;
	transition: background-color var(--nomon-archive-transition), border-color var(--nomon-archive-transition);
}

.nomon-archive-filters__option input[type="checkbox"]:checked {
	background-color: var(--nomon-archive-accent);
	border-color: var(--nomon-archive-accent);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

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

/* Price range */
.nomon-archive-filters__price {
	display: flex;
	align-items: center;
	gap: 8px;
}

.nomon-archive-filters__price-field {
	flex: 1 1 0;
	min-width: 0;
}

.nomon-archive-filters__price input {
	width: 100%;
	border: 1px solid var(--nomon-archive-border);
	padding: 8px 10px;
	font: inherit;
	color: var(--nomon-archive-text);
	background: #fff;
}

.nomon-archive-filters__price input:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 1px;
	border-color: var(--nomon-archive-accent);
}

.nomon-archive-filters__price-sep,
.nomon-archive-filters__price-unit {
	flex-shrink: 0;
	color: var(--nomon-archive-muted);
}

/* --------------------------------------------------------------------------
   Results — toolbar
   -------------------------------------------------------------------------- */
.nomon-archive-results__toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px;
	margin-bottom: 12px;
}

.nomon-archive-results__count {
	margin: 0;
	color: var(--nomon-archive-muted);
	font-size: 0.9375rem;
}

.nomon-archive-results__sort {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.nomon-archive-results__sort select {
	appearance: none;
	-webkit-appearance: none;
	border: 1px solid var(--nomon-archive-border);
	padding: 7px 34px 7px 11px;
	font: inherit;
	font-size: 15px;
	color: var(--nomon-archive-text);
	background-color: #fff;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236c6c6c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
	background-size: 14px;
	cursor: pointer;
}

.nomon-archive-results__sort select:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 1px;
	border-color: var(--nomon-archive-accent);
}

/* No-JS fallback submit — archive.js sets [hidden] on init. */
.nomon-archive-results__sort-go {
	padding: 9px 14px;
	border: 1px solid var(--nomon-archive-border);
	background: #fff;
	font: inherit;
	font-weight: 600;
	color: var(--nomon-archive-text);
	cursor: pointer;
}

.nomon-archive-results__sort-go[hidden] {
	display: none;
}

/* --------------------------------------------------------------------------
   Category pills
   -------------------------------------------------------------------------- */
.nomon-archive-results__pills {
	/* Inset by half the shear, so the leftmost pill's leaning corner lands on the
	   grid's edge instead of hanging outside the content column (same trick as
	   `.nomon-brands__carousel`). 35px is the pill's box height: 15px line + 18px
	   padding + 2px border. */
	--nomon-archive-pill-slant: calc(35px * tan(var(--nomon-archive-skew)) * -1);

	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	padding-inline: calc(var(--nomon-archive-pill-slant) / 2);
	margin-bottom: 24px;
}

/* Parallelogram on the theme's canonical slant. Text colour is the only thing
   that stays on the element — every state change lands on the pseudo below. */
.nomon-archive-pill {
	position: relative;
	isolation: isolate; /* Keeps the fill's z-index: -1 inside the pill. */
	display: inline-flex;
	align-items: center;
	padding: 9px 22px; /* Wider than an upright pill: the sheared ends eat into the label. */
	color: var(--nomon-archive-text);
	font-size: 0.9375rem;
	font-weight: 700;
	line-height: 1;
	text-decoration: none;
}

/* Fill + border ride a pseudo so the label stays upright — the pattern
   `.nomon-cart-trigger__count` uses in main.css, and it needs no inner element to
   counter-skew. Square corners: the theme's angled shapes are all hard-edged. */
.nomon-archive-pill::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border: 1px solid var(--nomon-archive-border);
	transform: skewX(var(--nomon-archive-skew));
	transition: background var(--nomon-archive-transition), border-color var(--nomon-archive-transition);
}

/* Back pill — leftmost, one level up. Tinted surface + arrow to read as "back",
   with a small gap before the sibling/child pills. Declared before the state
   rules below so their equal specificity still wins on hover/active. */
.nomon-archive-pill--back {
	gap: 6px;
	margin-right: 6px;
}

.nomon-archive-pill--back::before {
	background: var(--nomon-archive-surface);
	border-color: transparent;
}

/* Hover darkens the outline and tints the ground; the label stays black, since
   accent (#ffd200) on white is far short of AA. */
.nomon-archive-pill:hover::before {
	background: var(--nomon-archive-surface);
	border-color: var(--nomon-archive-text);
}

.nomon-archive-pill.is-active::before {
	background: var(--nomon-archive-accent);
	border-color: var(--nomon-archive-accent);
}

.nomon-archive-pill:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.nomon-archive-results__empty {
	padding: 40px 0;
}

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.nomon-archive-pagination {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px;
	margin-top: 40px;
}

.nomon-archive-pagination .page-numbers {
	display: inline-grid;
	place-items: center;
	min-width: 40px;
	height: 40px;
	padding: 0 10px;
	border: 1px solid var(--nomon-archive-border);
	color: var(--nomon-archive-text);
	font-weight: 600;
	text-decoration: none;
	transition: color var(--nomon-archive-transition), border-color var(--nomon-archive-transition), background var(--nomon-archive-transition);
}

.nomon-archive-pagination a.page-numbers:hover {
	border-color: var(--nomon-archive-accent);
	color: var(--nomon-archive-accent);
}

.nomon-archive-pagination .page-numbers.current {
	background: var(--nomon-archive-accent);
	border-color: var(--nomon-archive-accent);
	color: #fff;
}

.nomon-archive-pagination .page-numbers.dots {
	border-color: transparent;
}

.nomon-archive-pagination a.page-numbers:focus-visible {
	outline: 2px solid var(--nomon-archive-accent);
	outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   AJAX loading state — dim the grid + centre a spinner while fetching
   -------------------------------------------------------------------------- */
.nomon-archive__results {
	position: relative;
}

.nomon-archive__results[aria-busy="true"] .nomon-archive-results__grid,
.nomon-archive__results[aria-busy="true"] .nomon-archive-pagination {
	opacity: 0.4;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

.nomon-archive__results[aria-busy="true"]::after {
	content: "";
	position: absolute;
	top: 140px;
	left: 50%;
	width: 34px;
	height: 34px;
	margin-left: -17px;
	border: 3px solid var(--nomon-archive-border);
	border-top-color: var(--nomon-archive-accent);
	border-radius: 50%;
	animation: nomon-archive-spin 0.6s linear infinite;
}

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

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.nomon-archive__sidebar,
	.nomon-archive__backdrop,
	.nomon-archive-pill,
	.nomon-archive-pagination .page-numbers,
	.nomon-archive__results[aria-busy="true"] .nomon-archive-results__grid {
		transition: none;
	}

	.nomon-archive__results[aria-busy="true"]::after {
		animation: none;
	}
}
