/*
 * Product grid and product card.
 *
 * Shared by the homepage showcase and (from phase 6) the catalogue, so this
 * file is loaded globally rather than per-template.
 */

/* --- Grid ---------------------------------------------------------------- */

.pgrid {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: var(--wp--preset--spacing--6);
}

@media (max-width: 1100px) {
	.pgrid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: var(--wp--preset--spacing--5);
	}
}

/*
 * On phones the grid becomes a native swipe carousel: scroll-snap does the
 * work, so there is no carousel library and no JavaScript involved.
 */
@media (max-width: 781px) {
	.pgrid {
		display: flex;
		gap: var(--wp--preset--spacing--4);
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		/* Bleed to the screen edges so cards scroll out of frame properly. */
		margin-inline: calc(-1 * var(--wp--preset--spacing--5));
		padding-inline: var(--wp--preset--spacing--5);
		padding-bottom: var(--wp--preset--spacing--3);
		scroll-padding-left: var(--wp--preset--spacing--5);
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}

	.pgrid::-webkit-scrollbar {
		display: none;
	}

	.pgrid__item {
		flex: 0 0 76%;
		scroll-snap-align: start;
	}
}

.pgrid__item {
	display: flex;
	min-width: 0;
}

/* --- Card ---------------------------------------------------------------- */

.pcard {
	display: flex;
	flex-direction: column;
	width: 100%;
	min-width: 0;
	background: var(--wp--preset--color--base);
	border: 1px solid var(--wp--custom--border--on-light);
	border-radius: var(--wp--custom--radius--lg);
	overflow: hidden;
	transition:
		border-color var(--wp--custom--duration--fast) var(--wp--custom--ease--out),
		box-shadow var(--wp--custom--duration--base) var(--wp--custom--ease--out),
		transform var(--wp--custom--duration--base) var(--wp--custom--ease--out);
}

@media (hover: hover) {
	.pcard:hover {
		transform: translateY(-4px);
		border-color: transparent;
		box-shadow: var(--wp--custom--shadow--lg);
	}
}

/* --- Media --------------------------------------------------------------- */

.pcard__media {
	position: relative;
	display: block;
	aspect-ratio: 1 / 1;
	background: var(--wp--preset--color--base-soft);
	overflow: hidden;
}

/*
 * contain, not cover: these are cut-out product shots, and cropping them
 * would slice the hardware. The padding keeps the product off the edges.
 */
.pcard__img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	padding: 8%;
	transition: transform var(--wp--custom--duration--base) var(--wp--custom--ease--out);
}

@media (hover: hover) {
	.pcard:hover .pcard__img {
		transform: scale(1.05);
	}
}

.pcard--oos .pcard__img {
	opacity: 0.55;
}

/* --- Badges -------------------------------------------------------------- */

.pcard__badges {
	position: absolute;
	top: var(--wp--preset--spacing--3);
	left: var(--wp--preset--spacing--3);
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: var(--wp--preset--spacing--1);
}

.pcard__badge {
	display: inline-block;
	padding: 4px 8px;
	border-radius: var(--wp--custom--radius--sm);
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 700;
	letter-spacing: 0.02em;
	line-height: 1.4;
	font-variant-numeric: tabular-nums;
}

.pcard__badge--sale {
	background: var(--wp--preset--color--sale);
	color: var(--wp--preset--color--base);
}

.pcard__badge--install {
	background: var(--wp--preset--color--contrast);
	color: var(--wp--preset--color--base);
}

.pcard__badge--oos {
	background: var(--wp--preset--color--graphite);
	color: var(--wp--preset--color--base);
}

.pcard__badge--backorder {
	background: var(--wp--preset--color--warning);
	color: var(--wp--preset--color--base);
}

/*
 * "ТОП продажів" (inc/badges.php). The theme has no colour accent - the
 * palette is monochrome and the sale badge is near-black too - so the label
 * is told apart by its icon, capitals and a thin light inner outline rather
 * than by a second colour. Dark fill = the add-to-cart button's fill.
 * White on #111 is ~18:1, well past WCAG AA.
 */
.ef-top-label {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	border-radius: var(--wp--custom--radius--sm);
	background: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--base);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1.4;
	text-transform: uppercase;
	white-space: nowrap;
}

.ef-top-label__icon {
	flex: 0 0 auto;
	width: 12px;
	height: 12px;
	stroke-width: 2;
}

/*
 * Related products: WooCommerce's product image block is the anchor. The
 * row is five columns, so around 768-1000px a tile is only ~128px wide -
 * narrower than the full-size label; the container query below gives it a
 * smaller label there, still on one line and inside the photo.
 */
.wp-block-woocommerce-product-image:has(> .ef-top-label--collection) {
	position: relative;
	container-type: inline-size;
}

.ef-top-label--collection {
	position: absolute;
	top: var(--wp--preset--spacing--3);
	left: var(--wp--preset--spacing--3);
	z-index: 2;
	pointer-events: none;
}

