:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #f9fbfa;
  --text: #17201e;
  --muted: #6b7a77;
  --line: #e3eae8;
  --primary: #0f766e;
  --primary-600: #0d655e;
  --primary-soft: #e6f4f1;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --rose: #b91c1c;
  --rose-soft: #fdeced;
  --blue: #1d4ed8;
  --blue-soft: #eaeffd;
  --violet: #6d28d9;
  --violet-soft: #f1ecfd;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .05), 0 4px 16px rgba(16, 40, 36, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); text-decoration: none; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo { font-size: 19px; font-weight: 600; letter-spacing: .06em; color: var(--primary); }
.tagline { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- 视图容器 ---------- */
.view {
  flex: 1;
  width: 100%; max-width: 1120px; margin: 0 auto;
  padding: 16px 16px 28px;
}

/* ---------- 页脚（备案号，合规要求：须链接到工信部）---------- */
.site-footer {
  width: 100%; max-width: 1120px; margin: 0 auto;
  text-align: center; font-size: 12px; line-height: 1.9;
  color: var(--muted);
  padding: 10px 16px calc(74px + env(safe-area-inset-bottom));
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer .police { margin-left: 8px; }
.view-title { font-size: 17px; font-weight: 600; margin: 4px 0 14px; display: flex; align-items: center; gap: 8px; }
.view-title .count { font-size: 13px; font-weight: 400; color: var(--muted); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 10px;
  font-size: 11px; color: var(--muted);
  transition: color .15s;
}
.tab .ico { font-size: 17px; line-height: 1; }
.tab.active { color: var(--primary); font-weight: 600; }
.tab.active .ico { transform: translateY(-1px); }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 14px; color: var(--text);
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-600); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--rose); border-color: var(--rose-soft); background: var(--rose-soft); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea { resize: vertical; min-height: 76px; }
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.pri-now { background: var(--rose-soft); border-color: transparent; color: var(--rose); }
.chip.pri-read { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip.pri-reading { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.chip.pri-plan { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.chip.pri-later, .chip.pri-never { background: #f1f3f2; border-color: transparent; color: var(--muted); }
.chip.pri-fav { background: var(--violet-soft); border-color: transparent; color: var(--violet); }

/* ---------- 筛选栏 ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-wrap .input { padding-left: 34px; }
.search-wrap::before {
  content: "⌕"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 16px; pointer-events: none;
}
.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .select { width: auto; min-width: 92px; padding: 7px 10px; font-size: 13px; flex-shrink: 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { padding: 7px 13px; font-size: 13px; color: var(--muted); background: transparent; }
.seg button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- 书籍卡片 ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.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, transform .12s;
}
.book-card:active { transform: scale(.985); }
.book-card .cover {
  aspect-ratio: 3/4; background: linear-gradient(160deg, #eef4f2, #e2ebe8);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-card .cover .no-cover {
  font-size: 26px; color: #b9c7c3; font-weight: 600; letter-spacing: .1em;
  writing-mode: vertical-rl; text-align: center; padding: 10px;
  max-height: 100%; overflow: hidden;
}
.book-card .badge {
  position: absolute; top: 7px; left: 7px;
  padding: 2px 7px; border-radius: 999px; font-size: 11px;
  background: rgba(255,255,255,.92); color: var(--primary); font-weight: 600;
}
.book-card .badge.ebook { color: var(--blue); }
.book-card .meta { padding: 9px 10px 11px; }
.book-card .t { font-size: 13.5px; font-weight: 500; line-height: 1.4; max-height: 2.8em; overflow: hidden; }
.book-card .a { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-card .tags { display: flex; gap: 4px; margin-top: 7px; flex-wrap: wrap; }

.book-list { display: flex; flex-direction: column; gap: 9px; }
.book-row {
  display: flex; gap: 11px; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px;
}
.book-row .thumb {
  width: 42px; height: 56px; border-radius: 6px; flex-shrink: 0;
  background: #e8efed; display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-size: 11px; color: #9fb0ac;
}
.book-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.book-row .body { flex: 1; min-width: 0; }
.book-row .t { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-row .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.book-row .chips { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }

/* ---------- 看板 ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 15px;
}
.card h3 { margin: 0 0 10px; font-size: 13.5px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.card .big { font-size: 30px; font-weight: 600; line-height: 1.15; letter-spacing: -.01em; }
.card .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat-row > div { flex: 1; min-width: 66px; }
.stat-row .v { font-size: 20px; font-weight: 600; }
.stat-row .l { font-size: 12px; color: var(--muted); }
.bar-list { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.bar-item { font-size: 13px; }
.bar-item .line { display: flex; justify-content: space-between; margin-bottom: 3px; color: var(--muted); font-size: 12.5px; }
.bar-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .5s ease; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* ---------- 表单页 / 详情 ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 12px; }

.detail-head { display: flex; gap: 14px; }
.detail-head .cover { width: 104px; flex-shrink: 0; }
.detail-head .cover img, .detail-head .cover .no-cover { width: 104px; height: 139px; object-fit: cover; border-radius: 8px; background: #e8efed; display: flex; align-items: center; justify-content: center; color: #9fb0ac; }
.detail-head h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.35; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 7px 12px; font-size: 13.5px; margin-top: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- 扫码 ---------- */
.scan-box { position: relative; background: #0d1512; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4/3; }
.scan-box video, .scan-box canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; left: 8%; right: 8%; top: 32%; height: 30%;
  border: 2px solid rgba(255,255,255,.9); border-radius: 10px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35);
  pointer-events: none;
}
.scan-hint { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.scan-msg { font-size: 13px; color: var(--muted); margin-top: 10px; min-height: 20px; }
.manual-isbn { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- 模态 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(12, 24, 21, .42);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-mask.hidden, .toast.hidden { display: none; }
.modal {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) {
  .modal-mask { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; gap: 10px; margin-top: 16px; }
.modal-foot .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: rgba(23, 32, 30, .93); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  z-index: 90; max-width: 86vw; text-align: center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 空状态 / 加载 ---------- */
.empty { text-align: center; padding: 52px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .5; }
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--line);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.flex { display: flex; } .between { justify-content: space-between; } .center { align-items: center; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

@media (min-width: 720px) {
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); }
  .view { padding-bottom: 40px; }
}

/* ---------- 顶栏用户 ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; }

.userbtn {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 11px 4px 4px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
}
.userbtn:active { transform: scale(.98); }
.uavatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.uname {
  font-size: 13px; color: var(--text);
  max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 登录 / 初始化 ---------- */
.auth-layer {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--bg); overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 360px; margin: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px 18px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { font-size: 26px; font-weight: 600; letter-spacing: .14em; color: var(--primary); }
.auth-tag { font-size: 12.5px; color: var(--muted); margin-top: 5px; letter-spacing: .04em; }
.auth-hint {
  font-size: 12.5px; color: var(--muted); line-height: 1.75;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 16px;
}
.auth-err { color: var(--rose); font-size: 13px; min-height: 19px; margin: 2px 0 6px; }
.auth-foot { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 18px; line-height: 1.8; }
.auth-foot a { color: var(--muted); text-decoration: none; }
.auth-foot a:hover { text-decoration: underline; }
/* 登录页对外可见的网站说明（备案审核人员打开首页即可读到） */
.auth-note {
  font-size: 12px; color: var(--muted); line-height: 1.75; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 16px;
}

@media (max-width: 430px) {
  .uname { display: none; }
  .userbtn { padding: 3px; }
}
