/*
 * Product lists: shop page (/proizvodi/) and category pages (phase 4).
 * Loaded only on those pages (functions.php).
 */

/* Breadcrumbs: in components.css, so product pages get them too. */

/* ---------- Section 1: title, count, sorting ---------- */

.shop-header {
	margin-bottom: var(--space-xl);
}

.shop-header__title {
	margin: 0;
	font-size: var(--text-title1);
	font-weight: var(--font-weight-bold);
	line-height: 1.2;
	letter-spacing: -0.01em;
}

/* Bar under the title: count on the left, sorting on the right, thin line below
   (same line as under the product images and the header). */
.shop-header__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-xs) var(--space-md);
	margin-top: var(--space-md);
	padding-bottom: var(--space-sm);
	border-bottom: 1px solid var(--color-border);
}

.shop-header__count {
	margin: 0;
	font-size: var(--text-subheadline);
	color: var(--color-text-secondary);
}

/* WooCommerce floats the sorting form; here it sits in the flex bar. */
.woocommerce .shop-header .woocommerce-ordering,
.shop-sort {
	display: flex;
	align-items: center;
	gap: var(--space-xs);
	float: none;
	margin: 0;
}

.shop-sort__label {
	margin: 0;
	font-size: var(--text-subheadline);
	font-weight: var(--font-weight-regular);
	color: var(--color-text-secondary);
}

.woocommerce .shop-header .woocommerce-ordering select,
.shop-sort__select {
	width: auto;
	min-height: var(--size-button-small);
	padding-left: var(--space-sm);
	font-size: var(--text-subheadline);
	font-weight: var(--font-weight-semibold);
	cursor: pointer;
}

.shop-sort__apply {
	min-height: var(--size-button-small);
}

/* ---------- Section 4: category description and chips ---------- */

/* Description the client writes for a category (none yet) or on the shop page. */
.shop-header .term-description,
.shop-header .page-description {
	max-width: 72ch;
	margin-top: var(--space-sm);
	color: var(--color-text-secondary);
	font-size: var(--text-body);
	line-height: 1.6;
}

.shop-header .term-description > :last-child,
.shop-header .page-description > :last-child {
	margin-bottom: 0;
}

/*
 * Chips like on the home page ("Najčešće naručivano"): grey, selected one red.
 * Phones: one row that scrolls sideways to the screen edges; from 768px they wrap.
 */
.shop-chips {
	margin: var(--space-md) calc(var(--gutter) * -1) 0;
}

.shop-chips__list {
	display: flex;
	gap: var(--space-xs);
	margin: 0;
	padding: 2px var(--gutter);
	overflow-x: auto;
	list-style: none;
	scroll-padding-inline: var(--gutter);
	scrollbar-width: none;
}

.shop-chips__list::-webkit-scrollbar {
	display: none;
}

.shop-chips__list > li {
	flex-shrink: 0;
}

.shop-chips__chip {
	border-color: transparent;
	background: var(--color-background-secondary);
}

.shop-chips__chip:hover {
	background: var(--color-border);
}

.shop-chips__chip.is-selected:hover {
	background: var(--color-selected);
	color: var(--color-on-selected);
}

/* 36px chip, 44px touch area. */
.shop-chips__chip {
	position: relative;
}

.shop-chips__chip::after {
	content: "";
	position: absolute;
	inset: -4px 0;
}

/* /proizvodi/: from 768px the category strip above already shows the categories
   (same rule as the home page categories). */
@media (min-width: 768px) {
	.shop-chips--categories {
		display: none;
	}
}

/* From 1024px the column on the left shows the (sub)categories instead of chips
   (variant A, chips wrapped into three rows on "Vrećice"). */
@media (min-width: 1024px) {
	.shop-chips {
		display: none;
	}
}

/* ---------- Section 4 (variant A): two columns and the column on the left ---------- */

/*
 * More air ("da ovo malo više diše", too many letters):
 * wider column so fewer names wrap, taller rows, names in grey (black on hover),
 * counts as small grey pills, the current row on a light red background.
 */
@media (min-width: 1024px) {
	.shop-layout {
		display: grid;
		grid-template-columns: 272px minmax(0, 1fr);
		gap: 48px;
		align-items: start;
	}
}

/* Below 1024px only the list is shown; chips and the bar take over. */
.shop-sidebar {
	display: none;
}

/*
 * Sticky column: it stays in view while the list scrolls, so the
 * subcategories and "Samo na stanju" are always at hand. The header is not sticky, so
 * 24px from the top of the window is enough. A column taller than the window (many
 * subcategories on a low screen) scrolls on its own instead of being cut off.
 */
