/**
 * Unified 2:3 product image frames (display only).
 *
 * Uses --rocky-product-aspect from style.css. object-fit: cover crops in the
 * browser only; uploads and Media Library files are not modified.
 */

/* —— Catalog loops (shop, related, upsells, homepage carousel) —— */

ul.products li.product .rocky-product-image {
	position: relative;
	display: block;
	aspect-ratio: var(--rocky-product-aspect);
	overflow: hidden;
	background: #f4f4f4;
}

ul.products li.product .rocky-product-image__img,
ul.products li.product .rocky-product-image img,
ul.products li.product .rocky-product-image__primary,
ul.products li.product .rocky-product-image__hover {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	display: block;
	margin: 0;
}

ul.products li.product .rocky-product-image__hover {
	position: absolute;
	inset: 0;
	opacity: 0;
	transition: opacity 0.35s ease;
	pointer-events: none;
}

@media (hover: hover) {
	ul.products li.product .rocky-product-image--has-hover:hover .rocky-product-image__hover {
		opacity: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	ul.products li.product .rocky-product-image__hover {
		transition: none;
	}
}

ul.products li.product .rocky-product-image--has-promo .rocky-product-image__primary,
ul.products li.product .rocky-product-image--has-promo .rocky-product-image__hover {
	object-position: center top;
}

/* Legacy loop markup without .rocky-product-image wrapper */
ul.products li.product > a.woocommerce-LoopProduct-link > img,
ul.products li.product a.woocommerce-loop-product__link > img {
	aspect-ratio: var(--rocky-product-aspect);
	width: 100%;
	height: auto;
	object-fit: cover;
	object-position: center;
	display: block;
	background: #f4f4f4;
}

/* —— Single product gallery —— */

.single-product div.product .woocommerce-product-gallery {
	position: relative;
}

.single-product div.product .woocommerce-product-gallery .woocommerce-product-gallery__trigger {
	display: none;
}

.single-product div.product .woocommerce-product-gallery .flex-viewport {
	position: relative;
	aspect-ratio: var(--rocky-product-aspect);
	overflow: hidden;
	background: #f4f4f4;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav {
	list-style: none;
	margin: 0;
	padding: 0;
	position: absolute;
	inset: 0;
	z-index: 5;
	pointer-events: none;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav li {
	position: absolute;
	top: 50%;
	margin: 0;
	transform: translateY(-50%);
	pointer-events: auto;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav .flex-nav-prev {
	left: 0.65rem;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav .flex-nav-next {
	right: 0.65rem;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a {
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--rocky-gallery-nav-size);
	height: var(--rocky-gallery-nav-size);
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.94);
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
	color: var(--rocky-color-text-primary);
	text-decoration: none;
	font-size: 0;
	line-height: 1;
	transition:
		background 0.2s ease,
		box-shadow 0.2s ease,
		opacity 0.2s ease;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a:hover {
	background: var(--rocky-color-surface);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a::before {
	content: '';
	display: block;
	width: 0.45rem;
	height: 0.45rem;
	border: solid currentColor;
	border-width: 2px 2px 0 0;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a.flex-prev::before {
	transform: rotate(-135deg);
	margin-left: 0.15rem;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a.flex-next::before {
	transform: rotate(45deg);
	margin-right: 0.15rem;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a.flex-disabled {
	opacity: 0.35;
	pointer-events: none;
}

.single-product div.product .woocommerce-product-gallery .flex-viewport .woocommerce-product-gallery__image,
.single-product div.product .woocommerce-product-gallery .flex-viewport .woocommerce-product-gallery__image a {
	display: block;
	height: 100%;
}

.single-product div.product .woocommerce-product-gallery .flex-viewport img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	display: block;
}

.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li {
	overflow: hidden;
	aspect-ratio: var(--rocky-product-aspect);
}

.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	display: block;
}

/* PDP gallery: vertical thumbnail column (desktop). Mobile keeps Storefront row below image. */
@media (min-width: 769px) {
	.single-product div.product .woocommerce-product-gallery,
	.single-product div.product .images,
	.storefront-full-width-content.single-product div.product .woocommerce-product-gallery,
	.storefront-full-width-content.single-product div.product .images {
		width: 50%;
		margin-right: 0;
		padding-right: 1.5rem;
	}

	.single-product div.product .summary,
	.storefront-full-width-content.single-product div.product .summary {
		width: 50%;
		margin-right: 0;
	}

	.single-product div.product .woocommerce-product-gallery {
		container-type: inline-size;
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		gap: 0.75rem;
	}

	/* Width lives on the flex item. Variation swaps replace the gallery before
	   the thumb rail wrapper exists, and an unconstrained thumb list then
	   takes the main-image width. */
	.single-product div.product .woocommerce-product-gallery > .rocky-gallery-thumbs,
	.single-product div.product .woocommerce-product-gallery > .flex-control-thumbs {
		order: -1;
		flex: 0 0 var(--rocky-gallery-thumb-width);
		width: var(--rocky-gallery-thumb-width);
		max-width: var(--rocky-gallery-thumb-width);
		min-width: var(--rocky-gallery-thumb-width);
		align-self: flex-start;
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs {
		position: relative;
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs::before,
	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs::after {
		content: '';
		position: absolute;
		left: 0;
		right: 0;
		z-index: 1;
		height: 1.35rem;
		pointer-events: none;
		opacity: 0;
		transition: opacity 0.2s ease;
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs::before {
		top: 0;
		background: linear-gradient(to bottom, var(--rocky-color-surface) 15%, transparent);
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs::after {
		bottom: 0;
		background: linear-gradient(to top, var(--rocky-color-surface) 15%, transparent);
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs--overflow-top::before,
	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs--overflow-bottom::after {
		opacity: 1;
	}

	.single-product div.product .woocommerce-product-gallery .rocky-gallery-thumbs > .flex-control-thumbs {
		width: 100%;
		max-width: 100%;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs {
		max-height: var(
			--rocky-gallery-thumb-max-height,
			calc((100cqi - var(--rocky-gallery-thumb-width) - 0.75rem) * 3 / 2)
		);
		display: flex;
		flex-direction: column;
		gap: 0.5rem;
		margin: 0;
		padding: 0;
		list-style: none;
		overflow-x: hidden;
		overflow-y: auto;
		scrollbar-width: none;
		-ms-overflow-style: none;
		scroll-snap-type: y proximity;
		-webkit-overflow-scrolling: touch;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs::-webkit-scrollbar {
		display: none;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li {
		scroll-snap-align: start;
		flex-shrink: 0;
		border-radius: 0.2rem;
		outline: 1px solid transparent;
		outline-offset: 1px;
		transition:
			outline-color 0.2s ease,
			opacity 0.2s ease;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li img {
		opacity: 0.62;
		transition: opacity 0.2s ease;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li img.flex-active,
	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li:hover img {
		opacity: 1;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li img.flex-active {
		outline: none;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li:has(img.flex-active) {
		outline-color: var(--rocky-color-text-primary);
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs::before,
	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs::after {
		display: none;
	}

	.single-product div.product .woocommerce-product-gallery .flex-control-thumbs li {
		width: 100% !important;
		float: none !important;
		margin: 0 !important;
	}

	.single-product div.product .woocommerce-product-gallery[class*="woocommerce-product-gallery--columns-"]
		.flex-control-thumbs
		li {
		margin-right: 0 !important;
	}

	.single-product div.product .woocommerce-product-gallery .flex-viewport {
		flex: 1 1 auto;
		min-width: 0;
		margin-bottom: 0;
	}
}

/* —— My Account wishlist —— */

.woocommerce-account .rocky-wishlist-account__image {
	display: block;
	aspect-ratio: var(--rocky-product-aspect);
	overflow: hidden;
	background: #f4f4f4;
}

.woocommerce-account .rocky-wishlist-account__image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}
