/**
 * Product page: gallery, summary, variations, sticky bar, zoom.
 * ==========================================================================
 *
 * @package Cropped
 * @since   1.0.0
 * ========================================================================== */

.cr-product__layout {
	display: grid;
	gap: var( --cr-space-xl );
}

@media ( min-width: 64rem ) {
	.cr-product__layout {
		grid-template-columns: minmax( 0, 1.15fr ) minmax( 0, 1fr );
		gap: var( --cr-space-3xl );
		align-items: start;
	}

	/*
	 * The summary follows the shopper down a tall gallery. `align-self: start`
	 * on the grid item is what lets `position: sticky` work — a stretched grid
	 * item is already as tall as the row and has nothing to stick within.
	 */
	.cr-product__summary {
		position: sticky;
		top: calc( var( --cr-header-height-lg ) + var( --cr-space-lg ) );
	}
}

/* --------------------------------------------------------------------------
 * Gallery
 *
 * Phone: a scroll-snap strip, bled to the screen edges. No JavaScript, native
 * momentum, and it cannot desynchronise from itself.
 * Desktop: a thumbnail column beside one large image.
 * -------------------------------------------------------------------------- */

.cr-gallery__stage {
	display: flex;
	gap: var( --cr-space-xs );
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	margin-inline: calc( var( --cr-gutter ) * -1 );
	padding-inline: var( --cr-gutter );
	scrollbar-width: none;
}

.cr-gallery__stage::-webkit-scrollbar {
	display: none;
}

.cr-gallery__slide {
	flex: 0 0 86%;
	margin: 0;
	scroll-snap-align: center;
	background-color: var( --cr-surface-sunken );
	border-radius: var( --cr-radius-sm );
	overflow: hidden;

	/*
	 * `position: relative` is load-bearing, not tidiness.
	 *
	 * Each slide's zoom button carries an `.cr-sr-only` label, which is
	 * `position: absolute`. With no positioned ancestor between them, that
	 * label resolves against the initial containing block — so it escaped both
	 * this box's `overflow: hidden` and the stage's `overflow-x: auto`, and a
	 * 1 px label belonging to a slide scrolled off to the right extended the
	 * *document's* scroll width to 441 px inside a 360 px viewport. The product
	 * page scrolled sideways with nothing visible to explain it.
	 *
	 * Making the slide the containing block keeps the label inside the box it
	 * describes, where the existing clipping already handles it.
	 */
	position: relative;
}

.cr-gallery__zoom {
	display: block;
	inline-size: 100%;
	cursor: zoom-in;
}

.cr-gallery__zoom img {
	inline-size: 100%;
	aspect-ratio: var( --cr-ratio-product );
	object-fit: cover;
}

/* The thumbnail rail is redundant on a phone — the strip already scrolls. */
.cr-gallery__thumbs {
	display: none;
}

@media ( min-width: 64rem ) {
	.cr-gallery {
		display: grid;
		grid-template-columns: 4.5rem minmax( 0, 1fr );
		gap: var( --cr-space-sm );
	}

	.cr-gallery__thumbs {
		display: flex;
		flex-direction: column;
		gap: var( --cr-space-xs );
		margin: 0;
		padding: 0;
		list-style: none;
		/* A long gallery scrolls the rail, not the page. */
		max-block-size: 40rem;
		overflow-y: auto;
		overscroll-behavior-y: contain;
		scrollbar-width: thin;
	}

	.cr-gallery__thumb {
		display: block;
		inline-size: 100%;
		border: 1px solid transparent;
		border-radius: var( --cr-radius-sm );
		overflow: hidden;
		opacity: 0.68;
		transition: opacity var( --cr-duration ) var( --cr-ease ), border-color var( --cr-duration ) var( --cr-ease );
	}

	.cr-gallery__thumb img {
		inline-size: 100%;
		aspect-ratio: var( --cr-ratio-product );
		object-fit: cover;
	}

	.cr-gallery__thumb:hover,
	.cr-gallery__thumb.is-active {
		opacity: 1;
	}

	.cr-gallery__thumb.is-active {
		border-color: var( --cr-text );
	}

	/*
	 * With JavaScript the stage becomes a single frame and slides are swapped.
	 * Without it the `.js` class is never set, the stage stays a scrollable
	 * strip, and the gallery is still complete — which is why the desktop
	 * single-frame rules are scoped to `.js` rather than to the media query.
	 */
	.js .cr-gallery__stage {
		display: block;
		overflow: visible;
		margin-inline: 0;
		padding-inline: 0;
	}

	.js .cr-gallery__slide {
		display: none;
	}

	.js .cr-gallery__slide.is-active {
		display: block;
	}
}

