/* Giao diện: nền xám xanh nhạt, khối trắng viền mảnh, nút chính màu đen, điểm nhấn xanh dương, chip bo tròn.
   Font hệ thống (San Francisco / Segoe UI / Roboto) — có sẵn tiếng Việt, không phải tải font. */
:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --subtle: #f9fafb;
  --ink: #111827;
  --text: #1f2937;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --brand: #175cd3;          /* xanh dương: logo, link, trạng thái chọn — 5.6:1 trên mọi nền */
  --accent: #175cd3;
  --accent-hover: #1849a9;
  --accent-soft: #eff8ff;
  --accent-border: #b2ddff;
  --btn: #111827;            /* nút chính màu đen */
  --btn-hover: #1f2937;
  --success: #15803d;        /* xanh lá chỉ dành cho trạng thái "thành công" */
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --purple-soft: #f4f0fd; --purple-border: #d9ccf7; --purple: #6941c6;
  --red-soft: #fef3f2; --red-border: #fecdca; --red: #b42318;
  --accent-ink: #fff;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / .12);
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --serif: var(--sans);
  --focus: 0 0 0 3px #d1e9ff;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--sans); font-weight: 700; color: var(--ink); line-height: 1.25; letter-spacing: -.01em; margin: 0 0 .5em; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
/* Nền "bụi sao": quỹ đạo mảnh + bụi sao nhạt trên nền trắng ngả xanh (dùng chung header & footer) */
.site-header, .site-footer { background: url(/img/orbits.svg) no-repeat 26% center, url(/img/stars-light.svg), linear-gradient(90deg, #fff, #f3f7ff 55%, #eef1ff); }
.site-header { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--accent); font-weight: 800; font-size: 1.05rem; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; }
.logo em { font-style: normal; color: inherit; }
.logo svg { color: var(--brand); }
.logo svg ellipse { stroke: var(--ink); }
.search { flex: 1; max-width: 420px; margin-left: auto; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: rgb(255 255 255 / .85); color: var(--text); font: inherit; font-size: .9rem; }
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 0; border-color: var(--accent); box-shadow: var(--focus); }
.nav a { display: inline-flex; align-items: center; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: rgb(255 255 255 / .85); text-decoration: none; font-weight: 500; font-size: .9rem; white-space: nowrap; color: var(--ink); }
.nav a:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }

.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; font-weight: 600; color: var(--accent); margin: 0 0 8px; }

/* Sections */
.section { padding: 24px 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 1.35rem; margin: 0; text-transform: uppercase; }
.section-head a { color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.section-head a:hover { text-decoration: underline; }
.section-head .section-link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); font-weight: 600; font-size: .9rem; white-space: nowrap; cursor: pointer; }
.section-head .section-link:hover { text-decoration: underline; }

/* Tags (chip kiểu "payOS") */
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); text-decoration: none; font-size: .88rem; font-weight: 500; color: var(--ink); transition: border-color .15s, background .15s, color .15s; }
.tag span { color: var(--muted); font-size: .8rem; }
.tag:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }

