:root {
  --primary: #1E3A8A;
  --primary-hover: #1E40AF;
  --primary-soft: #EEF2FF;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --danger: #B91C1C;
  --success: #15803D;
  --warn: #C2410C;
  --sidebar-w: 248px;
  --sidebar-collapsed-w: 72px;
  --header-h: 60px;
  --radius: 10px;
  --space: 24px;
  --font-sans: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-num: "Inter", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}
html.dark {
  --bg: #0B1220;
  --card: #111827;
  --border: #1F2937;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --primary-soft: rgba(30, 58, 138, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}

/* 全局数字 / 时间 / IP：强制 Inter */
.num,
.stat-value,
.bar-count,
input[type="number"],
input[type="date"],
input[type="time"],
.table td.num,
.table th.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

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

.icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 22px; height: 22px; }

/* ===== Shell ===== */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 35;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}
/* 仅在 sidebar-ready 后启用宽度过渡（避免页面跳转首屏闪动） */
html.sidebar-ready .sidebar {
  transition: width 0.22s ease;
}

.sidebar-brand {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-mark .icon { color: #fff; }
.brand-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-toggle {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  padding: 0 10px;
}
.sidebar-toggle:hover {
  color: var(--text);
  background: var(--bg);
  border-color: #CBD5E1;
}
.sidebar-toggle .toggle-label { white-space: nowrap; }
.collapse-icon { transition: transform 0.22s ease; }

/* Collapsed state */
.app.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-w); }
.app.sidebar-collapsed .brand-text,
.app.sidebar-collapsed .nav-label,
.app.sidebar-collapsed .toggle-label { display: none; }
.app.sidebar-collapsed .sidebar-nav a {
  justify-content: center;
  padding: 0;
}
.app.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
}
.app.sidebar-collapsed .sidebar-foot { padding: 12px 8px; }
.app.sidebar-collapsed .collapse-icon { transform: rotate(180deg); }

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.header {
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 12px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-collapse {
  display: inline-flex;
}

.sys-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.header-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: 8px;
}
.header-search .search-ico {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}
.header-search input {
  width: min(360px, 36vw);
  margin: 0;
  padding: 0 14px 0 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--bg);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.user-name {
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  padding: 28px 32px 48px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Page ===== */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.page-sub {
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
}
.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.export-menu {
  position: relative;
  display: inline-flex;
}
.export-menu > .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.export-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.7;
  margin-left: 2px;
}
.export-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 168px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}
.export-dropdown[hidden] { display: none !important; }
.export-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.export-item:hover {
  background: var(--bg);
  text-decoration: none;
}
.export-item .icon { opacity: 0.85; }

.section {
  margin-bottom: 28px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.card + .card { margin-top: 20px; }
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-body { padding-top: 4px; }

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  min-height: 88px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
  border-color: #CBD5E1;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon .icon { width: 20px; height: 20px; }
.stat-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.stat-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.2;
}
.stat-value {
  font-family: var(--font-num);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  min-width: 640px;
}
.table th,
.table td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: transparent;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(241, 245, 249, 0.7); }
html.dark .table tr:hover td { background: rgba(30, 41, 59, 0.45); }

