/* parmalambë — an antiquarian reading-room aesthetic.
   Warm paper, oak, ink and oxblood; a serif voice; a little gilt. */

:root {
  --paper:      #f4ecd8;
  --paper-deep: #e9dcc0;
  --ink:        #2b2117;
  --ink-soft:   #5a4a36;
  --oxblood:    #7d2b21;
  --oxblood-dk: #5e1f17;
  --gilt:       #b08328;
  --forest:     #3a5240;
  --rule:       #c9b48a;
  --card:       #fbf5e6;
  --shadow:     rgba(43, 33, 23, 0.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "EB Garamond", "Iowan Old Style", Georgia, serif;
  font-size: 1.12rem;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  /* subtle layered "laid paper" texture, no images */
  background-image:
    repeating-linear-gradient(0deg, rgba(120,90,40,0.035) 0 1px, transparent 1px 4px),
    radial-gradient(120% 80% at 50% -10%, rgba(176,131,40,0.10), transparent 60%),
    radial-gradient(80% 60% at 100% 110%, rgba(125,43,33,0.06), transparent 55%);
  min-height: 100vh;
}

h1, h2, h3, .display {
  font-family: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  margin: 0 0 0.4em;
}

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

/* ---------- masthead ---------- */
.masthead {
  border-bottom: 3px double var(--rule);
  background:
    linear-gradient(180deg, rgba(255,250,238,0.7), rgba(233,220,192,0.4));
  padding: 1.4rem 1.5rem 1rem;
  text-align: center;
}
.masthead .wordmark {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--ink);
}
.masthead .wordmark a { color: inherit; }
.masthead .wordmark a:hover { text-decoration: none; color: var(--oxblood); }
.masthead .tagline {
  font-style: italic;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  font-size: 0.98rem;
  margin-top: 0.25rem;
}
.masthead .filigree {
  color: var(--gilt);
  letter-spacing: 0.5em;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
nav.rule-nav {
  margin-top: 0.7rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 0.95rem;
}
nav.rule-nav a { margin: 0 0.7rem; color: var(--ink-soft); }
nav.rule-nav a:hover { color: var(--oxblood); }

/* ---------- layout ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 1.8rem 1.5rem 4rem; }
.flash {
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--gilt);
  padding: 0.7rem 1rem;
  margin-bottom: 1.4rem;
  font-style: italic;
  color: var(--ink-soft);
  box-shadow: 0 1px 4px var(--shadow);
}

/* ---------- search ---------- */
.searchbar { display: flex; gap: 0.6rem; margin: 0.5rem 0 1.6rem; flex-wrap: wrap; }
.searchbar input[type=text] {
  flex: 1 1 320px;
  font-family: inherit; font-size: 1.1rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  border-radius: 2px;
}
.searchbar input[type=text]:focus { outline: 2px solid var(--gilt); }

.btn {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.05rem; font-variant: small-caps; letter-spacing: 0.08em;
  background: var(--oxblood); color: #f7eeda;
  border: 1px solid var(--oxblood-dk);
  padding: 0.55rem 1.2rem; border-radius: 2px; cursor: pointer;
  box-shadow: 0 1px 3px var(--shadow);
}
.btn:hover { background: var(--oxblood-dk); }
.btn.ghost { background: transparent; color: var(--oxblood); }
.btn.small { font-size: 0.92rem; padding: 0.3rem 0.7rem; }

/* ---------- genre rail ---------- */
.genre-rail { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.6rem; }
.genre-chip {
  display: inline-flex; align-items: baseline; gap: 0.4rem;
  border: 1px solid var(--rule); background: var(--card);
  padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.9rem;
  color: var(--ink-soft);
}
.genre-chip .dot {
  width: 0.6rem; height: 0.6rem; border-radius: 50%;
  display: inline-block;
}
.genre-chip .ct { color: var(--ink-soft); opacity: 0.7; font-size: 0.8rem; }
.genre-chip:hover { border-color: var(--gilt); text-decoration: none; }
.genre-chip.active { border-color: var(--oxblood); box-shadow: inset 0 0 0 1px var(--oxblood); }

/* ---------- result cards ---------- */
.count-line { color: var(--ink-soft); font-style: italic; margin-bottom: 1rem; }
.cards { display: grid; gap: 0.9rem; grid-template-columns: 1fr; }
@media (min-width: 680px) { .cards { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.9rem 1.1rem;
  box-shadow: 0 1px 5px var(--shadow);
  border-top: 3px solid var(--accent, var(--gilt));
  display: flex; flex-direction: column; gap: 0.2rem;
}
.card .title { font-family: "Cormorant Garamond", Georgia, serif; font-size: 1.3rem; line-height: 1.15; }
.card .by { color: var(--ink-soft); font-style: italic; }
.card .meta { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; }
.card .shelf-tag {
  font-variant: small-caps; letter-spacing: 0.06em;
  color: var(--ink); background: var(--paper-deep);
  padding: 0.05rem 0.5rem; border-radius: 2px; border: 1px solid var(--rule);
}
.tag-pill { font-size: 0.78rem; color: var(--forest); }
.call-number { font-family: monospace; font-size: 0.8rem; color: var(--forest);
  background: var(--paper-deep); padding: 0.05rem 0.4rem; border-radius: 2px;
  border: 1px solid var(--rule); letter-spacing: 0.04em; }

/* ---------- detail ---------- */
.detail { background: var(--card); border: 1px solid var(--rule); padding: 1.6rem 1.8rem;
  box-shadow: 0 2px 10px var(--shadow); border-top: 4px solid var(--accent, var(--gilt)); }
.detail h1 { font-size: 2.2rem; }
.detail .sub { font-style: italic; color: var(--ink-soft); font-size: 1.2rem; margin-bottom: 0.6rem; }
.detail dl { display: grid; grid-template-columns: 11rem 1fr; gap: 0.35rem 1rem; margin-top: 1.2rem; }
.detail dt { font-variant: small-caps; letter-spacing: 0.05em; color: var(--ink-soft); }
.detail dd { margin: 0; }

/* ---------- admin ---------- */
.admin-grid { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .admin-grid { grid-template-columns: 1fr 1fr; } }
.panel {
  background: var(--card); border: 1px solid var(--rule); border-radius: 3px;
  padding: 1.2rem 1.4rem; box-shadow: 0 1px 6px var(--shadow);
}
.panel h2 { border-bottom: 1px solid var(--rule); padding-bottom: 0.3rem; font-size: 1.5rem; }
.stat-row { display: flex; justify-content: space-between; padding: 0.2rem 0; border-bottom: 1px dotted var(--rule); }
.stat-row .n { font-weight: 700; }
.stat-row.flagged { color: var(--oxblood); }
.stat-row.flagged .n { color: var(--oxblood); }
.muted { color: var(--ink-soft); font-style: italic; }
.src-on { color: var(--forest); font-weight: 600; }
.src-off { color: var(--ink-soft); }

/* ── back-office zone headings ─────────────────────────── */
.zone-head {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--gilt);
  padding-bottom: 0.25rem;
  margin: 2rem 0 1rem;
}
.zone-head:first-of-type { margin-top: 1rem; }

/* ── needs-attention banner ────────────────────────────── */
.panel.attention {
  border-left: 4px solid var(--oxblood);
  margin-bottom: 1.2rem;
}
.panel.attention h2 { border: none; padding: 0; margin-bottom: 0.6rem; }
.attention-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.attention-chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: rgba(125,43,33,0.08);
  border: 1px solid var(--oxblood);
  color: var(--oxblood);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.92rem;
  text-decoration: none;
  transition: background 0.15s;
}
.attention-chip:hover { background: rgba(125,43,33,0.16); text-decoration: none; }
.attention-chip .n { font-weight: 700; font-size: 1.05rem; }
.attention-chip.soft { border-color: var(--gilt); color: #8a5a12; background: rgba(176,131,40,0.10); }
.attention-chip.soft:hover { background: rgba(176,131,40,0.18); }

form.inline { display: inline; }
label { display: block; font-variant: small-caps; letter-spacing: 0.05em; color: var(--ink-soft); margin: 0.6rem 0 0.15rem; }
input[type=text], input[type=password], input[type=number], select, textarea {
  font-family: inherit; font-size: 1rem; padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule); background: #fffaf0; color: var(--ink);
  border-radius: 2px; width: 100%; max-width: 26rem;
}
textarea { min-height: 3.5rem; }

