/* ============ 基础 ============ */
:root {
  --paper: #f5f2ea;
  --paper-2: #efe9dd;
  --surface: #fffdf8;
  --ink: #1f1d1a;
  --ink-soft: #46403a;
  --muted: #746c60;
  --line: #e2dbcb;
  --line-strong: #d3c9b4;
  --accent: #2f6156;
  --accent-dark: #234b42;
  --accent-soft: #e6efeb;
  --amber: #a9722c;
  --amber-soft: #f6ecda;
  --danger: #a5432f;
  --danger-soft: #f7e8e4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(31, 29, 26, .05), 0 6px 16px rgba(31, 29, 26, .05);
  --shadow-md: 0 2px 4px rgba(31, 29, 26, .06), 0 14px 34px rgba(31, 29, 26, .09);
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: #d8e6e1; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .16s ease, transform .16s ease, box-shadow .16s ease, color .16s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}
.btn-ghost:hover { background: rgba(47, 97, 86, .07); border-color: var(--accent); color: var(--accent-dark); }

.btn-line {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}
.btn-line:hover { border-color: var(--accent); color: var(--accent-dark); background: #fff; }

.btn-danger {
  background: transparent;
  border-color: #e2c4bc;
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; padding: 12px 18px; font-size: 15px; }

/* ============ 登录页 ============ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}

.auth-brand {
  position: relative;
  overflow: hidden;
  padding: 60px 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #f4efe2;
  background:
    radial-gradient(900px 520px at 78% 8%, rgba(178, 138, 74, .30), transparent 62%),
    linear-gradient(158deg, #35685c 0%, #234b42 46%, #172f2a 100%);
}

.auth-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 96px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .04) 0 1px, transparent 1px 96px);
  pointer-events: none;
}

.auth-brand > * { position: relative; z-index: 1; }

.brand-lockup { display: flex; align-items: center; gap: 14px; }
.brand-lockup .mark {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(244, 239, 226, .34);
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .07);
}
.brand-lockup .mark svg { width: 24px; height: 24px; }
.brand-lockup .name { font-family: var(--serif); font-size: 21px; letter-spacing: .16em; }
.brand-lockup .sub { font-size: 11px; letter-spacing: .34em; text-transform: uppercase; opacity: .66; }

.auth-quote { max-width: 460px; }
.auth-quote h1 { font-size: 40px; line-height: 1.32; letter-spacing: .02em; }
.auth-quote h1 span { color: #e5c48b; }
.auth-quote p { margin: 18px 0 0; color: rgba(244, 239, 226, .74); font-size: 14.5px; line-height: 1.85; }

.auth-stats { display: flex; gap: 42px; }
.auth-stats div { display: flex; flex-direction: column; gap: 2px; }
.auth-stats strong { font-family: var(--serif); font-size: 26px; color: #e5c48b; }
.auth-stats span { font-size: 12px; letter-spacing: .12em; opacity: .68; }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
  background: var(--surface);
}

.auth-card { width: 100%; max-width: 392px; }
.auth-card > .kicker {
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}
.auth-card h2 { font-size: 27px; margin-top: 6px; }
.auth-card > .hint { color: var(--muted); font-size: 13.5px; margin: 8px 0 24px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--paper-2);
  border-radius: 10px;
  margin-bottom: 24px;
}
.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  transition: all .16s ease;
}
.tabs button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .02em;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 97, 86, .12);
}
.field textarea { resize: vertical; min-height: 74px; }
.field .row-inline { display: flex; gap: 8px; }
.field .row-inline input { flex: 1; }

.form-note {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 14px;
  line-height: 1.7;
}
.form-note strong { color: var(--ink-soft); }

.msg {
  display: none;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  line-height: 1.6;
}
.msg.show { display: block; }
.msg.error { background: var(--danger-soft); color: var(--danger); border: 1px solid #ecd3cc; }
.msg.ok { background: var(--accent-soft); color: var(--accent-dark); border: 1px solid #cfe0d9; }

.auth-foot {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}
.link-btn:hover { text-decoration: underline; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 253, 248, .92);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 26px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--accent), #1d3f38);
  color: #f2eddf;
  display: grid; place-items: center;
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text { font-family: var(--serif); font-size: 18px; letter-spacing: .14em; }

.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  transition: all .16s ease;
}
.nav a:hover { background: var(--paper-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 500; }

.userbox { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--accent-dark);
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta strong { font-size: 13.5px; font-weight: 500; }
.user-meta em { font-style: normal; font-size: 11.5px; color: var(--muted); }

/* ============ 页面骨架 ============ */
.page { max-width: 1240px; margin: 0 auto; padding: 30px 28px 64px; }

.page-head { margin-bottom: 22px; }
.page-head .kicker {
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-head h1 { font-size: 30px; margin-top: 4px; }
.page-head p { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

.rule {
  height: 1px;
  background: linear-gradient(90deg, var(--line-strong), transparent);
  margin: 22px 0;
}

/* ============ 搜索区 ============ */
.searchbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.searchbar select {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink-soft);
  outline: none;
  min-width: 116px;
}
.searchbar .grow { flex: 1; min-width: 200px; position: relative; }
.searchbar .grow input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.searchbar .grow input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 97, 86, .12); }
.searchbar .grow svg {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.searchbar .btn { height: 44px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 18px 0 6px; }
.filters .label { font-size: 12.5px; color: var(--muted); letter-spacing: .1em; margin-right: 2px; }
.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  padding: 5px 13px;
  border-radius: 99px;
  font-size: 13px;
  cursor: pointer;
  transition: all .16s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.result-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 20px 0 14px;
  font-size: 13px;
  color: var(--muted);
}
.result-meta strong { color: var(--ink); font-family: var(--serif); font-size: 15px; }

/* ============ 布局：主区 + 侧栏 ============ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 26px;
  align-items: start;
}

/* ============ 图书网格 ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 16px;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
.book-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.cover {
  position: relative;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  padding: 16px 18px;
  color: #fdf8ec;
  background: linear-gradient(135deg, var(--c1, #3d6b5f), var(--c2, #22463e));
  overflow: hidden;
}
.cover::after {
  content: "";
  position: absolute;
  left: 10px; top: 0; bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, .22);
}
.cover::before {
  content: "";
  position: absolute;
  right: -40px; bottom: -60px;
  width: 150px; height: 150px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .16);
}
.cover .cover-title {
  position: relative;
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.35;
  letter-spacing: .06em;
  max-height: 3.9em;
  overflow: hidden;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .18);
}

.book-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.book-title {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.4;
  margin: 0 0 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author { font-size: 13px; color: var(--ink-soft); margin: 0 0 6px; }
.book-meta { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.7; }
.book-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.pill-ok { background: var(--accent-soft); color: var(--accent-dark); border-color: #cfe0d9; }
.pill-out { background: var(--amber-soft); color: var(--amber); border-color: #ecd9b6; }
.pill-off { background: #f0eeea; color: #8a8378; border-color: #e2ddd3; }
.pill-admin { background: #e8eef7; color: #34557d; border-color: #cfdcee; }
.pill-user { background: #f1efea; color: #77706a; border-color: #e1dbd0; }

/* ============ 侧栏 ============ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-head h2 { font-size: 16px; }
.panel-head .count { font-size: 12px; color: var(--muted); }
.panel-body { padding: 14px 16px; }

.borrow-item {
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.borrow-item:last-child { border-bottom: 0; padding-bottom: 0; }
.borrow-item .bi-main { flex: 1; min-width: 0; }
.borrow-item .bi-title {
  font-family: var(--serif);
  font-size: 14.5px;
  display: block;
  margin-bottom: 2px;
}
.borrow-item .bi-meta { font-size: 11.5px; color: var(--muted); line-height: 1.7; }
.borrow-item .overdue { color: var(--danger); }

.empty {
  text-align: center;
  padding: 34px 16px;
  color: var(--muted);
  font-size: 13.5px;
}
.empty svg { width: 26px; height: 26px; opacity: .5; margin-bottom: 8px; }

/* ============ 管理页 ============ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .k { font-size: 12px; color: var(--muted); letter-spacing: .08em; }
.stat .v { font-family: var(--serif); font-size: 27px; margin-top: 2px; }
.stat .v small { font-size: 13px; color: var(--muted); font-family: var(--sans); margin-left: 4px; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table-tools {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.table-tools input {
  flex: 1;
  min-width: 180px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
}
.table-tools input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 97, 86, .1); }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  vertical-align: middle;
}
table.data th {
  font-weight: 500;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: .03em;
  background: #faf7f0;
  white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbf9f3; }
table.data .t-title { font-family: var(--serif); font-size: 14.5px; }
table.data .t-sub { font-size: 12px; color: var(--muted); }
table.data .actions { display: flex; gap: 6px; justify-content: flex-end; }

.table-scroll { overflow-x: auto; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(24, 22, 19, .42);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(20, 18, 16, .3);
}
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-head h3 { font-size: 18px; }
.modal-close {
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--paper-2); color: var(--ink); }
.modal-body { padding: 20px 22px; }
.modal-foot {
  padding: 14px 22px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ============ 提示条 ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 14px);
  background: #26231f;
  color: #f6f2e9;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 12px 30px rgba(20, 18, 16, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 90;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: #7f2f22; }
.toast-ok { background: #234b42; }

.loading {
  padding: 46px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  vertical-align: -3px;
  margin-right: 8px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 响应式 ============ */
@media (max-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { padding: 44px 40px; }
  .auth-quote h1 { font-size: 32px; }
}

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { padding: 34px 26px; gap: 26px; min-height: auto; }
  .auth-brand .auth-stats { display: none; }
  .auth-quote h1 { font-size: 26px; }
  .auth-quote p { display: none; }
  .auth-panel { padding: 34px 22px 52px; }

  .topbar-inner { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; flex: 0 0 100%; gap: 2px; overflow-x: auto; }
  .nav a { padding: 6px 12px; }
  .user-meta { display: none; }
  .page { padding: 22px 16px 56px; }
  .page-head h1 { font-size: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
  .cover { aspect-ratio: 4 / 3; padding: 12px; }
  .cover .cover-title { font-size: 16px; }
  .book-body { padding: 11px 12px 13px; }
  .book-title { font-size: 14.5px; }
  .searchbar { padding: 12px; }
  .searchbar select { min-width: 100px; }
  .form-grid { grid-template-columns: 1fr; }
  table.data th, table.data td { padding: 10px 12px; }
}
