/* spec: specs/040-ui/01-ui-principles.md@v2 */
/* spec: specs/020-discovery/01-discovery-slice1.md@v5 */
/* spec: specs/040-ui/02-paper-view.md@v4 */
/* spec: specs/040-ui/03-reference-linking.md@v2 */
/* spec: specs/040-ui/05-paper-version-panel.md@v3 */
/* spec: specs/050-online/02-authentication.md@v3 */

/* Design tokens — the single home for palette, spacing, type (01-ui-principles §1). */
:root {
  --ink: #1c1c1f;
  --muted: #6b6b73;
  --faint: #9a9aa2;
  --line: #e7e7ea;
  --line-strong: #d6d6db;
  --bg: #fbfbfc;
  --panel: #ffffff;
  --accent: #3a6df0;
  --accent-weak: #eef2fe;
  --ok: #2e7d57;
  --ok-weak: #e9f4ee;
  --warn: #9a6400;
  --warn-weak: #f6efe0;
  --danger: #b23b2e;
  --danger-weak: #f7eae8;

  /* spacing scale (01-ui-principles §1): 4 8 12 16 24 32 */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s6: 1.5rem;
  --s8: 2rem;

  --radius: 7px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  /* very light pink → orange tint, fixed so it doesn't scroll-tile */
  background: linear-gradient(155deg, #fff1f2 0%, #fff6ef 52%, #fff0e4 100%) fixed;
  -webkit-font-smoothing: antialiased;
}

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

/* --- Header: low chrome, one hairline (01-ui-principles §1) --- */
header {
  display: flex;
  align-items: center;
  gap: var(--s6);
  padding: var(--s3) var(--s8);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to left, #b8cee0 0%, #cfdce8 45%, #e5edf4 100%);
}

/* Nav decoration: open book animation */
.nav-deco {
  margin-left: auto;
  align-self: center;
  display: flex;
  align-items: center;
  padding-right: var(--s2);
}
.nb-book {
  position: relative;
  width: 36px;
  height: 24px;
  flex-shrink: 0;
  opacity: 0.78;
}
.nb-book::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #f3f7fb;
  border: 1px solid rgba(80, 108, 135, 0.3);
  border-radius: 1px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
/* spine */
.nb-book::after {
  content: '';
  position: absolute;
  left: calc(50% - 0.5px);
  top: 1px;
  bottom: 1px;
  width: 1px;
  background: rgba(70, 100, 130, 0.4);
  z-index: 3;
}
.nb-left,
.nb-right {
  position: absolute;
  top: 3px;
  bottom: 3px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 1;
}
.nb-left {
  left: 3px;
  right: calc(50% + 2px);
  clip-path: inset(0 0 100% 0);
  animation: nb-fill-left 6s ease-in-out infinite;
}
.nb-right {
  left: calc(50% + 2px);
  right: 3px;
  clip-path: inset(0 0 100% 0);
  animation: nb-fill-right 6s ease-in-out infinite;
}
.nb-left span,
.nb-right span {
  display: block;
  height: 1.5px;
  background: rgba(55, 85, 115, 0.5);
  border-radius: 1px;
}
/* "random" line lengths — left page */
.nb-left span:nth-child(1) { width: 85%; }
.nb-left span:nth-child(2) { width: 63%; }
.nb-left span:nth-child(3) { width: 90%; }
.nb-left span:nth-child(4) { width: 54%; }
.nb-left span:nth-child(5) { width: 78%; }
.nb-left span:nth-child(6) { width: 82%; }
/* "random" line lengths — right page */
.nb-right span:nth-child(1) { width: 71%; }
.nb-right span:nth-child(2) { width: 94%; }
.nb-right span:nth-child(3) { width: 57%; }
.nb-right span:nth-child(4) { width: 88%; }
.nb-right span:nth-child(5) { width: 47%; }
.nb-right span:nth-child(6) { width: 76%; }
/* turning page: covers right, sweeps toward spine, reveals blank */
/* Overlay spans both pages; clip-path sweeps it from right edge to left edge */
.nb-turn {
  position: absolute;
  left: 1px;
  right: 1px;
  top: 1px;
  bottom: 1px;
  /* shadow on left edge = leading edge of the sweep */
  background: linear-gradient(to right,
    rgba(110, 158, 200, 0.75) 0%,
    #f3f7fb 7%,
    #f3f7fb 100%);
  clip-path: inset(0 0 0 100%);
  animation: nb-page-turn 6s ease-in-out infinite;
  z-index: 2;
}
@keyframes nb-fill-left {
  0%   { clip-path: inset(0 0 100% 0); }
  4%   { clip-path: inset(0 0 95% 0); }
  25%  { clip-path: inset(0 0 0% 0); }
  /* hold until the overlay reaches peak and covers left page */
  64%  { clip-path: inset(0 0 0% 0); }
  /* clear while hidden under the overlay */
  70%  { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 100% 0); }
}
@keyframes nb-fill-right {
  0%, 30% { clip-path: inset(0 0 100% 0); }
  34%     { clip-path: inset(0 0 95% 0); }
  56%     { clip-path: inset(0 0 0% 0); }
  /* hold; overlay enters from right starting at ~57% */
  61%     { clip-path: inset(0 0 0% 0); }
  /* clear while the entering overlay covers the right page */
  66%     { clip-path: inset(0 0 100% 0); }
  100%    { clip-path: inset(0 0 100% 0); }
}
/* clip-path: inset(top right bottom left)
   Enter: left clip 100%→0%  — overlay appears from right edge, sweeps left
   Peak:  inset(0 0 0 0)     — entire overlay visible, both pages covered
   Exit:  right clip 0%→100% — overlay continues sweeping leftward, vanishes at left edge */
@keyframes nb-page-turn {
  0%, 57% { clip-path: inset(0 0 0 100%); }
  65%     { clip-path: inset(0 0 0 0%); }
  73%     { clip-path: inset(0 100% 0 0%); }
  100%    { clip-path: inset(0 100% 0 0%); }
}
@media (prefers-reduced-motion: reduce) {
  .nb-left, .nb-right { animation: none; clip-path: inset(0 0 0% 0); }
  .nb-turn { animation: none; opacity: 0; }
}
.brand {
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
header nav { display: flex; gap: var(--s4); }
header nav a { color: var(--muted); font-size: 0.92rem; }
header nav a:hover { color: var(--ink); text-decoration: none; }

main { max-width: 1040px; margin: var(--s8) auto; padding: 0 var(--s8); }
main.narrow { max-width: 640px; }

h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 var(--s4); }
h2 { font-size: 1.05rem; font-weight: 600; margin: var(--s8) 0 var(--s3); }
p { margin: var(--s3) 0; }
.hint, .empty, .muted { color: var(--muted); }
.hint { font-size: 0.9rem; }
.empty { padding: var(--s6) 0; }

/* --- Flash messages: subtle, not a boxy banner --- */
.flashes { list-style: none; margin: 0 0 var(--s4); padding: 0; }
.flashes li {
  padding: var(--s2) var(--s3);
  background: var(--accent-weak);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.92rem;
  margin-bottom: var(--s2);
}

/* --- Tables: dense, hairline rows, scannable (01-ui-principles §1) --- */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
thead th {
  text-align: left;
  font-weight: 550;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--faint);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line-strong);
}
tbody td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #fcfcfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.date { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.doi, .slug { font-family: var(--mono); font-size: 0.78rem; color: var(--faint); }
.paper-title { font-weight: 500; }

