/*
 * MO-170 — commerce surface fixes (shop/catalog, cart, checkout).
 * Owned by the commerce workstream. Loads after components.css.
 */

/* =====================================================================
   Shop archive — one-product collection
   ===================================================================== */

.mo-shop {
	padding-inline: var(--wp--preset--spacing--md);
	padding-block: var(--wp--preset--spacing--xl) var(--wp--preset--spacing--3-xl);
	background: var(--wp--custom--section-glow), var(--wp--preset--color--surface-primary);
}

.mo-shop__head {
	max-width: 64ch;
	margin-bottom: var(--wp--preset--spacing--xl);
}

.mo-shop__title {
	margin: 0 0 var(--wp--preset--spacing--xs);
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--display-md);
	line-height: 1.05;
}

.mo-shop__lede {
	margin: 0;
	color: var(--wp--preset--color--text-muted);
}

/* fable/design: WooCommerce 11 renders the collection as
   ul.wc-block-product-template (no __responsive wrapper), so the old
   480px cap never matched and the single card's image filled the whole
   1440px column. A real grid instead: as many 300px+ cards as fit, each a
   bordered card whose image box is a fixed 4:3 frame. */
.mo-shop ul.wc-block-product-template {
	display: grid !important;
	grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
	justify-content: start;
	gap: var(--wp--preset--spacing--lg);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mo-shop ul.wc-block-product-template > li.wc-block-product {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--xs);
	/* WooCommerce sizes flex items with a fixed calc() width; as grid items
	   they must simply fill their track. */
	width: 100% !important;
	min-width: 0;
	max-width: none;
	margin: 0;
	padding: var(--wp--preset--spacing--md);
	border: 1px solid var(--wp--custom--border-subtle);
	border-radius: var(--wp--custom--radius--lg);
	background: var(--wp--custom--card-gradient);
	transition:
		transform var(--wp--custom--motion-duration) var(--wp--custom--motion-ease),
		border-color var(--wp--custom--motion-duration) var(--wp--custom--motion-ease);
}
.mo-shop ul.wc-block-product-template > li.wc-block-product:hover {
	transform: translateY(-3px);
	border-color: var(--wp--custom--border-accent);
}

.mo-shop .wc-block-components-product-image {
	aspect-ratio: 4 / 3;
	margin: 0;
}
.mo-shop .wc-block-components-product-image a,
.mo-shop .wc-block-components-product-image img {
	display: block;
	width: 100%;
	height: 100%;
}

.mo-shop .mo-product-card__title {
	margin: 0;
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.25;
}
.mo-shop .mo-product-card__title a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wp--custom--touch-target);
	color: var(--wp--preset--color--text-primary);
	text-decoration: none;
}
.mo-shop .mo-product-card__title a:hover {
	color: var(--wp--preset--color--accent-cobalt-light);
}

.mo-shop .wc-block-components-product-price {
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 700;
	color: var(--wp--preset--color--text-primary);
}

.mo-shop .wp-block-woocommerce-product-button {
	margin-top: auto;
	padding-top: var(--wp--preset--spacing--xs);
}
.mo-shop .wc-block-components-product-button__button {
	width: 100%;
	font-weight: 700;
}

.mo-shop .mo-product-card {
	height: 100%;
}

/* Shop pagination (only renders past loop_shop_per_page products). Store
   hook: .mo-shop__pagination, and its .page-numbers / .current links. */
