/* Ukuri Research Auditor: design tokens & shell
   Light, flat, hairline-driven. Layout follows the opencode web UI:
   quiet canvas, one bordered panel, monospace for meta, no drop shadows. */
:root {
  --canvas: #f4f4f3;
  --panel: #ffffff;
  --surface: #fafaf9; /* inset areas inside the panel */
  --surface-2: #f3f3f1; /* hover / pressed */
  --hairline: #e6e6e3;
  --hairline-strong: #d4d4d0;
  --ink: #1a1a18;
  --ink-muted: #6b6b66;
  --ink-faint: #a1a19b;
  /* Imigongo clay: the rust-red earth of Rwandan Imigongo art */
  --accent: #b4441c;
  --accent-strong: #933617;
  --accent-soft: #fbf1ec;
  --accent-line: #efd3c6;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --ghost: #6d28d9;

  --radius-panel: 8px;
  --radius-card: 6px;
  --radius-btn: 5px;

  --sidebar-w: 228px;

  --font-serif: "Fraunces", Georgia, serif;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono:
    "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
}
body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
::selection {
  background: #f6d9cc;
}

/* ---------- App shell ---------- */
.shell {
  display: flex;
  gap: 12px;
  height: 100dvh;
  padding: 12px;
}

/* ---------- Sidebar ---------- */
/* The sidebar partial is injected into <div data-component="sidebar">. Let the
   wrapper vanish from layout so the <aside> itself is the full-height flex child. */
[data-component="sidebar"] { display: contents; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 4px 0 8px;
  min-height: 0;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  text-decoration: none;
  color: inherit;
}
.wordmark-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  color: var(--accent);
  display: block;
}
.wordmark:hover .wordmark-mark {
  color: var(--accent-strong);
}
.wordmark-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.wordmark-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.015em;
  line-height: 1;
}
.wordmark-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  color: var(--ink-faint);
  letter-spacing: 0.01em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  padding: 8px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition:
    background 0.12s ease,
    color 0.12s ease,
    border-color 0.12s ease;
}

.nav-item:hover {
  background: #ececea;
  color: var(--ink);
}
.nav-item.is-active {
  background: var(--panel);
  border-color: var(--hairline);
  color: var(--ink);
}

.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--hairline-strong);
  border-radius: 5px;
  min-width: 20px;
  text-align: center;
  padding: 0 5px;
  font-variant-numeric: tabular-nums;
}

.served-by {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  width: max-content;
}
.served-by .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ink-faint);
}
.served-by[data-state="ok"] .dot {
  background: var(--ok);
}
.served-by[data-state="error"] .dot {
  background: var(--danger);
}

