/*
 * Bookshelf styles.
 *
 * Plain CSS served by Propshaft (no build step). Colours, spacing and fonts
 * are defined once as variables in :root, then reused everywhere, so changing
 * the look of the whole app means editing just those variables.
 */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-muted: #f1ede5;
  --text: #1f1b16;
  --text-muted: #6b6258;
  --border: #e4ddd1;
  --primary: #7a3e1d;
  --primary-hover: #5f2f15;
  --primary-soft: #f6e9df;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #1f7a4d;
  --success-soft: #e6f4ec;
  --star: #e0a526;
  --star-empty: #ddd4c6;
  --chart: #b5501f;       /* validated for charts on the light surface */
  --chart-grid: #ece6dc;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(31 27 22 / 0.06), 0 4px 16px rgb(31 27 22 / 0.06);
  --shadow-lift: 0 2px 4px rgb(31 27 22 / 0.08), 0 12px 32px rgb(31 27 22 / 0.12);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171411;
    --surface: #221e1a;
    --surface-muted: #2b2621;
    --text: #f3eee7;
    --text-muted: #a89e92;
    --border: #3a332c;
    --primary: #e0a37a;
    --primary-hover: #eebb98;
    --primary-soft: #3a2a1f;
    --danger: #f28b82;
    --danger-soft: #3b1f1c;
    --success: #7fd1a4;
    --success-soft: #1c3327;
    --star-empty: #5a5047;
    --chart: #d9703a;     /* validated for charts on the dark surface */
    --chart-grid: #332d27;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.35), 0 12px 32px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

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

/* Elements with the `hidden` attribute stay hidden even if a class sets `display`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.2;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}
h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); }
h2 { font-size: 1.25rem; }

p { margin: 0 0 1rem; }

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

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

main.container {
  flex: 1;
  padding-block: 2rem 4rem;
}

/* ---------- Header / navigation ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand svg { color: var(--primary); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-main {
  display: flex;
  gap: 0.15rem;
  margin-right: auto;
  margin-left: 1rem;
}

.nav-link {
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.nav-link:hover { color: var(--text); background: var(--surface-muted); text-decoration: none; }
.nav-link.active { color: var(--text); background: var(--surface-muted); }

.nav-count {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  margin-left: 0.2rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: 1px;
}

.nav-user {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.nav-user-name { color: var(--text); font-weight: 600; }

.nav-links form { margin: 0; }

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* Medium screens: drop "Signed in as…" so everything fits on one row. */
@media (max-width: 1000px) {
  .nav-user { display: none; }
}