.mo-shop__pagination {
	gap: var(--wp--preset--spacing--xs);
	margin-top: var(--wp--preset--spacing--lg);
}
.mo-shop__pagination a,
.mo-shop__pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: var(--wp--custom--touch-target);
	min-height: var(--wp--custom--touch-target);
	padding: 0 var(--wp--preset--spacing--xs);
	border-radius: var(--wp--custom--radius--sm);
	color: var(--wp--preset--color--text-primary);
}
.mo-shop__pagination .page-numbers.current {
	background: var(--wp--preset--color--text-primary);
	color: var(--wp--preset--color--surface-primary, #fff);
}

/* The concept render replaces WooCommerce's placeholder here and carries
   its own visible caption (.mo-shop-card__concept below), so the generic
   "Placeholder image" overlay from components.css would label the same
   image twice with different words. */
.mo-shop .wc-block-components-product-image:has(img.woocommerce-placeholder)::after {
	content: none;
}

@media (prefers-reduced-motion: reduce) {
	.mo-shop ul.wc-block-product-template > li.wc-block-product {
		transition: none;
	}
	.mo-shop ul.wc-block-product-template > li.wc-block-product:hover {
		transform: none;
	}
}

/* Real product media everywhere the WooCommerce placeholder would
   otherwise appear — shop, cart and checkout all key off this one rule
   family so the concept render is the single shared media source. */
.mo-shop .wc-block-components-product-image img.woocommerce-placeholder,
.wc-block-cart-item__image img[src*="woocommerce-placeholder"],
.wc-block-components-order-summary-item__image img[src*="woocommerce-placeholder"] {
	visibility: hidden;
}

.mo-shop .wc-block-components-product-image,
.wc-block-cart-item__image,
.wc-block-components-order-summary-item__image {
	position: relative;
	background-color: var(--mo-sf-card-media-bg, transparent);
	background-size: cover;
	background-position: 62% center;
	border-radius: var(--wp--custom--radius--md);
	overflow: hidden;
}

/* Shared-owner fix (store request: product photo consistency): the dash-cam
   concept render used to sit behind EVERY shop, cart and checkout image,
   real photos included (visible wherever a photo is letterboxed or has
   transparency, and downloaded on every shop page). It is now only the
   stand-in for a missing photo. */
.mo-shop .wc-block-components-product-image:has(img.woocommerce-placeholder),
.wc-block-cart-item__image:has(img[src*="woocommerce-placeholder"]),
.wc-block-components-order-summary-item__image:has(img[src*="woocommerce-placeholder"]) {
	background-image: url("../img/hero-night-drive-concept-mobile.webp");
}

@media (min-width: 768px) {
	.mo-shop .wc-block-components-product-image:has(img.woocommerce-placeholder) {
		background-image: url("../img/hero-night-drive-concept-desktop.webp");
	}
}

/* Shared listing-image hooks (see STORE-AGENT-GUIDE "Product photos"). All
   default to today's look; a store sets them on body.mo-sf-theme-<slug> to
   put every listing photo on one mat, e.g. ratio 4 / 5, fit contain, a light
   neutral bg, some padding and multiply blending for white-background shots:
     --mo-sf-card-media-ratio  container aspect ratio (default 4 / 3)
     --mo-sf-card-media-bg     mat colour behind the photo (default none)
     --mo-sf-card-media-fit    object-fit (default cover)
     --mo-sf-card-media-pad    inset of the photo on the mat (default 0)
     --mo-sf-card-media-blend  mix-blend-mode (default normal) */
.mo-shop .wc-block-components-product-image {
	aspect-ratio: var(--mo-sf-card-media-ratio, 4 / 3);
}
/* :where() keeps this at element specificity, so any existing store rule on
   these images (including store !important object-fit rules) still wins. */
:where(.mo-shop .wc-block-components-product-image) img:where(:not(.woocommerce-placeholder)) {
	/* !important: the product-image block writes object-fit inline. */
	object-fit: var(--mo-sf-card-media-fit, cover) !important;
	padding: var(--mo-sf-card-media-pad, 0);
	mix-blend-mode: var(--mo-sf-card-media-blend, normal);
	box-sizing: border-box;
}

.mo-shop .wc-block-components-product-button__button,
.wc-block-components-product-button__button {
	background: var(--wp--preset--color--accent-cobalt-dark);
	border: 1px solid var(--wp--preset--color--accent-cobalt);
	/* fable/design round 3: same --mo-sf-accent-contrast var .mo-btn--primary
	   uses (Mo_Storefronts_Theme::resolved_css_vars, AA-enforced against
	   the accent) — falls back to the original text-primary when unset
	   (default storefront), unchanged from before this variable existed. */
	color: var(--mo-sf-accent-contrast, var(--wp--preset--color--text-primary));
	border-radius: var(--wp--custom--radius--md);
	min-height: var(--wp--custom--touch-target);
}
.mo-shop .wc-block-components-product-button__button:hover,
.mo-shop .wc-block-components-product-button__button:focus-visible,
.wc-block-components-product-button__button:hover,
.wc-block-components-product-button__button:focus-visible {
	background: var(--wp--custom--accent-cobalt-hover);
}

/* Sorting control and result count serve no purpose with a single item —
   removed from the template rather than hidden, this rule is a defensive
   backstop in case either block is ever re-added above the fold. */
.mo-shop .wc-block-catalog-sorting,
.mo-shop .woocommerce-result-count {
	display: none;
}

/* =====================================================================
   Cart
   ===================================================================== */

/* Keep the complete commerce page, including its heading and notices,
   inside the store's content measure with gutters at every viewport. */
body.woocommerce-cart main,
body.woocommerce-checkout #mo-main {
	box-sizing: border-box;
	width: 100%;
	max-width: var(--wp--style--global--content-size, 1280px);
	margin-inline: auto;
	padding: var(--wp--preset--spacing--xl) var(--wp--preset--spacing--md);
}