/* ---------- Main panel ---------- */
.panel {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 48px;
  padding: 0 18px;
  border-bottom: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.topbar-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.topbar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.topbar-link {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  background: transparent;
  text-decoration: none;
  border: 1px solid var(--hairline);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition:
    color 0.12s ease,
    border-color 0.12s ease;
}
.topbar-link:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.page {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 36px 34px 56px;
  min-height: 0;
}
.page-inner {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.page-inner-wide {
  max-width: 1040px;
}

.page-head {
  margin-bottom: 24px;
}
.page-heading {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 28px;
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.page-sub {
  color: var(--ink-muted);
  font-size: 14px;
  margin-top: 6px;
  max-width: 62ch;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}

/* ---------- Primitives ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--hairline);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius-btn);
  padding: 0 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color 0.12s ease,
    color 0.12s ease,
    background 0.12s ease;
}
.btn:hover {
  border-color: var(--hairline-strong);
  background: var(--surface);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf7;
}
.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-muted);
}
.btn-ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--ink);
}
.btn-danger,
.btn-danger:hover {
  border-color: #f0c7c7;
  background: #fdf3f3;
  color: var(--danger);
}
.btn-small {
  height: 26px;
  font-size: 12px;
  padding: 0 9px;
  border-radius: 6px;
}

.btn:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 16px;
}

.input,
select.input,
textarea.input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-btn);
  padding: 7px 11px;
  transition: border-color 0.12s ease;
}
.input::placeholder {
  color: var(--ink-faint);
}
.input:hover {
  border-color: var(--hairline-strong);
}
.input:focus {
  border-color: var(--accent-line);
  outline: 3px solid var(--accent-soft);
}
.input:focus-visible {
  outline: 3px solid var(--accent-soft);
}
.input-mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  border-radius: 5px;
  padding: 1px 7px;
  border: 1px solid var(--hairline);
  color: var(--ink-muted);
  background: var(--surface);
  text-decoration: none;
}
.badge-oa {
  color: var(--ok);
  border-color: #cfe8d5;
  background: #f2f9f3;
}
.badge-retracted {
  color: var(--danger);
  border-color: #f3c8c8;
  background: #fdf2f2;
}
.badge-accent {
  color: var(--accent-strong);
  border-color: #cfe4e1;
  background: var(--accent-soft);
}

.muted {
  color: var(--ink-faint);
}
.kbd-inline {
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 0 5px;
  color: var(--ink);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 56px 20px;
  color: var(--ink-muted);
  font-size: 14px;
}
.empty-state p {
  max-width: 46ch;
}
.empty-state .btn {
  margin-top: 8px;
}
.empty-title {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.015em;
}
.error-box .empty-title {
  color: var(--danger);
}

.toast-wrap {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: var(--ink);
  color: #f6f6f4;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  max-width: 420px;
  animation: rise 0.2s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Search page ----------
   Two states on #searchPage[data-state]:
   idle    → composer centered in the panel, like starting a new chat
   results → composer docks to the top (sticky), results stream in below */
.search-page {
  padding: 0 34px;
  display: flex;
}
.search-stage {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.search-page[data-state="idle"] .search-stage {
  justify-content: center;
  padding: 0 0 12vh;
}
.search-page[data-state="results"] .search-stage {
  padding: 0 0 48px;
}

.search-hero {
  text-align: center;
  margin-bottom: 26px;
}
.search-hero-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: clamp(26px, 3.4vw, 34px);
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.search-hero-title em {
  font-style: italic;
  color: var(--accent);
}
.search-hero-sub {
  color: var(--ink-muted);
  font-size: 14px;
  margin-top: 8px;
}
.search-page[data-state="results"] .search-hero,
.search-page[data-state="results"] .suggestions {
  display: none;
}
.search-page[data-state="idle"] .results-area {
  display: none;
}

.composer {
  view-transition-name: composer;
  position: relative;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  transition: border-color 0.12s ease;
}
.composer:focus-within {
  border-color: var(--accent-line);
  outline: 3px solid var(--accent-soft);
}
.search-page[data-state="results"] .composer {
  position: sticky;
  top: 18px;
  z-index: 5;
  margin-top: 18px;
}
/* mask results scrolling under the docked composer */
.search-page[data-state="results"] .composer::before {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: -19px;
  height: 16px;
  background: var(--panel);
}

.composer-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
}
.composer-icon {
  width: 18px;
  height: 18px;
  color: var(--ink-faint);
  flex: 0 0 auto;
}
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 8px 0;
}
.composer-input::placeholder {
  color: var(--ink-faint);
}
.composer-input::-webkit-search-cancel-button {
  display: none;
}
.composer-input:focus-visible {
  outline: none;
}
.composer-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 1px 6px;
}
.composer:focus-within .composer-kbd {
  display: none;
}
.composer-submit {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fffaf7;
  cursor: pointer;
  transition:
    background 0.12s ease,
    opacity 0.12s ease;
}
.composer-submit svg {
  width: 16px;
  height: 16px;
}
.composer-submit:hover {
  background: var(--accent-strong);
}
.composer-input:placeholder-shown ~ .composer-submit {
  opacity: 0.3;
}
.composer-submit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.composer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--hairline);
}
.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 0.12s ease,
    background 0.12s ease,
    color 0.12s ease;
}
.pill:hover {
  border-color: var(--hairline-strong);
}
.pill:focus-within {
  border-color: var(--ink-faint);
  background: var(--panel);
}
.pill-key {
  color: var(--ink-faint);
}
.pill input,
.pill select {
  font: inherit;
  color: inherit;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.pill input[type="number"] {
  width: 4.2ch;
  -moz-appearance: textfield;
}
.pill input[type="number"]::-webkit-inner-spin-button,
.pill input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.pill input::placeholder {
  color: var(--ink-faint);
}
.pill select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%236b6b66' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right center / 10px 10px;
}
.pill:has(select):hover select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%231a1a18' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
/* fallback chevron for any native select we style as an input */
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background: var(--panel)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%236b6b66' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 11px center / 10px 10px;
}
/* menu buttons (Export) get the same affordance */
[aria-haspopup="true"]::after {
  content: "";
  width: 10px;
  height: 10px;
  margin-right: -2px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%236b6b66' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat center / 10px 10px;
  transition: transform 0.15s ease;
}
[aria-haspopup="true"][aria-expanded="true"]::after {
  transform: rotate(180deg);
}
.pill-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1.5px solid var(--ink-faint);
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
}
.pill-toggle:has(input:checked) {
  border-color: #cfe8d5;
  background: #f2f9f3;
  color: var(--ok);
}
.pill-toggle:has(input:checked) .pill-dot {
  background: var(--ok);
  border-color: var(--ok);
}
.pill-toggle:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}
.suggestion {
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  transition:
    color 0.12s ease,
    border-color 0.12s ease,
    background 0.12s ease;
}
.suggestion:hover {
  color: var(--accent-strong);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.results-area {
  animation: rise 0.28s ease both;
}
.results-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  min-height: 18px;
  margin: 18px 2px 4px;
}