/* 键值表（设置 / 详情）：无强制最小宽度，适配手机 */
.table-kv {
  min-width: 0 !important;
  table-layout: fixed;
}
.table-kv th {
  width: 30%;
  max-width: 120px;
  white-space: normal;
  vertical-align: top;
  color: var(--muted);
  font-weight: 500;
}
.table-kv td {
  width: 70%;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.table-kv th,
.table-kv td {
  padding: 12px 10px;
}

/* 表格复选框列对齐 */
.td-check {
  width: 44px;
  min-width: 44px;
  max-width: 48px;
  padding-left: 14px !important;
  padding-right: 8px !important;
  text-align: center !important;
  vertical-align: middle !important;
}
.td-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  vertical-align: middle;
  accent-color: var(--primary);
  cursor: pointer;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.cell-pinyin,
.cell-classno,
.cell-cardno {
  font-family: var(--font-num);
  letter-spacing: 0.02em;
  white-space: nowrap;
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 自定义下拉（替代原生 select，移动端高度一致） */
select.ns-native.js-select,
select.js-select.ns-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.ns {
  position: relative;
  width: 100%;
  margin-bottom: 16px;
}
.ns-toolbar {
  width: auto;
  min-width: 132px;
  margin-bottom: 0;
}
.ns-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  box-sizing: border-box;
  text-align: left;
}
.ns-toolbar .ns-trigger {
  height: 38px;
  min-height: 38px;
  font-size: 14px;
}
.ns-trigger:hover { border-color: #cbd5e1; }
.ns.is-open .ns-trigger {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}
.ns-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ns-caret {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.ns.is-open .ns-caret { transform: rotate(180deg); }
.ns-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 55;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}
.ns-menu[hidden] { display: none !important; }
.ns-option {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ns-option:hover,
.ns-option.is-active {
  background: var(--bg);
}
.ns-option.is-active {
  color: var(--primary);
  font-weight: 600;
}
.ns-option.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
html.dark .ns-menu {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

/* 自定义文件选择 */
.file-field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin-bottom: 10px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-sizing: border-box;
}
.toolbar .ns,
.batch-actions .ns {
  margin-bottom: 0;
}
.file-field-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  opacity: 0 !important;
}
.file-field-btn {
  flex-shrink: 0;
  height: 34px;
  min-height: 34px;
  padding: 0 12px;
  gap: 6px;
}
.file-field-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cover-preview {
  display: block;
  max-height: 100px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.cover-preview[hidden] { display: none !important; }

.books-batch-bar,
.batch-bar {
  align-items: center;
  gap: 12px 16px;
}
.batch-check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  font-size: 14px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  margin: 0;
}
/* 覆盖全局 input 的 width:100% / padding，避免复选框错位 */
.batch-check-label input[type="checkbox"],
.td-check input[type="checkbox"],
.toolbar input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  max-width: 16px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 3px;
  box-shadow: none !important;
  background: transparent !important;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
}
.batch-count {
  display: inline-flex;
  align-items: center;
  height: 36px;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}
.batch-actions .toolbar-status {
  min-width: 140px;
}

.check-placeholder {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: middle;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  opacity: 0.55;
  box-sizing: border-box;
}

.log-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.log-card-head {
  margin-bottom: 14px;
}
.log-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  font-family: var(--font-num);
}
.log-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}
.log-detail {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-logs td {
  white-space: nowrap;
}
.table-logs td.log-detail {
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
  text-decoration: none;
  background: var(--bg);
  border-color: #CBD5E1;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-danger {
  color: var(--danger);
  border-color: #FECACA;
  background: #fff;
}
.btn-danger:hover { background: #FEF2F2; }
.btn-ghost {
  border: none;
  background: transparent;
  color: var(--muted);
}
.btn-block { width: 100%; }
.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
  gap: 6px;
}
.btn .icon { width: 16px; height: 16px; }

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
}
.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
  text-decoration: none;
}

/* Forms：控件 ≥16px，避免 iOS/PWA 聚焦时自动放大 */
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  touch-action: manipulation;
}
a, button, .btn, .icon-btn, .entry-mode, .book-picker-item {
  touch-action: manipulation;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}
