/**
 * Catalog Archive V1: templates/archive-product.html (the Shop, and the product
 * brand, tag and attribute archives WooCommerce renders with it as fallback) and
 * product category archives (templates/taxonomy-product_cat.html).
 *
 * Loaded only when a Product Filters block renders (inc/assets.php), which only
 * these archives do (product search does not). Everything is scoped under
 * .alatinidza-catalog.
 * WooCommerce 11.1 component classes are styled on purpose (breadcrumb, Product
 * Filters, result count, sorting, Product Template); regression-test after major
 * WooCommerce updates.
 *
 * Layout (mobile-first):
 * - below 1024px: [Filter products button | sorting], result count, active
 *   filters, products; the filters open in WooCommerce's native drawer;
 * - from 1024px: persistent filter sidebar (17rem = 272px) beside
 *   [result count | sorting], active filters and the products.
 * The results and toolbar wrappers use display: contents so their blocks can sit
 * in the layout grid next to the sidebar; they are plain groups without semantics.
 */

/* Head: breadcrumb, H1 and the intro of top-level categories. */
.alatinidza-catalog__head > * {
	margin-block: 0;
}

.alatinidza-catalog__head > * + * {
	margin-block-start: var(--wp--preset--spacing--30);
}

.alatinidza-catalog__head .wp-block-query-title {
	margin-block-start: var(--wp--preset--spacing--20);
}

.alatinidza-catalog__intro {
	max-width: var(--wp--style--global--content-size);
}

.alatinidza-catalog__intro > :last-child {
	margin-block-end: 0;
}

/* Breadcrumb (WooCommerce's native trail): Inter 14px, muted links, current page darker and unlinked. */
.alatinidza-catalog .woocommerce-breadcrumb {
	margin: 0;
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.5;
}

.alatinidza-catalog .woocommerce-breadcrumb a {
	color: var(--wp--preset--color--contrast-muted);
	text-decoration-line: none;
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.25em;
}

/* Hover: brand accent underline (accent text would be below 4.5:1 at 14px). */
.alatinidza-catalog .woocommerce-breadcrumb a:hover {
	text-decoration-line: underline;
}

/* Direct subcategories (category archives only). */
.alatinidza-catalog__subcategories {
	margin-block-start: var(--wp--preset--spacing--50);
}

.alatinidza-catalog__subcategories:not(:has(li)) {
	display: none;
}

/* The layout grid. */
.alatinidza-catalog__layout {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	grid-template-areas:
		"filters sorting"
		"count   count"
		"active  active"
		"products products";
	align-items: center;
	gap: var(--wp--preset--spacing--30) var(--wp--preset--spacing--30);
	margin-block-start: var(--wp--preset--spacing--50);
}

.alatinidza-catalog__results,
.alatinidza-catalog__toolbar {
	display: contents;
}

.alatinidza-catalog__layout > *,
.alatinidza-catalog__results > *,
.alatinidza-catalog__toolbar > * {
	min-width: 0;
	margin: 0;
}

.alatinidza-catalog__filters {
	grid-area: filters;
}

.alatinidza-catalog .wc-block-catalog-sorting {
	grid-area: sorting;
	justify-self: end;
}

.alatinidza-catalog .wc-block-product-results-count {
	grid-area: count;
}

.alatinidza-active-filters {
	grid-area: active;
}

.alatinidza-catalog__products {
	grid-area: products;
	align-self: start;
}

/*
 * No filter group has options (for example an empty catalog): hide the filters
 * entirely. The sort list does not count as a filter; the dropdown stays.
 */
.alatinidza-catalog__filters:not(:has(.alatinidza-filters__group:not(.wc-block-product-filter--hidden, .alatinidza-core-sort))) {
	display: none;
}

/* ...and drop its grid column, so the results use the full width. */
.alatinidza-catalog__layout:not(:has(.alatinidza-filters__group:not(.wc-block-product-filter--hidden, .alatinidza-core-sort))) {
	grid-template-columns: minmax(0, 1fr) auto;
	grid-template-areas:
		"count    sorting"
		"active   active"
		"products products";
}

/* Result count and sorting (native blocks). */
.alatinidza-catalog .woocommerce-result-count {
	margin: 0;
	color: var(--wp--preset--color--contrast-muted);
	font-size: var(--wp--preset--font-size--small);
}

.alatinidza-catalog .woocommerce-ordering {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--20);
	margin: 0;
}