/* Shared flat list (search results + reading list) */
.results-list {
  display: flex;
  flex-direction: column;
}
.results-list > .result-card {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  padding: 16px 2px;
}
.results-list > .result-card:last-child {
  border-bottom: 0;
}
.result-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: rise 0.25s ease both;
}
.result-card:nth-child(2) {
  animation-delay: 0.03s;
}
.result-card:nth-child(3) {
  animation-delay: 0.06s;
}
.result-card:nth-child(4) {
  animation-delay: 0.09s;
}
.result-card:nth-child(n + 5) {
  animation-delay: 0.12s;
}
.result-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.result-title:hover {
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-color: var(--accent-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.result-authors {
  font-size: 13px;
  color: var(--ink-muted);
}
.result-journal {
  font-size: 12.5px;
  color: var(--ink-muted);
  font-style: italic;
}
.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.result-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.result-actions .btn {
  height: 26px;
  font-size: 12px;
  padding: 0 9px;
  border-radius: 6px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-muted);
}
.result-actions .btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.result-actions .btn[aria-pressed="true"] {
  color: var(--accent-strong);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 32px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0 10px;
  background: transparent;
}
.page-btn.is-current {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-strong);
}

.skeleton {
  gap: 10px;
}
.sk-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #efefed 0%, #f7f7f5 50%, #efefed 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.sk-line.w70 {
  width: 70%;
  height: 16px;
}
.sk-line.w45 {
  width: 45%;
}
.sk-line.w55 {
  width: 55%;
}
@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

::view-transition-group(composer) {
  animation-duration: 0.38s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.22s;
}

/* ---------- Cite page ---------- */
.lookup {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 6px 6px 6px 14px;
  margin-bottom: 16px;
  transition: border-color 0.12s ease;
}
.lookup:focus-within {
  border-color: var(--accent-line);
  outline: 3px solid var(--accent-soft);
}
.lookup-prefix {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-faint);
  border-right: 1px solid var(--hairline);
  padding-right: 10px;
}
.lookup-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--ink);
  padding: 6px 0;
}
.lookup-input::placeholder {
  color: var(--ink-faint);
}
.lookup-input:focus-visible {
  outline: none;
}

.cite-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 14px;
  align-items: start;
}
.cite-form .section-label {
  margin-bottom: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 12px;
}
.field .input {
  font-weight: 400;
}
.field-hint {
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 10.5px;
}
.field-2col {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
}
.field-3col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.cite-status {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  min-height: 18px;
  margin-bottom: 8px;
}
.cite-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

.cite-preview {
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--surface);
  position: sticky;
  top: 0;
}
.preview-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.apa-preview {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.65;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 14px 16px;
  padding-left: calc(16px + 2em);
  text-indent: -2em; /* APA hanging indent */
  overflow-wrap: anywhere;
}
.apa-inline {
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 14px;
  text-indent: 0;
}

/* ---------- Audit page ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 2px;
  margin-bottom: 12px;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-muted);
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.12s ease;
}
.tab:hover {
  color: var(--ink);
}
.tab.is-active {
  background: var(--panel);
  border-color: var(--hairline);
  color: var(--accent-strong);
}
.audit-pane {
  margin-bottom: 12px;
}
.pane-hint {
  font-size: 13px;
  color: var(--ink-muted);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius-card);
  padding: 30px 20px;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
  background: var(--surface);
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}
.dropzone:hover,
.dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone:hover .dropzone-icon,
.dropzone.dragging .dropzone-icon {
  color: var(--accent);
}
.dropzone-icon {
  width: 26px;
  height: 26px;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.dropzone-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.extract-status {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 8px;
  min-height: 18px;
}

.editor {
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-card);
  overflow: hidden;
  transition: border-color 0.12s ease;
}
.editor:focus-within {
  border-color: var(--accent-line);
  outline: 3px solid var(--accent-soft);
}
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.ref-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.editor-input {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  resize: vertical;
  min-height: 180px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--panel);
}
.editor-input::placeholder {
  color: var(--ink-faint);
}
.editor-input:focus-visible {
  outline: none;
}
.editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--hairline);
}
.editor-actions {
  display: flex;
  gap: 6px;
}
.audit-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}

.progress-wrap {
  margin-top: 20px;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.progress-bar {
  height: 3px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 3%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.progress-text {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* collapsed input after a run */
.input-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.input-summary-text {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
}