/* Row metadata: authors line, then a visible venue + faint doi. */
.authors {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60ch;
}
.authors .more { color: var(--faint); }
.meta { margin-top: 2px; display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.venue { color: var(--ink); font-size: 0.82rem; font-weight: 500; }

/* --- Status tabs: a low-chrome segmented control (01-ui-principles §4 queues) --- */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s4); }
.tabs a {
  padding: var(--s2) var(--s3);
  color: var(--muted);
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); font-weight: 550; border-bottom-color: var(--accent); }
.tabs .count {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--faint);
  margin-left: var(--s1);
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 0 var(--s2);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 550;
  line-height: 1.5;
}
.badge.new { background: var(--line); color: var(--muted); }
.badge.important { background: var(--ok-weak); color: var(--ok); }
.badge.later { background: var(--warn-weak); color: var(--warn); }
.badge.hidden { background: var(--danger-weak); color: var(--danger); }

/* --- Toolbar above a queue --- */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s3);
}
.toolbar .grow { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

/* --- Buttons (01-ui-principles §1: one accent, used sparingly) --- */
button, .button {
  font: inherit;
  font-size: 0.9rem;
  padding: var(--s2) var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--faint); text-decoration: none; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: #2f5fd8; border-color: #2f5fd8; }

/* compact ghost buttons for in-row curation */
.curate { display: inline-flex; align-items: stretch; gap: var(--s1); }
/* forms are layout-neutral so every button (incl. the form-wrapped ones and the bare
   Promote) is a direct, equal-height flex item — no per-form box inflating the row. */
.curate form { display: contents; }
.curate button {
  padding: 2px var(--s2);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: nowrap;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.curate button[disabled] { opacity: 0.7; cursor: not-allowed; }
.curate button.keep:hover { color: var(--ok); border-color: var(--ok); }
.curate button.later:hover { color: var(--warn); border-color: var(--warn); }
.curate button.hide:hover { color: var(--danger); border-color: var(--danger); }
.curate button.promote { color: var(--accent); border-color: var(--accent-weak); }
.curate button.promote:hover { background: var(--accent-weak); }
/* promoted (07-promotion): a link standing in for the spent Promote button */
.curate .promoted {
  padding: 2px var(--s2);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--ok);
  border-color: var(--ok);
}
.curate .promoted:hover { background: var(--ok-weak, var(--accent-weak)); text-decoration: none; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-weak); }