/* ---- styled file picker ---- */
.file-pick { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 0.4rem 0; }
.file-pick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-pick-btn {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1rem; font-variant: small-caps; letter-spacing: 0.07em;
  background: var(--paper-deep); color: var(--ink);
  border: 1px solid var(--rule); padding: 0.4rem 1rem;
  border-radius: 2px; cursor: pointer;
  box-shadow: 0 1px 3px var(--shadow);
  transition: background 0.15s;
}
.file-pick-btn:hover { background: var(--rule); }
.file-pick-name { font-size: 0.92rem; color: var(--ink-soft); font-style: italic; }

table.ledger { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-size: 0.95rem; }
table.ledger th, table.ledger td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.ledger th { font-variant: small-caps; letter-spacing: 0.05em; color: var(--ink-soft); }

/* Shelf occupancy strip: one equal-width cell per physical shelf, with
   proportional colour segments for the genres that share it. */
.shelf-strip { display: flex; flex-wrap: wrap; gap: 4px; margin: 0.4rem 0 1rem; }
.shelf-cell { flex: 1 1 0; min-width: 44px; }
.shelf-cell-bar {
  display: flex; height: 28px;
  border-radius: 2px; overflow: hidden;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.18);
}
.shelf-seg { height: 100%; min-width: 2px; }
.shelf-seg + .shelf-seg { border-left: 1px solid rgba(244,236,216,0.7); }
.shelf-cell-num {
  text-align: center; font-size: 0.75rem; color: var(--ink-soft);
  margin-top: 2px; cursor: default;
}
.progress { background: var(--paper-deep); border: 1px solid var(--rule); border-radius: 2px; height: 1.1rem; overflow: hidden; }
.progress > div { background: var(--forest); height: 100%; width: 0; transition: width 0.4s; }

