/* Bibliobyte — single site stylesheet */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6770;
  --border: #d8dce1;
  --accent: #1e7ad6;
  --accent-hover: #1665b3;
  --accent-text: #ffffff;
  --accent-soft: #e3effb;
  --header-bg: #26292e;
  --header-text: #f4f5f7;
  --danger: #c62828;
  --danger-hover: #a51f1f;
  --success: #1e8e3e;
  --success-bg: #e6f4ea;
  --success-text: #1e5e2f;
  --error-bg: #fdecea;
  --error-text: #8a1c1c;
  --row-hover: #eef4fb;
  --warning-bg: #fff4e5;
  --warning-text: #7a4b00;
  --warning-border: #e0a030;
  --radius: 6px;
  color-scheme: light;
}

/* Dark colours: follow the device unless the user picked a theme in Settings
   (base.html sets data-theme="light" or "dark" on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --surface: #1f2226;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #353a40;
    --accent: #4c9be8;
    --accent-hover: #6aaef0;
    --accent-text: #0d1117;
    --accent-soft: #1c2d40;
    --header-bg: #0f1113;
    --success: #5cc479;
    --success-bg: #1d3524;
    --success-text: #a8e0b5;
    --error-bg: #3d1e1e;
    --error-text: #f2b8b5;
    --row-hover: #262b31;
    --warning-bg: #3a2e14;
    --warning-text: #f5d08a;
    --warning-border: #b88a2e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181b;
  --surface: #1f2226;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --border: #353a40;
  --accent: #4c9be8;
  --accent-hover: #6aaef0;
  --accent-text: #0d1117;
  --accent-soft: #1c2d40;
  --header-bg: #0f1113;
  --success: #5cc479;
  --success-bg: #1d3524;
  --success-text: #a8e0b5;
  --error-bg: #3d1e1e;
  --error-text: #f2b8b5;
  --row-hover: #262b31;
  --warning-bg: #3a2e14;
  --warning-text: #f5d08a;
  --warning-border: #b88a2e;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 0.75rem; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; }

.muted { color: var(--muted); }

/* --- Header ------------------------------------------------------------- */

.site-header {
  background: var(--header-bg);
  color: var(--header-text);
}
/* When the links don't fit beside the brand (staff have more of them), the nav
   wraps onto its own row; on the narrowest screens its links scroll sideways. */