/* --- Forms (01-ui-principles §1 narrow measure, §3 input safety) --- */
form { margin: 0; }
.field { margin: var(--s3) 0; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: var(--s1); }
input[type="text"], textarea, select {
  width: 100%;
  font: inherit;
  padding: var(--s2) var(--s3);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
textarea { font-family: var(--mono); font-size: 0.85rem; resize: vertical; }
select { width: auto; }
.inline-form { display: flex; gap: var(--s2); align-items: flex-end; }
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: var(--s1);
}
input.invalid, textarea.invalid { border-color: var(--danger); }

/* --- Pager --- */
.pager { display: flex; align-items: center; gap: var(--s4); margin-top: var(--s4); color: var(--muted); font-size: 0.9rem; }
.pager .pos { font-variant-numeric: tabular-nums; }

/* --- Dashboard panels: separated by space, not boxes --- */
section + section { margin-top: var(--s8); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
}

/* --- Pull progress --- */
dl.pull-stats { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s4); margin: var(--s4) 0; }
dl.pull-stats dt { color: var(--faint); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
dl.pull-stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.done { color: var(--ok); }
.warn { color: var(--warn); }

/* --- Responsiveness (01-ui-principles §2): pending state + indicator --- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
button.htmx-request, .htmx-request button { opacity: 0.55; pointer-events: none; }
tr.htmx-request { opacity: 0.4; transition: opacity 0.15s; }
.spinner {
  display: inline-block;
  width: 0.85em; height: 0.85em;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: -0.1em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ingestion review form (label-wraps-input layout) */
form label > input[type="text"] { margin-top: var(--s1); }
.row { display: flex; gap: var(--s4); }
.row label { flex: 1; }
fieldset.author {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: var(--s3) 0;
  padding: 0 var(--s4) var(--s2);
}
fieldset.author legend { color: var(--faint); font-size: 0.8rem; padding: 0 var(--s1); }

/* file input / details (ingestion review) */
input[type="file"] { font-size: 0.9rem; }
details.rawtext { margin-top: var(--s8); }
details.rawtext pre {
  max-height: 320px; overflow: auto; padding: var(--s4);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  white-space: pre-wrap; font-size: 0.8rem; color: var(--muted);
}

/* === Paper view: full-width split-pane (02-paper-view) ============================== */

main.paper-view {
  position: relative;
  max-width: none;
  margin: 0;
  padding: 0;
  height: calc(100vh - 52px);
  overflow: hidden;
  display: flex;
  align-items: stretch;
}

/* --- Versions panel (05-paper-version-panel) — lives inside .metadata-pane, left-panel only --- */

.versions-panel {
  flex-shrink: 0;
  overflow-x: auto;
  /* Scroll-shadow (no JS, 01-ui-principles §6): fades an edge only while content is hidden there;
     the local-attached stop matches --bg exactly so it erases the shadow at each end. */
  background:
    linear-gradient(to right, var(--bg) 0%, rgba(251, 251, 252, 0) 100%) left / 24px 100% no-repeat local,
    linear-gradient(to left,  var(--bg) 0%, rgba(251, 251, 252, 0) 100%) right / 24px 100% no-repeat local,
    linear-gradient(to right, rgba(28, 28, 31, 0.12), rgba(28, 28, 31, 0)) left / 10px 100% no-repeat scroll,
    linear-gradient(to left,  rgba(28, 28, 31, 0.12), rgba(28, 28, 31, 0)) right / 10px 100% no-repeat scroll;
}

.versions-track {
  display: flex;
  align-items: flex-end; /* bottom-align chips so every dot lands on the same line */
  gap: var(--s6);
  border-bottom: 2px solid var(--line-strong);
  padding-bottom: 8px; /* room for the dot to straddle the border, see .version-chip-dot */
  margin-bottom: 4px;
}

.version-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-decoration: none;
  white-space: nowrap;
  color: var(--accent); /* sibling versions are links: accent blue */
}
.version-chip:hover { opacity: 0.8; }