/* verdict colours, shared by badges, bar segments and filters */
.v-valid {
  --v: var(--ok);
}
.v-mismatch {
  --v: var(--warn);
}
.v-ghost {
  --v: var(--ghost);
}
.v-retracted {
  --v: var(--danger);
}
.v-unverifiable {
  --v: var(--ink-faint);
}

/* ---- report header ---- */
.report {
  margin-top: 24px;
  animation: rise 0.25s ease both;
}
.report-head {
  display: flex;
  align-items: center;
  gap: 20px;
}
.report-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 92px;
  height: 92px;
  flex: 0 0 auto;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.report-score-num {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.report-score-num[data-tone="good"] {
  color: var(--ok);
}
.report-score-num[data-tone="ok"] {
  color: var(--warn);
}
.report-score-num[data-tone="bad"] {
  color: var(--danger);
}
.report-score-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 6px;
}
.report-headline {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.report-sub {
  font-size: 13.5px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.report-bar {
  display: flex;
  gap: 2px;
  height: 6px;
  margin: 18px 0 16px;
  border-radius: 999px;
  overflow: hidden;
}
.report-seg {
  background: var(--v);
  min-width: 4px;
  transition: flex-grow 0.4s ease;
}
.report-seg.is-pending {
  background: repeating-linear-gradient(
    -45deg,
    var(--surface-2) 0 4px,
    var(--hairline) 4px 8px
  );
}

/* ---- filters + tools ---- */
.report-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--hairline);
}
.report-tools-right {
  display: flex;
  gap: 6px;
  align-items: center;
}
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease,
    border-color 0.12s ease;
}
.filter-btn::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--v, transparent);
  display: var(--dot, inline-block);
}
.filter-btn:not([class*="v-"]):not(.is-attention)::before {
  display: none;
}
.filter-btn.is-attention::before {
  background: var(--accent);
}
.filter-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}
.filter-btn[aria-pressed="true"] {
  background: var(--panel);
  border-color: var(--hairline-strong);
  color: var(--ink);
}
.filter-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.filter-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.filter-btn[aria-pressed="true"] .filter-count {
  color: var(--ink-muted);
}

/* ---- rows ---- */
.verdicts {
  display: flex;
  flex-direction: column;
}
.verdicts-empty {
  padding: 28px 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
}
.vrow {
  border-bottom: 1px solid var(--hairline);
}
.vrow-summary {
  display: grid;
  grid-template-columns: 22px 108px minmax(0, 1fr) 30px 14px;
  align-items: center;
  gap: 12px;
  padding: 12px 6px;
  cursor: pointer;
  list-style: none;
  border-radius: 6px;
  transition: background 0.12s ease;
}
.vrow-summary::-webkit-details-marker {
  display: none;
}
.vrow-summary:hover {
  background: var(--surface);
}
.vrow-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.vrow-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.vrow .verdict-badge {
  justify-self: start;
}
.vrow-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.vrow-title,
.vrow-reason {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vrow-title {
  font-size: 13.5px;
  color: var(--ink);
}
.vrow-reason {
  font-size: 12px;
  color: var(--ink-muted);
}
.vrow-score {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.vrow-chev {
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--ink-faint);
  border-bottom: 1.5px solid var(--ink-faint);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.vrow[open] .vrow-chev {
  transform: rotate(45deg);
}
.vrow[open] .vrow-summary {
  background: var(--surface);
}
.vrow[open] .vrow-title {
  white-space: normal;
}

.vrow-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 6px 16px calc(22px + 12px + 6px);
  animation: rise 0.18s ease both;
}
.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
  color: var(--v);
  border: 1px solid color-mix(in srgb, var(--v) 28%, transparent);
  background: color-mix(in srgb, var(--v) 6%, transparent);
  padding: 1px 8px;
  border-radius: 5px;
}
.verdict-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--v);
}
.verdict-ref {
  font-size: 13.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.cmp {
  border: 1px solid var(--hairline);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 6px;
}
.cmp-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 7px 12px;
  font-size: 13px;
  border-top: 1px solid var(--hairline);
}
.cmp-row:first-child {
  border-top: 0;
}
.cmp-head {
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  padding-top: 5px;
  padding-bottom: 5px;
}
.cmp-key {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  padding-top: 1px;
}
.cmp-mine,
.cmp-theirs {
  overflow-wrap: anywhere;
}
.cmp-row:not(.cmp-head) .cmp-mine {
  color: var(--ink-muted);
}
.cmp-row.is-diff {
  background: #fdf7ee;
}
.cmp-row.is-diff .cmp-key {
  color: var(--warn);
}
.cmp-row.is-diff .cmp-key::after {
  content: " ≠";
}
.cmp-row.is-diff .cmp-theirs {
  color: var(--ink);
  font-weight: 500;
}

