/* Church Library — shared styles (public site + admin)
   Palette: church blue + communion red on cool paper.            */
:root {
  --blue-900: #0f2459;
  --blue-800: #16307a;
  --blue-600: #2451b3;
  --blue-100: #e6ecfa;
  --red-700: #a3132a;
  --red-600: #c11b33;
  --red-100: #fbe7ea;
  --paper: #f3f5fa;
  --surface: #ffffff;
  --ink: #182235;
  --ink-soft: #4a5570;
  --line: #d9dfec;
  --green: #17803d;
  --green-100: #e3f4e8;
  --amber: #a15c00;
  --amber-100: #fdf1dc;
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius-sm: 4px;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 36, 89, .08), 0 4px 14px rgba(15, 36, 89, .06);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.6 var(--sans); }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--blue-600); text-underline-offset: 2px; }
a:hover { color: var(--red-600); }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--blue-900); line-height: 1.2; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: clamp(1.9rem, 3.6vw, 2.6rem); }
h2 { font-size: clamp(1.4rem, 2.4vw, 1.8rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--red-600); outline-offset: 2px; }
.wrap { width: min(1180px, 100% - 32px); margin-inline: auto; }
.narrow { width: min(720px, 100% - 32px); margin-inline: auto; }
.muted { color: var(--ink-soft); }
.small { font-size: .9rem; }
.skip-link { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Header ---------- */
.site-header { background: var(--blue-800); color: #fff; border-bottom: 5px solid var(--red-600); }
.header-inner { display: flex; align-items: center; gap: 24px; min-height: 72px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }
.brand small { color: #c7d3f2; font-size: .82rem; }
.site-nav { margin-left: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.site-nav a { color: #e6ecfa; text-decoration: none; padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 600; font-size: .95rem; }
.site-nav a:hover, .site-nav a[aria-current] { background: rgba(255,255,255,.12); color: #fff; }
.site-nav a[aria-current] { box-shadow: inset 0 -3px 0 var(--red-600); }
.site-nav .nav-cta { background: var(--red-600); color: #fff; }
.site-nav .nav-cta:hover { background: var(--red-700); }
.site-nav .nav-admin { border: 1px solid rgba(255,255,255,.35); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; padding: 6px 12px; border-radius: var(--radius-sm); font: inherit; }
@media (max-width: 880px) {
  .nav-toggle { display: block; }
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 77px; background: var(--blue-900); flex-direction: column; align-items: stretch; padding: 8px 16px 16px; z-index: 50; }
  .site-nav.open { display: flex; }
  .site-header { position: relative; }
}

/* ---------- Home: the shelf ---------- */
.hero { background: var(--blue-900); color: #fff; padding: 48px 0 0; overflow: hidden; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 40px; align-items: end; }
.hero h1 { color: #fff; font-size: clamp(2rem, 4.4vw, 3.1rem); max-width: 14ch; }
.hero p { color: #c7d3f2; max-width: 46ch; font-size: 1.1rem; }
.hero-search { display: flex; margin: 24px 0 40px; max-width: 520px; background: #fff; border-radius: var(--radius); overflow: hidden; }
.hero-search input { flex: 1; border: 0; padding: 14px 16px; font: inherit; min-width: 0; color: var(--ink); }
.hero-search button { border: 0; background: var(--red-600); color: #fff; font: 600 1rem var(--sans); padding: 0 22px; cursor: pointer; }
.hero-search button:hover { background: var(--red-700); }
.shelf { display: flex; align-items: flex-end; gap: 4px; height: 300px; padding: 0 8px; border-bottom: 14px solid #6b3a1f; position: relative; }
.shelf::after { content: ""; position: absolute; left: -20px; right: -20px; bottom: -22px; height: 8px; background: #4d2913; }
.spine { flex: 0 0 auto; width: 44px; border-radius: 3px 3px 0 0; color: #fff; text-decoration: none; display: flex; align-items: center; justify-content: center; writing-mode: vertical-rl; transform: rotate(180deg); font: 600 .82rem/1.15 var(--serif); padding: 12px 4px; overflow: hidden; text-overflow: ellipsis; box-shadow: inset 4px 0 0 rgba(255,255,255,.12), inset -3px 0 0 rgba(0,0,0,.18); transition: transform .2s; }
.spine span { max-height: 100%; overflow: hidden; }
.spine:hover, .spine:focus-visible { color: #fff; transform: rotate(180deg) translateY(12px); }
.spine.c0 { background: var(--red-600); }
.spine.c1 { background: var(--blue-600); }
.spine.c2 { background: #f1f4fb; color: var(--blue-900); }
.spine.c3 { background: #7b1020; }
.spine.c4 { background: #3a63c9; }
.spine.c2:hover { color: var(--blue-900); }
@media (prefers-reduced-motion: reduce) { .spine { transition: none; } }
@media (max-width: 880px) { .hero-grid { grid-template-columns: 1fr; } .shelf { height: 220px; overflow: hidden; } }

/* ---------- Sections ---------- */
.section { padding: 48px 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.notice { background: var(--amber-100); border-left: 5px solid var(--amber); padding: 14px 18px; border-radius: var(--radius-sm); }
.notice-blue { background: var(--blue-100); border-left-color: var(--blue-600); }

/* ---------- Book grid ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 28px 22px; }
.book-card { display: flex; flex-direction: column; text-decoration: none; color: var(--ink); }
.book-card .cover { aspect-ratio: 2 / 3; background: var(--blue-100); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 10px; }
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card h3 { font-size: 1.02rem; margin: 0 0 2px; }
.book-card:hover h3 { color: var(--red-600); }
.book-card .by { color: var(--ink-soft); font-size: .92rem; margin: 0 0 6px; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; line-height: 1.5; }
.badge-green { background: var(--green-100); color: var(--green); }
.badge-red { background: var(--red-100); color: var(--red-700); }
.badge-blue { background: var(--blue-100); color: var(--blue-800); }
.badge-amber { background: var(--amber-100); color: var(--amber); }
.badge-muted { background: #eceff5; color: var(--ink-soft); }

/* ---------- Catalogue layout ---------- */
.catalogue { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 36px; padding: 32px 0 56px; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; align-self: start; position: sticky; top: 16px; }
.filters h2 { font-size: 1.1rem; }
.filters label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 4px; }
@media (max-width: 880px) { .catalogue { grid-template-columns: 1fr; } .filters { position: static; } }
.result-bar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-block; padding: 4px 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; text-decoration: none; color: var(--blue-800); font-size: .9rem; font-weight: 600; }
.chip:hover { border-color: var(--red-600); color: var(--red-600); }
.chip .count { color: var(--ink-soft); font-weight: 400; margin-left: 4px; }

/* Browse page: subject index */
.index-cols { columns: 3 240px; column-gap: 32px; }
.index-cols a { display: flex; justify-content: space-between; break-inside: avoid; padding: 8px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 600; }
.index-cols a:hover { color: var(--red-600); }
.index-cols a span { color: var(--ink-soft); font-weight: 400; }

/* ---------- Book detail ---------- */
.book-detail { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 44px; padding: 36px 0; }
.book-detail .cover-lg { border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow); background: var(--blue-100); }
.book-detail .by { font-size: 1.15rem; margin-top: -4px; }
.meta-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 20px 0; font-size: .96rem; }
.meta-list dt { color: var(--ink-soft); }
.meta-list dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0; }
.excerpt { background: var(--surface); border-left: 5px solid var(--red-600); padding: 20px 24px; font-family: var(--serif); font-size: 1.05rem; line-height: 1.75; max-width: 70ch; border-radius: 0 var(--radius) var(--radius) 0; }
.excerpt.clamped { max-height: 16em; overflow: hidden; position: relative; }
.excerpt.clamped::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5em; background: linear-gradient(transparent, var(--surface)); }
@media (max-width: 760px) { .book-detail { grid-template-columns: 1fr; } .book-detail .cover-lg { max-width: 220px; } }
.breadcrumb { font-size: .9rem; color: var(--ink-soft); padding-top: 20px; }
.breadcrumb a { color: var(--ink-soft); }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius-sm); border: 2px solid transparent; font: 600 .98rem var(--sans); cursor: pointer; text-decoration: none; background: var(--blue-800); color: #fff; line-height: 1.2; }
.btn:hover { background: var(--blue-900); color: #fff; }
.btn-red { background: var(--red-600); }
.btn-red:hover { background: var(--red-700); }
.btn-outline { background: transparent; border-color: var(--blue-800); color: var(--blue-800); }
.btn-outline:hover { background: var(--blue-100); color: var(--blue-900); }
.btn-ghost { background: transparent; color: var(--blue-800); padding-inline: 8px; }
.btn-ghost:hover { background: var(--blue-100); color: var(--blue-900); }
.btn-sm { padding: 5px 10px; font-size: .86rem; }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #b9c3da; border-radius: var(--radius-sm); font: inherit; font-size: 1rem; background: #fff; color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue-600); outline: 2px solid var(--blue-100); }
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.field { margin-bottom: 16px; }
.field > label, .label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field .hint { font-size: .85rem; color: var(--ink-soft); margin-top: 3px; }
.req { color: var(--red-600); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 20px; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfcfe; }
.check-grid label, .inline-check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.auth-page { padding: 48px 0 64px; }

/* ---------- Alerts ---------- */
.flash-area:empty { display: none; }
.flash-area { padding-top: 16px; }
.alert { position: relative; padding: 12px 40px 12px 16px; border-radius: var(--radius-sm); margin-bottom: 10px; border-left: 5px solid; }
.alert-success { background: var(--green-100); border-color: var(--green); }
.alert-error { background: var(--red-100); border-color: var(--red-600); }
.alert-info { background: var(--blue-100); border-color: var(--blue-600); }
.alert-warning { background: var(--amber-100); border-color: var(--amber); }
.alert-close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: inherit; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { background: #f6f8fc; color: var(--blue-900); font-weight: 700; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.overdue td { background: #fff6f7; }
table.data td.num, table.data th.num { text-align: right; }
.empty { padding: 32px; text-align: center; color: var(--ink-soft); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 36, 89, .55); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 200; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: min(520px, 100%); max-height: 92vh; overflow: auto; padding: 26px; border-top: 6px solid var(--red-600); }
.modal h2 { font-size: 1.35rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Account ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; font-weight: 600; color: var(--ink-soft); margin-bottom: -2px; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--blue-900); border-color: var(--red-600); }

/* ---------- Footer ---------- */
.site-footer { background: var(--blue-900); color: #c7d3f2; margin-top: 40px; font-size: .95rem; border-top: 5px solid var(--red-600); }
.site-footer a { color: #fff; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 24px; padding: 36px 0 20px; }
.footer-name { font-family: var(--serif); color: #fff; font-size: 1.2rem; margin-bottom: 4px; }
.footer-head { color: #fff; font-weight: 700; margin-bottom: 6px; }
.footer-grid p { margin: 0 0 4px; }
.footer-base { border-top: 1px solid rgba(255,255,255,.15); padding: 14px 0 20px; font-size: .85rem; }
@media (max-width: 700px) { .footer-grid { grid-template-columns: 1fr; } }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 28px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; text-decoration: none; }
.pagination .current { background: var(--blue-800); color: #fff; border-color: var(--blue-800); }

/* =================== ADMIN =================== */
.admin-body { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.admin-side { background: var(--blue-900); color: #c7d3f2; padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 5px solid var(--red-600); }
.admin-side .brand { padding: 0 18px 16px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 8px; }
.admin-side .brand strong { font-size: 1.05rem; }
.admin-side nav a { display: block; padding: 9px 20px; color: #dfe6f7; text-decoration: none; font-weight: 600; font-size: .95rem; border-left: 4px solid transparent; }
.admin-side nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.admin-side nav a.active { background: rgba(255,255,255,.1); border-left-color: var(--red-600); color: #fff; }
.admin-side nav .group { padding: 14px 20px 4px; font-size: .8rem; color: #8fa2d4; }
.admin-side nav .pill { float: right; background: var(--red-600); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .78rem; }
.admin-main { padding: 26px 32px 56px; min-width: 0; }
.admin-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.admin-top h1 { margin: 0; font-size: 1.8rem; }
.admin-mobile-bar { display: none; }
@media (max-width: 900px) {
  .admin-body { grid-template-columns: 1fr; }
  .admin-side { display: none; position: fixed; inset: 0; z-index: 100; height: auto; }
  .admin-side.open { display: block; }
  .admin-mobile-bar { display: flex; justify-content: space-between; align-items: center; background: var(--blue-900); color: #fff; padding: 10px 16px; border-bottom: 4px solid var(--red-600); }
  .admin-mobile-bar button { background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; padding: 4px 12px; border-radius: 4px; font: inherit; }
  .admin-main { padding: 20px 16px 48px; }
}
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; border-top: 4px solid var(--blue-800); text-decoration: none; color: var(--ink); }
.stat.red { border-top-color: var(--red-600); }
.stat .n { font-family: var(--serif); font-size: 2rem; font-weight: 700; color: var(--blue-900); line-height: 1.1; }
.stat.red .n { color: var(--red-700); }
.stat .l { color: var(--ink-soft); font-size: .92rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 22px; }
.panel h2 { font-size: 1.2rem; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
@media (max-width: 1000px) { .panel-grid { grid-template-columns: 1fr; } }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar .field { margin: 0; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.thumb { width: 42px; height: 62px; object-fit: cover; border-radius: 2px; background: var(--blue-100); }
.cover-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 10px; }
.cover-picks button { border: 3px solid transparent; padding: 0; background: var(--blue-100); cursor: pointer; border-radius: 4px; overflow: hidden; aspect-ratio: 2/3; }
.cover-picks button img { width: 100%; height: 100%; object-fit: cover; }
.cover-picks button.chosen { border-color: var(--red-600); }
.cover-picks .src { font-size: .72rem; color: var(--ink-soft); text-align: center; }
.chart-box { position: relative; height: 300px; }
.inline-form { display: inline; }
.count-input { width: 80px !important; }
.variance-neg { color: var(--red-700); font-weight: 700; }
.variance-pos { color: var(--green); font-weight: 700; }
@media print {
  .admin-side, .admin-mobile-bar, .no-print, .site-header, .site-footer { display: none !important; }
  .admin-body { display: block; } .admin-main { padding: 0; }
  body { background: #fff; font-size: 12px; }
}
@media (max-width: 520px) { .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; } }
