/* Endo Lab researcher portal — public-facing reading + filtering surface.
 *
 * Visual goals (distinct from /admin):
 *   - Generous whitespace, wide reading column for the paper detail page.
 *   - Serif body type on long-form prose (abstracts, eligibility) — sans on
 *     navigation/badges/forms.
 *   - Subtle, consistent badges (license, OA, study type) reusing the
 *     accent palette from the admin attribution panel for cross-surface
 *     consistency.
 *   - Mobile-responsive: the filter sidebar stacks above results below 720px.
 */

:root {
  --p-fg: #1f2330;
  --p-fg-muted: #5b6273;
  --p-fg-soft: #8a91a3;
  --p-bg: #fbfaf7;
  --p-card: #ffffff;
  --p-border: #e3e4e8;
  --p-border-strong: #c8cbd2;
  --p-accent: #2c5282;
  --p-accent-hover: #1e3a5f;
  --p-accent-light: #ebf4ff;
  --p-warn: #b45309;
  --p-warn-bg: #fef6e7;
  --p-danger: #b91c1c;
  --p-danger-bg: #fef2f2;
  --p-good: #166534;
  --p-good-bg: #ecfdf5;

  /* Type stack: sans for UI, serif for prose. */
  --p-font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
    Helvetica, Arial, sans-serif;
  --p-font-serif: "Lora", "Source Serif Pro", "Iowan Old Style", "Charter",
    "Georgia", "Cambria", serif;
  --p-font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--p-font-sans);
  margin: 0;
  background: var(--p-bg);
  color: var(--p-fg);
  font-size: 15px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

/* ---- Layout chrome ----------------------------------------------------- */

nav.portal-nav {
  background: var(--p-card);
  border-bottom: 1px solid var(--p-border);
  padding: 14px 28px;
  display: flex;
  gap: 22px;
  align-items: baseline;
  flex-wrap: wrap;
}

nav.portal-nav .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  margin-right: 18px;
  color: var(--p-fg);
}

nav.portal-nav .brand .brand-mark {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--p-accent);
  margin-right: 8px;
  vertical-align: middle;
}

nav.portal-nav a {
  color: var(--p-fg-muted);
  text-decoration: none;
  padding: 4px 0;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}

nav.portal-nav a:hover {
  color: var(--p-accent);
}

nav.portal-nav a.active {
  color: var(--p-fg);
  border-bottom-color: var(--p-accent);
}

nav.portal-nav .spacer { flex: 1; }

main.portal {
  max-width: 1240px;
  margin: 28px auto 64px;
  padding: 0 28px;
}

footer.portal-footer {
  border-top: 1px solid var(--p-border);
  padding: 24px 28px;
  text-align: center;
  color: var(--p-fg-soft);
  font-size: 13px;
}

footer.portal-footer a {
  color: var(--p-fg-muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--p-border-strong);
}

footer.portal-footer a:hover { color: var(--p-accent); }

/* ---- Typography -------------------------------------------------------- */

h1, h2, h3 {
  font-family: var(--p-font-sans);
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  line-height: 1.25;
}
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; margin-top: 28px; }
h3 { font-size: 15px; font-weight: 600; color: var(--p-fg-muted);
     text-transform: uppercase; letter-spacing: 0.05em; margin-top: 24px; }

p { margin: 0 0 12px; }

a { color: var(--p-accent); }
a:hover { color: var(--p-accent-hover); }

.muted   { color: var(--p-fg-muted); }
.soft    { color: var(--p-fg-soft); }
.serif   { font-family: var(--p-font-serif); }
.mono    { font-family: var(--p-font-mono); font-size: 0.94em; }

/* ---- Hero (home) ------------------------------------------------------- */

.hero {
  text-align: center;
  padding: 56px 24px 40px;
  background: linear-gradient(180deg, #ffffff 0%, var(--p-bg) 100%);
  border-bottom: 1px solid var(--p-border);
  margin: -28px -28px 32px;
}

.hero h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}

.hero .tagline {
  font-family: var(--p-font-serif);
  font-size: 18px;
  color: var(--p-fg-muted);
  max-width: 640px;
  margin: 0 auto 28px;
}

.hero form {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
}

.hero input[type=search] {
  flex: 1;
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 6px;
}

.hero button {
  font-size: 15px;
  padding: 12px 20px;
}

.corpus-teaser {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  max-width: 880px;
  margin: 32px auto 0;
}

.corpus-teaser .stat {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
}
.corpus-teaser .stat .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--p-fg);
}
.corpus-teaser .stat .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--p-fg-soft);
  margin-top: 4px;
}

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

.search-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 880px) {
  .search-layout { grid-template-columns: 1fr; }
}

/* Mobile filter-drawer toggle. Hidden on desktop; on mobile the button
   appears and the form is hidden until the user taps to expand. CSS-only
   via the hidden checkbox's :checked sibling selector. */
.filter-toggle-btn {
  display: none;
}
.filter-toggle-cb {
  display: none;
}

.search-sidebar {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 18px;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}

.search-sidebar h3 {
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 12px;
}
.search-sidebar h3:first-child { margin-top: 0; }

.search-sidebar .group {
  border-bottom: 1px solid var(--p-border);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.search-sidebar .group:last-child { border-bottom: none; margin-bottom: 0; }

.search-sidebar label.opt {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 2px 0;
  color: var(--p-fg);
  cursor: pointer;
}

.search-sidebar label.opt input[type=checkbox] {
  margin: 0;
}

.search-sidebar label.opt .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--p-fg-soft);
  font-variant-numeric: tabular-nums;
}

.search-sidebar input[type=text],
.search-sidebar input[type=number],
.search-sidebar select {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
}

.search-sidebar .year-range {
  display: flex;
  gap: 6px;
  align-items: center;
}
.search-sidebar .year-range input {
  flex: 1;
  text-align: center;
}

.search-sidebar .actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.search-sidebar .actions button { flex: 1; }
.search-sidebar .actions a.reset {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--p-fg-muted);
  text-decoration: none;
  border: 1px solid var(--p-border);
  border-radius: 4px;
  background: transparent;
}
.search-sidebar .actions a.reset:hover { color: var(--p-fg); }

/* ---- Search header (top of results column) ---------------------------- */

.search-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.search-head .meta {
  color: var(--p-fg-muted);
  font-size: 13px;
}

.search-head .exports {
  display: flex;
  gap: 6px;
}
.search-head .exports a {
  font-size: 12px;
  text-decoration: none;
  border: 1px solid var(--p-border);
  background: var(--p-card);
  color: var(--p-fg-muted);
  padding: 4px 9px;
  border-radius: 4px;
}
.search-head .exports a:hover {
  background: var(--p-accent-light);
  color: var(--p-accent);
  border-color: var(--p-accent);
}

#results .htmx-indicator {
  display: inline-block;
  font-size: 13px;
  color: var(--p-fg-muted);
  padding: 12px;
}

/* ---- Result cards ----------------------------------------------------- */

.r-card {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 14px;
  transition: border-color 0.1s ease;
}

.r-card:hover {
  border-color: var(--p-border-strong);
}

.r-card .r-head {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--p-fg-soft);
}

.r-card .r-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin-bottom: 6px;
  line-height: 1.3;
}
.r-card .r-title a {
  color: var(--p-fg);
  text-decoration: none;
}
.r-card .r-title a:hover {
  color: var(--p-accent);
  text-decoration: underline;
}

.r-card .r-meta {
  font-size: 13px;
  color: var(--p-fg-muted);
  margin-bottom: 8px;
}
.r-card .r-meta .sep { color: var(--p-fg-soft); margin: 0 6px; }

.r-card .r-abstract {
  font-family: var(--p-font-serif);
  color: var(--p-fg);
  font-size: 14.5px;
  line-height: 1.6;
  margin-bottom: 10px;
}

.r-card .r-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* Shared inline action row (📄 Abstract / ✨ AI summary) used on
   search-result cards, /research/new cards, and /research/trending
   rows. Sits between the body text/tags and the per-card metadata. */
