/* =========================================================
   Thư viện số — giao diện
   Màu chủ đạo: xanh navy + cam ấm. Font: Be Vietnam Pro
   ========================================================= */
:root {
  --navy-900: #0f2440;
  --navy-800: #16335a;
  --navy-700: #1e426f;
  --navy-600: #2a5589;
  --orange: #f26f21;
  --orange-600: #d95c12;
  --orange-50: #fff3eb;

  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --line: #e7e2d8;
  --text: #1c2433;
  --text-2: #5b6474;
  --text-3: #8a92a0;

  --ok: #127a52;      --ok-bg: #e4f5ec;
  --warn: #9a5b00;    --warn-bg: #fdf1dc;
  --danger: #b42318;  --danger-bg: #fdeceb;
  --info: #1e5aa8;    --info-bg: #e8f0fb;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px -8px rgba(16, 24, 40, .12);
  --shadow-lg: 0 20px 50px -20px rgba(15, 36, 64, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--navy-600); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--orange); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.05), 0 4px 12px -4px rgba(242,111,33,.55); }
.btn-primary:hover:not(:disabled) { background: var(--orange-600); }
.btn-dark { background: var(--navy-800); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--navy-900); }
.btn-outline { background: var(--surface); color: var(--navy-800); border-color: var(--line); }
.btn-outline:hover:not(:disabled) { border-color: var(--navy-600); }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Ô nhập ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
input {
  font: inherit; font-size: 14px; color: var(--text);
  width: 100%; padding: 11px 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--text-3); }
input:focus { border-color: var(--navy-600); box-shadow: 0 0 0 4px rgba(42, 85, 137, .12); }
.pw { position: relative; }
.pw input { padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: 12px; font-weight: 600; color: var(--navy-600);
  background: transparent; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.pw-toggle:hover { background: var(--surface-2); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Thương hiệu ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--orange); box-shadow: 0 6px 16px -6px rgba(242,111,33,.8);
}
.brand-mark svg { width: 19px; height: 19px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.brand-light { color: #fff; }

/* =========================================================
   MÀN HÌNH ĐĂNG NHẬP
   ========================================================= */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art {
  position: relative; overflow: hidden; color: #fff;
  padding: 40px 56px; display: flex; flex-direction: column;
  background:
    radial-gradient(900px 500px at 110% -10%, rgba(242,111,33,.35), transparent 60%),
    radial-gradient(700px 400px at -20% 110%, rgba(72,128,200,.35), transparent 60%),
    linear-gradient(160deg, var(--navy-800), var(--navy-900));
}
.login-hero { margin: auto 0; max-width: 480px; padding: 48px 0 200px; }
.login-hero h1 { font-size: clamp(28px, 3.2vw, 40px); font-weight: 800; }
.login-hero p { margin-top: 16px; color: rgba(255,255,255,.78); font-size: 16px; }
.login-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-points li { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.9); }
.login-points span {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); font-size: 16px;
}

/* Kệ sách minh họa bằng CSS */
.shelf {
  position: absolute; left: 56px; right: 56px; bottom: 44px;
  display: flex; align-items: flex-end; gap: 6px; height: 180px;
  border-bottom: 10px solid rgba(255,255,255,.14); padding: 0 12px;
}
.shelf i {
  display: block; width: var(--w); height: var(--t); border-radius: 4px 4px 2px 2px;
  background: linear-gradient(90deg, hsl(var(--h) 55% 52%), hsl(var(--h) 60% 44%));
  box-shadow: inset -3px 0 0 rgba(0,0,0,.12), inset 0 10px 0 rgba(255,255,255,.12), inset 0 -14px 0 rgba(255,255,255,.1);
  opacity: .92;
}
.shelf i.tilt { transform: rotate(-9deg); transform-origin: bottom left; margin-left: 6px; }

.login-panel { display: grid; place-items: center; padding: 32px 24px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 36px 32px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 18px;
}
.login-card h2 { font-size: 26px; font-weight: 800; }
.login-card > .muted:first-of-type { margin-top: -8px; }