.version-chip--current {
  color: var(--ink); /* the version being viewed: plain text, not a link, ink black */
  cursor: default;
}

.version-chip-label {
  font-size: 0.85rem;
  font-weight: 600;
}
.version-chip-date {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

/* Timeline dot centered on .versions-track's border-bottom, evenly spaced by chip. */
.version-chip-dot {
  position: absolute;
  bottom: -12px; /* = track padding-bottom (8px) + half the dot's own height (4px) */
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--accent);
}
.version-chip--current .version-chip-dot {
  background: var(--ink);
  border-color: var(--ink);
}

/* Flash messages inside the paper-view sit as an overlay, not a flex child. */
main.paper-view > .flashes {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 20;
  margin: 0;
  padding: 0 var(--s6);
  background: rgba(251, 251, 252, 0.96);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

/* --- Metadata pane (left) --- */

.metadata-pane {
  width: 50%;
  min-width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: var(--s5, 1.25rem) var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  background: transparent;
}

/* --- Draggable divider --- */

.split-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--line);
  transition: background 0.15s;
  user-select: none;
  touch-action: none;
}
.split-handle:hover,
.split-handle.dragging { background: var(--line-strong); }

/* --- PDF pane (right) --- */

.pdf-pane {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #525659;
}

.pdf-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #bbb;
  padding: var(--s4);
  gap: var(--s3);
}

/* PDF upload form inside the empty pane */
#pdf-upload-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  max-width: 320px;
}

