/* Bibliobyte — single site stylesheet */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6770;
  --border: #d8dce1;
  --accent: #1e7ad6;
  --accent-hover: #1665b3;
  --accent-text: #ffffff;
  --header-bg: #26292e;
  --header-text: #f4f5f7;
  --danger: #c62828;
  --danger-hover: #a51f1f;
  --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;
    --header-bg: #0f1113;
    --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;
  --header-bg: #0f1113;
  --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);
}
.site-header .inner {
  display: flex;
  align-items: center;
  gap: 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; }
.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 { 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; }

@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 .dismiss { background: none; border: 0; color: inherit; font-size: 1.2rem; cursor: pointer; padding: 0 0.25rem; }

/* --- 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; }
.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);
}
.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); }

/* --- 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; }

.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 {
  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; }
.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; }
.isbn-status:empty { display: none; }
.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 { 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; }
.cover-actions { display: flex; justify-content: center; gap: 1rem; margin-top: 0.5rem; }

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;
}
