/* Books, Book list and Loans screens (books.js, book-list.js, loans.js). Uses the tokens
   and components in styles.css; only what these screens need is here. */

/* ---------- Shared by both lists ---------- */
.toolbar-search { flex: 1 1 260px; min-width: 0; }
/* The count sits on the open sky, so it carries full ink weight. */
.list-count { font-weight: 650; color: var(--ink); min-height: 1.5em; font-variant-numeric: tabular-nums; text-shadow: var(--ground-halo); }
.list-foot { display: grid; justify-items: center; gap: var(--space-2); padding-top: var(--space-1); }
.list-foot .btn { min-width: 180px; }

/* ---------- Book list ---------- */
/* The filters are one solid bar: the search row, then the chips that narrow it. */
.catalogue-filters {
  display: grid; gap: var(--space-3); padding: var(--space-4);
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.catalogue-filters .toolbar { padding: 0; background: none; border: 0; border-radius: 0; box-shadow: none; }
.catalogue-filters .chip { box-shadow: none; }
.toolbar .field-level { flex: 0 1 130px; }
.catalogue-filters input[aria-invalid="true"] { border-color: var(--alert); }
.hint-alert { color: var(--alert); }
.book.is-archived { border-style: dashed; background: var(--surface-sunk); box-shadow: none; }
/* Copies, on loan, waiting: the same three numbers wherever a title is shown. */
.book-counts { font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- A book's page ---------- */
/* A book's facts are data, so they sit on a solid surface like any other panel. */
.book-hero {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-8); align-items: start;
  padding: var(--space-6);
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.book-hero-main { display: grid; gap: var(--space-4); min-width: 0; }
.book-hero-main h1 { overflow-wrap: anywhere; text-wrap: balance; }
.book-byline { color: var(--muted); font-size: var(--text-lg); }
.book-description { max-width: 70ch; white-space: pre-line; text-wrap: pretty; }
.book-notes { display: grid; gap: var(--space-1); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--surface-sunk); }
.book-notes h2 { font-family: var(--font-ui); font-size: var(--text-sm); letter-spacing: 0; color: var(--muted); }
.book-notes p { white-space: pre-line; overflow-wrap: anywhere; }

.copy-list { display: grid; gap: var(--space-2); }
.copy-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.copy-row.is-overdue { border-color: var(--alert-line); background: var(--alert-wash); }
.copy-row.is-inactive { background: var(--surface-sunk); }
.copy-code { font-family: var(--font-mono); font-weight: 700; min-width: 7ch; overflow-wrap: anywhere; }
.copy-detail { flex: 1 1 220px; font-size: var(--text-sm); }
.copy-actions { margin-left: auto; }
.copy-add { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2) var(--space-3); margin-top: var(--space-4); }
.copy-add .field { flex: 1 1 220px; }
.copy-add .hint { flex-basis: 100%; }

/* The waiting list: children in the order they asked, and a picker to add one. */
.wait-list { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.wait-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.wait-place {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-pill);
  background: var(--brand-soft); color: var(--brand);
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 700;
}
.wait-who { display: grid; gap: 1px; min-width: 0; }
.wait-who a { font-weight: 650; overflow-wrap: anywhere; }
.wait-who .muted { font-size: var(--text-sm); }
.wait-add { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2) var(--space-3); margin-top: var(--space-4); }
.wait-add .field { flex: 1 1 200px; }
.wait-add .hint { flex-basis: 100%; }
.wait-open { margin-top: var(--space-4); }

