/* ==========================================================================
   Hệ thống thiết kế dùng chung – Cổng thông tin Thư viện
   Theo nhận diện Trường Đại học CMC: xanh CMC, xanh navy, đỏ CMC, xanh ngọc; nền sáng dịu mắt
   ========================================================================== */
:root {
  /* Nhận diện Trường Đại học CMC: xanh CMC (logo #1C9AD6, web #008FD5), xanh navy #002757, đỏ #AE152D, xanh ngọc #00DEDF.
     Các sắc 600–700 được làm đậm hơn để chữ trắng/chữ xanh đạt chuẩn tương phản WCAG AA (≥ 4.5:1). */
  --brand-950: #001733;
  --brand-900: #002757;
  --brand-800: #004f82;
  --brand-700: #006aa3;
  --brand-600: #0079b8;
  --brand-500: #008fd5;
  --brand-200: #bfe2f4;
  --brand-100: #e2f2fb;
  --brand-50: #f1f8fd;
  --accent-700: #7d0f20;
  --accent-600: #9d2235;
  --accent-500: #ae152d;
  --accent-300: #efb3bd;
  --accent-100: #fbebee;
  --cyan: #00dedf;
  --brand-bar: #10386b; /* màu thanh trên cùng của website cmcu.edu.vn */

  --ink: #18212f;
  --ink-2: #3a4556;
  --muted: #5f6b7d;
  --faint: #8a94a4;
  --line: #e1e6ee;
  --line-2: #edf1f6;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --paper: #fffdf8;

  --success: #1b7a4b; --success-bg: #e4f4eb;
  --danger: #b42318;  --danger-bg: #fdecea;
  --warning: #9a4a07; --warning-bg: #fef3e2;
  --info: #1d5fbf;    --info-bg: #e7f0fd;
  --violet: #5b3fa8;  --violet-bg: #efeafb;

  --series-1: #008fd5;
  --grid: #e7e9ee;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 32, 60, .06);
  --shadow: 0 6px 20px rgba(15, 32, 60, .08);
  --shadow-lg: 0 18px 48px rgba(15, 32, 60, .18);
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-head: 'Montserrat', 'Be Vietnam Pro', system-ui, sans-serif;
  --font-serif: 'Noto Serif', Georgia, 'Times New Roman', serif;
  --focus: 0 0 0 3px rgba(0, 143, 213, .35);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--ink);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}
