/* Comma PDF Flipbook — giao diện trình đọc */

.cpfb-reader {
	position: relative;
	width: 100%;
	min-height: 360px;
	margin: 24px 0;
	background: #1b1b1f;
	border-radius: 14px;
	padding: 18px 18px 64px;
	box-sizing: border-box;
	overflow: hidden;
}

.cpfb-reader:fullscreen {
	border-radius: 0;
	padding: 24px 24px 72px;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

/* --- khung cuộn: chỉ có tác dụng khi phóng to quá khổ màn hình --- */
.cpfb-viewport {
	position: relative;
	display: flex;
	width: 100%;
	overflow: auto;
	overscroll-behavior: contain;
}

/* margin:auto CHỨ KHÔNG justify-content:center — canh giữa bằng
   justify-content thì lúc nội dung rộng hơn khung, phần tràn bên trái bị cắt
   và không cuộn tới được. margin:auto trong flex thì không bị lỗi đó. */
.cpfb-viewport > * {
	margin: auto;
	flex: 0 0 auto;
}

.cpfb-reader.cpfb-zoomed .cpfb-viewport {
	cursor: grab;
}

/* --- sách --- */
.cpfb-stage {
	margin: 0 auto;
	/* StPageFlip ghi min-width/min-height thẳng vào style của khung, tính từ
	   tuỳ chọn minWidth. Plugin cố tình đặt minWidth cực lớn để ép chế độ
	   1 trang/màn, nên phải chặn lại ở đây, nếu không khung phình ra cả triệu
	   pixel. Quy tắc !important của stylesheet đè được style nội tuyến. */
	min-width: 0 !important;
	min-height: 0 !important;
}

.cpfb-page {
	background: #fff;
	overflow: hidden;
}

.cpfb-page__ph {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	color: #c9c9cf;
	font-size: 13px;
	background: #f4f4f6;
}

.cpfb-canvas {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

/* --- thanh điều khiển --- */
.cpfb-bar {
	position: absolute;
	left: 50%;
	bottom: 14px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 6px;
	background: rgba(255, 255, 255, 0.1);
	border: 1px solid rgba(255, 255, 255, 0.14);
	border-radius: 999px;
	backdrop-filter: blur(8px);
	z-index: 5;
}

/* Nút tải là thẻ <a> -> ăn màu link của theme và đè lên màu trắng.
   Phải ghi rõ màu cho cả 4 trạng thái, kèm !important vì theme thường
   đặt "a { color: ... }" với độ ưu tiên cao hơn. */
.cpfb-reader .cpfb-btn,
.cpfb-reader a.cpfb-btn,
.cpfb-reader a.cpfb-btn:link,
.cpfb-reader a.cpfb-btn:visited,
.cpfb-reader a.cpfb-btn:hover,
.cpfb-reader a.cpfb-btn:focus {
	width: 34px;
	height: 34px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #fff !important;
	cursor: pointer;
	text-decoration: none;
	box-shadow: none;
	transition: background 0.15s;
}

.cpfb-reader .cpfb-btn:hover,
.cpfb-reader a.cpfb-btn:hover {
	background: rgba(255, 255, 255, 0.16);
}

/* SVG vẽ theo currentColor -> ép luôn cho chắc */
.cpfb-reader .cpfb-btn svg {
	stroke: currentColor;
}

.cpfb-btn svg { display: block; }

.cpfb-sep {
	width: 1px;
	height: 18px;
	background: rgba(255, 255, 255, 0.18);
	margin: 0 2px;
}

.cpfb-counter {
	min-width: 78px;
	text-align: center;
	color: #fff;
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	opacity: 0.9;
}

/* --- đang tải --- */
.cpfb-loading {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	z-index: 4;
}

.cpfb-loading__label {
	color: #d8d8e0;
	font-size: 13.5px;
}

.cpfb-loading__track {
	width: min(260px, 60%);
	height: 4px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.14);
	overflow: hidden;
}

.cpfb-loading__bar {
	width: 0;
	height: 100%;
	background: #fff;
	border-radius: 999px;
	transition: width 0.25s ease;
}

/* --- lỗi --- */
.cpfb-error {
	padding: 22px;
	text-align: center;
	color: #ffd7d7;
	background: rgba(179, 45, 46, 0.18);
	border: 1px solid rgba(179, 45, 46, 0.4);
	border-radius: 10px;
	font-size: 14px;
}

/* --- điện thoại: sách 1 trang, nút to hơn cho dễ bấm --- */
@media (max-width: 640px) {
	.cpfb-reader {
		padding: 12px 12px 58px;
		border-radius: 10px;
	}

	.cpfb-btn {
		width: 40px;
		height: 40px;
	}
}

/* ------------------------------------------------------------------
   Mẫu trang chi tiết PDF (templates/single-pdf_file.php)
   Cố ý viết tối giản và trung tính để không chọi với giao diện theme.
   ------------------------------------------------------------------ */
.cpfb-single__wrap {
	max-width: 1180px;
	margin: 0 auto;
	padding: 28px 20px 48px;
}

.cpfb-single__cats {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 10px;
}

.cpfb-single__cat {
	display: inline-block;
	padding: 3px 11px;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.06);
	font-size: 12.5px;
	text-decoration: none;
	color: inherit;
}

