/*
 * Re-skins WooCommerce's own markup (classic shop loop, single product,
 * and the Cart/Checkout blocks) to the design system. Phase 2 is the
 * visual layer only — the quantity stepper's plus/minus buttons and
 * server-side stock clamping are wired to real data in Phase 3/5; the
 * CSS shell here is what that JS progressively enhances.
 */

/* ---------- Shop loop ----------
 * Two markup shapes both need this: the classic shortcode loop
 * (`ul.products > li.product`) and the block-based Product Collection
 * (`ul.wc-block-product-template > li.product` — WooCommerce's own
 * `get_post_class()` call always adds the plain `product` class, so one
 * selector list covers both). */

ul.products,
.wc-block-product-template {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--wp--preset--spacing--md);
	list-style: none;
	margin: 0;
	padding: 0;
}

@media (min-width: 600px) {
	ul.products,
	.wc-block-product-template { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1100px) {
	ul.products,
	.wc-block-product-template { grid-template-columns: repeat(4, 1fr); gap: var(--wp--preset--spacing--lg); }
}

/*
 * Container query, not viewport (R3.3): the same card renders inside the
 * full-width shop grid, the narrower featured-products band, a sidebar-
 * adjacent archive column and the Gifts grid — four different rendered
 * widths at any one viewport size. `container-type: inline-size` on the
 * card itself lets its own title/price sizing respond to how much room
 * IT actually has, not how wide the browser window is.
 */
ul.products li.product,
.wc-block-product-template li.product {
	background: var(--wp--preset--color--card-background);
	border: 1px solid var(--wp--preset--color--card-border);
	border-radius: var(--wp--custom--radius--lg);
	box-shadow: var(--wp--preset--shadow--soft-md);
	overflow: hidden;
	/* Makes the card the containing block for anything WooCommerce positions
	   absolutely inside it (the visually-hidden "Price range: …" text of a plant
	   with options, badges). Without it those escape `overflow: hidden`, land far
	   to the right in the horizontally-scrolling featured row, and make the whole
	   homepage wider than a phone — shrinking it on Chrome for Android. */
	position: relative;
	padding: 0 !important;
	margin: 0 !important;
	container-type: inline-size;
	container-name: vv-product-card;
}

ul.products li.product img,
.wc-block-product-template li.product img {
	aspect-ratio: 4 / 5;
	object-fit: cover;
	width: 100%;
}

/* Card titles run one line for a short name ("Sweet Basil") and two for a
   longer one ("One of One — Hand-carved Fynbos Garden Sign") — left alone, that
   makes the price sit at a different height on every card in the row,
   depending on the product it happens to land next to (R8, caught live:
   the price never lined up between neighbouring cards). Clamping every
   title to a fixed two-line box, regardless of how much of it actually
   wraps, gives the price after it the same starting height on every card
   in the grid — an ellipsis on a genuinely long name is the one real
   trade-off, not a visual regression on the two/three-word names that are
   most of the catalogue. */
ul.products li.product .woocommerce-loop-product__title,
.wc-block-product-template li.product .wp-block-post-title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	font-family: var(--wp--preset--font-family--karla);
	font-size: var(--wp--preset--font-size--h-4) !important;
	font-weight: 700;
	line-height: 1.3;
	/* box-sizing here is border-box (theme-wide reset), so the padding-top
	   below is part of this height, not extra on top of it — omitting it
	   left the box ~10px short of two real lines of text, clipping into
	   the middle of the second line instead of leaving it be or clamping
	   it with the "…" `-webkit-line-clamp` is actually meant to add.
	   Recalculated per padding context below, same reason. */
	height: calc(var(--wp--preset--spacing--xs) + 1.3em * 2);
	color: var(--wp--preset--color--forest-900);
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--xs) 0;
	margin: 0;
	text-align: center !important;
}

/* A card with real breathing room (a wide grid cell) gets the more
   generous padding brand guide §9.1 specifies; a narrow one (this exact
   card rendered in a tighter column) stays compact instead of the text
   crowding its own edges — the container query R3.3 asks for, not a
   viewport breakpoint standing in for one. */
