/*
 * Product page (phase 5). Loaded only on product pages (functions.php).
 */

/* ---------- Section 1: layout and image ---------- */

/*
 * Two columns from 900px: image on the left, name, price and cart on the right; the
 * description and similar products below span both. Phones: image on top.
 * WooCommerce floats the two halves at 48%; here they sit in a grid.
 */
.woocommerce div.product {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--space-xl);
	margin-top: var(--space-sm);
}

.woocommerce div.product > * {
	grid-column: 1 / -1;
}

@media (min-width: 900px) {
	.woocommerce div.product {
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		column-gap: 48px;
		row-gap: var(--space-xxxl);
	}

	.woocommerce div.product > div.images {
		grid-column: 1;
	}

	.woocommerce div.product > div.summary {
		grid-column: 2;
	}
}

.woocommerce div.product div.images,
.woocommerce div.product div.summary {
	float: none;
	width: auto;
	margin: 0;
}

/*
 * The image like on the app's product screen and the product cards: square, white,
 * thin frame, 16px corners, the whole photo with room around it ("contain"). Shop
 * photos come in many proportions (1080×1080, 1536×2048, 1920×1080…), all fit uncut.
 */
.woocommerce div.product div.images .woocommerce-product-gallery__wrapper {
	margin: 0;
}

.woocommerce div.product div.images .woocommerce-product-gallery__image {
	position: relative;
	aspect-ratio: 1;
	overflow: hidden;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-lg);
	background: var(--color-background);
}

.woocommerce div.product div.images .woocommerce-product-gallery__image a {
	display: block;
	width: 100%;
	height: 100%;
	padding: var(--space-xl);
	cursor: zoom-in;
}

.woocommerce div.product div.images .woocommerce-product-gallery__image img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	transition: transform 300ms ease-out;
}

.woocommerce div.product div.images .woocommerce-product-gallery__image a:hover img {
	transform: scale(1.02);
}

/* A small round "enlarge" sign in the corner (theme magnifier icon), so it is clear
   the image opens big. ::before is the white circle, ::after the icon. */
.woocommerce div.product div.images .woocommerce-product-gallery__image a::before,
.woocommerce div.product div.images .woocommerce-product-gallery__image a::after {
	content: "";
	position: absolute;
	right: var(--space-sm);
	bottom: var(--space-sm);
	z-index: 1;
	width: 40px;
	height: 40px;
	pointer-events: none;
}

.woocommerce div.product div.images .woocommerce-product-gallery__image a::before {
	border: 1px solid var(--color-border);
	border-radius: var(--radius-full);
	background: var(--color-background);
}

.woocommerce div.product div.images .woocommerce-product-gallery__image a::after {
	background-color: var(--color-text-primary);
	-webkit-mask: url("../icons/search.svg") center / 20px 20px no-repeat;
	mask: url("../icons/search.svg") center / 20px 20px no-repeat;
}

.woocommerce div.product div.images .woocommerce-product-gallery__image a:focus-visible {
	outline: 2px solid var(--color-selected);
	outline-offset: -2px;
	border-radius: var(--radius-lg);
}

/* More photos later (the client can add them): small square thumbnails under the image. */
.woocommerce div.product div.images .flex-control-thumbs {
	display: grid;
	grid-template-columns: repeat(5, minmax(0, 1fr));
	gap: var(--space-xs);
	margin: var(--space-sm) 0 0;
	padding: 0;
	list-style: none;
}

.woocommerce div.product div.images .flex-control-thumbs li {
	float: none;
	width: auto;
	margin: 0;
}

.woocommerce div.product div.images .flex-control-thumbs img {
	aspect-ratio: 1;
	padding: var(--space-xxs);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	background: var(--color-background);
	object-fit: contain;
	opacity: 1;
	cursor: pointer;
}

.woocommerce div.product div.images .flex-control-thumbs img.flex-active {
	border-color: var(--color-selected);
}

