/* =====================================================================
   HỆ THỐNG THIẾT KẾ - THƯ VIỆN TRUYỀN THỐNG
   Tông màu: đỏ son (chủ đạo, phong cách cơ quan nhà nước), vàng nhũ (điểm nhấn),
   nền giấy kem (không khí thư viện), chữ có chân Lora cho tiêu đề.
   ===================================================================== */
@import url('/vendor/fonts/be-vietnam-pro/400.css');
@import url('/vendor/fonts/be-vietnam-pro/500.css');
@import url('/vendor/fonts/be-vietnam-pro/600.css');
@import url('/vendor/fonts/be-vietnam-pro/700.css');
@import url('/vendor/fonts/lora/500.css');
@import url('/vendor/fonts/lora/600.css');
@import url('/vendor/fonts/lora/700.css');
@import url('/vendor/fonts/lora/400-italic.css');

:root {
  /* Màu thương hiệu */
  --red-900: #6e1510;
  --red-800: #8f1b14;
  --red-700: #b3261e;
  --red-600: #c62828;
  --red-500: #d9412f;
  --red-100: #fbe3df;
  --red-50: #fdf2f0;
  --gold-700: #9a6b00;
  --gold-600: #c48a00;
  --gold-500: #e8a317;
  --gold-400: #f5c242;
  --gold-200: #fbe3a0;
  --gold-100: #fff3cf;
  --gold-50: #fffaeb;
  --blue-700: #0b5cad;
  --blue-600: #1570cd;
  --blue-100: #dcebfb;
  --blue-50: #eef5fd;
  --green-700: #1e7b45;
  --green-600: #23904f;
  --green-100: #dcf3e4;
  --amber-700: #a45a00;
  --amber-100: #fdeccc;

  /* Nền, chữ, viền */
  --paper: #fcf8f0;
  --paper-2: #f6efe1;
  --surface: #ffffff;
  --surface-2: #fdfbf7;
  --ink: #1f2328;
  --ink-2: #3a3f46;
  --muted: #646b75;
  --faint: #8a9099;
  --line: #e8dfcd;
  --line-2: #f0e9dc;
  --focus: #f5c242;

  --primary: var(--red-700);
  --primary-hover: var(--red-800);
  --link: var(--blue-700);

  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(60, 40, 10, .06);
  --shadow: 0 1px 3px rgba(60, 40, 10, .08), 0 6px 18px -8px rgba(60, 40, 10, .14);
  --shadow-lg: 0 18px 50px -12px rgba(40, 20, 5, .35);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
img, svg { vertical-align: middle; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--red-900); line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; font-family: var(--font); font-weight: 600; color: var(--ink); }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
small, .small { font-size: .85em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.upper { text-transform: uppercase; letter-spacing: .04em; }
.serif { font-family: var(--serif); }
.strong { font-weight: 600; }
.text-red { color: var(--red-700); }
.text-green { color: var(--green-700); }
.text-amber { color: var(--amber-700); }
.text-blue { color: var(--blue-700); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* Bố cục */
.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; white-space: normal; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.sm { gap: 6px; }
.stack.lg { gap: 20px; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.gap-sm { gap: 8px; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
@media (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .container { padding: 0 14px; }
}

/* Thẻ nội dung */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line-2);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.08rem; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card.flat { box-shadow: none; }
.card.gold { border-color: var(--gold-200); background: linear-gradient(180deg, var(--gold-50), #fff); }
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 1.3rem; color: var(--red-900); margin: 0 0 14px;
}
.section-title::before {
  content: ''; width: 6px; height: 22px; border-radius: 3px;
  background: linear-gradient(180deg, var(--red-600), var(--gold-500));
}

/* Nút */
.btn {
  --bg: var(--surface); --fg: var(--ink); --bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: var(--r-sm);
  border: 1px solid var(--bd); background: var(--bg); color: var(--fg);
  font: 500 14px/1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  text-decoration: none !important;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn svg { flex: none; }
.btn-primary { --bg: var(--red-700); --fg: #fff; --bd: var(--red-700); }
.btn-primary:hover { background: var(--red-800); border-color: var(--red-800); }
.btn-gold { --bg: var(--gold-500); --fg: #3b2500; --bd: var(--gold-600); font-weight: 600; }
.btn-gold:hover { background: var(--gold-400); }
.btn-blue { --bg: var(--blue-700); --fg: #fff; --bd: var(--blue-700); }
.btn-blue:hover { background: var(--blue-600); }
.btn-green { --bg: var(--green-700); --fg: #fff; --bd: var(--green-700); }
.btn-green:hover { background: var(--green-600); }
.btn-danger { --bg: #fff; --fg: var(--red-700); --bd: #eab4ad; }
.btn-danger:hover { background: var(--red-50); border-color: var(--red-600); }
.btn-ghost { --bg: transparent; --bd: transparent; --fg: var(--ink-2); }
.btn-ghost:hover { background: rgba(0, 0, 0, .05); }
.btn-link { --bg: transparent; --bd: transparent; --fg: var(--link); padding: 0 4px; height: auto; }
.btn-link:hover { background: transparent; text-decoration: underline !important; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 16px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.btn-group .btn.active { background: var(--red-50); color: var(--red-800); border-color: #e7b3ab; z-index: 1; }

/* Biểu mẫu */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field .error { font-size: 12.5px; color: var(--red-700); }
.req::after { content: ' *'; color: var(--red-600); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid #d9cfbc; border-radius: var(--r-sm);
  background: #fff; color: var(--ink); font: 400 14.5px var(--font);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 84px; padding: 9px 11px; line-height: 1.5; resize: vertical; }
.select { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23646b75' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.select[multiple] { height: auto; padding: 4px; background-image: none; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--gold-600); box-shadow: 0 0 0 3px rgba(245, 194, 66, .35); }
.input[readonly], .input:disabled, .select:disabled, .textarea:disabled { background: var(--paper-2); color: var(--muted); }
.input-sm, .select.input-sm { height: 31px; font-size: 13.5px; }
.input-lg { height: 50px; font-size: 16px; padding: 0 16px; }
.input.mono { font-family: var(--mono); }
.input-group { display: flex; align-items: stretch; }
.input-group > .input, .input-group > .select { border-radius: 0; }
.input-group > :first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group > :last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.input-group > * + * { margin-left: -1px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--red-700); margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; } }
fieldset.group { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; margin: 0 0 16px; background: var(--surface-2); }
fieldset.group > legend { padding: 0 8px; font-family: var(--serif); font-weight: 700; color: var(--red-800); }

/* Bảng */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.table th { background: #faf5ea; font-weight: 600; font-size: 12.5px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table tbody tr:hover { background: #fffcf4; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.selected { background: var(--gold-50); }
.table tr.row-danger td { background: #fff6f5; }
.table tr.row-warning td { background: #fffaf0; }
.table.compact th, .table.compact td { padding: 6px 10px; }
.table td.actions { white-space: nowrap; text-align: right; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap > .table th:first-child { border-top-left-radius: var(--r); }

/* Nhãn trạng thái */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1.6;
  background: #eef0f2; color: #4a5059; white-space: nowrap;
}
.badge.success { background: var(--green-100); color: #13572f; }
.badge.warning { background: var(--amber-100); color: #7a4300; }
.badge.danger { background: var(--red-100); color: var(--red-800); }
.badge.info { background: var(--blue-100); color: #0a4a8a; }
.badge.gold { background: var(--gold-100); color: #6b4a00; border: 1px solid var(--gold-200); }
.badge.outline { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

/* Thông báo */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r); border: 1px solid; font-size: 14px; align-items: flex-start; }
.alert > svg { flex: none; margin-top: 2px; }
.alert.info { background: var(--blue-50); border-color: #bcd7f4; color: #0a3d73; }
.alert.success { background: #effaf3; border-color: #b6e2c5; color: #14532d; }
.alert.warning { background: #fff8e8; border-color: #f3d58e; color: #6b4000; }
.alert.danger { background: var(--red-50); border-color: #f0bdb6; color: var(--red-900); }
.alert .alert-title { font-weight: 700; }

/* Tab */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 10px 14px; border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  font: 500 14px var(--font); color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--red-800); border-bottom-color: var(--red-700); font-weight: 600; }
.tab .count { background: var(--paper-2); color: var(--ink-2); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.tab.active .count { background: var(--red-100); color: var(--red-800); }

/* Phân trang */
.pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination .pg {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: #fff; cursor: pointer; font: 500 14px var(--font); color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.pagination .pg:hover { border-color: var(--gold-500); }
.pagination .pg.active { background: var(--red-700); color: #fff; border-color: var(--red-700); }
.pagination .pg[disabled] { opacity: .4; cursor: default; }
.pagination .gap { padding: 0 4px; color: var(--faint); }

/* Hộp thoại */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(35, 20, 8, .45); z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
  animation: fadeIn .15s ease;
}
.modal {
  width: 100%; max-width: 560px; background: #fff; border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  border-top: 5px solid var(--red-700); animation: pop .18s ease;
}
.modal.lg { max-width: 820px; }
.modal.xl { max-width: 1100px; }
.modal.sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* Toast */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r);
  background: #fff; box-shadow: var(--shadow-lg); border-left: 5px solid var(--blue-700); font-size: 14px;
  animation: pop .2s ease;
}
.toast.success { border-left-color: var(--green-700); }
.toast.error { border-left-color: var(--red-700); }
.toast.warning { border-left-color: var(--gold-500); }
.toast .close { margin-left: auto; }

/* Trạng thái rỗng / đang tải */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { color: var(--gold-600); opacity: .8; margin-bottom: 8px; }
.empty .title { font-family: var(--serif); font-size: 1.1rem; color: var(--ink-2); margin-bottom: 4px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 36px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 3px solid var(--gold-200); border-top-color: var(--red-700); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Danh sách mô tả */
.dl { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: 7px 18px; margin: 0; font-size: 14.5px; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; gap: 2px; } .dl dd { margin-bottom: 8px; } }

/* Tiêu đề trang */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: 14px; }
.breadcrumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--red-700); }

/* Ảnh bìa */
.cover { width: 100%; aspect-ratio: 11 / 16; object-fit: cover; border-radius: 4px 8px 8px 4px; background: var(--paper-2); box-shadow: 0 1px 2px rgba(0,0,0,.15), 4px 6px 14px -6px rgba(60, 30, 5, .45); }
.cover.sm { width: 56px; }
.cover.md { width: 92px; }
.cover.lg { width: 200px; }

/* Thẻ số liệu */
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--red-50); color: var(--red-700); flex: none; }
.stat .ico.gold { background: var(--gold-100); color: var(--gold-700); }
.stat .ico.blue { background: var(--blue-50); color: var(--blue-700); }
.stat .ico.green { background: var(--green-100); color: var(--green-700); }
.stat .val { font-size: 1.6rem; font-weight: 700; font-family: var(--serif); color: var(--ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; }

/* Chip / facet */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.chip:hover { border-color: var(--gold-500); background: var(--gold-50); text-decoration: none; }
.chip.active { background: var(--red-700); color: #fff; border-color: var(--red-700); }
.chip .x { opacity: .75; }

/* MARC */
.marc { font-family: var(--mono); font-size: 13px; line-height: 1.7; background: #fffdf7; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; white-space: pre-wrap; }
.marc .tag { color: var(--red-700); font-weight: 700; }
.marc .ind { color: var(--gold-700); }
.marc .sf { color: var(--blue-700); font-weight: 700; }
.isbd { font-family: var(--serif); font-size: 15px; line-height: 1.8; background: #fffdf7; border: 1px solid var(--line); border-radius: var(--r); padding: 16px 20px; }
.isbd .heading { font-weight: 700; }

/* Công cụ */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); }
.kbd { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: #fff; }
.divider-v { width: 1px; align-self: stretch; background: var(--line); }

/* In ấn */
@media print {
  body { background: #fff; }
  .no-print, .toasts, .modal-backdrop { display: none !important; }
  .card { box-shadow: none; border-color: #ccc; }
}
