/**
 * Advanced Dynamic Product Showcase Styles
 *
 * @package AdvancedDynamicProductShowcase
 */

/* CSS Variables */
.adps-showcase {
	--adps-list-spacing: 10px;
	--adps-list-radius: 4px;
	--adps-small-img-size: 60px;
	--adps-small-img-radius: 4px;
	--adps-large-radius: 8px;
	--adps-overlay-bg: rgba(0, 0, 0, 0.5);
	--adps-overlay-opacity: 0.5;
	--adps-transition-duration: 0.3s;
	--adps-column-gap: 30px;
	--adps-breakpoint: 767px;
	--adps-aspect-h-per-w: 0.625;
}

/* Root */
.adps-showcase {
	width: 100%;
	contain: layout style paint;
}

.adps-showcase__inner {
	display: flex;
	flex-wrap: wrap;
	gap: var(--adps-column-gap);
	align-items: stretch;
}

/* Desktop: list-left = list on left, preview on right */
.adps-showcase__inner--list-left {
	flex-direction: row;
}

.adps-showcase__inner--list-left .adps-showcase__list {
	order: 1;
}

.adps-showcase__inner--list-left .adps-showcase__preview {
	order: 2;
}

/* Desktop: list-right = list on right, preview on left */
.adps-showcase__inner--list-right {
	flex-direction: row;
}

.adps-showcase__inner--list-right .adps-showcase__list {
	order: 2;
}

.adps-showcase__inner--list-right .adps-showcase__preview {
	order: 1;
}

/* List */
.adps-showcase__list {
	flex: 0 1 280px;
	min-width: 0;
}

.adps-showcase__list-inner {
	display: flex;
	flex-direction: column;
	gap: var(--adps-list-spacing);
}

.adps-showcase__item {
	display: flex;
	align-items: center;
	padding: 10px 12px;
	border-radius: var(--adps-list-radius);
	cursor: pointer;
	transition: background-color var(--adps-transition-duration) ease,
				color var(--adps-transition-duration) ease;
	outline: none;
}

.adps-showcase__item:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.adps-showcase__item-inner {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: 1;
	min-width: 0;
	text-decoration: none;
	color: inherit;
}

.adps-showcase__item-link {
	cursor: pointer;
}

.adps-showcase__item-link:hover {
	text-decoration: none;
	color: inherit;
}

.adps-showcase__item-thumb {
	flex-shrink: 0;
	overflow: hidden;
	border-radius: var(--adps-small-img-radius);
}

.adps-showcase__item-thumb img {
	display: block;
	width: var(--adps-small-img-size);
	height: var(--adps-small-img-size);
	object-fit: cover;
}

.adps-showcase__item-title {
	flex: 1;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	margin: 0;
	font-weight: 500;
}

/* Preview: container lets us cap height without shrinking width (aspect-ratio + max-height narrows the box). */
.adps-showcase__preview {
	container-type: inline-size;
	container-name: adps-preview;
	flex: 1 1 400px;
	min-width: 0;
	min-height: 0;
}

.adps-showcase__preview-image-wrap {
	position: relative;
	overflow: hidden;
	border-radius: var(--adps-large-radius);
	width: 100%;
	min-width: 100%;
	max-width: 100%;
	/* Full width; height = min( width×(h/w), Preview Max Height ). --adps-aspect-h-per-w set inline from aspect ratio option. */
	height: min(
		calc(100cqw * var(--adps-aspect-h-per-w, 0.625)),
		var(--adps-preview-max-height, 10000px)
	);
	max-height: none;
	aspect-ratio: unset;
	background: #f0f0f0;
}

/* Elementor prints max-height from the slider; when cqw works, height + min() already cap — drop duplicate max-height. */
@supports (width: 1cqw) {
	.elementor-widget-advanced-dynamic-product-showcase .adps-showcase__preview-image-wrap {
		max-height: none !important;
	}
}

/* Browsers without container query units: fall back to aspect-ratio (max-height may narrow width). */
@supports not (width: 1cqw) {
	.adps-showcase__preview-image-wrap {
		height: auto;
		aspect-ratio: var(--adps-preview-aspect, 16 / 10);
		max-height: var(--adps-preview-max-height, none);
	}
}

