/* ---------- Design tokens ---------- */
:root {
  --bg: #EAE2CE;
  --surface: #F2ECDA;
  --surface-raised: #FBF8EE;
  --ink: #2A2117;
  --ink-muted: #6E6047;
  --accent: #7A2E2E;
  --accent-ink: #F5EFE0;
  --gold: #A6822F;
  --line: #D9CBA6;
  --shadow: 42, 33, 23;

  --font-serif: "PT Serif", Georgia, serif;
  --font-sans: "Inter", -apple-system, "Segoe UI", sans-serif;

  --radius-sm: 4px;
  --radius-md: 8px;
  --transition: 160ms ease;
}

html[data-theme="dark"] {
  --bg: #1E1710;
  --surface: #271F15;
  --surface-raised: #332818;
  --ink: #ECE2CB;
  --ink-muted: #B7A987;
  --accent: #C1614C;
  --accent-ink: #1E1710;
  --gold: #D4AF37;
  --line: #3C2F1E;
  --shadow: 0, 0, 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 96px;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
}

.brand-mark {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 30px;
  line-height: 1;
  text-decoration: none;
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-muted);
}

.search-wrap {
  flex: 1;
  min-width: 220px;
}

.search-wrap input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

.search-wrap input:focus-visible {
  border-color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
}

.user-name {
  font-weight: 600;
}

.text-link {
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.text-link:hover {
  color: var(--ink);
  border-bottom-color: var(--ink-muted);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

.icon-btn:hover {
  background: var(--surface);
}

#theme-toggle .theme-icon-dark { display: none; }
html[data-theme="dark"] #theme-toggle .theme-icon-dark { display: inline; }
html[data-theme="dark"] #theme-toggle .theme-icon-light { display: none; }

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-accent:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-ghost:hover { background: var(--surface); }

.btn-danger {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Stats & filters ---------- */
.stats-strip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px 0;
  color: var(--ink-muted);
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}

.stats-strip strong { color: var(--ink); }
.stats-strip .dot { opacity: .5; }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0 4px;
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.chip:hover { border-color: var(--ink-muted); }

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Shelves ---------- */
.shelves {
  display: flex;
  flex-direction: column;
  gap: 44px;
  padding-top: 32px;
}

.shelf-title {
  display: flex;
  align-items: baseline;
  margin: 0 0 18px;
  gap: 16px;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 20px;
}

.shelf-title::after {
  content: "";
  order: 1;
  flex: 1;
  border-bottom: 1px solid var(--line);
  transform: translateY(-6px);
}

.shelf-name { order: 0; white-space: nowrap; }

.shelf-count {
  order: 2;
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 13px;
  color: var(--ink-muted);
  white-space: nowrap;
}

.shelf-books {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 22px 18px;
}

/* ---------- Book card ---------- */
.book-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  width: 100%;
}

.book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-raised);
  box-shadow: 3px 6px 14px rgba(var(--shadow), 0.28);
  transition: box-shadow var(--transition), transform var(--transition);
}

.book-card:hover .book-cover,
.book-card:focus-visible .book-cover {
  box-shadow: 4px 10px 20px rgba(var(--shadow), 0.34);
  transform: translateY(-3px);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-cover-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-muted);
}

.book-cover-ribbon {
  position: absolute;
  top: 0;
  left: 16px;
  width: 14px;
  height: 38px;
  background: var(--gold);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
  box-shadow: 1px 2px 4px rgba(var(--shadow), 0.3);
}

.book-title {
  margin-top: 10px;
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.book-status {
  font-size: 11px;
  color: var(--gold);
  margin-top: 4px;
  font-weight: 500;
}

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  color: var(--ink-muted);
  padding: 64px 16px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 17px;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(var(--shadow), 0.35);
  transition: transform var(--transition);
}

.fab:hover { transform: scale(1.06); }

/* ---------- Scrim ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(var(--shadow), 0.45);
  z-index: 40;
}

/* ---------- Side panel ---------- */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--surface-raised);
  box-shadow: -8px 0 30px rgba(var(--shadow), 0.25);
  transform: translateX(100%);
  transition: transform 220ms ease;
  z-index: 50;
  overflow-y: auto;
}

.side-panel.is-open { transform: translateX(0); }

.side-panel-inner { padding: 28px 26px 40px; }

.side-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.side-panel-header h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  margin: 0;
}

.side-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- Form fields ---------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink-muted);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="date"],
.field input[type="number"],
.field input[type="file"],
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

.field textarea { resize: vertical; }

.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.field-narrow { max-width: 110px; }

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-checkbox label { margin: 0; font-weight: 500; color: var(--ink); }
.field-checkbox input { width: auto; }

.form-error {
  color: var(--accent);
  font-size: 13px;
  margin: -6px 0 14px;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(var(--shadow), 0.45);
  padding: 20px;
}

.modal.is-open { display: flex; }

.modal-card {
  position: relative;
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  padding: 30px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(var(--shadow), 0.35);
}

.modal-card h2 {
  font-family: var(--font-serif);
  margin: 0 0 4px;
  font-size: 22px;
}

.modal-hint {
  color: var(--ink-muted);
  font-size: 13px;
  margin: 0 0 18px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.detail-card { max-width: 640px; }

.detail-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
}

.detail-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 3px 6px 14px rgba(var(--shadow), 0.28);
}

.detail-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.detail-info h2 {
  font-family: var(--font-serif);
  margin: 0 0 4px;
  font-size: 22px;
}

.detail-author { color: var(--ink-muted); margin: 0 0 14px; }

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
  margin: 0 0 14px;
}

.detail-meta dt { color: var(--ink-muted); }
.detail-meta dd { margin: 0; }

.detail-comments {
  font-size: 13.5px;
  color: var(--ink);
  white-space: pre-wrap;
  margin: 0 0 18px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 520px) {
  .detail-layout { grid-template-columns: 120px 1fr; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 80;
  box-shadow: 0 10px 26px rgba(var(--shadow), 0.35);
}

.toast.is-error { background: var(--accent); color: var(--accent-ink); }

/* ---------- Admin page ---------- */
.admin-page { padding-top: 32px; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.admin-table-actions form { display: flex; gap: 8px; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .page { padding: 0 16px 96px; }
  .site-header { padding-top: 20px; gap: 14px; }
  .brand-mark { font-size: 24px; }
  .shelf-books { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 16px 12px; }
}