.pill { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.5rem; border-radius: 999px; border: 1px solid var(--rule); }
.pill.enriched { color: var(--forest); border-color: var(--forest); }
.pill.no_match { color: var(--gilt); border-color: var(--gilt); }
.pill.error { color: var(--oxblood); border-color: var(--oxblood); }
.pill.pending { color: var(--ink-soft); }
.pill.manual { color: var(--forest); border-color: var(--forest); background: rgba(43,90,58,0.10); }
.pill.genre_form { color: var(--forest); border-color: var(--forest); }
.pill.subject { color: #4a5e7a; border-color: #4a5e7a; }
.pill.lc_class { color: var(--ink-soft); border-color: var(--rule); }
.pill.overflow { color: var(--gilt); border-color: var(--gilt); }
.pill.no_match_rule { color: var(--muted); border-color: var(--rule); }
.pill.oversized { color: #8a5a12; border-color: var(--gilt); background: rgba(176,131,40,0.12); }

/* oversized / big-books flag */
.oversize-marker {
  color: var(--gilt);
  font-weight: 700;
  font-size: 0.95em;
  cursor: help;
}
.oversize-note {
  margin: 0.4rem 0 1rem;
  padding: 0.7rem 0.9rem;
  background: rgba(176,131,40,0.10);
  border-left: 3px solid var(--gilt);
  border-radius: 2px;
  font-size: 0.95rem;
  line-height: 1.5;
}
.oversize-note .pill { margin-right: 0.4rem; }

footer.colophon { text-align: center; color: var(--ink-soft); font-style: italic;
  font-size: 0.85rem; padding: 2rem 1rem; border-top: 1px solid var(--rule); }

/* ---------- ratings ---------- */
/* Detail-page rating: a gold star bar clipped to the score's percentage,
   over a faint empty bar, plus the numeric value. */
.rating { display: flex; align-items: baseline; gap: 0.45rem; margin: 0.5rem 0 0.2rem; }
.rating .stars {
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  /* gold up to the score, soft grey beyond — both clipped to the star glyphs */
  background: linear-gradient(90deg,
    var(--gilt) var(--pct, 0%), rgba(0, 0, 0, 0.18) var(--pct, 0%));
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.rating .rating-num { font-weight: 600; }
/* Compact rating chip on search/sort cards. */
.rating-tag {
  border: 1px solid var(--gilt);
  color: var(--gilt);
  border-radius: 3px;
  padding: 0 0.3rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ---------- sort bar ---------- */
.sort-bar {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin: 0.2rem 0 1rem; font-size: 0.88rem;
}
.sort-link {
  text-decoration: none; color: var(--ink-soft);
  border: 1px solid var(--rule); border-radius: 999px;
  padding: 0.12rem 0.7rem;
}
.sort-link.active { color: var(--ink); border-color: var(--gilt); background: rgba(176,131,40,0.10); }
.sort-link:hover { border-color: var(--gilt); }

/* ---------- shelf-strip display ---------- */
.shelf-row { margin-bottom: 1.8rem; }
.shelf-row-label {
  font-variant: small-caps; letter-spacing: 0.04em;
  font-size: 0.9rem; color: var(--ink-soft);
  margin-bottom: 0.4rem; padding-left: 0.2rem;
}

.shelf-track-wrap {
  overflow: hidden;
  position: relative;
  background: linear-gradient(to bottom, #d4a96a 0%, #c49050 70%, #b07830 100%);
  border-radius: 2px 2px 0 0;
  cursor: pointer;
}
/* The books live inside their own clip layer. Promoting this container to its
   own compositing layer (translateZ + hidden backface) makes WebKit apply the
   overflow:hidden clip against the animated track's *painted* position, fixing
   the iOS Safari bug where books scrolling in from the right were clipped at
   their original layout spot. We deliberately do NOT use a CSS mask here: a
   masked container with an animated child forces an expensive re-rasterisation
   every frame on iOS, which made books flicker and blink out. */
.shelf-clip {
  overflow: hidden;
  position: relative;
  /* Headroom lives INSIDE the clip layer (not on the wrap) so the hover lift
     (translateY(-10px) on .spine) stays within the clipped box instead of
     having the top of the book sheared off. */
  padding-top: 10px;
  -webkit-transform: translateZ(0);
          transform: translateZ(0);
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}
/* Soft edge fade so books slip behind the frame rather than hard-clipping.
   A cheap painted overlay (no compositing cost) tinted to the shelf wood; kept
   to a thin 2.5% so it never hides a whole book at the edge. */
.shelf-track-wrap::before {
  content: '';
  position: absolute; inset: 0;
  z-index: 2; pointer-events: none;
  background: linear-gradient(to right,
    #cd9d5c 0%, transparent 2.5%,
    transparent 97.5%, #cd9d5c 100%);
}
/* shelf ledge — tinted with the genre colour */
.shelf-track-wrap::after {
  content: '';
  display: block;
  height: 10px;
  background: color-mix(in srgb, var(--shelf-color, #9a6820) 40%, #5a3a08 60%);
  border-radius: 0 0 2px 2px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.35);
}
.shelf-track {
  display: flex;
  width: max-content;
  /* No padding or flex gap here — both break the seamless loop. The -50%
     translate assumes the track is exactly 2× one copy wide. A flex gap puts
     2N-1 gaps between 2N books (an odd count), leaving the loop half a gap
     short and causing a visible jolt every cycle. Spacing comes from
     margin-right on each .spine instead, which the -50% divides evenly. */
  animation: shelf-scroll linear infinite;
  will-change: transform;
  /* translate3d + hidden backface keep the track on a single stable GPU layer
     so iOS doesn't blink books in and out as they scroll across the viewport. */
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
  -webkit-transform: translate3d(0, 0, 0);
          transform: translate3d(0, 0, 0);
}
.shelf-track.static { animation: none; }
.shelf-track-wrap:hover .shelf-track { animation-play-state: paused; }

@keyframes shelf-scroll {
  0%   { -webkit-transform: translate3d(0, 0, 0);    transform: translate3d(0, 0, 0); }
  100% { -webkit-transform: translate3d(-50%, 0, 0); transform: translate3d(-50%, 0, 0); }
}

.spine {
  flex-shrink: 0;
  display: block;
  margin-right: 3px; /* book spacing — see the .shelf-track note on flex gap */
  text-decoration: none;
  transition: transform 0.18s, filter 0.18s;
  position: relative;
  z-index: 0;
}
.spine:hover { transform: translateY(-10px); filter: brightness(1.08); z-index: 3; }

.spine img {
  display: block;
  height: 130px;
  /* Fixed width, not width:auto. The marquee translates by a percentage of
     the track's own width, so every cover that finished loading used to grow
     the track and make the whole strip lurch mid-scroll. Covers are ~2:3
     anyway; object-fit crops the rare outlier instead of reflowing the row. */
  width: 86px;
  object-fit: cover;
  border-radius: 1px 3px 3px 1px;
  box-shadow: 2px 0 5px rgba(0,0,0,0.25);
}
.spine-blank {
  height: 130px;
  width: 28px;
  border-radius: 1px 3px 3px 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 2px 0 5px rgba(0,0,0,0.25);
  /* a cloth-binding sheen layered over the per-book background-color:
     darker at the gutter, a faint highlight a third of the way across. */
  background-image: linear-gradient(
    to right,
    rgba(0,0,0,0.22) 0%,
    rgba(255,255,255,0.10) 32%,
    rgba(0,0,0,0.06) 60%,
    rgba(0,0,0,0.20) 100%);
}
.spine-blank span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.92);
  line-height: 1.1;
  padding: 6px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 118px;
}

/* ── Recently Added ─────────────────────────────────── */
.recent-section {
  margin: 1.6rem 0 0.4rem;
}
.recent-heading {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.7rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.7;
}
.recent-rail {
  display: flex;
  gap: 0.8rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.recent-rail::-webkit-scrollbar { height: 4px; }
.recent-rail::-webkit-scrollbar-track { background: transparent; }
.recent-rail::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }

.recent-card {
  flex-shrink: 0;
  width: 100px;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.18s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.recent-card:hover { transform: translateY(-4px); }

.recent-cover {
  width: 100px;
  height: 140px;
  overflow: hidden;
  border-radius: 2px 4px 4px 2px;
  box-shadow: 2px 3px 8px var(--shadow);
}
.recent-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.recent-cover-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem;
  background-image: linear-gradient(
    to right,
    rgba(0,0,0,0.20) 0%,
    rgba(255,255,255,0.10) 34%,
    rgba(0,0,0,0.06) 62%,
    rgba(0,0,0,0.18) 100%);
}
.recent-cover-blank span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.88);
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  max-height: 130px;
}
.recent-meta {
  padding: 0 2px;
}
.recent-title {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.78rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.recent-author {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- reshelving list ---------- */
.reshelf-controls {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin: 0.2rem 0 0.8rem; font-size: 0.9rem;
}
.reshelf-shelf { margin-top: 1.2rem; }
.reshelf-shelf h2 { font-size: 1.35rem; }
table.reshelf-table td.pos { width: 2.2rem; text-align: right; }
table.reshelf-table tr.genre-row td {
  background: var(--paper-deep);
  font-variant: small-caps; letter-spacing: 0.05em;
  border-bottom: 2px solid var(--rule);
}

/* Print: the reshelving list is meant to be carried around the room.
   Strip the chrome, keep the ink. */
@media print {
  .masthead, footer.colophon, .no-print { display: none !important; }
  body { background: none; font-size: 10pt; }
  .wrap { max-width: none; padding: 0; }
  .panel { box-shadow: none; border: none; padding: 0.4rem 0; }
  .reshelf-shelf h2 { break-after: avoid; }
  table.ledger th, table.ledger td { padding: 0.15rem 0.35rem; }
  a { color: inherit; text-decoration: none; }
}

/* ── Mobile & responsive ─────────────────────────────── */

/* Admin ledger tables — horizontal scroll on small screens so columns
   don't collapse into unreadable squash. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Book detail definition list: single column on narrow screens */
@media (max-width: 560px) {
  .detail dl {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }
  .detail dt {
    margin-top: 0.6rem;
    font-size: 0.8rem;
  }
  .detail dd { margin-bottom: 0.2rem; }
  .detail h1 { font-size: 1.6rem; }
}

/* Masthead nav: tighten spacing on small screens */
@media (max-width: 500px) {
  .masthead { padding: 1rem 1rem 0.7rem; }
  .masthead .tagline { font-size: 0.85rem; }
  nav.rule-nav { font-size: 0.82rem; }
  nav.rule-nav a { margin: 0 0.3rem; }
  .wrap { padding: 1.2rem 1rem 3rem; }
}

/* Shelf rows: shorter spines on very small screens */
@media (max-width: 480px) {
  .spine img,
  .spine-blank {
    height: 100px;
  }
  .spine img { width: 66px; }
}

/* Genre rail: smaller chips on mobile */
@media (max-width: 480px) {
  .genre-chip { font-size: 0.8rem; padding: 0.2rem 0.5rem; }
}

/* Search bar: full-width button on very small screens */
@media (max-width: 380px) {
  .searchbar { flex-direction: column; }
  .searchbar .btn { width: 100%; }
  .searchbar input[type=text] { flex-basis: auto; }
}

/* Admin book-list filter form: stack on mobile */
@media (max-width: 600px) {
  .admin-filter-form { flex-direction: column; }
  .admin-filter-form > div { min-width: 0; }
  .admin-filter-form select,
  .admin-filter-form input[type=text] { max-width: 100%; width: 100%; }
}

/* Cards grid: always single column below 480px */
@media (max-width: 479px) {
  .cards { grid-template-columns: 1fr !important; }
}

/* Panel headings & stat rows: compact on mobile */
@media (max-width: 500px) {
  .panel { padding: 0.9rem 1rem; }
  .admin-grid { gap: 0.8rem; }
  .shelf-row-label { font-size: 0.82rem; }
}

/* ---------- the room map: bookcases as columns of shelves ---------- */
.room-map {
  display: flex; flex-wrap: wrap; gap: 0.9rem;
  align-items: stretch; margin: 0.6rem 0 1rem;
}
.room-col {
  display: flex; flex-direction: column;
  background: var(--paper-deep);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: 6px; box-shadow: 0 2px 5px var(--shadow);
  min-width: 3.2rem;
}
/* ---------- back-office sub-navigation ---------- */
.admin-subnav {
  display: flex; flex-wrap: wrap; gap: 0.15rem 0.4rem;
  justify-content: center; align-items: center;
  max-width: 60rem; margin: 0.4rem auto 0; padding: 0 1rem 0.2rem;
}
.admin-subnav a {
  font-variant: small-caps; letter-spacing: 0.05em; font-size: 0.9rem;
  color: var(--ink-soft); text-decoration: none;
  padding: 0.2rem 0.6rem; border-radius: 3px; border: 1px solid transparent;
}
.admin-subnav a:hover { color: var(--oxblood); background: var(--paper-deep); }
.admin-subnav a.active {
  color: var(--ink); border-color: var(--rule); background: var(--card);
}

/* ---------- FAQ / help accordions ---------- */
.faq { margin: 0.4rem 0 0.4rem; }
.faq details {
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--card); margin-bottom: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow);
}
.faq summary {
  cursor: pointer; padding: 0.6rem 0.9rem;
  font-family: 'Cormorant Garamond', Garamond, serif;
  font-size: 1.12rem; font-weight: 600; color: var(--ink);
  list-style-position: inside;
}
.faq summary:hover { color: var(--oxblood); }
.faq details[open] summary { border-bottom: 1px solid var(--rule); }
.faq details > p, .faq details > ul { margin: 0.6rem 0.9rem; }
.faq details > ul { padding-left: 1.4rem; }
.faq details > ul li { margin: 0.25rem 0; }

/* ---------- room layout editor ---------- */
.case-row {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.9rem;
  padding: 0.5rem 0.6rem; margin-bottom: 0.5rem;
  background: var(--paper-deep); border: 1px solid var(--rule); border-radius: 3px;
}
.case-row label { margin: 0; font-size: 0.82rem; color: var(--ink-soft); }
.case-row input, .case-row select { margin: 0.1rem 0 0; }
.case-row .case-no {
  font-variant: small-caps; letter-spacing: 0.05em; color: var(--ink-soft);
  min-width: 3.6rem; align-self: center;
}

.room-col-inner { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.room-col.align-bottom .room-col-inner { justify-content: flex-end; }
/* A case flipped onto its side: shelves read left-to-right, bars run vertical. */
.room-col.flip .room-col-inner { flex-direction: row; align-items: flex-end; gap: 3px; }
.room-col.flip .room-shelf { flex-direction: column; align-items: center; min-height: 0; }
.room-col.flip .room-shelf-bar { flex-direction: column; height: auto; width: 16px; min-width: 0; }
.room-col.flip .shelf-seg { width: 100%; height: auto; }
.room-col.flip .shelf-seg + .shelf-seg { border-left: none; border-top: 1px solid rgba(244,236,216,0.7); }
.room-col.flip .room-shelf-num { min-width: 0; text-align: center; }
.room-shelf {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--rule);
  border-radius: 2px; padding: 3px 6px; min-height: 26px;
}
.room-shelf.highlight {
  border-color: var(--oxblood);
  box-shadow: 0 0 0 2px var(--oxblood);
  background: #f7e2cf;
}
.room-shelf-num {
  font-size: 0.75rem; color: var(--ink-soft); min-width: 1.4rem;
  text-align: right; cursor: default;
}
.room-shelf-bar {
  display: flex; flex: 1; height: 16px; min-width: 6rem;
  border-radius: 2px; overflow: hidden;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15);
}
.room-map.compact .room-shelf { min-height: 20px; padding: 2px 6px; }
.room-map.compact .room-shelf-num { text-align: center; width: 100%; min-width: 1.8rem; }
.room-flags { display: flex; flex-direction: column; gap: 2px; }
.room-flag {
  font-size: 0.68rem; line-height: 1.25; color: var(--ink-soft);
  border-left: 3px solid var(--gilt); padding-left: 4px;
  white-space: nowrap;
}
.room-col-label {
  text-align: center; font-size: 0.72rem; color: var(--ink-soft);
  font-variant: small-caps; letter-spacing: 0.06em; margin-top: 2px;
}

/* ---------- patron due-date alerts ---------- */
.due-alert {
  background: #f7e9d3; border: 1px solid var(--gilt);
  border-left: 5px solid var(--gilt); border-radius: 3px;
  padding: 0.6rem 0.9rem; margin: 0 0 1rem; font-size: 0.98rem;
}
.pill.missing { color: #fff; background: var(--oxblood); border-color: var(--oxblood); }
.pill.recatalog { color: #4a5e7a; border-color: #4a5e7a; background: rgba(74,94,122,0.10); }
tr.audit-missing > td { background: rgba(140,59,46,0.07); }
.audit-actions form { display: inline; }
.audit-actions .btn { margin: 0 0.2rem 0.2rem 0; }
.pill.overdue { color: #fff; background: var(--oxblood); border-color: var(--oxblood); }
.pill.due-soon { color: var(--ink); background: #edd9a3; border-color: var(--gilt); }
.pill.active { color: var(--forest); border-color: var(--forest); }
.pill.requested { color: var(--gilt); border-color: var(--gilt); }
.pill.returned { color: var(--ink-soft); }
.pill.cancelled { color: var(--ink-soft); border-color: var(--rule); }
.pill.suspended { color: #fff; background: var(--oxblood); border-color: var(--oxblood); }
.alert-dot { color: var(--oxblood); font-size: 0.7em; vertical-align: super; }