.site-header .inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--header-text); font-weight: 600; font-size: 1.15rem; }
.brand img { height: 40px; width: auto; }
.brand:hover { text-decoration: none; }
.site-nav { display: flex; align-items: center; gap: 0.25rem; flex: 1 1 auto; min-width: 0; }
.nav-links { display: flex; gap: 0.25rem; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
.site-nav a:not(.avatar) {
  color: var(--header-text); padding: 0.35rem 0.65rem; border-radius: var(--radius); white-space: nowrap;
}
.site-nav a:not(.avatar):hover { background: rgb(255 255 255 / 0.08); text-decoration: none; }
.site-nav a[aria-current="page"]:not(.avatar) { background: rgb(255 255 255 / 0.12); }
.site-nav .spacer { flex: 1; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 2.25rem; height: 2.25rem; margin-left: 0.5rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 1.05rem;
  box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 3px transparent;
}
.avatar:hover, .avatar[aria-current="page"] { text-decoration: none; box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 4px var(--header-text); }

@media (max-width: 480px) {
  .site-header .inner { gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .brand { font-size: 1.05rem; }
  .brand img { height: 32px; }
  .site-nav a:not(.avatar) { padding: 0.35rem 0.5rem; }
}
@media (max-width: 359px) {
  .brand-name { display: none; }
}

/* --- Settings ---------------------------------------------------------- */

.settings-layout { display: grid; grid-template-columns: 180px minmax(0, 640px); gap: 1.5rem; align-items: start; }
.settings-nav { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.settings-nav a { padding: 0.4rem 0.75rem; border-radius: var(--radius); color: var(--text); }
.settings-nav a:hover { background: var(--row-hover); text-decoration: none; }
.settings-sections { display: grid; gap: 1.25rem; }
.settings-section { scroll-margin-top: 1rem; }
.settings-section .section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.settings-section h2 { margin: 0; }
.settings-section .section-intro { margin: -0.5rem 0 1rem; }
.settings-section .field-label, .form-field .field-label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.account-links { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: center; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
fieldset.choice-field { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
fieldset.choice-field legend { font-weight: 600; margin-bottom: 0.35rem; padding: 0; }
.choice-field label.choice { display: flex; align-items: center; gap: 0.5rem; margin: 0; padding: 0.2rem 0; font-weight: normal; cursor: pointer; }
.choice-field label.choice input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; margin: 0; }
/* Many checkboxes (genres on the book form): columns instead of one long list. */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 1rem; }

.badge { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.4rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); vertical-align: middle; }
.genre-books { padding-left: 1.2rem; }

/* A small square button with just a symbol in it, like × to remove a row. */
.icon-button {
  width: 2rem; height: 2rem; flex: none; padding: 0; border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: var(--muted); font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.icon-button:hover { color: var(--danger); border-color: var(--border); }

/* The book form's custom categories (categories.book_form). */
.custom-field { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
.custom-field legend { font-weight: 600; margin-bottom: 0.35rem; }
.option-buttons { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.option-buttons label {
  position: relative; display: inline-flex; align-items: center; margin: 0; padding: 0.3rem 0.85rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-weight: normal;
}
.option-buttons input { position: absolute; opacity: 0; pointer-events: none; }
.option-buttons label:hover { border-color: var(--accent); }
.option-buttons label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.option-buttons label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.option-buttons label.option-none { color: var(--muted); border-style: dashed; }
.option-buttons label.option-none:has(input:checked) { background: var(--surface); color: var(--text); border-style: solid; border-color: var(--muted); font-weight: normal; }
.custom-number { max-width: 12rem; }

@media (max-width: 720px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; gap: 0.25rem; }
  .settings-nav a { border: 1px solid var(--border); background: var(--surface); padding: 0.3rem 0.8rem; }
}

/* --- Layout ------------------------------------------------------------- */

.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.narrow { max-width: 480px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.back { display: inline-block; margin-bottom: 0.75rem; }

/* --- Messages ----------------------------------------------------------- */

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.6rem 0.9rem; border-radius: var(--radius); margin-bottom: 0.5rem;
  background: var(--success-bg); color: var(--success-text);
}
.messages li.error, .messages li.warning { background: var(--error-bg); color: var(--error-text); }
.messages li.limit-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.messages .dismiss-limit { margin: 0; }
.messages .dismiss { background: none; border: 0; color: inherit; font-size: 1.2rem; cursor: pointer; padding: 0 0.25rem; }
/* "Moved to your Archive. Undo": Undo sits just before the dismiss button. */
.messages li:has(.message-undo) { justify-content: flex-start; }
.messages .message-undo { margin: 0 0 0 auto; }
.messages .message-undo .link-button { color: inherit; font-weight: 600; text-decoration: underline; }

/* --- Buttons ------------------------------------------------------------ */

.button, button[type="submit"]:not(.link-button) {
  display: inline-block;
  font: inherit;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
}
.button:hover, button[type="submit"]:not(.link-button):hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.button.secondary, button[type="submit"].secondary { background: transparent; color: var(--accent); }
.button.secondary:hover, button[type="submit"].secondary:hover { background: var(--row-hover); }
.button.danger, button[type="submit"].danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.danger:hover, button[type="submit"].danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
/* A sent form's button while the next page loads (site.js). The label turns invisible
   but still sizes the button, and a spinner sits where it was, so nothing moves. */
button.is-busy { position: relative; cursor: progress; }
button[type="submit"]:not(.link-button).is-busy { color: transparent; --busy-color: var(--accent-text); }
button[type="submit"].secondary.is-busy { --busy-color: var(--accent); }
button[type="submit"].danger.is-busy { --busy-color: #fff; }
button[type="submit"]:not(.link-button).is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--busy-color) 35%, transparent);
  border-top-color: var(--busy-color);
  animation: spin 0.7s linear infinite;
}
.link-button.is-busy { opacity: 0.6; text-decoration: none; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* --- Forms -------------------------------------------------------------- */

.form-field { margin-bottom: 1rem; }
/* Spam trap on the account request form. */
.form-field:has(input[name="website"]) { position: absolute; left: -10000px; }
.form-field label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.form-field .help { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.form-field .help ul { margin: 0.25rem 0; padding-left: 1.2rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.errorlist { list-style: none; padding: 0; margin: 0.25rem 0 0; color: var(--danger); font-size: 0.9rem; }
.field-warning {
  margin-top: 0.35rem; padding: 0.4rem 0.6rem; font-size: 0.9rem;
  border-radius: var(--radius); background: var(--warning-bg); color: var(--warning-text);
}
.field-notice {
  margin-top: 0.35rem; padding: 0.4rem 0.6rem; font-size: 0.9rem;
  border-radius: var(--radius); background: var(--success-bg); color: var(--success-text);
}
.form-field.has-warning input { border-color: var(--warning-border); }
.form-field.has-error input, .form-field.has-error select, .form-field.has-error textarea { border-color: var(--danger); }

/* --- My Library's tabs: Books, Archive ---------------------------------- */

.page-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: -0.25rem 0 1rem; overflow-x: auto; scrollbar-width: none; }
.page-tabs a {
  padding: 0.45rem 0.9rem; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.page-tabs a:hover { color: var(--text); text-decoration: none; }
.page-tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* --- Archive ------------------------------------------------------------ */

/* One row, whichever way the switch is set: Restore selected, or the red bar, then the
   switch. Its height doesn't change, so flipping the switch doesn't move the table. */
.archive-actions { display: flex; align-items: center; gap: 0.5rem 1rem; margin: 0 0 0.75rem; }
.archive-actions-slot { display: flex; flex: 1; min-width: 0; align-self: stretch; }
.archive-actions button, .archive-danger button, table.books.archive td.row-actions .button,
table.books.archive td.row-actions button { padding: 0.3rem 0.85rem; font-size: 0.9rem; }

/* Restore | Delete: a link drawn as a switch, Restore (off) by default. */
.switch { display: inline-flex; flex: none; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.95rem; }
.switch:hover { text-decoration: none; }
.switch[aria-checked="false"] .switch-off, .switch[aria-checked="true"] .switch-on { color: var(--text); font-weight: 600; }
.switch[aria-checked="true"] .switch-on { color: var(--danger); }
.switch-track {
  position: relative; flex: none; width: 2.4rem; height: 1.35rem; border-radius: 999px;
  background: var(--border); transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 0.15rem; left: 0.15rem; width: 1.05rem; height: 1.05rem;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); transition: transform 0.15s;
}
.switch[aria-checked="true"] .switch-track { background: var(--danger); }
.switch[aria-checked="true"] .switch-track::after { transform: translateX(1.05rem); }
@media (prefers-reduced-motion: reduce) { .switch-track, .switch-track::after { transition: none; } }

/* The bar beside the switch: Restore selected, or (switched to Delete) the red one. Both
   have the same shape, and the row keeps the height of the taller, so nothing moves. */
.archive-restore, .archive-danger {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; width: 100%;
  padding: 0.3rem 0.4rem 0.3rem 0.9rem; border-radius: var(--radius);
}
.archive-restore { background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.archive-danger { background: var(--error-bg); border: 1px solid transparent; color: var(--error-text); }
.archive-restore p, .archive-danger p { margin: 0 auto 0 0; }
.archive-danger a { color: inherit; text-decoration: underline; }
.archive-actions { min-height: 3.3rem; }
@media (max-width: 1080px) {
  /* The switch on its own line, above a bar tall enough for the wrapped text either way. */
  .archive-actions { flex-direction: column-reverse; align-items: stretch; }
  .archive-actions .switch { align-self: flex-end; }
  .archive-actions-slot { min-height: 5.7rem; }
  .archive-restore, .archive-danger { padding: 0.5rem 0.75rem; align-content: center; }
  .archive-restore p, .archive-danger p { flex-basis: 100%; }
}
@media (max-width: 480px) {
  .archive-actions-slot { min-height: 9.25rem; }
}

table.books.archive td.pick, table.books.archive th.pick { width: 1%; padding-right: 0; }
table.books.archive td.pick input { width: 1.05rem; height: 1.05rem; margin: 0.15rem 0 0; accent-color: var(--accent); }
table.books.archive td.row-actions { white-space: nowrap; text-align: right; }
table.books.archive td.row-actions form { display: inline; }
/* Restore and Delete the same width, so switching doesn't nudge the columns. */
table.books.archive td.row-actions .button, table.books.archive td.row-actions button {
  display: inline-block; box-sizing: border-box; width: 5.5rem; padding-inline: 0; text-align: center;
}
table.books.archive .by { display: none; }
@media (max-width: 640px) {
  /* The author moves under the title, so nothing scrolls sideways. */
  table.books.archive .author { display: none; }
  table.books.archive .by { display: block; font-weight: 400; font-size: 0.9rem; }
}
.archive-purge-link { margin: 1.5rem 0 0; font-size: 0.9rem; }
.archive-purge-link a { color: var(--danger); }
.archived-note {
  margin: 0 0 0.75rem; padding: 0.5rem 0.75rem; border-radius: var(--radius);
  background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border);
}

/* --- Library table ------------------------------------------------------ */

.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input[type="search"] { flex: 1 1 240px; width: auto; }
.toolbar select { width: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat-grid .card { padding: 0.9rem 1rem; }
.stat-grid .value { font-size: 1.5rem; font-weight: 600; display: block; }
.stat-grid .label { font-size: 0.85rem; color: var(--muted); }
.alert-list { border-left: 4px solid var(--danger); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.books { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.books th, table.books td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.books th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
table.books th a { color: inherit; }
table.books tbody tr:last-child td { border-bottom: 0; }
table.books tbody tr[data-href] { cursor: pointer; }
table.books tbody tr:hover { background: var(--row-hover); }
table.books td.title { overflow-wrap: anywhere; font-weight: 500; }
table.books td.num { white-space: nowrap; }

.pagination { display: flex; gap: 0.75rem; align-items: center; justify-content: center; margin-top: 1rem; }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1.5rem; margin: 0; }
dl.details dt { font-weight: 600; color: var(--muted); }
dl.details dd { margin: 0; overflow-wrap: anywhere; }

/* --- Feedback ----------------------------------------------------------- */

.feedback-tab {
  position: fixed; right: 1rem; bottom: 0;
  padding: 0.4rem 1rem; border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  font: inherit; cursor: pointer; z-index: 10;
}
dialog.feedback .trap { display: none; }
dialog.feedback {
  width: min(440px, calc(100vw - 2rem));
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.25rem;
}
dialog.feedback::backdrop { background: rgb(0 0 0 / 0.4); }
dialog.feedback .dialog-head { display: flex; justify-content: space-between; align-items: center; }
dialog.feedback .dialog-head h2 { margin: 0; }
.feedback-status { margin-top: 0.5rem; min-height: 1.5em; }

/* Staff feedback page */
.toolbar a.current { font-weight: 600; color: var(--text); }
.feedback-items { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.feedback-items .card { margin: 0; }
.feedback-items .resolved { opacity: 0.65; }

/* --- Admin (staff pages) ------------------------------------------------ */

.admin-links { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem; }
.admin-links a.card { display: flex; flex-direction: column; gap: 0.35rem; height: 100%; color: inherit; }
.admin-links a.card:hover { background: var(--row-hover); text-decoration: none; }
.admin-link-title { display: flex; align-items: center; gap: 0.45rem; font-size: 1.1rem; font-weight: 600; color: var(--accent); }
.admin-links a.card[class*="admin-status-"] { border-left-width: 4px; }
.admin-links a.admin-status-ok { border-left-color: var(--status-ok); }
.admin-links a.admin-status-warn { border-left-color: var(--warning-border); }
.admin-links a.admin-status-bad { border-left-color: var(--status-bad); }
.admin-badge {
  margin-left: auto; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; white-space: nowrap;
  background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border);
}
.admin-status-bad .admin-badge { background: var(--error-bg); color: var(--error-text); border-color: var(--status-bad); }
.actions form { margin: 0; }
table.decided-requests { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.decided-requests th, table.decided-requests td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.decided-requests th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
table.decided-requests tbody tr:last-child td { border-bottom: 0; }
table.decided-requests td:nth-child(2) { overflow-wrap: anywhere; }
.feedback-meta { font-size: 0.9rem; overflow-wrap: anywhere; }
.feedback-subject { font-size: 1.05rem; margin: 0.5rem 0 0; overflow-wrap: anywhere; }
.feedback-message { margin: 0.5rem 0; white-space: normal; overflow-wrap: anywhere; }

/* --- ISBN lookup -------------------------------------------------------- */

.isbn-status { font-size: 0.85rem; margin-top: 0.25rem; display: flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.isbn-status:empty { display: none; }
/* The ISBN hint and status in one cell: the hidden hint still holds its space. */
.isbn-slot { display: grid; }
.isbn-slot > * { grid-area: 1 / 1; }
.isbn-slot > .help[hidden] { display: block; visibility: hidden; }
.isbn-status[data-state="error"] { color: var(--error-text); }
.lookup-mark svg { width: 1.1rem; height: 1.1rem; flex: none; color: var(--success); }
/* Beside a field's label: what the ISBN lookup did with that field. */
.lookup-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.1rem; height: 1.1rem; margin: -0.15rem 0 0 0.4rem; vertical-align: middle;
}
.lookup-mark .spinner { width: 0.8rem; height: 0.8rem; }
.lookup-mark[data-state="missing"] { color: var(--muted); cursor: help; }
.lookup-mark .dash { width: 0.6rem; height: 2px; border-radius: 1px; background: currentColor; }
/* The user's value differs from Open Library's: a button that shows what was found. */
button.lookup-mark { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 3px; }
.lookup-mark[data-state="differs"] svg { color: var(--warning-border); }
.lookup-mark[data-state="differs"]:hover svg { color: var(--warning-text); }
.lookup-offer {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap;
  margin-top: 0.35rem; padding: 0.4rem 0.6rem; font-size: 0.9rem; border-radius: var(--radius);
  background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border);
}
.lookup-offer strong { overflow-wrap: anywhere; }
.lookup-offer .button { padding: 0.15rem 0.6rem; font-size: 0.85rem; }
.spinner {
  width: 0.9rem; height: 0.9rem; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, button.is-busy::after { animation-duration: 2s; } }

/* --- Covers ------------------------------------------------------------- */

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
table.books th.cover-col, table.books td.cover-col { width: 40px; padding-right: 0; }
.cover-thumb {
  display: block; width: 40px; height: 60px; object-fit: cover;
  border-radius: 3px; background: var(--bg); border: 1px solid var(--border);
}

.book-detail { display: flex; gap: 1.5rem; align-items: flex-start; }
.book-detail-body { flex: 1; min-width: 0; }
.cover-full { width: 200px; height: auto; border-radius: var(--radius); border: 1px solid var(--border); flex: none; }

.book-form-card { max-width: 760px; }
.book-form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 1.5rem; align-items: start; }
.cover-picker { text-align: center; }
.cover-picker .help { font-size: 0.85rem; margin: 0.5rem 0 0; }
.cover-slot {
  display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 2 / 3;
  padding: 0; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--muted); font: inherit; cursor: pointer; overflow: hidden;
}
.cover-slot:hover, .cover-slot:focus-visible { border-color: var(--accent); color: var(--accent); }
.cover-slot.has-cover { border-style: solid; }
.cover-slot img { width: 100%; height: 100%; object-fit: cover; }
.cover-slot.has-cover .cover-empty { display: none; }
/* Search/Change above Remove, each centred on its own row: the column is too narrow for
   both side by side, and Remove keeps its row while hidden, so nothing moves. */
.cover-actions { display: grid; justify-items: center; gap: 0.25rem; margin-top: 0.5rem; }
.cover-actions > [hidden] { display: inline; visibility: hidden; }
/* Wide enough for "Search" or "Change", so its box doesn't change size either. */
.cover-actions > :first-child { min-width: 3.75em; }

dialog.cover-dialog {
  width: min(760px, calc(100vw - 2rem)); max-height: calc(100vh - 4rem);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.25rem;
}
dialog.cover-dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog.cover-dialog .dialog-head { display: flex; justify-content: space-between; align-items: center; }
dialog.cover-dialog .dialog-head h2 { margin: 0; }
.cover-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.75rem; }
.cover-option {
  display: flex; flex-direction: column; gap: 0.25rem; padding: 0.25rem; text-align: left;
  border: 2px solid transparent; border-radius: var(--radius); background: none; font: inherit; color: inherit; cursor: pointer;
}
.cover-option:hover, .cover-option:focus-visible { border-color: var(--accent); }
.cover-option img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; background: var(--bg); border-radius: 3px; }
.cover-option span { font-size: 0.75rem; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

@media (max-width: 640px) {
  .book-form-layout { grid-template-columns: minmax(0, 1fr) 110px; gap: 1rem; }
  .book-detail { flex-direction: column; }
  .cover-full { width: 120px; }
  table.books .hide-sm { display: none; }
  h1 { font-size: 1.35rem; }
}
.cover-more { display: block; margin: 1rem auto 0; }
/* A cover whose preview wouldn't load: still selectable. */
.no-preview-wrap { position: relative; }
.no-preview-wrap img { opacity: 0; }
.no-preview-wrap::after {
  content: "Preview unavailable"; position: absolute; left: 0; right: 0; top: 35%;
  text-align: center; font-size: 0.75rem; color: var(--muted); pointer-events: none;
}

/* The Advanced cover picker (site.js setUpAdvancedCoverPicker): a tall dialog with a fixed
   search bar and footer, and the books or covers scrolling between them. Full screen on phones. */
dialog.advanced-cover-dialog {
  width: min(980px, calc(100vw - 2rem)); height: min(860px, calc(100vh - 3rem)); max-height: none;
  padding: 0; overflow: hidden;
}
dialog.advanced-cover-dialog[open] { display: flex; flex-direction: column; }
.acp-top { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: grid; gap: 0.75rem; }
.acp-top .dialog-close { font-size: 1.5rem; line-height: 1; color: var(--muted); }
.acp-search { display: flex; gap: 0.5rem; }
.acp-search input { flex: 1; min-width: 0; }
.acp-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 1rem 1.25rem 1.25rem; }
.acp-status { margin: 0 0 1rem; }
.acp-status[hidden] { display: none; }
.acp-view { display: grid; gap: 1.25rem; align-content: start; }
.acp-view > * { min-width: 0; }
.acp-foot { border-top: 1px solid var(--border); padding: 0.75rem 1.25rem; display: flex; align-items: center; gap: 0.9rem; }
.acp-foot[hidden] { display: none; }
.acp-foot img { width: 48px; height: 72px; object-fit: cover; border-radius: 3px; border: 1px solid var(--border); flex: none; background: var(--bg); }
.acp-selected { flex: 1; min-width: 0; font-size: 0.9rem; }
.acp-selected strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acp-selected span { color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.acp-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.acp-section-head h3 { margin: 0; font-size: 1rem; }
.acp-count { font-size: 0.875rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.acp-book-strip { display: flex; gap: 0.9rem; align-items: center; padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.acp-book-info { flex: 1; min-width: 0; }
.acp-book-info strong { display: block; }
.acp-book-info span { font-size: 0.875rem; color: var(--muted); }
.acp-books { display: grid; gap: 0.5rem; }
.acp-book {
  display: flex; gap: 0.9rem; align-items: center; width: 100%; padding: 0.65rem 0.9rem; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; font: inherit; cursor: pointer;
}
.acp-book:hover, .acp-book:focus-visible { border-color: var(--accent); }
.acp-editions { font-size: 0.875rem; color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }

.acp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 0.9rem 0.75rem; }
.acp-option {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 0.3rem; position: relative; min-width: 0; text-align: left;
  border: 2px solid transparent; border-radius: var(--radius); background: none; color: inherit; font: inherit; cursor: pointer;
}
.acp-option:hover { border-color: var(--border); }
.acp-option.is-yours { border: 2px dashed var(--accent); background: var(--accent-soft); }
.acp-option.is-yours .acp-pub { color: var(--accent); }
.acp-option[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.acp-option img { width: 100%; aspect-ratio: 2 / 3; object-fit: contain; background: var(--bg); border-radius: 3px; display: block; }
.acp-pub { font-size: 0.8rem; font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.acp-meta { font-size: 0.75rem; color: var(--muted); line-height: 1.3; font-variant-numeric: tabular-nums; }
.acp-tag {
  position: absolute; top: 0.55rem; left: 0.55rem; padding: 0.05rem 0.4rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 600; background: var(--accent); color: var(--accent-text);
}
.acp-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.9rem; }
.acp-chip {
  padding: 0.25rem 0.7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer; font-variant-numeric: tabular-nums;
}
.acp-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.acp-filters select, .acp-filters input { font-size: 0.85rem; padding: 0.25rem 0.5rem; width: auto; }
.acp-filters input { width: 12rem; max-width: 100%; }
.acp-sep { width: 1px; align-self: stretch; background: var(--border); }
.acp-more { justify-self: center; }
@media (prefers-reduced-motion: no-preference) {
  .acp-option, .acp-chip, .acp-book { transition: border-color 0.12s, background-color 0.12s; }
}

@media (max-width: 640px) {
  dialog.advanced-cover-dialog {
    width: 100vw; height: 100%; max-width: 100vw; max-height: 100%; margin: 0; border: 0; border-radius: 0;
  }
  .acp-top { padding: calc(0.75rem + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 0.75rem max(16px, env(safe-area-inset-left, 0px)); }
  .acp-body { padding: 0.9rem max(16px, env(safe-area-inset-right, 0px)) 1rem max(16px, env(safe-area-inset-left, 0px)); }
  .acp-foot { padding: 0.6rem max(16px, env(safe-area-inset-right, 0px)) calc(0.6rem + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
  .acp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem 0.4rem; }
  .acp-book-strip { flex-wrap: wrap; }
  .acp-book-strip .button { flex: 1 1 100%; justify-content: center; }
  .acp-wide { display: none; }
  .acp-filters input { width: 100%; }
  .acp-sep { display: none; }
}

/* --- Server health (staff) ---------------------------------------------- */

/* Chart colours, in a fixed order (health/charts.py). Checked for colour blindness against both surfaces. */
:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --grid: #e6e8eb; --status-bad: #d03b3b; --status-ok: #0ca30c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #2c3036; }
}
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #2c3036; }

.health-controls { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented a { padding: 0.35rem 0.9rem; color: var(--text); font-variant-numeric: tabular-nums; }
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a:hover { background: var(--row-hover); text-decoration: none; }
.segmented a[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
.health-loading { font-size: 0.85rem; }

.health-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.health-tabs a {
  display: flex; flex-direction: column; align-items: center; padding: 0.5rem 0.9rem; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.health-tabs a:hover { color: var(--text); text-decoration: none; }
.health-tabs a[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
/* Bold text is wider: reserve its width so tabs don't shift when selected. */
.health-tabs a::after { content: attr(data-label); display: block; height: 0; overflow: hidden; visibility: hidden; font-weight: 600; }

/* While another range loads, keep showing this one, dimmed. */
.health.is-loading .health-panel { opacity: 0.55; transition: opacity 0.15s; }
.health h3 { font-size: 1rem; margin: 0 0 0.5rem; }
.health-panel > h3 { margin-top: 1.5rem; }
.warning-card { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); margin-bottom: 1rem; }
.stat-bad { border-left: 4px solid var(--status-bad); }
/* Page speed tab: the slowest views' breakdown, and error messages with their stacks. */
.speed-parts { display: flex; flex-wrap: wrap; gap: 0.15rem 0.75rem; font-size: 0.8rem; color: var(--muted); min-width: 16rem; }
.speed-parts strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.speed-message { min-width: 18rem; max-width: 40rem; overflow-wrap: anywhere; }
.speed-message summary { cursor: pointer; }
.speed-message pre { white-space: pre-wrap; font-size: 0.75rem; margin: 0.35rem 0; max-height: 14rem; overflow: auto; }
.stat-bad-text { color: var(--status-bad); font-weight: 600; }
.tag-note { font-size: 0.75rem; color: var(--status-bad); white-space: nowrap; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.chart-card { margin: 0; padding: 0.9rem 1rem; min-width: 0; }
.chart-card figcaption { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; min-height: 1.5rem; }
.chart-card figcaption h3 { margin: 0; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.75rem; font-size: 0.8rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--key); }
.key-line { width: 14px; height: 2px; border-radius: 1px; }
/* Dashed, so it can't be taken for an orange series. */
.key-alarm { width: 14px; height: 2px; background: repeating-linear-gradient(90deg, var(--status-bad) 0 4px, transparent 4px 6px); }
.legend-stats { font-variant-numeric: tabular-nums; }
.legend strong { color: var(--text); font-weight: 600; }
.series-1 { --key: var(--series-1); }
.series-2 { --key: var(--series-2); }
.series-3 { --key: var(--series-3); }

/* Fixed height, so a chart takes the same room loading, empty or full. */
.chart { position: relative; height: 150px; margin-top: 0.5rem; padding: 0.4rem 0 1.4rem 3.6rem; font-size: 0.75rem; color: var(--muted); }
.chart .plot { position: relative; height: 100%; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart rect { fill: var(--key); }
.chart .line { fill: none; stroke: var(--key); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart .alarm { stroke: var(--status-bad); stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.chart .dot { fill: none; stroke: var(--key); stroke-width: 7; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .y-axis { position: absolute; left: 0; top: 0.4rem; bottom: 1.4rem; width: 3.2rem; }
.chart .y-axis span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart .x-axis { position: absolute; left: 3.6rem; right: 0; bottom: 0; height: 1.2rem; }
.chart .x-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart .no-data { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; }
.chart .crosshair { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--muted); pointer-events: none; }
.chart-bar .crosshair { border-left: 0; background: rgb(127 127 127 / 0.14); }
.chart-tip {
  position: absolute; top: 0; z-index: 2; pointer-events: none; min-width: 9rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15); padding: 0.4rem 0.6rem; font-size: 0.8rem;
}
.chart-tip .tip-label { color: var(--muted); margin-bottom: 0.2rem; white-space: nowrap; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.chart-tip .tip-row strong { font-variant-numeric: tabular-nums; }
.chart-tip .tip-row span:last-child { color: var(--muted); }
.chart-note { font-size: 0.8rem; margin: 0.4rem 0 0; }

.status-list { margin-bottom: 1rem; }
.status-list ul { list-style: none; margin: 0; padding: 0; }
.status-row { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 0.4rem 1rem; align-items: center; padding: 0.35rem 0; border-top: 1px solid var(--border); }
.status-row:first-child { border-top: 0; }
.status-name { display: flex; align-items: baseline; gap: 0.4rem; min-width: 0; }
.status-name .muted { overflow-wrap: anywhere; }
.status-dot {
  flex: none; display: inline-grid; place-items: center; width: 1.1rem; height: 1.1rem; border-radius: 50%;
  font-size: 0.7rem; font-weight: 700; color: #fff; background: var(--border); align-self: center;
}
.status-dot.ok { background: var(--status-ok); }
.status-dot.bad { background: var(--status-bad); }
.status-dot.warn { background: var(--warning-border); color: #1f2328; }
.status-strip { display: flex; gap: 2px; height: 1.1rem; }
.status-strip span { flex: 1; border-radius: 2px; background: var(--border); opacity: 0.6; }
.status-strip .ok { background: var(--status-ok); opacity: 0.55; }
.status-strip .bad { background: var(--status-bad); opacity: 1; }
@media (max-width: 640px) {
  .status-row { grid-template-columns: minmax(0, 1fr); }
  /* Wrapping buttons, like the Settings sections, instead of a strip that scrolls sideways. */
  .health-tabs { flex-wrap: wrap; border-bottom: 0; }
  .health-tabs a {
    padding: 0.3rem 0.8rem; margin-bottom: 0; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
  }
  .health-tabs a[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
  .segmented a { padding: 0.35rem 0.75rem; }
}

/* --- Ratings -------------------------------------------------------------- */
/* Five stars filled to a rating (library/stars.html), and the rating field
   (library/rating_input.html, static/js/rating.js). Each star is a mask over a
   gradient, so it can be filled to any width: --fill, set per star. */

:root {
  --star: #f2a900;
  --star-preview: #f7c64d;
  --star-empty: #d5d9de;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --star: #f5b72a;
    --star-preview: #b8913a;
    --star-empty: #3c4249;
  }
}
:root[data-theme="dark"] {
  --star: #f5b72a;
  --star-preview: #b8913a;
  --star-empty: #3c4249;
}

.rating { display: inline-flex; align-items: center; gap: 0.5rem; white-space: nowrap; vertical-align: middle; }
.stars { --size: 1.25rem; display: inline-flex; gap: 0.125rem; line-height: 0; }
.star {
  width: var(--size); height: var(--size); flex: none;
  background: linear-gradient(90deg, var(--star) var(--fill, 0%), var(--star-empty) var(--fill, 0%));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.6c.4 0 .8.2 1 .6l2.7 5.6 6.1.9c.9.1 1.3 1.3.6 1.9l-4.4 4.3 1 6.1c.2.9-.8 1.6-1.6 1.2L12 19.3l-5.4 2.9c-.8.4-1.8-.3-1.6-1.2l1-6.1-4.4-4.3c-.7-.6-.3-1.8.6-1.9l6.1-.9 2.7-5.6c.2-.4.6-.6 1-.6z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.6c.4 0 .8.2 1 .6l2.7 5.6 6.1.9c.9.1 1.3 1.3.6 1.9l-4.4 4.3 1 6.1c.2.9-.8 1.6-1.6 1.2L12 19.3l-5.4 2.9c-.8.4-1.8-.3-1.6-1.2l1-6.1-4.4-4.3c-.7-.6-.3-1.8.6-1.9l6.1-.9 2.7-5.6c.2-.4.6-.6 1-.6z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.rating-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.rating-small .stars { --size: 1rem; gap: 1px; }
.rating-small .rating-number { font-weight: 500; color: var(--muted); font-size: 0.9em; }
td.rating-col { white-space: nowrap; }
/* On a phone, the library's Rating column is one star and the number, to leave room for the title. */
.rating-small { gap: 0.375rem; }
.rating-small .star-one { --size: 1rem; display: none; }
@media (max-width: 640px) {
  .rating-small .stars { display: none; }
  .rating-small .star-one { display: block; }
  .rating-small .rating-number { color: var(--text); }
}

/* The rating field. */
.rating-control { display: none; }
.js .rating-control { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.875rem; }
.rating-stars {
  --size: 2.25rem; gap: 0.25rem; padding: 0.25rem; margin: -0.25rem;
  border-radius: var(--radius); cursor: pointer;
  /* Sideways drags rate; up-and-down swipes still scroll the page. */
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.rating-stars:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rating-input.is-previewing .star { --star: var(--star-preview); }
/* A fixed width, the same rated or not ("Not rated" takes the −/+ buttons' place), so nothing
   moves as the rating changes. Where it doesn't fit beside the stars, it wraps to its own row. */
.rating-readout {
  display: inline-flex; align-items: center; box-sizing: content-box; width: 8.5rem; height: 2.25rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.rating-readout .rating-number { flex: 1; min-width: 0; text-align: center; font-size: 1.125rem; }
.rating-input.is-previewing .rating-number { color: var(--muted); }
.rating-input.is-unrated .rating-readout { border-color: transparent; background: none; }
.rating-input.is-unrated .rating-number { font-weight: 400; font-size: 1rem; color: var(--muted); text-align: left; }
.rating-input.is-unrated .rating-step { display: none; }
.rating-step {
  width: 2.25rem; height: 2.25rem; padding: 0; border: 0; border-radius: 999px;
  background: none; color: var(--text); font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.rating-step:hover:not(:disabled) { background: var(--row-hover); color: var(--accent); }
.rating-step:disabled { opacity: 0.3; cursor: default; }
.rating-clear { font-size: 0.9rem; }
@media (pointer: coarse) {
  .rating-stars { --size: 2.75rem; }
  .rating-step { width: 2.75rem; height: 2.75rem; }
  .rating-readout { width: 9.5rem; height: 2.75rem; }
}
@media (max-width: 380px) {
  .rating-stars { --size: 2.35rem; }
}

/* Rating a book from its page. */
.book-rating { margin: 0.25rem 0 1.25rem; }
.book-rating .rating-status { display: block; height: 1.25rem; line-height: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 0.375rem; font-size: 0.875rem; }
.rating-status.is-saved { color: var(--success); }
.rating-status.is-error { color: var(--danger); }
html.js .no-js-only { display: none; }

/* Series and universe on the book form: a name box with suggestions (site.js), and the series' number beside it. */
/* The number goes under the series where the two don't fit side by side (phones). */
.list-name-row { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: flex-end; }
.combo { position: relative; flex: 1 1 11rem; min-width: 0; }
.series-number { flex: 0 0 8rem; }
.series-number[hidden] { display: none; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin: 0.2rem 0 0; padding: 0.25rem 0;
  list-style: none; max-height: 16rem; overflow-y: auto; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}
.combo-list li { padding: 0.45rem 0.75rem; cursor: pointer; }
.combo-list li:hover, .combo-list li[aria-selected="true"] { background: var(--row-hover); }
.combo-list li[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--accent); }
.combo-hint { min-height: 1.25rem; font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.combo-hint.is-new { color: var(--accent); }
.combo-hint:empty { min-height: 0; margin: 0; }

/* Long lists in Settings, and the library page's filter menus: a box to find one. */
.list-search { width: 100%; margin-bottom: 0.5rem; }

/* A book's page: the others in its series and universe. */
.related-books { margin-top: 1rem; }
.related-books h2 { margin-top: 0; font-size: 1.15rem; }
.related-books ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.related-books a { display: flex; align-items: center; gap: 0.75rem; padding: 0.35rem 0.5rem; border-radius: var(--radius); color: inherit; }
.related-books a:hover { background: var(--row-hover); text-decoration: none; }
.related-text { display: grid; min-width: 0; }
.related-title { font-weight: 600; color: var(--accent); }
.related-text .muted { font-size: 0.9rem; }


/* --- Tags --------------------------------------------------------------- */

/* A tag: a colored label (library/tag.html). Each color (Tag.Color) has a light and a dark
   shade set; .tag-<color> also colors the swatches and dots that pick it. */
.tag {
  display: inline-flex; align-items: center; gap: 0.3rem; max-width: 100%;
  padding: 0.2rem 0.6rem; border: 1px solid var(--tag-bd); border-radius: 999px;
  background: var(--tag-bg); color: var(--tag-fg);
  font-size: 0.8rem; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
a.tag:hover { text-decoration: none; filter: brightness(0.96); }
.tag.is-hidden { opacity: 0.6; }
.tag-list { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; vertical-align: top; }
dd.tag-list { display: flex; }
table.books td.tags-col { min-width: 8rem; max-width: 18rem; }
table.books .title-tags { display: none; }
@media (max-width: 640px) {
  /* The tags move under the title, so the table doesn't get too wide. */
  table.books .tags-col { display: none; }
  table.books .title-tags { display: flex; margin-top: 0.35rem; font-weight: 400; }
}
.tag-red { --tag-bg: #fde2e4; --tag-fg: #9b1c31; --tag-bd: #f3a3ad; }
.tag-orange { --tag-bg: #ffe8cc; --tag-fg: #8a4300; --tag-bd: #f8b878; }
.tag-yellow { --tag-bg: #fff3bf; --tag-fg: #6b5300; --tag-bd: #e9cc5c; }
.tag-lime { --tag-bg: #e9fac8; --tag-fg: #3f6212; --tag-bd: #b5e07a; }
.tag-green { --tag-bg: #d3f9d8; --tag-fg: #1e6b34; --tag-bd: #8fd6a0; }
.tag-teal { --tag-bg: #c3fae8; --tag-fg: #0c5e4c; --tag-bd: #74d6bb; }
.tag-cyan { --tag-bg: #c5f6fa; --tag-fg: #0b6070; --tag-bd: #7fd3df; }
.tag-blue { --tag-bg: #dbe4ff; --tag-fg: #2b3f9e; --tag-bd: #a4b6f3; }
.tag-purple { --tag-bg: #eebefa; --tag-fg: #6e1f84; --tag-bd: #d28ae6; }
.tag-pink { --tag-bg: #ffdeeb; --tag-fg: #9c1d5c; --tag-bd: #f2a1c4; }
.tag-brown { --tag-bg: #efe3d6; --tag-fg: #5c3d1e; --tag-bd: #cfb193; }
.tag-gray { --tag-bg: #e9ecef; --tag-fg: #3b434b; --tag-bd: #c3c9cf; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag-red { --tag-bg: #3b1219; --tag-fg: #ffb3bd; --tag-bd: #7a2633; }
  :root:not([data-theme="light"]) .tag-orange { --tag-bg: #3a1f0a; --tag-fg: #ffc58a; --tag-bd: #7a4415; }
  :root:not([data-theme="light"]) .tag-yellow { --tag-bg: #33290a; --tag-fg: #f5d77a; --tag-bd: #6b5615; }
  :root:not([data-theme="light"]) .tag-lime { --tag-bg: #1f2e0c; --tag-fg: #c6ec8a; --tag-bd: #4a6b1c; }
  :root:not([data-theme="light"]) .tag-green { --tag-bg: #10301a; --tag-fg: #9ee3b0; --tag-bd: #2a6b3c; }
  :root:not([data-theme="light"]) .tag-teal { --tag-bg: #0b2f28; --tag-fg: #8be8cf; --tag-bd: #1f6b5a; }
  :root:not([data-theme="light"]) .tag-cyan { --tag-bg: #0b2c33; --tag-fg: #95e3ee; --tag-bd: #1f6370; }
  :root:not([data-theme="light"]) .tag-blue { --tag-bg: #18213f; --tag-fg: #b3c3ff; --tag-bd: #34478a; }
  :root:not([data-theme="light"]) .tag-purple { --tag-bg: #2e1438; --tag-fg: #e8b3f7; --tag-bd: #6b2f80; }
  :root:not([data-theme="light"]) .tag-pink { --tag-bg: #3a1228; --tag-fg: #ffb3d4; --tag-bd: #7d2856; }
  :root:not([data-theme="light"]) .tag-brown { --tag-bg: #2e2218; --tag-fg: #e3c9ad; --tag-bd: #6b5038; }
  :root:not([data-theme="light"]) .tag-gray { --tag-bg: #2a2f35; --tag-fg: #d0d5da; --tag-bd: #4a525a; }
}
:root[data-theme="dark"] .tag-red { --tag-bg: #3b1219; --tag-fg: #ffb3bd; --tag-bd: #7a2633; }
:root[data-theme="dark"] .tag-orange { --tag-bg: #3a1f0a; --tag-fg: #ffc58a; --tag-bd: #7a4415; }
:root[data-theme="dark"] .tag-yellow { --tag-bg: #33290a; --tag-fg: #f5d77a; --tag-bd: #6b5615; }
:root[data-theme="dark"] .tag-lime { --tag-bg: #1f2e0c; --tag-fg: #c6ec8a; --tag-bd: #4a6b1c; }
:root[data-theme="dark"] .tag-green { --tag-bg: #10301a; --tag-fg: #9ee3b0; --tag-bd: #2a6b3c; }
:root[data-theme="dark"] .tag-teal { --tag-bg: #0b2f28; --tag-fg: #8be8cf; --tag-bd: #1f6b5a; }
:root[data-theme="dark"] .tag-cyan { --tag-bg: #0b2c33; --tag-fg: #95e3ee; --tag-bd: #1f6370; }
:root[data-theme="dark"] .tag-blue { --tag-bg: #18213f; --tag-fg: #b3c3ff; --tag-bd: #34478a; }
:root[data-theme="dark"] .tag-purple { --tag-bg: #2e1438; --tag-fg: #e8b3f7; --tag-bd: #6b2f80; }
:root[data-theme="dark"] .tag-pink { --tag-bg: #3a1228; --tag-fg: #ffb3d4; --tag-bd: #7d2856; }
:root[data-theme="dark"] .tag-brown { --tag-bg: #2e2218; --tag-fg: #e3c9ad; --tag-bd: #6b5038; }
:root[data-theme="dark"] .tag-gray { --tag-bg: #2a2f35; --tag-fg: #d0d5da; --tag-bd: #4a525a; }

/* The tag's Edit page shows it in both themes, whichever one the page is in. */
.tag-preview { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.tag-preview > div { padding: 0.6rem 0.9rem; border-radius: var(--radius); border: 1px solid; }
.tag-preview .tag-preview-light { background: #ffffff; border-color: #d8dce1; }
.tag-preview .tag-preview-dark { background: #1f2226; border-color: #353a40; }
.tag-preview .tag-preview-light .tag-red { --tag-bg: #fde2e4; --tag-fg: #9b1c31; --tag-bd: #f3a3ad; }
.tag-preview .tag-preview-light .tag-orange { --tag-bg: #ffe8cc; --tag-fg: #8a4300; --tag-bd: #f8b878; }
.tag-preview .tag-preview-light .tag-yellow { --tag-bg: #fff3bf; --tag-fg: #6b5300; --tag-bd: #e9cc5c; }
.tag-preview .tag-preview-light .tag-lime { --tag-bg: #e9fac8; --tag-fg: #3f6212; --tag-bd: #b5e07a; }
.tag-preview .tag-preview-light .tag-green { --tag-bg: #d3f9d8; --tag-fg: #1e6b34; --tag-bd: #8fd6a0; }
.tag-preview .tag-preview-light .tag-teal { --tag-bg: #c3fae8; --tag-fg: #0c5e4c; --tag-bd: #74d6bb; }
.tag-preview .tag-preview-light .tag-cyan { --tag-bg: #c5f6fa; --tag-fg: #0b6070; --tag-bd: #7fd3df; }
.tag-preview .tag-preview-light .tag-blue { --tag-bg: #dbe4ff; --tag-fg: #2b3f9e; --tag-bd: #a4b6f3; }
.tag-preview .tag-preview-light .tag-purple { --tag-bg: #eebefa; --tag-fg: #6e1f84; --tag-bd: #d28ae6; }
.tag-preview .tag-preview-light .tag-pink { --tag-bg: #ffdeeb; --tag-fg: #9c1d5c; --tag-bd: #f2a1c4; }
.tag-preview .tag-preview-light .tag-brown { --tag-bg: #efe3d6; --tag-fg: #5c3d1e; --tag-bd: #cfb193; }
.tag-preview .tag-preview-light .tag-gray { --tag-bg: #e9ecef; --tag-fg: #3b434b; --tag-bd: #c3c9cf; }
.tag-preview .tag-preview-dark .tag-red { --tag-bg: #3b1219; --tag-fg: #ffb3bd; --tag-bd: #7a2633; }
.tag-preview .tag-preview-dark .tag-orange { --tag-bg: #3a1f0a; --tag-fg: #ffc58a; --tag-bd: #7a4415; }
.tag-preview .tag-preview-dark .tag-yellow { --tag-bg: #33290a; --tag-fg: #f5d77a; --tag-bd: #6b5615; }
.tag-preview .tag-preview-dark .tag-lime { --tag-bg: #1f2e0c; --tag-fg: #c6ec8a; --tag-bd: #4a6b1c; }
.tag-preview .tag-preview-dark .tag-green { --tag-bg: #10301a; --tag-fg: #9ee3b0; --tag-bd: #2a6b3c; }
.tag-preview .tag-preview-dark .tag-teal { --tag-bg: #0b2f28; --tag-fg: #8be8cf; --tag-bd: #1f6b5a; }
.tag-preview .tag-preview-dark .tag-cyan { --tag-bg: #0b2c33; --tag-fg: #95e3ee; --tag-bd: #1f6370; }
.tag-preview .tag-preview-dark .tag-blue { --tag-bg: #18213f; --tag-fg: #b3c3ff; --tag-bd: #34478a; }
.tag-preview .tag-preview-dark .tag-purple { --tag-bg: #2e1438; --tag-fg: #e8b3f7; --tag-bd: #6b2f80; }
.tag-preview .tag-preview-dark .tag-pink { --tag-bg: #3a1228; --tag-fg: #ffb3d4; --tag-bd: #7d2856; }
.tag-preview .tag-preview-dark .tag-brown { --tag-bg: #2e2218; --tag-fg: #e3c9ad; --tag-bd: #6b5038; }
.tag-preview .tag-preview-dark .tag-gray { --tag-bg: #2a2f35; --tag-fg: #d0d5da; --tag-bd: #4a525a; }

/* Picking a color: round swatches (forms.ColorChoices, and the Settings popover). */
.swatches { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.swatch {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--tag-bd); background: var(--tag-bg); color: var(--tag-fg);
}
.swatches .swatch { display: inline-flex; margin: 0; font-weight: 700; line-height: 1; }
.swatch:hover { filter: brightness(0.95); background: var(--tag-bg); }
.swatch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.swatch:has(input:checked), .swatch.is-current { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch:has(input:checked)::after, .swatch.is-current::after { content: "✓"; font-weight: 700; font-size: 0.9rem; }
.swatch:has(input:focus-visible), .swatch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch-auto {
  --tag-bd: var(--border);
  background: conic-gradient(#f3a3ad, #f8b878, #e9cc5c, #8fd6a0, #7fd3df, #a4b6f3, #d28ae6, #f2a1c4, #f3a3ad);
  color: #1f2328; font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
}
.swatch-auto:has(input:checked)::after { content: none; }
.swatches .swatch-auto > span[aria-hidden] {
  font-size: 0.5rem; letter-spacing: 0; line-height: 1; padding: 0.1rem 0.15rem;
  border-radius: 3px; background: rgba(255, 255, 255, 0.85); pointer-events: none;
}

/* The book form's tags box (site.js): the tags so far, then a box to type another. */
.tag-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; min-height: 2.6rem; padding: 0.3rem 0.5rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: text;
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30, 122, 214, 0.18); }
.tag-input input { flex: 1 1 8rem; min-width: 6rem; width: auto; padding: 0.25rem; border: 0; background: transparent; box-shadow: none; }
.tag-input input:focus { outline: none; box-shadow: none; }
.tag-remove {
  padding: 0 0.1rem; margin: 0 -0.2rem 0 0; border: 0; background: none; color: inherit; opacity: 0.7;
  font: inherit; font-weight: 700; line-height: 1; cursor: pointer;
}
.tag-remove:hover { opacity: 1; background: none; }
.tags-field .combo-list li { display: flex; align-items: center; gap: 0.5rem; }
.tags-field .combo-list .muted { margin-left: auto; font-size: 0.85rem; }
.tags-field .combo-list li.combo-new { border-top: 1px solid var(--border); }