@container vv-product-card (min-width: 220px) {
	ul.products li.product .woocommerce-loop-product__title,
	.wc-block-product-template li.product .wp-block-post-title {
		height: calc(var(--wp--preset--spacing--sm) + 1.3em * 2);
		padding: var(--wp--preset--spacing--sm) var(--wp--preset--spacing--sm) 0;
	}

	ul.products li.product .price,
	.wc-block-product-template li.product .price,
	.wc-block-product-template li.product .wc-block-components-product-price {
		padding-inline: var(--wp--preset--spacing--sm);
	}
}

/* `.price` is the classic shortcode loop's own markup; the block-based
   Product Collection (used by `patterns/featured-products.php` and the
   Gifts grid) renders `.wc-block-components-product-price` instead — a
   completely different element that this rule never matched until now, so
   the block-collection price was rendering in WooCommerce's own unstyled
   default (caught alongside the title-height fix above: the price sitting
   right after a now fixed-height title still needs the same font/colour
   treatment as the classic loop for the two to actually look aligned, not
   just occupy the same row). */
ul.products li.product .price,
.wc-block-product-template li.product .price,
.wc-block-product-template li.product .wc-block-components-product-price {
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	color: var(--wp--preset--color--price-text);
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--xs) var(--wp--preset--spacing--sm);
	display: block;
	text-align: center !important;
}

.wc-block-product-template li.product .wp-block-woocommerce-product-button {
	padding: 0 var(--wp--preset--spacing--sm) var(--wp--preset--spacing--sm);
	text-align: center;
}

/* Everything under a card's photo reads as one centred column. The care-icon
   row, the stock / "New" badges and the "notify me" form are bare blocks
   placed straight inside the card, so with nothing centring them they sat
   flush against the card's left edge while the title and button above and
   below them were inset or centred. The side padding matches the title's. */
ul.products li.product,
.wc-block-product-template li.product {
	text-align: center;
}

ul.products li.product .vv-care-icons,
.wc-block-product-template li.product .vv-care-icons {
	justify-content: center;
	padding-inline: var(--wp--preset--spacing--xs);
}

ul.products li.product .vv-badge,
.wc-block-product-template li.product .vv-badge {
	margin: 0 var(--wp--preset--spacing--3-xs) var(--wp--preset--spacing--xs);
}

ul.products li.product .vv-notify-me,
.wc-block-product-template li.product .vv-notify-me {
	padding-inline: var(--wp--preset--spacing--sm);
	padding-block-end: var(--wp--preset--spacing--sm);
}

@container vv-product-card (min-width: 220px) {
	ul.products li.product .vv-care-icons,
	.wc-block-product-template li.product .vv-care-icons {
		padding-inline: var(--wp--preset--spacing--sm);
	}
}

ul.products li.product .price ins {
	text-decoration: none;
	color: var(--wp--preset--color--price-text);
}

ul.products li.product .price del {
	color: var(--wp--preset--color--sand-500);
	opacity: 0.8;
}

/* A plant with no price shows "Price on request" (Catalog\PriceOnRequest) — it reads as a price, not an error —
   and the cart, which shows R0.00 for it, says what that means. */
.vv-price-on-request {
	font-weight: 600;
	color: var(--wp--preset--color--price-text);
}

.vv-cart-note {
	margin: 0 0 var(--wp--preset--spacing--md);
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--sm);
	background: var(--wp--preset--color--cream-100);
	border: 1px solid var(--wp--preset--color--card-border);
	border-radius: var(--wp--custom--radius--md);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--forest-900);
}

/* ---------- Buttons — every WooCommerce button reads as our pill CTA ---------- */

.woocommerce a.button,
.woocommerce button.button,
.woocommerce input.button,
.woocommerce #respond input#submit,
.wc-block-components-button {
	font-family: var(--wp--preset--font-family--karla) !important;
	font-weight: 600;
	font-size: var(--wp--preset--font-size--button);
	background: var(--wp--preset--color--button-primary) !important;
	color: var(--wp--preset--color--button-primary-text) !important;
	border: none;
	border-radius: var(--wp--custom--radius--pill) !important;
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--md) !important;
	/* R7: was `none !important` — every Add to Cart button on the site sat
	   completely flat. This is the site's highest-traffic CTA, so it gets
	   the same shadow/lift treatment as base.css's button system; kept
	   !important to hold against WooCommerce's own specificity. */
	box-shadow: var(--wp--preset--shadow--soft-md) !important;
	transition: background-color 200ms ease-out, box-shadow var(--wp--custom--motion--micro-duration) ease, transform var(--wp--custom--motion--micro-duration) ease;
}