.r-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}
.btn-inline-action {
  appearance: none;
  border: 1px solid var(--p-border, #d6cfc4);
  background: transparent;
  color: var(--p-fg);
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.4;
}
.btn-inline-action:hover {
  background: var(--p-bg-soft, #f7f5f1);
}
.btn-inline-action[aria-expanded="true"] {
  background: var(--p-bg-soft, #f7f5f1);
  border-color: var(--p-accent, #8d6e63);
}

/* Inline expandable panels on result cards (📄 Abstract / ✨ AI summary) */
.r-card .r-expand,
.whats-new-card .r-expand,
.trending-row .r-expand {
  margin: 8px 0 10px;
  padding: 10px 12px;
  background: var(--p-bg-soft, #f7f5f1);
  border-left: 3px solid var(--p-accent, #8d6e63);
  border-radius: 4px;
}
.r-expand-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--p-fg-soft);
  margin-bottom: 4px;
}
.r-expand-body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--p-fg);
}
.r-expand-footnote {
  margin: 6px 0 0;
  font-size: 12px;
}

.r-card .r-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--p-border);
  font-size: 12px;
  color: var(--p-fg-soft);
}
.r-card .r-foot .actions { display: flex; gap: 6px; }
.r-card .r-foot .score {
  font-family: var(--p-font-mono);
  background: var(--p-accent-light);
  color: var(--p-accent);
  padding: 2px 8px;
  border-radius: 3px;
}

/* ---- Badges ----------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  white-space: nowrap;
}

.badge.study      { background: var(--p-accent-light); color: var(--p-accent); }
.badge.year       { background: #f3f4f6; color: #374151; }
.badge.oa-gold    { background: #fef3c7; color: #92400e; }
.badge.oa-green   { background: #d1fae5; color: #065f46; }
.badge.oa-hybrid  { background: #ede9fe; color: #5b21b6; }
.badge.oa-bronze  { background: #fde6c4; color: #92400e; }
.badge.oa-diamond { background: #e0f2fe; color: #075985; }
.badge.oa-closed  { background: #f3f4f6; color: #4b5563; }
.badge.preprint   { background: #f5f3ff; color: #5b21b6; }
.badge.retracted  { background: var(--p-danger-bg); color: var(--p-danger); }
.badge.license    { background: #f0f9ff; color: #075985; }
/* Metadata-only: surfaced when the paper has no DOI/PMID/PMCID/OA URL/
   full-text on file. Warm-grey desaturated tone so it signals 'not
   a reading path' without competing visually with study / OA / license
   badges that point at actionable destinations. */
.badge.metadata-only {
  background: #fff7ed;
  color: #9a3412;
  border: 1px dashed #fdba74;
}

.tag {
  display: inline-block;
  background: #eef2ff;
  color: #4338ca;
  border-radius: 3px;
  padding: 1px 7px;
  font-size: 11.5px;
  white-space: nowrap;
}
.tag.outcome { background: #ecfeff; color: #155e75; }
.tag.mesh    { background: #fdf4ff; color: #86198f; }
.tag.major   { background: #fbcfe8; color: #831843; font-weight: 600; }

/* ---- Buttons & forms -------------------------------------------------- */

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

input[type=text], input[type=search], input[type=number], select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--p-border);
  border-radius: 4px;
  background: var(--p-card);
  color: var(--p-fg);
}
input[type=text]:focus, input[type=search]:focus,
input[type=number]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--p-accent);
  box-shadow: 0 0 0 2px var(--p-accent-light);
}

button {
  background: var(--p-accent);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: var(--p-accent-hover); }
button.ghost {
  background: transparent;
  color: var(--p-fg-muted);
  border: 1px solid var(--p-border);
  font-weight: 400;
}
button.ghost:hover { color: var(--p-fg); border-color: var(--p-border-strong); }

button.btn-cite {
  background: transparent;
  color: var(--p-fg-muted);
  border: 1px solid var(--p-border);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
}
button.btn-cite:hover { color: var(--p-accent); border-color: var(--p-accent); }

a.btn {
  display: inline-block;
  padding: 7px 14px;
  background: var(--p-accent);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
}
a.btn:hover { background: var(--p-accent-hover); color: white; }
a.btn.ghost {
  background: transparent;
  color: var(--p-fg-muted);
  border: 1px solid var(--p-border);
}
a.btn.ghost:hover { color: var(--p-fg); border-color: var(--p-border-strong); }

/* ---- Paper detail layout ---------------------------------------------- */

.paper-detail {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 32px;
  max-width: 880px;
}

.paper-detail h1 {
  font-family: var(--p-font-serif);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 14px;
}

.paper-detail .authors {
  font-size: 15px;
  color: var(--p-fg);
  margin-bottom: 4px;
}

.paper-detail .pub-meta {
  color: var(--p-fg-muted);
  font-size: 14px;
  margin-bottom: 16px;
}
.paper-detail .pub-meta .sep { margin: 0 8px; color: var(--p-fg-soft); }

.paper-detail .badges {
  margin-bottom: 22px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.paper-detail .abstract {
  font-family: var(--p-font-serif);
  font-size: 16px;
  line-height: 1.7;
  color: var(--p-fg);
  margin-bottom: 28px;
}

.paper-detail section + section { margin-top: 28px; }
.paper-detail section h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--p-fg-muted);
  border-bottom: 1px solid var(--p-border);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.paper-detail dl.kv,
.entity-card dl.kv {
  display: grid;
  grid-template-columns: 200px 1fr;
  row-gap: 8px;
  font-size: 14px;
  margin: 16px 0;
}
.paper-detail dl.kv dt,
.entity-card dl.kv dt { color: var(--p-fg-muted); font-weight: 500; margin: 0; }
.paper-detail dl.kv dd,
.entity-card dl.kv dd { margin: 0; word-break: break-word; }

/* Render a JSON-ish dict (e.g. trial.interventions) as a readable list. */
.trial-interventions {
  list-style: none;
  padding: 0;
  margin: 0;
}
.trial-interventions li {
  border-left: 3px solid var(--p-accent-light, #d3e2f1);
  padding: 8px 12px;
  margin: 6px 0;
  background: var(--p-card, #fafafa);
  border-radius: 0 4px 4px 0;
}
.trial-interventions .iv-name {
  font-weight: 600;
  font-size: 14px;
}
.trial-interventions .iv-type {
  margin-left: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--p-fg-muted);
}
.trial-interventions .iv-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--p-fg);
}

.paper-detail .ref-list,
.paper-detail .citing-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.paper-detail .ref-list li,
.paper-detail .citing-list li {
  padding: 6px 0;
  border-bottom: 1px dashed var(--p-border);
  font-size: 14px;
}
.paper-detail .ref-list li:last-child,
.paper-detail .citing-list li:last-child { border-bottom: none; }

