/*
 * gp-site-fix — 文章資訊表（主法上師／日期／地址…兩欄欄位表）全寬度呈現
 * 規格：build-site-audit/SPEC_info-table-mobile.md（DESIGN-system-v1 元件清單「表格」指向它）。資料庫原文不動，只在顯示時改。
 * 載入順序：排在 site-fix-3.css 之後（之後由 gp-site-fix.php 輸出）。
 *
 * 套用範圍（規格第六節最後一列）：內文裡「每一列剛好兩格」的表——有 <td> 第 2 格、沒有 <th>、沒有合併儲存格、沒有第 3 格、
 * 沒有只有 1 格的列（td:only-child）或空列（:has() 不能巢狀，所以用「找不到不合格的列」來表達「每一列都合格」）。
 * 舊來源（snippet #21 的「表格美化」、額外 CSS 的 P0／P2、snippet #23 的 .gp-info-table、各篇行內 style）都帶 !important 或行內樣式，
 * 這裡用 html body … :not(#_#_)（id 層級）＋!important 蓋過；只蓋表格本身與它外面那一個資訊框，其他元素不動。
 *
 * 版型看表格自己的寬度（＝資訊框裡面的寬度，container query），不看視窗寬：
 *   ≥324px：兩欄並排。欄位名欄寬＝這張表最長的欄位名，上限 6 字（6×14＝84px），超過的在欄內換行；值欄＝剩下的寬度。
 *   <324px：上下疊。欄位名一行在上、值在下，都從左緣開始。
 *   324＝欄位名上限 84＋欄間距 16＋值 14 字（14×16＝224）（規格 3.2）。
 * 值是空的列（說明列）：欄位名橫跨整列，不留空的值欄（規格 3.4）。
 */

/* ---------- 資訊框（變體 A：行內 style 的米底金線框；變體 C：.gp-info-table 外框）
 * 內距照提示框元件 16–24；表格寬（＝框裡面）<324 時用下限 16。改前 A 是左右 22，C 被 palyul-cta-style 清成 0（字貼金線）。
 * 門檻：框寬 <324＋左右內距 44＋左線 4＝372。框是內文欄全寬，百分比內距的基準（包含區塊＝.entry-content 內容寬）就是框寬，
 * 所以用 calc 做 16／22 兩段，不把 .entry-content 設成 container（container 會擋住開頭段落外距合併，8300 整段下移 20px）。
 * 只動「裡面那張表會被套用」的框（:has() 不能巢狀，條件跟下面表格的套用條件逐項對應）；混合列表的框維持原樣。 */
html body .entry-content div:is([style*="#FAF6EE" i], .gp-info-table):has(> table td:nth-child(2)):not(:has(> table :is(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty))):not(#_#_) {
	padding-left: calc(16px + clamp(0px, (100% - 371.99px) * 1000, 6px)) !important;
	padding-right: calc(16px + clamp(0px, (100% - 371.99px) * 1000, 6px)) !important;
	box-sizing: border-box !important;
}

/* ---------- 表格本身：拿掉卡片感（圓角、陰影、白底、斑馬紋、hover），寬＝框裡面或內文欄 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) {
	display: block !important;
	container: gp-infotable / inline-size;
	width: 100% !important;
	max-width: 100% !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	background: transparent !important;
	overflow: visible !important;
	font-family: var(--gp-font-body) !important;
	font-size: inherit !important;
}
/* 變體 B、C 不在框裡（B 原本行內 max-width:600、上下 20）：上下外距照段落 */
html body .entry-content > table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) {
	margin: 20px 0 !important;
}

/* 兩欄並排：tbody 是格線，每一列用 subgrid 共用同一條欄線（欄位名欄寬＝整張表最長的那個，上限 84） */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody {
	display: grid !important;
	grid-template-columns: fit-content(84px) minmax(0, 1fr);
	column-gap: 16px;
}
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr {
	display: grid !important;
	grid-column: 1 / -1;
	grid-template-columns: subgrid;
	align-items: first baseline; /* 並排時欄位名與值第一行的基線對齊（名 14／1.5 與值 16／1.8 行高不同，頂端對齊會讓名看起來偏高） */
	padding: 6px 0 !important;
	border: 0 !important;
	background: transparent !important;
}
/* 列與列之間 1px 分隔線；第一列上方、最後一列下方不畫，也不留內距（框的內距已經夠） */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr + tr {
	border-top: 1px solid var(--gp-border) !important;
}
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr:first-child {
	padding-top: 0 !important;
}
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr:last-child {
	padding-bottom: 0 !important;
}

/* 每一格：清掉舊的內距、底線、背景、固定寬 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td {
	display: block !important;
	width: auto !important;
	min-width: 0 !important;
	max-width: none !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	background: transparent !important;
	text-align: left !important;
}
/* 欄位名：內文字 600、14px、#6B5E4A；可換行（不撐寬整欄） */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:first-child {
	font-family: var(--gp-font-body) !important;
	font-size: 14px !important;
	font-weight: 600 !important;
	line-height: 1.5 !important;
	color: var(--gp-meta-warm) !important;
	white-space: normal !important;
	overflow-wrap: anywhere;
}
/* 欄位名裡的粗體、連結不另外變色、變粗 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:first-child :is(strong, b) {
	color: inherit !important;
	font-weight: inherit !important;
}
/* 值：＝內文（<922 是 16、≥922 是 16.8，行高 1.8、#2C2420）；英數長串放不下時任意斷 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:nth-child(2) {
	font-family: var(--gp-font-body) !important;
	font-size: 16.8px !important;
	font-weight: 400 !important;
	line-height: 1.8 !important;
	color: var(--gp-tx) !important;
	white-space: normal !important;
	overflow-wrap: anywhere;
	min-width: 0 !important;
	/* 行尾的全形括號、句號不壓成半寬：壓成半寬時那個字的框仍是全寬，會超出值欄 4px（1412 銀行地址列 375 寬實量） */
	text-spacing-trim: space-all;
}
@media (max-width: 921px) {
	html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:nth-child(2) {
		font-size: 16px !important;
	}
}
/* 值裡原本就有的行內標章（例：紅底「已圓滿」）也要能在欄內換行 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:nth-child(2) * {
	max-width: 100%;
	white-space: normal !important;
}

/* 說明列（值是空的）：欄位名橫跨整列，空的值欄不佔位 */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr:has(> td:nth-child(2):empty) > td:first-child {
	grid-column: 1 / -1;
}
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr > td:nth-child(2):empty {
	display: none !important;
}

/* 藏文值：行高 ≥1.6（DESIGN 藏文規則；1.8 已經符合，這裡只防別處把行高壓低） */
html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) td:nth-child(2) :lang(bo) {
	line-height: 1.8 !important;
}

/* ---------- 上下疊：表格寬 <324 */
@container gp-infotable (max-width: 323.98px) {
	html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody {
		grid-template-columns: minmax(0, 1fr);
		row-gap: 0;
	}
	html body .entry-content table:has(td:nth-child(2)):not(:has(th, td[colspan], td[rowspan], td:nth-child(3), td:only-child, tr:empty)):not(#_#_) > tbody > tr {
		grid-template-columns: minmax(0, 1fr);
		row-gap: 4px; /* 欄位名 → 值（S1），列 → 列是上下各 6＝12（S2），約 1:3 */
	}
}
