:root {
  --bg: #f4f2ef;
  --ink: #1c1b1a;
  --muted: #5c5854;
  --card: #fff;
  --accent: #c45c26;
  --line: #ddd8d1;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }
.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; background: #111; color: #fff;
}
.top a { color: #fff; text-decoration: none; margin-left: 16px; }
.brand { font-weight: 700; margin-left: 0 !important; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { margin: 0 0 8px; font-size: 1.75rem; }
.lead { color: var(--muted); margin: 0 0 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters select, .filters input, .filters button, button, textarea, input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
button,
.row-actions a,
.btn {
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
}
button:hover,
.row-actions a:hover,
.btn:hover {
  background: #f3efe9;
  border-color: #cfc8bf;
}
button:active,
.row-actions a:active,
.btn:active {
  background: #ebe6df;
}
button:focus-visible,
.row-actions a:focus-visible,
.btn:focus-visible,
.btn-google:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); display: flex; flex-direction: column;
  text-decoration: none; color: inherit; transition: transform .15s ease, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.card .cover {
  aspect-ratio: 3/4; background: #e8e4de;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px;
  overflow: hidden;
}
.card .cover img {
  width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block;
}
.card .cover-fallback { letter-spacing: .04em; }
.card .meta { padding: 10px 12px 14px; }
.card .brand-tag { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.card h2 { font-size: 15px; margin: 4px 0 0; line-height: 1.3; font-weight: 600; }
.card .pages { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Viewer */
.page-viewer { background: #16161a; color: #eee; min-height: 100vh; }
.page-viewer .top { background: #0d0d10; }
.viewer-wrap { height: calc(100vh - 52px); }
#book { height: 100%; width: 100%; --fb-bg: #16161a; }
.viewer-toolbar-extra {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px;
}
.viewer-toolbar-extra a {
  cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: background .15s ease;
}
.viewer-toolbar-extra a:hover { background: rgba(255,255,255,.12); }

/* Admin */
.page-admin main { max-width: 960px; }
.admin-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.table th { background: #efebe6; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eee; }
.badge.live { background: #d7f5df; }
.badge.draft { background: #fff1c9; }
.badge.archived { background: #e8e8e8; }
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center;
  background: #fff; margin-bottom: 20px; cursor: pointer;
}
.drop.drag { border-color: var(--accent); background: #fff7f2; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions button,
.row-actions a {
  font-size: 12px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); text-decoration: none; display: inline-block;
}
.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.msg.ok { background: #d7f5df; }
.msg.err { background: #ffd9d9; }
.snippet {
  width: 100%; min-height: 72px; font-family: ui-monospace, monospace; font-size: 12px;
}
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 12px; padding: 20px; max-width: 520px; width: 100%; max-height: 90vh; overflow: auto;
}
.modal.modal-wide { max-width: 640px; }
.modal h3 { margin-top: 0; }
.modal-footer { margin-top: 16px; margin-bottom: 0; }
.form-grid { display: grid; gap: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-id { margin: 0; font-size: 13px; color: var(--muted); }
.form-block {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0;
  display: grid; gap: 12px;
}
.form-block legend {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink); padding: 0 4px;
}
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.hint { font-weight: 400; color: #888; font-size: 12px; }
.check-grid {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.check-chip {
  display: inline-flex !important; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: #faf9f7; font-size: 13px; color: var(--ink); cursor: pointer;
  grid-template-columns: none !important;
}
.check-chip:has(input:checked) {
  background: #fff7f2; border-color: var(--accent); color: var(--ink);
}
.check-chip input { margin: 0; accent-color: var(--accent); }
.check-inline {
  display: flex !important; align-items: center; gap: 8px; flex-direction: row !important;
  color: var(--ink) !important; cursor: pointer;
}
.check-inline input { width: auto; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }
.btn-primary {
  background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important;
  font-weight: 600; padding: 10px 14px !important;
}
.btn-primary:hover { filter: brightness(1.05); }
.row-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: #efebe6; color: var(--muted);
}
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.admin-login { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; margin-bottom: 20px; }
.admin-login p { margin: 0 0 16px; line-height: 1.5; }
.btn-google {
  display: inline-block; padding: 12px 18px; border-radius: 8px; background: #fff;
  border: 1px solid #dadce0; color: #3c4043; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-google:hover { background: #f8f9fa; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-color: #c0c4c8; }
.admin-user { font-size: 14px; color: var(--muted); margin-right: auto; }
.admin-token-fallback { margin-top: 20px; font-size: 13px; color: #666; }
.admin-token-fallback label { display: block; margin-top: 8px; }
@media (max-width: 600px) {
  .card h2 { font-size: 14px; }
}
