/* =========================================================================
 * Content fixes — Chí Vinh
 * Sửa bảng so sánh / bảng nội dung bị TRÀN & CẮT CHỮ trên mobile.
 *
 * Nguyên nhân: bảng .pp-table / .pp-compare-table nằm trong .pp-table-scroll
 * nhưng bản compare bị overflow-x:visible -> tràn ~100px, không cuộn được,
 * cắt mất cột "Mua máy mới". CSS gốc nằm inline trong nội dung nên override
 * ở đây (sitewide) bằng !important cho chắc.
 * ========================================================================= */

/* 1) Mọi wrapper bảng luôn cuộn ngang được, cuộn mượt trên iOS. */
.pp-table-scroll {
	overflow-x: auto !important;
	-webkit-overflow-scrolling: touch;
	position: relative;
}

/* 2) Bảng đủ rộng để chữ không bị bóp, phần dư sẽ cuộn (không cắt). */
.pp-table,
.pp-compare-table {
	min-width: 560px;
}

/* 3) Gợi ý "vuốt ngang" bằng bóng mờ mép phải (chỉ hiện khi còn nội dung). */
.pp-table-scroll::after {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	width: 24px;
	height: 100%;
	pointer-events: none;
	background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(0, 0, 0, .06));
}

/* 4) Dự phòng cho MỌI bảng khác trong nội dung: không tràn khỏi khung. */
.entry-content table,
.page-content table,
.rich-text table,
.product-short-description table {
	max-width: 100%;
}

@media (min-width: 850px) {
	/* Trên desktop bảng vừa khung, tắt bóng gợi ý. */
	.pp-table-scroll::after {
		display: none;
	}
}

/* =========================================================================
 * 5) BẢNG GUTENBERG (.wp-block-table) — responsive + đẹp cho PC & Mobile
 * -------------------------------------------------------------------------
 * Bảng block lõi của WordPress không tự cuộn trên mobile -> bảng nhiều cột
 * (so sánh gói/model...) bị TRÀN & cắt chữ. Xử lý:
 *   - Bọc cuộn ngang ngay trên <figure> (không cần sửa HTML/không cần JS).
 *   - Style header xanh thương hiệu, viền mềm, zebra, bo góc.
 *   - Mobile: GHIM cột đầu (tiêu chí) để so sánh không mất ngữ cảnh + bóng gợi ý vuốt.
 * Biến --fs-color-primary lấy từ Flatsome (mặc định #0e6d3d nếu thiếu).
 * ========================================================================= */