@container (max-width: 179px) {
	.ef-top-label--collection {
		top: 6px;
		left: 6px;
		gap: 3px;
		padding: 3px 6px;
		font-size: 10px;
		letter-spacing: 0.02em;
	}

	.ef-top-label--collection .ef-top-label__icon {
		width: 10px;
		height: 10px;
	}
}

/* --- Body ---------------------------------------------------------------- */

.pcard__body {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--2);
	padding: var(--wp--preset--spacing--5);
	/* Pushes .pcard__footer to the bottom so prices line up across the row. */
	flex-grow: 1;
}

.pcard__title {
	margin: 0;
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.02em;
}

.pcard__title a {
	color: var(--wp--preset--color--contrast);
	text-decoration: none;
}

/* The whole card is clickable, but only the title is a real tab stop. */
.pcard__title a::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
}

.pcard {
	position: relative;
}

/* Real WooCommerce attributes. */
.pcard__spec {
	margin: 0;
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 600;
	letter-spacing: 0.04em;
	color: var(--wp--preset--color--primary);
	font-variant-numeric: tabular-nums;
}

.pcard__desc {
	margin: 0;
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.5;
	color: var(--wp--preset--color--contrast-subtle);
}

.pcard__footer {
	margin-top: auto;
	padding-top: var(--wp--preset--spacing--4);
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--3);
}

/* --- Advantages (inc/badges.php) ----------------------------------------- */

/* Deliberately quiet: no fill, no border - it must not compete with the price. */
.ef-advantages {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ef-advantage {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	line-height: 1.4;
	color: var(--wp--preset--color--primary);
}

.ef-advantage__icon {
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	color: var(--wp--preset--color--success);
}

/* --- Price --------------------------------------------------------------- */

.pcard__price {
	margin: 0;
	display: flex;
	align-items: baseline;
	/*
	 * In a narrow card the old price wraps; reverse wrapping puts it on the
	 * line above, so the current price stays on the bottom line - level with
	 * the non-discounted prices beside it - instead of rising above them.
	 */
	flex-wrap: wrap-reverse;
	gap: var(--wp--preset--spacing--2);
	font-variant-numeric: tabular-nums;
}

.pcard__price-now {
	font-size: var(--wp--preset--font-size--xl);
	font-weight: 700;
	letter-spacing: -0.02em;
	color: var(--wp--preset--color--contrast);
}

.pcard__price-was {
	font-size: var(--wp--preset--font-size--sm);
	color: var(--wp--preset--color--contrast-muted);
	text-decoration-thickness: 1px;
}

/* WooCommerce wraps prices in .woocommerce-Price-amount; neutralise its own sizing. */
.pcard__price .woocommerce-Price-amount {
	font-size: inherit;
	font-weight: inherit;
	color: inherit;
}

/* --- CTA ----------------------------------------------------------------- */

/*
 * The button sits above the title's full-card overlay so it stays separately
 * clickable. It is always visible - hiding a buy control until hover would
 * fail on touch, where there is no hover - and "reveals" by filling in.
 */
.pcard__cta {
	position: relative;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--wp--preset--spacing--2);
	width: 100%;
	padding: 0.8rem 1.25rem;
	border: 1px solid var(--wp--custom--border--on-light);
	border-radius: var(--wp--custom--radius--md);
	background: transparent;
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	transition:
		background-color var(--wp--custom--duration--fast) var(--wp--custom--ease--out),
		border-color var(--wp--custom--duration--fast) var(--wp--custom--ease--out),
		color var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.pcard__cta:hover,
.pcard__cta:focus-visible {
	background: var(--wp--preset--color--primary);
	border-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--base);
}

@media (hover: hover) {
	.pcard:hover .pcard__cta {
		background: var(--wp--preset--color--primary);
		border-color: var(--wp--preset--color--primary);
		color: var(--wp--preset--color--base);
	}
}

.pcard__cta .btn-arrow {
	transition: transform var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

@media (hover: hover) {
	.pcard:hover .pcard__cta .btn-arrow {
		transform: translateX(4px);
	}
}

/*
 * WooCommerce injects a "View cart" link after a successful AJAX add. In the
 * footer it made only that card taller, so the whole grid row grew and every
 * neighbour's price and button dropped ~56px below the clicked card's.
 * Confirm on the button itself instead (same pattern as the product page);
 * the header cart badge already updates and is the way into the cart.
 * Extra .pcard outranks WooCommerce's `.woocommerce a.added_to_cart`.
 */
.pcard .pcard__footer a.added_to_cart {
	display: none;
}

.pcard__cta.added {
	background: var(--wp--preset--color--success);
	border-color: var(--wp--preset--color--success);
	color: var(--wp--preset--color--base);
}

.pcard__cta.added .btn-arrow {
	display: none;
}

.pcard__cta.added::after {
	content: "✓";
}

.pcard__cta.loading {
	opacity: 0.7;
}
