/*
 * THÂN BÀI — kiểu chung cho cả 13 giao diện (theme 1.30.0):
 *   phần 1: ảnh trong bài · phần 2: khối ký tên cuối bài (tác giả + nguồn)
 *
 * ẢNH TRONG BÀI
 *
 * Bài đổ về các báo từ nhiều nguồn nên ảnh tới theo bốn kiểu thẻ:
 *   1. <figure class="wp-caption aligncenter" style="width: 446px"> + figcaption
 *      (bài soạn trong WordPress cổ điển)
 *   2. <figure> + <figcaption> trơn, hoặc figure.wp-block-image (bài lấy tự động,
 *      bài soạn bằng Gutenberg)
 *   3. <table> hai dòng: dòng trên là ảnh, dòng dưới là chú thích (bài chép từ
 *      các báo dùng kiểu "bảng ảnh")
 *   4. <p><img></p> hoặc <img class="align…"> không chú thích
 *
 * Trước đây mỗi bố cục tự lo một phần: bố cục cổ điển (8, 9) không căn giữa
 * khung figure, nên ảnh dạt về lề trái; bố cục Nhật Trình (15–18) thả ảnh
 * alignleft/alignright trôi sang mép; bảng ảnh thì bị base.css biến thành khối
 * cuộn ngang dạt trái. Ra mỗi báo một kiểu.
 *
 * Từ bản này: MỌI ảnh trong bài nằm giữa cột, trong một khung nền nhạt viền
 * mảnh, chú thích nằm trong khung ngay dưới ảnh, chữ nghiêng căn giữa. Ảnh nhỏ
 * giữ đúng cỡ (không phóng to cho vỡ), ảnh lớn co vừa cột. Căn trái/phải trong
 * trình soạn bị bỏ qua — chủ hệ thống chốt luôn căn giữa.
 *
 * File nạp SAU skin-N.css. Bộ chọn mở đầu bằng `body:not(#_)` để có trọng số
 * một id: thắng mọi luật ảnh cũ trong base/layout/skin (kể cả luật float trong
 * @media của layout-nt) mà không cần !important — riêng `width` phải dùng
 * !important vì WordPress ghi width nội tuyến lên figure.wp-caption.
 *
 * Không đụng tới: ảnh đại diện đầu bài, khối quảng cáo trong bài (.bqc-*, chỉ
 * có div/a/img), thư viện ảnh (gallery), khung nhúng video.
 */

body:not(#_) .entry-content {
	--anh-nen: #f4f4f1;
	--anh-vien: #dddcd5;
	--anh-chu: #555;
	--anh-dem: 8px;
}