/* Khung cuộn: chính <figure> là vùng cuộn ngang. */
:is(.entry-content, .product-short-description) .wp-block-table {
	--cv-primary: var(--fs-color-primary, #0e6d3d);
	display: block;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	position: relative;
	margin: 24px 0;
	border: 1px solid #e3e8ee;
	border-radius: 12px;
	scrollbar-width: thin;                 /* Firefox */
	scrollbar-color: var(--cv-primary) #eef1f4;
}

/* Thanh cuộn mảnh, gọn (WebKit). */
:is(.entry-content, .product-short-description) .wp-block-table::-webkit-scrollbar { height: 8px; }
:is(.entry-content, .product-short-description) .wp-block-table::-webkit-scrollbar-track { background: #eef1f4; }
:is(.entry-content, .product-short-description) .wp-block-table::-webkit-scrollbar-thumb {
	background: var(--cv-primary);
	border-radius: 8px;
}

/* Bảng: đủ rộng để không bóp chữ (phần dư sẽ cuộn), gộp viền. */
:is(.entry-content, .product-short-description) .wp-block-table table {
	width: 100%;
	min-width: 560px;
	margin: 0;
	border: 0;
	border-collapse: collapse;
	background: #fff;
	font-size: 15px;
	line-height: 1.55;
}

/* Header xanh thương hiệu. */
:is(.entry-content, .product-short-description) .wp-block-table thead th,
:is(.entry-content, .product-short-description) .wp-block-table th {
	background: var(--cv-primary);
	color: #fff;
	font-weight: 700;
	text-align: left;
	padding: 13px 16px;
	border: 1px solid rgba(255, 255, 255, .18);
	white-space: nowrap;                   /* tiêu đề cột không xuống dòng lộn xộn */
}
:is(.entry-content, .product-short-description) .wp-block-table thead th strong { font-weight: 700; }

/* Ô dữ liệu. */
:is(.entry-content, .product-short-description) .wp-block-table td {
	padding: 12px 16px;
	border: 1px solid #e6ebf0;
	vertical-align: top;
	color: #2b3a33;
}

/* Zebra + hover cho dễ đọc theo hàng. */
:is(.entry-content, .product-short-description) .wp-block-table tbody tr:nth-child(even) td { background: #f5faf7; }
:is(.entry-content, .product-short-description) .wp-block-table tbody tr:hover td { background: #eaf5ee; }

/* Nhấn mạnh cột đầu (tiêu chí). */
:is(.entry-content, .product-short-description) .wp-block-table tbody td:first-child {
	font-weight: 600;
	color: #12321f;
}

/* Bo góc mượt cho ô ở 4 góc bảng. */
:is(.entry-content, .product-short-description) .wp-block-table thead tr:first-child th:first-child { border-top-left-radius: 11px; }
:is(.entry-content, .product-short-description) .wp-block-table thead tr:first-child th:last-child { border-top-right-radius: 11px; }
:is(.entry-content, .product-short-description) .wp-block-table tbody tr:last-child td:first-child { border-bottom-left-radius: 11px; }
:is(.entry-content, .product-short-description) .wp-block-table tbody tr:last-child td:last-child { border-bottom-right-radius: 11px; }

/* Caption (nếu có). */
:is(.entry-content, .product-short-description) .wp-block-table figcaption {
	font-size: 13px;
	color: #6b7a72;
	text-align: center;
	padding: 8px 12px 0;
}

/* ---- Mobile: BẢNG DẠNG THẺ "XUỐNG HÀNG" (stacked) ----
 * Mỗi hàng thành 1 thẻ, mỗi ô kèm nhãn cột (data-label do responsive-tables.php
 * gắn). Khách đọc đầy đủ, KHÔNG cần cuộn ngang. HTML vẫn là <table> -> chuẩn SEO.
 * Chỉ áp cho bảng đã đánh dấu data-cv-stack; bảng khác vẫn cuộn ngang (fallback).
 */
@media (max-width: 600px) {

	/* Bảng stacked: bỏ min-width & bỏ cuộn -> vừa khít màn hình. */
	:is(.entry-content, .product-short-description) .wp-block-table:has(table[data-cv-stack]) {
		overflow: visible;
		border: 0;
		border-radius: 0;
	}
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] {
		min-width: 0;
		width: 100%;
		font-size: 15px;
	}

	/* Ẩn hàng tiêu đề (giữ trong DOM cho a11y/SEO) — nhãn đã hiện qua data-label. */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
		border: 0;
		padding: 0;
		margin: -1px;
	}

	/* Mỗi hàng = 1 thẻ. */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody tr {
		display: block;
		border: 1px solid #e3e8ee;
		border-radius: 12px;
		margin: 0 0 14px;
		overflow: hidden;
		box-shadow: 0 1px 3px rgba(16, 40, 30, .05);
		background: #fff;
	}

	/* Mỗi ô = 1 dòng "Nhãn ............ Giá trị". */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
		gap: 14px;
		text-align: right;
		padding: 10px 14px;
		border: 0;
		border-top: 1px solid #eef2f0;
		background: #fff;
		color: #2b3a33;
	}
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td::before {
		content: attr(data-label);
		flex: 0 0 42%;
		text-align: left;
		font-weight: 600;
		color: #12321f;
	}
	/* Ô rỗng thì không tạo dòng trống xấu. */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td:empty { display: none; }

	/* Ô ĐẦU mỗi hàng = tiêu đề thẻ (nền xanh, full-width, không nhãn). */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td:first-child {
		display: block;
		text-align: left;
		background: var(--cv-primary);
		color: #fff;
		font-weight: 700;
		font-size: 16px;
		padding: 12px 14px;
		border-top: 0;
	}
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td:first-child::before {
		display: none;
	}

	/* Bỏ zebra/hover kiểu bảng khi đã ở dạng thẻ. */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody tr:nth-child(even) td,
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody tr:hover td {
		background: #fff;
	}
	/* Ô tiêu đề thẻ luôn giữ nền màu. Trên điện thoại, chạm vào thẻ sẽ kích hoạt :hover
	 * -> nếu thiếu tr:hover ở đây, thẻ hàng lẻ hóa trắng (chữ trắng trên nền trắng). */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody tr:nth-child(even) td:first-child,
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody tr:hover td:first-child {
		background: var(--cv-primary);
	}
	/* Link trong ô tiêu đề thẻ: chữ trắng gạch chân (màu link mặc định trùng nền). */
	:is(.entry-content, .product-short-description) .wp-block-table table[data-cv-stack] tbody td:first-child a {
		color: #fff;
		text-decoration: underline;
		text-underline-offset: 3px;
	}

	/* Fallback: bảng KHÔNG có data-cv-stack vẫn cuộn ngang + gợi ý vuốt. */
	:is(.entry-content, .product-short-description) .wp-block-table:not(:has(table[data-cv-stack])) {
		box-shadow: inset -14px 0 12px -12px rgba(0, 0, 0, .28);
	}
}

/* =========================================================================
 * 6) FAQ BLOCK của RANK MATH (#rank-math-faq) — thẻ card đẹp, chuẩn SEO
 * -------------------------------------------------------------------------
 * RankMath render Q&A dạng thô (h3.rank-math-question + div.rank-math-answer)
 * và tự xuất FAQPage schema. Ở đây CHỈ tạo giao diện card, KHÔNG ẩn nội dung
 * (câu trả lời luôn hiển thị -> tốt cho SEO/AEO & người đọc), tối ưu PC & mobile.
 * ========================================================================= */
.entry-content #rank-math-faq {
	--cv-primary: var(--fs-color-primary, #0e6d3d);
	margin: 28px 0;
}

.entry-content #rank-math-faq .rank-math-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.entry-content #rank-math-faq .rank-math-list-item {
	background: #fff;
	border: 1px solid #e3e8ee;
	border-left: 4px solid var(--cv-primary);
	border-radius: 12px;
	padding: 16px 20px;
	box-shadow: 0 1px 3px rgba(16, 40, 30, .05);
	margin: 0;
}