/* Wide post blocks must fit the padded main, rather than restore edge-to-edge widths. */
body.woocommerce-cart main > .alignwide,
body.woocommerce-cart main > .wp-block-post-content,
body.woocommerce-checkout #mo-main > .alignwide,
body.woocommerce-checkout #mo-main > .wp-block-post-content {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin-inline: 0;
}

/* Duplicated price: the per-line unit price next to the title repeats the
   line total shown in its own column. Drop the redundant one. */
.wc-block-cart-item__product .wc-block-cart-item__prices {
	display: none;
}

/* The short description was written for the product page's persuasive
   copy, not a cart line item, and reads as an overpromise out of that
   context. Presentation-only removal — the underlying product excerpt is
   untouched. */
.wc-block-cart-item__product .wc-block-components-product-metadata__description {
	display: none;
}

.wc-block-components-quantity-selector__button {
	min-width: var(--wp--custom--touch-target);
	min-height: var(--wp--custom--touch-target);
}
.wc-block-components-quantity-selector__input {
	min-height: var(--wp--custom--touch-target);
}

/* "Proceed to Checkout" reads as disabled at the default WooCommerce
   gray. Restrained blue, matching every other primary CTA on the site. */
.wc-block-cart__submit-button,
.wc-block-components-checkout-place-order-button {
	background: var(--wp--preset--color--accent-cobalt-dark) !important;
	border-color: var(--wp--preset--color--accent-cobalt) !important;
	color: var(--wp--preset--color--text-primary) !important;
	border-radius: var(--wp--custom--radius--md) !important;
	min-height: var(--wp--custom--touch-target);
}
.wc-block-cart__submit-button:hover,
.wc-block-cart__submit-button:focus-visible,
.wc-block-components-checkout-place-order-button:hover,
.wc-block-components-checkout-place-order-button:focus-visible {
	background: var(--wp--custom--accent-cobalt-hover) !important;
}

/* Tax line: the rate name is an internal setup note ("US Sales Tax
   (pending jurisdiction setup)"), not customer-facing copy. It comes from
   WooCommerce's tax-rate configuration, which this workstream does not
   touch, so it is swapped for plain wording visually here rather than at
   the source. Screen readers will still announce the underlying rate
   name — a known gap, flagged in docs/MO-170-commerce-qa.md, that can
   only be closed by renaming the tax rate itself. */
.wc-block-components-totals-taxes .wc-block-components-totals-item__label {
	font-size: 0;
}
.wc-block-components-totals-taxes .wc-block-components-totals-item__label::after {
	content: "Estimated tax (sample rate)";
	font-size: var(--wp--preset--font-size--sm);
}

/* =====================================================================
   Checkout
   ===================================================================== */

.mo-checkout__title {
	font-family: var(--wp--preset--font-family--display);
	padding-inline: var(--wp--preset--spacing--md);
}

.wc-block-checkout__terms {
	line-height: 1.5;
}

/* MO-466 D2: "Edit cart" link above the checkout (Mo_Checkout_Ux). */
.mo-checkout-edit-cart {
	max-width: var(--wp--style--global--wide-size, 1200px);
	margin: 0 auto var(--wp--preset--spacing--sm);
	padding-inline: var(--wp--preset--spacing--md);
	font-size: var(--wp--preset--font-size--sm);
}
.mo-checkout-edit-cart a {
	color: var(--wp--preset--color--text-primary);
	text-underline-offset: 3px;
}
/* MO-423 (5): while the cart store loads shipping rates
   (checkout-shipping-state.js), WooCommerce's "No shipping options" notice
   waits; it shows once loading ends with no rates. The status line is for
   screen readers only. */