/* =========================================================
   KHUNG ỨNG DỤNG
   ========================================================= */
.topbar {
  position: sticky; top: 0; z-index: 20; color: #fff;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  box-shadow: 0 6px 20px -12px rgba(15,36,64,.6);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 24px;
}
#mainNav { display: flex; gap: 4px; flex: 1; }
.tab-btn {
  font: inherit; font-size: 14px; font-weight: 600; color: rgba(255,255,255,.72);
  background: transparent; border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer;
  transition: background .15s, color .15s; white-space: nowrap;
}
.tab-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.tab-btn.active { color: var(--navy-900); background: #fff; }

.user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--orange); color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: 0 0 0 2px rgba(255,255,255,.2);
}
.user-text { display: flex; flex-direction: column; line-height: 1.2; max-width: 180px; }
.user-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-text small { font-size: 12px; color: rgba(255,255,255,.65); }

.container { max-width: 1160px; margin: 0 auto; padding: 32px 24px 24px; }
.tab-panel { display: none; animation: fade .25s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head h2 { font-size: 26px; font-weight: 800; }
.page-head p { margin-top: 4px; }

.footer { text-align: center; padding: 24px; }

/* ---------- Thanh tìm kiếm ---------- */
.searchbar {
  display: flex; gap: 10px; padding: 10px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.search-field { position: relative; display: flex; align-items: center; min-width: 200px; }
.search-field.grow { flex: 1; }
.search-field .ic { position: absolute; left: 12px; color: var(--text-3); pointer-events: none; }
.search-field input { padding-left: 38px; }
.searchbar .search-field input { border-color: transparent; background: var(--surface-2); }
.searchbar .search-field input:focus { background: var(--surface); border-color: var(--navy-600); }
.result-count { font-size: 13px; margin: 4px 2px 14px; min-height: 20px; }

/* ---------- Hộp mượn hộ (thủ thư) ---------- */
.notice {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--orange-50); border: 1px solid #fbd5bd; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.notice-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: #fff; font-size: 18px; }
.notice-body { display: flex; flex-direction: column; flex: 1; min-width: 200px; }
.notice input { max-width: 280px; border-color: #f6c3a2; }

/* ---------- Lưới sách ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.book {
  display: flex; gap: 16px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); transition: box-shadow .2s, transform .2s, border-color .2s;
}
.book:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: #ddd6c9; }
.cover {
  position: relative; flex: none; width: 74px; height: 104px; border-radius: 4px 8px 8px 4px;
  background: linear-gradient(135deg, hsl(var(--h) 55% 50%), hsl(calc(var(--h) + 25) 60% 36%));
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 26px;
  box-shadow: inset 6px 0 0 rgba(0,0,0,.15), inset 8px 0 0 rgba(255,255,255,.12), 0 6px 14px -6px hsl(var(--h) 50% 30% / .6);
  text-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.cover::after { content: ""; position: absolute; left: 14px; right: 8px; bottom: 12px; height: 2px; background: rgba(255,255,255,.35); border-radius: 2px; }
.cover.sm { width: 46px; height: 64px; font-size: 18px; }
.cover.sm::after { left: 10px; bottom: 8px; }
.book-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.book-body h3 { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.book-body .author { font-size: 13px; color: var(--text-2); }
.book-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 6px; }
.stock { display: flex; flex-direction: column; gap: 5px; min-width: 110px; }
.stock-bar { height: 6px; border-radius: 99px; background: #efebe3; overflow: hidden; }
.stock-bar span { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.stock-bar.low span { background: #e0a100; }
.stock-bar.out span { background: var(--danger); }
.stock small { font-size: 12px; font-weight: 600; color: var(--text-2); }

/* ---------- Chip / huy hiệu ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
}
.tag.subject { background: var(--info-bg); color: var(--info); border-color: transparent; }
.tag.link { text-decoration: none; background: var(--orange-50); color: var(--orange-600); border-color: transparent; }
.tag.link:hover { text-decoration: underline; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: #eeece7; color: var(--text-2); }

.chip {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2); transition: all .15s;
}
.chip:hover { border-color: var(--navy-600); color: var(--navy-700); }
.chip.active { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }

/* ---------- Thẻ thống kê ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stats-3 { grid-template-columns: repeat(3, 1fr); }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 14px;
}
.stat-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; flex: none; }
.stat-icon.blue { background: var(--info-bg); }
.stat-icon.green { background: var(--ok-bg); }
.stat-icon.red { background: var(--danger-bg); }
.stat-icon.orange { background: var(--orange-50); }
.stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--text-2); }

/* ---------- Panel quản lý ---------- */
.admin-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; margin-bottom: 16px; align-items: start; }
.panel-col { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.panel-head h3 { font-size: 16px; font-weight: 700; }
.panel-head-wrap { justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.panel-head-title { display: flex; align-items: center; gap: 10px; }
.panel-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 15px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-sm { min-width: 220px; }
.search-sm input { padding-top: 7px; padding-bottom: 7px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-2 { grid-column: span 2; }

/* ---------- Danh sách phiếu mượn ---------- */
.loan-list { display: flex; flex-direction: column; gap: 10px; }
.loan {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.panel .loan { background: var(--surface-2); }
.loan.overdue { border-color: #f3c4c0; background: #fff8f7; }
.loan-main { flex: 1; min-width: 0; }
.loan-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.loan-title strong { font-size: 15px; }
.loan-meta { margin-top: 3px; font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.loan-meta b { color: var(--text); font-weight: 600; }
.loan-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
.due { font-size: 12px; font-weight: 600; }
.due.ok { color: var(--ok); }
.due.warn { color: var(--warn); }
.due.danger { color: var(--danger); }
.fine { font-size: 13px; font-weight: 700; color: var(--danger); }

/* ---------- Trạng thái rỗng & đang tải ---------- */
.empty {
  grid-column: 1 / -1; text-align: center; padding: 48px 20px;
  background: var(--surface); border: 1px dashed #d8d1c3; border-radius: var(--radius);
}
.empty .emoji { font-size: 36px; }
.empty h4 { margin: 10px 0 4px; font-size: 16px; }
.skeleton { background: linear-gradient(90deg, #eeeae2 0%, #f7f4ee 50%, #eeeae2 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); min-height: 136px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Thông báo nổi ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); z-index: 50;
  max-width: calc(100% - 32px); padding: 12px 18px 12px 14px; border-radius: 12px;
  background: var(--navy-900); color: #fff; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast::before { content: "ℹ️"; }
#toast.success::before { content: "✅"; }
#toast.error { background: #7a1d16; }
#toast.error::before { content: "⚠️"; }

/* =========================================================
   ĐIỆN THOẠI / MÀN HÌNH NHỎ
   ========================================================= */
@media (max-width: 980px) {
  .admin-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 28px 24px 24px; }
  .login-hero { padding: 28px 0 8px; }
  .login-points, .shelf { display: none; }
  .login-panel { padding: 0 16px 32px; margin-top: -8px; }
  .login-card { padding: 28px 22px; }

  .topbar-inner { flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; }
  .brand { flex: 1; }
  #mainNav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; }
  #mainNav::-webkit-scrollbar { display: none; }
  .hide-sm { display: none; }
  .user-text { display: none; }

  .container { padding: 22px 16px; }
  .page-head h2 { font-size: 22px; }
  .searchbar { flex-direction: column; }
  .search-field { min-width: 0; }
  .notice input { max-width: none; }
  .loan { flex-wrap: wrap; }
  .loan-side { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; text-align: left; }
}
@media (max-width: 520px) {
  .stats, .stats-3 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; font-size: 16px; }
  .stat-value { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .book-grid { grid-template-columns: 1fr; }
  .cover { width: 62px; height: 88px; font-size: 22px; }
}