.vrow-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.export-row {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.export-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .report-head {
    gap: 14px;
  }
  .report-score {
    width: 72px;
    height: 72px;
  }
  .report-score-num {
    font-size: 24px;
  }
  .vrow-summary {
    grid-template-columns: 22px minmax(0, 1fr) 14px;
  }
  .vrow .verdict-badge {
    grid-column: 2;
    grid-row: 1;
  }
  .vrow-main {
    grid-column: 2;
    grid-row: 2;
  }
  .vrow-score {
    display: none;
  }
  .vrow-chev {
    grid-column: 3;
    grid-row: 1;
  }
  .vrow-body {
    padding-left: 6px;
  }
  .cmp-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .cmp-head {
    display: none;
  }
  .cmp-mine::before {
    content: "yours: ";
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
  }
  .cmp-theirs::before {
    content: "match: ";
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
  }
}

/* ---------- Reading list ---------- */
.list-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--surface);
  margin-bottom: 14px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-left: 1px solid var(--hairline);
  min-width: 0;
}
.stat:first-child {
  border-left: 0;
}
.stat-num {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

.notice {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-card);
  border: 1px solid var(--hairline);
  margin-bottom: 14px;
}
.notice-danger {
  color: #7f1d1d;
  border-color: #f3c8c8;
  background: #fdf3f3;
}
.notice strong {
  font-weight: 600;
}
.notice-link {
  font: inherit;
  font-weight: 600;
  color: var(--danger);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.list-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}
.list-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  transition: border-color 0.12s ease;
}
.list-search:focus-within {
  border-color: var(--accent-line);
  outline: 3px solid var(--accent-soft);
}
.list-search svg {
  width: 16px;
  height: 16px;
  color: var(--ink-faint);
  flex: 0 0 auto;
}
.list-search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}
.list-search input::placeholder {
  color: var(--ink-faint);
}
.list-tools-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.select-bar {
  position: sticky;
  top: -36px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 0;
  padding: 6px 6px 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
}
.select-bar.has-selection {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
}
.select-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  cursor: pointer;
}
.check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.btn-quiet-danger {
  color: var(--danger);
}
.btn-quiet-danger:hover {
  background: #fdf3f3;
  color: var(--danger);
}

.export-menu {
  position: relative;
}
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
}
.menu button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
}
.menu button span {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.menu button:hover,
.menu button:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.saved-list {
  display: flex;
  flex-direction: column;
}
.saved-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 6px;
  padding: 14px 6px;
  border-bottom: 1px solid var(--hairline);
  animation: rise 0.2s ease both;
  transition: background 0.12s ease;
}
.saved-row:last-child {
  border-bottom: 0;
}
.saved-row:hover {
  background: var(--surface);
}
.saved-row.is-selected {
  background: var(--accent-soft);
}
.saved-check {
  padding-top: 3px;
  align-self: start;
}
.saved-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.saved-main .result-meta {
  margin-top: 0;
}
.saved-when {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.list-apa {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.6;
  padding-left: 2em;
  text-indent: -2em;
  overflow-wrap: anywhere;
}
.saved-list .result-actions {
  opacity: 0.55;
  transition: opacity 0.12s ease;
}
.saved-row:hover .result-actions,
.saved-row:focus-within .result-actions {
  opacity: 1;
}
.list-tools + .map-card,
#mapCard {
  margin-top: 14px;
}

/* ---------- Citation map (Kroki.io) ---------- */
.map-card {
  grid-column: 1 / -1;
  padding: 12px 14px;
  background: var(--surface);
}
.map-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.map-head .preview-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.map-tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 2px;
}
.map-tabs .tab {
  height: 24px;
  font-size: 11.5px;
  padding: 0 10px;
  border-radius: 5px;
}

.map-viewport {
  position: relative;
  height: 460px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background-color: var(--panel);
  background-image: radial-gradient(circle, #e4e4e0 1px, transparent 1.2px);
  background-size: 18px 18px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.map-viewport.is-dragging {
  cursor: grabbing;
}
.map-viewport:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.map-canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.map-canvas svg {
  display: block;
  max-width: none;
  height: auto;
}
.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 24px;
  text-align: center;
}

.map-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  cursor: default;
}
.map-ctrl {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}
.map-ctrl svg {
  width: 15px;
  height: 15px;
}
.map-ctrl:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.map-level {
  min-width: 48px;
  height: 28px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.map-level:hover {
  background: var(--surface-2);
}
.map-ctrl-sep {
  width: 1px;
  height: 16px;
  background: var(--hairline);
  margin: 0 3px;
}
.map-ctrl:focus-visible,
.map-level:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.map-foot {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 8px;
}

.map-card.is-fullscreen {
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: var(--canvas);
}
.map-card.is-fullscreen #citationMap {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.map-card.is-fullscreen .map-viewport {
  flex: 1 1 auto;
  height: auto;
}

