/* ---------------------------------------------------------------------------
   Personal library.

   Three type voices, each carrying meaning:
     serif  -- the book's own voice (titles, authors, descriptions)
     sans   -- the system's voice (labels, buttons, navigation)
     mono   -- the machine's voice (barcodes, IDs, dates, counts)

   The palette comes from the aniline violet of a date-due stamp rather than
   the usual library-nostalgia cream.
--------------------------------------------------------------------------- */

:root {
  --ink:        #191830;
  --ink-soft:   #43415e;
  --muted:      #6f6c88;
  --faint:      #9a97ad;

  --paper:      #fbfbfd;
  --surface:    #ffffff;
  --sunk:       #f4f3f8;
  --rule:       #e2e0ec;
  --rule-firm:  #cbc8dc;

  --stamp:      #5a3fb0;
  --stamp-soft: #efeafc;
  --overdue:    #b8342c;
  --overdue-soft:#fdecea;
  --good:       #1d7a5f;
  --good-soft:  #e6f4ef;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "DejaVu Sans Mono", monospace;

  --step: 0.5rem;
  --max: 1180px;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--stamp); text-decoration-color: var(--rule-firm); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

/* --- masthead ------------------------------------------------------------ */

.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.masthead-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 calc(var(--step) * 3);
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 3);
  min-height: 60px;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--serif);
  font-size: 1.16rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

/* The bar cluster is the one ornament: a literal fragment of Code 128, the
   symbology every label in this system is printed in. */
.wordmark::before {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 8px;
  vertical-align: -2px;
  background-image: linear-gradient(90deg,
    var(--ink) 0 2px, transparent 2px 4px,
    var(--ink) 4px 5px, transparent 5px 8px,
    var(--ink) 8px 11px, transparent 11px 12px,
    var(--ink) 12px 13px, transparent 13px 15px);
}

.nav { display: flex; gap: calc(var(--step) * 2.5); flex-wrap: wrap; }
.nav a {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--stamp); }
.nav-end { margin-left: auto; display: flex; align-items: center; gap: var(--step); }

/* --- layout -------------------------------------------------------------- */

main { max-width: var(--max); margin: 0 auto; padding: calc(var(--step) * 5) calc(var(--step) * 3) calc(var(--step) * 10); }

.page-head { margin-bottom: calc(var(--step) * 4); }
.eyebrow {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 6px;
}
h1 { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 4px; }
h2 { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; margin: 0 0 calc(var(--step) * 2); }
h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 0 0 var(--step); font-weight: 600; }
.lede { color: var(--muted); margin: 0; max-width: 62ch; }

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: calc(var(--step) * 3);
}
.panel + .panel { margin-top: calc(var(--step) * 3); }