.pdf-upload-label {
  display: block;
  width: 100%;
  padding: var(--s4) var(--s3);
  border: 2px dashed #666;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.pdf-upload-label:hover { border-color: var(--accent); background: rgba(255,255,255,0.04); }

.pdf-upload-label input[type="file"] {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.pdf-upload-hint { font-size: 0.85rem; }

.pdf-empty.drag-over .pdf-upload-label,
.pdf-empty.drag-over { border-color: var(--accent); }
.pdf-empty.drag-over { background: rgba(255,255,255,0.04); }

.upload-error {
  color: var(--danger);
  font-size: 0.85rem;
}

/* DOI external link in the label row */
a.meta-label-link {
  font-size: 0.72rem;
  color: var(--muted);
  text-decoration: none;
  margin-left: 0.25em;
}
a.meta-label-link:hover { text-decoration: underline; }

/* --- Compact paper title --- */

.paper-title-input {
  width: 100%;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: var(--s1) var(--s2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  margin: 0;
}
.paper-title-input:focus {
  border-color: var(--line);
  background: var(--panel);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-weak);
}

/* --- Scalar metadata row --- */

.meta-row {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s3);
}
.meta-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
}
.meta-field > span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.meta-field input[type="text"] {
  font-size: 0.85rem;
  padding: var(--s1) var(--s2);
}
.meta-field--wide  { flex: 2; }
.meta-field--narrow { flex: 1; min-width: 80px; }

/* --- Authors compact list --- */

.authors-section h2 { margin-top: var(--s3); margin-bottom: var(--s2); }

.authors-compact {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.88rem;
  line-height: 1.45;
  cursor: pointer;
}
.authors-compact:hover { color: var(--accent); }

.authors-more {
  color: var(--faint);
  font-style: normal;
}

.authors-collapse {
  font-size: 0.78rem;
  color: var(--faint);
  cursor: pointer;
  user-select: none;
  padding-bottom: var(--s2);
}
.authors-collapse:hover { color: var(--accent); }

.authors-list { display: flex; flex-direction: column; }

.author-row {
  border-top: 1px solid var(--line);
  padding: var(--s2) 0;
}
.author-row:first-child { border-top: none; }

.author-summary {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  cursor: pointer;
  user-select: none;
}
.author-toggle {
  font-size: 0.55rem;
  color: var(--faint);
  display: inline-block;
  transition: transform 0.15s;
  flex-shrink: 0;
  width: 0.7em;
}
.author-toggle.open { transform: rotate(90deg); }
.author-name { font-size: 0.88rem; flex: 1; }
.author-index { font-size: 0.78rem; color: var(--faint); }

.author-detail {
  padding-top: var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

/* --- Action bar --- */

.action-bar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s4);
}
.action-bar button {
  padding: 3px var(--s3);
  font-size: 0.85rem;
}

/* --- References panel --- */

.refs-section { display: flex; flex-direction: column; }
.refs-section h2 {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: 0;
  margin-bottom: var(--s2);
}
.refs-section .count { font-size: 0.82rem; font-weight: 400; color: var(--faint); }

.refs-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden; /* clip .ref-link slices to the list's rounded corners */
}

.ref-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: var(--s2);
  border-bottom: 1px solid var(--line);
  font-size: 0.82rem;
  align-items: stretch;
}
.ref-row:last-child { border-bottom: none; }

.ref-num {
  font-variant-numeric: tabular-nums;
  color: var(--faint);
  text-align: right;
  padding: var(--s2) 0 var(--s2) var(--s3);
}
.ref-text {
  padding: var(--s2) 0;
  min-width: 0; /* allow the clamp span below to actually constrain to the grid track */
  /* .ref-row stretches .ref-link to full row height (03-reference-linking); opt this cell out so its
     clamped child sizes to two lines instead of the row's stretched height. */
  align-self: start;
}
/* -webkit-line-clamp lives on a plain (non-grid-item) child: a `-webkit-box` element
   that is itself a grid/flex item gets its `display` "blockified" inconsistently across
   engines (Firefox in particular drops the clamp entirely in that position), so the
   clamp box must be nested one level below the grid cell. */