body.mo-shipping-loading .wc-block-components-shipping-rates-control__no-results-notice {
	display: none !important;
}
.mo-shipping-status {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* MO-423 (2): qualified payment line under "Edit cart" (Mo_Checkout_Ux). */
.mo-checkout-pay-help {
	max-width: var(--wp--style--global--wide-size, 1200px);
	margin: 0 auto var(--wp--preset--spacing--md);
	padding-inline: var(--wp--preset--spacing--md);
	font-size: var(--wp--preset--font-size--sm);
	color: var(--wp--preset--color--text-muted);
}

/* MO-466 D3: order summary rows -- thumbnail (whole photo, no crop, with
   the quantity badge on its corner), name, line price. The unit price and
   the product excerpt repeat the line / product page, as on the cart.
   Scoped one class above WooCommerce's own order-summary rules. */
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item {
	align-items: center;
	gap: var(--wp--preset--spacing--sm);
	padding-block: var(--wp--preset--spacing--sm);
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__image {
	flex: 0 0 64px;
	width: 64px;
	height: 64px;
	margin: 0;
	padding: 0;
	overflow: visible;
	background-color: var(--ar-cabin, rgba(255, 255, 255, 0.04));
	border: 1px solid var(--wp--custom--border-subtle, var(--ar-line, #33415a));
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__image > img {
	display: block;
	width: 100%;
	max-width: none;
	height: 100%;
	object-fit: contain;
	border-radius: inherit;
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__quantity {
	top: auto;
	right: -8px;
	bottom: -8px;
	left: auto;
	transform: none;
	border: 1px solid var(--wp--custom--border-subtle, var(--ar-line, #33415a));
	background: var(--wp--preset--color--surface-elevated);
	font-weight: 700;
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__quantity span {
	color: var(--wp--preset--color--text-primary);
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__quantity span[aria-hidden="true"]::before {
	content: "\00d7";
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__description {
	flex: 1 1 auto;
	padding: 0;
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__description .wc-block-components-product-name {
	margin: 0;
	color: var(--wp--preset--color--text-primary);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	line-height: 1.35;
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary-item__description .wc-block-cart-item__prices,
.wp-block-woocommerce-checkout .wc-block-components-order-summary-item__description .wc-block-components-product-metadata__description {
	display: none;
}
.wp-block-woocommerce-checkout .wc-block-components-order-summary .wc-block-components-order-summary-item__total-price {
	padding-top: 0;
	white-space: nowrap;
	font-weight: 600;
}

/* =====================================================================
   MO-170 — visible concept-render disclosure on the shop card
   ---------------------------------------------------------------------
   components.css styles .mo-concept-tag as an absolutely-positioned
   overlay. On a card this small that would sit on top of the product, so
   here it is returned to normal flow as a caption directly beneath the
   image. Visible to sighted visitors at every width — alt text is not a
   disclosure. Same wording as the product page, deliberately.
   ===================================================================== */
.mo-shop .mo-shop-card__concept {
	position: static;
	max-width: 100%;
	margin: var(--wp--preset--spacing--xs) 0 var(--wp--preset--spacing--sm);
	padding: 0;
	background: none;
	color: var(--wp--preset--color--text-muted);
	font-size: var(--wp--preset--font-size--xs);
	font-style: italic;
	line-height: 1.4;
}

@media (min-width: 768px) {
	.mo-shop .mo-shop-card__concept {
		font-size: var(--wp--preset--font-size--xs);
	}
}

/* =====================================================================
   MO-466 P1: success-notice toast (assets/js/notice-toast.js).
   "X has been added to your cart. View cart" leaves the page flow and
   shows briefly at the bottom: full width above the sticky CTA on
   phones, bottom-right on wider screens. The action uses the storefront
   link colour (accent-cobalt-light, AA-enforced per storefront). Above
   the sticky CTA / consent bar (100), below the Dev strip.
   ===================================================================== */
.mo-toast-region {
	position: fixed;
	left: var(--wp--preset--spacing--sm);
	right: var(--wp--preset--spacing--sm);
	bottom: calc(var(--mo-sticky-h, 0px) + var(--mo-dev-strip, 0px) + env(safe-area-inset-bottom, 0px) + var(--wp--preset--spacing--sm));
	z-index: 1000;
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--xs);
	pointer-events: none;
}

.mo-toast {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--sm);
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--xs) var(--wp--preset--spacing--xs) var(--wp--preset--spacing--md);
	background: var(--wp--preset--color--surface-elevated);
	color: var(--wp--preset--color--text-primary);
	border: 1px solid var(--wp--custom--border-subtle);
	border-radius: var(--wp--custom--radius--md);
	box-shadow: var(--wp--preset--shadow--md);
	pointer-events: auto;
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.mo-toast.is-visible {
	opacity: 1;
	transform: none;
}

.mo-toast__text {
	flex: 1 1 auto;
	margin: 0;
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.4;
}

.mo-toast__action,
.mo-toast__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	min-width: var(--wp--custom--touch-target);
	min-height: var(--wp--custom--touch-target);
	border-radius: var(--wp--custom--radius--sm);
}

.mo-toast__action {
	padding: 0 var(--wp--preset--spacing--xs);
	color: var(--wp--preset--color--accent-cobalt-light);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
	white-space: nowrap;
}

.mo-toast__close {
	padding: 0;
	background: none;
	border: 0;
	color: var(--wp--preset--color--text-secondary);
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.mo-toast__action:hover,
.mo-toast__close:hover {
	color: var(--wp--preset--color--text-primary);
}

@media (min-width: 768px) {
	.mo-toast-region {
		left: auto;
		right: var(--wp--preset--spacing--md);
		bottom: calc(var(--mo-dev-strip, 0px) + var(--wp--preset--spacing--md));
		width: min(400px, calc(100vw - 2 * var(--wp--preset--spacing--md)));
	}
}

@media (prefers-reduced-motion: reduce) {
	.mo-toast {
		transform: none;
		transition: none;
	}
}