/* --------------------------------------------------------------------------
 * Summary column
 * -------------------------------------------------------------------------- */

.cr-product__eyebrow {
	margin-block-end: var( --cr-space-xs );
}

.cr-product__eyebrow a {
	color: inherit;
	text-decoration: none;
}

.cr-product__eyebrow a:hover {
	color: var( --cr-text-accent );
}

.cr-product__summary .product_title {
	margin: 0 0 var( --cr-space-sm );
	font-size: var( --cr-text-2xl );
}

.cr-product__summary .price {
	display: block;
	margin-block-end: var( --cr-space-md );
	font-size: var( --cr-text-lg );
}

.cr-product__summary .woocommerce-product-details__short-description {
	margin-block-end: var( --cr-space-lg );
	color: var( --cr-text-secondary );
	max-inline-size: var( --cr-measure );
}

.cr-product__whatsapp {
	margin-block-start: var( --cr-space-sm );
}

/* --------------------------------------------------------------------------
 * Variations
 * -------------------------------------------------------------------------- */

.cr-variations__grid {
	display: flex;
	flex-direction: column;
	gap: var( --cr-space-md );
	margin-block-end: var( --cr-space-lg );
}

.cr-variations__label {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var( --cr-space-sm );
	margin-block-end: var( --cr-space-2xs );
}

.cr-variations__label label,
.cr-variations__label .cr-variations__name {
	font-size: var( --cr-text-xs );
	font-weight: var( --cr-weight-semibold );
	letter-spacing: var( --cr-tracking-wider );
	text-transform: uppercase;
	color: var( --cr-text-muted );
}

.cr-size-guide-link {
	display: inline-flex;
	align-items: center;
	gap: var( --cr-space-3xs );
	font-size: var( --cr-text-xs );
	color: var( --cr-text-muted );
	text-decoration: underline;
	text-underline-offset: 0.25em;
	/*
	 * Small link, real target. `padding-block` alone came to 29 px — measured,
	 * not estimated. The minimum makes it 44 without moving the text, which
	 * matters because this sits on the label row beside "Size".
	 */
	padding-block: var( --cr-space-2xs );
	min-block-size: var( --cr-tap-target );
}

.cr-size-guide-link:hover {
	color: var( --cr-text-accent );
}

/*
 * A single-value attribute renders as a stated fact rather than a control —
 * see woocommerce/single-product/add-to-cart/variable.php. It is set in body
 * text, not in the small uppercase eyebrow used for the label: the label is the
 * field name and this is the answer, and the two set identically would make the
 * row read as a heading with nothing under it.
 */
.cr-variations__fixed {
	margin: 0;
	font-size: 1rem;
	color: var( --cr-text-primary );
}

.cr-variations__value select {
	inline-size: 100%;
	min-block-size: var( --cr-control-height );
	padding: var( --cr-space-sm ) var( --cr-space-2xl ) var( --cr-space-sm ) var( --cr-space-md );
	border: 1px solid var( --cr-border-strong );
	border-radius: var( --cr-radius-sm );
	background-color: var( --cr-surface );
	font-size: 1rem;
	appearance: none;
	background-image: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%231a1917' stroke-width='1.5'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E" );
	background-repeat: no-repeat;
	background-position: right var( --cr-space-md ) center;
	background-size: 0.7rem;
}

.reset_variations {
	display: inline-flex;
	align-items: center;
	margin-block-start: var( --cr-space-xs );
	font-size: var( --cr-text-xs );
}

/*
 * "Clear" is a real control and needs a real target. It measured 31x17 on a
 * phone — the same shape of miss as .cr-size-guide-link, and found the same
 * way. It only started appearing on page load once single-value attributes
 * began being pre-selected, which is what first put it in front of a finger.
 *
 * Keyed to pointer:coarse because what decides target size is whether the
 * pointer is a finger, not how wide the screen is.
 */
