/**
 * ส่วนรีวิวบนหน้าสินค้า (Phase C1.3 รอบ UI · 14 ส.ค. 2026)
 *
 * โหลดเฉพาะหน้าสินค้า (`includes/product-reviews.php` → `wpc_rev_enqueue()`)
 *
 * ── บริบทที่ตรวจแล้วก่อนเขียนไฟล์นี้ ──────────────────────────────
 * ✅ **CSS 45KB ใน Customizer ไม่มีกฎเกี่ยวกับรีวิวเลยสักข้อ** (ค้นคำว่า comment/rating/star/
 *    commentlist/#reviews = 0 · ที่เจอคำว่า "review" 18 ครั้งเป็น `woocommerce-checkout-review-order-table`
 *    ของหน้า checkout ล้วน) → **รอบนี้ไม่ต้องแข่ง specificity** ต่างจากงาน checkout/cart ที่ผ่านมา
 * ✅ จุดตัดมือถือใช้ 768.98px ให้ตรงธีม
 *
 * โครง DOM ที่อ้างถึง (ของ WooCommerce + WoodMart — ห้ามเปลี่ยนชื่อคลาสเอง):
 *   #reviews > .wd-rating-summary-wrap > .wd-rating-summary
 *            > #comments > .wd-reviews-heading > .wd-reviews-tools (หัวข้อ + ล้างตัวกรอง)
 *                                              > form.wd-reviews-filters (เฉพาะมีรูป + เรียง)
 *                        > .wd-reviews-content > ol.commentlist > li.review
 *            > #review_form_wrapper > #respond (ฟอร์ม)
 */

/* ==================================================================
 * 0) เก็บขยะจาก widget หัวข้อที่เราเพิ่มเข้า layout เอง
 *    (ค่าเริ่มต้นของ wd_title พ่น "Subtitle text example" / "Text after title text example")
 *    แก้ที่ตัวสคริปต์ layout แล้ว — กฎนี้เป็นตาข่ายกันพลาดถ้ามีใครเพิ่ม widget ซ้ำผ่าน Elementor
 * ================================================================== */
#wpc-product-reviews .title-subtitle,
#wpc-product-reviews .title-after_title {
	display: none !important;
}

#wpc-product-reviews {
	scroll-margin-top: 90px;   /* กันหัวเว็บที่ตรึงอยู่บังตอนกดลิงก์ #wpc-product-reviews จากอีเมล/LINE */
}

/* ==================================================================
 * 1) แดชบอร์ดสรุปคะแนน (ของธีม เปิดผ่าน filter — ไม่ได้เขียนเอง)
 * ================================================================== */
.wd-rating-summary-wrap {
	margin-bottom: 24px;
	padding: 18px;
	border: 1px solid #eee;
	border-radius: 12px;
	background: #fff;
	color-scheme: only light;
}

.wd-rating-summary {
	display: flex;
	flex-direction: column;
	gap: 18px;
}

.wd-rating-summary-heading {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding-bottom: 14px;
	border-bottom: 1px solid #f2f2f2;
}

.wd-rating-summary-main {
	font-size: 42px;
	font-weight: 700;
	line-height: 1.1;
	color: #23211f;
	-webkit-text-fill-color: #23211f;
}

.wd-rating-summary-total {
	font-size: 13px;
	color: #6d6864;
	-webkit-text-fill-color: #6d6864;
}

/* แถบ 5★–1★ ของธีม → chip กดกรองแถวเดียว (Phase C2 ส่วน A)
   ทำด้วย CSS ล้วน ไม่แตะ markup — ตัวกรองจริง (`?wd_rating=`) ยังเป็นของธีม
   คลาส `wd-active` / `wd-empty` ธีมติดมาให้เอง (class-rating-summary.php:123-125)
   ธีมอัปเดตแล้วคลาสเปลี่ยน = กลับไปหน้าตาเดิม ไม่ใช่พัง */
.wd-rating-summary-cont {
	display: flex;
	flex-direction: row;
	flex-wrap: nowrap;
	gap: 8px;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	padding-bottom: 4px;
}

.wd-rating-summary-cont::-webkit-scrollbar { display: none; }

.wd-rating-summary-item {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 7px 14px;
	border: 1px solid #e0e0e0;
	border-radius: 999px;
	background: #fff;
	cursor: pointer;
	min-height: 36px;
	transition: background .15s ease;
}