.cpfb-single__title {
	margin: 0 0 8px;
	line-height: 1.25;
}

.cpfb-single__meta {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	font-size: 13.5px;
	opacity: 0.7;
}

.cpfb-single__desc {
	margin-top: 16px;
	line-height: 1.7;
}

@media (max-width: 640px) {
	.cpfb-single__wrap {
		padding: 18px 12px 32px;
	}
}

/* ------------------------------------------------------------------
   Bảng bên: Mục lục & Thumbnail
   ------------------------------------------------------------------ */
.cpfb-panel {
	position: absolute;
	top: 12px;
	left: 12px;
	bottom: 62px;
	width: min(320px, calc(100% - 24px));
	display: flex;
	flex-direction: column;
	background: rgba(28, 28, 32, 0.96);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 12px;
	backdrop-filter: blur(10px);
	z-index: 6;
	overflow: hidden;
	animation: cpfbPanelIn 0.18s ease;
}

.cpfb-panel[hidden] { display: none; }

@keyframes cpfbPanelIn {
	from { opacity: 0; transform: translateX(-8px); }
	to   { opacity: 1; transform: none; }
}

.cpfb-panel__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 11px 12px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.1);
	color: #fff;
	font-size: 13.5px;
	flex: none;
}

.cpfb-panel__x {
	width: 26px;
	height: 26px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #fff;
	cursor: pointer;
}

.cpfb-panel__x:hover { background: rgba(255, 255, 255, 0.14); }

.cpfb-panel__body {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 8px;
}

/* --- mục lục --- */
.cpfb-toc-list { list-style: none; margin: 0; padding: 0; }

.cpfb-toc-item {
	display: block;
	width: 100%;
	text-align: left;
	padding: 8px 10px;
	border: 0;
	border-radius: 7px;
	background: transparent;
	color: #d8d8e0;
	font-size: 13px;
	line-height: 1.45;
	cursor: pointer;
}

.cpfb-toc-item:hover {
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
}

/* --- thumbnail --- */
.cpfb-thumb-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
	gap: 8px;
}

.cpfb-thumb {
	position: relative;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.14);
	border-radius: 6px;
	background: #2a2a30;
	aspect-ratio: 3 / 4;
	overflow: hidden;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cpfb-thumb:hover { border-color: rgba(255, 255, 255, 0.5); }

.cpfb-thumb canvas {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
}

.cpfb-thumb__n {
	position: absolute;
	right: 3px;
	bottom: 2px;
	padding: 0 5px;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.62);
	color: #fff;
	font-size: 10.5px;
	font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
	.cpfb-panel { top: 8px; left: 8px; right: 8px; width: auto; }
	.cpfb-thumb-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}

.cpfb-toc-item {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	align-items: baseline;
}