@media (prefers-reduced-motion: reduce) {
	.woocommerce div.product div.images .woocommerce-product-gallery__image img {
		transition: none;
	}
}

/* ---------- Section 2: name, code, category, price, stock ---------- */

/* Like the app's product screen: bold name, quiet line below, big price with a badge. */
.product-head {
	margin-bottom: var(--space-xxl);
}

.product-head__title {
	margin: 0;
	font-size: var(--text-title2);
	font-weight: var(--font-weight-bold);
	line-height: 1.25;
	letter-spacing: -0.01em;
	text-wrap: pretty;
}

/* "Šifra 09-08-0201 · Fišeci" */
.product-head__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-xxs) var(--space-xs);
	margin: var(--space-sm) 0 0;
	color: var(--color-text-secondary);
	font-size: var(--text-subheadline);
}

.product-head__sku .sku {
	color: var(--color-text-primary);
	font-weight: var(--font-weight-semibold);
	font-variant-numeric: tabular-nums;
}

.product-head__sku + .product-head__category::before {
	content: "·";
	margin-right: var(--space-xs);
	color: var(--color-text-tertiary);
}

.product-head__category {
	color: var(--color-text-secondary);
	text-decoration: underline;
	text-decoration-color: var(--color-separator);
	text-underline-offset: 3px;
}

.product-head__category:hover {
	color: var(--color-primary-pressed);
	text-decoration-color: currentColor;
}

.product-head__price-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-xs) var(--space-sm);
	margin-top: var(--space-xl);
}

/* WooCommerce colours prices green-grey; here they are plain and bold, 28px like a headline. */
.woocommerce div.product .product-head__price.price,
.product-head__price {
	margin: 0;
	color: var(--color-text-primary);
	font-size: var(--text-title1);
	font-weight: var(--font-weight-bold);
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}

.product-head__price .woocommerce-Price-amount,
.product-head__price ins {
	color: inherit;
	text-decoration: none;
}

.product-head__price del {
	margin-right: var(--space-xs);
	color: var(--color-text-tertiary);
	font-size: var(--text-headline);
	font-weight: var(--font-weight-regular);
}

/* Badges as on the product cards; "Na stanju" a little darker to read next to the big price. */
.product-head__stock.badge--neutral {
	color: var(--color-text-primary);
}

@media (min-width: 900px) {
	.product-head__title {
		font-size: var(--text-title1);
	}
}

/* Phones: the product name is right under the breadcrumbs, so the last crumb (the same
   name) is left out there and the breadcrumbs stay on one line. */
@media (max-width: 767px) {
	.single-product .breadcrumbs__item:last-child {
		display: none;
	}
}

/*
 * More air in the right column:
 * the name uses the whole column width (no balanced, shorter lines), and the groups
 * (name, price, short description, cart) have clear gaps. From 900px the column starts
 * a little lower, in line with the photo inside its frame.
 */
.woocommerce div.product .woocommerce-product-details__short-description {
	margin-bottom: var(--space-xxl);
	color: var(--color-text-secondary);
	line-height: 1.6;
}

.woocommerce div.product .woocommerce-product-details__short-description > :last-child {
	margin-bottom: 0;
}

@media (min-width: 900px) {
	.woocommerce div.product > div.summary {
		padding-top: var(--space-xs);
	}
}

/* ---------- Packaging and measures ---------- */

/*
 * One card with the filled-in facts side by side (Pakovanje, Dimenzije, Zapremina,
 * Debljina): icon, small label, value. The 1px gap on the border colour draws the lines
 * between them, so every cell in a row has the same height. Two per row on phones.
 */
.product-facts {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1px;
	margin: 0 0 var(--space-xxl);
	padding: 0;
	overflow: hidden;
	list-style: none;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-lg);
	background: var(--color-border);
}

.product-facts--1 {
	grid-template-columns: minmax(0, 1fr);
}

/* Three on phones: the last one takes the whole second row (no empty grey cell). */
.product-facts--3 .product-facts__item:last-child {
	grid-column: 1 / -1;
}