/* toast with action (undo) */
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
}
.toast-action {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #f6c9b6;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.toast-action:hover {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 640px) {
  .list-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat:nth-child(3) {
    border-left: 0;
  }
  .stat:nth-child(n + 3) {
    border-top: 1px solid var(--hairline);
  }
  .saved-list .result-actions {
    opacity: 1;
  }
  .map-viewport {
    height: 360px;
  }
}

/* ---------- 404 ---------- */
.notfound {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 10vh;
}
.notfound-code {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  padding: 2px 10px;
  margin-bottom: 16px;
}
.notfound .page-sub {
  margin: 8px auto 22px;
}
.notfound-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ---------- A11y utilities ---------- */
.skip-link {
  position: fixed;
  top: -48px;
  left: 16px;
  z-index: 100;
  background: var(--accent);
  color: #fffaf7;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 5px;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 12px;
}
.page:focus {
  outline: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .cite-grid {
    grid-template-columns: 1fr;
  }
  .cite-preview {
    position: static;
  }
}
@media (max-width: 900px) {
  .shell {
    padding: 8px;
    gap: 8px;
  }
  .sidebar {
    width: 52px;
    flex: 0 0 52px;
    align-items: center;
  }
  .wordmark-text,
  .nav-label,
  .nav-item span {
    display: none;
  }
  .wordmark {
    padding: 6px 0 16px;
    justify-content: center;
  }
  .nav-item {
    justify-content: center;
    padding: 9px;
  }
  .page {
    padding: 24px 16px 40px;
  }
  .search-page {
    padding: 0 16px;
  }
  .search-page[data-state="idle"] .search-stage {
    padding-bottom: 6vh;
  }
  .composer-kbd {
    display: none;
  }
  .topbar {
    padding: 0 14px;
  }
  .field-2col {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 560px) {
  .field-3col {
    grid-template-columns: 1fr 1fr;
  }
  .result-actions {
    margin-left: 0;
    width: 100%;
  }
  .summary-score {
    margin-left: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  ::view-transition-group(*) {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- Imigongo motifs ----------
   Geometry borrowed from Rwandan Imigongo panels: nested zigzags and
   concentric diamonds, drawn in clay. Used sparingly as ornament. */
:root {
  /* two nested zigzag lines, 10px period */
  --imigongo-zigzag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='12' viewBox='0 0 10 12'%3E%3Cg fill='none' stroke='%23b4441c' stroke-width='1.4' stroke-linejoin='miter'%3E%3Cpolyline points='0,1.5 5,6 10,1.5'/%3E%3Cpolyline points='0,6 5,10.5 10,6'/%3E%3C/g%3E%3C/svg%3E");
  /* concentric diamond lattice tile */
  --imigongo-diamond: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg fill='none' stroke='%23b4441c' stroke-width='1.2'%3E%3Cpath d='M16 1 31 16 16 31 1 16Z'/%3E%3Cpath d='M16 7 25 16 16 25 7 16Z'/%3E%3C/g%3E%3Cpath d='M16 12.5 19.5 16 16 19.5 12.5 16Z' fill='%23b4441c'/%3E%3C/svg%3E");
}

/* small zigzag band under page headings */
.page-head::after,
.imigongo-mark {
  content: "";
  display: block;
  width: 60px;
  height: 12px;
  margin-top: 14px;
  background: var(--imigongo-zigzag) repeat-x left center / 10px 12px;
  -webkit-mask: linear-gradient(90deg, #000 60%, transparent);
  mask: linear-gradient(90deg, #000 60%, transparent);
}
.imigongo-mark {
  margin: 0 auto 18px;
  width: 80px;
  -webkit-mask: linear-gradient(
    90deg,
    transparent,
    #000 30%,
    #000 70%,
    transparent
  );
  mask: linear-gradient(90deg, transparent, #000 30%, #000 70%, transparent);
}

/* search idle state: a faint diamond lattice rising from the bottom of the panel */
.search-page {
  position: relative;
}
.search-page::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  pointer-events: none;
  background: var(--imigongo-diamond) repeat center bottom / 32px 32px;
  opacity: 0.09;
  -webkit-mask: linear-gradient(to top, #000, transparent 85%);
  mask: linear-gradient(to top, #000, transparent 85%);
  transition: opacity 0.3s ease;
}
.search-page[data-state="results"]::after {
  opacity: 0;
}
.search-stage {
  position: relative;
  z-index: 1;
}

/* empty states carry a single diamond */
.empty-state:not(.error-box)::before {
  content: "";
  width: 32px;
  height: 32px;
  margin-bottom: 6px;
  background: var(--imigongo-diamond) no-repeat center / 32px 32px;
  opacity: 0.8;
}

/* 404: a framed diamond field behind the code */
.notfound::before {
  content: "";
  width: 96px;
  height: 96px;
  margin-bottom: 18px;
  background: var(--imigongo-diamond) repeat center / 32px 32px;
  -webkit-mask: radial-gradient(circle, #000 40%, transparent 72%);
  mask: radial-gradient(circle, #000 40%, transparent 72%);
}

@media (max-width: 900px) {
  .search-page::after {
    height: 30%;
  }
}

/* ---------- Sidebar: secondary nav ---------- */
.nav-secondary {
  margin-top: auto;
}
.nav-sep {
  display: block;
  height: 12px;
  margin: 12px 10px 12px;
  background: var(--imigongo-zigzag) repeat-x left center / 10px 12px;
  opacity: 0.35;
}

/* ---------- Topbar server chip ---------- */
.topbar .served-by {
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
}

/* ---------- Credits ---------- */
.credit-group {
  margin-top: 28px;
}
.credit-group:first-of-type {
  margin-top: 0;
}
.credit-list {
  list-style: none;
  border-top: 1px solid var(--hairline);
  margin-top: 8px;
}
.credit {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 4px 18px;
  align-items: baseline;
  padding: 12px 2px;
  border-bottom: 1px solid var(--hairline);
}
.credit-name {
  font-family: var(--font-serif);
  font-size: 15.5px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}
.credit-name::after {
  content: " ↗";
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.credit-name:hover {
  color: var(--accent-strong);
}
.credit-role {
  font-size: 13.5px;
  color: var(--ink-muted);
}
.credit .badge {
  justify-self: end;
}
.infra {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13.5px;
  color: var(--ink-muted);
  background: var(--surface);
}
.infra-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.served-by-lg {
  font-size: 12px;
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
  background: var(--panel);
  border-radius: 6px;
  padding: 2px 9px;
}

@media (max-width: 900px) {
  .nav-sep {
    margin: 0 4px 8px;
    width: 30px;
  }
}
@media (max-width: 640px) {
  .credit {
    grid-template-columns: 1fr auto;
  }
  .credit-role {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .topbar .served-by {
    display: none;
  }
}

/* Search: the topbar only appears once the first search has run */
body[data-search-state="idle"] .topbar {
  display: none;
}
body[data-search-state="results"] .topbar {
  view-transition-name: topbar;
}

[hidden] {
  display: none !important;
}

/* ---------- Cite: lookup results, source bar, checks, formats, map ---------- */
.lookup-wrap {
  position: relative;
  margin-bottom: 10px;
}
.lookup-wrap .lookup {
  margin-bottom: 0;
}
.lookup-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
}
.lookup-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  width: 100%;
  font: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 5px;
  padding: 8px 10px;
  cursor: pointer;
}
.lookup-option.is-active {
  background: var(--accent-soft);
}
.lookup-option-title {
  font-family: var(--font-serif);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.35;
}
.lookup-option-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}

.source-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin-bottom: 12px;
}
.source-bar .cite-status {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
}
.source-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ink-faint);
}
.source-chip[data-kind="linked"] {
  color: var(--accent-strong);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.source-chip[data-kind="linked"] .dot {
  background: var(--accent);
}
.source-chip[data-kind="edited"] {
  color: var(--warn);
  border-color: #f1dcbf;
  background: #fdf7ee;
}
.source-chip[data-kind="edited"] .dot {
  background: var(--warn);
}

.field.is-missing {
  color: var(--ink);
}
.field.is-missing .input:placeholder-shown {
  border-style: dashed;
}

.code-preview {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0;
  max-height: 280px;
  overflow: auto;
}
.preview-head .map-tabs .tab {
  height: 24px;
  font-size: 11.5px;
  padding: 0 10px;
  border-radius: 5px;
}

.checks {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: -6px;
}
.check-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-muted);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 3px 6px;
  cursor: pointer;
}
.check-item::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--warn);
  flex: 0 0 auto;
  transform: translateY(-1px);
}
.check-item:hover {
  background: var(--panel);
  color: var(--ink);
}

.cite-preview .notice {
  margin-bottom: 0;
}

.map-collapsible {
  margin: 0 0 14px;
  padding: 0;
}
.map-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 12px 14px;
  cursor: pointer;
  border-radius: var(--radius-card);
}
.map-toggle:hover {
  background: var(--surface-2);
}
.map-toggle-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}
.map-toggle-meta {
  flex: 1 1 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.map-collapsible.is-open .vrow-chev {
  transform: rotate(45deg);
}
.map-collapsible #citationMap {
  padding: 0 14px 14px;
}
.map-collapsible .map-head .preview-label {
  display: none;
}
.map-loading-inline {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 18px 0;
  text-align: center;
}
.map-card.is-fullscreen.map-collapsible .map-toggle {
  display: none;
}

@media (max-width: 640px) {
  .source-bar {
    flex-wrap: wrap;
  }
  .source-bar .cite-status {
    order: 3;
    flex-basis: 100%;
    white-space: normal;
  }
}

/* ---------- Audit: citation network ---------- */
.network-card {
  margin: 0 0 16px;
}
.network-card #networkBody {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.network-insights {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.network-card .map-viewport {
  height: 520px;
}
.network-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
}
.lg {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.lg::before {
  content: "";
  display: inline-block;
}
.lg-mine::before {
  width: 14px;
  height: 9px;
  border: 1.4px solid var(--ok);
  border-radius: 3px;
  background: #fff;
}
.lg-hub::before {
  width: 14px;
  height: 9px;
  border: 1px dashed var(--accent-line);
  border-radius: 3px;
  background: var(--accent-soft);
}
.lg-int::before {
  width: 18px;
  height: 0;
  border-top: 1.5px solid var(--accent);
}
.lg-ext::before {
  width: 18px;
  height: 0;
  border-top: 1.5px dashed #c9c9c4;
}

@media (max-width: 640px) {
  .network-card .map-viewport {
    height: 400px;
  }
}
.network-card.is-fullscreen #networkBody {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
}
.network-card.is-fullscreen .network-legend {
  display: none;
}
.network-card.is-fullscreen #networkMap {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.network-card.is-fullscreen .map-viewport {
  flex: 1 1 auto;
  height: auto;
}
.apa-preview.is-empty {
  color: var(--ink-faint);
}