/* Lưới sách nằm trong khối trắng viền mảnh */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 28px 20px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card { display: flex; flex-direction: column; min-width: 0; }
.card-link { display: block; text-decoration: none; color: inherit; }
.card-link .card-title { margin-top: 10px; }
.cover { aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; overflow: hidden; box-shadow: 0 1px 3px rgb(16 24 40 / .12), 0 4px 12px rgb(16 24 40 / .08); transition: transform .2s ease, box-shadow .2s ease; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
/* Rê chuột: sách nhấc lên và nghiêng nhẹ */
.card-link:hover .cover { transform: translateY(-5px) rotate(-1.5deg); box-shadow: 0 4px 8px rgb(16 24 40 / .12), 0 16px 30px rgb(16 24 40 / .18); }
@media (prefers-reduced-motion: reduce) { .card-link:hover .cover { transform: none; } }
.card-body { padding-top: 10px; }
/* Tên sách tối đa 2 dòng, dài hơn thì "…" */
.card-title { font-size: .95rem; font-weight: 600; color: var(--ink); line-height: 1.35; margin: 0 0 2px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
.card-link:hover .card-title { color: var(--accent); }
.card-author { margin: 0; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-author a, .book-author a { color: inherit; text-decoration: none; }
.card-author a:hover, .book-author a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Nút */
.btn { display: inline-block; padding: 10px 18px; border-radius: var(--radius); background: var(--btn); color: #fff; text-decoration: none; font: inherit; font-weight: 600; border: 1px solid var(--btn); cursor: pointer; box-shadow: var(--shadow); transition: background .15s; }
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.empty { text-align: center; padding: 96px 16px; }

/* Chip trạng thái (kiểu "Chủ sở hữu" / "Chưa xác thực") */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: .78rem; font-weight: 500; white-space: nowrap; }
.pill-purple { background: var(--purple-soft); border-color: var(--purple-border); color: var(--purple); }
.pill-red { background: var(--red-soft); border-color: var(--red-border); color: var(--red); }
.pill-green { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }

/* Trang danh sách */
.sort label { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); white-space: nowrap; }
.sort select { padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 24px; }
.pagination a, .pagination span { min-width: 38px; padding: 7px 12px; border-radius: var(--radius); text-align: center; text-decoration: none; font-weight: 500; font-size: .9rem; }
.pagination a { border: 1px solid var(--line-strong); background: var(--surface); }
.pagination a:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
.pagination .current { background: var(--accent); color: #fff; }
.pagination .gap { color: var(--muted); }

/* Trang sản phẩm */
.book { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 40px; padding-top: 32px; padding-bottom: 24px; align-items: start; }
.book-cover { position: sticky; top: 84px; }
.book-cover img { width: 100%; height: auto; border-radius: 6px; box-shadow: 0 1px 3px rgb(16 24 40 / .12), 0 16px 36px rgb(16 24 40 / .16); }
.book-info h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); margin-bottom: 4px; }
.book-author { margin: 0 0 14px; font-size: 1rem; color: var(--muted); }
.buy-box { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 16px; margin: 24px 0 12px; padding: 16px 20px; background: url(/img/orbits.svg) no-repeat right -150px center, url(/img/stars-light.svg), linear-gradient(90deg, #fff, #f3f7ff 55%, #eef1ff); border: 1px solid #dfe5f5; border-radius: var(--radius); box-shadow: var(--shadow); }
.buy-meta { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.buy-price { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.buy-formats { margin: 0; font-size: .85rem; color: var(--muted); }
.buy-btn { justify-self: stretch; min-height: 44px; text-align: center; }
.btn-lg { width: 100%; padding: 12px 20px; font-size: 1rem; }
.btn-sm { padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.book-desc { padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.book-desc h2 { font-size: 1rem; text-transform: uppercase; margin-bottom: 10px; }
.book-desc p { margin: 0 0 1em; max-width: 68ch; }
.book-desc p:last-child { margin-bottom: 0; }

/* Footer */
.site-footer { margin-top: 56px; background-position: 72% center, 0 0, 0 0; border-top: 1px solid var(--line); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 22px 16px; font-size: .88rem; }
.footer-inner p { margin: 0; }

@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .nav { margin-left: auto; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 22px 14px; padding: 14px; }
  /* Trang sản phẩm: bìa nhỏ bên trái, tên/tác giả/tag bên phải; thẻ mua, chia sẻ, giới thiệu trải hết chiều ngang */
  .book { grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; column-gap: 16px; row-gap: 0; padding-top: 20px; }
  .book-info { display: contents; }
  .book-cover { position: static; grid-column: 1; grid-row: 1 / 5; }
  .book-cover img { border-radius: 4px; box-shadow: 0 1px 3px rgb(16 24 40 / .15), 0 8px 18px rgb(16 24 40 / .16); }
  .book-info > h1 { grid-column: 2; grid-row: 1; font-size: 1.35rem; line-height: 1.25; }
  .book-author { grid-column: 2; grid-row: 2; margin-bottom: 10px; font-size: .92rem; }
  .book-info > .tags { grid-column: 2; grid-row: 3; gap: 6px; }
  .book-info > .tags .tag { padding: 3px 10px; font-size: .8rem; }
  .book-info > :is(.buy-box, .share, .book-desc) { grid-column: 1 / -1; }
  .buy-box { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin: 20px 0 12px; padding: 12px 12px 12px 16px; background: url(/img/stars-light.svg), linear-gradient(90deg, #fff, #f3f7ff 55%, #eef1ff); }
  .buy-price { font-size: 1.1rem; }
  .buy-formats { font-size: .8rem; }
  .buy-btn { min-height: 48px; padding: 10px 12px; }
}

/* ---------- Admin ---------- */
.admin { font-size: 15px; }
.admin-bar { background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--line); }
.admin-bar-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.admin-bar .logo { font-size: 1rem; }
.admin-bar .logo small { font-family: var(--sans); font-weight: 500; font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; opacity: .6; margin-left: 4px; }
.admin-bar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.admin-bar nav a { color: var(--text); text-decoration: none; padding: 6px 12px; border-radius: var(--radius); font-weight: 500; }
.admin-bar nav a:hover { background: var(--subtle); }
.admin-bar nav a.active { background: var(--accent-soft); color: var(--accent); }
.admin-bar .link-btn { color: var(--muted); }
.admin-main { padding-top: 28px; padding-bottom: 64px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.admin-head h1, .admin-head h2 { margin: 0; }
.admin-head h1 { font-size: 1.8rem; }
.admin-head a:not(.btn) { color: var(--accent); text-decoration: none; font-weight: 500; }
.crumbs-admin { margin: 0; font-size: .9rem; }
.crumbs-admin a { color: var(--muted); text-decoration: none; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn.danger, .danger { color: var(--red); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; }
.nowrap { white-space: nowrap; }

.notice { padding: 12px 16px; border-radius: 10px; background: #e6f4ea; color: #1e6b3a; border: 1px solid #c3e5cd; margin: 0 0 16px; }
.notice-warn { background: #fdecea; color: #a1281c; border-color: #f5c6c0; }
ul.notice { padding-left: 32px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 36px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat p { margin: 0 0 6px; color: var(--muted); font-size: .88rem; }
.stat strong { font-size: 1.5rem; color: var(--ink); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table a { text-decoration: none; }
.table a:hover { color: var(--accent); }
.row-muted td { opacity: .55; }
.row-muted td:has(.vis-toggle), .row-muted td:has(.price-edit), .row-muted td.col-chon { opacity: 1; }

/* Danh sách sách: tìm kiếm, sắp xếp, sửa giá nhanh, ẩn/hiện */
/* Trang danh sách sách trong admin: khung rộng theo màn hình để đủ chỗ cho nhiều cột */
.admin-main:has(.books-table) { max-width: 1480px; }

/* Bảng sách: chữ nhỏ một nấc, mọi ô 1 dòng, căn giữa (trừ tên sách), cột ẩn/hiện được */
.books-table { font-size: .86rem; }
.books-table th, .books-table td { padding: 7px 8px; text-align: center; white-space: nowrap; }
.books-table th { font-size: .7rem; }
.books-table .num { text-align: center; }
.books-table th.col-ten, .books-table td.col-ten { text-align: left; }
.books-table td.col-ten { max-width: 230px; }
.books-table .one { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.books-table .one.sub { color: var(--muted); font-size: .78rem; }
.books-table .thumb { width: 30px; height: 45px; max-width: none; display: block; margin: 0 auto; }
.books-table .col-chon, .books-table .col-anh { width: 1%; }
.books-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.books-table .col-hidden { display: none; }
.books-table tr.row-sel td { background: color-mix(in srgb, var(--accent-soft) 75%, transparent); }
.books-table .badge, .books-table .chip, .books-table .vis-toggle { font-size: .74rem; }
.books-table .sort-link { justify-content: center; }
.books-table th.col-ten .sort-link { justify-content: flex-start; }
.alias-copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; color: var(--ink); background: var(--subtle); border: 1px solid transparent; padding: 2px 7px; border-radius: 5px; cursor: copy; }
.alias-copy:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
.set-alias { font-size: .76rem; }

/* Thanh lọc trên bảng sách */
.book-filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin: 0 0 12px; }
.book-filters input[type=search], .book-filters select, .per-page select { font: inherit; font-size: .9rem; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.book-filters input[type=search] { width: 240px; max-width: 100%; }
.book-filters .btn { box-shadow: none; margin: 0; }
.filter-select { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.tag-filter { position: relative; }
.tag-box { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 200px; min-height: 37px; padding: 3px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-size: .88rem; }
.tag-box:focus-visible { outline: 0; border-color: var(--accent); box-shadow: var(--focus); }
.tag-ph { color: var(--muted); }
.tag-chip { display: inline-flex; gap: 2px; align-items: center; padding: 2px 4px 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 600; }
.tag-chip button { border: 0; background: none; color: inherit; font: inherit; font-weight: 700; cursor: pointer; padding: 0 4px; }
.tag-menu { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; width: 280px; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; }
.tag-menu input[type=text] { width: 100%; font: inherit; font-size: .88rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 4px; }
.tag-menu label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: .88rem; cursor: pointer; }
.tag-menu label:hover { background: var(--subtle); }
.tag-menu label[hidden] { display: none; }
.tag-menu label span { margin-left: auto; color: var(--muted); font-size: .76rem; }
.col-picker { position: relative; margin-left: auto; }
.col-menu { position: absolute; z-index: 40; right: 0; top: calc(100% + 4px); width: 260px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 10px; }
.col-menu p { margin: 0 0 8px; }
.col-menu ul { list-style: none; margin: 0 0 8px; padding: 0; }
.col-menu li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; font-size: .88rem; background: var(--surface); }
.col-menu li:hover { background: var(--subtle); }
.col-menu li.dragging { opacity: .4; }
.col-menu .drag { cursor: grab; color: var(--muted); }
.col-menu label { display: flex; align-items: center; gap: 6px; flex: 1; cursor: pointer; }
.col-move { display: inline-flex; gap: 2px; }
.col-move button { border: 1px solid var(--line); background: var(--surface); border-radius: 4px; font: inherit; font-size: .72rem; line-height: 1; padding: 3px 5px; cursor: pointer; color: var(--muted); }
.col-move button:hover { color: var(--ink); border-color: var(--line-strong); }

/* Thanh chọn nhiều sách */
.bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 8px 12px; margin-bottom: 10px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent-border); font-size: .9rem; }
.bulk[hidden] { display: none; }
.bulk strong { color: var(--accent); }
.bulk select { font: inherit; font-size: .88rem; padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.bulk .btn { box-shadow: none; }
.select-all-hint { margin: -4px 0 10px; font-size: .86rem; }

/* Chia trang */
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; font-size: .88rem; }
.pager nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pager nav a, .pager nav span { min-width: 32px; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line); text-align: center; text-decoration: none; color: var(--text); background: var(--surface); }
.pager nav a:hover { border-color: var(--line-strong); }
.pager nav .on { background: var(--btn); color: #fff; border-color: var(--btn); }
.pager nav .off { color: var(--line-strong); }
.pager nav .gap { border-color: transparent; background: none; }
.per-page { margin: 0; }
.per-page select { padding: 4px 6px; font-size: .86rem; }

/* Tooltip tên sách, thông báo nhỏ */
.name-tip { position: fixed; z-index: 60; max-width: 380px; padding: 8px 10px; border-radius: 8px; background: #1f2937; color: #fff; font-size: .82rem; line-height: 1.4; pointer-events: none; box-shadow: var(--shadow-lg); }
.name-tip small { display: block; opacity: .75; }
.toast { position: fixed; z-index: 70; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 9px 16px; border-radius: 999px; background: #1f2937; color: #fff; font-size: .88rem; box-shadow: var(--shadow-lg); }

/* Trang sửa sách: khung link ngắn */
.link-list { list-style: none; margin: 0 0 8px; padding: 0; }
.link-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.link-list li .muted { margin-right: auto; }
.link-list li.is-main .alias-copy { border-color: #c3e5cd; background: #e6f4ea; }
.link-add { display: flex; gap: 8px; align-items: stretch; margin-top: 8px; }
.link-add .prefix-input { flex: 1; }
.link-add .btn { box-shadow: none; }
.prefix-input { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.prefix-input:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.prefix-input > span { padding: 6px 4px 6px 8px; background: var(--subtle); color: var(--muted); font-size: .84rem; display: flex; align-items: center; }
.prefix-input input { border: 0; outline: 0; padding: 6px 8px; font: inherit; font-size: .9rem; min-width: 0; flex: 1; background: transparent; color: var(--text); }
.orders-table th.num .sort-link { justify-content: flex-end; }
.sort-link { color: inherit; display: inline-flex; gap: 4px; align-items: center; }
.sort-link:hover, .sort-link.on { color: var(--ink); }
.sort-arrow { font-size: .9rem; min-width: .6em; }
.price-edit { background: none; border: 1px dashed transparent; border-radius: 6px; padding: 4px 6px; margin: -4px -6px; font: inherit; color: inherit; text-align: right; cursor: pointer; line-height: 1.4; }
.price-edit:hover, .price-edit[aria-expanded="true"] { border-color: var(--accent-border); background: var(--accent-soft); }
.price-pen { color: var(--muted); font-size: .8rem; opacity: 0; transition: opacity .15s; }
.price-edit:hover .price-pen, .price-edit:focus-visible .price-pen { opacity: 1; }
.price-missing { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #fff4d6; color: #8a6100; font-size: .82rem; font-weight: 600; }
.flash-ok { animation: flash-ok 1.6s ease-out; }
@keyframes flash-ok { from { background: #e6f4ea; } to { background: transparent; } }
.price-pop { position: absolute; z-index: 50; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg, 0 12px 32px rgb(0 0 0 / .18)); padding: 14px 16px 12px; }
.price-pop .field { margin-bottom: 10px; }
.price-pop .field-row-3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.price-pop .field-row-3 .field input { padding: 8px; font-size: .92rem; }
.price-pop .field-hint { margin: -2px 0 10px; }
.price-pop-title { margin: 0 0 10px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price-pop .notice { margin: 0 0 10px; padding: 8px 12px 8px 28px; }
.price-pop-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; }
.price-pop-actions .btn { box-shadow: none; }
.vis-toggle { font: inherit; font-size: .8rem; font-weight: 500; padding: 3px 10px 3px 8px; border-radius: 999px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.vis-toggle::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.vis-on { background: #e6f4ea; color: #1e6b3a; }
.vis-on:hover { border-color: #1e6b3a; }
.vis-off { background: #eeeaf0; color: #6f6a78; }
.vis-off::before { background: transparent; border: 1.5px solid currentColor; }
.vis-off:hover:not(:disabled) { border-color: #6f6a78; }
.vis-toggle:disabled { cursor: not-allowed; opacity: .6; }

.thumb { width: 40px; height: 60px; object-fit: cover; border-radius: 2px 4px 4px 2px; box-shadow: 0 1px 3px rgb(0 0 0 / .2); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 500; white-space: nowrap; }
.badge-pending { background: #fff4d6; color: #8a6100; }
.badge-paid { background: #e0ecff; color: #1d4ed8; }
.badge-sent { background: #e6f4ea; color: #1e6b3a; }
.badge-expired, .badge-cancelled { background: #eeeaf0; color: #6f6a78; }
.chip { display: inline-block; padding: 1px 9px; margin-right: 4px; border-radius: 999px; background: var(--purple-soft); border: 1px solid var(--purple-border); color: var(--purple); font-size: .75rem; font-weight: 600; letter-spacing: .03em; }

.login-box { max-width: 380px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.login-box h1 { text-align: center; font-size: 1.6rem; margin-bottom: 24px; }
.login-box h1 em { color: var(--accent); }

.book-form { display: grid; grid-template-columns: 1fr 320px; gap: 32px; align-items: start; }
.form-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-weight: 500; font-size: .92rem; }
.field input, .field textarea { font: inherit; font-weight: 400; font-size: 1rem; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); width: 100%; }
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus { outline: 0; border-color: var(--accent); box-shadow: var(--focus); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3 { font-size: 1rem; margin-bottom: 12px; }
.panel input[type=file] { font-size: .85rem; width: 100%; }
.panel p { margin: 8px 0 0; }
.cover-preview { width: 120px; margin-bottom: 12px; border-radius: 2px 6px 6px 2px; box-shadow: var(--shadow); }
.file-list { list-style: none; margin: 0 0 12px; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.file-list li .link-btn { margin-left: auto; font-size: .85rem; }
.danger-zone { display: flex; justify-content: space-between; padding: 0 4px; font-size: .9rem; }

@media (max-width: 800px) {
    .book-form { grid-template-columns: 1fr; }
  .form-side { position: static; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .admin-bar-inner { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
}

/* ---------- Mua sách ---------- */
.accent { color: var(--accent); }
.field-error, .form-error { color: var(--red); font-weight: 400; font-size: .85rem; min-height: 0; }
.form-error:empty, .field-error:empty { display: none; }
.field input[aria-invalid] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.pay-info { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; text-align: left; padding: 12px 16px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius); }
.pay-info > div { display: contents; }
.pay-info dt { color: var(--muted); font-size: .9rem; }
.pay-info dd { margin: 0; font-weight: 600; text-align: right; }
.pay-wait { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; margin: 0 0 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); margin: 8px 0; }
.btn-ghost:hover { background: var(--subtle); border-color: var(--line-strong); }
.btn-mock { display: block; width: 100%; margin: 12px 0; background: var(--surface); color: var(--accent); border: 1px dashed var(--accent-border); box-shadow: none; }
.btn-mock:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Trang tải sách ---------- */
.download { display: flex; gap: 40px; align-items: flex-start; padding-top: 48px; padding-bottom: 24px; }
.download-cover { width: 160px; flex: none; border-radius: 3px 8px 8px 3px; box-shadow: var(--shadow); }
.download h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin-bottom: 2px; }
.download-list { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 10px; max-width: 480px; }
.download-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; transition: border-color .15s, background .15s; }
.download-item:hover { border-color: var(--accent-border); background: var(--accent-soft); }
.download-arrow { margin-left: auto; font-size: 1.3rem; color: var(--accent); }
@media (max-width: 640px) {
  .download { flex-direction: column; align-items: center; text-align: center; gap: 20px; }
  .download-item { text-align: left; }
}
.system-status { margin: -16px 0 32px; font-size: .9rem; }
.system-status p { margin: 4px 0; }
.system-status code { font-size: .85rem; background: var(--bg); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.settings-layout { display: grid; grid-template-columns: 1fr 300px; gap: 32px; align-items: start; }
.settings-form { display: flex; flex-direction: column; gap: 20px; }
.settings-group { padding: 20px; }
.settings-group h2 { font-size: 1.15rem; margin-bottom: 4px; }
.settings-group > p { margin: 0 0 16px; }
.settings-group code, .form-side code { font-size: .82rem; background: var(--bg); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.settings-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.settings-fields .field:only-child, .settings-payos .field:first-child { grid-column: 1 / -1; }
.field .check { font-weight: 400; margin-top: 2px; }
.field .check input { width: 15px; height: 15px; }
.form-side .panel form { margin: 0 0 10px; }
.form-side .panel p { margin: 6px 0 10px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: .9rem; background: var(--surface); color: var(--text); }
@media (max-width: 800px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-fields { grid-template-columns: 1fr; }
}

/* Nút Messenger nổi */
.messenger-btn { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 16px 10px 12px; border-radius: 999px; background: #0866ff; color: #fff; text-decoration: none; font-weight: 600; font-size: .92rem; box-shadow: var(--shadow-lg); transition: transform .15s; }
.messenger-btn:hover { transform: translateY(-2px); }
@media (max-width: 640px) { .messenger-btn span { display: none; } .messenger-btn { padding: 12px; } }

/* Footer + nav */
.nav { display: flex; gap: 16px; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.footer-nav a { display: inline-flex; align-items: center; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: rgb(255 255 255 / .85); text-decoration: none; font-weight: 500; white-space: nowrap; color: var(--ink); }
.footer-nav a:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
.footer-inner > div p { margin: 0; }
.field-hint { margin: -8px 0 16px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.home-tags { padding-top: 40px; }
@media (max-width: 640px) { .home-tags { padding-top: 24px; } }

/* Tag trang chủ */
.tags-home { justify-content: center; }

/* ---------- Trang tất cả sách / trang tag ---------- */
.catalog { display: grid; grid-template-columns: 230px 1fr; gap: 40px; padding-top: 32px; align-items: start; }
.catalog > * { min-width: 0; }
.catalog-side { position: sticky; top: 84px; max-height: calc(100vh - 104px); overflow-y: auto; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.side-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 10px 8px; }
.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.tag-list a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; text-decoration: none; font-size: .9rem; color: var(--text); }
.tag-list a span { min-width: 24px; padding: 0 7px; border-radius: 999px; background: var(--subtle); border: 1px solid var(--line); color: var(--muted); font-size: .75rem; text-align: center; font-variant-numeric: tabular-nums; }
.tag-list a:hover { background: var(--subtle); color: var(--ink); }
.tag-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag-list a.active span { background: var(--surface); border-color: var(--accent-border); color: var(--accent); }
.catalog-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.catalog-head h1 { font-size: clamp(1.4rem, 3.5vw, 1.8rem); margin-bottom: 2px; text-transform: uppercase; }
.catalog-head p { margin: 0; }
.catalog-main .empty { padding: 48px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
@media (max-width: 800px) {
  .catalog { grid-template-columns: 1fr; gap: 16px; padding-top: 20px; }
  .catalog-side { position: static; max-height: none; overflow: visible; padding: 0; background: none; border: 0; }
  .side-title { display: none; }
  .tag-list { flex-direction: row; overflow-x: auto; margin: 0 -16px; padding: 0 16px 6px; scrollbar-width: none; }
  .tag-list li { flex: none; }
  .tag-list a { border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); padding: 5px 12px; }
  .tag-list a.active { border-color: var(--accent-border); }
}

/* ---------- Donate ---------- */
.donate { padding: 16px; margin: 0 0 16px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius); text-align: center; }
.donate-note { margin: 0 0 8px; font-size: .9rem; color: var(--text); }
.donate-amount { display: block; font-size: 2.1rem; font-weight: 700; color: var(--ink); line-height: 1.2; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.donate-range { --fill: 0%; -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; cursor: pointer; touch-action: pan-y; }
.donate-range::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: linear-gradient(to right, var(--accent) var(--fill), var(--line) var(--fill)); }
.donate-range::-moz-range-track { height: 8px; border-radius: 999px; background: var(--line); }
.donate-range::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--accent); }
.donate-range::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); box-shadow: 0 1px 4px rgb(16 24 40 / .2); }
.donate-range::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); box-shadow: 0 2px 8px rgb(0 0 0 / .2); }
.donate-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
.donate-scale { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.qr-caption { text-align: center; font-size: .88rem; color: var(--muted); margin: 0 0 14px; }
.qr-caption a { color: var(--accent); font-weight: 600; }
.countdown { margin: 0 0 12px; padding: 8px 12px; border-radius: var(--radius); background: #fffaeb; border: 1px solid #fedf89; color: #93370d; font-size: .9rem; text-align: center; }
.countdown strong { font-variant-numeric: tabular-nums; font-size: 1.05rem; color: #b54708; }
.countdown strong.urgent { color: var(--red); }
@media (max-width: 640px) {
  .donate-amount { font-size: 1.9rem; }
}
.field-row-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 800px) { .field-row-3 { grid-template-columns: 1fr; } }
.donate-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.chip-btn { min-width: 62px; padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; font-size: .9rem; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.chip-btn:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
.chip-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--accent); }
.email-hint { font-weight: 400; font-size: .85rem; color: var(--muted); }
.email-hint .link-btn { font-weight: 600; }
.pay-info dd { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.copy-btn { padding: 1px 9px; border: 1px solid var(--accent-border); border-radius: 999px; background: var(--surface); color: var(--accent); font: inherit; font-size: .75rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.copy-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Màu chip tag (mỗi tag một màu cố định, xem tagColor trong layout.js) ---------- */
.c0 { --tag-bg: #ecfdf3; --tag-border: #abefc6; --tag-ink: #067647; }  /* xanh lá */
.c1 { --tag-bg: #f4f0fd; --tag-border: #d9ccf7; --tag-ink: #6941c6; }  /* tím */
.c2 { --tag-bg: #eff8ff; --tag-border: #b2ddff; --tag-ink: #175cd3; }  /* xanh dương */
.c3 { --tag-bg: #fff6ed; --tag-border: #fddcab; --tag-ink: #b93815; }  /* cam */
.c4 { --tag-bg: #fdf2fa; --tag-border: #fcceee; --tag-ink: #c11574; }  /* hồng */
.c5 { --tag-bg: #f0fdf9; --tag-border: #99f6e0; --tag-ink: #107569; }  /* ngọc */
.c6 { --tag-bg: #fef3f2; --tag-border: #fecdca; --tag-ink: #b42318; }  /* đỏ */
.c7 { --tag-bg: #eef4ff; --tag-border: #c7d7fe; --tag-ink: #3538cd; }  /* chàm */
.c8 { --tag-bg: #fffaeb; --tag-border: #fedf89; --tag-ink: #b54708; }  /* vàng */

.tag[class*=" c"] { background: var(--tag-bg); border-color: var(--tag-border); color: var(--tag-ink); }
.tag[class*=" c"]:hover { background: var(--tag-bg); border-color: var(--tag-ink); color: var(--tag-ink); }

/* Cột tag trang danh sách: chấm màu trước tên; tag đang chọn tô màu của nó */
.tag-list a[class^="c"]::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--tag-ink); opacity: .75; margin-right: 2px; }
.tag-list a[class^="c"] { justify-content: flex-start; }
.tag-list a[class^="c"] span { margin-left: auto; }
.tag-list a[class^="c"].active { background: var(--tag-bg); color: var(--tag-ink); }
.tag-list a[class^="c"].active span { border-color: var(--tag-border); color: var(--tag-ink); }
@media (max-width: 800px) {
  .tag-list a[class^="c"] { background: var(--tag-bg); border-color: var(--tag-border); color: var(--tag-ink); }
  .tag-list a[class^="c"].active { border-color: var(--tag-ink); box-shadow: inset 0 0 0 1px var(--tag-ink); }
}
.donate-settings { margin: 0 0 16px; padding: 14px 16px 2px; border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.donate-settings legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }

/* ================= Cửa sổ thanh toán =================
   Các vùng: head · book · qr · panels · foot (anh em trong .pay-form, sắp xếp bằng grid-template-areas).
   Trạng thái: .pay[data-state = form | pay | done | expired]. Nội dung các trạng thái chồng trong cùng
   một ô lưới và chỉ ẩn/hiện bằng visibility → khung giữ nguyên kích thước. */
.pay { --qz: 240px; width: min(820px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow: auto; overscroll-behavior: contain; }
.pay::backdrop { background: rgb(16 24 40 / .45); }
.pay-form { display: grid; gap: 0 28px; padding: 0 24px 20px; }
.pay-head { grid-area: head; position: relative; margin: 0 -24px 18px; padding: 14px 56px; text-align: center; border-bottom: 1px solid var(--line); }
.pay-head h2 { font-size: 1.1rem; margin: 0; }
.pay-sub { margin: 2px 0 0; font-size: .88rem; color: var(--muted); }
.pay-x { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #f2f4f7; color: var(--ink); font-size: 1.7rem; line-height: 1; cursor: pointer; }
.pay-x:hover { background: #e4e7ec; }
.pay-steps { display: none; }

.pay-book { grid-area: book; display: flex; gap: 12px; align-items: center; padding: 10px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--subtle); min-width: 0; }
.pay-book img { flex: none; width: 48px; height: 72px; object-fit: cover; border-radius: 4px; box-shadow: 0 1px 3px rgb(16 24 40 / .15); }
.pay-book > div { min-width: 0; }
.pay-book-title { margin: 0; font-weight: 600; color: var(--ink); line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.pay-book-author { margin: 0; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pay-book-price { margin: 2px 0 0; font-weight: 700; color: var(--ink); }

/* Vùng QR: kích thước cố định, 5 trạng thái chồng lên nhau */
.pay-qr { grid-area: qr; display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; }
.qz { display: grid; width: var(--qz); max-width: 100%; aspect-ratio: 1; transition: width .2s ease; }
.qz-item { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; visibility: hidden; opacity: 0; transition: opacity .2s ease, visibility .2s; overflow: hidden; }
.qz-item svg, .qz-real img { display: block; width: 100%; height: auto; }
.qz-real { padding: 10px; border-radius: 16px; }
.qz-real img { image-rendering: pixelated; -webkit-touch-callout: default; user-select: auto; }
.qz-tip { align-items: center; gap: 8px; margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius); background: #f2f4f7; font-size: .82rem; color: var(--text); text-align: left; }
.qz-item strong { color: var(--ink); font-size: .95rem; }
.qz-item small { color: var(--text); font-size: .82rem; max-width: 88%; }
.qz-icon { font-size: 2.4rem; line-height: 1; }
.qz-free { background: var(--accent-soft); border-color: var(--accent-border); }
.qz-blur { position: relative; border-style: dashed; border-color: var(--line-strong); }
.qz-blur-img { position: absolute; inset: 14px; filter: blur(6px); opacity: .45; }
.qz-hint { position: relative; font-size: 1.3rem !important; font-weight: 800; line-height: 1.25; text-transform: uppercase; text-shadow: 0 0 12px #fff, 0 0 4px #fff; }
.qz-hint b { color: var(--accent); }
.qz-done { background: var(--success-soft); border-color: var(--success-border); }
.qz-ok { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--success); color: #fff; font-size: 2rem; }
.qz-expired { background: var(--subtle); }
.qz-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; visibility: hidden; }
.qz-actions .btn { margin: 0; }
.qr-caption { margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
.qr-caption a { color: var(--accent); font-weight: 600; }

.pay[data-state="form"][data-free="1"][data-zero="1"] .qz-free,
.pay[data-state="form"]:not([data-free="1"][data-zero="1"]) .qz-blur,
.pay[data-state="pay"] .qz-real,
.pay[data-state="done"] .qz-done,
.pay[data-state="expired"] .qz-expired { visibility: visible; opacity: 1; }
.pay[data-state="pay"] .qz-actions { visibility: visible; }

/* Nội dung theo trạng thái */
.pay-panels { grid-area: panels; display: grid; min-width: 0; }
.pp { grid-area: 1 / 1; min-width: 0; visibility: hidden; opacity: 0; transition: opacity .2s ease, visibility .2s; }
.pay[data-state="form"] .pp-form, .pay[data-state="pay"] .pp-pay,
.pay[data-state="done"] .pp-done, .pay[data-state="expired"] .pp-expired { visibility: visible; opacity: 1; }
.pp-label { margin: 0 0 10px; font-weight: 600; color: var(--ink); }
.pp .field { margin-bottom: 12px; }
.pp .donate { margin-bottom: 16px; }
.pp h3 { font-size: 1.15rem; margin: 4px 0 8px; }
.pp p { margin: 0 0 8px; }

/* Chân: Huỷ + nút chính theo trạng thái */
.pay-foot { grid-area: foot; display: flex; gap: 10px; padding-top: 8px; }
.pay-foot .btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; min-height: 48px; margin: 0; padding: 0 16px; text-align: center; }
.pay-foot [data-cancel] { background: #eaecf0; border-color: #eaecf0; color: #344054; box-shadow: none; }
.pay-foot [data-cancel]:hover { background: #dfe3e8; border-color: #dfe3e8; }
.pay-foot [data-submit], .pay-foot [data-download], .pay-foot [data-restart] { display: none; }
.pay[data-state="form"] [data-submit], .pay[data-state="done"]:not(.no-download) [data-download],
.pay[data-state="expired"] [data-restart] { display: inline-flex; }

/* Bố cục (máy tính): QR trái, thông tin phải */
.pay { --qz: 250px; }
.pay-form { grid-template-columns: var(--qz) minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; grid-template-areas: "head head" "qr book" "qr panels" "qr foot"; }
.qz-tip { display: none; }

/* Điện thoại: toàn màn hình. Bước điền thông tin: sách → form → nút → QR mờ. Bước thanh toán: QR to lên đầu. */
@media (max-width: 640px) {
  .pay { --qz: min(260px, calc(100vw - 120px)); width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .pay-form { padding: 0 16px 24px; grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "head" "book" "panels" "foot" "qr"; }
  .pay-head { position: sticky; top: 0; z-index: 3; margin: 0 -16px 14px; padding: 12px 56px; background: var(--surface); }
  .pay-sub { font-size: .82rem; }
  .pay-foot { padding: 4px 0 20px; }
  .pay-qr { padding-top: 4px; }
  .pay[data-state="form"] .qz-actions { display: none; }
  .pay .qz-hint { font-size: 1.1rem !important; }
  .pay:not([data-state="form"]) .pay-book { display: none; }
  .pay:not([data-state="form"]) .pay-form { grid-template-areas: "head" "qr" "panels" "foot"; }
  .pay:not([data-state="form"]) .pay-qr { margin-bottom: 16px; }
  .pay[data-state="pay"] .qz-tip { display: flex; }
}
.logo-icon { font-size: 1.5rem; line-height: 1; text-transform: none; }

/* Chia sẻ */
.share { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 20px; font-size: .85rem; color: var(--muted); }
.share-btn { padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: .82rem; font-weight: 500; text-decoration: none; cursor: pointer; }
.share-btn:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }

/* Giới thiệu dài: thu gọn */
.book-desc.is-collapsed .book-desc-body { max-height: 13.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.book-desc-more { margin-top: 6px; font-weight: 600; text-decoration: none; }

/* Thanh mua nổi (chỉ điện thoại) */
.buy-bar { display: none; }
@media (max-width: 640px) {
  .buy-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; align-items: center; gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(16 24 40 / .08); transform: translateY(110%); transition: transform .2s ease; }
  .buy-bar.show { transform: none; }
  .buy-bar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .buy-bar-text strong { font-size: .9rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .buy-bar-text span { font-size: .85rem; color: var(--muted); }
  .buy-bar .btn { flex: none; min-height: 44px; }
  body.has-buy-bar .messenger-btn { bottom: 84px; }
}

/* Donate gọn, khiêm nhường (sách miễn phí) */
.donate-sm { padding: 10px 12px; text-align: left; background: var(--subtle); }
.donate-sm .donate-note { margin: 0 0 6px; font-size: .82rem; color: var(--muted); }
.donate-row { display: flex; align-items: center; gap: 12px; }
.donate-row .donate-range { flex: 1; height: 28px; }
.donate-sm .donate-amount { flex: none; min-width: 72px; margin: 0; font-size: 1rem; font-weight: 700; text-align: right; }
.donate-sm .donate-range::-webkit-slider-runnable-track { height: 4px; }
.donate-sm .donate-range::-moz-range-track, .donate-sm .donate-range::-moz-range-progress { height: 4px; }
.donate-sm .donate-range::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8px; border-width: 2px; }
.donate-sm .donate-range::-moz-range-thumb { width: 16px; height: 16px; border-width: 2px; }
.donate-sm .donate-chips { justify-content: flex-start; gap: 6px; margin-top: 6px; }
.donate-sm .chip-btn { min-width: 0; padding: 3px 10px; font-size: .8rem; }

/* Trang gửi lại sách */
.resend { padding-top: 48px; }
.resend-card { max-width: 480px; margin: 0 auto; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.resend-card h1 { font-size: 1.4rem; }
.resend-form .btn { width: 100%; min-height: 46px; }

/* Gợi ý tìm kiếm */
.search { position: relative; }
.suggest { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; margin: 0; padding: 6px; list-style: none; max-height: min(70vh, 460px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); }
.suggest a { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; text-decoration: none; color: var(--text); }
.suggest img { flex: none; width: 32px; height: 48px; object-fit: cover; border-radius: 3px; box-shadow: 0 1px 2px rgb(16 24 40 / .15); }
.suggest span { display: flex; flex-direction: column; min-width: 0; }
.suggest strong { font-size: .9rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest small { font-size: .8rem; color: var(--muted); }
.suggest [aria-selected="true"] a, .suggest a:hover { background: var(--accent-soft); }
.suggest-all { justify-content: center; padding: 10px 8px !important; font-size: .85rem; font-weight: 600; color: var(--accent) !important; border-top: 1px solid var(--line); margin-top: 4px; }
.empty-tags { justify-content: center; margin-top: 16px; }
.empty-head { margin-top: 28px; }

/* Gợi ý tìm kiếm: dòng tác giả */
.suggest-author-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); font-size: 1rem; }

/* Nội dung HTML của phần giới thiệu */
.rich > :first-child { margin-top: 0; }
.rich h2, .rich h3, .rich h4 { margin: 1.2em 0 .5em; text-transform: none; }
.rich h2 { font-size: 1.2rem; } .rich h3 { font-size: 1.08rem; } .rich h4 { font-size: 1rem; }
.rich p, .rich ul, .rich ol, .rich blockquote, .rich table, .rich figure, .rich pre { margin: 0 0 1em; max-width: 68ch; }
.rich ul, .rich ol { padding-left: 1.4em; }
.rich li { margin-bottom: .3em; }
.rich a { color: var(--accent); }
.rich blockquote { padding: 10px 16px; border-left: 3px solid var(--accent-border); background: var(--subtle); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text); }
.rich img { height: auto; max-width: 100%; border-radius: 6px; margin: 4px 0; }
.rich figure { margin-left: 0; margin-right: 0; }
.rich figcaption { font-size: .85rem; color: var(--muted); text-align: center; margin-top: 4px; }
.rich table { width: 100%; border-collapse: collapse; font-size: .92rem; display: block; overflow-x: auto; }
.rich th, .rich td { padding: 6px 10px; border: 1px solid var(--line); text-align: left; }
.rich th { background: var(--subtle); }
.rich hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
.rich pre { padding: 12px; background: var(--subtle); border-radius: var(--radius); overflow-x: auto; }

/* ---------- Admin: thẻ cài đặt, quản lý tag/tác giả ---------- */
.tabs { display: flex; gap: 4px; margin: 0 0 20px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; text-decoration: none; font-weight: 500; color: var(--muted); }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.taxo-help { margin: -8px 0 16px; }
.taxo-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.taxo-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.taxo-row:last-child { border-bottom: 0; }
.taxo-edit, .taxo-merge { display: flex; align-items: center; gap: 6px; min-width: 0; }
.taxo-edit input, .taxo-merge input { min-width: 0; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; font: inherit; font-size: .88rem; background: var(--surface); color: var(--text); }
.taxo-edit input[name="name"] { flex: 1 1 180px; }
.taxo-edit input[name="slug"] { flex: 1 1 160px; font-size: .8rem; }
.taxo-merge input { width: 150px; }
.taxo-dot { flex: none; width: 12px; height: 12px; padding: 0; border-radius: 50%; background: var(--tag-ink); border: 0; }
.taxo-count { font-size: .85rem; color: var(--accent); text-decoration: none; white-space: nowrap; }
@media (max-width: 900px) { .taxo-row { grid-template-columns: 1fr; } }

/* ---------- Admin: ô chip Tag / Tác giả ---------- */
.chip-field { position: relative; }
.chip-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 44px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); cursor: text; }
.chip-box:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.chip-type { flex: 1; min-width: 160px; border: 0 !important; padding: 4px !important; outline: 0; box-shadow: none !important; font: inherit; font-weight: 400; background: transparent; }
.chip-item { flex: none; white-space: nowrap; padding: 3px 4px 3px 10px !important; gap: 2px !important; font-weight: 500; }
.chip-x { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: transparent; color: inherit; font-size: 1rem; line-height: 1; cursor: pointer; opacity: .7; }
.chip-x:hover { background: rgb(0 0 0 / .08); opacity: 1; }
.chip-suggest { position: absolute; left: 0; right: 0; top: calc(100% - 26px); z-index: 20; margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.chip-suggest button { display: block; width: 100%; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; font: inherit; font-weight: 400; cursor: pointer; }
.chip-suggest button:hover { background: var(--accent-soft); }
.chip-toggle { align-self: flex-start; font-weight: 500; }
.chip-panel { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.chip-opt { cursor: pointer; font: inherit; font-size: .85rem; font-weight: 500; }
.chip-opt.selected { box-shadow: inset 0 0 0 1.5px currentColor; }
.chip-opt.selected::before { content: "✓"; font-weight: 700; }
.jodit-container { margin-bottom: 16px; }
.taxo-dot.tag { background: var(--tag-ink); border: 0; padding: 0; }
