/**
 * Dropdown layout for WooCommerce Extra Product Options "imagegroup" fields.
 *
 * Scoped entirely under .thwepo-imagegroup-select, which is only emitted by
 * get_html_imagegroup() in quarty-child/thwepo/class-thwepo-utils-field.php.
 * No other field type is affected.
 *
 * The rows deliberately do not carry the plugin's stock grid classes
 * (.thwepo-image-group-item etc.) — style.css sizes those to 46x46 swatch tiles
 * and hides their captions — so nothing here needs to fight inherited styles.
 *
 * Hovering an option's swatch shows the enlarged image; the card is appended to
 * <body> by thwepo-imagegroup.js because the panel's overflow would clip it.
 */

.thwepo-imagegroup-select {
	position: relative;
	width: 100%;
	/*max-width: 520px;*/
	font-size: 15px;
	line-height: 1.4;
}

/* ---------- closed state ---------- */

.thwepo-imagegroup-select .thwepo-imagegroup-trigger {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	min-height: 56px;
	margin: 0;
	padding: 14px 18px;
	background: #fff;
	border: 1px solid #d9d9d9;
	border-radius: 4px;
	box-shadow: none;
	color: #1a1a1a;
	font-size: inherit;
	font-weight: 400;
	line-height: inherit;
	text-align: left;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
}

.thwepo-imagegroup-select .thwepo-imagegroup-trigger:hover,
.thwepo-imagegroup-select .thwepo-imagegroup-trigger:focus {
	background: #fff;
	border-color: #b3b3b3;
	color: #1a1a1a;
	outline: none;
}

.thwepo-imagegroup-select [hidden] {
	display: none !important;
}

/* Swatch + name travel together; the caret stays pinned right. */
.thwepo-imagegroup-trigger-main {
	display: flex;
	align-items: center;
	gap: 14px;
	min-width: 0;
}

.thwepo-imagegroup-trigger-swatch {
	flex: 0 0 auto;
	display: block;
	line-height: 0;
}

.thwepo-imagegroup-trigger-swatch .thwepo-imagegroup-img {
	display: block;
	width: 36px;
	height: 36px;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 1px solid #e0e0e0;
	object-fit: cover;
}

.thwepo-imagegroup-trigger-text {
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* Chevron, drawn in CSS so it needs no image asset. */
.thwepo-imagegroup-caret {
	flex: 0 0 auto;
	width: 10px;
	height: 10px;
	margin-top: -4px;
	border-right: 2px solid #4a4a4a;
	border-bottom: 2px solid #4a4a4a;
	transform: rotate(45deg);
	transition: transform 0.15s ease;
}

.thwepo-imagegroup-select.is-open .thwepo-imagegroup-caret {
	margin-top: 3px;
	transform: rotate(-135deg);
}

/* ---------- open panel ---------- */

.thwepo-imagegroup-panel {
	display: none;
	position: absolute;
	z-index: 99;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	max-height: 300px;
	overflow-x: hidden;
	overflow-y: auto;
	background: #fff;
	border: 1px solid #d9d9d9;
	border-radius: 4px;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
	overscroll-behavior: contain;
}

.thwepo-imagegroup-select.is-open .thwepo-imagegroup-panel {
	display: block;
}

.thwepo-imagegroup-panel::-webkit-scrollbar {
	width: 10px;
}

.thwepo-imagegroup-panel::-webkit-scrollbar-thumb {
	background: #c9c9c9;
	border: 3px solid #fff;
	border-radius: 5px;
}

/* ---------- rows ---------- */

.thwepo-imagegroup-panel .thwepo-imagegroup-option {
	display: block;
	position: relative;
	width: auto;
	height: auto;
	margin: 0;
	background: none;
	border-bottom: 1px solid #ededed;
	box-shadow: none;
	cursor: pointer;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-option:last-child {
	border-bottom: 0;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-option:hover {
	background: #f7f7f7;
}

/* Same off-screen technique the plugin uses: keeps `required` radios focusable
   so the browser can anchor its validation bubble to them. */
.thwepo-imagegroup-panel .thwepo-imagegroup-option input[type="radio"],
.thwepo-imagegroup-panel .thwepo-imagegroup-option input[type="checkbox"] {
	position: absolute;
	bottom: 0;
	left: 18px;
	width: 1px !important;
	height: 1px;
	margin: 0;
	opacity: 0;
	pointer-events: none;
}

/* !important guards against the theme's generic form-label rules. */
.thwepo-imagegroup-panel .thwepo-imagegroup-row {
	display: flex !important;
	align-items: center;
	gap: 16px;
	width: 100%;
	margin: 0 !important;
	padding: 10px 18px;
	font-weight: 400;
	line-height: 1.4;
	text-align: left;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-swatch {
	flex: 0 0 auto;
	display: block;
	line-height: 0;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-img {
	display: block;
	width: 48px;
	height: 48px;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 1px solid #e0e0e0;
	object-fit: cover;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-text {
	flex: 0 1 auto;
	min-width: 0;
	color: #1a1a1a;
	text-align: left;
	overflow-wrap: anywhere;
}

/* The swatch is the zoom trigger, so signal that it is worth pointing at. */
.thwepo-imagegroup-select .thwepo-imagegroup-swatch {
	cursor: zoom-in;
}

/* ---------- placeholder row ---------- */

.thwepo-imagegroup-panel .thwepo-imagegroup-option--placeholder .thwepo-imagegroup-row {
	padding: 16px 18px;
	color: #1a1a1a;
}

/* Reads as the current selection while the field is empty. */
.thwepo-imagegroup-select.is-empty .thwepo-imagegroup-option--placeholder {
	background: #ebebeb;
}

/* ---------- selected state ---------- */

.thwepo-imagegroup-panel .thwepo-imagegroup-option input:checked + .thwepo-imagegroup-row {
	background: #f2f2f2;
}

.thwepo-imagegroup-panel .thwepo-imagegroup-option input:checked + .thwepo-imagegroup-row .thwepo-imagegroup-img {
	border: 2px solid #1a1a1a;
}

/* ---------- hover zoom ---------- */

/* Appended to <body> by the script — the panel's overflow-y would clip it. */
.thwepo-imagegroup-zoom {
	position: absolute;
	z-index: 100000;
	width: 320px;
	padding: 12px;
	background: #fff;
	border: 1px solid #d9d9d9;
	border-radius: 2px;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.12s ease;
	/* Never let the preview eat the pointer — it can overlap the row it came from. */
	pointer-events: none;
}

.thwepo-imagegroup-zoom.is-visible {
	opacity: 1;
	visibility: visible;
}

/* Reserves the image box so the card never resizes, and shows a neutral panel
   instead of the previous option's swatch while a cold image is still loading. */
.thwepo-imagegroup-zoom .thwepo-imagegroup-zoom-media {
	display: block;
	height: 296px;
	background: #f4f4f4;
}

.thwepo-imagegroup-zoom .thwepo-imagegroup-zoom-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	object-fit: cover;
}

.thwepo-imagegroup-zoom.is-loading .thwepo-imagegroup-zoom-img {
	visibility: hidden;
}

.thwepo-imagegroup-zoom .thwepo-imagegroup-zoom-label {
	display: block;
	margin-top: 12px;
	color: #1a1a1a;
	font-size: 14px;
	line-height: 1.4;
	text-align: left;
}

@media (max-width: 480px) {
	.thwepo-imagegroup-select {
		max-width: 100%;
	}

	.thwepo-imagegroup-zoom {
		width: 240px;
	}

	.thwepo-imagegroup-zoom .thwepo-imagegroup-zoom-media {
		height: 216px;
	}
}
