/*
 * 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--oos {
	background: var(--wp--preset--color--graphite);
	color: var(--wp--preset--color--base);
}

/* --- 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);
}

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

.pcard__price {
	margin: 0;
	display: flex;
	align-items: baseline;
	flex-wrap: wrap;
	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. */
.pcard__footer .added_to_cart {
	position: relative;
	z-index: 2;
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	text-align: center;
}

.pcard__cta.loading {
	opacity: 0.7;
}