/* ---- Khung: figure (kiểu 1, 2), div.wp-caption cũ, bảng ảnh (kiểu 3) ---- */
body:not(#_) .entry-content figure:has(img):not(.wp-block-gallery, .wp-block-gallery figure, .gallery figure),
body:not(#_) .entry-content .wp-caption,
body:not(#_) .entry-content table:has(img) {
	display: block;
	box-sizing: border-box;
	width: fit-content !important;  /* đè width nội tuyến của WordPress */
	min-width: min(100%, 260px);    /* ảnh bé tí thì chú thích vẫn đủ chỗ đọc */
	max-width: 100%;
	height: auto;
	float: none;
	clear: both;
	margin: 28px auto;
	padding: var(--anh-dem);
	background: var(--anh-nen);
	border: 1px solid var(--anh-vien);
	border-radius: 0;
	text-align: center;
	overflow: visible;
}

/* Ảnh trong khung: giữa, co vừa cột, không bo góc, không viền riêng. */
body:not(#_) .entry-content figure:has(img) img,
body:not(#_) .entry-content .wp-caption img,
body:not(#_) .entry-content table:has(img) img {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 0 auto;
	padding: 0;
	border: 0;
	border-radius: 0;
	float: none;
}
body:not(#_) .entry-content figure:has(img) > a,
body:not(#_) .entry-content .wp-caption > a { display: block; }

/* ---- Chú thích ---- */
body:not(#_) .entry-content figure:has(img) figcaption,
body:not(#_) .entry-content .wp-caption .wp-caption-text,
body:not(#_) .entry-content table:has(img) td:not(:has(img)),
body:not(#_) .entry-content table:has(img) th:not(:has(img)) {
	/*
	 * contain: inline-size — chú thích không được nới khung ra. Khung ôm đúng bề
	 * rộng ảnh, chú thích dài thì xuống dòng bên trong. Trình duyệt quá cũ không
	 * hiểu thì khung chỉ rộng ra tới hết cột, vẫn căn giữa.
	 */
	contain: inline-size;
	display: block;
	margin: 0;
	padding: 9px 6px 2px;
	border: 0;
	background: none;
	font-size: 14px;
	font-style: italic;
	font-weight: 400;
	line-height: 1.5;
	color: var(--anh-chu);
	text-align: center;
}
body:not(#_) .entry-content table:has(img) td:not(:has(img)) :is(p, em, i, span, strong) {
	margin: 0;
	font-size: inherit;
	line-height: inherit;
	color: inherit;
	text-align: inherit;
}

/* ---- Bảng ảnh: trải phẳng thành khung giống figure ---- */
body:not(#_) .entry-content table:has(img) :is(thead, tbody, tfoot, tr, td, th) {
	display: block;
	width: auto !important;
	height: auto !important;
	border: 0;
	background: none;
}
body:not(#_) .entry-content table:has(img) td:has(img),
body:not(#_) .entry-content table:has(img) th:has(img) {
	padding: 0;
}
/* Dòng/ô trống (nguồn hay để thừa) thì đừng chiếm chỗ. */
body:not(#_) .entry-content table:has(img) td:empty,
body:not(#_) .entry-content table:has(img) tr:empty { display: none; }

/* ---- Ảnh không chú thích (kiểu 4): vẫn giữa cột, cùng khung ---- */
body:not(#_) .entry-content > p > img,
body:not(#_) .entry-content > p > a > img,
body:not(#_) .entry-content > img,
body:not(#_) .entry-content > a > img,
body:not(#_) .entry-content > div:not([class]) > img,
body:not(#_) .entry-content > div:not([class]) > p > img {
	display: block;
	box-sizing: border-box;
	max-width: 100%;
	height: auto;
	float: none;
	margin: 28px auto;
	padding: var(--anh-dem);
	background: var(--anh-nen);
	border: 1px solid var(--anh-vien);
	border-radius: 0;
}
/* Ảnh nằm trong đoạn: khoảng cách trên/dưới do đoạn lo, ảnh chỉ căn giữa. */
body:not(#_) .entry-content > p > img,
body:not(#_) .entry-content > p > a > img,
body:not(#_) .entry-content > div:not([class]) > p > img { margin: 0 auto; }
body:not(#_) .entry-content > p:has(> img, > a > img) {
	margin-top: 28px;
	margin-bottom: 28px;
	text-align: center;
}

/* Căn trái/phải từ trình soạn: luôn đưa về giữa, không cho chữ chảy quanh. */
body:not(#_) .entry-content :is(.alignleft, .alignright, .aligncenter, .alignnone):is(img, figure, .wp-caption) {
	float: none;
	margin-left: auto;
	margin-right: auto;
}

/* ---- Điện thoại: khung mỏng hơn, sát cột hơn ---- */
@media (max-width: 640px) {
	body:not(#_) .entry-content { --anh-dem: 5px; }
	body:not(#_) .entry-content figure:has(img):not(.wp-block-gallery, .wp-block-gallery figure, .gallery figure),
	body:not(#_) .entry-content .wp-caption,
	body:not(#_) .entry-content table:has(img),
	body:not(#_) .entry-content > p:has(> img, > a > img) {
		margin-top: 22px;
		margin-bottom: 22px;
	}
	body:not(#_) .entry-content figure:has(img) figcaption,
	body:not(#_) .entry-content .wp-caption .wp-caption-text,
	body:not(#_) .entry-content table:has(img) td:not(:has(img)) {
		font-size: 13.5px;
		padding: 7px 4px 2px;
	}
}

/*
 * ============================================================================
 * KHỐI KÝ TÊN CUỐI BÀI — tác giả + nguồn
 *
 * HTML do inc/ky-ten.php dựng từ hai đoạn cuối mà Tòa soạn gửi xuống:
 *   <footer class="bai-ky-ten">
 *     <p class="bai-ky-ten__tac-gia">Hà An</p>
 *     <p class="bai-ky-ten__nguon"><span class="bai-ky-ten__nhan">Nguồn</span>
 *        <a class="bai-ky-ten__link" href="…">Báo Giáo dục &amp; Thời đại</a></p>
 *   </footer>
 * Tên tác giả in đậm căn phải theo lối ký tên của báo Việt; dòng nguồn đặt
 * trong ô nền nhạt cùng tông với khung ảnh, link mang màu link của giao diện.
 * ============================================================================
 */
body:not(#_) .entry-content .bai-ky-ten {
	clear: both;
	margin-top: 28px;
	margin-bottom: 0;
}
body:not(#_) .entry-content .bai-ky-ten p { margin: 0; text-indent: 0; }
body:not(#_) .entry-content .bai-ky-ten__tac-gia {
	text-align: right;
	font-weight: 700;
	font-style: normal;
}
body:not(#_) .entry-content .bai-ky-ten__tac-gia + .bai-ky-ten__nguon { margin-top: 16px; }
body:not(#_) .entry-content .bai-ky-ten__nguon {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 4px 10px;
	padding: 10px 14px;
	background: var(--anh-nen);
	border: 1px solid var(--anh-vien);
	font-size: 14.5px;
	font-style: normal;
	line-height: 1.5;
	text-align: left;
}
body:not(#_) .entry-content .bai-ky-ten__nhan {
	font-size: 11.5px;
	font-weight: 700;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--anh-chu);
}
body:not(#_) .entry-content .bai-ky-ten__link,
body:not(#_) .entry-content .bai-ky-ten__ten {
	min-width: 0;
	overflow-wrap: anywhere;
	font-weight: 600;
}
body:not(#_) .entry-content .bai-ky-ten__link { text-decoration: none; }
body:not(#_) .entry-content .bai-ky-ten__link:hover { text-decoration: underline; text-underline-offset: 2px; }
body:not(#_) .entry-content .bai-ky-ten__link::after {
	content: "\2197"; /* ↗ — mở bài gốc ở tab mới */
	display: inline-block;
	margin-left: 4px;
	font-size: .9em;
	font-weight: 400;
	text-decoration: none;
}