@media ( pointer: coarse ) {
	.reset_variations {
		min-block-size: var( --cr-tap-target );
		/* Both axes. "Clear" is only 31px of text — height alone left it 31x44. */
		min-inline-size: var( --cr-tap-target );
	}
}

/*
 * WooCommerce shows the reset link only once a variation is chosen. It writes
 * `visibility: hidden` inline, which leaves it occupying a line of space above
 * the add-to-cart button that appears and disappears as the shopper chooses.
 */
.reset_variations[style*="hidden"] {
	display: none;
}

/* --------------------------------------------------------------------------
 * Size swatches, layered over the native select by main.js
 * -------------------------------------------------------------------------- */

.cr-size-picker {
	display: flex;
	flex-wrap: wrap;
	gap: var( --cr-space-xs );
}

.cr-size-picker__option {
	min-inline-size: var( --cr-tap-target );
	min-block-size: var( --cr-tap-target );
	padding-inline: var( --cr-space-sm );
	border: 1px solid var( --cr-border-strong );
	border-radius: var( --cr-radius-sm );
	background-color: var( --cr-surface );
	color: var( --cr-text );
	font-size: var( --cr-text-sm );
	letter-spacing: var( --cr-tracking-wide );
	text-transform: uppercase;
	transition: background-color var( --cr-duration ) var( --cr-ease ), border-color var( --cr-duration ) var( --cr-ease );
}

.cr-size-picker__option:hover:not( :disabled ) {
	border-color: var( --cr-text );
}

.cr-size-picker__option[aria-pressed="true"] {
	background-color: var( --cr-action );
	border-color: var( --cr-action );
	color: var( --cr-action-text );
}

/*
 * A size that cannot be bought. Struck through as well as dimmed, and left in
 * the tab order — a shopper is entitled to find out that their size is the one
 * that is sold out, rather than having it silently vanish.
 */
.cr-size-picker__option:disabled {
	color: var( --cr-text-disabled );
	border-color: var( --cr-border );
	text-decoration: line-through;
	cursor: not-allowed;
}

/* --------------------------------------------------------------------------
 * "Please select the size"
 *
 * Replaces WooCommerce's `window.alert()` — see `initVariationValidation()`
 * in `shop.js` for why an alert was the wrong shape for this.
 *
 * The red, the icon sizing and the flex layout all come from `.cr-field-error`
 * in `components/form.css`, which is the same treatment an invalid checkout
 * field gets; only the spacing and the state of the swatches belong here.
 * `form.css` arrives through `main.css`'s `@import` chain rather than its own
 * enqueue, so it is present on a product page — verified in the browser, not
 * assumed, because a shared component living in a conditionally loaded
 * stylesheet is a bug this theme has shipped more than once.
 * -------------------------------------------------------------------------- */

.cr-variations__error {
	margin-block: var( --cr-space-xs ) 0;
	font-size: var( --cr-text-sm );
}

/*
 * Colour is not the only signal — there is a worded message above — but the
 * swatches carry it too, so the eye is sent to the control and not just to the
 * sentence. Sold-out sizes keep their own disabled styling; they are not the
 * ones that need choosing.
 */
.cr-variations__row.is-invalid .cr-size-picker__option:not( :disabled ),
.cr-variations__row.is-invalid .cr-select {
	border-color: var( --cr-sale );
}

/* --------------------------------------------------------------------------
 * Add to cart
 * -------------------------------------------------------------------------- */

.cr-variations__single .woocommerce-variation-add-to-cart,
.cr-product__summary form.cart {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: var( --cr-space-sm );
}

.cr-product__summary form.cart .single_add_to_cart_button,
.cr-variations__single .single_add_to_cart_button {
	flex: 1 1 12rem;
	min-block-size: var( --cr-control-height );
	font-size: var( --cr-text-base );
}

.woocommerce-variation-price {
	inline-size: 100%;
	margin-block-end: var( --cr-space-xs );
	font-size: var( --cr-text-lg );
}

.woocommerce-variation-availability {
	inline-size: 100%;
}