/* ---------- Audit: loading state ---------- */
.input-summary-main {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.spinner {
  display: none;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 2px solid var(--accent-line);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.input-summary.is-running {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.input-summary.is-running .spinner {
  display: inline-block;
}
.input-summary.is-running .input-summary-text {
  color: var(--accent-strong);
}
.btn.is-loading {
  position: relative;
  padding-left: 30px;
}
.btn.is-loading::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 999px;
  border: 2px solid rgba(255, 250, 247, 0.4);
  border-top-color: #fffaf7;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-fill.is-waiting {
  width: 28%;
  animation: indeterminate 1.3s ease-in-out infinite;
}
@keyframes indeterminate {
  from {
    transform: translateX(-110%);
  }
  to {
    transform: translateX(380%);
  }
}

.vrow-skeleton {
  display: grid;
  grid-template-columns: 22px 96px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 16px 6px;
  border-bottom: 1px solid var(--hairline);
}
.vrow-skeleton .sk-line {
  display: block;
  height: 10px;
}
.vrow-skeleton .sk-badge {
  height: 16px;
  border-radius: 5px;
}
.vrow-skeleton:nth-child(2) .sk-text {
  width: 80%;
}
.vrow-skeleton:nth-child(3) .sk-text {
  width: 65%;
}
.vrow-skeleton:nth-child(4) .sk-text {
  width: 72%;
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill.is-waiting {
    transform: none;
    width: 100%;
    opacity: 0.4;
  }
}

/* ---------- Font Awesome icon sizing ---------- */
.nav-icon {
  width: 16px;
  flex: 0 0 auto;
  text-align: center;
  font-size: 13.5px;
}
svg.nav-icon {
  height: 16px;
}
.nav-item.is-active .nav-icon {
  color: var(--accent);
}
i.composer-icon {
  width: auto;
  height: auto;
  font-size: 15px;
}
.composer-submit i {
  font-size: 14px;
}
.list-search i {
  font-size: 13px;
  color: var(--ink-faint);
  flex: 0 0 auto;
}
i.dropzone-icon {
  width: auto;
  height: auto;
  font-size: 24px;
}
.map-ctrl i {
  font-size: 12.5px;
}
/* safety net: any SVG icon in a nav item inherits the text colour */
.nav-item svg {
  stroke: currentColor;
}

/* ---------- Sidebar: developer credit ---------- */
.sidebar-dev {
  display: flex; align-items: center; flex-wrap: wrap; gap: 5px;
  margin: 10px 10px 2px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}
.sidebar-dev a {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--ink-muted);
  text-decoration: none;
  transition: color 0.12s ease;
}
.sidebar-dev a:hover { color: var(--accent-strong); }
.sidebar-dev i { font-size: 11.5px; }
@media (max-width: 900px) {
  .sidebar-dev { display: none; }
}
