/**
 * Styling for preset WooCommerce Product Collection cards.
 *
 * Applies to every collection: `is-preset-collection` is added to each one in
 * includes/ProductCollectionRender.php, which also swaps the card into
 * WooCommerce's own list. Loaded on both front-end and editor via
 * wp_enqueue_block_style, only when the block is present.
 *
 * Some rules below are left over from when that render built the list and the
 * cards by hand; they are marked TODO: REMOVE and match nothing now.
 */

/* ── Grid ───────────────────────────────────────────────────────────── */
.wp-block-woocommerce-product-collection.is-preset-collection .wc-block-product-template {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	/* Column/row gap driven by theme.json custom variables. */
	column-gap: var(--wp--custom--product-grid-gap-column, var(--wp--preset--spacing--1));
	row-gap: var(--wp--custom--product-grid-gap-row, var(--wp--preset--spacing--4));
}

/* Carousel: one scrolling row instead of the grid. WooCommerce's carousel
 * CSS handles overflow, scroll-snap and item widths. */
.wp-block-woocommerce-product-collection.is-preset-collection .wc-block-product-template.is-product-collection-layout-carousel {
	display: flex;
	flex-wrap: nowrap;
}

.is-preset-collection .wc-block-product-template.is-list,
.is-preset-collection .wc-block-product-template.columns-1 {
	grid-template-columns: 1fr;
}

@media (min-width: 782px) {
	.is-preset-collection .wc-block-product-template.columns-3 { grid-template-columns: repeat(3, 1fr); }
	.is-preset-collection .wc-block-product-template.columns-4 { grid-template-columns: repeat(4, 1fr); }
	.is-preset-collection .wc-block-product-template.columns-5 { grid-template-columns: repeat(5, 1fr); }
	.is-preset-collection .wc-block-product-template.columns-6 { grid-template-columns: repeat(6, 1fr); }
}

/* TODO: REMOVE. Written for the list the old preset-collection render built by
 * hand (includes/ProductCollectionRender.php before it swapped the card in
 * WooCommerce's own list). That markup is gone: `li.wc-block-product-template__product` (WooCommerce's own items are `li.wc-block-product`).
 * Check a collection on the front end and in the editor, then delete. */
.is-preset-collection .wc-block-product-template__product {
	margin: 0;
	list-style: none;
}

/* ── Image ──────────────────────────────────────────────────────────── */
.is-preset-collection .wc-block-components-product-image {
	position: relative;
	display: block;
}

.is-preset-collection .wc-block-components-product-image img {
	display: block;
	width: 100%;
	height: auto;
}

/* TODO: REMOVE. Written for the list the old preset-collection render built by
 * hand (includes/ProductCollectionRender.php before it swapped the card in
 * WooCommerce's own list). That markup is gone: `.onsale` was the sale badge it printed; the card has the Sale Badge block now.
 * Check a collection on the front end and in the editor, then delete. */
.is-preset-collection .wc-block-components-product-image .onsale {
	position: absolute;
	top: 0.5em;
	right: 0.5em;
	margin: 0;
	padding: 0.2em 0.6em;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	line-height: 1.4;
	background: var(--wp--preset--color--secondary, #791220);
	color: var(--wp--preset--color--base, #fff);
	border-radius: 0;
}

/* ── Title + price ──────────────────────────────────────────────────── */
/* TODO: REMOVE. Written for the list the old preset-collection render built by
 * hand (includes/ProductCollectionRender.php before it swapped the card in
 * WooCommerce's own list). That markup is gone: `.wc-block-components-product-name` was the title it printed; the card has a Post Title block (`.wp-block-post-title`) now. The same goes for the three `.wc-block-components-product-name` rules that follow.
 * Check a collection on the front end and in the editor, then delete. */
.is-preset-collection .wc-block-components-product-name {
	font-size: var(--wp--preset--font-size--s, 0.875rem);
	font-weight: 500;
	line-height: 1.3;
	margin: 1.1em 0 0.44em;
}

.is-preset-collection .wc-block-components-product-name a {
	color: var(--wp--preset--color--contrast, #000);
	text-decoration: none;
}

.is-preset-collection .wc-block-components-product-name a:hover,
.is-preset-collection .wc-block-components-product-name a:focus-visible {
	text-decoration: underline;
}

.is-preset-collection .wc-block-components-product-price {
	font-size: 14px;
	font-weight: 300;
	line-height: 1.3;
	color: var(--wp--preset--color--contrast, #000);
}

/* ── Editor preview ─────────────────────────────────────────────────────
 * The editor renders the block's inner template (post-title, product-button,
 * pagination …) — our server render can't run there. Nudge that preview
 * toward the live card: portrait image, matching title/price, hide the
 * add-to-cart and pagination that the front-end card omits.
 */
.editor-styles-wrapper .wp-block-woocommerce-product-collection .wc-block-components-product-image--aspect-ratio-3-4 {
	aspect-ratio: 3 / 4;
	overflow: hidden;
}

.editor-styles-wrapper .wp-block-woocommerce-product-collection .wc-block-components-product-image--aspect-ratio-3-4 img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.editor-styles-wrapper .wp-block-woocommerce-product-collection .wp-block-post-title {
	font-size: var(--wp--preset--font-size--s);
	font-weight: 500;
	margin: 1.1em 0 0.44em;
}

.editor-styles-wrapper .wp-block-woocommerce-product-collection .wp-block-button.wc-block-components-product-button,
.editor-styles-wrapper .wp-block-woocommerce-product-collection .wc-block-components-product-button,
.editor-styles-wrapper .wp-block-woocommerce-product-collection .wp-block-query-pagination {
	display: none;
}