/* Below 768px the label is visually hidden (the select sits beside the filter button); it stays for assistive tech. */
.alatinidza-catalog .woocommerce-ordering label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.alatinidza-catalog .woocommerce-ordering select {
	max-width: 100%;
	min-height: var(--wp--custom--control-height);
	padding-block: 0;
	padding-inline: var(--wp--preset--spacing--30) var(--wp--preset--spacing--60);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--medium);
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--contrast-muted);
	border-radius: var(--wp--preset--border-radius--control);
}

/* Filter panel (sidebar from 1024px, drawer content below). */
.alatinidza-filters {
	--wc-product-filter-block-spacing: var(--wp--preset--spacing--50);
	color: var(--wp--preset--color--contrast);
}

.alatinidza-filters__title {
	margin: 0;
	font-size: var(--wp--preset--font-size--x-large);
}

.alatinidza-filters__group {
	padding-block-start: var(--wp--preset--spacing--40);
	border-block-start: 1px solid var(--wp--preset--color--border);
}

.alatinidza-filters .alatinidza-filters__heading {
	margin: 0 0 var(--wp--preset--spacing--20);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	line-height: 1.3;
}

/* Checkbox options: the whole row is the label (44px list target). */
.alatinidza-filters .wc-block-product-filter-checkbox-list__label {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--30);
	min-height: var(--wp--custom--touch-target);
	font-size: var(--wp--preset--font-size--medium);
	cursor: pointer;
}

.alatinidza-filters .wc-block-product-filter-checkbox-list__count {
	color: var(--wp--preset--color--contrast-muted);
	font-size: var(--wp--preset--font-size--small);
}

.alatinidza-filters .wc-block-product-filter-checkbox-list__show-more-button,
.alatinidza-filters .wc-block-product-filter__show-more {
	min-height: var(--wp--custom--touch-target);
	margin: 0;
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
}

/*
 * Price: the native slider above two equal "Od" / "Do" inputs. The inputs fill
 * their column so a seven-digit amount with the currency ("1.234.567 рсд") fits
 * at 375px and in the 17rem sidebar; 16px text also prevents iOS focus zoom.
 */
.alatinidza-filters .wc-block-product-filter-price-slider__content {
	grid-template-columns: repeat(2, minmax(0, 1fr));
	grid-template-areas:
		"price-slider price-slider"
		"left-input   right-input";
	gap: var(--wp--preset--spacing--30);
}

.alatinidza-filters .wc-block-product-filter-price-slider .text input[type="text"] {
	box-sizing: border-box;
	width: 100%;
	max-width: none;
	min-height: var(--wp--custom--control-height);
	padding-inline: var(--wp--preset--spacing--20);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--medium);
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--contrast-muted);
	border-radius: var(--wp--preset--border-radius--control);
}

/*
 * Slider: thin graphite track, the selected range in the brand accent and large
 * white handles (24px) with a graphite edge. WooCommerce removes the range
 * inputs' outline, so keyboard focus is a ring around the handle.
 */
.alatinidza-filters .wc-block-product-filter-price-slider__range {
	--wc-product-filter-price-slider: var(--wp--preset--color--accent);
	--alatinidza-price-handle: 1.5rem;
	margin-block: var(--wp--preset--spacing--40);
	border-radius: 2px;
}

.alatinidza-filters .wc-block-product-filter-price-slider__range::before {
	background: var(--wp--preset--color--graphite);
	border-radius: inherit;
	opacity: 1;
}

.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]::-webkit-slider-thumb {
	box-sizing: border-box;
	width: var(--alatinidza-price-handle);
	height: var(--alatinidza-price-handle);
	margin-block-start: calc(2px - var(--alatinidza-price-handle) / 2);
	background: var(--wp--preset--color--base);
	border: 2px solid var(--wp--preset--color--graphite);
	box-shadow: 0 1px 3px color-mix(in srgb, var(--wp--preset--color--contrast) 30%, transparent);
}

.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]::-moz-range-thumb {
	box-sizing: border-box;
	width: var(--alatinidza-price-handle);
	height: var(--alatinidza-price-handle);
	background: var(--wp--preset--color--base);
	border: 2px solid var(--wp--preset--color--graphite);
	box-shadow: 0 1px 3px color-mix(in srgb, var(--wp--preset--color--contrast) 30%, transparent);
}