.woocommerce a.button:hover,
.woocommerce button.button:hover,
.woocommerce input.button:hover,
.wc-block-components-button:hover {
	background: var(--wp--preset--color--terracotta-700) !important;
	box-shadow: var(--wp--preset--shadow--soft-lg) !important;
	transform: translateY(-2px);
}

/*
 * R7 — brief "Added" success state (assets/js/cart-count.js's `showAdded()`
 * swaps the button's own content, this just re-skins it in-place). A
 * distinct sage fill reads as confirmation, not just a repeat of the
 * primary terracotta CTA colour. `gap`/`display:inline-flex` lay out the
 * swapped-in checkmark SVG + label; the fade/scale-in on the swap itself
 * is handled by the shared `transition` above (background/box-shadow) plus
 * this rule's own opacity keyframe so the content doesn't just pop.
 */
.woocommerce a.button.is-added,
.woocommerce button.button.is-added,
.wc-block-components-button.is-added {
	display: inline-flex !important;
	align-items: center;
	gap: var(--wp--preset--spacing--3-xs);
	background: var(--wp--preset--color--in-stock-text) !important;
	animation: vv-added-fade-in var(--wp--custom--motion--micro-duration) ease-out both;
}

@keyframes vv-added-fade-in {
	from { opacity: 0.4; transform: scale(0.96); }
	to   { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.woocommerce a.button.is-added,
	.woocommerce button.button.is-added,
	.wc-block-components-button.is-added {
		animation: none;
	}
}

.woocommerce a.button.loading,
.woocommerce #respond input#submit.disabled {
	opacity: 0.6;
}

/* ---------- Sale / stock badges ---------- */

.woocommerce span.onsale {
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	font-size: var(--wp--preset--font-size--small);
	background: var(--wp--preset--color--low-stock-bg);
	color: var(--wp--preset--color--low-stock-text);
	border-radius: var(--wp--custom--radius--pill);
	min-height: 0;
	min-width: 0;
	line-height: 1;
	padding: var(--wp--preset--spacing--3-xs) var(--wp--preset--spacing--xs);
	position: absolute;
	top: var(--wp--preset--spacing--xs);
	left: var(--wp--preset--spacing--xs);
	margin: 0;
}

.woocommerce p.stock.in-stock,
.woocommerce p.stock.out-of-stock,
.woocommerce p.stock.available-on-backorder {
	display: inline-flex;
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 600;
	font-size: var(--wp--preset--font-size--small);
	border-radius: var(--wp--custom--radius--pill);
	padding: var(--wp--preset--spacing--3-xs) var(--wp--preset--spacing--sm);
}

.woocommerce p.stock.in-stock { color: var(--wp--preset--color--in-stock-text); background: var(--wp--preset--color--in-stock-bg); }
.woocommerce p.stock.out-of-stock { color: var(--wp--preset--color--sand-700); background: var(--wp--preset--color--sand-100); }
.woocommerce p.stock.available-on-backorder { color: var(--wp--preset--color--on-request-text); background: var(--wp--preset--color--on-request-bg); }

/* ---------- Quantity input (stepper JS enhances this in Phase 3/5) ---------- */

.quantity {
	display: inline-flex;
	border: 1px solid var(--wp--preset--color--card-border);
	border-radius: var(--wp--custom--radius--pill);
	overflow: hidden;
}

.quantity .qty {
	min-height: 44px;
	min-width: 3.25rem;
	text-align: center;
	border: none;
	background: var(--wp--preset--color--cream-50);
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 600;
	color: var(--wp--preset--color--forest-900);
	/* Real stepper buttons replace the browser's own tiny up/down arrows (brief §5.5: "not a bare <input type=number>"). */
	appearance: textfield;
	-moz-appearance: textfield;
}

.quantity .qty::-webkit-outer-spin-button,
.quantity .qty::-webkit-inner-spin-button {
	appearance: none;
	-webkit-appearance: none;
	margin: 0;
}

/* .quantity button[data-qty-action] reuses .vv-qty-stepper__btn's own styling (base.css) — only the states specific to this context are added here. */

@media (hover: hover) {
	.quantity button[data-qty-action]:hover:not(:disabled) {
		background: var(--wp--preset--color--cream-200);
	}
}

.quantity button[data-qty-action]:disabled {
	color: var(--wp--preset--color--sand-500);
	cursor: not-allowed;
}

