:root {
  --primary: #2f6f64;
  --accent: #c47b38;
  --page-bg: #fbf7ef;
  --ink: #18231f;
  --muted: #69746f;
  --line: rgba(24, 35, 31, .12);
  --panel: #fffdf8;
  --soft: rgba(47, 111, 100, .10);
  --shadow: 0 18px 48px rgba(42, 34, 24, .11);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Tahoma, Arial, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(196, 123, 56, .16), transparent 34rem),
    linear-gradient(180deg, var(--page-bg), #fffaf1 46rem, #f7f5ee);
  color: var(--ink);
  line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem clamp(1rem, 4vw, 3rem);
  background: rgba(255, 253, 248, .86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.topbar-brand, .brand-mark, .admin-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
}
.topbar-brand img, .brand-mark img, .admin-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}
.topbar-brand span, .book-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
}
.admin-link {
  padding: .55rem .9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary);
  background: #fff;
}

.site-main {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.1rem 0 3rem;
}
.library-hero {
  padding: .75rem;
  margin-top: .5rem;
  background: rgba(255, 253, 248, .82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(42, 34, 24, .07);
}
.brand-mark small { display: block; color: var(--muted); line-height: 1.4; }
.eyebrow {
  color: var(--accent);
  font-weight: 700;
  margin: .2rem 0;
}
.hero-copy h1 {
  margin: 0;
  font-size: clamp(2rem, 9vw, 4.4rem);
  line-height: 1.08;
  letter-spacing: 0;
}
.hero-copy p:last-child {
  max-width: 54rem;
  margin: .75rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}
.search-panel {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}
.copy-label {
  display: block;
  margin-bottom: .45rem;
  color: var(--muted);
  font-weight: 700;
}
.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .65rem;
}
input, textarea, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .72rem .85rem;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; }
.search-row button, .btn {
  border: 0;
  border-radius: 8px;
  padding: .72rem 1rem;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  font-weight: 700;
}
.btn.primary, .search-row button {
  color: #fff;
  background: var(--primary);
}
.btn.ghost {
  color: var(--primary);
  background: #fff;
  border: 1px solid var(--line);
}
.btn.large { min-height: 52px; }
.category-strip {
  display: flex;
  gap: .55rem;
  overflow-x: auto;
  padding: 1rem .1rem;
  margin: .8rem 0;
  scrollbar-width: thin;
}
.category-strip a {
  flex: 0 0 auto;
  padding: .6rem .9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
}
.category-strip a.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.section-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.5rem 0 .8rem;
}
.section-head h2, .panel-head h2 { margin: 0; font-size: 1.3rem; }
.section-head span { color: var(--muted); }
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .9rem;
}
.book-card {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(42, 34, 24, .08);
  transition: transform .18s ease, box-shadow .18s ease;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.book-cover {
  aspect-ratio: 3 / 4;
  background: linear-gradient(145deg, var(--soft), rgba(196, 123, 56, .12));
}
.book-cover img, .detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-placeholder {
  width: 100%;
  height: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background:
    linear-gradient(160deg, rgba(47, 111, 100, .18), rgba(196, 123, 56, .16)),
    #fff8eb;
}
.cover-placeholder span {
  display: grid;
  place-items: center;
  width: 68px;
  height: 86px;
  border: 3px solid currentColor;
  border-radius: 6px;
}
.book-card-body { padding: .9rem; }
.book-category, .pill {
  display: inline-flex;
  width: fit-content;
  padding: .22rem .55rem;
  border-radius: 999px;
  color: var(--primary);
  background: var(--soft);
  font-size: .78rem;
  font-weight: 700;
}
.pill.warm { color: #8a4c18; background: rgba(196, 123, 56, .16); }
.book-card h3 {
  margin: .55rem 0 .35rem;
  font-size: 1rem;
  line-height: 1.35;
}
.book-card p {
  color: var(--muted);
  margin: 0;
  font-size: .9rem;
  min-height: 3.2rem;
}
.book-card-meta {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .8rem;
  color: var(--muted);
  font-size: .82rem;
}
.book-card-meta b { color: var(--accent); }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.empty-icon { font-size: 3rem; color: var(--primary); }
.back-link {
  display: inline-flex;
  margin: 1rem 0;
  color: var(--primary);
  font-weight: 700;
}
.book-detail {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: clamp(1rem, 4vw, 2rem);
  align-items: start;
  padding: clamp(1rem, 4vw, 2rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.detail-cover {
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.pill-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.detail-content h1 {
  margin: .9rem 0;
  font-size: clamp(1.8rem, 7vw, 3.5rem);
  line-height: 1.15;
}
.description { color: var(--muted); font-size: 1.02rem; }
.meta-grid, .stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .7rem;
  margin: 1.2rem 0;
}
.meta-grid div, .stat-card {
  padding: .9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.meta-grid strong, .stat-card strong { display: block; font-size: 1.4rem; color: var(--primary); }
.meta-grid span, .stat-card span { color: var(--muted); font-size: .86rem; }
.download-box {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: .65rem;
  margin: 1rem 0;
}
.copy-input { direction: ltr; text-align: left; }
.copy-row { display: grid; grid-template-columns: 1fr auto; gap: .6rem; }
.footer { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card {
  width: min(440px, 100%);
  padding: clamp(1.1rem, 5vw, 2rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 .4rem; }
.auth-card p { color: var(--muted); margin-top: 0; }
.auth-card label, .admin-form label {
  display: grid;
  gap: .35rem;
  margin-bottom: .85rem;
  color: var(--muted);
  font-weight: 700;
}
.setup-badge, .role-badge {
  display: inline-flex;
  padding: .28rem .65rem;
  border-radius: 999px;
  color: var(--primary);
  background: var(--soft);
  font-weight: 700;
}
.alert {
  padding: .8rem 1rem;
  border-radius: 8px;
  margin: .8rem 0;
  border: 1px solid transparent;
}
.alert.success { background: rgba(47, 111, 100, .12); border-color: rgba(47, 111, 100, .25); }
.alert.error { background: rgba(185, 51, 51, .10); border-color: rgba(185, 51, 51, .25); color: #8c2020; }
.upload-progress {
  padding: .9rem;
  margin: 1rem 0;
  border: 1px solid rgba(47, 111, 100, .22);
  border-radius: 8px;
  background: rgba(47, 111, 100, .08);
}
.upload-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .55rem;
}
.upload-progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(24, 35, 31, .12);
}
.upload-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .18s ease;
}
.upload-progress p {
  margin: .55rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.admin-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  background: #f6f3ea;
}
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1rem;
  background: #14342f;
  color: #fff;
}
.admin-brand {
  padding: .6rem;
  margin-bottom: 1rem;
  font-weight: 700;
}
.admin-brand img { background: #fff; border-radius: 8px; padding: .2rem; }
.admin-sidebar nav { display: grid; gap: .35rem; }
.admin-sidebar nav a {
  padding: .75rem .85rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, .86);
}
.admin-sidebar nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.admin-main {
  width: min(1180px, 100%);
  padding: 1rem;
  margin: 0 auto;
}
.admin-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.admin-top h1 { margin: .1rem 0 0; font-size: 1.8rem; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 28px rgba(42, 34, 24, .06);
}
.stat-grid { grid-template-columns: repeat(4, 1fr); }
.stat-grid.small { grid-template-columns: repeat(2, 1fr); }
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
th, td {
  padding: .8rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}
th { color: var(--muted); font-size: .9rem; }
.thumb-cell img, .thumb-cell span {
  width: 46px;
  height: 58px;
  border-radius: 6px;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--primary);
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}
.row-actions a, .row-actions button {
  color: var(--primary);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: .25rem;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .8rem;
}
.color-grid input { min-height: 54px; padding: .25rem; }
.check-row, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
}
.check-row label, .checkbox-label {
  display: flex;
  align-items: center;
  gap: .45rem;
}
.check-row input, .checkbox-label input { width: auto; min-height: auto; }
.inline-form {
  display: grid;
  grid-template-columns: 1fr 140px auto auto auto;
  gap: .75rem;
  align-items: end;
}
.logo-preview {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: .8rem 0;
}
.logo-preview img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.book-stat-panel { display: grid; gap: 1rem; }

@media (max-width: 760px) {
  .topbar { padding: .7rem 1rem; }
  .topbar-brand strong { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .search-row, .download-box, .book-detail, .copy-row { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .book-card-body { padding: .75rem; }
  .book-card p { display: none; }
  .meta-grid, .stat-grid, .stat-grid.small { grid-template-columns: 1fr; }
  .detail-cover { max-width: 260px; width: 100%; margin: 0 auto; }
  .admin-body { display: block; }
  .admin-sidebar {
    position: static;
    height: auto;
    border-radius: 0 0 8px 8px;
  }
  .admin-sidebar nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: .2rem;
  }
  .admin-main { padding: .8rem; }
  .admin-top { align-items: flex-start; }
  .form-grid, .inline-form { grid-template-columns: 1fr; }
  .panel-head { align-items: flex-start; }
}

@media (max-width: 420px) {
  .site-main { width: min(100% - 1rem, 1120px); }
  .library-hero { padding: .55rem; }
  .books-grid { gap: .55rem; }
  .book-card h3 { font-size: .92rem; }
  .book-category { font-size: .72rem; }
}