.cpfb-toc-page {
	flex: none;
	opacity: 0.55;
	font-size: 11.5px;
	font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------
   Trạng thái khi mở (đặt riêng từng tài liệu trong meta box)
   ------------------------------------------------------------------ */

/* wide: kéo khung ra hết chiều ngang màn hình dù đang nằm trong cột hẹp.
   Mẹo 50vw hai bên — không cần JS, không phụ thuộc bố cục của theme. */
.cpfb-reader.cpfb-wide {
	width: 100vw;
	max-width: 100vw;
	margin-left: calc(50% - 50vw);
	margin-right: calc(50% - 50vw);
	border-radius: 0;
}

/* ------------------------------------------------------------------
   TOÀN MÀN HÌNH
   Lớp phủ CSS, không phụ thuộc requestFullscreen() của trình duyệt.
   Vì sao cần: Safari trên iPhone không cho phần tử thường bung toàn màn
   hình, và mọi trình duyệt đều chặn tự bung khi người dùng chưa thao tác.
   Lớp phủ thì ở đâu cũng chạy — và nó che kín header/footer của theme,
   đúng thứ người xem cần khi đang đọc tài liệu.

   z-index để rất cao vì header dán trên cùng của các theme hay đặt
   z-index 9999–99999; thanh admin của WordPress là 99999.
   ------------------------------------------------------------------ */
.cpfb-reader.cpfb-fs {
	position: fixed;
	inset: 0;
	width: 100%;
	max-width: none;
	height: 100%;
	margin: 0;
	border-radius: 0;
	padding: 14px 14px 72px;
	z-index: 2147483000;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.cpfb-reader.cpfb-fs .cpfb-viewport {
	flex: 1 1 auto;
	min-height: 0;
}

/* Khoá cuộn nền: không thì cuộn trên trình đọc lại lôi cả trang phía sau đi */
html.cpfb-fs-lock,
html.cpfb-fs-lock body {
	overflow: hidden !important;
}

/* Cửa sổ nổi mở từ link PDF trong bài viết.
   Nền phải là màu ĐẶC, không được dùng rgba() dù alpha cao tới 0.97: lớp phủ
   này là position:fixed phủ toàn màn hình nên trình duyệt tách nó ra một lớp
   compositor riêng, và ở đó nền có alpha bị trộn sai — nội dung trang phía sau
   lộ qua rõ mồn một chứ không mờ 3% như con số ngụ ý. Đã đo trên Chrome. */
.cpfb-reader.cpfb-modal {
	background: #0a0a0c;
}

.cpfb-close {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 38px;
	height: 38px;
	display: grid;
	place-items: center;
	border: 1px solid rgba(255, 255, 255, 0.16);
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	cursor: pointer;
	backdrop-filter: blur(8px);
	z-index: 8;
	transition: background 0.15s;
}

.cpfb-close:hover {
	background: rgba(255, 255, 255, 0.22);
}

/* Nút bị quản trị tắt: ẩn đi nhưng vẫn tồn tại trong DOM, để lúc vào
   toàn màn hình còn hiện lại làm lối thoát. */
.cpfb-btn--off {
	display: none !important;
}

.cpfb-reader .cpfb-btn:disabled {
	opacity: 0.32;
	cursor: default;
}

.cpfb-reader .cpfb-btn:disabled:hover {
	background: transparent;
}

/* Nút đang bật (tự lật đang chạy) */
.cpfb-reader .cpfb-btn--on {
	background: rgba(255, 255, 255, 0.24);
}

/* ------------------------------------------------------------------
   KIỂU XEM 2: TRƯỢT NGANG
   ------------------------------------------------------------------ */
.cpfb-slide {
	position: relative;
	overflow: hidden;
	/* pan-y: vuốt dọc vẫn cuộn trang như thường, chỉ vuốt ngang mới lật.
	   Thiếu dòng này thì trên điện thoại trang bị khoá cuộn. */
	touch-action: pan-y;
}

.cpfb-slide__track {
	display: flex;
	height: 100%;
	will-change: transform;
}

.cpfb-slide__view {
	flex: 0 0 100%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cpfb-slide .cpfb-page {
	flex: 0 0 auto;
	box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

/* ------------------------------------------------------------------
   BẢNG NHỎ: chia sẻ
   ------------------------------------------------------------------ */
.cpfb-panel--sm {
	top: auto;
	bottom: 62px;
	left: 50%;
	transform: translateX(-50%);
	width: min(280px, calc(100% - 24px));
	max-height: min(420px, calc(100% - 90px));
	animation: cpfbPanelUp 0.16s ease;
}

@keyframes cpfbPanelUp {
	from { opacity: 0; transform: translate(-50%, 8px); }
	to   { opacity: 1; transform: translate(-50%, 0); }
}

/* --- chia sẻ --- */
.cpfb-share {
	display: flex;
	flex-direction: column;
	gap: 7px;
}

.cpfb-share__copy {
	padding: 9px 12px;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.16);
	color: #fff;
	font-size: 13.5px;
	font-weight: 600;
	cursor: pointer;
}

.cpfb-share__copy:hover { background: rgba(255, 255, 255, 0.26); }

.cpfb-share__url {
	padding: 0 4px 4px;
	color: #8f8f9c;
	font-size: 11.5px;
	line-height: 1.4;
	word-break: break-all;
}

.cpfb-reader a.cpfb-share__net,
.cpfb-reader a.cpfb-share__net:link,
.cpfb-reader a.cpfb-share__net:visited {
	display: block;
	padding: 8px 10px;
	border-radius: 8px;
	background: transparent;
	color: #d8d8e0 !important;
	font-size: 13.5px;
	text-decoration: none;
}

.cpfb-reader a.cpfb-share__net:hover {
	background: rgba(255, 255, 255, 0.1);
	color: #fff !important;
}

/* ------------------------------------------------------------------
   ĐIỆN THOẠI: thanh nút nhiều nút -> cho cuộn ngang thay vì tràn ra ngoài
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
	.cpfb-bar {
		left: 8px;
		right: 8px;
		transform: none;
		justify-content: flex-start;
		overflow-x: auto;
		scrollbar-width: none;
		border-radius: 22px;
	}

	.cpfb-bar::-webkit-scrollbar { display: none; }

	.cpfb-reader .cpfb-btn { flex: none; }

	.cpfb-panel--sm {
		left: 8px;
		right: 8px;
		width: auto;
		transform: none;
		animation: none;
	}
}
