/* books-catalog.css — the /books/ browse page, scoped to .books-catalog.
 *
 * Layout idea: the controls live in ONE bar (tabs left, search + language +
 * sort + a Filters popover right) so a book is visible without scrolling.
 * The advanced filters float over the page instead of pushing it down.
 * Covers lead each card; they are generated typography on flat tints. */

.books-catalog {
  --bc-r: 10px;
  --bc-control-h: 40px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  box-sizing: border-box;
  font-family: var(--font-body);
  color: var(--ink);
}
.books-catalog *, .books-catalog *::before, .books-catalog *::after { box-sizing: border-box; }
.books-catalog :focus-visible { outline: 3px solid var(--line-brand); outline-offset: 2px; }
.books-page.books-catalog { padding: 20px 0 48px; }

/* ── Header: title, count and shelf link on one line ── */
.books-catalog .bc-head {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 4px 14px; padding: 0 12px 12px;
}
.books-catalog .bc-heading {
  margin: 0; font-family: var(--font-display);
  font-size: clamp(1.6rem, 3vw, 1.9rem); font-weight: 800; line-height: 1.1;
}
.books-catalog .bc-results-count { margin: 0; font-size: .9rem; color: var(--ink-soft); }
.books-catalog .bc-shelf-link {
  margin-left: auto; font-size: .9rem; font-weight: 600;
  color: var(--line-brand); text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center;
}
.books-catalog .bc-shelf-link:hover { text-decoration: underline; }

/* ── Single control bar ── */
.books-catalog .bc-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}
.books-catalog .bc-tabs { display: flex; gap: 4px; flex: 0 0 auto; }
.books-catalog .bc-tab {
  display: inline-flex; align-items: center;
  min-height: var(--bc-control-h); padding: 0 14px;
  font-size: .9rem; font-weight: 600; white-space: nowrap;
  color: var(--ink-soft); text-decoration: none;
  border-radius: 999px; border: 1px solid transparent;
}
.books-catalog .bc-tab:hover { color: var(--ink); background: var(--paper-raised); border-color: var(--border); }
.books-catalog .bc-tab--active,
.books-catalog .bc-tab--active:hover {
  color: var(--line-brand-on); background: var(--line-brand); border-color: var(--line-brand);
}

.books-catalog .bc-controls {
  display: flex; align-items: center; gap: 8px;
  flex: 1 1 420px; min-width: 0; justify-content: flex-end;
}
.books-catalog .bc-search { position: relative; flex: 1 1 200px; min-width: 0; max-width: 340px; }
.books-catalog .bc-input,
.books-catalog .bc-select {
  height: var(--bc-control-h);
  border: 1px solid var(--border-strong); border-radius: var(--bc-r);
  background: var(--paper-raised); color: var(--ink);
  font-family: var(--font-body); font-size: .9rem;
}
.books-catalog .bc-input { width: 100%; padding: 0 40px 0 12px; appearance: none; }
.books-catalog .bc-select { padding: 0 8px; width: auto; max-width: 100%; }
.books-catalog .bc-input:focus,
.books-catalog .bc-select:focus { outline: 3px solid var(--line-brand); outline-offset: 1px; }
.books-catalog .bc-search-btn {
  position: absolute; top: 0; right: 0; width: var(--bc-control-h); height: var(--bc-control-h);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--ink-soft); border: 0; border-radius: var(--bc-r); cursor: pointer;
}
.books-catalog .bc-search-btn:hover { color: var(--line-brand); }