@media (min-width: 1024px) {
	.shop-sidebar {
		position: sticky;
		top: var(--space-xl);
		display: block;
		max-height: calc(100vh - 2 * var(--space-xl));
		max-height: calc(100dvh - 2 * var(--space-xl));
		/* Room for the row hover background, which reaches 12px past the names. */
		margin-inline: calc(var(--space-sm) * -1);
		padding: var(--space-xxs) var(--space-sm) var(--space-xs);
		overflow-y: auto;
		overscroll-behavior: contain;
		scrollbar-width: thin;
		scrollbar-color: var(--color-separator) transparent;
	}
}

.shop-sidebar__group + .shop-sidebar__group {
	margin-top: var(--space-xl);
	padding-top: var(--space-xl);
	border-top: 1px solid var(--color-border);
}

.shop-sidebar__title {
	margin: 0 0 var(--space-sm);
	font-size: var(--text-headline);
	font-weight: var(--font-weight-bold);
	color: var(--color-text-primary);
}

.shop-sidebar__list {
	display: flex;
	flex-direction: column;
	gap: 2px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.shop-sidebar__link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-md);
	min-height: 40px;
	margin-inline: calc(var(--space-sm) * -1);
	padding: var(--space-xs) var(--space-sm);
	border-radius: var(--radius-sm);
	color: var(--color-text-secondary);
	font-size: var(--text-subheadline);
	line-height: 1.3;
	text-decoration: none;
	text-wrap: pretty;
	transition: background-color var(--transition-fast), color var(--transition-fast);
}

.shop-sidebar__link:hover {
	background: var(--color-background-secondary);
	color: var(--color-text-primary);
}

.shop-sidebar__link.is-current,
.shop-sidebar__link.is-current:hover {
	background: var(--color-button-tinted);
	color: var(--color-on-button-tinted);
	font-weight: var(--font-weight-semibold);
}

.shop-sidebar__count {
	flex-shrink: 0;
	min-width: 28px;
	padding: 2px var(--space-xs);
	border-radius: var(--radius-full);
	background: var(--color-background-secondary);
	color: var(--color-text-secondary);
	font-size: var(--text-caption);
	font-weight: var(--font-weight-semibold);
	line-height: 1.4;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.shop-sidebar__link.is-current .shop-sidebar__count {
	background: var(--color-background);
	color: var(--color-on-button-tinted);
}

/* "Samo na stanju" in the column: same grey as the names. */
.shop-stock--sidebar .shop-stock__label {
	color: var(--color-text-secondary);
}

/* ---------- Section 5: "Samo na stanju" checkbox ---------- */

/* Controls on the right of the bar: checkbox (below 1024px) and sorting. */
.shop-header__controls {
	display: flex;
	align-items: center;
	gap: var(--space-sm) var(--space-lg);
}

/* Plain checkbox with its label (theme checkbox: 20px, red when ticked). */
.shop-stock {
	margin: 0;
}

.shop-stock__label {
	font-size: var(--text-subheadline);
	color: var(--color-text-primary);
}

.shop-stock__apply {
	min-height: var(--size-button-small);
	margin-top: var(--space-xs);
}

/* From 1024px the checkbox is in the column on the left only. */
@media (min-width: 1024px) {
	.shop-stock--bar {
		display: none;
	}
}

@media (max-width: 767px) {
	.shop-header__controls {
		flex: 1 1 100%;
		justify-content: space-between;
	}

	/* Sorting takes the rest of the row; a long choice is cut by the select itself. */
	.woocommerce .shop-header .woocommerce-ordering,
	.shop-sort {
		flex: 1 1 auto;
		justify-content: flex-end;
		min-width: 0;
	}

	.woocommerce .shop-header .woocommerce-ordering select,
	.shop-sort__select {
		width: 100%;
		max-width: 220px;
		min-width: 0;
	}

	.shop-stock {
		flex-shrink: 0;
	}
}

/* ---------- Section 2: product grid ---------- */

/*
 * Same card as on the home page. 2 columns on phones (cards about 165px, like the
 * app's 160px), 4 from 768px, 3 from 1024px next to the column on the left.
 * The selectors are long on purpose: WooCommerce's own list CSS (floats, widths,
 * clearfix) has to be switched off here.
 */
.woocommerce ul.products.product-grid,
.product-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--space-sm);
	margin: 0 0 var(--space-xxl);
	padding: 0;
	list-style: none;
}

.woocommerce ul.products.product-grid::before,
.woocommerce ul.products.product-grid::after {
	display: none;
}