.vv-qty-hint {
	display: block;
	margin-top: var(--wp--preset--spacing--3-xs);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--sand-700);
}

/* ---------- Single product ---------- */

.woocommerce div.product .woocommerce-product-gallery {
	border-radius: var(--wp--custom--radius--lg);
	overflow: hidden;
}

.woocommerce div.product .woocommerce-product-gallery__image {
	aspect-ratio: 4 / 5;
	background: var(--wp--preset--color--cream-100);
}

.woocommerce div.product .woocommerce-product-gallery__image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.woocommerce div.product p.price,
.woocommerce div.product span.price {
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	font-size: var(--wp--preset--font-size--h-3);
	color: var(--wp--preset--color--price-text);
}

.vv-scale-reference {
	display: inline-flex;
	align-items: center;
	gap: var(--wp--preset--spacing--3-xs);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--muted-text);
	margin-block-start: var(--wp--preset--spacing--xs);
}

.woocommerce-tabs {
	border-top: 1px solid var(--wp--preset--color--card-border);
	margin-block-start: var(--wp--preset--spacing--lg);
	padding-block-start: var(--wp--preset--spacing--lg);
}

.woocommerce-tabs ul.tabs {
	display: flex;
	/* Wrap, so "Description" and "Reviews (0)" never push the page wider than a phone screen. */
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--2-xs) var(--wp--preset--spacing--md);
	list-style: none;
	padding: 0;
	margin: 0 0 var(--wp--preset--spacing--md);
	border-bottom: 1px solid var(--wp--preset--color--card-border);
}

/* On a phone WooCommerce stacks the tabs and marks the open one with a bar beside it; a flex row would push the page wider than the screen. */
@media (max-width: 768px) {
	.woocommerce-tabs ul.tabs {
		flex-direction: column;
		gap: var(--wp--preset--spacing--3-xs);
	}
}

.woocommerce-tabs ul.tabs li a {
	display: inline-block;
	padding-block-end: var(--wp--preset--spacing--xs);
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	color: var(--wp--preset--color--muted-text);
	text-decoration: none;
}

.woocommerce-tabs ul.tabs li.active a {
	color: var(--wp--preset--color--heading-text);
	border-bottom: 2px solid var(--wp--preset--color--terracotta-600);
}

/* ---------- Category tiles (dynamic — brief §1.3) ---------- */

.vv-category-tiles.wc-block-product-categories-list {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--wp--preset--spacing--sm);
	list-style: none;
	margin: 0;
	padding: 0;
}

