/**
 * ch/quick-view — shared modal styles.
 *
 * Generic and theme-agnostic: colours, radii and spacing are driven by
 * CSS custom properties with neutral fallbacks so consumer themes can
 * skin the modal without overriding rules. No client-specific values.
 */

/* data-wp-bind--hidden toggles the `hidden` attribute. Class rules below set
   explicit display values (flex/grid/block) that would otherwise out-specify
   the UA `[hidden] { display:none }`, leaving "hidden" elements visible — so
   enforce hiding for any element inside the modal. */
.ch-quick-view [hidden] {
	display: none !important;
}

.ch-quick-view {
	--ch-qv-bg: var( --wp--preset--color--white, #fff );
	--ch-qv-fg: var( --wp--preset--color--black, #111 );
	--ch-qv-muted: var( --wp--preset--color--dark-grey, #565657 );
	--ch-qv-border: var( --wp--preset--color--light-grey, #e5e5e5 );
	--ch-qv-accent: var( --wp--preset--color--original-blue, #0071ce );
	--ch-qv-accent-fg: var( --wp--preset--color--white, #fff );
	--ch-qv-radius: var( --wp--preset--spacing--20, 12px );
	--ch-qv-gap: clamp( 1rem, 3vw, 2rem );
	--ch-qv-max-width: 56rem;
}

/* Centered modal. A modal <dialog> is `position: fixed` + top-layer by UA
   default; we set the fixed centering explicitly (and margin:0 to drop the UA
   auto-margins) so it is robust and animatable. Being `fixed` makes it the
   containing block for the absolutely-positioned close button, which stays
   pinned while the inner .ch-quick-view__panel scrolls. */
.ch-quick-view__dialog {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate( -50%, -50% );
	margin: 0;
	width: min( var( --ch-qv-max-width ), calc( 100vw - 2rem ) );
	max-width: var( --ch-qv-max-width );
	max-height: calc( 100dvh - 2rem );
	padding: 0;
	border: 0;
	border-radius: var( --ch-qv-radius );
	background: var( --ch-qv-bg );
	color: var( --ch-qv-fg );
	overflow: hidden;
}

/* When open, lay the dialog out as a flex column so the panel fills the
   capped dialog height exactly (and scrolls inside it) instead of growing
   past it. Scoped to [open] so a closed dialog keeps the UA `display:none`
   — a bare `display:flex` would out-specify it and show the modal always. */
.ch-quick-view__dialog[open] {
	display: flex;
	flex-direction: column;
}

.ch-quick-view__dialog::backdrop {
	background: rgba( 0, 0, 0, 0.55 );
}

@media ( prefers-reduced-motion: no-preference ) {
	.ch-quick-view__dialog {
		opacity: 0;
		transform: translate( -50%, -46% ) scale( 0.98 );
		transition: opacity 0.2s ease, transform 0.2s ease, overlay 0.2s ease allow-discrete, display 0.2s ease allow-discrete;
	}
	.ch-quick-view__dialog[open] {
		opacity: 1;
		transform: translate( -50%, -50% );
	}
	@starting-style {
		.ch-quick-view__dialog[open] {
			opacity: 0;
			transform: translate( -50%, -46% ) scale( 0.98 );
		}
	}
	.ch-quick-view__dialog::backdrop {
		opacity: 0;
		transition: opacity 0.2s ease, overlay 0.2s ease allow-discrete, display 0.2s ease allow-discrete;
	}
	.ch-quick-view__dialog[open]::backdrop {
		opacity: 1;
	}
	@starting-style {
		.ch-quick-view__dialog[open]::backdrop {
			opacity: 0;
		}
	}
}

/* Scroll container — flex-fills the dialog's capped height and scrolls long
   content. `min-height: 0` lets it shrink below content height so overflow
   scrolls rather than overflowing the dialog. The close button is a sibling
   on the (non-scrolling, fixed) dialog, so it stays pinned while this
   scrolls. */
.ch-quick-view__panel {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: clamp( 1.25rem, 4vw, 2.5rem );
}

/* Two-column layout (media | details) on desktop; stacks on narrow. The grid
   belongs on __body — media + details are its children, not the panel's. */
.ch-quick-view__body {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var( --ch-qv-gap );
	align-items: start;
}

@media ( max-width: 640px ) {
	.ch-quick-view__body {
		grid-template-columns: 1fr;
	}
}

.ch-quick-view__close {
	position: absolute;
	top: 0.75rem;
	right: 0.75rem;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --ch-qv-bg );
	color: var( --ch-qv-fg );
	cursor: pointer;
	box-shadow: 0 1px 4px rgba( 0, 0, 0, 0.15 );
}

.ch-quick-view__close:hover {
	background: var( --ch-qv-border );
}

/* ---------- Media — swipe carousel (driven by lib/carousel.js) ---------- */

.ch-quick-view__media {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	min-width: 0;
}

/* Viewport: horizontal scroll-snap strip. setupCarousel() handles snap
   detection, keyboard and programmatic goTo against these slides; the CSS
   here owns the scroll/snap presentation. */
.ch-quick-view__gallery {
	display: flex;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	border-radius: calc( var( --ch-qv-radius ) * 0.66 );
	background: var( --ch-qv-border );
	aspect-ratio: 1;
}

.ch-quick-view__gallery::-webkit-scrollbar {
	display: none;
}

.ch-quick-view__gallery:focus-visible {
	outline: 2px solid var( --ch-qv-accent );
	outline-offset: 2px;
}

.ch-quick-view__slide {
	flex: 0 0 100%;
	scroll-snap-align: center;
}

.ch-quick-view__slide img {
	display: block;
	width: 100%;
	height: 100%;
	aspect-ratio: 1;
	object-fit: cover;
}

.ch-quick-view__dots {
	display: flex;
	justify-content: center;
	gap: 0.45rem;
}

.ch-quick-view__dot {
	width: 7px;
	height: 7px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --ch-qv-border );
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease;
}

.ch-quick-view__dot.is-active {
	background: var( --ch-qv-accent );
	transform: scale( 1.3 );
}

/* Thumbnails are the desktop nav over the same carousel; dots are the mobile
   nav. Show one per breakpoint (matches the body's 640px stack point). */
.ch-quick-view__thumbs {
	display: none;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.ch-quick-view__thumb {
	width: 3.25rem;
	height: 3.25rem;
	padding: 0;
	border: 2px solid transparent;
	border-radius: calc( var( --ch-qv-radius ) * 0.4 );
	overflow: hidden;
	background: none;
	cursor: pointer;
	transition: border-color 0.15s ease;
}

.ch-quick-view__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ch-quick-view__thumb.is-active {
	border-color: var( --ch-qv-accent );
}

@media ( min-width: 641px ) {
	.ch-quick-view__dots {
		display: none;
	}
	.ch-quick-view__thumbs {
		display: flex;
	}
}

/* ---------- Details ---------- */

.ch-quick-view__details {
	display: flex;
	flex-direction: column;
	gap: 0.85rem;
	min-width: 0;
}

.ch-quick-view__title {
	margin: 0;
	font-size: clamp( 1.25rem, 2.5vw, 1.75rem );
	line-height: 1.2;
}

.ch-quick-view__price {
	font-size: 1.25rem;
	font-weight: 700;
}

.ch-quick-view__stock {
	margin: 0;
	font-size: 0.8125rem;
	color: var( --ch-qv-muted );
}

.ch-quick-view__stock[data-status='out'] {
	color: var( --wp--preset--color--red, #d00 );
}

.ch-quick-view__delivery {
	margin: 0.25rem 0 0;
	font-size: 0.8125rem;
	color: var( --ch-qv-muted );
}

.ch-quick-view__delivery-breakdown {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	margin: 0.15rem 0 0;
}

.ch-quick-view__delivery-info {
	align-self: flex-start;
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: var( --ch-qv-muted );
	cursor: pointer;
	line-height: 0;
}

.ch-quick-view__delivery-info:hover,
.ch-quick-view__delivery-info:focus-visible {
	color: inherit;
}

.ch-quick-view__delivery-list {
	font-size: 0.8125rem;
	color: var( --ch-qv-muted );
}

.ch-quick-view__delivery-list-title {
	margin: 0 0 0.15rem;
	font-weight: 600;
}

.ch-quick-view__delivery-list ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ch-quick-view__delivery-list li {
	margin: 0;
	padding: 0.1rem 0;
}

.ch-quick-view__excerpt {
	margin: 0;
	color: var( --ch-qv-muted );
	font-size: 0.9375rem;
	line-height: 1.5;
}

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

.ch-quick-view__variations {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.ch-quick-view__variation {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	font-size: 0.8125rem;
	font-weight: 600;
}

.ch-quick-view__select {
	padding: 0.6rem 0.75rem;
	border: 1px solid var( --ch-qv-border );
	border-radius: calc( var( --ch-qv-radius ) * 0.33 );
	background: var( --ch-qv-bg );
	color: var( --ch-qv-fg );
	font-size: 0.9375rem;
}

/* ---------- Actions ---------- */

.ch-quick-view__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: 0.75rem;
	margin-top: 0.25rem;
}

.ch-quick-view__quantity {
	display: inline-flex;
	align-items: center;
	border: 1px solid var( --ch-qv-border );
	border-radius: calc( var( --ch-qv-radius ) * 0.33 );
	overflow: hidden;
}

.ch-quick-view__qty-btn {
	width: 2.5rem;
	height: 100%;
	min-height: 2.75rem;
	border: 0;
	background: none;
	color: var( --ch-qv-fg );
	font-size: 1.25rem;
	cursor: pointer;
}

.ch-quick-view__qty-input {
	width: 3rem;
	border: 0;
	border-left: 1px solid var( --ch-qv-border );
	border-right: 1px solid var( --ch-qv-border );
	text-align: center;
	font-size: 0.9375rem;
	-moz-appearance: textfield;
	appearance: textfield;
}

.ch-quick-view__qty-input::-webkit-outer-spin-button,
.ch-quick-view__qty-input::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.ch-quick-view__add {
	flex: 1 1 auto;
	min-height: 2.75rem;
	padding: 0 1.5rem;
	border: 0;
	border-radius: calc( var( --ch-qv-radius ) * 0.33 );
	background: var( --ch-qv-accent );
	color: var( --ch-qv-accent-fg );
	font-weight: 600;
	cursor: pointer;
	transition: opacity 0.15s ease, background 0.15s ease;
}

.ch-quick-view__add:hover:not( [disabled] ) {
	opacity: 0.9;
}

.ch-quick-view__add[disabled] {
	opacity: 0.5;
	cursor: not-allowed;
}

.ch-quick-view__add.is-added {
	background: var( --wp--preset--color--green, #1a7f37 );
}

.ch-quick-view__full {
	font-size: 0.8125rem;
	color: var( --ch-qv-muted );
	text-decoration: underline;
}

/* ---------- Loading ---------- */

.ch-quick-view__loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var( --ch-qv-bg );
	z-index: 1;
}

.ch-quick-view__spinner {
	width: 2rem;
	height: 2rem;
	border: 3px solid var( --ch-qv-border );
	border-top-color: var( --ch-qv-accent );
	border-radius: 50%;
	animation: ch-qv-spin 0.7s linear infinite;
}

@keyframes ch-qv-spin {
	to {
		transform: rotate( 360deg );
	}
}

.ch-quick-view__error {
	grid-column: 1 / -1;
	padding: 1rem;
	color: var( --wp--preset--color--red, #d00 );
	font-size: 0.9375rem;
}

.ch-quick-view__announce {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	clip-path: inset( 50% );
	white-space: nowrap;
}

/* Editor placeholder */
.ch-quick-view-editor {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	padding: 1rem 1.25rem;
	border: 1px dashed var( --wp--preset--color--light-grey, #e5e5e5 );
	border-radius: 8px;
	background: var( --wp--preset--color--lightest-grey, #fafafa );
	color: var( --wp--preset--color--dark-grey, #565657 );
}

.ch-quick-view-editor__icon {
	font-size: 1.5rem;
	line-height: 1;
}

.ch-quick-view-editor p {
	margin: 0.25rem 0 0;
	font-size: 0.8125rem;
}