.ref-text-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.icon-btn:hover { opacity: 0.75; }

/* --- PDF toolbar --- */

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  background: #3d4043;
  color: #e8eaed;
  flex-shrink: 0;
}
.pdf-toolbar .icon-btn { color: #e8eaed; font-size: 1rem; padding: 2px var(--s2); }
.pdf-toolbar .icon-btn:hover { background: rgba(255,255,255,0.12); border-radius: 4px; opacity: 1; }
.pdf-page-info { font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* --- PDF pages container --- */

.pdf-pages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
}

/* --- Individual page --- */

.pdf-page {
  position: relative;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.55);
}
.pdf-page canvas { display: block; }

.text-layer,
.highlight-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Text layer: invisible spans positioned by PDF.js over the canvas. */
.text-layer { line-height: 1; }
.text-layer span,
.text-layer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.text-layer ::selection { background: rgba(0,100,255,0.18); color: transparent; }

.highlight-layer { pointer-events: none; }

.pdf-highlight {
  position: absolute;
  background: rgba(255,210,0,0.38);
  mix-blend-mode: multiply;
  border-radius: 2px;
  transition: opacity var(--_fade, 0s);
}
.pdf-highlight.fade { --_fade: 0.4s; opacity: 0; }

/* --- Responsive: stack on narrow viewports --- */

@media (max-width: 860px) {
  main.paper-view {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .metadata-pane { width: 100%; overflow: visible; }
  .split-handle  { display: none; }
  .pdf-pane      { height: 70vh; }
}

/* --- Reference linking (03-reference-linking) --- */

/* Secondary button style (used in several templates) */
button.secondary, .button.secondary {
  color: var(--muted);
  border-color: var(--line-strong);
}
button.secondary:hover, .button.secondary:hover {
  color: var(--ink);
  border-color: var(--faint);
}
button.small, .button.small {
  padding: 1px var(--s2);
  font-size: 0.8rem;
}

/* Ref-link navigation control: a full-row-height colored slice (02-paper-view §3, 03-reference-linking §1) */
.ref-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6rem;
  font-size: 1rem;
  text-decoration: none;
}
.ref-link--linked { background: var(--ok); color: #fff; }
.ref-link--linked:hover { opacity: 0.88; }
.ref-link--candidates { background: var(--accent-weak); color: var(--accent); }
.ref-link--candidates:hover { background: #e2e9fd; }
.ref-link--fetch { background: var(--line-strong); color: var(--muted); }
.ref-link--fetch:hover { background: var(--line-strong); color: var(--ink); }

.ref-rejected-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--danger);
  cursor: default;
}

/* Breadcrumb navigation */
.breadcrumb { margin-bottom: var(--s4); font-size: 0.9rem; }

/* Candidates page */
.candidates-page, .fetch-page {
  max-width: 960px;
  margin: var(--s6) auto;
  padding: 0 var(--s6);
}
.candidates-page h1, .fetch-page h1 {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  margin-bottom: var(--s2);
}
.candidates-page h1 .count {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--faint);
}
.ref-summary {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: var(--s4);
  line-height: 1.45;
  font-style: italic;
}

/* Link status banners */
.link-status {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: var(--s4);
}
.link-status.linked { background: var(--ok-weak); color: var(--ok); }
.link-status.linked a { color: var(--ok); text-decoration: underline; }
.link-status.rejected { background: var(--danger-weak); color: var(--danger); }