.wd-rating-summary-item:hover { background: #faf9f8; }

/* chip ที่กำลังกรองอยู่ */
.wd-rating-summary-item.wd-active {
	border-color: #f5a623;
	background: #fff8ec;
}

/* chip ที่ยังไม่มีรีวิวเลย — จางลงแต่ยังกดได้ */
.wd-rating-summary-item.wd-empty { opacity: 0.55; }

.wd-rating-summary-item .wd-rating-label { flex: 0 0 auto; min-width: 0; }

/* โหมด chip ไม่มีแท่งเปอร์เซ็นต์ */
.wd-rating-summary-item .wd-rating-progress-bar { display: none; }

.wd-rating-summary-item .wd-rating-count {
	flex: 0 0 auto;
	font-size: 13px;
	color: #6d6864;
	-webkit-text-fill-color: #6d6864;
	white-space: nowrap;
}

@media ( max-width: 768.98px ) {
	.wd-rating-summary-item { padding: 6px 12px; }
}

/* ==================================================================
 * 2) หัวข้อ + แถบตัวกรอง/เรียง
 * ================================================================== */
#reviews .wd-reviews-heading {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 14px;
}

#reviews .woocommerce-Reviews-title {
	margin: 0;
	font-size: 18px;
	font-weight: 600;
	color: #23211f;
	-webkit-text-fill-color: #23211f;
}

#reviews .wd-reviews-filters {
	display: flex;
	align-items: center;
	gap: 14px;
	flex-wrap: wrap;
}

#reviews .wd-with-image label {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 7px 12px;
	border: 1px solid #e3e3e3;
	border-radius: 99px;
	font-size: 13px;
	line-height: 1.2;
	cursor: pointer;
	background: #fff;
}

#reviews .wd-with-image input:checked + label {
	border-color: #e8430a;
	background: #fff5f1;
	color: #c9380a;
	-webkit-text-fill-color: #c9380a;
}

#reviews .wd-reviews-sorting-clear {
	font-size: 13px;
	color: #e8430a;
	-webkit-text-fill-color: #e8430a;
	text-decoration: underline;
}

#reviews .wd-reviews-sorting-clear.wd-hide {
	display: none;
}

/* ==================================================================
 * 3) การ์ดรีวิว
 * ================================================================== */
#reviews ol.commentlist {
	margin: 0;
	padding: 0;
	list-style: none;
}

#reviews ol.commentlist li.review {
	margin-bottom: 12px;
}

#reviews .comment_container {
	padding: 16px;
	border: 1px solid #eee;
	border-radius: 12px;
	background: #fff;
	color-scheme: only light;
}

#reviews .comment-text p.meta {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0 0 6px;
	font-size: 14px;
}

#reviews .woocommerce-review__author {
	font-weight: 600;
	color: #23211f;
	-webkit-text-fill-color: #23211f;
}

#reviews .woocommerce-review__dash {
	display: none;   /* ขีดคั่นแบบฝรั่ง — ตัดออก ใช้ระยะห่างแทน */
}

#reviews .woocommerce-review__published-date {
	font-size: 13px;
	color: #8a8580;
	-webkit-text-fill-color: #8a8580;
}

/* ป้าย "ซื้อสินค้านี้แล้ว" (เปิดผ่าน show_reviews_purchased_indicator) */
#reviews .woocommerce-review__verified,
#reviews .wd-purchased-indicator {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 2px 8px;
	border-radius: 99px;
	background: #eaf7ef;
	color: #1f7a45;
	-webkit-text-fill-color: #1f7a45;
	font-size: 12px;
	font-style: normal;
	font-weight: 500;
}

#reviews .comment-text .star-rating {
	margin-bottom: 8px;
	font-size: 13px;
}

#reviews .comment-text .description {
	font-size: 15px;
	line-height: 1.6;
	color: #3d3a37;
	-webkit-text-fill-color: #3d3a37;
}

#reviews .comment-text .description p:last-child {
	margin-bottom: 0;
}

/* รูปที่ลูกค้าแนบมา — ธีมพ่นผ่าน gallery shortcode */
#reviews .comment-text .wd-images-gallery,
#reviews .comment-text .gallery {
	margin-top: 10px;
}