/* --------------------------------------------------------------------------
 * Detail accordion
 * -------------------------------------------------------------------------- */

.cr-product__details {
	margin-block-start: var( --cr-space-xl );
}

.cr-spec {
	margin: 0;
	font-size: var( --cr-text-sm );
}

.cr-spec dt {
	font-size: var( --cr-text-xs );
	font-weight: var( --cr-weight-semibold );
	letter-spacing: var( --cr-tracking-wider );
	text-transform: uppercase;
	color: var( --cr-text-muted );
	margin-block-start: var( --cr-space-md );
}

.cr-spec dt:first-child {
	margin-block-start: 0;
}

.cr-spec dd {
	margin: var( --cr-space-3xs ) 0 0;
	color: var( --cr-text-secondary );
}

.cr-spec__list {
	margin: 0;
	padding-inline-start: var( --cr-space-md );
}

.cr-spec__list li + li {
	margin-block-start: var( --cr-space-3xs );
}

/* --------------------------------------------------------------------------
 * Related products
 * -------------------------------------------------------------------------- */

.related.products,
.up-sells {
	margin-block-start: var( --cr-space-4xl );
	padding-block-start: var( --cr-space-2xl );
	border-block-start: 1px solid var( --cr-border );
}

.related.products > h2,
.up-sells > h2 {
	margin-block-end: var( --cr-space-xl );
	font-size: var( --cr-text-2xl );
}

/* --------------------------------------------------------------------------
 * Sticky add-to-cart bar (phone only)
 * -------------------------------------------------------------------------- */

.cr-sticky-atc {
	position: fixed;
	inset-inline: 0;
	inset-block-end: 0;
	z-index: var( --cr-z-sticky );
	display: flex;
	align-items: center;
	gap: var( --cr-space-md );
	padding: var( --cr-space-sm ) var( --cr-gutter );
	padding-block-end: calc( var( --cr-space-sm ) + env( safe-area-inset-bottom ) );
	background-color: var( --cr-surface );
	border-block-start: 1px solid var( --cr-border );
	box-shadow: var( --cr-shadow-lg );
	transform: translateY( 100% );
	transition: transform var( --cr-duration ) var( --cr-ease-out );
}

.cr-sticky-atc.is-visible {
	transform: translateY( 0 );
}

@media ( prefers-reduced-motion: reduce ) {
	.cr-sticky-atc {
		transform: none;
		opacity: 0;
		transition: opacity 150ms linear;
	}

	.cr-sticky-atc.is-visible {
		opacity: 1;
	}
}

@media ( min-width: 64rem ) {
	/*
	 * Never on desktop: the summary column is already sticky there, so the real
	 * add-to-cart button is permanently on screen.
	 */
	.cr-sticky-atc {
		display: none;
	}
}

.cr-sticky-atc__info {
	flex: 1 1 auto;
	min-inline-size: 0;
}

.cr-sticky-atc__title {
	margin: 0;
	font-size: var( --cr-text-sm );
	font-weight: var( --cr-weight-medium );
}

.cr-sticky-atc__price {
	margin: 0;
	font-size: var( --cr-text-xs );
	color: var( --cr-text-muted );
}

/* --------------------------------------------------------------------------
 * Zoom modal
 * -------------------------------------------------------------------------- */

.cr-zoom {
	position: fixed;
	inset: 0;
	z-index: var( --cr-z-modal );
	display: grid;
	place-items: center;
	padding: var( --cr-space-md );
	overflow: auto;
	overscroll-behavior: contain;
}

.cr-zoom__image {
	max-inline-size: min( 100%, 60rem );
	max-block-size: 92vh;
	max-block-size: 92dvh; /* `vh` line above is required — see reset.css */
	object-fit: contain;
	border-radius: var( --cr-radius-sm );
	background-color: var( --cr-surface );
}

.cr-zoom__close {
	position: fixed;
	inset-block-start: var( --cr-space-md );
	inset-inline-end: var( --cr-space-md );
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: var( --cr-tap-target );
	block-size: var( --cr-tap-target );
	border-radius: var( --cr-radius-full );
	background-color: var( --cr-surface );
	color: var( --cr-text );
	box-shadow: var( --cr-shadow-md );
}