.paper-detail .annotation-group {
  border: 1px solid var(--p-border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}
.paper-detail .annotation-group summary {
  padding: 10px 14px;
  background: #f9fafb;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  color: var(--p-fg);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.paper-detail .annotation-group summary::-webkit-details-marker { display: none; }
.paper-detail .annotation-group summary::after { content: "▾"; color: var(--p-fg-soft); }
.paper-detail .annotation-group[open] summary::after { content: "▴"; }
.paper-detail .annotation-group .anno-list {
  padding: 10px 14px 14px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.paper-detail .actions-row {
  margin: 22px 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.paper-detail .attribution {
  background: #f7f9fc;
  border: 1px solid #d4dae3;
  border-radius: 6px;
  padding: 14px;
  font-size: 13px;
  color: var(--p-fg-muted);
  margin-top: 24px;
}
.paper-detail .attribution em { color: var(--p-fg); font-style: normal; font-weight: 500; }

/* ---- Trial / Grant / Author / Journal pages --------------------------- */

.entity-card {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 22px;
}

.entity-card h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.entity-card .subtitle {
  color: var(--p-fg-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.entity-card details {
  margin-top: 12px;
}
.entity-card details summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  color: var(--p-accent);
  padding: 4px 0;
}
.entity-card details .body {
  font-family: var(--p-font-serif);
  padding: 8px 0;
  color: var(--p-fg);
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.6;
}

/* ---- Cite popover ----------------------------------------------------- */

#cite-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
#cite-overlay.open { display: flex; }

#cite-popover {
  background: var(--p-card);
  border-radius: 8px;
  padding: 20px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
}

#cite-popover header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
#cite-popover header h2 { margin: 0; font-size: 16px; }
#cite-popover header button.close {
  background: transparent;
  color: var(--p-fg-muted);
  border: none;
  font-size: 22px;
  padding: 0 4px;
  cursor: pointer;
}

#cite-popover .tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--p-border);
}
#cite-popover .tabs button {
  background: transparent;
  color: var(--p-fg-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
#cite-popover .tabs button.active {
  color: var(--p-accent);
  border-bottom-color: var(--p-accent);
}

#cite-popover pre {
  background: #f6f7f9;
  border: 1px solid var(--p-border);
  border-radius: 4px;
  padding: 12px;
  font-family: var(--p-font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 360px;
  overflow: auto;
}

#cite-popover .copy-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}
#cite-popover .copy-status {
  font-size: 12px;
  color: var(--p-good);
  opacity: 0;
  transition: opacity 0.2s;
}
#cite-popover .copy-status.show { opacity: 1; }

/* ---- Pagination ------------------------------------------------------- */

.pagination {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 24px 0 8px;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  border: 1px solid var(--p-border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--p-fg);
  background: var(--p-card);
  font-size: 13px;
}
.pagination a:hover { border-color: var(--p-accent); color: var(--p-accent); }
.pagination span.disabled { color: var(--p-fg-soft); }

/* ---- Errors ---------------------------------------------------------- */

.notice {
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 14px;
}
.notice.error { background: var(--p-danger-bg); color: var(--p-danger); border: 1px solid #fecaca; }
.notice.info  { background: var(--p-accent-light); color: var(--p-accent); border: 1px solid #cdddf3; }
.notice.warn  { background: var(--p-warn-bg); color: var(--p-warn); border: 1px solid #fde0b8; }

/* ---- Empty state ------------------------------------------------------ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--p-fg-muted);
  font-family: var(--p-font-serif);
  font-size: 16px;
}
.empty-state .hint {
  font-family: var(--p-font-sans);
  font-size: 13px;
  color: var(--p-fg-soft);
  margin-top: 8px;
}

/* ---- Inline cite triggers (copy from clipboard) ----------------------- */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }

/* ---- Explore: index + page chrome ------------------------------------- */

.explore-page {
  max-width: 980px;
  margin: 0 auto;
}
.explore-page h1 {
  margin-top: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.explore-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 18px 0 22px;
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 10px 12px;
}
.explore-form input[type="text"],
.explore-form input[type="number"] {
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--p-border);
  border-radius: 4px;
  font-family: var(--p-font-sans);
  background: white;
  color: var(--p-fg);
}
.explore-form button {
  padding: 7px 14px;
  background: var(--p-accent);
  color: white;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.explore-form button:hover { background: var(--p-accent-hover); }
.explore-form label { font-size: 13px; color: var(--p-fg-muted); }

.explore-meta {
  font-size: 13px;
  margin-bottom: 10px;
}

ul.explore-index {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
  display: grid;
  gap: 12px;
}
ul.explore-index li a {
  display: block;
  padding: 14px 16px;
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--p-fg);
  transition: border-color 0.15s;
}
ul.explore-index li a:hover { border-color: var(--p-accent); }
ul.explore-index li a strong { display: block; margin-bottom: 4px; }
ul.explore-index li a .muted {
  font-size: 13px;
  color: var(--p-fg-muted);
}

.vega-chart {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 16px;
  margin: 8px 0 18px;
  min-height: 280px;
  /* CRITICAL: an empty div has no measurable width before Vega draws into it,
     so `width: "container"` in the spec collapses to ~0px. Force a width so
     the parent has a measurable client rect when Vega computes `container`. */
  width: 100%;
  box-sizing: border-box;
}
.vega-chart canvas, .vega-chart svg {
  max-width: 100%;
  height: auto;
}
.vega-chart-heatmap {
  /* Heatmaps need more height for axis labels + room for cells; the default
     280px min collapses everything to a sliver. */
  min-height: 540px;
}

.footnote {
  font-size: 12px;
  margin-top: 18px;
  border-top: 1px dashed var(--p-border);
  padding-top: 10px;
  line-height: 1.5;
  max-width: 760px;
}

/* ---- Result-set sparkline (search results) ---------------------------- */

.result-sparkline {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 6px 12px 8px;
  margin-bottom: 10px;
}
.vega-spark {
  width: 100%;
  height: 60px;
}

/* ---- Word clouds ------------------------------------------------------ */

.wc-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 12px;
}
@media (max-width: 800px) {
  .wc-grid { grid-template-columns: 1fr; }
}
.wc-panel {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 14px;
  min-height: 160px;
}
.wc-panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.wc-panel h3 .muted { font-size: 11px; font-weight: 400; }
.wc-cloud {
  line-height: 1.25;
  word-spacing: 6px;
  text-align: center;
  /* Hand-tuned vertical rhythm — the line-height + per-word leading lets
     the bigger words feel "lifted" out of the smaller ones rather than
     stacked into uniform rows. */
}
.wc-word {
  display: inline-block;
  padding: 2px 5px;
  cursor: pointer;
  color: var(--p-fg);
  font-family: var(--p-font-serif);
  transition: background 0.15s, transform 0.15s, opacity 0.15s;
  border-radius: 3px;
  /* small vertical perturbation gives the cloud some texture without
     becoming d3-cloud rotated text */
  vertical-align: baseline;
}
.wc-word:hover {
  background: var(--p-accent-light);
  opacity: 1 !important;
  transform: scale(1.05);
}
.wc-word.hl {
  background: var(--p-accent);
  color: white;
  opacity: 1 !important;
}
/* Per-decade tinting (subtle). */
.wc-panel.decade-197 h3 { color: #5b6273; }
.wc-panel.decade-198 h3 { color: #4a6fa5; }
.wc-panel.decade-199 h3 { color: #3d5d85; }
.wc-panel.decade-200 h3 { color: #2e4972; }
.wc-panel.decade-201 h3 { color: #233a5e; }
.wc-panel.decade-202 h3 { color: #1a2c4a; }

/* ----- Legal/access compliance bits ----- */
.legal-page {
  max-width: 760px;
  margin: 24px auto;
  padding: 0 16px;
  font-family: var(--p-serif, "Source Serif Pro", Georgia, serif);
  font-size: 16px;
  line-height: 1.65;
  color: var(--p-fg);
}
.legal-page h1 {
  font-size: 28px;
  margin: 16px 0 8px;
}
.legal-page h2 {
  font-size: 18px;
  margin: 28px 0 10px;
  color: var(--p-fg);
}
.legal-page p, .legal-page li {
  font-size: 16px;
  margin: 8px 0;
}
.legal-page ul {
  padding-left: 20px;
}
.legal-page .muted {
  color: var(--p-fg-muted);
  font-style: italic;
  font-size: 14px;
}

/* Footer expansion */
.footer-attribution {
  font-size: 13px;
  line-height: 1.6;
  color: var(--p-fg-muted);
  max-width: 920px;
  margin: 0 auto 8px;
}
.footer-attribution a {
  color: var(--p-fg-muted);
  text-decoration: underline;
}
.footer-legal {
  font-size: 13px;
  text-align: center;
  color: var(--p-fg-muted);
}
.footer-legal a {
  color: var(--p-fg-muted);
  margin: 0 4px;
}
.footer-credit {
  margin-top: 10px;
  font-size: 12px;
  text-align: center;
  color: var(--p-fg-muted);
  letter-spacing: 0.02em;
}

/* Non-commercial click-through gate */
.nc-gate {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
/* `display: flex` above otherwise beats the user-agent default for
   the [hidden] attribute, which is display: none. */
.nc-gate[hidden] {
  display: none;
}
.nc-gate-panel {
  background: var(--p-card, #fff);
  max-width: 520px;
  padding: 28px 32px;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  font-size: 15px;
  line-height: 1.55;
}
.nc-gate-panel h2 { margin: 0 0 12px; font-size: 20px; }
.nc-gate-panel button {
  background: var(--p-accent, #1a2c4a);
  color: white;
  border: 0;
  padding: 10px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  margin-top: 8px;
}
.nc-gate-panel .small {
  font-size: 12px;
  color: var(--p-fg-muted);
  margin-top: 14px;
}

/* ----- Library settings dialog ("Find at my library") ----- */
.lib-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}
.lib-overlay.open { display: flex; }
.lib-panel {
  background: var(--p-card, #fff);
  max-width: 560px;
  width: calc(100% - 32px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 28px;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  font-size: 14px;
  line-height: 1.5;
}
.lib-panel header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 8px;
}
.lib-panel h2 {
  margin: 0;
  font-size: 18px;
}
.lib-panel header .close {
  background: transparent;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  color: var(--p-fg-muted);
  line-height: 1;
}
.lib-panel label {
  display: block;
  margin: 14px 0;
}
.lib-panel label > span {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}
.lib-panel label > span em {
  font-weight: normal;
  font-style: italic;
  color: var(--p-fg-muted);
  font-size: 12px;
}
.lib-panel input[type="url"],
.lib-panel input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--p-border, #d6d9e0);
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--p-mono, monospace);
  box-sizing: border-box;
}
.lib-panel small {
  display: block;
  margin-top: 4px;
  color: var(--p-fg-muted);
  font-size: 12px;
}
.lib-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.lib-actions .btn.primary {
  background: var(--p-accent, #1a2c4a);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.lib-actions .btn.ghost {
  background: transparent;
  border: 1px solid var(--p-border, #d6d9e0);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.lib-panel .small {
  font-size: 12px;
}

/* ----- AI-generated content (TLDR, yes/no meter, Q&A) ----- */
.ai-tldr {
  background: linear-gradient(135deg, #f8f6ff 0%, #f4f9fe 100%);
  border: 1px solid #d8d2f0;
  border-left: 4px solid #6b46c1;
  border-radius: 6px;
  padding: 16px 20px;
  margin: 16px 0 24px;
}
.ai-badge {
  display: flex;
  align-items: center;
  flex-wrap: wrap;        /* let the meta blurb drop below the label on narrow widths */
  gap: 8px;
  font-size: 12px;
  color: var(--p-fg-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ai-badge strong {
  color: #6b46c1;
  font-weight: 700;
  /* Don't let flex squeeze the brand label into per-word vertical stacking
     ("ASK / THIS / PAPER" on mobile) — keep it intact. */
  flex-shrink: 0;
  white-space: nowrap;
}
.ai-badge .ai-badge-meta {
  /* Meta info can wrap onto its own line at narrow widths, but should
     never get smaller than ~150px or it ends up unreadable. */
  flex: 1 1 150px;
}
.ai-badge-icon {
  display: inline-block;
  font-size: 14px;
  color: #6b46c1;
}
.ai-badge-meta {
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  color: var(--p-fg-muted);
}
.ai-tldr-body {
  font-size: 16px;
  line-height: 1.55;
  color: var(--p-fg);
  margin: 0;
}
.ai-tldr-footnote {
  margin: 10px 0 0;
  font-size: 12px;
}
.ai-tldr-footnote a {
  color: var(--p-fg-muted);
  text-decoration: underline dotted;
}
/* Smaller inline variant for search result cards */
.ai-tldr-inline {
  background: #f8f6ff;
  border-left: 3px solid #6b46c1;
  padding: 8px 12px;
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--p-fg);
  font-family: var(--p-serif, "Source Serif Pro", Georgia, serif);
}
.ai-tldr-inline::before {
  content: "⚙ AI summary: ";
  font-family: var(--p-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b46c1;
}

/* ----- Compare-bar (floating selection on search results) ----- */
.compare-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--p-card, #fff);
  border: 1px solid var(--p-border, #d6d9e0);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 12px 20px;
  border-radius: 32px;
  z-index: 500;
  font-size: 14px;
}
.compare-bar[hidden] { display: none; }
.compare-bar .compare-count {
  font-weight: 600;
  color: var(--p-accent, #1a2c4a);
}
.compare-bar button {
  background: var(--p-accent, #1a2c4a);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
}
.compare-bar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.compare-bar button.ghost {
  background: transparent;
  color: var(--p-fg-muted);
  font-weight: normal;
}
.r-compare-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  color: var(--p-fg-muted);
}
.r-compare-toggle input { margin: 0; }

/* ----- Comparison page table ----- */
.compare-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin-top: 8px;
}
.compare-table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 14px;
}
.compare-table th, .compare-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--p-border, #d6d9e0);
  vertical-align: top;
  /* Cap each column so titles wrap onto multiple lines instead of truncating
     mid-word with text-overflow. min/max-width together give Vega-style
     "fit content but never exceed the cap" behavior. */
  min-width: 220px;
  max-width: 360px;
  word-break: normal;
  overflow-wrap: break-word;
}
.compare-table th {
  background: var(--p-bg, #fbfaf7);
  position: sticky;
  top: 0;
  font-weight: 600;
}
.compare-table thead th a {
  font-weight: 600;
  /* Allow long titles to wrap rather than overflow the column */
  display: inline-block;
  max-width: 100%;
}

/* Hybrid search found 0 BM25 hits — banner above the results explains
   why the corpus-total "matching papers" number isn't being shown. */
.search-lexical-zero {
  background: #fff8eb;
  border-left: 3px solid #d69e2e;
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--p-fg, #1f2a37);
}
.search-lexical-zero em { font-style: italic; }
.search-lexical-zero .lexical-zero-bm25 {
  color: var(--p-accent, #2c5282);
  text-decoration: underline;
  white-space: nowrap;
}
.search-lexical-zero .lexical-zero-bm25:hover {
  color: var(--p-accent-hover, #1a365d);
}
.compare-table td:first-child {
  font-weight: 600;
  color: var(--p-fg-muted);
  text-transform: capitalize;
  white-space: nowrap;
}

/* ----- AI Q&A box on paper detail ----- */
.ai-qa {
  background: linear-gradient(135deg, #f8f6ff 0%, #f4f9fe 100%);
  border: 1px solid #d8d2f0;
  border-left: 4px solid #6b46c1;
  border-radius: 6px;
  padding: 16px 20px;
  margin: 24px 0;
}
.ai-qa form {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}
.ai-qa input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--p-border, #d6d9e0);
  border-radius: 4px;
  font-size: 14px;
}
.ai-qa button {
  background: #6b46c1;
  color: white;
  border: 0;
  padding: 8px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.ai-qa button:disabled { opacity: 0.6; cursor: not-allowed; }
.ai-qa-answer {
  margin-top: 14px;
  background: var(--p-card, #fff);
  border-radius: 4px;
  padding: 12px 16px;
  border: 1px solid #e8e4f5;
}
.ai-qa-answer .ai-answer { font-family: var(--p-serif, "Georgia", serif); font-size: 15px; }
.ai-qa-answer .ai-unanswerable {
  font-style: italic;
  color: var(--p-fg-muted);
}
.ai-qa-answer .ai-error {
  color: var(--p-danger, #b91c1c);
}
.ai-qa-answer .ai-quotes {
  margin: 12px 0;
  padding-left: 20px;
}
.ai-qa-answer .ai-quotes blockquote {
  border-left: 3px solid #6b46c1;
  padding-left: 12px;
  margin: 4px 0;
  font-family: var(--p-serif, "Georgia", serif);
  font-style: italic;
  color: var(--p-fg);
}

/* ----- AI verdict button on search results ----- */
#ai-verdict-bar {
  margin: 8px 0 12px;
}
#ai-verdict-bar button {
  background: linear-gradient(135deg, #6b46c1 0%, #2c5282 100%);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
#ai-verdict-bar button:disabled { opacity: 0.6; cursor: not-allowed; }
.ai-verdict-yes .ai-badge strong  { color: #166534; }
.ai-verdict-no .ai-badge strong   { color: #b91c1c; }
.ai-verdict-possibly .ai-badge strong { color: #b45309; }
.ai-verdict-insufficient_evidence .ai-badge strong { color: var(--p-fg-muted); }

/* ----- AI TLDR loading placeholder ----- */
.ai-tldr-loading .ai-tldr-body {
  font-style: italic;
}
.ai-spinner {
  display: inline-block;
  animation: ai-spin 1.4s linear infinite;
}
@keyframes ai-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ===== What's new page ===== */
.whats-new-head h1 { margin-bottom: 6px; }
.whats-new-head .serif { max-width: 720px; }
.whats-new-tabs {
  display: flex;
  gap: 4px;
  margin: 22px 0 14px;
  border-bottom: 1px solid var(--p-border);
}
.whats-new-tab {
  padding: 8px 18px;
  text-decoration: none;
  color: var(--p-fg-muted);
  border-bottom: 3px solid transparent;
  font-weight: 600;
  font-size: 14px;
}
.whats-new-tab:hover { color: var(--p-accent); }
.whats-new-tab.active {
  color: var(--p-accent);
  border-bottom-color: var(--p-accent);
}
.whats-new-sparkline {
  margin: 6px 0 22px;
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 8px 14px;
  min-height: 90px;
}
.whats-new-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 28px;
  align-items: start;
}
@media (max-width: 980px) {
  .whats-new-grid { grid-template-columns: 1fr; }
}
.whats-new-col h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--p-fg-muted);
  margin: 24px 0 12px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.whats-new-col h2 .small { font-size: 11px; text-transform: none; letter-spacing: 0; font-weight: normal; }
.whats-new-col h2:first-child { margin-top: 0; }
.whats-new-card {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 14px 18px;
  margin-bottom: 10px;
}
.whats-new-card.slim { padding: 10px 14px; margin-bottom: 8px; }
.whats-new-meta {
  font-size: 12px;
  color: var(--p-fg-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.whats-new-meta .sep { color: var(--p-fg-soft); }
.whats-new-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 6px;
}
.whats-new-title a {
  color: var(--p-fg);
  text-decoration: none;
}
.whats-new-title a:hover { color: var(--p-accent); }
.whats-new-snippet {
  font-family: var(--p-font-serif, Georgia, serif);
  font-size: 13px;
  color: var(--p-fg-muted);
  margin: 4px 0 6px;
  line-height: 1.45;
}
.whats-new-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
  font-size: 11px;
}
.whats-new-side {
  position: sticky;
  top: 18px;
  align-self: start;
}

/* ===== Saved searches (sidebar panel) ===== */
.saved-searches { margin-top: 18px; }
.saved-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  font-size: 13px;
}
.saved-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
}
.saved-item a {
  flex: 1;
  color: var(--p-fg);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-item a:hover { color: var(--p-accent); }
.saved-delete {
  background: transparent;
  border: 0;
  color: var(--p-fg-soft);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.saved-delete:hover { color: var(--p-danger); }
.ghost-link {
  background: transparent;
  border: 1px dashed var(--p-border);
  border-radius: 4px;
  color: var(--p-fg-muted);
  cursor: pointer;
  padding: 4px 8px;
  width: 100%;
  text-align: left;
  font-size: 12px;
}
.ghost-link:hover { color: var(--p-accent); border-color: var(--p-accent); }

/* In the My Research grid the "+ New list" button shouldn't be a full-width
   dashed placeholder — make it a compact, solid pill that sits inline with
   the card content. */
.my-card .ghost-link {
  display: inline-block;
  width: auto;
  border-style: solid;
  border-color: var(--p-border);
  color: var(--p-fg);
  font-size: 13px;
  padding: 6px 12px;
  margin-top: 8px;
}
.my-card .ghost-link:hover {
  background: var(--p-accent-light, #eef3fa);
  border-color: var(--p-accent);
  color: var(--p-accent);
}

/* ===== Reading list menu (floating) ===== */
.rl-menu {
  position: absolute;
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  min-width: 240px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 800;
  font-size: 13px;
}
.rl-menu[hidden] { display: none; }
.rl-menu-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--p-border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}
.rl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--p-fg);
  font-size: 13px;
}
.rl-row:hover { background: var(--p-accent-light); }
.rl-row .rl-check { width: 16px; color: var(--p-accent); font-weight: 700; }
.rl-row .rl-name { flex: 1; }
.rl-menu-foot {
  border-top: 1px solid var(--p-border);
  padding: 6px;
}
.rl-menu-foot .rl-new {
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
  padding: 6px 12px;
  color: var(--p-accent);
  cursor: pointer;
  font-size: 13px;
}
.rl-menu-foot .rl-new:hover { background: var(--p-accent-light); }

/* ===== Paper detail: personal notes section ===== */
.paper-note-section { margin: 24px 0; }
.paper-note-section h2 { margin-bottom: 8px; }
.paper-note-section textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  font-family: var(--p-font-serif, Georgia, serif);
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid var(--p-border);
  border-radius: 6px;
  background: var(--p-bg, #fffef9);
  resize: vertical;
  color: var(--p-fg);
  box-sizing: border-box;
}
.paper-note-section textarea:focus {
  outline: 2px solid var(--p-accent-light);
  border-color: var(--p-accent);
}
.paper-note-foot { margin-top: 6px; }

/* ===== My research page ===== */
.my-research-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 22px;
  margin-top: 22px;
}
@media (max-width: 980px) {
  .my-research-grid { grid-template-columns: 1fr; }
}
.my-card {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 18px;
}
.my-card h2 {
  font-size: 16px;
  margin: 0 0 10px;
}
.rl-grid { display: grid; gap: 10px; margin-bottom: 10px; }
.rl-card {
  background: var(--p-bg);
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 12px 14px;
}
.rl-card-head { display: flex; align-items: baseline; justify-content: space-between; }
.rl-card-head h3 { font-size: 14px; margin: 0; }
.rl-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0;
  font-size: 11px;
}
.rl-paper-tile {
  background: white;
  border: 1px solid var(--p-border);
  border-radius: 3px;
  padding: 3px 6px;
  font-family: var(--p-font-mono, monospace);
  color: var(--p-fg-muted);
  text-decoration: none;
}
.rl-paper-tile:hover { color: var(--p-accent); border-color: var(--p-accent); }
.rl-card-actions { display: flex; gap: 8px; font-size: 12px; }
.rl-card-actions button {
  background: transparent;
  border: 0;
  color: var(--p-fg-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
}
.rl-card-actions .rl-delete:hover { color: var(--p-danger); }
.rl-card-actions .rl-rename:hover { color: var(--p-accent); }

#ss-list { list-style: none; padding: 0; margin: 0; }
.ss-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--p-border);
}
.ss-row:last-child { border-bottom: 0; }
.ss-row a { flex: 1; color: var(--p-fg); text-decoration: none; }
.ss-row a:hover { color: var(--p-accent); }
.ss-delete {
  background: transparent;
  border: 0;
  color: var(--p-fg-soft);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.ss-delete:hover { color: var(--p-danger); }

#notes-list { list-style: none; padding: 0; margin: 0; }
.note-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--p-border);
}
.note-row:last-child { border-bottom: 0; }
.note-paper-id,
.note-paper-link {
  color: var(--p-fg-muted);
  text-decoration: none;
  font-size: 13px;
}
.note-paper-id { font-family: var(--p-font-mono, monospace); font-size: 12px; }
.note-paper-link { font-weight: 500; }
.note-paper-id:hover,
.note-paper-link:hover { color: var(--p-accent); text-decoration: underline; }
.note-snippet {
  font-size: 13px;
  color: var(--p-fg);
  margin-top: 4px;
  line-height: 1.4;
}

.my-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}
.my-actions button, .my-actions .ghost-link {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 4px;
  cursor: pointer;
}
.my-actions button.danger {
  color: var(--p-danger);
  border-color: var(--p-danger);
}
.my-actions button.danger:hover {
  background: var(--p-danger-bg);
}

/* ===== Trending list ===== */
.trending-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  counter-reset: trending;
}
.trending-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--p-border);
}
.trending-row:last-child { border-bottom: 0; }
.trending-rank {
  font-size: 28px;
  font-weight: 700;
  color: var(--p-fg-soft);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.trending-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
  line-height: 1.35;
}
.trending-title a { color: var(--p-fg); text-decoration: none; }
.trending-title a:hover { color: var(--p-accent); }
.trending-meta {
  font-size: 12px;
  color: var(--p-fg-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.trending-cites {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
}
.trending-cite-badge {
  background: var(--p-accent);
  color: white;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 11px;
}

/* Fix: ensure My-Research action buttons have a readable text colour */
.my-actions button { color: var(--p-fg); }
.my-actions button:hover { color: var(--p-accent); }
.my-actions button.danger { color: var(--p-danger); }
.my-actions button.danger:hover { color: var(--p-danger); background: var(--p-danger-bg); }

/* Disabled tab (e.g. "Today" with 0 items) */
.whats-new-tab.disabled {
  color: var(--p-fg-soft);
  cursor: not-allowed;
  background: transparent;
}
.whats-new-tab.disabled:hover { color: var(--p-fg-soft); }

/* Small "info" icon used inline next to headings + labels that need
   a longer explanation than the badge tooltip itself can carry. */
.info-icon {
  display: inline-block;
  font-size: 11px;
  color: var(--p-fg-soft);
  background: transparent;
  border: 1px solid var(--p-border);
  border-radius: 50%;
  width: 14px;
  height: 14px;
  line-height: 12px;
  text-align: center;
  cursor: help;
  margin-left: 4px;
  font-style: italic;
  font-weight: normal;
  vertical-align: middle;
}
.info-icon:hover, .info-icon:focus {
  color: var(--p-accent);
  border-color: var(--p-accent);
  outline: none;
}

/* ===== Inline search bar (query + Search button) ===== */
.query-row {
  display: flex;
  gap: 6px;
}
.query-row input[type="text"] {
  flex: 1;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--p-border);
  border-radius: 4px;
}
.query-row input[type="text"]:focus {
  outline: 2px solid var(--p-accent-light);
  border-color: var(--p-accent);
}
.query-go {
  background: var(--p-accent);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.query-go:hover { background: var(--p-accent-hover); }
.query-hint {
  margin: 6px 0 0;
  font-size: 11px;
}
.query-hint kbd {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--p-font-mono, monospace);
  font-size: 11px;
  color: var(--p-fg);
}

/* ===========================================================
   Full-text body — collapsible section on paper detail
   ----------------------------------------------------------- */
.fulltext-section {
  margin: 18px 0;
  border-left: 3px solid var(--p-accent-light, #d8e3f3);
  padding-left: 14px;
}
.fulltext-section summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 0;
  font-size: 15px;
}
.fulltext-section summary::-webkit-details-marker { display: none; }
.fulltext-section summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--p-fg-muted);
  transition: transform 0.15s;
}
.fulltext-section details[open] summary::before {
  transform: rotate(90deg);
}
.fulltext-body {
  font-family: var(--p-font-serif);
  font-size: 15px;
  line-height: 1.7;
  /* Pre-wrap so paragraph breaks (\n\n from PDF extraction) survive while
     long lines still wrap to the container width. */
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  max-height: 720px;
  overflow-y: auto;
  padding: 12px 14px;
  margin: 8px 0;
  background: var(--p-card, #fbfaf7);
  border: 1px solid var(--p-border, #e6e3da);
  border-radius: 4px;
  /* Default to mid-grey so the reader can tell at a glance this is
     extracted prose, not the cleaner abstract. */
  color: var(--p-fg, #2d3748);
}
/* Inline section bodies don't get their own scroll buffer — the parent
   ``<details>`` is the only scroll context. Keeps the per-section reading
   flow uninterrupted and lets the anchor jumps actually scroll. */
.fulltext-body-inline {
  max-height: none;
  overflow-y: visible;
  background: transparent;
  border: 0;
  padding: 4px 0 12px;
  margin: 0;
}

.fulltext-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 12px 0;
  padding: 8px 12px;
  border: 1px solid var(--p-border, #e6e3da);
  border-radius: 4px;
  background: var(--p-card, #fbfaf7);
  position: sticky;
  top: 8px;
  z-index: 2;
  font-size: 13px;
}
.fulltext-toc a {
  color: var(--p-accent, #2c5282);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 3px;
}
.fulltext-toc a:hover {
  background: var(--p-accent-light, #e6efff);
  text-decoration: underline;
}

.fulltext-sections {
  /* The parent ``details`` provides the outer max-height; per-section
     rows just flow naturally below the ToC. */
  max-height: 720px;
  overflow-y: auto;
  scroll-padding-top: 70px;  /* leave room for the sticky ToC when anchor-jumping */
}
.fulltext-section-row {
  padding: 8px 14px;
  border-top: 1px dashed var(--p-border, #e6e3da);
}
.fulltext-section-row:first-child { border-top: 0; }
.fulltext-section-row h3 {
  font-size: 15px;
  margin: 4px 0 6px;
  color: var(--p-fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* ===========================================================
   In-corpus citation count badge
   ----------------------------------------------------------- */
.badge.citation-count {
  background: #fef5e7;
  border: 1px solid #f0c674;
  color: #7a4f01;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  /* Slightly larger than the other badges so it pops as a "signal"
     metric. A reader scanning a list cares about citation count more than
     about which license tag the paper carries. */
}

/* ===========================================================
   Open Access PDF / landing buttons (Unpaywall-sourced)
   ----------------------------------------------------------- */
.btn-oa-pdf {
  /* Direct PDF — green to signal "free download right now" */
  background: #2f855a;
  color: white;
  border: 0;
}
.btn-oa-pdf:hover { background: #276749; }
.btn-oa-page {
  /* OA landing page — paler shade so PDF stands out as "even better" */
  background: #d6f5d6;
  color: #22543d;
  border: 1px solid #9ae6b4;
}
.btn-oa-page:hover { background: #c6efc6; }

/* Compact inline variant on result cards — small green pill */
.btn-oa-inline {
  background: #c6f0d4;
  color: #1a3a2a;
  border: 1px solid #74c79a;
  font-weight: 600;
}
.btn-oa-inline:hover {
  background: #a4e3bd;
  color: #0d2a1c;
}

/* ===========================================================
   Author + journal profile strip (the "30-second profile")
   ----------------------------------------------------------- */
.profile-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 16px 0 24px;
}
.profile-card {
  background: var(--p-card, #fff);
  border: 1px solid var(--p-border, #e6e3da);
  border-radius: 6px;
  padding: 12px 14px;
}
.profile-card h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--p-fg-muted);
  font-weight: 600;
}
.profile-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
}
.profile-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}
.profile-list li:not(:last-child) {
  border-bottom: 1px dashed var(--p-border, #e6e3da);
}
.profile-name {
  color: var(--p-fg);
  text-decoration: none;
  flex: 1;
  /* Allow long journal/author titles to wrap onto a second line rather than
     truncating mid-word ("Gynecologic and obstetric investigati..." was the
     original audit finding). Cap at 2 lines with line-clamp so a 4-word
     title still fits the card without pushing the row to 3 lines. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  line-height: 1.3;
}
a.profile-name { color: var(--p-accent, #2c5282); }
a.profile-name:hover { text-decoration: underline; }
.profile-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  flex: 0 0 auto;
}
.profile-sparkline {
  height: 60px;
  margin-top: 4px;
  width: 100%;
  overflow: hidden;
}
.profile-sparkline svg, .profile-sparkline canvas {
  /* Vega ships with a fixed pixel width (720); on narrower viewports we
     want the SVG to scale rather than cause horizontal scroll. */
  max-width: 100%;
  height: auto;
}

/* ===========================================================
   Mobile / narrow-viewport rules
   ----------------------------------------------------------- */

/* Tablet (≤ 880px): search layout collapses, side aside drops below */
@media (max-width: 880px) {
  main.portal { padding: 12px; }
  nav.portal-nav { flex-wrap: wrap; gap: 6px 14px; padding: 10px 12px; }
  nav.portal-nav .spacer { display: none; }
  /* API docs + Admin are operator surfaces — researchers don't need them
     on mobile. Hide to keep the nav on one row when the screen permits. */
  nav.portal-nav a.nav-desktop-only { display: none; }

  /* Filter drawer: show the toggle button, hide the form by default.
     User taps "Filters ▼" to expand. Inputs stay in the DOM either way
     (display:none doesn't unmount them) so HTMX still picks them up. */
  .search-sidebar { padding: 8px 12px; }
  .filter-toggle-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 8px 12px;
    margin: 4px 0;
    border: 1px solid var(--p-border);
    border-radius: 6px;
    background: var(--p-bg, #f5f3ed);
    font-size: 14px;
    font-weight: 600;
    color: var(--p-fg);
    user-select: none;
  }
  .filter-toggle-arrow {
    transition: transform 0.15s;
    font-size: 11px;
    color: var(--p-fg-muted);
  }
  .filter-toggle-cb:checked + .filter-toggle-btn .filter-toggle-arrow {
    transform: rotate(180deg);
  }
  .filter-toggle-cb:not(:checked) ~ #search-form {
    display: none;
  }

  /* Card overflow guard — long titles, long DOIs, and the action row
     can push past viewport width without explicit containment. */
  .r-card {
    overflow: hidden;
    word-break: normal;
    overflow-wrap: break-word;
  }
  .r-card .r-title a,
  .r-card .r-meta .mono {
    overflow-wrap: anywhere;
  }
  .r-card .actions {
    flex-wrap: wrap;
    gap: 4px;
  }
  .r-card .actions > * {
    /* Each action stays at its content width; the row wraps onto a
       second line as needed. */
    flex: 0 0 auto;
  }

  .whats-new-grid { grid-template-columns: 1fr !important; }
  .whats-new-side { display: contents; }
  .paper-detail { max-width: 100%; }
  .paper-detail dl.kv,
  .entity-card dl.kv { grid-template-columns: 140px 1fr; }
  /* Vega charts ship width=720 baked into the spec — let them scale down */
  .vega-chart svg, .vega-spark svg, #whats-new-sparkline svg {
    max-width: 100% !important;
    height: auto !important;
  }
  .compare-table th, .compare-table td {
    min-width: 200px;
    max-width: 280px;
  }
}

/* Phone (≤ 600px): single-column everything, denser type */
@media (max-width: 600px) {
  main.portal { padding: 8px; }
  nav.portal-nav { font-size: 13px; padding: 8px 10px; gap: 4px 10px; }
  nav.portal-nav .brand { font-size: 14px; }
  .my-research-grid { grid-template-columns: 1fr !important; }
  .paper-detail h1 { font-size: 22px; }
  .paper-detail dl.kv,
  .entity-card dl.kv {
    grid-template-columns: 1fr;
    row-gap: 2px;
  }
  .entity-card dl.kv dt,
  .paper-detail dl.kv dt {
    /* On phone the "label / value" pattern reads better as stacked rows
       with a lighter label above the value. */
    color: var(--p-fg-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 8px;
  }
  .actions-row { flex-wrap: wrap; }
  .actions-row .btn,
  .actions-row .btn.ghost { flex: 0 1 auto; }
  .r-card { padding: 12px; }
  .r-head { flex-wrap: wrap; gap: 4px; }
  .r-foot { flex-wrap: wrap; gap: 6px; }
  .r-foot .actions { flex-wrap: wrap; }
  /* Hide rank-score on phone — researchers know they're scrolling top-down */
  .r-foot .score, .r-foot .muted { font-size: 11px; }
  /* The home-page stats row already uses auto-fit; the breakpoint here
     makes them stack 2-wide on small screens for legibility. */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Very narrow (≤ 380px): drop a few non-essential rows */
@media (max-width: 380px) {
  nav.portal-nav { font-size: 12px; }
  .r-head .badge.year { display: none; }
  .home-stats { grid-template-columns: 1fr; }
}

/* ---- Fact-check page --------------------------------------------------- */

.factcheck-page {
  max-width: 800px;
  margin: 0 auto;
}

.factcheck-header {
  margin-bottom: 24px;
}

.factcheck-subtitle {
  font-family: var(--p-font-serif);
  font-size: 17px;
  color: var(--p-fg-muted);
  max-width: 680px;
  line-height: 1.6;
}

.factcheck-form-card {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 24px 28px 20px;
  margin-bottom: 24px;
}

/* Tab bar */
.factcheck-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--p-border);
  margin-bottom: 20px;
}

.factcheck-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--p-fg-muted);
  cursor: pointer;
  letter-spacing: 0.01em;
  border-radius: 4px 4px 0 0;
  transition: color 0.15s, border-color 0.15s;
}

.factcheck-tab:hover {
  color: var(--p-accent);
}

.factcheck-tab.active {
  color: var(--p-fg);
  border-bottom-color: var(--p-accent);
}

/* Panels — hidden unless active */
.factcheck-panel {
  display: none;
}

.factcheck-panel--active {
  display: block;
}

.factcheck-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
}

.factcheck-textarea {
  width: 100%;
  font-family: var(--p-font-sans);
  font-size: 14px;
  line-height: 1.55;
  padding: 10px 12px;
  border: 1px solid var(--p-border-strong);
  border-radius: 5px;
  resize: vertical;
  background: var(--p-bg);
  color: var(--p-fg);
}

.factcheck-textarea:focus,
.factcheck-url-input:focus,
.factcheck-file-input:focus {
  outline: 2px solid var(--p-accent);
  outline-offset: 1px;
  border-color: var(--p-accent);
}

.factcheck-url-input {
  width: 100%;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--p-border-strong);
  border-radius: 5px;
  background: var(--p-bg);
  color: var(--p-fg);
}

.factcheck-file-input {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

.factcheck-hint {
  margin: 6px 0 0;
}

.factcheck-submit-row {
  margin-top: 18px;
}

.factcheck-submit-btn {
  background: var(--p-accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 5px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.factcheck-submit-btn:hover {
  background: var(--p-accent-hover);
}

.factcheck-disclaimer-link {
  margin-top: 12px;
  margin-bottom: 0;
}

/* Loading indicator — big, centred, with a spinner. Shown via the
   .htmx-request class HTMX adds to the element with id=fact-check-loading
   while a request is in flight. */
.factcheck-loading {
  display: none;
  text-align: center;
  margin: 20px auto;
  padding: 28px 24px;
  background: var(--p-bg-panel, #f7f7f5);
  border: 1px solid var(--p-border, #e3e0d8);
  border-radius: 10px;
  max-width: 560px;
}

.htmx-request .factcheck-loading,
.htmx-request.factcheck-loading {
  display: block;
}

.factcheck-loading-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border: 3px solid var(--p-border, #d0cdc4);
  border-top-color: var(--p-accent, #2c5d8a);
  border-radius: 50%;
  animation: factcheck-spin 0.9s linear infinite;
}

.factcheck-loading-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--p-fg, #2a2a2a);
  margin-bottom: 6px;
}

.factcheck-loading-detail {
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.5;
}

@keyframes factcheck-spin {
  to { transform: rotate(360deg); }
}

/* Submit button — dual-state label. Idle shows "Check claims"; while
   the form is mid-request HTMX adds .htmx-request to the form and the
   button swaps to a spinner + "Checking…". hx-disabled-elt disables
   the button so a double-click can't fire two requests. */
.factcheck-submit-label-idle { display: inline; }
.factcheck-submit-label-busy { display: none; align-items: center; gap: 8px; }
.htmx-request .factcheck-submit-label-idle,
.htmx-request.factcheck-submit-label-idle { display: none; }
.htmx-request .factcheck-submit-label-busy,
.htmx-request.factcheck-submit-label-busy { display: inline-flex; }

.factcheck-submit-btn[disabled] {
  opacity: 0.7;
  cursor: progress;
}

.factcheck-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: factcheck-spin 0.8s linear infinite;
  vertical-align: -2px;
}

/* Empty state */
.factcheck-empty-state {
  text-align: center;
  padding: 24px 0;
}

/* ---- Report output ----------------------------------------------------- */

.factcheck-report {
  background: var(--p-card);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 24px 28px;
}

.factcheck-report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--p-border);
}

.factcheck-source-label {
  font-weight: 600;
  font-size: 15px;
}

.factcheck-relevance {
  display: flex;
  align-items: center;
  gap: 8px;
}

.factcheck-relevance-bar {
  width: 100px;
  height: 6px;
  background: var(--p-border);
  border-radius: 3px;
  overflow: hidden;
}

.factcheck-relevance-fill {
  height: 100%;
  background: var(--p-accent);
  border-radius: 3px;
}

.factcheck-notes {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--p-warn-bg);
  border-left: 3px solid var(--p-warn);
  border-radius: 0 4px 4px 0;
}

/* Claim cards */
.factcheck-claims {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.factcheck-claim-card {
  border: 1px solid var(--p-border);
  border-radius: 6px;
  padding: 16px 18px;
  background: var(--p-bg);
}

.factcheck-claim-top {
  margin-bottom: 10px;
}

/* Verdict pills */
.factcheck-verdict-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.factcheck-verdict-pill--supported {
  background: var(--p-good-bg);
  color: var(--p-good);
}

.factcheck-verdict-pill--contradicted {
  background: var(--p-danger-bg);
  color: var(--p-danger);
}

.factcheck-verdict-pill--mixed {
  background: var(--p-warn-bg);
  color: var(--p-warn);
}

.factcheck-verdict-pill--insufficient {
  background: #f3f4f6;
  color: var(--p-fg-muted);
}

/* Adjacent-evidence pills: same hue family as supported / contradicted
   to signal direction, but desaturated + dashed border to signal
   low-confidence-by-design. The confidence is capped at 0.5 server-
   side (see ``_clamp_confidence`` in src/endo_lab/llm/yesno.py). */
.factcheck-verdict-pill--adjacent-supports {
  background: var(--p-good-bg);
  color: var(--p-good);
  border: 1px dashed var(--p-good);
  opacity: 0.85;
}

.factcheck-verdict-pill--adjacent-contradicts {
  background: var(--p-danger-bg);
  color: var(--p-danger);
  border: 1px dashed var(--p-danger);
  opacity: 0.85;
}

.factcheck-claim-text {
  font-family: var(--p-font-serif);
  font-size: 16px;
  font-style: italic;
  color: var(--p-fg);
  margin: 8px 0;
  padding-left: 14px;
  border-left: 3px solid var(--p-border-strong);
}

.factcheck-anchor {
  margin: 4px 0 8px;
}

.factcheck-rationale {
  font-size: 14px;
  margin: 0 0 10px;
  line-height: 1.6;
}

/* Citation list */
.factcheck-citations {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.factcheck-citation {
  font-size: 13px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.factcheck-paper-link {
  color: var(--p-accent);
  text-decoration: none;
}

.factcheck-paper-link:hover {
  color: var(--p-accent-hover);
  text-decoration: underline;
}

.factcheck-paper-year {
  font-size: 12px;
}

.factcheck-license-badge {
  font-size: 11px;
}

.factcheck-no-claims {
  margin: 16px 0;
  text-align: center;
}

/* Disclaimer footer */
.factcheck-disclaimer {
  border-top: 1px solid var(--p-border);
  margin-top: 20px;
  padding-top: 14px;
  font-size: 13px;
  color: var(--p-fg-muted);
  font-style: italic;
  line-height: 1.55;
}

/* Error card */
.factcheck-error-card {
  background: var(--p-danger-bg);
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 20px 24px;
  text-align: center;
}

.factcheck-error-message {
  color: var(--p-danger);
  margin: 0 0 12px;
  font-size: 15px;
}

.factcheck-retry-link {
  color: var(--p-accent);
  font-weight: 600;
  font-size: 14px;
}

.factcheck-report-slot {
  /* Reserve vertical space for the report or empty state */
  min-height: 40px;
}

/* ---------------------------------------------------------------- */
/*  /research/chat — researcher chat over the corpus tools         */
/* ---------------------------------------------------------------- */
.chat-page {
  max-width: 880px;
}

.chat-disclaimer {
  margin: 14px 0 20px;
  font-size: 14px;
}

.chat-transcript {
  margin: 18px 0;
  padding: 14px;
  background: var(--p-surface, #fafafa);
  border: 1px solid var(--p-border, #e5e7eb);
  border-radius: 6px;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
}

.chat-empty {
  padding: 22px 8px;
  text-align: center;
  font-size: 14px;
}

.chat-exchange {
  border-bottom: 1px dashed var(--p-border, #e5e7eb);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.chat-exchange:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.chat-msg {
  margin: 8px 0;
}
.chat-msg-role {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--p-fg-muted, #6b7280);
  margin-bottom: 4px;
}
.chat-msg-body {
  padding: 8px 12px;
  border-radius: 6px;
  line-height: 1.55;
}
.chat-msg--user .chat-msg-body {
  background: #eff6ff;
  color: #1e3a8a;
  white-space: pre-wrap;
}
.chat-msg--assistant .chat-msg-body {
  background: #ffffff;
  border: 1px solid var(--p-border, #e5e7eb);
}
.chat-msg--assistant .chat-msg-body a {
  color: var(--p-accent, #2563eb);
  text-decoration: underline;
}
.chat-msg-footer {
  margin: 6px 0 0 4px;
}

.chat-tool-trace {
  margin: 6px 0;
  padding: 6px 12px;
  background: #f9fafb;
  border: 1px solid var(--p-border, #e5e7eb);
  border-radius: 6px;
  font-size: 13px;
}
.chat-tool-trace-summary {
  cursor: pointer;
  user-select: none;
  color: var(--p-fg-muted, #6b7280);
}
.chat-tool-trace-count {
  display: inline-block;
  background: var(--p-accent-light, #dbeafe);
  color: var(--p-accent, #1e40af);
  padding: 0 6px;
  border-radius: 8px;
  font-weight: 700;
  margin-right: 4px;
}
.chat-tool-list {
  margin: 8px 0 0;
  padding-left: 18px;
}
.chat-tool-entry {
  margin: 8px 0;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
}
.chat-tool-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-tool-name {
  font-family: var(--p-font-mono, monospace);
  font-size: 12px;
  background: #eef2ff;
  color: #4338ca;
  padding: 2px 6px;
  border-radius: 3px;
}
.chat-tool-args pre,
.chat-tool-result pre {
  background: #f3f4f6;
  padding: 8px;
  border-radius: 4px;
  font-size: 12px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-tool-error-tag {
  color: var(--p-danger, #b91c1c);
  font-weight: 700;
}

.chat-iter-cap-warning {
  margin: 6px 0 0 4px;
  color: #b45309;
}

.chat-form {
  margin-top: 14px;
}
.chat-form textarea {
  width: 100%;
  padding: 10px;
  font-family: inherit;
  font-size: 15px;
  border: 1px solid var(--p-border, #e5e7eb);
  border-radius: 6px;
  resize: vertical;
}
.chat-form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.chat-form .btn-primary {
  padding: 8px 18px;
}
.chat-form .btn-primary[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-exchange--error {
  margin-top: 14px;
}
.chat-source-quotes {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fdfbef;
  border-left: 3px solid #d4b85c;
  border-radius: 4px;
}
.chat-source-quotes[open] {
  padding-bottom: 14px;
}
.chat-source-quotes-summary {
  cursor: pointer;
  font-size: 13px;
  color: #6b5e2a;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
.chat-source-quotes-summary::-webkit-details-marker {
  display: none;
}
.chat-source-quotes-summary::before {
  content: '▸ ';
  display: inline-block;
  transition: transform 0.15s ease;
}
.chat-source-quotes[open] .chat-source-quotes-summary::before {
  transform: rotate(90deg);
}
.chat-source-quotes-count {
  display: inline-block;
  background: #d4b85c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 4px;
  min-width: 18px;
  text-align: center;
}
.chat-quote-list {
  margin: 10px 0 0 0;
  padding-left: 22px;
}
.chat-quote + .chat-quote {
  margin-top: 12px;
}
.chat-quote-text {
  margin: 0;
  padding: 4px 0 4px 12px;
  border-left: 2px solid #ddd2a3;
  font-style: italic;
  color: #3d3422;
  font-size: 14px;
  line-height: 1.45;
}
.chat-quote-meta {
  margin-top: 4px;
  padding-left: 12px;
}
.chat-quote-section {
  font-weight: 600;
}
.chat-exchange--streaming {
  position: relative;
}
.chat-stream-stage {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-top: 10px;
  background: #f0f6ff;
  border-left: 3px solid #6086cc;
  border-radius: 4px;
  font-size: 13px;
  color: #2f4d80;
}
.chat-stage-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #c3d5f0;
  border-top-color: #2f4d80;
  border-radius: 50%;
  animation: chat-stage-spin 0.9s linear infinite;
  flex-shrink: 0;
}
@keyframes chat-stage-spin {
  to { transform: rotate(360deg); }
}
.chat-stream-tools {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 0;
}
.chat-stream-tool-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  margin-top: 4px;
  background: #f8f8f8;
  border-radius: 4px;
  font-size: 13px;
}
.chat-stream-tool-entry--complete {
  background: #f0f7ed;
  color: #3a5128;
}
.chat-stream-tool-name code {
  background: transparent;
  padding: 0;
  font-weight: 600;
}
.chat-stream-tool-status::before {
  content: '⏳ ';
  display: inline-block;
}
.chat-stream-tool-entry--complete .chat-stream-tool-status::before {
  content: '✓ ';
}
.chat-msg--streaming .chat-msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-stream-error,
.chat-stream-aborted {
  margin-top: 10px;
}
.btn-secondary {
  padding: 8px 14px;
  font-size: 14px;
  background: #fff;
  color: #444;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  cursor: pointer;
}
.btn-secondary:hover {
  background: #f5f5f5;
}
#chat-abort {
  margin-left: 6px;
}
.chat-export-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 10px 14px;
  background: #f8f8f8;
  border-radius: 6px;
  font-size: 13px;
}
.chat-export-label {
  font-weight: 600;
  margin-right: 2px;
}
.chat-export-btn {
  padding: 6px 12px;
  font-size: 13px;
}
.chat-export-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