label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
}
.form-grid .form-span {
  grid-column: 1 / -1;
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
  padding-top: 8px;
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar .grow {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}
.toolbar-status {
  width: auto;
  min-width: 140px;
  margin-bottom: 0;
}
.toolbar select,
.toolbar input {
  margin-bottom: 0;
}
.toolbar .btn { margin: 0; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
  max-width: 100%;
}
.tabs .btn {
  border: none;
  background: transparent;
  min-height: 36px;
}
.tabs .btn.btn-primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge-ok { background: #F0FDF4; color: var(--success); }
.badge-warn { background: #FFF7ED; color: var(--warn); }
.badge-danger { background: #FEF2F2; color: var(--danger); }

.alert {
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.6;
}
.alert-success {
  background: #F0FDF4;
  color: #166534;
  border: 1px solid #BBF7D0;
}
.alert-error {
  background: #FEF2F2;
  color: #991B1B;
  border: 1px solid #FECACA;
}
.error { color: var(--danger); font-size: 13px; margin-bottom: 8px; }

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo .icon { width: 28px; height: 28px; color: #fff; }
.login-brand h1 { font-size: 22px; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 13px; margin-top: 6px; }

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 18px;
  padding: 16px 12px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  gap: 12px;
  flex-wrap: wrap;
}
.pager-info {
  min-width: 4.5em;
  text-align: center;
}

.cover-thumb {
  width: 40px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
}
/* ===== 扫码工作室（Quagga2） ===== */
.scan-studio {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}
.scan-studio-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #F8FAFC 0%, #fff 100%);
}
html.dark .scan-studio-head {
  background: linear-gradient(180deg, #111827 0%, var(--card) 100%);
}
.scan-studio-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
}
.scan-studio-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.scan-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.scan-switch input { margin: 0; width: auto; }

.scan-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 420px;
  background:
    radial-gradient(ellipse at center, #1e293b 0%, #0f172a 70%);
  overflow: hidden;
}
.scan-viewport {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.scan-viewport video,
.scan-viewport canvas,
.scan-engine-video {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  border: 0 !important;
  background: #0f172a;
}
.scan-viewport canvas.drawingBuffer {
  display: none !important;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.scan-frame {
  position: relative;
  width: min(94%, 560px);
  height: 52%;
  min-height: 140px;
  max-height: 240px;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.48);
}
.scan-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid #F8FAFC;
  border-radius: 3px;
}
.scan-corner.tl { left: -1px; top: -1px; border-right: 0; border-bottom: 0; }
.scan-corner.tr { right: -1px; top: -1px; border-left: 0; border-bottom: 0; }
.scan-corner.bl { left: -1px; bottom: -1px; border-right: 0; border-top: 0; }
.scan-corner.br { right: -1px; bottom: -1px; border-left: 0; border-top: 0; }
.scan-laser {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  top: 20%;
  background: linear-gradient(90deg, transparent, #38BDF8, transparent);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.8);
  animation: scanLaser 2.2s ease-in-out infinite;
}
@keyframes scanLaser {
  0%, 100% { top: 18%; opacity: 0.35; }
  50% { top: 78%; opacity: 1; }
}
.scan-overlay-tip {
  font-size: 12px;
  color: rgba(248, 250, 252, 0.9);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}
.scan-stage:not(.is-live) .scan-laser { display: none; }

.scan-idle {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #CBD5E1;
  background: rgba(15, 23, 42, 0.35);
}
.scan-idle[hidden] { display: none !important; }
.scan-idle-ico {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #E2E8F0;
}
.scan-idle p {
  font-size: 13px;
  color: #94A3B8;
}

.scan-status {
  margin: 0;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font-num);
  min-height: 42px;
  display: flex;
  align-items: center;
}
.scan-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 14px;
  align-items: center;
}
.scan-photo-btn {
  margin: 0;
  cursor: pointer;
}
.scan-photo-btn input {
  display: none;
}
.scan-main-btn { min-width: 120px; }

.scan-pending {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 12px 16px;
  background: #EEF2FF;
  border-top: 1px solid var(--border);
}
html.dark .scan-pending { background: rgba(30, 58, 138, 0.28); }
.scan-pending[hidden] { display: none !important; }
.scan-pending-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.scan-pending-main strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scan-pending-isbn {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-num);
}

/* 旧扫码样式兼容清理 */
.scan-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0F172A;
  min-height: 240px;
}
.scan-opt { display: none; }
.barcode-scan-wrap, .barcode-scan-shell, .scan-guide, .scan-video { display: none !important; }