#reviews .comment-text .wd-images-gallery img,
#reviews .comment-text .gallery img {
	width: 84px !important;
	height: 84px !important;
	max-width: 84px !important;
	object-fit: cover !important;
	border: 1px solid #eee;
	border-radius: 8px;
	cursor: zoom-in;
	background: #fff;
}

/* ==================================================================
 * 4) ฟอร์มเขียนรีวิว
 * ================================================================== */
#review_form_wrapper {
	margin-top: 22px;
	padding: 18px;
	border: 1px solid #eee;
	border-radius: 12px;
	background: #fcfbfa;
	color-scheme: only light;
}

#reviews #reply-title {
	display: block;
	margin-bottom: 4px;
	font-size: 17px;
	font-weight: 600;
	color: #23211f;
	-webkit-text-fill-color: #23211f;
}

.wpc-rev-form__note,
#reviews .comment-notes {
	margin: 0 0 14px;
	font-size: 13px;
	color: #6d6864;
	-webkit-text-fill-color: #6d6864;
}

#reviews .comment-form-rating label {
	display: block;
	margin-bottom: 4px;
	font-size: 14px;
	font-weight: 500;
}

/* ดาวให้คะแนน — WooCommerce แปลง select เป็น p.stars ด้วย JS ของมันเอง
 *
 * 🔴🔴 **ห้ามตั้ง `font-size` ให้ `p.stars a` เด็ดขาด**
 *      ธีมซ่อนข้อความ "1 of 5 stars … 5 of 5 stars" ด้วย `.stars span { font-size: 0 }`
 *      แล้ววาดดาวจาก `a:before` ที่ตั้งขนาดเองด้วย `var(--wd-text-font-size)`
 *      → ตั้ง font-size ที่ตัว <a> เมื่อไหร่ = ปลุกข้อความกลับมาโผล่ทับกันทันที (เจอจริง 14 ส.ค.)
 *      **วิธีที่ถูกคือขยับตัวแปรของธีม** ซึ่งคุมทั้งความกว้างของช่องและขนาดดาวพร้อมกัน
 *      · มีเทสใน tests/test-product-reviews.php ดักไว้แล้ว
 */
#reviews p.stars {
	--wd-text-font-size: 26px;
}

#reviews p.stars span {
	gap: 4px;
}

/* ถ้าดาวไม่ถูกสร้าง (JS ของ Woo ไม่ทำงาน) ต้องเห็น dropdown แทน ห้ามซ่อนทิ้ง */
#respond.wpc-rev-no-stars #rating {
	display: block !important;
	width: 100%;
	max-width: 320px;
	height: 44px;
	border: 1px solid #ddd;
	border-radius: 10px;
	padding: 0 12px;
}

#reviews .comment-form-comment label {
	display: block;
	margin-bottom: 4px;
	font-size: 14px;
	font-weight: 500;
}

#reviews textarea#comment {
	width: 100%;
	min-height: 110px;
	padding: 12px 14px;
	border: 1px solid #ddd;
	border-radius: 10px;
	font-size: 15px;
	line-height: 1.55;
	background: #fff;
	resize: vertical;
}

#reviews textarea#comment:focus,
#reviews .comment-form input[type="text"]:focus,
#reviews .comment-form input[type="email"]:focus {
	border-color: #e8430a;
	outline: none;
	box-shadow: 0 0 0 3px rgba(232, 67, 10, .12);
}

#reviews .comment-form input[type="text"],
#reviews .comment-form input[type="email"] {
	width: 100%;
	height: 44px;
	padding: 0 14px;
	border: 1px solid #ddd;
	border-radius: 10px;
	font-size: 15px;
	background: #fff;
}

#reviews .form-submit input[type="submit"],
#reviews .form-submit .submit {
	min-height: 46px;
	padding: 0 26px;
	border-radius: 10px;
	background: #e8430a;
	color: #fff;
	-webkit-text-fill-color: #fff;
	font-size: 15px;
	font-weight: 600;
	border: none;
}

#reviews .form-submit input[type="submit"]:hover {
	background: #c9380a;
}

/* ==================================================================
 * 5) ตัวอัปโหลดรูปของเรา (แทนหน้าตาเปล่า ๆ ของธีม)
 * ================================================================== */

/* ซ่อนของเดิมของธีม — ตัว input ยังอยู่ (ห้ามลบ ธีมอ่านไฟล์จากช่องนี้) */
#reviews .wd-add-img-btn-wrapper > label,
#reviews .wd-add-img-msg,
#reviews .wd-add-img-count,
#reviews #wd-add-img-btn {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