/* ---------- Add / edit dialog ---------- */
.book-lookup { display: grid; gap: var(--space-3); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.book-lookup-result { display: flex; align-items: flex-start; gap: var(--space-3); }
.lookup-status { font-size: var(--text-sm); font-weight: 600; }
.lookup-good { color: var(--good); }
.lookup-alert { color: var(--alert); }
.lookup-none { color: var(--muted); }
.book-group { display: grid; gap: var(--space-3); }
.book-group legend { padding: 0; margin-bottom: var(--space-2); font-weight: 700; font-size: var(--text-md); }
.error-list { list-style: disc; padding-left: 20px; display: grid; gap: 2px; }

/* ---------- Import a list ---------- */
.import-text {
  min-height: 200px; font-family: var(--font-mono); font-size: 14px;
  white-space: pre; overflow-wrap: normal; overflow-x: auto; tab-size: 8;
}
.import-summary { font-weight: 650; }
.import-summary:focus { outline: none; }
.import-table td { overflow-wrap: anywhere; min-width: 4ch; }
.import-table tr.has-problem td { background: var(--alert-tint); }
.row-problems { display: grid; gap: 2px; color: var(--alert); font-size: 14px; font-weight: 600; min-width: 22ch; }

/* ---------- The book list (book-list.js) ---------- */
.blist { display: grid; gap: var(--space-4); }
/* "Saving…" and "All changes saved" sit on the open sky beside the title. */
.blist-status {
  min-height: 1.5em; font-size: var(--text-sm); font-weight: 600; color: var(--ink-2);
  text-shadow: var(--ground-halo);
}
.blist-status.is-alert { color: var(--alert); }
.blist-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat-of { font-family: var(--font-ui); font-size: var(--text-md); font-weight: 600; letter-spacing: 0; color: var(--muted); }
/* The filters are one solid bar: the year groups, then which titles to show. */
.blist-filters {
  display: grid; gap: var(--space-3); padding: var(--space-4);
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.blist-filters .chip { box-shadow: none; }
.blist-group .panel-head { margin-bottom: var(--space-2); }
.blist-tally { font-size: var(--text-sm); font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.blist-none { color: var(--muted); }
.blist-rows { display: grid; margin: 0; padding: 0; list-style: none; }
.blist-row {
  display: grid; grid-template-columns: 2.5ch auto minmax(0, 1fr) auto; align-items: center;
  gap: var(--space-2) var(--space-3); padding: var(--space-2) 0;
  border-top: 1px solid var(--line);
}
.blist-row:first-child { border-top: 0; }
.blist-cover { display: block; flex: none; text-decoration: none; }
.blist-row:hover .blist-cover .cover { transform: translateY(-1px); }
.blist-num {
  font-family: var(--font-mono); font-size: var(--text-sm); color: var(--muted);
  text-align: right; font-variant-numeric: tabular-nums;
}
.blist-book { display: grid; gap: 1px; min-width: 0; }
.blist-title { font-weight: 650; line-height: var(--leading-snug); overflow-wrap: anywhere; }
.blist-author { font-size: var(--text-sm); color: var(--muted); overflow-wrap: anywhere; }
/* A title's numbers: its copies (with the stepper), then how many are out and who waits. */
.blist-numbers { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2) var(--space-5); }
.blist-copies { display: inline-flex; align-items: center; gap: var(--space-2); }
.blist-unit { width: 6ch; font-size: var(--text-sm); color: var(--muted); }
.blist-fact { min-width: 9ch; font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.blist-fact b { font-family: var(--font-mono); font-weight: 600; }
.blist-fact.is-some { color: var(--ink); }
.blist-fact.is-some b { font-weight: 700; }
.blist-title { color: var(--ink); text-decoration: none; }
a.blist-title:hover { color: var(--accent-ink); text-decoration: underline; }

/* A number with a step either side: one bordered control, like the other inputs. */
.stepper {
  display: inline-grid; grid-template-columns: var(--control-sm) 5ch var(--control-sm);
  height: var(--control-sm); overflow: hidden;
  border: 1px solid var(--control-line); border-radius: var(--radius-sm);
  background: var(--field);
}
.stepper-btn {
  display: grid; place-items: center; padding: 0; border: 0;
  background: var(--surface); color: var(--ink);
  font-size: var(--text-lg); font-weight: 600; line-height: 1; cursor: pointer;
}
.stepper-btn:hover { background: var(--surface-hover); }
.stepper-btn:active { background: var(--surface-sunk); }
.stepper-btn[aria-disabled="true"], .stepper-btn[aria-disabled="true"]:hover {
  background: var(--surface-sunk); color: var(--line-strong); cursor: default;
}
.stepper .stepper-value {
  width: 100%; height: 100%; min-height: 0; padding: 0;
  border: 0; border-inline: 1px solid var(--line); border-radius: 0; box-shadow: none;
  font-family: var(--font-mono); font-size: var(--text-md); font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
/* The stepper clips its corners, so its parts keep their focus ring inside. */
.stepper-btn:focus-visible, .stepper .stepper-value:focus-visible {
  outline: 2.5px solid var(--focus-ring); outline-offset: -3px; box-shadow: none;
}
/* A title the library has is marked where the eye already is: on its number. */
.blist-row.is-owned .stepper { border-color: var(--good); }
.blist-row.is-owned .stepper-value { background: var(--good-tint); color: var(--good); }
.blist-row.is-owned .blist-num { color: var(--good); font-weight: 700; }
@media (pointer: coarse) {
  .stepper { grid-template-columns: var(--tap) 5ch var(--tap); height: var(--tap); }
}
@media (prefers-reduced-motion: no-preference) {
  .stepper, .stepper-btn { transition: background-color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out); }
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  /* The book list: the cover stays beside its title, and the stepper sits underneath. */
  .blist-row { grid-template-columns: 2.5ch auto minmax(0, 1fr); }
  .blist-numbers { grid-column: 2 / -1; justify-content: flex-start; gap: var(--space-2) var(--space-4); }
  .blist-fact { min-width: 0; }
  .blist-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wait-row { grid-template-columns: auto minmax(0, 1fr); }
  .wait-row .btn { grid-column: 2; justify-self: start; }
  .blist-stats .stat { padding: var(--space-3); }
  .blist-stats .stat-number { font-size: var(--text-2xl); }
  .stat-of { font-size: var(--text-sm); }
  .book-hero { grid-template-columns: 1fr; gap: var(--space-4); padding: var(--space-4); }
  .toolbar .field-level { flex: 1 1 120px; }
  .copy-actions { margin-left: 0; }
  .book-lookup-result { flex-wrap: wrap; }
}

/* ---------- Print (the loans list's sheet for a class teacher) ---------- */
.print-only { display: none; }
@media print {
  .print-only { display: block; }
  /* The book list prints as a plain list with its numbers. */
  .blist-filters, .blist-status, .blist-cover, .stepper-btn { display: none !important; }
  .stepper { display: inline; border: 0; }
  .stepper .stepper-value { width: 4ch; border: 0; background: none; color: #000; }
  .blist-group { break-inside: avoid; }
  .loans-print { display: grid; gap: 8pt; }
  .loans-print h2 { font-size: 16pt; }
  .loans-print .table { font-size: 10.5pt; }
  .loans-print .table th, .loans-print .table td { padding: 4pt 6pt; border-bottom: 1px solid #999; }
  .loans-print tr { break-inside: avoid; }
  .loans-print thead { display: table-header-group; }
}