.adps-showcase__large-img {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	object-fit: var(--adps-image-fit, cover);
	object-position: center;
	display: block;
	transition: opacity var(--adps-transition-duration, 0.3s) ease;
	pointer-events: none;
}

.adps-showcase__large-img[data-layer="a"] { z-index: 1; }
.adps-showcase__large-img[data-layer="b"] { z-index: 2; }
.adps-showcase__large-img--next { opacity: 0; }

/* Overlay */
.adps-showcase__overlay {
	position: absolute;
	top: auto;
	left: 0;
	right: auto;
	bottom: 0;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	align-items: flex-start;
	padding: 24px;
	color: #fff;
	pointer-events: none;
	text-align: left;
}

.adps-showcase__overlay .adps-showcase__preview-btn {
	pointer-events: auto;
	align-self: flex-start;
	display: inline-block;
	padding: 10px 20px;
	border-radius: 4px;
	text-decoration: none;
	color: inherit;
	transition: opacity var(--adps-transition-duration) ease,
				background-color var(--adps-transition-duration) ease;
}

.adps-showcase__overlay .adps-showcase__preview-btn:hover {
	opacity: 0.9;
}

.adps-showcase__preview-title {
	margin: 0 0 8px 0;
	font-size: 1.25em;
	font-weight: 600;
	line-height: 1.3;
}

.adps-showcase__preview-price {
	margin: 0 0 8px 0;
	font-size: 1.1em;
	font-weight: 600;
}

.adps-showcase__preview-desc {
	margin: 0 0 12px 0;
	font-size: 0.95em;
	line-height: 1.4;
	opacity: 0.95;
}

.adps-showcase__badge {
	position: absolute;
	top: 16px;
	inset-inline-start: 16px;
	padding: 4px 10px;
	font-size: 0.8em;
	font-weight: 600;
	border-radius: 4px;
}

/* RTL */
[dir="rtl"] .adps-showcase__badge {
	inset-inline-start: auto;
	inset-inline-end: 16px;
}

/* Mobile (breakpoint 767px - override via Elementor responsive controls if needed) */
@media (max-width: 767px) {
	.adps-showcase__inner {
		flex-direction: column;
	}

	.adps-showcase__inner--list-left,
	.adps-showcase__inner--list-right {
		flex-direction: column;
	}

	.adps-showcase__inner--mobile-image-top .adps-showcase__list {
		order: 2;
	}

	.adps-showcase__inner--mobile-image-top .adps-showcase__preview {
		order: 1;
	}

	.adps-showcase__inner--mobile-image-bottom .adps-showcase__list {
		order: 1;
	}

	.adps-showcase__inner--mobile-image-bottom .adps-showcase__preview {
		order: 2;
	}

	.adps-showcase__list {
		flex: 0 1 auto;
		min-width: 0;
	}

	.adps-showcase__preview {
		flex: 0 1 auto;
		min-width: 0;
		min-height: 0;
	}

	/*
	 * Elementor injects list/preview widths & min-widths from layout sliders; on narrow
	 * viewports those px values force horizontal overflow. Reset for this widget only.
	 */
	.elementor-widget-advanced-dynamic-product-showcase .elementor-widget-container {
		min-width: 0;
		max-width: 100%;
	}

	.elementor-widget-advanced-dynamic-product-showcase .adps-showcase__inner {
		min-width: 0;
	}

	.elementor-widget-advanced-dynamic-product-showcase .adps-showcase__list {
		flex: 0 1 auto !important;
		min-width: 0 !important;
		width: 100% !important;
		max-width: 100% !important;
	}

	.elementor-widget-advanced-dynamic-product-showcase .adps-showcase__preview {
		flex: 0 1 auto !important;
		min-width: 0 !important;
		width: 100% !important;
		max-width: 100% !important;
	}

	.elementor-widget-advanced-dynamic-product-showcase .adps-showcase__preview-image-wrap {
		max-width: 100%;
	}
}

/* Screen reader utilities */
.adps-showcase .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
