:root {
  --ink: #16181d;
  --ink-soft: #3f4553;
  --muted: #6a7180;
  --line: #e4e7ec;
  --line-strong: #d3d8e0;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --accent: #0e6b5c;
  --accent-hover: #0b5548;
  --accent-soft: #e7f2ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

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

h1, h2, h3 { margin: 0; line-height: 1.3; letter-spacing: 0; }

.icon { flex: none; vertical-align: -2px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; word-break: break-all; }

/* ---------- chrome ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
}

.topnav { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.topnav a { color: var(--ink-soft); }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.link-btn:hover { color: var(--accent); }

.page { max-width: 1160px; margin: 0 auto; padding: 28px 20px 72px; }

.footer {
  border-top: 1px solid var(--line);
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.footer-dot { color: var(--line-strong); }

/* ---------- flashes ---------- */

.flashes { display: grid; gap: 8px; margin-bottom: 18px; }
.flash {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
}
.flash-success { border-color: #b7ded4; background: var(--accent-soft); color: #0a4a40; }
.flash-warn { border-color: #f2d9a8; background: #fdf5e6; color: #7a4b06; }
.flash-error { border-color: #f3c3bd; background: var(--danger-soft); color: #8a1c12; }

/* ---------- hero ---------- */

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.hero h1 { font-size: 26px; }
.hero-copy p { margin: 6px 0 0; color: var(--muted); max-width: 520px; }

.hero-metrics { display: flex; gap: 28px; }
.metric { display: flex; flex-direction: column; }
.metric-value { font-size: 20px; font-weight: 650; }
.metric-label { font-size: 12px; color: var(--muted); }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.toolbar-inline { border: 0; box-shadow: none; padding: 0; background: none; }

.field { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.field-search {
  flex: 1 1 240px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
}
.field-search input {
  flex: 1;
  border: 0;
  outline: none;
  padding: 9px 0;
  font: inherit;
  min-width: 0;
  background: none;
}

select, input[type="text"], input[type="password"], input[type="search"], textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 10px;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }

.field-col { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.field-col input, .field-col select, .field-col textarea { width: 100%; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 14px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.7; cursor: progress; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-large { padding: 11px 18px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.icon-btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.inline-form { display: inline; margin: 0; }

/* ---------- shelf ---------- */

.result-line { color: var(--muted); font-size: 14px; margin: 16px 0 12px; }

.shelf {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card-cover {
  display: block;
  aspect-ratio: 4 / 3;
  background: #eceef2;
  overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cover-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 40px;
  font-weight: 600;
  color: hsl(var(--hue, 200) 42% 28%);
  background: linear-gradient(150deg,
      hsl(var(--hue, 200) 60% 94%),
      hsl(calc(var(--hue, 200) + 28) 55% 88%));
}
.cover-fallback-lg { aspect-ratio: 3 / 4; border-radius: var(--radius); font-size: 64px; }

.card-body { padding: 12px 13px 13px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.card-title {
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.card-title:hover { color: var(--accent); }
.card-author { margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.card-foot {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
  line-height: 1.7;
  background: #f1f3f6;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0;
}
.badge-plain { text-transform: none; background: #f1f3f6; color: var(--muted); }
.badge-epub { background: #e3f2ef; color: #0a5c50; }
.badge-pdf { background: var(--danger-soft); color: #96231a; }
.badge-mobi, .badge-azw, .badge-azw3 { background: #e8edfd; color: #1e42a8; }
.badge-txt, .badge-md { background: #f2f4f7; color: #475467; }
.badge-docx, .badge-doc, .badge-rtf { background: #e6f0fb; color: #17458c; }
.badge-zip { background: #fdf1dd; color: #8a5a0b; }
.badge-fb2, .badge-djvu, .badge-cbz, .badge-cbr { background: #f3eafc; color: #6a2f9c; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 22px; font-size: 13px; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 52px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
}
.empty p { margin: 0; }
.empty h1 { font-size: 34px; color: var(--ink); }
.empty-tall { padding: 76px 20px; }

/* ---------- detail ---------- */

.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 16px; }

.detail {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.detail-cover img { width: 100%; height: auto; border-radius: 6px; display: block; border: 1px solid var(--line); }
.detail-title { font-size: 23px; margin-bottom: 6px; word-break: break-word; }
.detail-author { margin: 0 0 12px; color: var(--muted); }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.meta-list { margin: 16px 0 0; display: grid; gap: 6px; font-size: 13px; }
.meta-list > div { display: flex; gap: 12px; }
.meta-list dt { color: var(--muted); flex: 0 0 84px; margin: 0; }
.meta-list dd { margin: 0; color: var(--ink-soft); word-break: break-word; min-width: 0; }
.meta-list-tight { margin-top: 12px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 18px;
  box-shadow: var(--shadow);
}
.panel-title { font-size: 16px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head .panel-title { margin-bottom: 0; }
.prose { margin: 0; color: var(--ink-soft); white-space: pre-wrap; word-break: break-word; }

.shelf-compact { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }

/* ---------- admin ---------- */

.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; margin-bottom: 20px; }
.admin-head h1 { font-size: 22px; }
.admin-head p { margin: 6px 0 0; font-size: 14px; }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 88px;
  display: flex;
  flex-direction: column;
}
.stat-value { font-size: 18px; font-weight: 650; }
.stat-label { font-size: 12px; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
  padding: 30px 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fafbfc;
  cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type="file"] { display: none; }
.dropzone-icon { color: var(--accent); }
.dropzone-title { font-weight: 600; }
.dropzone-hint { font-size: 12px; color: var(--muted); }
.file-list { margin: 0; font-size: 13px; color: var(--accent); word-break: break-word; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.col-actions { width: 1%; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; align-items: center; }

.cell-title { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cell-title a { color: var(--ink); font-weight: 550; }
.thumb { width: 32px; height: 42px; object-fit: cover; border-radius: 3px; border: 1px solid var(--line); flex: none; }
.thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: hsl(var(--hue, 200) 42% 28%);
  background: hsl(var(--hue, 200) 55% 92%);
  border: 0;
}

.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 11px; }
.pill-on { background: var(--accent-soft); color: #0a4a40; }
.pill-off { background: #f2f4f7; color: var(--muted); }

/* ---------- edit ---------- */

.edit-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 22px; align-items: start; }
.edit-cover { display: flex; flex-direction: column; gap: 14px; }
.edit-cover img { width: 100%; border-radius: 6px; border: 1px solid var(--line); }
.edit-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

.danger-zone {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.danger-zone p { margin: 4px 0 0; font-size: 13px; }

/* ---------- auth ---------- */

.auth { display: flex; justify-content: center; padding: 56px 0; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}
.auth-title { font-size: 18px; display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.auth-card .muted { margin: 0 0 18px; font-size: 13px; }

@media (max-width: 760px) {
  .hero { align-items: flex-start; }
  .hero-metrics { gap: 20px; }
  .detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 190px; }
  .edit-layout { grid-template-columns: 1fr; }
  .edit-cover { max-width: 190px; }
  .page { padding: 20px 14px 56px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
  .card-foot { flex-direction: column; align-items: flex-start; gap: 6px; }
  .meta-list > div { flex-direction: column; gap: 2px; }
  .meta-list dt { flex: none; }
}