/* WooCommerce turns the handle dark on hover and focus; it stays white here (the ring shows focus). */
.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]:is(:hover, :focus)::-webkit-slider-thumb {
	background: var(--wp--preset--color--base);
	border-color: var(--wp--preset--color--contrast);
}

.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]:is(:hover, :focus)::-moz-range-thumb {
	background: var(--wp--preset--color--base);
	border-color: var(--wp--preset--color--contrast);
}

.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]:focus-visible::-webkit-slider-thumb {
	box-shadow: 0 0 0 2px var(--wp--preset--color--base), 0 0 0 4px var(--wp--preset--color--contrast);
}

.alatinidza-filters .wc-block-product-filter-price-slider__range input[type="range"]:focus-visible::-moz-range-thumb {
	box-shadow: 0 0 0 2px var(--wp--preset--color--base), 0 0 0 4px var(--wp--preset--color--contrast);
}

/*
 * Sorting (alatinidza-core/catalog-sort): mutually exclusive links drawn as a
 * radio list, 44px rows. The active option has a filled marker and bold text
 * (not color alone); the plugin marks it with aria-current.
 */
.alatinidza-filters .alatinidza-core-sort__title {
	margin: 0 0 var(--wp--preset--spacing--20);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	line-height: 1.3;
}

.alatinidza-filters .alatinidza-core-sort__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.alatinidza-filters .alatinidza-core-sort__link {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--30);
	min-height: var(--wp--custom--touch-target);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--medium);
	text-decoration: none;
}

.alatinidza-filters .alatinidza-core-sort__link::before {
	content: "";
	flex: none;
	box-sizing: border-box;
	width: 1.25rem;
	height: 1.25rem;
	background-color: var(--wp--preset--color--base);
	border: 2px solid var(--wp--preset--color--contrast-muted);
	border-radius: 50%;
}

.alatinidza-filters .alatinidza-core-sort__link.is-active {
	font-weight: 600;
}

.alatinidza-filters .alatinidza-core-sort__link.is-active::before {
	border-color: var(--wp--preset--color--graphite);
	box-shadow: inset 0 0 0 3px var(--wp--preset--color--base);
	background-color: var(--wp--preset--color--graphite);
}

@media (hover: hover) {
	.alatinidza-filters .alatinidza-core-sort__link:hover {
		text-decoration: underline;
		text-decoration-color: var(--wp--preset--color--accent);
		text-decoration-thickness: 2px;
		text-underline-offset: 0.25em;
	}

	.alatinidza-filters .alatinidza-core-sort__link:hover::before {
		border-color: var(--wp--preset--color--graphite);
	}
}

/* "Filter products" button (drawer trigger, below 1024px). */
.alatinidza-filters .wc-block-product-filters__open-overlay {
	gap: var(--wp--preset--spacing--20);
	min-height: var(--wp--custom--control-height);
	padding-inline: var(--wp--preset--spacing--40);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--preset--border-radius--control);
	cursor: pointer;
}

.alatinidza-filters .wc-block-product-filters__open-overlay span,
.alatinidza-filters .wc-block-product-filters__close-overlay span {
	padding: 0;
}

/*
 * Drawer below 1024px. WooCommerce's native overlay only covers up to 600px and
 * becomes an inline panel above that (zero-specificity :where() rules), so the
 * drawer rules are restated here up to the approved 1024px breakpoint. This
 * max-width query is the one exception to the mobile-first rule: it only
 * extends WooCommerce's own mobile behavior; from 1024px WooCommerce's inline
 * panel applies unchanged. The drawer opens from the side (full width on phones).
 */
