/**
 * Single product gallery — mobile layout.
 *
 * Woodmart renders the gallery unstyled on phones: the main image sits flat on
 * the page, the prev/next arrows only reveal on hover (so never on touch), the
 * enlarge button hides its label in a small circle at the bottom-left, and the
 * active thumbnail is dimmed instead of highlighted.
 *
 * Below 769px we wrap the main image in a card, pin always-visible round arrows
 * to its edges, turn the enlarge button into a labelled pill at the bottom, and
 * give the thumbnails a bordered square look with the active one outlined.
 *
 * Desktop keeps Woodmart's vertical thumbnail strip, so everything here is
 * inside the mobile media query. All horizontal offsets use logical properties
 * so the Arabic (RTL) layout mirrors without a separate stylesheet.
 */

@media (max-width: 768.98px) {

	/* ── Undo the older gallery styling ──────────────────────────────
	 *
	 * Two earlier rule sets still target this gallery and have to be beaten
	 * here rather than deleted, because both also run on desktop, which we
	 * are leaving alone:
	 *
	 *   1. Woodmart Theme Settings → Custom CSS draws a cyan border, 8px
	 *      padding and a 16px bottom margin on EVERY .wd-carousel-item —
	 *      main slides and thumbnails alike — and pads the active main slide
	 *      by 72px, which is what shrank the image inside its card.
	 *   2. The child theme's inline CSS forces `--wd-col-sm: 1 !important`
	 *      on every .wd-carousel.wd-grid. That selector is broad enough to
	 *      catch the thumbnail carousel, and since the gallery JS reads the
	 *      computed value to set Swiper's slidesPerView, it rendered a single
	 *      full-width thumbnail instead of a row.
	 *
	 * Both original rules use !important, so these need matching weight.
	 */

	body.single-product .wd-single-gallery .woocommerce-product-gallery .wd-carousel-item {
		padding: 0 calc(var(--wd-gap) / 2) !important;
		margin-bottom: 0;
		background: none;
		border: 0;
		border-radius: 0;
	}

	body.single-product .wd-single-gallery .wd-carousel-container.wd-gallery-images .wd-carousel-item.wd-active {
		padding: 0 calc(var(--wd-gap) / 2) !important;
	}

	body.single-product .wd-single-gallery .wd-gallery-thumb .wd-carousel.wd-grid {
		--wd-col-sm: 5 !important;
	}

	/* ── Main image card ─────────────────────────────────────────── */

	.wd-single-gallery .wd-gallery-images > .wd-carousel-inner {
		background-color: #fff;
		border: 1px solid #e5e7eb;
		border-radius: 14px;
		padding: 12px;
	}

	/* Uniform card height whatever the source image aspect ratio is. */
	.wd-single-gallery .wd-gallery-images .woocommerce-product-gallery__image img {
		aspect-ratio: 5 / 4;
		object-fit: contain;
	}

	/* ── Prev / next arrows ──────────────────────────────────────── */

	.wd-single-gallery .wd-gallery-images .wd-nav-arrows {
		--wd-arrow-size: 38px;
		--wd-arrow-icon-size: 13px;
		--wd-arrow-radius: 50%;
		--wd-arrow-bg: #fff;
		--wd-arrow-bg-hover: #fff;
		--wd-arrow-bg-dis: #fff;
		--wd-arrow-color: #333;
		--wd-arrow-color-dis: #c4c4c4;
		--wd-arrow-shadow: 0 2px 8px rgba(0, 0, 0, .16);
	}

	/* The theme only un-hides arrows on hover, which never fires on touch. */
	.wd-single-gallery .wd-gallery-images .wd-nav-arrows,
	.wd-single-gallery .wd-gallery-images .wd-nav-arrows .wd-btn-arrow {
		opacity: 1;
		visibility: visible;
		transform: none;
		pointer-events: auto;
	}

	/* A one-image product leaves both arrows permanently disabled. */
	.wd-single-gallery .wd-gallery-images .wd-nav-arrows:has(.wd-prev.wd-disabled):has(.wd-next.wd-disabled) {
		display: none;
	}

	/* Sit just inside the card instead of Woodmart's width-derived offset. */
	.wd-single-gallery .wd-gallery-images .wd-nav-arrows.wd-pos-sep .wd-prev {
		inset-inline-start: 4px;
		inset-inline-end: auto;
	}

	.wd-single-gallery .wd-gallery-images .wd-nav-arrows.wd-pos-sep .wd-next {
		inset-inline-end: 4px;
		inset-inline-start: auto;
	}

	/* ── Enlarge button → labelled pill, bottom trailing corner ──── */

	.wd-single-gallery .product-additional-galleries {
		inset-inline-start: auto;
		inset-inline-end: 0;
		padding: 12px;
	}

	.wd-single-gallery .wd-show-product-gallery-wrap.wd-style-icon-bg-text > a {
		background-color: var(--wd-primary-color, #28b9de);
		box-shadow: 0 2px 8px rgba(0, 0, 0, .16);
	}

	.wd-single-gallery .wd-show-product-gallery-wrap.wd-style-icon-bg-text .wd-action-icon {
		color: #fff;
		width: calc(var(--wd-action-w) / 1.6);
	}

	/* Label is collapsed to max-width 0 until hover by default. */
	.wd-single-gallery .wd-show-product-gallery-wrap.wd-style-icon-bg-text .wd-action-text {
		max-width: 200px;
		padding-inline-end: calc(var(--wd-action-w) / 2.4);
		color: #fff;
		font-size: 13px;
		font-weight: 500;
	}

	/* ── Thumbnails ──────────────────────────────────────────────── */

	.wd-single-gallery .wd-gallery-thumb {
		margin-top: 4px;
	}

	.wd-single-gallery .wd-gallery-thumb .wd-carousel-item img {
		aspect-ratio: 1;
		object-fit: contain;
		background-color: #fff;
		border: 1px solid #e5e7eb;
		border-radius: 10px;
		padding: 4px;
	}

	/* Woodmart dims the active and hovered thumbnail; outline them instead. */
	.wd-single-gallery .wd-gallery-thumb .wd-carousel-item,
	.wd-single-gallery .wd-gallery-thumb .wd-carousel-item:hover,
	.wd-single-gallery .wd-gallery-thumb .wd-thumb-active,
	.wd-single-gallery .wd-gallery-thumb .wd-carousel:not(.wd-initialized) .wd-carousel-item:first-child {
		opacity: 1;
	}

	.wd-single-gallery .wd-gallery-thumb .wd-thumb-active img {
		border-color: var(--wd-primary-color, #28b9de);
		box-shadow: 0 0 0 1px var(--wd-primary-color, #28b9de);
	}

	/* The strip is swipeable on touch, so its arrows only cover thumbnails. */
	.wd-single-gallery .wd-gallery-thumb .wd-nav-arrows {
		display: none;
	}
}