/* Câu hỏi + huy hiệu "Hỏi". */
.entry-content #rank-math-faq .rank-math-question {
	margin: 0 0 8px;
	padding-left: 34px;
	position: relative;
	font-size: 18px;
	font-weight: 700;
	line-height: 1.45;
	color: #12321f;
}
.entry-content #rank-math-faq .rank-math-question::before {
	content: "?";
	position: absolute;
	left: 0;
	top: 1px;
	width: 24px;
	height: 24px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--cv-primary);
	color: #fff;
	font-size: 15px;
	font-weight: 700;
	border-radius: 50%;
}

/* Câu trả lời. */
.entry-content #rank-math-faq .rank-math-answer {
	color: #3a4a42;
	font-size: 15.5px;
	line-height: 1.7;
	padding-left: 34px;
}
.entry-content #rank-math-faq .rank-math-answer p:last-child { margin-bottom: 0; }
.entry-content #rank-math-faq .rank-math-answer a { color: var(--cv-primary); font-weight: 600; }

/* Mobile: gọn hơn một chút. */
@media (max-width: 600px) {
	.entry-content #rank-math-faq .rank-math-list-item { padding: 14px 16px; }
	.entry-content #rank-math-faq .rank-math-question { font-size: 16.5px; padding-left: 30px; }
	.entry-content #rank-math-faq .rank-math-question::before { width: 22px; height: 22px; font-size: 14px; }
	.entry-content #rank-math-faq .rank-math-answer { font-size: 15px; padding-left: 0; }
}