img, svg, video { max-width: 100%; }
img { display: block; height: auto; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-800); text-decoration: underline; text-underline-offset: 2px; }
a[data-link] { cursor: pointer; } /* liên kết đã ẩn href (xem maskLinks trong common.js) */
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; color: var(--brand-900); font-weight: 700; font-family: var(--font-head); }
p { margin: 0 0 1em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
::selection { background: var(--brand-200); color: var(--brand-950); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 1000; background: var(--accent-500); color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 600; }
.skip-link:focus { top: 12px; }

.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.i-sm { width: 15px; height: 15px; }
.i-lg { width: 24px; height: 24px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: 10px; font-weight: 600; font-size: 14px; line-height: 1.2; cursor: pointer;
  background: var(--surface); color: var(--ink-2); border-color: var(--line); transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-800); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.btn-primary:hover { background: var(--brand-800); border-color: var(--brand-800); color: #fff; }
.btn-accent { background: var(--accent-500); border-color: var(--accent-500); color: #fff; }
.btn-accent:hover { background: var(--accent-600); border-color: var(--accent-600); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #146038; border-color: #146038; color: #fff; }
.btn-danger { background: var(--surface); border-color: #f1c0bb; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--brand-50); border-color: transparent; }
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: 13px; border-radius: 8px; gap: 6px; }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: 15px; }
.btn-icon { width: 34px; min-height: 34px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- Biểu mẫu ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label, .label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.field .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 12.5px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid #cfd7e3; border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s; font-size: 14.5px;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: #9aa3b2; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6b7d' stroke-width='2' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; }
.input-sm, .select-sm { min-height: 36px; padding-top: 6px; padding-bottom: 6px; font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand-600); margin: 0; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 22px; background: #cdd5e1; border-radius: 99px; position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .track { background: var(--brand-600); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f4c7c1; padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.input-group { display: flex; gap: 8px; }
.input-group > .input { flex: 1; }

/* ---------- Nhãn trạng thái ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: 12.5px;
  font-weight: 600; line-height: 1.4; background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.t-success { background: var(--success-bg); color: var(--success); }
.badge.t-danger { background: var(--danger-bg); color: var(--danger); }
.badge.t-warning { background: var(--warning-bg); color: var(--warning); }
.badge.t-info { background: var(--info-bg); color: var(--info); }
.badge.t-violet { background: var(--violet-bg); color: var(--violet); }
.badge.t-navy { background: var(--brand-100); color: var(--brand-700); }
.badge.t-gold { background: var(--accent-100); color: var(--accent-700); }
.badge.t-muted { background: #eef0f3; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 13.5px; color: var(--ink-2); cursor: pointer; text-decoration: none !important; }
.chip:hover { border-color: var(--brand-200); background: var(--brand-50); color: var(--brand-800); }
.chip.active { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.chip .n { font-size: 12px; opacity: .7; }
mark, .hl { background: #ffe58a; color: inherit; padding: 0 1px; border-radius: 3px; }
.hl.current { background: #ffb020; box-shadow: 0 0 0 2px #ffb020; }

/* ---------- Thẻ & bảng ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
.table tbody tr:hover { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Bìa sách tự sinh ---------- */
.cover {
  --c: #006aa3; position: relative; aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; overflow: hidden;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 82%, #fff) 0%, var(--c) 55%, color-mix(in srgb, var(--c) 70%, #000) 100%);
  color: #fff; padding: 14% 12% 10% 16%; display: flex; flex-direction: column; box-shadow: 0 6px 14px rgba(15, 32, 60, .22), inset 4px 0 0 rgba(0,0,0,.18);
  font-family: var(--font-serif);
}
.cover::before { content: ''; position: absolute; left: 7%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.25); }
.cover::after { content: ''; position: absolute; right: 10%; bottom: 8%; width: 34%; height: 2px; background: var(--cyan); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-fmt { font-family: var(--font); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; opacity: .85; margin-bottom: 10%; font-weight: 600; }
.cover-title { font-weight: 700; font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover-author { margin-top: auto; font-family: var(--font); font-size: 10px; opacity: .85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cover.sm { padding: 12% 10% 10% 14%; }
.cover.sm .cover-title { font-size: 10px; -webkit-line-clamp: 4; }
.cover.sm .cover-author, .cover.sm .cover-fmt { display: none; }
.cover.lg .cover-title { font-size: 20px; }
.cover.lg .cover-author { font-size: 13px; }
.cover.lg .cover-fmt { font-size: 11px; }

/* ---------- Phân trang ---------- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; justify-content: center; margin-top: 24px; }
.pagination button { min-width: 38px; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; color: var(--ink-2); }
.pagination button:hover:not(:disabled) { border-color: var(--brand-200); background: var(--brand-50); }
.pagination button.active { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.pagination button:disabled { opacity: .45; cursor: default; }
.pagination .gap { padding: 0 4px; color: var(--faint); }

/* ---------- Hộp thoại ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 23, 51, .55); display: flex; align-items: flex-start; justify-content: center; z-index: 900; padding: 5vh 16px; overflow-y: auto; animation: fade .15s ease; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; display: flex; flex-direction: column; animation: pop .18s ease; margin-bottom: 5vh; }
.modal.lg { max-width: 860px; }
.modal.xl { max-width: 1080px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 18px; margin: 0; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: #fafbfd; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Thông báo nổi ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--brand-900); color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px; animation: pop .2s ease; }
.toast.success { background: #145c39; }
.toast.error { background: #8f1d14; }
.toast .i { margin-top: 1px; }

/* ---------- Tiện ích ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .i { width: 40px; height: 40px; stroke-width: 1.5; color: var(--brand-200); margin-bottom: 8px; }
.loading { display: flex; justify-content: center; padding: 48px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--brand-100); border-top-color: var(--brand-600); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Nội dung soạn thảo (bài viết, toàn văn) ---------- */
.prose { font-size: 16px; line-height: 1.75; color: #222b38; overflow-wrap: anywhere; }
.prose h2 { font-size: 1.3em; margin: 1.4em 0 .6em; }
.prose h3 { font-size: 1.15em; margin: 1.2em 0 .5em; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1em; }
.prose li { margin: .3em 0; }
.prose blockquote { margin: 1.2em 0; padding: 12px 18px; border-left: 4px solid var(--brand-500); background: var(--brand-50); border-radius: 0 10px 10px 0; font-style: italic; color: var(--ink-2); }
.prose table { width: 100%; border-collapse: collapse; margin: 1em 0 1.4em; font-size: 14.5px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.prose th { background: var(--brand-50); color: var(--brand-800); }
.prose img { border-radius: 10px; margin: 1em auto; }
.prose iframe { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 10px; }
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose > :first-child { margin-top: 0; }

/* ---------- Trình soạn thảo văn bản ---------- */
.editor { border: 1px solid #cfd7e3; border-radius: 10px; background: #fff; overflow: hidden; }
.editor:focus-within { border-color: var(--brand-500); box-shadow: var(--focus); }
.editor-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line-2); background: #f8fafc; }
.editor-bar button { min-width: 32px; height: 32px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0 7px; }
.editor-bar button:hover { background: var(--brand-100); color: var(--brand-800); }
.editor-bar .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.editor-area { min-height: 220px; max-height: 520px; overflow-y: auto; padding: 14px 16px; outline: none; font-size: 15px; }
.editor-area:empty::before { content: attr(data-placeholder); color: #9aa3b2; }
.editor-src { width: 100%; min-height: 220px; border: 0; padding: 14px 16px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical; outline: none; }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; margin: 0; }
  .modal-foot { border-radius: 0; }
}
@media print {
  .no-print { display: none !important; }
}