.grid { display: grid; gap: calc(var(--step) * 3); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.stack > * + * { margin-top: calc(var(--step) * 3); }
.row { display: flex; gap: var(--step); align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: var(--step); }

/* --- the ID chip: the signature element ---------------------------------- */

/* An accession number on screen should look like the number on the spine
   label in your hand, so matching one to the other takes no translation. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--sunk);
  border: 1px solid var(--rule-firm);
  border-radius: 3px;
  padding: 3px 8px 3px 5px;
  text-decoration: none;
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 9px;
  align-self: stretch;
  min-height: 15px;
  background-image: linear-gradient(90deg,
    var(--ink-soft) 0 1px, transparent 1px 3px,
    var(--ink-soft) 3px 5px, transparent 5px 6px,
    var(--ink-soft) 6px 7px, transparent 7px 9px);
  opacity: 0.75;
}
a.chip:hover { border-color: var(--stamp); color: var(--stamp); }
.chip-lg { font-size: 1.05rem; padding: 6px 12px 6px 7px; }
.chip-lg::before { width: 13px; min-height: 22px; }

/* --- stamps: status, in the language of a rubber stamp ------------------- */

.stamp {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  padding: 3px 7px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}
.stamp-available { color: var(--good); background: var(--good-soft); }
.stamp-on_loan   { color: var(--stamp); background: var(--stamp-soft); }
.stamp-in_transit{ color: var(--ink-soft); background: var(--sunk); }
.stamp-lost, .stamp-overdue { color: var(--overdue); background: var(--overdue-soft); }
.stamp-withdrawn { color: var(--faint); background: var(--sunk); }
.stamp-lg { font-size: 0.82rem; padding: 6px 12px; letter-spacing: 0.16em; }

/* --- the scan slot ------------------------------------------------------- */

/* The scanner is a keyboard, so the whole desk is one field. It is deliberately
   oversized: it is the target for every barcode in the building. */
.slot { position: relative; }
.slot input {
  width: 100%;
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: calc(var(--step) * 2.5) calc(var(--step) * 2) calc(var(--step) * 2.5) 52px;
  border: 2px solid var(--rule-firm);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
.slot input::placeholder { color: var(--faint); font-weight: 400; letter-spacing: 0.02em; }
.slot input:focus {
  outline: none;
  border-color: var(--stamp);
  box-shadow: 0 0 0 4px var(--stamp-soft);
}
.slot::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 26px;
  background-image: linear-gradient(90deg,
    var(--rule-firm) 0 2px, transparent 2px 5px,
    var(--rule-firm) 5px 6px, transparent 6px 8px,
    var(--rule-firm) 8px 11px, transparent 11px 13px,
    var(--rule-firm) 13px 14px, transparent 14px 16px,
    var(--rule-firm) 16px 18px);
  pointer-events: none;
}
.slot:focus-within::before { background-image: linear-gradient(90deg,
    var(--stamp) 0 2px, transparent 2px 5px,
    var(--stamp) 5px 6px, transparent 6px 8px,
    var(--stamp) 8px 11px, transparent 11px 13px,
    var(--stamp) 13px 14px, transparent 14px 16px,
    var(--stamp) 16px 18px); }

.slot-hint { font-family: var(--mono); font-size: 0.72rem; color: var(--faint); margin-top: var(--step); letter-spacing: 0.02em; }

@media (max-width: 560px) {
  .slot input { font-size: 1.05rem; padding-left: 44px; }
  main { padding: calc(var(--step) * 3) calc(var(--step) * 2) calc(var(--step) * 8); }
  h1 { font-size: 1.55rem; }
}

/* --- forms --------------------------------------------------------------- */

label, .field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 5px;
}

/* Selecting on [type=text] misses `<input name="x">`, which is text by default
   but carries no type attribute, so match by exclusion instead. The exclusions
   sit inside :where() so this rule keeps a specificity of one element -- a bare
   :not() chain would score higher than `.slot input` and silently strip the
   scan box's padding. */
input:where(:not([type=checkbox], [type=radio], [type=submit], [type=button], [type=file])),
select, textarea {
  width: 100%;
  font-family: var(--sans);
  font-size: 0.94rem;
  color: var(--ink);
  padding: 8px 10px;
  border: 1px solid var(--rule-firm);
  border-radius: 3px;
  background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--stamp); box-shadow: 0 0 0 3px var(--stamp-soft); }
textarea { min-height: 84px; resize: vertical; font-family: var(--sans); }
.field { margin-bottom: calc(var(--step) * 2); }
.field-mono input { font-family: var(--mono); letter-spacing: 0.04em; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 9px 16px;
  border-radius: 3px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--stamp); border-color: var(--stamp); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--rule-firm); }