/* Small screens: the page links get their own centred row. */
@media (max-width: 800px) {
  .nav { padding-block: 0.5rem; }
  .nav-main { margin: 0; order: 3; width: 100%; justify-content: center; flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .nav { justify-content: center; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn-primary, .btn-primary:hover { color: #1f1b16; }
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-muted); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-muted); color: var(--text); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-block { width: 100%; padding-block: 0.75rem; }

/* ---------- Flash messages ---------- */
.flash {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-notice { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.flash-alert { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

/* ---------- Forms ---------- */
.form { display: grid; gap: 1.1rem; }

.field { display: grid; gap: 0.35rem; }

.field label {
  font-size: 0.9rem;
  font-weight: 600;
}

.field-hint { font-size: 0.85rem; color: var(--text-muted); }

.input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--text-muted); opacity: 0.8; }
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea.input { min-height: 8rem; resize: vertical; }

/* Rails wraps fields that failed validation in .field_with_errors */
.field_with_errors { display: contents; }
.field_with_errors .input { border-color: var(--danger); }
.field_with_errors label { color: var(--danger); }

.form-errors {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
}
.form-errors h2 {
  font-family: var(--font-body);
  font-size: 0.95rem;
  margin: 0 0 0.35rem;
}
.form-errors ul { margin: 0; padding-left: 1.2rem; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}
.checkbox-field input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.15rem 0 0;
  accent-color: var(--primary);
}
.checkbox-field label { display: block; }

.form-row {
  display: grid;
  gap: 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* ---------- Auth pages (sign in / sign up / passwords) ---------- */
.auth {
  display: grid;
  place-items: center;
  padding-block: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-header p { margin: 0; }

.auth-icon {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 1rem;
}

.auth-footer {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.auth-footer p { margin: 0.25rem 0; }

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.label-row a { font-size: 0.85rem; font-weight: 500; }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.page-header p { margin: 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}

/* ---------- Book cover (generated, coloured by title) ---------- */
.book-cover {
  --hue: 20;
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 4px 10px 10px 4px;
  padding: 1rem 1rem 1rem 1.4rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  background:
    linear-gradient(90deg, rgb(0 0 0 / 0.25) 0 6px, rgb(255 255 255 / 0.12) 6px 8px, transparent 8px),
    linear-gradient(160deg, hsl(var(--hue) 45% 42%), hsl(calc(var(--hue) + 25) 50% 28%));
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08), var(--shadow);
  overflow: hidden;
}

.exchange-badge {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.92);
  color: #1f7a4d;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
}
/* Leave room so a long title doesn't run under the badge. */
.book-cover:has(.exchange-badge) .book-cover-title { margin-top: 1.4rem; }

.book-cover-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: balance;
}

.book-cover-author {
  font-size: 0.8rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* A real cover image instead of the generated one */
.book-cover-image {
  padding: 0;
  background: var(--surface-muted);
}
.book-cover-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Search (books page) ---------- */
.search-form {
  display: flex;
  gap: 0.5rem;
  max-width: 560px;
  margin-bottom: 1rem;
}
.search-input {
  flex: 1;
  padding-left: 2.4rem;
  /* magnifying-glass icon drawn as an inline SVG background */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238a8178' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.75rem center;
}
.search-summary { margin-bottom: 1.5rem; }

/* While Turbo loads new results, fade the old ones slightly. */
turbo-frame#books_results[busy] { opacity: 0.6; transition: opacity 0.15s; }

/* ---------- Book grid (index page) ---------- */
.book-grid {
  display: grid;
  gap: 1.75rem 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  color: var(--text);
}
.book-card:hover { text-decoration: none; color: var(--text); }
.book-card .book-cover { transition: transform 0.2s, box-shadow 0.2s; }
.book-card:hover .book-cover {
  transform: translateY(-4px) rotate(-0.5deg);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08), var(--shadow-lift);
}

.book-card-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.book-card-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text-muted);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card-meta { font-size: 0.9rem; color: var(--text-muted); margin: 0; }
.book-card-owner { font-size: 0.8rem; color: var(--text-muted); margin: 0.15rem 0 0; opacity: 0.85; }

/* ---------- Book detail (show page) ---------- */
.book-detail {
  display: grid;
  gap: 2.5rem;
  grid-template-columns: minmax(180px, 260px) 1fr;
  align-items: start;
}
@media (max-width: 640px) {
  .book-detail { grid-template-columns: 1fr; }
  .book-detail .book-cover { max-width: 220px; }
}

.book-subtitle {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-style: italic;
  color: var(--text-muted);
  margin: -0.25rem 0 0.5rem;
}

.book-detail-author {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.meta-list {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.pill a { color: var(--text); font-weight: 600; }

.pill.pill-exchange {
  background: var(--success-soft);
  color: var(--success);
}

.pill {
  /* inline-block (not flex) so spaces around a link inside are kept */
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.book-description {
  font-size: 1.05rem;
  max-width: 65ch;
  white-space: pre-line;
}

.book-review {
  display: block; /* <turbo-frame> is inline by default */
  margin-top: 2rem;
  max-width: 65ch;
}

.book-review-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.book-review-header a { font-size: 0.9rem; font-weight: 500; }

.review-form { margin-top: 0.75rem; }
.review-form textarea.input { min-height: 10rem; }

.book-review-text {
  margin: 0.75rem 0 0;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--primary-soft);
  font-family: var(--font-display);
  font-size: 1.1rem;
  line-height: 1.65;
  white-space: pre-line;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.actions form { margin: 0; }

.admin-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.9rem;
  color: var(--primary);
}

/* ---------- Ratings ---------- */
.rating-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rating-summary {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.stars-display {
  display: inline-flex;
  gap: 0.05em;
  font-size: 1.15rem;
  line-height: 1;
}
.star-full  { color: var(--star); }
.star-empty { color: var(--star-empty); }
/* Half star: paint the glyph with a half-gold, half-grey background and
   let that background show through the letter shape. */
.star-half {
  background: linear-gradient(90deg, var(--star) 50%, var(--star-empty) 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.rating-average { font-size: 1.1rem; }

.rate {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

.rate-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Stars are in the page as 5,4,3,2,1 and shown reversed (1..5), so
   "this star and every star after it in the page" = "this star and the
   ones to its left" on screen. */
.star-input {
  display: flex;
  flex-direction: row-reverse;
}

.star-form { margin: 0; }

.star {
  padding: 0 0.1rem;
  border: 0;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--star-empty);
  cursor: pointer;
  transition: color 0.1s, transform 0.1s;
}
.star-on { color: var(--star); }

.star-input:hover .star { color: var(--star-empty); }
.star-form:hover .star,
.star-form:hover ~ .star-form .star { color: #f0b93a; }
.star-form:hover .star { transform: scale(1.15); }
.star:focus-visible { outline: 2px solid var(--primary); border-radius: 4px; }

.remove-rating { margin: 0; }

.rate-note { margin: 0; font-size: 0.9rem; }

.book-card-rating {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
}
.book-card-rating span[aria-hidden] { color: var(--star); }

/* ---------- Comments ---------- */
.comments {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  max-width: 65ch;
  scroll-margin-top: 80px; /* keep the heading clear of the sticky header */
}

.comments h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
}

.comment-list {
  display: grid;
  gap: 1rem;
  margin: 1.25rem 0;
}
.comment-list:has(.comment) { margin-bottom: 1.75rem; }

/* Show "No comments yet" only while the list has no comments in it. */
.no-comments { display: none; }
.comments:not(:has(.comment)) .no-comments { display: block; }

.comment {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  align-items: start;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.avatar {
  --hue: 20;
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: hsl(var(--hue) 45% 88%);
  color: hsl(var(--hue) 50% 28%);
  font-size: 0.85rem;
  font-weight: 700;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  font-size: 0.95rem;
}
.comment-meta .badge { margin-left: 0; }
.comment-author { color: var(--text); font-weight: 700; }
.comment-meta time { font-size: 0.85rem; color: var(--text-muted); }

.comment-body {
  margin: 0.25rem 0 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.comment form { margin: 0; }

.comment-thread { display: grid; gap: 0.6rem; }

.replies {
  display: grid;
  gap: 0.6rem;
  margin-left: 1.6rem;
  padding-left: 1rem;
  border-left: 2px solid var(--border);
}
.replies:empty { display: none; }

.comment-reply { background: var(--surface-muted); border-color: transparent; }
.comment-reply .avatar { width: 2rem; height: 2rem; font-size: 0.75rem; }

.comment-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.4rem;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.link-button:hover { color: var(--primary); text-decoration: underline; }
.link-button-danger:hover { color: var(--danger); }

.reply-form {
  margin-left: 2.6rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 0.75rem;
}
.reply-form label { font-size: 0.85rem; }
.reply-form textarea.input { min-height: 4.5rem; }
.reply-form .form-actions { margin-top: 0; }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.comment-form textarea.input { min-height: 5.5rem; }

/* ---------- Members & profiles ---------- */
.member-list {
  display: grid;
  gap: 0.75rem;
  max-width: 720px;
}

.member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.member-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  color: var(--text);
}
.member-link:hover { text-decoration: none; }
.member-link:hover .member-name { color: var(--primary); }

.member-name { font-weight: 700; }
.member-meta { display: block; font-size: 0.85rem; color: var(--text-muted); }

.follow-box {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.follow-box form { margin: 0; }
.follow-count { font-size: 0.9rem; color: var(--text-muted); }
.follow-count:hover { color: var(--primary); }

.profile {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
}
.profile h1 { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.2rem; }
.profile-main p { margin-bottom: 0.9rem; }

.profile-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  color: var(--text-muted);
}
.profile-stats > a { color: var(--text-muted); }
.profile-stats > a:hover { color: var(--primary); }
.profile-stats strong { color: var(--text); }
.profile-stats .follow-count { font-size: 1rem; }

.avatar-lg { width: 5rem; height: 5rem; font-size: 1.6rem; }

.section-title { margin-bottom: 1.25rem; }

/* ---------- Exchange requests ---------- */
.exchange-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1.1rem;
  background: var(--success-soft);
  border: 1px solid color-mix(in srgb, var(--success) 20%, transparent);
  border-radius: var(--radius);
}
.exchange-panel form { margin: 0; }
.exchange-panel-actions { display: flex; gap: 0.5rem; }

.mini-cover {
  --hue: 20;
  flex: none;
  display: flex;
  align-items: flex-end;
  width: 3.4rem;
  aspect-ratio: 2 / 3;
  padding: 0.3rem 0.3rem 0.3rem 0.45rem;
  border-radius: 2px 5px 5px 2px;
  background:
    linear-gradient(90deg, rgb(0 0 0 / 0.25) 0 3px, transparent 3px),
    linear-gradient(160deg, hsl(var(--hue) 45% 42%), hsl(calc(var(--hue) + 25) 50% 28%));
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.55rem;
  line-height: 1.15;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.mini-cover:hover { text-decoration: none; color: #fff; transform: translateY(-2px); }
.mini-cover span { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.mini-cover-image { padding: 0; background: var(--surface-muted); }
.mini-cover-image img { width: 100%; height: 100%; object-fit: cover; }

.mini-cover-empty {
  align-items: center;
  justify-content: center;
  background: var(--surface-muted);
  border: 2px dashed var(--border);
  box-shadow: none;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.request-target {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0 1.5rem;
  padding: 0.9rem;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
}
.request-target p { margin: 0; }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

.request-list { display: grid; gap: 1rem; max-width: 760px; }

.request {
  display: flex;
  gap: 1.25rem;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.request-declined, .request-cancelled { opacity: 0.7; }

.request-books { display: flex; align-items: center; gap: 0.4rem; flex: none; }
.request-swap { color: var(--text-muted); font-size: 1.1rem; }

.request-main { flex: 1; min-width: 0; }
.request-summary { margin: 0 0 0.2rem; font-weight: 500; }
.request-summary a { font-weight: 700; }
.request-offer { margin: 0 0 0.6rem; font-size: 0.9rem; }

.request-message {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.85rem;
  border-left: 3px solid var(--border);
  background: var(--surface-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-line;
}

.request-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.request-actions { display: flex; gap: 0.5rem; margin-left: auto; }
.request-actions form { margin: 0; }

.status {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-pending   { background: #fdf3dc; color: #8a5a00; }
.status-accepted  { background: var(--success-soft); color: var(--success); }
.status-declined,
.status-cancelled { background: var(--surface-muted); color: var(--text-muted); }
@media (prefers-color-scheme: dark) {
  .status-pending { background: #3a2f17; color: #f0c261; }
}

.request-contact {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.85rem;
  background: var(--success-soft);
  color: var(--success);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.request-contact a { color: inherit; font-weight: 700; }

@media (max-width: 560px) {
  .request { flex-direction: column; }
  .request-actions { margin-left: 0; }
}

/* ---------- Welcome page (visitors) ---------- */
.btn-lg { padding: 0.8rem 1.4rem; font-size: 1rem; }

.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 3rem;
  align-items: center;
  padding-block: 1.5rem 3.5rem;
}
@media (max-width: 800px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; }
}

.eyebrow {
  margin-bottom: 0.75rem;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 { font-size: clamp(2rem, 4.5vw, 3rem); margin-bottom: 1rem; }
.hero-lead { font-size: 1.15rem; color: var(--text-muted); max-width: 52ch; margin-bottom: 1.75rem; }

.hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem 1.25rem;
}

/* A little fan of three covers */
.hero-covers {
  position: relative;
  height: 320px;
  max-width: 380px;
  width: 100%;
  justify-self: center;
}
.hero-covers .book-cover {
  position: absolute;
  width: 170px;
  top: 30px;
  box-shadow: var(--shadow-lift);
}
.hero-covers .book-cover:nth-child(1) { left: 0; transform: rotate(-8deg); }
.hero-covers .book-cover:nth-child(2) { left: 50%; margin-left: -85px; top: 0; z-index: 2; }
.hero-covers .book-cover:nth-child(3) { right: 0; transform: rotate(8deg); }
.hero-covers .exchange-badge { display: none; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1.25rem;
  margin-bottom: 3.5rem;
}
.feature {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.feature-icon {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.85rem;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.3rem;
}
.feature h2 { font-size: 1.15rem; }
.feature p { margin: 0; color: var(--text-muted); }

.how-it-works { margin-bottom: 3.5rem; }
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  counter-increment: step;
  position: relative;
  padding: 1.25rem 1.25rem 1.25rem 4rem;
  background: var(--surface-muted);
  border-radius: var(--radius);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 1.25rem;
  top: 1.15rem;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .steps li::before { color: #1f1b16; }
}
.steps strong { display: block; }
@media (max-width: 600px) {
  .steps { grid-template-columns: 1fr; }
}

.recent { margin-bottom: 3.5rem; }
.book-card-static { cursor: default; }
/* Six covers in one row on a computer, two per row on a phone */
.recent-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

.cta {
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cta p { margin-bottom: 1.25rem; }

/* ---------- Home dashboard (members) ---------- */
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-bottom: 1.25rem;
}
.section-heading h2 { margin: 0; }
.section-heading p { margin: 0; }
.section-heading a { font-weight: 600; font-size: 0.95rem; }

.welcome {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}
.welcome p { margin: 0; }
.attention a { color: var(--primary); }

.checklist { margin-bottom: 2.5rem; padding: 1.5rem; max-width: 760px; }
.checklist-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.checklist-header h2 { margin: 0; }

.progress {
  height: 6px;
  margin: 0.85rem 0 1.25rem;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--success);
  border-radius: inherit;
}

.checklist-steps {
  display: grid;
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.checklist-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.check {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.05rem;
  border: 2px solid var(--border);
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
}
.checklist-step.done .check { background: var(--success); border-color: var(--success); color: #fff; }
.checklist-step.done .step-label { color: var(--text-muted); text-decoration: line-through; }
.step-label { font-weight: 600; }
.step-hint { display: block; font-size: 0.88rem; color: var(--text-muted); }

.home-section { margin-bottom: 2.75rem; }
.home-empty {
  padding: 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Admin reports ---------- */
.report-section { margin-bottom: 2.75rem; }
.report-section > h2 { margin-bottom: 1rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
}
.stat-tile {
  display: grid;
  gap: 0.2rem;
  align-content: start;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.stat-value { font-size: 1.9rem; font-weight: 650; line-height: 1.1; }
.stat-detail { font-size: 0.82rem; color: var(--text-muted); }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}
.chart {
  margin: 0;
  padding: 1.1rem 1.25rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.chart-header h3 { margin: 0; font-family: var(--font-body); font-size: 1rem; }
.chart-total { color: var(--text); }

.chart-plot { display: flex; gap: 0.5rem; height: 160px; }
.chart-axis-y {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
  min-width: 1.5rem;
  transform: translateY(-0.45em);
}
.chart-axis-y span:last-child { transform: translateY(0.9em); }

.chart-area {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: end;
  border-top: 1px solid var(--chart-grid);    /* top gridline */
  border-bottom: 1px solid var(--border);     /* baseline */
}

/* Each column is the hover/focus target: the full height, not just the bar */
.chart-col {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 100%;
  outline: none;
}
.chart-bar {
  position: relative;
  width: min(24px, 60%);
  min-height: 2px;
  background: var(--chart);
  border-radius: 4px 4px 0 0;   /* rounded data-end, square at the baseline */
  transition: filter 0.1s;
}
.chart-col:hover .chart-bar,
.chart-col:focus-visible .chart-bar { filter: brightness(1.15); }
.chart-col:focus-visible { box-shadow: inset 0 0 0 2px var(--primary-soft); border-radius: 4px; }

.chart-cap {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -2px);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
}

.chart-tip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  z-index: 5;
  display: none;
  transform: translateX(-50%);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.chart-tip strong { font-size: 0.95rem; }
.chart-tip span { display: block; opacity: 0.8; }
.chart-col:hover .chart-tip,
.chart-col:focus-visible .chart-tip { display: block; }

.chart-axis-x {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin: 0.4rem 0 0 2rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

.chart-table { margin-top: 0.75rem; font-size: 0.85rem; }
.chart-table summary { cursor: pointer; color: var(--text-muted); font-weight: 600; }
.chart-table table { width: 100%; margin-top: 0.5rem; border-collapse: collapse; }
.chart-table th, .chart-table td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
.chart-table td:last-child, .chart-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  align-items: start;
}
.report-card {
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.report-card h3 { font-family: var(--font-body); font-size: 1rem; margin-bottom: 0.75rem; }
.report-card > p:last-child { margin: 0; }
.report-card-note { margin-bottom: 0.5rem; font-size: 0.85rem; }
@media (min-width: 900px) {
  .report-card-wide { grid-row: span 2; }
}

.report-list {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding-left: 1.2rem;
}
ul.report-list { list-style: none; padding-left: 0; }
.report-list li { line-height: 1.4; }
.report-list li > .muted { display: block; font-size: 0.85rem; }
.report-list q { display: block; margin: 0.15rem 0; font-style: italic; }

.tags { display: inline-flex; gap: 0.3rem; margin-left: 0.3rem; }
.tag {
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-top: 2rem;
}
.pagination-info { font-size: 0.95rem; text-align: center; }
.pagination [aria-disabled="true"] { opacity: 0.45; cursor: default; pointer-events: none; }

/* ---------- Settings ---------- */
.settings { max-width: 720px; }
.settings .tabs { flex-wrap: wrap; }
.settings-card h2 { margin-bottom: 1rem; }
.danger-list { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--text-muted); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state svg { color: var(--text-muted); margin-bottom: 1rem; }
.empty-state p { max-width: 36ch; margin-inline: auto; margin-bottom: 1.5rem; }

/* ---------- Cover picker (book form) ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.field-label { font-size: 0.9rem; font-weight: 600; }

.cover-field-body {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.cover-preview {
  flex: none;
  display: grid;
  place-items: center;
  width: 5.5rem;
  aspect-ratio: 2 / 3;
  border-radius: 4px 8px 8px 4px;
  border: 2px dashed var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
  overflow: hidden;
}
.cover-preview:has(img) { border-style: solid; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }

.cover-field-options { display: grid; gap: 0.6rem; }
.cover-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.file-button { position: relative; }
.file-button:focus-within { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
.remove-cover { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

#cover_results:not(:empty) {
  display: block;
  margin-top: 0.5rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}
.cover-results-message { margin: 0 0 0.6rem; font-size: 0.9rem; color: var(--text-muted); }
.cover-results-message:only-child { margin: 0; }

.cover-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.75rem;
}

.cover-result {
  display: grid;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.cover-result:hover { border-color: var(--border); }
.cover-result[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.cover-result img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 3px;
  background: var(--surface-muted);
}
.cover-result-title {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cover-result-meta { font-size: 0.72rem; color: var(--text-muted); }

/* ---------- Narrow form pages ---------- */
.form-page { max-width: 640px; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}