/* Filters: a button that opens a popover, so it never changes page height */
.books-catalog .bc-advanced { position: relative; flex: 0 0 auto; }
.books-catalog .bc-advanced-summary {
  display: inline-flex; align-items: center; gap: 6px;
  height: var(--bc-control-h); padding: 0 12px; list-style: none; cursor: pointer;
  font-size: .9rem; font-weight: 600; color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: var(--bc-r);
  background: var(--paper-raised); user-select: none;
}
.books-catalog .bc-advanced-summary::-webkit-details-marker { display: none; }
.books-catalog .bc-advanced-summary:hover,
.books-catalog .bc-advanced[open] .bc-advanced-summary { border-color: var(--line-brand); color: var(--line-brand); }
.books-catalog .bc-adv-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 .3rem;
  font-size: .72rem; font-weight: 700; border-radius: 999px;
  background: var(--line-brand); color: var(--line-brand-on);
}
.books-catalog .bc-popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: min(480px, calc(100vw - 24px));
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 14px;
  background: var(--paper); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .16);
}
.books-catalog .bc-popover .bc-select { width: 100%; }
.books-catalog .bc-label { display: block; margin-bottom: 4px; font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.books-catalog .bc-popover-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.books-catalog .bc-apply-btn {
  height: var(--bc-control-h); padding: 0 18px;
  font-family: var(--font-display); font-size: .875rem; font-weight: 700;
  background: var(--line-brand); color: var(--line-brand-on);
  border: 0; border-radius: var(--bc-r); cursor: pointer;
}
.books-catalog .bc-apply-btn:hover { opacity: .9; }
.books-catalog .bc-clear-link {
  flex: 0 0 auto; font-size: .85rem; color: var(--line-brand); text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center; white-space: nowrap;
}
.books-catalog .bc-clear-link:hover { text-decoration: underline; }

.books-catalog .bc-notice {
  margin: 12px; padding: .5rem .75rem;
  border-left: 3px solid var(--line-brand); background: var(--paper-raised);
  font-size: .85rem; border-radius: 0 var(--bc-r) var(--bc-r) 0;
}

/* ── Grid: portrait covers. Fixed counts (3 tablet, 5 wide, 2 phone below)
   that all divide BOOKS_PER_PAGE (books/models.py), so no page ends in a
   row with empty slots. ── */
.books-catalog .bc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px 20px;
  list-style: none; margin: 0; padding: 20px 12px 24px;
}
.books-catalog .bc-grid-item { display: contents; }
@media (min-width: 1000px) { .books-catalog .bc-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.books-catalog .bc-card { display: flex; flex-direction: column; min-width: 0; }

/* Covers: an illustration chosen for the book (books/cover_art.py) fills the
   cover and fades to dark at the bottom, where the title and author sit. */
.books-catalog .bc-cover {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end;
  aspect-ratio: 2 / 3; padding: 16px 14px 14px; overflow: hidden;
  background: #0d1420; color: #fff8ec;
  border-radius: 4px 8px 8px 4px; text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 8px 18px rgba(0, 0, 0, .2);
}
.books-catalog .bc-cover-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
/* thin inset frame gives it a printed-book look */
.books-catalog .bc-cover::before {
  content: ""; position: absolute; inset: 7px; z-index: 1;
  border: 1px solid #fff8ec; opacity: .28; border-radius: 2px; pointer-events: none;
}
/* keeps the title legible over any painting */
.books-catalog .bc-cover::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(8, 10, 18, .35) 0, rgba(8, 10, 18, 0) 22%, rgba(8, 10, 18, 0) 48%, rgba(8, 10, 18, .88) 100%);
}
.books-catalog .bc-cover > :not(.bc-cover-art) { position: relative; z-index: 1; }
.books-catalog .bc-cover-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: auto; text-shadow: 0 1px 3px rgba(0, 0, 0, .55); }
.books-catalog .bc-cover-year { font-size: .7rem; font-weight: 600; opacity: .85; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.books-catalog .bc-cover-label { font-size: .7rem; font-weight: 600; opacity: .85; line-height: 1.25; }
.books-catalog .bc-cover-title {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.2rem; font-weight: 700; line-height: 1.18; text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
  overflow-wrap: anywhere; hyphens: auto; display: -webkit-box;
  -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.books-catalog .bc-cover-author {
  font-family: Georgia, "Iowan Old Style", serif; font-size: .74rem; font-style: italic;
  opacity: .9; line-height: 1.3; margin-top: 6px; text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.books-catalog .bc-cover:hover { box-shadow: 0 1px 2px rgba(0, 0, 0, .22), 0 12px 24px rgba(0, 0, 0, .28); }

.books-catalog .bc-card-title {
  margin: 12px 0 2px; font-family: var(--font-display);
  font-size: .95rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere;
}
.books-catalog .bc-card-title a { color: var(--ink); text-decoration: none; }
.books-catalog .bc-card-title a:hover { color: var(--line-brand); text-decoration: underline; }
.books-catalog .bc-card-original { margin: 0 0 2px; font-size: .8rem; font-style: italic; color: var(--ink-soft); overflow-wrap: anywhere; }
.books-catalog .bc-card-author {
  margin: 0; font-size: .85rem; color: var(--ink-soft); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Actions ── */
.books-catalog .bc-card-ctas { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 10px; }
.books-catalog .bc-btn-primary,
.books-catalog .bc-btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--bc-control-h); padding: 0 16px; flex: 1 1 auto;
  font-family: var(--font-display); font-size: .875rem; font-weight: 700;
  border-radius: var(--bc-r); text-decoration: none; white-space: nowrap;
}
.books-catalog .bc-btn-primary { background: var(--line-brand); color: var(--line-brand-on); }
.books-catalog .bc-btn-primary:hover { opacity: .9; }
.books-catalog .bc-btn-secondary { color: var(--line-brand); border: 1px solid var(--border-strong); }
.books-catalog .bc-btn-secondary:hover { background: var(--paper-raised); }
.books-catalog .bc-btn-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: var(--bc-control-h); height: var(--bc-control-h);
  color: var(--line-brand); border: 1px solid var(--border-strong); border-radius: var(--bc-r);
  text-decoration: none;
}
.books-catalog .bc-btn-icon:hover { background: var(--paper-raised); }

.books-catalog .book-shelf-control { margin: 4px 0 0; font-size: .85rem; }
.books-catalog .bc-card .book-shelf-control { margin-top: 8px; }
.books-catalog .bc-card .book-shelf-control form { width: 100%; }
.books-catalog .bc-card .shelf-add-btn { width: 100%; }
.books-catalog .book-shelf-control a { color: var(--ink-soft); text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }
.books-catalog .book-shelf-control a:hover { color: var(--line-brand); text-decoration: underline; }
.books-catalog .books-text-button {
  font-size: .85rem; color: var(--ink-soft); background: transparent; border: 0; cursor: pointer;
  padding: 0; min-height: 44px; display: inline-flex; align-items: center;
}
.books-catalog .books-text-button:hover { color: var(--line-brand); text-decoration: underline; }

/* ── Empty state ── */
.books-catalog .bc-empty { grid-column: 1 / -1; padding: 3rem 1.5rem; text-align: center; }
.books-catalog .bc-empty-heading { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; margin: 0 0 .5rem; }
.books-catalog .bc-empty-body { color: var(--ink-soft); font-size: .9rem; margin: 0 0 1rem; }
.books-catalog .bc-empty-link { color: var(--line-brand); font-weight: 600; text-decoration: none; }
.books-catalog .bc-empty-link:hover { text-decoration: underline; }

/* ── Pagination ── */
.books-catalog .bc-pagination {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: .3rem; padding: 10px 12px; border-top: 1px solid var(--border);
}
.books-catalog .bc-page-link,
.books-catalog .bc-page-current,
.books-catalog .bc-page-ellipsis {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: .2rem .6rem;
  font-size: .85rem; border-radius: var(--bc-r); border: 1px solid var(--border);
}
.books-catalog .bc-page-link { color: var(--line-brand); text-decoration: none; background: var(--paper-raised); border-color: var(--border-strong); }
.books-catalog .bc-page-link:hover { background: var(--line-brand); color: var(--line-brand-on); }
.books-catalog .bc-page-current { background: var(--line-brand); color: var(--line-brand-on); border-color: var(--line-brand); font-weight: 700; }
.books-catalog .bc-page-ellipsis { color: var(--ink-soft); border-color: transparent; }

/* ── Rights ── */
.books-catalog .bc-rights { padding: 10px 12px 0; border-top: 1px solid var(--border); }
.books-catalog .bc-rights-summary {
  cursor: pointer; list-style: none; font-size: .85rem; font-weight: 600;
  color: var(--ink-soft); min-height: 44px; display: inline-flex; align-items: center; user-select: none;
}
.books-catalog .bc-rights-summary::-webkit-details-marker { display: none; }
.books-catalog .bc-rights-summary:hover { color: var(--ink); }
.books-catalog .bc-rights-body { font-size: .8rem; color: var(--ink-soft); margin: .4rem 0 0; max-width: 60rem; line-height: 1.65; }

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

/* ── Narrow: tabs scroll on their own row, controls fill the next ── */
@media (max-width: 899px) {
  .books-catalog .bc-tabs { flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }
  .books-catalog .bc-controls { flex: 1 1 100%; justify-content: flex-start; flex-wrap: wrap; }
  .books-catalog .bc-search { flex: 1 1 100%; max-width: none; }
}
@media (max-width: 599px) {
  .books-page.books-catalog { padding-top: 12px; }
  .books-catalog .bc-head { padding: 0 8px 8px; }
  .books-catalog .bc-bar { padding: 0 8px 8px; gap: 6px; }
  .books-catalog .bc-input, .books-catalog .bc-select { font-size: 1rem; }
  .books-catalog .bc-controls .bc-select { flex: 1 1 0; min-width: 0; }
  .books-catalog .bc-popover { position: fixed; left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; grid-template-columns: 1fr; }
  .books-catalog .bc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; padding: 16px 8px 20px; }
  .books-catalog .bc-cover { padding: 12px 10px 10px; }
  .books-catalog .bc-cover-title { font-size: 1rem; }
  .books-catalog .bc-card-ctas { gap: 6px; }
  .books-catalog .bc-btn-primary, .books-catalog .bc-btn-secondary { padding: 0 8px; }
  .books-catalog .bc-btn-primary, .books-catalog .bc-btn-secondary, .books-catalog .bc-btn-icon { min-height: 44px; }
  .books-catalog .bc-btn-icon { width: 44px; height: 44px; }
  .books-catalog .bc-pagination, .books-catalog .bc-rights { padding-left: 8px; padding-right: 8px; }
}