@media (min-width: 600px) {
	.vv-category-tiles.wc-block-product-categories-list { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1100px) {
	.vv-category-tiles.wc-block-product-categories-list {
		grid-template-columns: repeat(4, 1fr);
		grid-auto-flow: dense;
	}
}

.vv-category-tiles.wc-block-product-categories-list li {
	background: var(--wp--preset--color--card-background);
	border: 1px solid var(--wp--preset--color--card-border);
	border-radius: var(--wp--custom--radius--lg);
	border-bottom: 4px solid var(--vv-category-accent, var(--wp--custom--category-accent--default));
	box-shadow: var(--wp--preset--shadow--soft-sm);
	padding: var(--wp--preset--spacing--sm);
	text-align: center;
	transition: box-shadow 200ms ease-out, transform 200ms ease-out;
}

.vv-category-tiles.wc-block-product-categories-list li:hover {
	box-shadow: var(--wp--preset--shadow--soft-md);
	transform: translateY(-2px);
}

.vv-category-tiles.wc-block-product-categories-list li a {
	text-decoration: none;
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	color: var(--wp--preset--color--forest-900);
}

.vv-category-tiles.wc-block-product-categories-list img {
	border-radius: var(--wp--custom--radius--md);
	aspect-ratio: 4 / 3;
	object-fit: cover;
	margin-block-end: var(--wp--preset--spacing--xs);
}

.vv-category-tiles .wc-block-product-categories-list-item-count {
	color: var(--wp--preset--color--muted-text);
	font-weight: 400;
}

/* Editorial variance (R3.3: "a featured plant spanning two columns, not a
   uniform 4×4"): the first category the owner has set up reads as the
   featured entry — a taller image, a larger name — rather than every tile
   being an identical size. Owner-managed taxonomy still decides which
   category that is; this is pure CSS positioning, no hardcoded category. */
@media (min-width: 1100px) {
	.vv-category-tiles.wc-block-product-categories-list li:first-child {
		grid-column: span 2;
		grid-row: span 2;
		display: flex;
		flex-direction: column;
		padding: var(--wp--preset--spacing--md);
	}

	.vv-category-tiles.wc-block-product-categories-list li:first-child img {
		flex: 1;
		aspect-ratio: auto;
		min-height: 14rem;
	}

	.vv-category-tiles.wc-block-product-categories-list li:first-child a {
		font-size: var(--wp--preset--font-size--h-3);
		font-family: var(--wp--preset--font-family--fraunces);
	}
}

/* ---------- Featured products — horizontal scroll on mobile, grid on
   desktop (R3.5: "horizontal scroll on mobile with snap points, grid on
   desktop") ---------- */

@media (max-width: 781px) {
	.vv-featured-products .wc-block-product-template {
		display: flex !important;
		flex-wrap: nowrap !important;
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		/* Without this the first card snaps flush against the screen's edge instead of keeping the row's side padding. */
		scroll-padding-inline: var(--wp--preset--spacing--sm);
		gap: var(--wp--preset--spacing--sm);
		padding-block-end: var(--wp--preset--spacing--xs);
		margin-inline: calc(var(--wp--preset--spacing--sm) * -1);
		padding-inline: var(--wp--preset--spacing--sm);
		-webkit-overflow-scrolling: touch;
	}

	.vv-featured-products .wc-block-product-template > li.product {
		flex: 0 0 72vw;
		max-width: 18rem;
		scroll-snap-align: start;
	}
}

/* ---------- Cart & Checkout blocks ---------- */

.wc-block-cart,
.wc-block-checkout {
	--wc-blocks-item-border-color: var(--wp--preset--color--card-border);
}

.wc-block-cart-item,
.wc-block-components-order-summary,
.wc-block-components-panel,
.wc-block-checkout__form {
	border-radius: var(--wp--custom--radius--md);
}

.wc-block-components-totals-item,
.wc-block-components-panel {
	border-color: var(--wp--preset--color--card-border) !important;
}

.wc-block-components-product-badge,
.wc-block-components-sale-badge {
	background: var(--wp--preset--color--low-stock-bg) !important;
	color: var(--wp--preset--color--low-stock-text) !important;
	border-radius: var(--wp--custom--radius--pill) !important;
}

.wc-block-components-radio-control__option,
.wc-block-components-checkbox .wc-block-components-checkbox__mark {
	border-radius: var(--wp--custom--radius--sm) !important;
}

/* ---------- What-you'll-receive + POPIA consent + form field polish ---------- */

.woocommerce form .form-row input.input-text,
.woocommerce form .form-row textarea,
.woocommerce form .form-row select {
	border: 1px solid var(--wp--preset--color--card-border);
	border-radius: var(--wp--custom--radius--sm);
	padding: var(--wp--preset--spacing--xs);
	font-family: var(--wp--preset--font-family--karla);
	background: var(--wp--preset--color--cream-50);
}

.woocommerce form .form-row input.input-text:focus,
.woocommerce form .form-row textarea:focus,
.woocommerce form .form-row select:focus {
	border-color: var(--wp--preset--color--forest-500);
}

/* ---------- Attribute filter sidebar (vv/attribute-filters, brief §1.3) ---------- */

.vv-shop-sidebar {
	min-width: 180px;
}

.vv-filters {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--md);
}

.vv-filter {
	border: none;
	margin: 0;
	padding: 0;
}

.vv-filter__legend {
	font-family: var(--wp--preset--font-family--karla);
	font-weight: 700;
	font-size: var(--wp--preset--font-size--small);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--wp--preset--color--forest-800);
	padding: 0 0 var(--wp--preset--spacing--3-xs);
}

.vv-filter__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--3-xs);
}

.vv-filter__item a {
	display: block;
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--forest-700);
	text-decoration: none;
	padding: var(--wp--preset--spacing--3-xs) 0;
}

.vv-filter__item.is-active a {
	color: var(--wp--preset--color--terracotta-600);
	font-weight: 700;
}

.vv-filter__count {
	color: var(--wp--preset--color--muted-text);
}

.vv-filter__clear {
	align-self: flex-start;
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--terracotta-600);
	text-decoration: underline;
}