@media (max-width: 1023.98px) {
	.alatinidza-filters {
		display: inline-flex;
	}

	.alatinidza-filters .wc-block-product-filters__open-overlay {
		display: flex;
	}

	.alatinidza-filters .wc-block-product-filters__overlay {
		position: fixed;
		inset: 0;
		/*
		 * WooCommerce's --top-padding is the admin bar height above 782px, which is
		 * undefined for logged-out visitors; without the fallback the overlay would
		 * lose its top edge and collapse. Logged in, the admin bar offset still applies.
		 */
		inset-block-start: var(--top-padding, 0px);
		pointer-events: none;
		background-color: transparent;
	}

	.alatinidza-filters .wc-block-product-filters__overlay-wrapper {
		width: 100%;
		height: 100%;
	}

	.alatinidza-filters .wc-block-product-filters__overlay-dialog {
		position: absolute;
		inset: 0 0 0 auto;
		width: min(100%, 26.25rem);
		color: var(--wp--preset--color--contrast);
		background-color: var(--wp--preset--color--base);
		transform: translateX(100%);
		visibility: hidden;
	}

	.alatinidza-filters .wc-block-product-filters__overlay-header {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		padding: var(--wp--preset--spacing--20) var(--wp--preset--spacing--20) 0;
	}

	.alatinidza-filters .wc-block-product-filters__close-overlay {
		justify-content: center;
		gap: var(--wp--preset--spacing--10);
		min-width: var(--wp--custom--control-height);
		min-height: var(--wp--custom--control-height);
		padding-inline: var(--wp--preset--spacing--20);
		font-size: var(--wp--preset--font-size--medium);
		font-weight: 600;
		border-radius: var(--wp--preset--border-radius--control);
		cursor: pointer;
	}

	.alatinidza-filters .wc-block-product-filters__overlay-content {
		overflow-y: auto;
		padding: 0 var(--wp--preset--spacing--40) var(--wp--preset--spacing--40);
		overscroll-behavior: contain;
	}

	/* Sticky action at the bottom of the drawer (native "Apply" closes it; filters apply as they change). */
	.alatinidza-filters .wc-block-product-filters__overlay-footer {
		display: block;
		padding: var(--wp--preset--spacing--30) var(--wp--preset--spacing--40);
		border-block-start: 1px solid var(--wp--preset--color--border);
		box-shadow: none;
	}

	.alatinidza-filters.is-overlay-opened .wc-block-product-filters__overlay {
		z-index: 100000;
		pointer-events: auto;
		background-color: color-mix(in srgb, var(--wp--preset--color--contrast) 50%, transparent);
	}

	.alatinidza-filters.is-overlay-opened .wc-block-product-filters__overlay-dialog {
		transform: none;
		visibility: visible;
	}

	/* The sort control takes the rest of the first row. */
	.alatinidza-catalog .wc-block-catalog-sorting,
	.alatinidza-catalog .woocommerce-ordering,
	.alatinidza-catalog .woocommerce-ordering select {
		width: 100%;
	}
}

@media (max-width: 1023.98px) and (prefers-reduced-motion: no-preference) {
	.alatinidza-filters .wc-block-product-filters__overlay-dialog {
		transition: transform 0.25s ease, visibility 0.25s;
	}
}

/* Active filter chips and "Clear all" (native Active Filters block). */
.alatinidza-active-filters .wp-block-woocommerce-product-filter-active {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--wp--preset--spacing--20);
}

.alatinidza-active-filters .wp-block-woocommerce-product-filter-active[hidden] {
	display: none;
}

.alatinidza-active-filters .wc-block-product-filter-removable-chips__items {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--20);
	margin: 0;
	padding: 0;
	list-style: none;
}

.alatinidza-active-filters .wc-block-product-filter-removable-chips__item {
	display: inline-flex;
	align-items: center;
	min-height: var(--wp--custom--touch-target);
	padding-inline-start: var(--wp--preset--spacing--30);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--preset--border-radius--control);
}

.alatinidza-active-filters .wc-block-product-filter-removable-chips__remove {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	align-self: stretch;
	min-width: var(--wp--custom--touch-target);
	min-height: calc(var(--wp--custom--touch-target) - 2px);
	padding: 0;
	color: inherit;
	background: none;
	border: 0;
	border-radius: var(--wp--preset--border-radius--control);
	cursor: pointer;
}

.alatinidza-active-filters .wc-block-product-filter-removable-chips__remove-icon {
	width: 1.25rem;
	height: 1.25rem;
	fill: currentColor;
}

.alatinidza-active-filters .wp-block-buttons {
	margin: 0;
}

.alatinidza-active-filters .alatinidza-active-filters__clear .wp-block-button__link {
	min-height: var(--wp--custom--touch-target);
	padding: 0 var(--wp--preset--spacing--20);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	text-decoration: underline;
	background: none;
	border: 0;
}

.alatinidza-active-filters .alatinidza-active-filters__clear .wp-block-button__link:hover {
	text-decoration: none;
}

/* Product grid (native Product Template with Product Card V1): 2 columns, 3 from 1024px (sidebar), 4 from 1280px. */
.alatinidza-catalog .wc-block-product-template.wc-block-product-template {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--wp--preset--spacing--50) var(--wp--preset--spacing--40);
	margin: 0;
	padding: 0;
	list-style: none;
}