@media (min-width: 600px) {
	.product-facts--3 {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.product-facts--3 .product-facts__item:last-child {
		grid-column: auto;
	}

	.product-facts--4 {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

.product-facts__item {
	display: flex;
	flex-direction: column;
	gap: var(--space-sm);
	margin: 0;
	padding: var(--space-md);
	background: var(--color-background);
}

.product-facts__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: var(--radius-full);
	background: var(--color-primary-subtle);
	color: var(--color-primary);
}

.product-facts__icon svg {
	width: 20px;
	height: 20px;
}

.product-facts__text {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.product-facts__label {
	color: var(--color-text-secondary);
	font-size: var(--text-footnote);
}

.product-facts__value {
	font-weight: var(--font-weight-semibold);
	font-variant-numeric: tabular-nums;
	overflow-wrap: anywhere;
}

/* ---------- Section 3: packaging, quantity, total, "Dodaj u korpu" ---------- */

/*
 * Like the app's bottom bar on the product screen, as one framed block in the column:
 * "Ukupno" with the total on top, quantity − / + and the red button in one row below.
 */
.product-buy {
	margin-bottom: var(--space-xxl);
	padding: var(--space-lg);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-lg);
	background: var(--color-background);
}

.woocommerce div.product form.cart.product-buy__form {
	margin: 0;
}

/* WooCommerce floats the field and the button; here they sit in a flex row. */
.woocommerce div.product form.cart.product-buy__form::before,
.woocommerce div.product form.cart.product-buy__form::after {
	display: none;
}

.product-buy__packaging {
	display: flex;
	align-items: center;
	gap: var(--space-xs);
	margin: 0 0 var(--space-md);
	padding: var(--space-sm) var(--space-md);
	border-radius: var(--radius-md);
	background: var(--color-background-secondary);
	font-size: var(--text-subheadline);
}

.product-buy__packaging svg {
	flex-shrink: 0;
	width: 22px;
	height: 22px;
	color: var(--color-primary);
}

.product-buy__total {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-md);
	margin: 0 0 var(--space-md);
}

.product-buy__total-label {
	color: var(--color-text-secondary);
	font-size: var(--text-subheadline);
}

.product-buy__total-value {
	font-size: var(--text-title3);
	font-weight: var(--font-weight-bold);
	font-variant-numeric: tabular-nums;
}

.product-buy__total-value .woocommerce-Price-amount {
	color: inherit;
}

.product-buy__row {
	display: flex;
	align-items: stretch;
	gap: var(--space-sm);
}

/* The button takes the rest of the row, with the cart icon like on the product cards. */
.woocommerce div.product form.cart .button.product-buy__add,
.product-buy__add {
	display: inline-flex;
	flex: 1;
	align-items: center;
	justify-content: center;
	gap: var(--space-xs);
	float: none;
	min-height: var(--size-button);
	margin: 0;
}

.product-buy__add svg {
	width: 22px;
	height: 22px;
}

/* Out of stock / no price: grey, inactive (theme disabled button) and a line with the phone. */
.product-buy__ask {
	margin: var(--space-sm) 0 0;
	color: var(--color-text-secondary);
	font-size: var(--text-subheadline);
	text-align: center;
}

.product-buy__ask a {
	font-weight: var(--font-weight-semibold);
	white-space: nowrap;
}

/* The label stays on one line. Phones: a little less padding in the block, and below
   420px the button shows only the text (the cart icon would push it to two lines). */
.product-buy__add {
	white-space: nowrap;
}

@media (max-width: 599px) {
	.product-buy {
		padding: var(--space-md);
	}
}

@media (max-width: 419px) {
	.product-buy__add svg {
		display: none;
	}
}

/* ---------- Section 4: specifications and description ---------- */

/* Plain sections under the cart (no WooCommerce tabs), each with a small heading. */
.product-details__section + .product-details__section {
	margin-top: var(--space-xxl);
}

.product-details__title {
	margin: 0 0 var(--space-sm);
	font-size: var(--text-headline);
	font-weight: var(--font-weight-bold);
}

/* Specifications: label on the left in grey, value on the right, thin lines between rows. */
.spec-list {
	margin: 0;
	border-top: 1px solid var(--color-border);
}

.spec-list__row {
	display: flex;
	justify-content: space-between;
	gap: var(--space-md);
	padding: var(--space-sm) 0;
	border-bottom: 1px solid var(--color-border);
	font-size: var(--text-subheadline);
}

.spec-list dt {
	color: var(--color-text-secondary);
}

.spec-list dd {
	margin: 0;
	font-weight: var(--font-weight-semibold);
	text-align: right;
}

.product-details__text {
	color: var(--color-text-primary);
	line-height: 1.65;
	text-wrap: pretty;
}

.product-details__text > :first-child {
	margin-top: 0;
}

.product-details__text > :last-child {
	margin-bottom: 0;
}

/* Shop descriptions are often a few short lines, each its own paragraph: smaller gaps between paragraphs, so they read as one text. */
.product-details__text p {
	margin: 0 0 var(--space-xs);
}

/* ---------- Section 5: similar products ---------- */

/*
 * Same cards as in the lists and on the home page. Heading like the home page sections.
 * Computer and tablet: 4 in a row. Phones: one row that scrolls sideways to the screen
 * edges (cards 160px, like "Najčešće naručivano" on the home page).
 */
.woocommerce div.product .related.products {
	margin-top: var(--space-xl);
	padding-top: clamp(32px, 2rem + 1vw, 48px);
	border-top: 1px solid var(--color-border);
}

.woocommerce div.product .related.products > h2 {
	margin: 0 0 var(--space-xl);
	font-size: clamp(1.375rem, 1.1rem + 0.9vw, 1.75rem);
	font-weight: var(--font-weight-bold);
	line-height: 1.2;
	letter-spacing: -0.005em;
}

.woocommerce div.product .related ul.products.product-grid {
	display: grid;
	grid-auto-columns: 160px;
	grid-auto-flow: column;
	gap: var(--space-sm);
	margin: 0 calc(var(--gutter) * -1);
	padding: 2px var(--gutter) var(--space-xs);
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-padding-inline: var(--gutter);
	scrollbar-width: none;
	list-style: none;
}

.woocommerce div.product .related ul.products.product-grid::-webkit-scrollbar {
	display: none;
}

.woocommerce div.product .related ul.products.product-grid::before,
.woocommerce div.product .related ul.products.product-grid::after {
	display: none;
}

.woocommerce div.product .related ul.products.product-grid li.product {
	float: none;
	clear: none;
	width: auto;
	margin: 0;
	padding: 0;
	scroll-snap-align: start;
}

/* WooCommerce sizes list images itself; the card needs its own (as in shop.css). */
.woocommerce div.product .related ul.products li.product .product-card__image img {
	height: 100%;
	margin: 0;
	box-shadow: none;
}

@media (min-width: 768px) {
	.woocommerce div.product .related ul.products.product-grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
		grid-auto-columns: auto;
		grid-auto-flow: row;
		gap: var(--space-md);
		margin: 0;
		padding: 0;
		overflow: visible;
	}
}

@media (min-width: 1024px) {
	.woocommerce div.product .related ul.products.product-grid {
		gap: var(--space-xl);
	}
}

/* ---------- Section 6: bar at the bottom of the screen (phones) ---------- */

/*
 * Like the app's bottom bar on the product screen: total on the left, red
 * "Dodaj u korpu" on the right. Below 900px only, and only while the block with the
 * quantity is out of view (product.js); it slides up from the bottom.
 */
@media (min-width: 900px) {
	.buy-bar,
	.buy-bar[hidden] {
		display: none;
	}

	body.has-buy-bar {
		padding-bottom: 0;
	}
}