#qr-reader__dashboard_section,
#qr-reader__dashboard_section_csr,
#qr-reader__header_message {
  display: none !important;
}
.ocr-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
  align-items: stretch;
}
.grid-2 > .card {
  height: 100%;
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

/* ===== 设置页 ===== */
.settings-page {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1080px;
}
/* 覆盖全局 .card + .card 的 margin-top，避免双卡片错位并压住下方 */
.settings-page .card + .card,
.settings-top > .card {
  margin-top: 0;
}
.settings-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: stretch;
}
.settings-card {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* 由 grid stretch 拉齐高度，勿再用 height:100% + 外边距 */
  height: auto;
  min-height: 100%;
  align-self: stretch;
  box-sizing: border-box;
}
.settings-card-wide {
  width: 100%;
  margin-top: 0;
}
.settings-card-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.settings-card-head-main { flex: 1; min-width: 0; }
.settings-ico {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings-ico .icon { width: 20px; height: 20px; }
.settings-card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--text);
}
.settings-card-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.settings-status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}
.settings-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  white-space: nowrap;
}
.settings-status .icon { width: 14px; height: 14px; }
.settings-status.is-on {
  color: var(--success);
  border-color: rgba(21, 128, 61, 0.28);
  background: rgba(21, 128, 61, 0.08);
}
.settings-status.is-off {
  color: var(--muted);
}
.settings-form {
  padding: 18px 22px 20px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.settings-field { margin-bottom: 4px; }
.settings-field label,
.settings-form label {
  display: block;
}
.settings-form input {
  margin-bottom: 14px;
}
.settings-form-foot {
  display: flex;
  justify-content: flex-start;
  margin-top: auto;
  padding-top: 8px;
}
.settings-form-foot .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.settings-meta {
  margin: 0;
  padding: 8px 8px 12px;
  flex: 1 1 auto;
  min-height: 0;
}
.settings-meta-row {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  gap: 12px 16px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 8px;
}
.settings-meta-row:nth-child(odd) {
  background: var(--bg);
}
.settings-meta-row dt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.settings-meta-ico {
  width: 16px;
  height: 16px;
  color: var(--primary);
  opacity: 0.85;
}
.settings-meta-row dd {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
}
.settings-user { font-weight: 600; margin-right: 8px; }
.settings-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid transparent;
}
.settings-tips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 22px 0;
}
.settings-tip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.settings-tip:hover {
  border-color: #CBD5E1;
  background: var(--card);
  text-decoration: none;
}
html.dark .settings-tip:hover { border-color: #374151; }
.settings-tip-ico {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings-tip-ico .icon { width: 18px; height: 18px; }
.settings-tip-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-tip-body strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.settings-tip-body span {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.settings-tip-ext {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
}
.settings-block {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.settings-block:last-of-type { margin-bottom: 8px; }
.settings-block .form-grid { gap: 0 16px; }
.settings-block input { background: var(--card); }
.settings-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 14px;
}
.settings-block-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.settings-block-head h3 .icon { width: 16px; height: 16px; color: var(--primary); }
.settings-block-head span {
  font-size: 12px;
  color: var(--muted);
}
.settings-card > .alert {
  margin: 16px 22px 0;
}
.settings-test {
  margin: 0 22px 22px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.settings-test-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}
.settings-test-bar .grow {
  flex: 1;
  min-width: 180px;
  margin: 0;
  background: var(--card);
}
.settings-test-bar .btn {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.grid-2 > .card .card-body,
.grid-2 > .card .chart-box,
.grid-2 > .card .empty-panel {
  flex: 1;
}
.chart-box {
  min-height: 280px;
  width: 100%;
}
.empty-panel {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.empty-panel .icon { width: 28px; height: 28px; opacity: 0.55; }

.tag-chip {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
  line-height: 1.2;
}
.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 图书表单标签多选 */
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 20px;
}
.tag-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text);
  user-select: none;
}
.tag-check:hover { border-color: #CBD5E1; background: var(--card); }
.tag-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.tag-check.is-on {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

/* 颜色选择器 */
.color-field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
input[type="color"].color-input {
  width: 48px;
  height: 40px;
  max-width: 48px;
  padding: 3px;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.color-hex {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 分类管理：树形卡片列表（手机友好） */
.cat-card-head {
  flex-wrap: wrap;
  gap: 10px 16px;
}
.cat-toolbar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cat-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-children {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-group.is-collapsed .cat-children {
  display: none;
}
.cat-group.is-collapsed .cat-toggle-ico {
  transform: rotate(-90deg);
}
.cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.cat-item.is-child {
  margin-left: 18px;
  background: var(--card);
}
.cat-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}
.cat-check input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  max-width: 16px !important;
  padding: 0 !important;
  margin: 0 !important;
  accent-color: var(--primary);
  cursor: pointer;
}
.cat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.cat-toggle:hover {
  color: var(--primary);
  border-color: var(--primary);
}
.cat-toggle-ico {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}
.cat-toggle-spacer {
  width: 28px;
  flex-shrink: 0;
}
.cat-item-main {
  min-width: 0;
  flex: 1;
}
.cat-item-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}
.cat-item-branch {
  color: var(--muted);
  margin-right: 4px;
  font-weight: 400;
}
.cat-item-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.cat-item-actions {
  flex-shrink: 0;
}
.log-toolbar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.renew-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.renew-presets .btn {
  min-width: 64px;
}

/* 表格行操作按钮对齐 */
.table th,
.table td {
  vertical-align: middle;
}
.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  vertical-align: middle;
}
.row-actions > form {
  display: inline-flex;
  margin: 0;
}
.row-actions .btn,
.row-actions .icon-btn {
  margin: 0;
}
.row-actions .btn-sm {
  min-height: 32px;
  min-width: 72px;
  justify-content: center;
}

/* 录入方式按钮 */
.entry-modes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.entry-mode {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.entry-mode:hover {
  border-color: #CBD5E1;
  background: var(--card);
}
.entry-mode.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.entry-mode-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.entry-mode.active .entry-mode-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.entry-mode-desc {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.4;
}
.entry-mode.active .entry-mode-desc { color: var(--primary); opacity: 0.85; }

/* ISBN 内置数字键盘（手机 / iPad）靠右 */
.isbn-numpad {
  margin-top: 12px;
  margin-left: auto;
  margin-right: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(360px, 100%);
  max-width: 360px;
}
.isbn-numpad[hidden] { display: none !important; }
.isbn-numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.np-key {
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.np-key:active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.np-key.np-muted {
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
}
.np-key.np-ok {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.np-key.np-ok:active {
  background: var(--primary-hover);
  color: #fff;
}
.isbn-numpad-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

@media (min-width: 901px) and (pointer: fine) {
  .isbn-numpad { display: none !important; }
}

/* 弹窗 */
.modal-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 60;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask.is-open { display: flex; }
.modal-panel {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

/* 内置确认 / 提示 / 输入弹窗（无渐变） */
.dlg-mask {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
}
.dlg-mask.is-open,
.dlg-mask:not([hidden]) {
  display: flex;
}
.dlg-mask[hidden] { display: none !important; }
body.dlg-open { overflow: hidden; }
.dlg-panel {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
  padding: 22px 22px 18px;
  animation: dlg-in 0.16s ease-out;
}
@keyframes dlg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.dlg-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.dlg-ico {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
}
.dlg-ico.is-warn {
  color: #b45309;
  background: rgba(180, 83, 9, 0.08);
  border-color: rgba(180, 83, 9, 0.22);
}
.dlg-ico.is-danger {
  color: var(--danger);
  background: rgba(185, 28, 28, 0.08);
  border-color: rgba(185, 28, 28, 0.22);
}
.dlg-ico.is-info {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: rgba(30, 58, 138, 0.18);
}
.dlg-ico-svg { width: 20px; height: 20px; }
.dlg-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.dlg-msg {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.dlg-msg[hidden] { display: none !important; }
.dlg-field { margin-bottom: 16px; }
.dlg-field[hidden] { display: none !important; }
.dlg-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.dlg-input {
  width: 100%;
  margin: 0 !important;
  box-sizing: border-box;
}
.dlg-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--danger);
}
.dlg-hint[hidden] { display: none !important; }
.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.dlg-actions .btn {
  min-width: 88px;
  justify-content: center;
}
html.dark .dlg-panel {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
html.dark .dlg-mask {
  background: rgba(0, 0, 0, 0.55);
}
.modal-panel .card-title { margin-top: 0; }
.modal-panel.modal-book {
  max-width: 760px;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 900px);
  overflow: hidden;
}
.modal-book-head {
  flex-shrink: 0;
  margin: 0;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-book-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.modal-book-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 22px 8px;
  -webkit-overflow-scrolling: touch;
}
.modal-book-body .form-grid { margin-bottom: 4px; }
.modal-book-body label { margin-top: 8px; }
.modal-book-foot {
  flex-shrink: 0;
  margin: 0;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 -6px 16px rgba(15, 23, 42, 0.04);
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.modal-book-foot.form-actions {
  margin-top: 0;
  padding-top: 12px;
}

.cell-category {
  max-width: 128px;
  width: 128px;
  overflow: hidden;
}
.cat-pill {
  display: inline-block;
  box-sizing: border-box;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.cat-pill.is-empty {
  color: var(--muted);
  background: var(--bg);
  border-color: var(--border);
  font-weight: 400;
}
html.dark .cat-pill {
  color: #93c5fd;
  background: rgba(30, 58, 138, 0.35);
  border-color: rgba(147, 197, 253, 0.25);
}
html.dark .cat-pill.is-empty {
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}
.cell-title {
  max-width: 200px;
  width: 200px;
  overflow: hidden;
}
.book-title-link {
  display: block;
  font-weight: 600;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: keep-all;
}
a.book-title-link:hover { color: var(--primary); }
.cell-status {
  width: 1%;
  white-space: nowrap;
}
.cell-muted {
  color: var(--muted);
  font-size: 13px;
}
.cell-author {
  color: var(--muted);
  font-size: 13px;
  max-width: 260px;
  min-width: 120px;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: break-word;
  line-height: 1.4;
}
.cell-isbn {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}
.input-author {
  min-height: 64px;
  resize: vertical;
  line-height: 1.45;
  margin-bottom: 16px;
}
.book-edit-form {
  padding: 0;
  overflow: visible;
}
.book-edit-body {
  padding: 20px 22px 12px;
}
.book-edit-foot {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  margin: 0;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.06);
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.entry-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}
.entry-toast[hidden] { display: none !important; }
.entry-toast.is-ok { border-color: #86efac; }
.entry-toast.is-err { border-color: #fca5a5; }

.borrow-lend-card .card-title { margin-bottom: 16px; }
.borrow-lend-grid {
  display: grid;
  grid-template-columns: 1.5fr 1.1fr minmax(150px, 0.9fr) auto;
  gap: 14px 16px;
  align-items: end;
}
.borrow-lend-grid > div { min-width: 0; }
.borrow-lend-grid label {
  display: block;
  margin-bottom: 6px;
  min-height: 20px;
  line-height: 1.25;
}
.borrow-lend-grid input,
.borrow-lend-grid select {
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.borrow-due {
  min-width: 0;
  max-width: 100%;
}
.borrow-due label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.borrow-due input[type="date"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  /* 避免部分手机原生 date 控件按内容撑破容器 */
  -webkit-appearance: none;
  appearance: none;
  line-height: 1.25;
  height: 44px;
  min-height: 44px;
}
.borrow-due input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}
.borrow-lend-actions {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding-top: 0;
  min-height: 44px;
}
.borrow-lend-actions .btn {
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
}
.book-picker { position: relative; }
.book-picker-field {
  display: flex;
  gap: 8px;
  align-items: stretch;
  min-height: 44px;
  height: 44px;
}
.book-picker-input {
  flex: 1;
  margin-bottom: 0 !important;
  height: 44px !important;
  min-height: 44px !important;
  box-sizing: border-box;
}
.book-picker-input[hidden] { display: none !important; }
.book-picker-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  padding: 0 8px 0 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-sizing: border-box;
}
.book-picker-chip[hidden] { display: none !important; }
.book-picker-chip-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0;
  overflow: hidden;
}
.book-picker-chip-text strong {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-picker-chip-text span {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-picker-chip-clear {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.book-picker-chip-clear:hover {
  background: var(--bg);
  color: var(--text);
}
html.dark .book-picker-chip {
  background: rgba(255,255,255,0.04);
}
.book-picker-clear {
  flex-shrink: 0;
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  font-weight: 500;
  color: var(--muted);
}
.book-picker-selected {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.book-picker-selected strong { font-size: 14px; }
.book-picker-selected span { font-size: 12px; color: var(--muted); }
.book-picker-selected[hidden] { display: none !important; }
.book-picker-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  max-height: 280px;
  overflow: auto;
  padding: 6px;
}
.book-picker-results[hidden] { display: none !important; }
.book-picker-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.book-picker-item:hover,
.book-picker-item:focus,
.book-picker-item.is-active {
  background: var(--bg);
  outline: none;
}
.book-picker-item.is-active {
  background: rgba(43, 67, 140, 0.1);
  box-shadow: inset 0 0 0 1px rgba(43, 67, 140, 0.22);
}
html.dark .book-picker-item.is-active {
  background: rgba(96, 165, 250, 0.12);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.28);
}
.book-picker-item-title {
  font-size: 14px;
  font-weight: 600;
}
.book-picker-item-meta {
  font-size: 12px;
  color: var(--muted);
}
.book-picker-empty {
  padding: 14px 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 960px) {
  .borrow-lend-grid {
    grid-template-columns: 1fr;
  }
  .borrow-lend-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
    padding-top: 0;
  }
  .borrow-lend-actions .btn { width: 100%; }
  .borrow-due label { white-space: normal; }
}
@media (max-width: 640px) {
  .scan-pending { flex-direction: column; align-items: stretch; }
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 14px;
}
.bar-row:last-child { margin-bottom: 0; }
.bar-label {
  width: 72px;
  flex-shrink: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
}
.bar-count {
  width: 36px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.desktop-only { display: flex; }
.mobile-only { display: none !important; }

#pwaUpdateBar {
  display: none;
  position: fixed;
  left: 24px;
  right: 24px;
  bottom: 24px;
  z-index: 99;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 14px 18px;
  border-radius: 10px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .settings-top { grid-template-columns: 1fr; }
  .settings-tips { grid-template-columns: 1fr; }
  .content { padding: 24px 20px 40px; }
  .entry-modes { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
  .header-collapse { display: none !important; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    transition: transform 0.22s ease;
    z-index: 50;
  }
  body.sidebar-mobile-open .sidebar { transform: translateX(0); }
  body.sidebar-mobile-open .sidebar-overlay { display: block; }
  .app.sidebar-collapsed .sidebar { width: var(--sidebar-w) !important; }
  .app.sidebar-collapsed .brand-text,
  .app.sidebar-collapsed .nav-label,
  .app.sidebar-collapsed .toggle-label { display: inline; }
  .app.sidebar-collapsed .sidebar-nav a {
    justify-content: flex-start;
    padding: 0 12px;
  }
  .sidebar-toggle { display: none; }
  .btn-text { display: none; }
  .content {
    padding: 16px 14px 32px;
    max-width: 100%;
  }
  .header { padding: 0 12px; }
  .header-search { display: flex !important; flex: 1; margin-left: 0; min-width: 0; }
  .header-search input { width: 100%; min-width: 0; }
  .sys-name { display: none; }
  .page-head {
    gap: 12px;
    margin-bottom: 20px;
  }
  .page-head h1 { font-size: 22px; word-break: break-word; overflow-wrap: break-word; }
  .page-actions {
    width: 100%;
  }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .tabs .btn { flex-shrink: 0; }
  .log-tabs { width: 100%; }
  .card {
    padding: 16px;
  }
  .card-title { margin-bottom: 14px; padding-bottom: 10px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .form-actions .btn { width: 100%; justify-content: center; }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }
  .toolbar .grow { min-width: 0; width: 100%; }
  .toolbar-status,
  .toolbar select,
  .toolbar input,
  .toolbar .btn {
    width: 100%;
    min-width: 0;
  }
  .settings-card-head {
    flex-wrap: wrap;
    padding: 16px 16px 14px;
  }
  .settings-status-group {
    width: 100%;
    justify-content: flex-start;
  }
  .settings-form,
  .settings-tips,
  .settings-test {
    padding-left: 16px;
    padding-right: 16px;
  }
  .settings-test { margin-left: 16px; margin-right: 16px; }
  .settings-meta-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .settings-test-bar { flex-direction: column; align-items: stretch; }
  .settings-test-bar .btn { width: 100%; justify-content: center; }
  .books-batch-bar {
    align-items: stretch;
  }
  .batch-actions {
    margin-left: 0;
    width: 100%;
  }
  .batch-actions .toolbar-status,
  .batch-actions .btn {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table {
    min-width: 720px;
    font-size: 13px;
    overflow-wrap: normal;
    word-break: normal;
  }
  .table th,
  .table td {
    padding: 10px 8px;
    overflow-wrap: normal;
    word-break: keep-all;
  }
  .table-kv { min-width: 0 !important; }
  .table-kv td {
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
  }
  .row-actions .btn-sm { min-width: 0; }
  .cat-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding-left: calc(12px + var(--depth, 0) * 14px);
  }
  .cat-item-actions {
    width: 100%;
    display: flex;
  }
  .cat-item-actions .btn,
  .cat-item-actions > form {
    flex: 1 1 0;
  }
  .cat-item-actions .btn {
    width: 100%;
    justify-content: center;
  }
  .modal-mask { padding: 10px; align-items: flex-end; }
  .modal-panel {
    max-height: min(92vh, 100%);
    border-radius: 12px 12px 0 0;
    max-width: none;
    width: 100%;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .modal-panel label {
    display: block;
    margin-top: 12px;
  }
  .modal-panel input,
  .modal-panel select,
  .modal-panel textarea {
    width: 100%;
    max-width: 100%;
    font-size: 16px; /* 避免 iOS 聚焦放大 */
  }
  .modal-panel.modal-book {
    max-height: min(94vh, 100%);
    border-radius: 14px 14px 0 0;
  }
  .scan-studio { padding: 12px; }
  .isbn-numpad-grid { gap: 8px; }
  .entry-modes { gap: 8px; }
  /* 仅说明/长链接折断，避免表格中文被拆成竖排 */
  .help-text, .muted-block {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .user-chip { display: none; }
  .entry-modes { grid-template-columns: 1fr; }
  .content { padding: 12px 10px 28px; }
  .card { padding: 14px 12px; border-radius: 10px; }
  .page-head h1 { font-size: 20px; }
  .page-sub { font-size: 13px; }
  .stat-value { font-size: 24px; }
  .table { min-width: 680px; }
  .table-kv th { width: 34%; max-width: 96px; font-size: 12px; }
  .table-kv td { font-size: 13px; }
  .page-actions .btn { font-size: 13px; padding: 8px 10px; }
  .export-dropdown { right: auto; left: 0; }
  .login-box { margin: 16px; padding: 24px 20px; width: auto; }
  .borrow-lend-actions { padding-top: 0; width: 100%; }
  .borrow-lend-actions .btn { width: 100%; }
  .detail-cover { max-width: 100%; height: auto; }
}

@media print {
  .sidebar, .header, .page-actions, .btn, #pwaUpdateBar { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
}