.btn-ghost:hover { background: var(--sunk); color: var(--ink); border-color: var(--ink); }
.btn-danger { background: transparent; color: var(--overdue); border-color: var(--overdue); }
.btn-danger:hover { background: var(--overdue); color: #fff; }
.btn-sm { font-size: 0.74rem; padding: 6px 11px; }

/* --- tables -------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--rule-firm);
}
td { padding: 11px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--sunk); }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; text-align: right; }
/* On a narrow screen a table should scroll sideways rather than squeeze its
   columns until titles wrap three words at a time. Desktop tables are already
   wider than this, so the floor only takes effect on phones. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 34rem; }

.title-cell { font-family: var(--serif); font-size: 1rem; color: var(--ink); text-decoration: none; display: block; }
.title-cell:hover { color: var(--stamp); }
.byline { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 0.88rem; }
.meta { font-size: 0.8rem; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.82rem; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- stat tiles ---------------------------------------------------------- */

.tile {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: calc(var(--step) * 2.5);
  text-decoration: none;
  display: block;
  color: inherit;
}
.tile:hover { border-color: var(--rule-firm); }
.tile-value { font-family: var(--mono); font-size: 1.85rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; }
.tile-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 5px; }
.tile-alert .tile-value { color: var(--overdue); }

/* --- book detail --------------------------------------------------------- */

.book-head { display: grid; grid-template-columns: 150px 1fr; gap: calc(var(--step) * 4); align-items: start; }
@media (max-width: 620px) { .book-head { grid-template-columns: 1fr; } }
.cover {
  width: 100%;
  border-radius: 3px;
  border: 1px solid var(--rule-firm);
  background: var(--sunk);
  display: block;
}
.cover-none {
  aspect-ratio: 2 / 3;
  min-height: 42px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--faint);
  text-align: center;
  padding: var(--step);
}
.book-title { font-family: var(--serif); font-size: 1.75rem; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 2px; line-height: 1.2; }
.book-sub { font-family: var(--serif); font-size: 1.1rem; color: var(--muted); font-style: italic; margin: 0 0 10px; }
.book-desc { font-family: var(--serif); font-size: 1rem; line-height: 1.6; color: var(--ink-soft); max-width: 66ch; }

/* A definition grid, not a table: these are facts about one thing. */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px calc(var(--step) * 2); margin: 0; font-size: 0.88rem; }
.facts dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); padding-top: 3px; }
.facts dd { margin: 0; color: var(--ink-soft); }

.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 0.72rem;
  color: var(--ink-soft);
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 2px 7px;
  text-decoration: none;
}
.tag:hover { border-color: var(--stamp); color: var(--stamp); }

/* --- timeline ------------------------------------------------------------ */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: calc(var(--step) * 2);
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.88rem;
}
.timeline li:last-child { border-bottom: none; }
.timeline time { font-family: var(--mono); font-size: 0.74rem; color: var(--faint); padding-top: 2px; }
.timeline .ev { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--stamp); font-weight: 600; }

/* --- flash --------------------------------------------------------------- */

