/* ---------- Badge ---------- */
li.product,
.wc-block-components-product-image,
.woocommerce-product-gallery,
.woocommerce-product-gallery__image,
.wp-block-woocommerce-product-image-gallery {
	position: relative;
}

.wcse-badge {
	position: absolute;
	z-index: 9;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	width: max-content;
	padding: 4px 5px 4px 11px;
	border-radius: 999px;
	background: var(--wcse-bg, #e53935);
	color: var(--wcse-color, #fff);
	font-size: 12px;
	line-height: 1.3;
	font-weight: 600;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

/* ตำแหน่งสำรอง (ก่อน JS คำนวณตำแหน่งจริงจากขอบรูปภาพ) */
.wcse-pos-top-left     { top: 10px; left: 10px; }
.wcse-pos-top-center   { top: 10px; left: 50%; transform: translateX(-50%); }
.wcse-pos-top-right    { top: 10px; right: 10px; }
.wcse-pos-center       { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.wcse-pos-bottom-left  { bottom: 10px; left: 10px; }
.wcse-pos-bottom-center{ bottom: 10px; left: 50%; transform: translateX(-50%); }
.wcse-pos-bottom-right { bottom: 10px; right: 10px; }

.wcse-badge__text { white-space: nowrap; }

.wcse-badge__info {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--wcse-color, #fff);
	color: var(--wcse-bg, #e53935);
	font: italic 700 12px/1 Georgia, "Times New Roman", serif;
	cursor: pointer;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
}

.wcse-badge__info:hover,
.wcse-badge__info:focus-visible {
	transform: scale(1.15);
	outline: 2px solid rgba(255, 255, 255, .85);
}

@media (max-width: 480px) {
	.wcse-badge {
		gap: 4px;
		padding: 3px 4px 3px 9px;
		font-size: 11px;
	}
	.wcse-badge__info {
		width: 16px;
		height: 16px;
		font-size: 11px;
	}
}

/* ---------- Modal (ไม่มี scrollbar: JS ปรับขนาดตัวอักษรให้พอดี) ---------- */
.wcse-overlay {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
	background: rgba(0, 0, 0, .55);
	-webkit-overflow-scrolling: auto;
	overscroll-behavior: contain;
}

.wcse-overlay[hidden] { display: none; }

.wcse-modal {
	position: relative;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	width: min(100%, 560px);
	max-height: 100%;
	padding: clamp(16px, 4vw, 28px);
	border-radius: 14px;
	background: #fff;
	color: #222;
	box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
	overflow: hidden;
	font-size: clamp(14px, .9vw + 11px, 16px);
}

.wcse-modal__title {
	flex: 0 0 auto;
	margin: 0 40px 10px 0;
	padding: 0;
	font-size: clamp(17px, 1.4vw + 13px, 22px);
	line-height: 1.3;
	color: inherit;
	word-break: break-word;
}

.wcse-modal__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow: hidden; /* JS จะเปลี่ยนเป็น auto เฉพาะกรณีสุดวิสัยจริงๆ เพื่อไม่ให้เนื้อหาถูกตัด */
	line-height: 1.65;
	word-break: break-word;
}

.wcse-modal__body > :first-child { margin-top: 0; }
.wcse-modal__body > :last-child { margin-bottom: 0; }
.wcse-modal__body p,
.wcse-modal__body li,
.wcse-modal__body td,
.wcse-modal__body th { font-size: 1em; }
.wcse-modal__body h1,
.wcse-modal__body h2,
.wcse-modal__body h3,
.wcse-modal__body h4,
.wcse-modal__body h5,
.wcse-modal__body h6 { font-size: 1.15em; margin: .8em 0 .4em; line-height: 1.3; }
.wcse-modal__body img,
.wcse-modal__body video,
.wcse-modal__body iframe,
.wcse-modal__body table { max-width: 100%; height: auto; }
.wcse-modal__body img { max-height: 35vh; object-fit: contain; }

/* ปุ่มปิด: รีเซ็ตสไตล์ปุ่มของธีมทั้งหมด แล้ววาดกากบาทด้วย CSS (ไม่พึ่งฟอนต์) */
.wcse-overlay .wcse-modal .wcse-modal__close {
	all: unset;
	box-sizing: border-box;
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 2;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: rgba(0, 0, 0, .07);
	color: #555;
	font-size: 0;
	line-height: 0;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color .15s, color .15s, transform .15s;
}

.wcse-overlay .wcse-modal .wcse-modal__close::before,
.wcse-overlay .wcse-modal .wcse-modal__close::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 14px;
	height: 2px;
	border-radius: 2px;
	background: currentColor;
	transform: translate(-50%, -50%) rotate(45deg);
}

.wcse-overlay .wcse-modal .wcse-modal__close::after {
	transform: translate(-50%, -50%) rotate(-45deg);
}

.wcse-overlay .wcse-modal .wcse-modal__close:hover {
	background: rgba(0, 0, 0, .14);
	color: #000;
}

.wcse-overlay .wcse-modal .wcse-modal__close:active { transform: scale(.94); }

.wcse-overlay .wcse-modal .wcse-modal__close:focus { outline: none; }

.wcse-overlay .wcse-modal .wcse-modal__close:focus-visible {
	box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2271b1;
}

.wcse-modal:focus { outline: none; }

@media (prefers-color-scheme: dark) {
	.wcse-modal { background: #1f1f1f; color: #eee; }
	.wcse-overlay .wcse-modal .wcse-modal__close { background: rgba(255, 255, 255, .12); color: #ddd; }
	.wcse-overlay .wcse-modal .wcse-modal__close:hover { background: rgba(255, 255, 255, .22); color: #fff; }
	.wcse-overlay .wcse-modal .wcse-modal__close:focus-visible { box-shadow: 0 0 0 2px #1f1f1f, 0 0 0 4px #72aee6; }
}