/* Candidates table */
.candidates-scroll { overflow-x: auto; margin-bottom: var(--s3); }
.candidates-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.candidates-table th {
  text-align: left;
  padding: var(--s2) var(--s3);
  border-bottom: 2px solid var(--line-strong);
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.candidates-table td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.candidates-table tbody tr:last-child td { border-bottom: none; }
.candidates-table tbody tr:hover { background: var(--accent-weak); }
.col-check { width: 2rem; text-align: center; }
.col-date  { width: 8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-authors { max-width: 14rem; }
.col-venue   { max-width: 10rem; }
.col-status  { width: 6rem; white-space: nowrap; }
.date-warn { color: var(--warn); margin-left: var(--s1); }

/* Secondary action row below the candidates form */
.secondary-actions {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s4);
}

/* Fetch page */
.ref-raw {
  font-size: 0.85rem;
  font-family: var(--mono);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Identity chrome and the sign-in surface (02-authentication). Low-chrome and dense, like the
   rest: the signed-in user is a quiet label, not a widget. */
.who {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.92rem;
  color: var(--muted);
}
.who a { color: var(--muted); }
.who a:hover { color: var(--ink); text-decoration: none; }
.who form { display: inline; margin: 0; }

/* A button that reads as a link — used for POST-only actions (sign out) that must not be a
   GET link (02-authentication §"logout"). */
.linklike {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}
.linklike:hover { color: var(--ink); }

/* Stacked form fields, for the two identity forms. */
.stack { display: flex; flex-direction: column; gap: var(--s3); max-width: 22rem; }
.stack label { display: flex; flex-direction: column; gap: var(--s1); font-size: 0.92rem; }
.stack button { align-self: flex-start; }

/* AGPL §13's offer has to be visible, so it lives in the page footer (04-licensing). */
/* .source-offer {
  padding: var(--s3) var(--s8);
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.82rem;
} */

/* ---------------------------------------------------------------------------
   Public shell: sign-in and about (02-authentication). No header; the page is
   a full-viewport column with the content block, the reserved animation stage,
   and a thin footer.
   --------------------------------------------------------------------------- */
body.public {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #eef3f8 0%, var(--bg) 55%);
}
.public-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s8);
  padding: var(--s8) var(--s6);
}
.public-flashes { max-width: 60rem; margin: 0 auto; width: 100%; }

/* The two blocks straddle the centre line: identity ends just left of it, the form starts just
   right of it. One centred grid does that at every width without magic offsets. */
.signin {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s8);
  align-items: center;
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
}
.signin-identity { text-align: right; }
.signin-form { max-width: 22rem; }

.brand-mark {
  margin: 0;
  font-size: clamp(2.75rem, 7vw, 5rem);
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 600;
  color: var(--ink);
}
.brand-inline {
  text-shadow: 1px 1px 1px var(--bg), -1px -1px 1px var(--bg), 0px 0px 5px var(--accent);
}
.signin-identity .tagline {
  margin: var(--s3) 0 0;
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 26rem;
  margin-left: auto;
}
.stage-note { margin: var(--s4) 0 0; }
.chip {
  display: inline-block;
  padding: 0.1rem var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.signin-form h2 {
  margin: 0 0 var(--s3);
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

/* Reserved for the graph-traversal animation. Sized now so its arrival does not reflow the
   page; the dotted rule is a placeholder, not a design. */
.graph-stage {
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
  min-height: 12rem;
  border-top: 1px dotted var(--line);
}

.public-footer {
  display: flex;
  align-items: center;
  gap: var(--s6);
  padding: var(--s3) var(--s8);
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--faint);
}
.public-footer nav { display: flex; gap: var(--s4); }
.public-footer a { color: var(--muted); }
.public-footer .source-offer {
  margin-left: auto;
  padding: 0;
  border: 0;
}

.prose { max-width: 40rem; margin: 0 auto; }
.prose h1 { margin-top: 0; }

@media (max-width: 46rem) {
  .signin { grid-template-columns: 1fr; gap: var(--s6); }
  .signin-identity { text-align: left; }
  .signin-identity .tagline { margin-left: 0; }
  .graph-stage { min-height: 6rem; }
}