.woocommerce ul.products.product-grid li.product.product-grid__item {
	float: none;
	clear: none;
	width: auto;
	margin: 0;
	padding: 0;
}

/* WooCommerce sizes list images itself (height: auto, margin below); the card needs its own. */
.woocommerce ul.products.product-grid li.product .product-card__image img {
	height: 100%;
	margin: 0;
	box-shadow: none;
}

@media (min-width: 768px) {
	.woocommerce ul.products.product-grid,
	.product-grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
		gap: var(--space-md);
	}
}

/* From 1024px the column on the left takes 320px (272 + gap), so 3 cards per row (about 260px each,
   the same size as on the home page). */
@media (min-width: 1024px) {
	.woocommerce ul.products.product-grid,
	.product-grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: var(--space-xl);
	}
}

/* ---------- Section 3: pagination ---------- */

/*
 * Round 44px buttons without frames (instead of WooCommerce's boxed row).
 * Current page: filled red like a selected chip; previous/next: tinted red with an arrow;
 * other numbers: plain, grey circle on hover. Phones: arrows and "Stranica 5 od 29".
 */
.woocommerce nav.woocommerce-pagination.shop-pagination,
.shop-pagination {
	margin: 0 0 var(--space-xxl);
	text-align: initial;
}

.shop-pagination__list,
.woocommerce nav.woocommerce-pagination.shop-pagination ul {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var(--space-xxs);
	margin: 0;
	padding: 0;
	border: 0;
	list-style: none;
	white-space: normal;
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li {
	float: none;
	display: block;
	margin: 0;
	padding: 0;
	border: 0;
	overflow: visible;
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: var(--size-touch-target);
	height: var(--size-touch-target);
	margin: 0;
	padding: 0 var(--space-xs);
	border-radius: var(--radius-full);
	background: transparent;
	color: var(--color-text-primary);
	font-size: var(--text-subheadline);
	font-weight: var(--font-weight-semibold);
	line-height: 1;
	text-decoration: none;
	transition: background-color var(--transition-fast), color var(--transition-fast);
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li a.page-numbers:hover,
.woocommerce nav.woocommerce-pagination.shop-pagination ul li a.page-numbers:focus-visible {
	background: var(--color-background-secondary);
	color: var(--color-text-primary);
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li span.page-numbers.current {
	background: var(--color-selected);
	color: var(--color-on-selected);
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li span.page-numbers.dots {
	min-width: 24px;
	padding: 0;
	color: var(--color-text-tertiary);
}

/* Previous / next: tinted red circles, a little apart from the numbers. */
.shop-pagination__item--prev {
	margin-right: var(--space-xs);
}

.shop-pagination__item--next {
	margin-left: var(--space-xs);
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li .page-numbers.prev,
.woocommerce nav.woocommerce-pagination.shop-pagination ul li .page-numbers.next {
	width: var(--size-touch-target);
	padding: 0;
	background: var(--color-button-tinted);
	color: var(--color-on-button-tinted);
}

.woocommerce nav.woocommerce-pagination.shop-pagination ul li a.page-numbers.prev:hover,
.woocommerce nav.woocommerce-pagination.shop-pagination ul li a.page-numbers.next:hover {
	background: var(--color-button-tinted-pressed);
	color: var(--color-on-button-tinted-pressed);
}

/* First / last page: the missing arrow is grey and inactive. */
.woocommerce nav.woocommerce-pagination.shop-pagination ul li .page-numbers.is-disabled {
	width: var(--size-touch-target);
	padding: 0;
	background: var(--color-background-secondary);
	color: var(--color-text-tertiary);
}

/* WooCommerce pads every span in the pagination (.5em); the arrow span needs none. */
.woocommerce nav.woocommerce-pagination.shop-pagination ul li .shop-pagination__arrow,
.shop-pagination .shop-pagination__arrow svg {
	display: block;
	flex: none;
	width: 22px;
	height: 22px;
	padding: 0;
	min-width: 0;
	border: 0;
}

.shop-pagination__arrow--prev {
	transform: scaleX(-1);
}

/* "Stranica 5 od 29": phones only. */
.woocommerce nav.woocommerce-pagination.shop-pagination ul li.shop-pagination__item--status {
	display: none;
	padding-inline: var(--space-sm);
	font-size: var(--text-subheadline);
	color: var(--color-text-secondary);
}

@media (max-width: 479px) {
	.woocommerce nav.woocommerce-pagination.shop-pagination ul li.shop-pagination__item--number,
	.woocommerce nav.woocommerce-pagination.shop-pagination ul li.shop-pagination__item--dots {
		display: none;
	}

	.woocommerce nav.woocommerce-pagination.shop-pagination ul li.shop-pagination__item--status {
		display: block;
	}

	.shop-pagination__item--prev,
	.shop-pagination__item--next {
		margin-inline: 0;
	}
}

/* Narrow phones: the "Sortiraj" label is read by screen readers only, so the count
   and the sorting fit in one row (the selected option already says what it is). */
@media (max-width: 479px) {
	.shop-sort__label {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(1px, 1px, 1px, 1px);
		white-space: nowrap;
	}
}

@media (min-width: 768px) {
	.shop-header__title {
		font-size: var(--text-large-title);
	}
}

/* ---------- Section 7: empty list ---------- */

/* Styles of the empty state are shared (components.css: .shop-empty), also used by the empty cart. */

/* ---------- Category header picture ---------- */

/*
 * Full-width band under the category strip, in the category's own colour (taken from the
 * picture's flat background). Computers: breadcrumbs and title on the left; the picture
 * (4 : 1) is as tall as the band and anchored to the content's right line, moved right by
 * its empty right margin (3 %), so the products end on that line like the home banners.
 */
.has-category-header .site-main {
	padding-top: 0;
}

.category-header {
	position: relative;
	overflow: hidden;
	margin-bottom: var(--space-xl);
	background: var(--category-header-bg, var(--color-background-secondary));
}

.category-header__media picture {
	display: contents;
}

.category-header__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.category-header__inner {
	position: relative;
	padding-block: var(--space-md) var(--space-lg);
}

.category-header .breadcrumbs {
	margin-bottom: 0;
	color: var(--color-text-secondary);
}

.category-header .breadcrumbs a {
	color: var(--color-text-secondary);
}

.category-header .breadcrumbs__item + .breadcrumbs__item::before {
	background-color: var(--color-text-secondary);
}

.category-header__title {
	margin: 0;
	color: var(--color-text-primary);
	font-size: var(--text-title1);
	font-weight: var(--font-weight-bold);
	line-height: 1.15;
	letter-spacing: -0.015em;
	text-wrap: balance;
}

/* Short description and "37 proizvoda · 7 vrsta" under the title (short titles left the band looking empty). */
.category-header__text {
	margin: var(--space-xs) 0 0;
	color: var(--color-text-secondary);
	font-size: var(--text-body);
	line-height: 1.45;
	text-wrap: pretty;
}

.category-header__facts {
	margin: var(--space-sm) 0 0;
	color: var(--color-text-primary);
	font-size: var(--text-footnote);
	font-weight: var(--font-weight-semibold);
}

/*
 * Phones: the phone picture (2 : 1, products in the top half) is the background of the
 * whole band; breadcrumbs and title sit on its empty bottom part, so there is no edge
 * between picture and text (like the home banners on phones).
 */
@media (max-width: 767px) {
	.category-header {
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		/* At least 2 : 1 like the picture; a min-height (not aspect-ratio, which the
		   hidden overflow would keep fixed) lets a long title make it taller. */
		min-height: 50vw;
	}

	.category-header__media {
		position: absolute;
		inset: 0;
	}

	.category-header__image {
		object-position: center top;
	}

	/* Text starts below the products (they end at about 55 % of the picture's height).
	   A longer title makes the band taller instead of running into the products. */
	.category-header__inner {
		flex-shrink: 0;
		padding-block: 28% var(--space-sm);
	}

	.category-header .breadcrumbs__item {
		min-height: 32px;
	}

	/* The last crumb is the title right below it (as on the product page on phones). */
	.category-header .breadcrumbs__item:last-child {
		display: none;
	}

	.category-header__title {
		font-size: var(--text-title2);
	}
}

@media (min-width: 768px) {
	.category-header {
		display: flex;
		align-items: center;
		min-height: clamp(200px, 19vw, 280px);
	}

	.category-header__media {
		position: absolute;
		top: 0;
		right: max(var(--gutter), calc((100% - var(--container-max)) / 2 + var(--gutter)));
		bottom: 0;
		aspect-ratio: 4 / 1;
		transform: translateX(3%);
		-webkit-mask-image: linear-gradient(to right, transparent 0, #000 30%, #000 96%, transparent 100%);
		mask-image: linear-gradient(to right, transparent 0, #000 30%, #000 96%, transparent 100%);
	}

	.category-header__inner {
		width: 100%;
		padding-block: var(--space-lg);
	}

	/* Title and text in the left half, where the picture is empty. */
	.category-header__text {
		max-width: 52%;
	}

	.category-header__title {
		max-width: 55%;
		font-size: clamp(var(--text-title1), 3.2vw, 2.75rem);
	}
}