.wpc-rev-upload {
	margin: 14px 0;
}

.wpc-rev-upload__zone {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	width: 100%;
	min-height: 96px;
	padding: 14px;
	border: 1.5px dashed #d9d4d0;
	border-radius: 12px;
	background: #fff;
	cursor: pointer;
	transition: border-color .15s ease, background .15s ease;
}

.wpc-rev-upload__zone:hover,
.wpc-rev-upload__zone.is-over {
	border-color: #e8430a;
	background: #fff8f5;
}

.wpc-rev-upload__icon {
	font-size: 24px;
	line-height: 1;
}

.wpc-rev-upload__hint {
	font-size: 15px;
	font-weight: 600;
	color: #23211f;
	-webkit-text-fill-color: #23211f;
}

.wpc-rev-upload__sub {
	font-size: 12.5px;
	color: #8a8580;
	-webkit-text-fill-color: #8a8580;
	text-align: center;
}

.wpc-rev-upload__list {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 10px;
}

.wpc-rev-upload__item {
	position: relative;
	width: 84px;
	height: 84px;
	border: 1px solid #eee;
	border-radius: 10px;
	overflow: hidden;
	background: #fff;
}

.wpc-rev-upload__item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.wpc-rev-upload__del {
	position: absolute;
	top: 4px;
	right: 4px;
	width: 24px;
	height: 24px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: rgba(0, 0, 0, .6);
	color: #fff;
	-webkit-text-fill-color: #fff;
	font-size: 16px;
	line-height: 24px;
	text-align: center;
	cursor: pointer;
}

.wpc-rev-upload__del:hover {
	background: #e8430a;
}

.wpc-rev-upload__counter {
	margin-top: 8px;
	font-size: 12.5px;
	color: #6d6864;
	-webkit-text-fill-color: #6d6864;
}

.wpc-rev-upload__errors {
	display: none;
	margin-top: 10px;
}

.wpc-rev-upload__errors.is-show {
	display: block;
}

.wpc-rev-upload__error {
	padding: 8px 12px;
	margin-bottom: 6px;
	border-radius: 8px;
	background: #fdecea;
	color: #b3261e;
	-webkit-text-fill-color: #b3261e;
	font-size: 13px;
	line-height: 1.45;
}

/* กล่องชวนล็อกอิน (คนยังไม่ล็อกอินแนบรูปไม่ได้ — ข้อจำกัดของธีม) */
.wpc-rev-guest {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	margin: 14px 0;
	padding: 12px 14px;
	border: 1px solid #ffe0b2;
	border-radius: 10px;
	background: #fff8ec;
	color-scheme: only light;
}

.wpc-rev-guest__icon {
	font-size: 18px;
	line-height: 1.4;
}

.wpc-rev-guest__text {
	font-size: 13.5px;
	line-height: 1.55;
	color: #6b4b16;
	-webkit-text-fill-color: #6b4b16;
}

.wpc-rev-guest__text a {
	color: #e8430a;
	-webkit-text-fill-color: #e8430a;
	font-weight: 600;
	text-decoration: underline;
}

.wpc-rev-guest__text small {
	display: block;
	font-size: 12px;
	color: #8a8580;
	-webkit-text-fill-color: #8a8580;
}

/* ==================================================================
 * 6) จอคอม
 * ================================================================== */
@media (min-width: 769px) {
	.wd-rating-summary {
		flex-direction: row;
		align-items: center;
	}

	.wd-rating-summary-heading {
		flex: 0 0 190px;
		padding: 0 22px 0 0;
		border-bottom: none;
		border-right: 1px solid #f2f2f2;
	}

	.wd-rating-summary-cont {
		flex: 1 1 auto;
		padding-left: 22px;
	}

	.wpc-rev-upload__zone {
		min-height: 110px;
	}
}

@media (max-width: 768.98px) {
	#reviews .wd-reviews-heading {
		flex-direction: column;
		align-items: flex-start;
	}

	#reviews .form-submit input[type="submit"],
	#reviews .form-submit .submit {
		width: 100%;
	}

	.wpc-rev-upload__item,
	#reviews .comment-text .wd-images-gallery img,
	#reviews .comment-text .gallery img {
		width: 72px !important;
		height: 72px !important;
		max-width: 72px !important;
	}
}