.flash {
  border: 1px solid var(--rule-firm);
  border-left: 3px solid var(--stamp);
  background: var(--surface);
  border-radius: 3px;
  padding: 11px 14px;
  margin-bottom: calc(var(--step) * 2);
  font-size: 0.9rem;
}
.flash-error { border-left-color: var(--overdue); background: var(--overdue-soft); color: #7d221c; }
.flash-ok { border-left-color: var(--good); background: var(--good-soft); }

/* --- misc ---------------------------------------------------------------- */

.empty { text-align: center; padding: calc(var(--step) * 7) var(--step); color: var(--muted); }
.empty h3 { color: var(--ink); font-size: 1rem; text-transform: none; letter-spacing: 0; margin-bottom: 6px; font-family: var(--serif); }
.divider { border: 0; border-top: 1px solid var(--rule); margin: calc(var(--step) * 4) 0; }
.tree-indent { display: inline-block; }
.barcode-img { display: block; max-width: 240px; }
.barcode-img svg { width: 100%; height: auto; }
.receipt { list-style: none; margin: 0; padding: 0; }
.receipt li { display: flex; gap: var(--step); align-items: baseline; padding: 7px 0; border-bottom: 1px dashed var(--rule); font-size: 0.88rem; }
.receipt li:last-child { border-bottom: none; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 0.88rem; font-weight: 400; color: var(--ink-soft); }
.footer { max-width: var(--max); margin: 0 auto; padding: calc(var(--step) * 3); color: var(--faint); font-size: 0.76rem; border-top: 1px solid var(--rule); font-family: var(--mono); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .masthead, .footer, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .panel { border: none; padding: 0; }
}

/* A conservation instruction has to be read before the book is picked up, so
   it is set apart from the ordinary record rather than filed among it. */
.handling-note {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: #7d221c;
  background: var(--overdue-soft);
  border-left: 3px solid var(--overdue);
  border-radius: 0 3px 3px 0;
  padding: 9px 12px;
  margin: 0 0 1rem;
  max-width: 60ch;
}

/* The shelf every add lands on. Deliberately loud when set: while a stack is
   being worked through, the destination is the one thing worth being certain
   about, and a wrong shelf is only discovered by hunting for the book later. */
.shelf-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--step) * 2);
  flex-wrap: wrap;
  border: 1px solid var(--rule-firm);
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: calc(var(--step) * 2);
  background: var(--surface);
}
.shelf-bar:has(.shelf-bar-set) {
  border-color: var(--stamp);
  background: var(--stamp-soft);
}
.shelf-bar-set { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.shelf-bar-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stamp);
}
.shelf-bar-where {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
}
.shelf-bar-where:hover { text-decoration: underline; }
.shelf-bar-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.shelf-bar-pick label { margin: 0; white-space: nowrap; }
.shelf-bar-pick select { width: auto; min-width: 220px; }

/* --- the tap page ---------------------------------------------------------
   Opened by tapping an NFC tag, so it is read on a phone, one-handed, while
   holding the book. Everything is bigger than the desktop record and the
   primary action is a thumb-sized target near the bottom of the reach. */

.tap { max-width: 30rem; margin: 0 auto; }
.tap-head { display: grid; grid-template-columns: 92px 1fr; gap: calc(var(--step) * 2.5); align-items: start; }
.tap-cover .cover { border-radius: 3px; }
.tap-title { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; line-height: 1.2; margin: 0 0 2px; letter-spacing: -0.01em; }
.tap-byline { font-family: var(--serif); font-style: italic; color: var(--muted); margin: 0; font-size: 0.95rem; }
.tap-facts { margin: calc(var(--step) * 3) 0; }

.btn-tap {
  width: 100%;
  justify-content: center;
  font-size: 1.02rem;
  padding: 16px 20px;
  border-radius: 4px;
}
.tap-other { margin-top: calc(var(--step) * 2); }
.tap-other summary { font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.tap-links { margin-top: calc(var(--step) * 3); gap: calc(var(--step) * 2); }

/* --- tag writing queue ---------------------------------------------------- */

.tag-progress {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--step);
  flex-wrap: wrap;
  margin-bottom: calc(var(--step) * 2);
}
.tag-progress-count { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; }
.tag-card { max-width: 40rem; }
.tag-book { display: flex; gap: calc(var(--step) * 2.5); align-items: flex-start; margin-bottom: calc(var(--step) * 3); }
.tag-url-row { display: flex; gap: var(--step); align-items: stretch; }
.tag-url-row input { font-size: 0.86rem; }
.tag-url-row .btn { flex: none; }

/* --- stations ------------------------------------------------------------- */

/* A token is visible exactly once, so the panel that shows it should be
   impossible to scroll past without noticing. */
.token-panel {
  border-color: var(--stamp);
  background: var(--stamp-soft);
  margin-bottom: calc(var(--step) * 3);
}
.token-panel input { font-size: 0.9rem; background: var(--surface); }
.station-config {
  font-size: 0.78rem;
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0;
}