.alatinidza-catalog .wc-block-product-template > li {
	width: auto;
	max-width: none;
	margin: 0;
}

/* Pagination: numbered, real links; 44px targets. */
.alatinidza-pagination {
	gap: var(--wp--preset--spacing--20);
	margin-block-start: var(--wp--preset--spacing--70);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
}

.alatinidza-pagination .wp-block-query-pagination-numbers {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--wp--preset--spacing--20);
}

.alatinidza-pagination .page-numbers,
.alatinidza-pagination .wp-block-query-pagination-previous,
.alatinidza-pagination .wp-block-query-pagination-next {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: var(--wp--custom--touch-target);
	min-height: var(--wp--custom--touch-target);
	margin: 0;
	padding-inline: var(--wp--preset--spacing--20);
	color: var(--wp--preset--color--contrast);
	text-decoration: none;
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--preset--border-radius--control);
}

.alatinidza-pagination .page-numbers.dots {
	background: none;
	border-color: transparent;
}

/* Current page: filled and bold (not color alone); core marks it with aria-current="page". */
.alatinidza-pagination .page-numbers.current {
	color: var(--wp--preset--color--base);
	background-color: var(--wp--preset--color--graphite);
	border-color: var(--wp--preset--color--graphite);
}

@media (hover: hover) {
	.alatinidza-pagination a:hover {
		border-color: var(--wp--preset--color--contrast-muted);
	}
}

/* Empty / no-results state. */
.alatinidza-catalog__empty {
	padding: var(--wp--preset--spacing--60) var(--wp--preset--spacing--40);
	text-align: center;
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--preset--border-radius--card);
}

.alatinidza-catalog__empty > * {
	margin-block: 0;
}

.alatinidza-catalog__empty > * + * {
	margin-block-start: var(--wp--preset--spacing--30);
}

.alatinidza-catalog__empty .alatinidza-catalog__empty-title {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--xx-large);
	font-weight: 700;
	line-height: 1.2;
}

.alatinidza-catalog__empty .wp-block-buttons {
	justify-content: center;
	margin-block-start: var(--wp--preset--spacing--40);
}

/* "Clear filters": WooCommerce's clear button inside a drawer-less Product Filters block; same spacing as a direct button row. */
.alatinidza-catalog__empty > .alatinidza-catalog__empty-clear {
	margin-block-start: 0;
}

@media (min-width: 600px) {
	.alatinidza-catalog .wc-block-product-template.wc-block-product-template {
		gap: var(--wp--preset--spacing--60) var(--wp--preset--spacing--50);
	}

	/* The sort control keeps its natural width once there is room. */
	.alatinidza-catalog__layout {
		grid-template-columns: auto minmax(0, 1fr) auto;
		grid-template-areas:
			"filters count   sorting"
			"active  active  active"
			"products products products";
	}

	.alatinidza-catalog .wc-block-catalog-sorting,
	.alatinidza-catalog .woocommerce-ordering,
	.alatinidza-catalog .woocommerce-ordering select {
		width: auto;
	}
}

/* The visible "Sort by" label needs the room of 768px (the result count stays on one line). */
@media (min-width: 768px) {
	.alatinidza-catalog .woocommerce-ordering label {
		position: static;
		width: auto;
		height: auto;
		overflow: visible;
		clip-path: none;
		font-size: var(--wp--preset--font-size--small);
		font-weight: 600;
	}
}

@media (min-width: 1024px) {
	/* The sidebar column exists only while at least one filter group has options. */
	.alatinidza-catalog__layout:has(.alatinidza-filters__group:not(.wc-block-product-filter--hidden, .alatinidza-core-sort)) {
		grid-template-columns: 17rem minmax(0, 1fr) auto;
		grid-template-rows: auto auto 1fr;
		grid-template-areas:
			"filters count    sorting"
			"filters active   active"
			"filters products products";
		column-gap: var(--wp--preset--spacing--60);
	}

	.alatinidza-catalog__filters {
		align-self: start;
	}

	.alatinidza-filters {
		gap: var(--wp--preset--spacing--40);
	}

	.alatinidza-catalog .wc-block-product-template.wc-block-product-template {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

@media (min-width: 1280px) {
	.alatinidza-catalog .wc-block-product-template.wc-block-product-template {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}
