/* =====================================================================
   DESIGN TOKENS
   Every colour, space and elevation resolves through this block. Neutrals
   carry a slight cool bias so they sit with the green accent rather than
   fighting it -- a pure grey reads as inherited rather than chosen.

   Two structural rules:
   - Semantic colour (--good/--warn/--crit) is deliberately NOT the accent.
     If green meant both "our brand" and "this is fine", state could not be
     read without reading the text.
   - Spacing comes from --sp*, never ad-hoc rem values, so sibling groups
     share one rhythm.
   ===================================================================== */
:root {
  color-scheme: light dark;

  --sp1: .25rem; --sp2: .5rem;  --sp3: .75rem; --sp4: 1rem;
  --sp5: 1.5rem; --sp6: 2rem;   --sp7: 3rem;

  --radius: 10px;
  --radius-lg: 14px;

  /* Three faces, each with a job. Inter carries body copy, JetBrains Mono
     carries anything the eye scans as a value (labels, ids, numbers), and
     Fraunces carries headings and KPI figures -- the serif is what stops a
     dashboard reading as a generic admin panel. */
  --body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Fraunces", Georgia, serif;

  --rail-w: 220px;
  --rail-w-icons: 64px;
}

:root,
:root[data-theme="light"] {
  --ground: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #e8eef5;
  --surface-3: #dfe7f0;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --rule: #cbd5e1;
  --rule-strong: #94a3b8;
  --accent: #059669;
  --accent-press: #047857;
  --accent-soft: #d1fae5;

  --good: #047857;  --good-bg: #ecfdf5;
  --warn: #b45309;  --warn-bg: #fffbeb;
  --crit: #dc2626;  --crit-bg: #fef2f2;
  --info: #2563eb;  --info-bg: #eff6ff;
  --violet: #7c3aed; --violet-bg: #f5f3ff;

  --e1: 0 1px 2px rgba(15, 23, 42, .05);
  --e2: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --e3: 0 16px 40px rgba(15, 23, 42, .12);
}

/* Not an inversion: the accent is lifted so it still reads as interactive
   on a dark ground, and surfaces step up rather than down. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #020617;
    --surface: #0f172a;
    --surface-alt: #1e293b;
    --surface-3: #334155;
    --ink: #f8fafc;
    --ink-soft: #cbd5e1;
    --muted: #94a3b8;
    --rule: #334155;
    --rule-strong: #475569;
    --accent: #34d399;
    --accent-press: #6ee7b7;
    --accent-soft: #064e3b;

    --good: #34d399;  --good-bg: #064e3b;
    --warn: #fbbf24;  --warn-bg: #2c2416;
    --crit: #f87171;  --crit-bg: #2e1d1a;
    --info: #60a5fa;  --info-bg: #1e3a8a;
    --violet: #a78bfa; --violet-bg: #4c1d95;

    --e1: 0 1px 2px rgba(0, 0, 0, .4);
    --e2: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --e3: 0 16px 40px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --ground: #020617;
  --surface: #0f172a;
  --surface-alt: #1e293b;
  --surface-3: #334155;
  --ink: #f8fafc;
  --ink-soft: #cbd5e1;
  --muted: #94a3b8;
  --rule: #334155;
  --rule-strong: #475569;
  --accent: #34d399;
  --accent-press: #6ee7b7;
  --accent-soft: #064e3b;

  --good: #34d399;  --good-bg: #064e3b;
  --warn: #fbbf24;  --warn-bg: #2c2416;
  --crit: #f87171;  --crit-bg: #2e1d1a;
  --info: #60a5fa;  --info-bg: #1e3a8a;
  --violet: #a78bfa; --violet-bg: #4c1d95;

  --e1: 0 1px 2px rgba(0, 0, 0, .4);
  --e2: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --e3: 0 16px 40px rgba(0, 0, 0, .5);
}

/* --- reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(5, 150, 105, .09), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, .07), transparent 50%),
    var(--ground);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: -.02em;
  font-weight: 600;
}
h4 { margin: 0; font-weight: 600; letter-spacing: -.015em; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute; left: -9999px; top: var(--sp2);
  background: var(--accent); color: #fff;
  padding: var(--sp2) var(--sp4); border-radius: var(--radius); z-index: 100;
}
.skip-link:focus { left: var(--sp4); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- shell ------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.nav-rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--rule);
  padding: 1rem .85rem;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: width .18s ease, flex-basis .18s ease;
}

.brand {
  display: flex; align-items: center; gap: var(--sp3);
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--rule);
}
.brand-mark {
  width: 30px; height: 30px; flex: 0 0 30px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 8px;
  font-family: var(--display);
  font-weight: 700; font-size: .78rem; letter-spacing: -.03em;
}
.brand-title {
  font-family: var(--display);
  font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em;
}
.brand-sub {
  font-family: var(--mono); font-size: .6rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}

/* --- workspace switcher ------------------------------------------------
   A segmented control, not a nav link. Onco and Non-Onco are different
   contexts for the whole platform, and burying that in a list of pages
   would read as "another page" rather than "another workspace". */
.workspace {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 3px;
}
.workspace a {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: var(--sp2) var(--sp1);
  border-radius: 7px;
  color: var(--muted);
  font-size: .78rem; font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.workspace a:hover { color: var(--ink); background: var(--surface-3); text-decoration: none; }
.workspace a.is-active {
  background: var(--surface); color: var(--accent);
  box-shadow: var(--e1);
}
.workspace .ws-count {
  font-family: var(--mono); font-size: .6rem; font-weight: 500;
  color: var(--muted);
}
.workspace a.is-active .ws-count { color: var(--accent); }

/* --- nav --------------------------------------------------------------- */
.nav-scroll { flex: 1; display: flex; flex-direction: column; gap: var(--sp4); }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-section {
  font-family: var(--mono); font-size: .62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
  padding: .35rem .5rem;
}
.nav-link {
  display: flex; align-items: center; gap: .55rem;
  padding: .38rem .55rem;
  border-radius: 4px;
  color: var(--ink-soft);
  font-size: .84rem;
  text-decoration: none;
  transition: background .14s ease, color .14s ease;
}
.nav-link:hover { background: var(--surface-alt); color: var(--ink); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link svg {
  flex: 0 0 17px; width: 17px; height: 17px; opacity: .85;
  overflow: visible;
}
.nav-link.is-active svg { opacity: 1; }
.icon-btn svg { width: 18px; height: 18px; }
.empty-icon svg { width: 22px; height: 22px; }
.nav-count {
  margin-left: auto;
  font-family: var(--mono); font-size: .66rem;
  color: var(--muted);
}

/* Icon-only mode. Labels are hidden, not removed, so screen readers and
   the tooltip both still have them. */
.shell.nav-icons .nav-rail { width: var(--rail-w-icons); flex-basis: var(--rail-w-icons); }
.shell.nav-icons .nav-label,
.shell.nav-icons .nav-section,
.shell.nav-icons .brand-text,
.shell.nav-icons .nav-count,
.shell.nav-icons .ws-label { display: none; }
.shell.nav-icons .nav-link { justify-content: center; padding: .5rem; }
.shell.nav-icons .brand { justify-content: center; padding: 0; }
.shell.nav-icons .workspace { grid-template-columns: 1fr; }
.shell.nav-icons .workspace a { padding: var(--sp2) 0; }

/* --- top bar ----------------------------------------------------------- */
.top-bar {
  display: flex; align-items: center; gap: var(--sp3);
  padding: .85rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  background: transparent; border: 1px solid transparent;
  border-radius: 8px; color: var(--ink-soft);
}
.icon-btn:hover { background: var(--surface-alt); border-color: var(--rule); color: var(--ink); }

.search { position: relative; flex: 1; max-width: 460px; }
.search input {
  width: 100%;
  padding: .48rem var(--sp3) .48rem 2.1rem;
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink); font-size: .86rem;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { background: var(--surface); border-color: var(--accent); outline: none; }
.search svg {
  position: absolute; left: .62rem; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--muted); pointer-events: none;
}
.search kbd {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: .62rem; color: var(--muted);
  background: var(--surface-3); border: 1px solid var(--rule);
  border-radius: 4px; padding: 1px 5px;
}
/* --- omni search typeahead --------------------------------------------- */
/* Anchored to .search, which is already position: relative. */
.omni-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  max-height: min(70vh, 30rem); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
  padding: .3rem;
}
.omni-panel[hidden] { display: none; }

.omni-group + .omni-group { border-top: 1px solid var(--rule); margin-top: .25rem; }
.omni-group-head {
  padding: .4rem .55rem .25rem;
  font-family: var(--mono); font-size: .64rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}

.omni-item {
  display: flex; align-items: flex-start; gap: var(--sp2);
  padding: .4rem .55rem; border-radius: 6px;
  color: var(--ink); text-decoration: none;
}
.omni-item:hover,
.omni-item.is-active { background: var(--accent-soft); }
.omni-item .badge { flex: none; margin-top: .1rem; }

.omni-text { min-width: 0; display: flex; flex-direction: column; }
.omni-title {
  font-size: .84rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.omni-sub {
  font-size: .74rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.omni-more {
  justify-content: center; font-size: .78rem; font-weight: 600;
  color: var(--accent); border-top: 1px solid var(--rule);
  margin-top: .25rem; border-radius: 0 0 6px 6px;
}
.omni-empty, .omni-note {
  padding: .6rem .55rem; font-size: .78rem; color: var(--muted);
}
.omni-note { border-top: 1px solid var(--rule); }

.top-spacer { flex: 1; }

/* --- breadcrumbs ------------------------------------------------------- */
.breadcrumbs {
  padding: .55rem 1.25rem 0;
  font-size: .78rem; color: var(--muted);
  display: flex; align-items: center; gap: var(--sp1); flex-wrap: wrap;
}
.crumb-sep { color: var(--rule-strong); }

/* --- page -------------------------------------------------------------- */
.page { padding: 1.15rem 1.35rem 2.5rem; }
.page-stack { display: flex; flex-direction: column; gap: 1.15rem; }
.page-header { display: flex; align-items: flex-start; gap: var(--sp4); flex-wrap: wrap; }
.page-header h1 { font-size: 1.75rem; letter-spacing: -.03em; }
.page-header p { margin: .4rem 0 .55rem; max-width: 62ch; color: var(--muted); font-size: .9rem; }
.page-header-actions { margin-left: auto; display: flex; gap: var(--sp2); }

/* Drug header: copy left, ChEMBL structure + outbound chip right */
.drug-header { align-items: stretch; flex-wrap: nowrap; }
.drug-header-copy { min-width: 0; flex: 1 1 auto; }
.drug-header-aside {
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp2);
  flex: 0 0 auto;
}
.drug-structure {
  margin: 0;
  padding: .55rem .65rem;
  background: #ffffff;
  border: 1px solid var(--rule, #e2e8f0);
  border-radius: 10px;
  line-height: 0;
  max-width: min(320px, 42vw);
}
.drug-structure img {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  aspect-ratio: 280 / 220;
  object-fit: contain;
}
@media (max-width: 760px) {
  .drug-header { flex-wrap: wrap; }
  .drug-header-aside {
    margin-left: 0;
    width: 100%;
    align-items: stretch;
  }
  .drug-structure { max-width: none; }
  .drug-structure img { max-width: none; }
}

/* --- kpi tiles --------------------------------------------------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(226px, 1fr));
  gap: .75rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: .85rem .95rem;
  box-shadow: var(--e1);
  display: flex; flex-direction: column;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
a.kpi:hover {
  border-color: var(--accent); box-shadow: var(--e2);
  transform: translateY(-1px); text-decoration: none;
}
.kpi-label {
  font-family: var(--mono); font-size: .64rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.kpi-value {
  font-family: var(--display);
  font-size: 1.35rem; font-weight: 600;
  margin-top: .25rem; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.kpi-note { font-size: .72rem; color: var(--muted); margin-top: .2rem; }
a.kpi { color: inherit; text-decoration: none; cursor: pointer; }
td.num a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--rule-strong, #94a3b8);
}
td.num a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* --- panels ------------------------------------------------------------ */
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--e2);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: var(--sp3);
  padding: 1.1rem 1.2rem .85rem;
  border-bottom: 1px solid var(--rule);
}
.panel-head h2 { font-size: 1.15rem; }
.panel-head p { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.panel-head .panel-action { margin-left: auto; font-size: .8rem; }
.panel-head-icon { align-items: center; gap: .85rem; }
.panel-head-icon-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.panel-head-icon-mark svg {
  width: 20px;
  height: 20px;
}
.panel-head-copy { min-width: 0; }
.panel-head-copy h2 { margin: 0; line-height: 1.25; }
.panel-head-copy p { margin: .15rem 0 0; }
.panel-body { padding: 1.1rem 1.2rem; }
.panel-body.is-flush { padding: 0; }
.chart-host { width: 100%; height: 280px; }
.chart-host-tall { height: 360px; }
.chart-host-box { height: 220px; }
.chart-host-map { height: 340px; }

/* --- trial compare (Gantt + duration box) -------------------------------- */
.trial-compare.is-muted #trial-compare-charts { opacity: .45; pointer-events: none; }
#trial-compare-charts.is-empty .chart-host { min-height: 0; height: 0; overflow: hidden; margin: 0; }
#trial-compare-charts.is-empty .chart-subhead { display: none; }
.trial-compare-check {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}
.trial-compare-check input {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--info, #2563eb);
}
.chart-subhead {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0 0 .55rem;
}
.chart-split { align-items: stretch; }

/* --- pipeline disease picker (Bootstrap dropdown + app tokens) -------- */
.pipeline-picker { margin-bottom: .85rem; }
.pipeline-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .65rem;
}
.pipeline-picker-label {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.pipeline-picker-label .muted {
  margin-left: .35rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}
.pipeline-picker-dropdown { position: relative; flex: 0 1 auto; max-width: min(16rem, 55%); }
.pipeline-picker-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: .45rem;
  min-height: 34px;
  max-width: 100%;
  padding: .35rem .7rem;
  background: var(--surface) !important;
  border: 1px solid var(--rule) !important;
  border-radius: 999px !important;
  color: var(--ink) !important;
  box-shadow: none;
  font-size: .8rem;
}
.pipeline-picker-trigger:hover,
.pipeline-picker-trigger:focus,
.pipeline-picker-trigger.show {
  border-color: var(--rule-strong) !important;
  background: var(--surface-alt) !important;
  color: var(--ink) !important;
}
.pipeline-picker-trigger::after { margin-left: .35rem; }
.pipeline-picker-summary {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-weight: 500;
}
.pipeline-picker-summary.is-placeholder {
  color: var(--muted);
  font-weight: 400;
}
.pipeline-picker-menu {
  min-width: 18rem;
  max-width: min(22rem, 90vw);
  padding: .5rem 0 .35rem;
  border: 1px solid var(--rule) !important;
  border-radius: var(--radius) !important;
  background: var(--surface) !important;
  box-shadow: var(--e3) !important;
}
.pipeline-picker-options {
  max-height: 14rem;
  overflow-y: auto;
}
.pipeline-disease-option {
  cursor: pointer;
  color: var(--ink-soft) !important;
  white-space: normal;
}
.pipeline-disease-option:hover,
.pipeline-disease-option:focus {
  background: var(--surface-alt) !important;
  color: var(--ink) !important;
}
.pipeline-disease-option.is-disabled {
  opacity: .5;
  cursor: not-allowed;
}
.pipeline-option-name { font-weight: 500; font-size: .84rem; }
.pipeline-option-count { flex-shrink: 0; }
.pipeline-picker-empty { padding: 1rem .75rem; }
.pipeline-picker-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}
.pipeline-tag {
  --tag-color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  max-width: 100%;
  padding: .28rem .65rem;
  border: 1px solid color-mix(in srgb, var(--tag-color) 35%, var(--rule));
  border-radius: 999px;
  background: color-mix(in srgb, var(--tag-color) 12%, var(--surface));
  color: var(--ink-soft);
  font-size: .74rem;
  font-weight: 600;
}
.pipeline-tag-dot {
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--tag-color);
}
.pipeline-tag-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pipeline-tag-x { opacity: .65; line-height: 1; color: var(--tag-color); }
.pipeline-phase-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
  gap: .5rem;
  margin: .9rem 0 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--rule);
}
.pipeline-phase-total {
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: .55rem .65rem;
  text-align: center;
}
.pipeline-phase-total-label {
  display: block;
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .2rem;
}
.pipeline-phase-total-value {
  display: block;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pipeline-fallback {
  display: flex;
  flex-direction: column;
  gap: .7rem;
}
.pipeline-fallback-row {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .25rem;
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.15rem; }

/* --- tables ------------------------------------------------------------ */
.table-scroll { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .84rem; }
th, td {
  text-align: left; padding: .5rem 1.1rem;
  border-bottom: 1px solid var(--rule); vertical-align: middle;
}
th {
  font-family: var(--mono); font-size: .64rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  background: var(--surface-alt); white-space: nowrap;
  position: sticky; top: 0;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-alt); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- badges & chips ---------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp1);
  padding: .12rem .45rem;
  border-radius: 5px;
  font-family: var(--mono); font-size: .66rem; font-weight: 600;
  letter-spacing: .03em; white-space: nowrap; line-height: 1.2;
  background: var(--surface-alt); color: var(--ink-soft);
}
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.evidence-legend {
  display: inline-flex; align-items: center; gap: .35rem;
  margin-left: .65rem; vertical-align: middle;
}
.evidence-legend .badge { font-size: .62rem; font-weight: 600; }
.evidence-type-cell {
  display: inline-flex; align-items: center; gap: .35rem;
}
.badge-crit { background: var(--crit-bg); color: var(--crit); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp1);
  background: var(--accent-soft); color: var(--accent);
  border: 0; border-radius: 999px;
  padding: .18rem .55rem; font-size: .76rem; font-weight: 600;
}

/* --- score bar --------------------------------------------------------- */
.score { display: flex; align-items: center; gap: var(--sp2); min-width: 108px; }
.score-track {
  flex: 1; height: 5px; border-radius: 999px;
  background: var(--surface-3); overflow: hidden;
}
.score-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  width: 0;
}
.score-value {
  font-family: var(--mono); font-size: .72rem;
  color: var(--ink-soft); font-variant-numeric: tabular-nums;
}

/* --- disease list: filters, sort, completeness ------------------------- */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .65rem .85rem;
}
.filter-field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.filter-label {
  font-family: var(--mono); font-size: .62rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.filter-search { flex: 1 1 220px; }
.filter-search input {
  width: 100%;
  padding: .42rem .65rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-alt); color: var(--ink); font-size: .86rem;
}
.filter-search input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-field select {
  padding: .42rem .55rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-alt); color: var(--ink); font-size: .86rem;
}
.filter-check {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .84rem; color: var(--ink-soft); cursor: pointer;
  padding: .35rem 0;
}
.filter-check input { accent-color: var(--accent); }

.sort-link {
  color: inherit; text-decoration: none; font-weight: 600;
  display: inline-flex; align-items: center; gap: .3rem;
}
.sort-link:hover { color: var(--accent); text-decoration: none; }
.sort-link.is-active { color: var(--accent); }
.sort-dir {
  font-family: var(--mono); font-size: .62rem; font-weight: 500;
  text-transform: uppercase; color: var(--muted);
}

.badge-row { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }

.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp3); padding: var(--sp4) var(--sp4);
  border-top: 1px solid var(--rule);
}
.pagination-status { font-size: .84rem; }
.btn.is-disabled {
  opacity: .45; pointer-events: none; cursor: default;
}

/* --- buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp2);
  padding: .42rem var(--sp4);
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-size: .84rem; font-weight: 500; text-decoration: none;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-press); border-color: var(--accent-press); }

/* --- callout note -------------------------------------------------------
   Used where two measurements look combinable but are not (e.g. HPA nTPM
   and disease log2FC come from different platforms and are never
   multiplied together into an estimated value). */
.callout {
  display: flex; gap: var(--sp3); align-items: flex-start;
  padding: var(--sp3) var(--sp4);
  border: 1px solid var(--info); border-left: 3px solid var(--info);
  background: var(--info-bg); border-radius: var(--radius);
  font-size: .84rem; color: var(--ink-soft);
}
.callout svg { flex: none; width: 18px; height: 18px; color: var(--info); margin-top: .1rem; }
.callout p { margin: 0; }
.callout strong { color: var(--ink); }

/* --- chart tab switcher -------------------------------------------------
   Segmented buttons that swap the dataset feeding one chart host, rather
   than separate routes: the three HPA series (tissue / cell type / cell
   line) share one chart and one story ("how much, where"). */
.chart-tabs { display: flex; flex-wrap: wrap; gap: var(--sp2); margin-bottom: var(--sp3); }
.chart-tab {
  padding: .32rem .8rem;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--surface-alt); color: var(--ink-soft);
  font-size: .8rem; font-weight: 600; cursor: pointer;
}
.chart-tab:hover { color: var(--ink); }
.chart-tab.is-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.col-expand { width: 2.25rem; vertical-align: middle; }
.row-expand-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.75rem; padding: 0;
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--surface-alt); color: var(--ink-soft); cursor: pointer;
}
.row-expand-btn:hover { color: var(--ink); border-color: var(--accent); }
.row-expand-btn.is-open { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.row-expand-btn i {
  width: 1rem; height: 1rem;
  transform: rotate(0deg);
  transform-origin: center;
  transition: transform .2s ease;
}
.row-expand-btn.is-open i { transform: rotate(90deg); }
.status-drugged { display: inline-flex; align-items: center; gap: .35rem; }
.status-drugs-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: .35rem;
  min-width: 12rem; text-align: left;
}
.status-drugs-list li {
  display: flex; justify-content: space-between; gap: .75rem;
  font-size: .85rem;
}
.target-ntpm-detail > td { background: var(--surface-alt); padding: var(--sp4) !important; }
.ntpm-expand-panel { max-width: 52rem; }
.ntpm-expand-head h3 { margin: 0 0 .25rem; font-size: 1rem; }
.ntpm-expand-head p { margin: 0 0 .35rem; }

/* --- empty state -------------------------------------------------------
   Treated as a real design surface: an empty dashboard is the first thing
   a new workspace shows, and "no data" without a reason reads as broken. */
.empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: var(--sp3);
  padding: var(--sp7) var(--sp4);
}
.empty-icon {
  width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 50%; background: var(--surface-alt); color: var(--muted);
}
.empty h3 { font-size: 1rem; }
.empty p { color: var(--muted); font-size: .86rem; max-width: 46ch; }
.empty code {
  font-family: var(--mono); font-size: .78rem;
  background: var(--surface-alt); border: 1px solid var(--rule);
  border-radius: 6px; padding: .12rem .4rem;
}

/* --- responsive --------------------------------------------------------
   Below 900px the rail becomes an overlay: a 236px fixed column on a
   360px screen leaves no room for a table. */
@media (max-width: 900px) {
  .nav-rail {
    position: fixed; z-index: 40; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--e3);
  }
  .shell.nav-open .nav-rail { transform: translateX(0); }
  .shell.nav-icons .nav-rail { width: var(--rail-w); flex-basis: var(--rail-w); }
  .shell.nav-icons .nav-label,
  .shell.nav-icons .nav-section,
  .shell.nav-icons .brand-text,
  .shell.nav-icons .ws-label { display: revert; }
  .shell.nav-icons .nav-link { justify-content: flex-start; padding: .42rem var(--sp2); }
  .nav-scrim {
    position: fixed; inset: 0; z-index: 39;
    background: rgba(2, 6, 23, .45);
  }
  .page, .top-bar, .breadcrumbs { padding-left: var(--sp4); padding-right: var(--sp4); }
  .search kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* --- column explainers ---------------------------------------------------
   Every derived column carries one. These metrics are joins and set
   intersections, not raw counts, so a reader who cannot see the definition
   has no way to judge whether the number means anything. */
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: .3rem; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%;
  background: transparent; color: var(--muted);
  font-size: 10px; font-weight: 600; line-height: 1; font-style: italic;
  cursor: help; vertical-align: middle;
}
.info-dot:hover, .info-dot:focus-visible {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft);
}
.info-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Bootstrap renders popovers in its own stacking context, so the platform
   tokens have to be pushed onto them explicitly or they arrive white-on-white
   in dark mode. */
.popover {
  --bs-popover-bg: var(--surface);
  --bs-popover-border-color: var(--rule);
  --bs-popover-header-bg: var(--surface);
  --bs-popover-header-color: var(--ink);
  --bs-popover-body-color: var(--muted);
  --bs-popover-max-width: 300px;
  --bs-popover-font-size: .8rem;
  --bs-popover-header-font-size: .82rem;
  box-shadow: var(--e3);
}
.popover .popover-body { line-height: 1.55; }

/* The association-score explainer carries a formula and section headings, so
   it needs more room than a one-paragraph popover and a monospace line that
   will not wrap mid-expression. */
.popover-assoc { --bs-popover-max-width: 380px; }
.popover-assoc .popover-body > p { margin: 0 0 .5rem; }
.popover-assoc .popover-body > p:last-child { margin-bottom: 0; }
.popover-assoc .pop-h {
  margin-top: .7rem;
  color: var(--ink);
  font-size: .7rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
}
.popover-assoc .pop-formula {
  display: block; margin: .1rem 0 .6rem; padding: .45rem .55rem;
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--accent-soft);
  color: var(--ink);
  font-family: var(--mono); font-size: .78rem;
  overflow-x: auto; white-space: nowrap;
}
.popover-assoc .pop-src { color: var(--muted); font-size: .72rem; }

/* Secondary figure under a cell's headline number. */
.cell-note {
  margin-top: 2px;
  font-size: .72rem; font-weight: 400; color: var(--muted);
  white-space: nowrap;
}
.cell-note.is-warn { color: var(--warn); }

/* --- disease detail ------------------------------------------------------ */
.detail-definition {
  max-width: 68ch; margin-top: var(--sp2);
  color: var(--ink-soft); line-height: 1.6;
}

.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp2); }
.chip-key {
  margin-right: .35rem; color: var(--muted);
  font-size: .68rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
}

.mention-chips {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-top: .4rem; align-items: center;
}
.mention-chip { font-size: .72rem; font-weight: 500; }
.mention-gene { background: var(--accent-soft); color: var(--accent-press); }
.mention-drug { background: var(--info-soft, #dbeafe); color: var(--info, #2563eb); }
.mention-concept { background: var(--surface-alt); color: var(--ink-soft); }
.mention-trial { background: var(--violet-soft, #ede9fe); color: var(--violet, #7c3aed); }
.mention-company { background: var(--surface-alt); color: var(--ink-soft); }
a.mention-link {
  background: var(--accent-soft); color: var(--accent-press);
  text-decoration: none;
}
a.mention-link:hover { text-decoration: underline; }
.mention-cite-note { margin: .35rem 0 0; }
.mentions-expand-panel { padding: var(--sp2) var(--sp3) var(--sp3); }
.mention-group { margin-bottom: var(--sp3); }
.mention-group:last-child { margin-bottom: 0; }
.mention-group h4 {
  margin: 0 0 .4rem;
  font-size: .72rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
}
.chip.is-primary { border-color: var(--accent); background: var(--accent-soft); }
.chip.is-primary .chip-key { color: var(--accent-press); }
.chip-quiet { background: var(--surface-alt); color: var(--ink-soft); }

.synonym-block { margin-top: var(--sp3); }
.synonym-block > summary {
  cursor: pointer; color: var(--muted); font-size: .82rem;
  margin-bottom: var(--sp2);
}
.synonym-block > summary:hover { color: var(--ink); }

/* The funnel is plain markup rather than a chart: four numbers whose whole
   point is that each is a subset of the one above it read better as stacked
   bars on a shared scale than as a chart that has to be waited for. */
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp3); }
.funnel-meta {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--sp2); margin-bottom: .3rem;
}
.funnel-label { font-size: .85rem; color: var(--ink-soft); }
.funnel-value { font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.funnel-track {
  height: 10px; border-radius: 999px;
  background: var(--surface-alt); overflow: hidden;
}
.funnel-fill {
  height: 100%; border-radius: 999px; background: var(--accent);
  min-width: 3px;
}
.funnel-step:last-child .funnel-fill { background: var(--info); }
.funnel-hint { margin: .3rem 0 0; font-size: .75rem; color: var(--muted); }
.row-link { color: inherit; text-decoration: none; }
.row-link:hover strong { color: var(--accent); text-decoration: underline; }

/* --- disease tabs -------------------------------------------------------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: var(--sp1);
  border-bottom: 1px solid var(--rule); padding-bottom: 0;
}
.tab {
  padding: .5rem var(--sp3); border-bottom: 2px solid transparent;
  color: var(--muted); font-size: .88rem; text-decoration: none;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab.is-pending { color: var(--rule-strong); cursor: not-allowed; }
.tab-count {
  margin-left: .35rem; padding: .05rem .4rem; border-radius: 999px;
  background: var(--surface-alt); color: var(--muted); font-size: .72rem;
}

/* --- evidence heatmap strip ----------------------------------------------
   One cell per evidence type, ordered by what each type claims. Opacity
   carries the score, so a target resting entirely on literature reads as a
   single dark cell on the right rather than as a number a reader must decode. */
.dt-strip { display: flex; gap: 2px; }
.dt-cell {
  width: 14px; height: 20px; border-radius: 2px;
  background: var(--accent);
  opacity: calc(.15 + var(--dt-weight, 0) * .85);
}
.dt-cell.is-empty { background: var(--surface-alt); opacity: 1; }
.panel-head-actions { margin-left: auto; }

/* --- trial stop reasons --------------------------------------------------
   A bar per bucket that opens to the sponsor's own words. The examples are
   not decoration: the bucketing is keyword matching over free text, and the
   only honest way to show it is to let a reader check what it caught. */
.reason-list { display: grid; gap: var(--sp2); }
.reason > summary {
  display: grid; grid-template-columns: 13rem 3rem 1fr; align-items: center;
  gap: var(--sp3); cursor: pointer; padding: .3rem 0;
  font-size: .85rem; color: var(--ink-soft);
}
.reason > summary::-webkit-details-marker { display: none; }
.reason-label { font-weight: 500; }
.reason-count { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.reason-track { height: 8px; border-radius: 999px; background: var(--surface-alt); }
.reason-fill { display: block; height: 100%; border-radius: 999px; background: var(--crit); }
.reason-examples {
  margin: .2rem 0 .6rem; padding-left: 13rem; list-style: none;
  display: grid; gap: .3rem; font-size: .78rem;
}
.reason-examples li { display: flex; gap: var(--sp2); }

@media (max-width: 760px) {
  .reason > summary { grid-template-columns: 1fr auto; }
  .reason-track { grid-column: 1 / -1; }
  .reason-examples { padding-left: 0; }
}

/* --- literature ----------------------------------------------------------
   The title is the row's primary action: a paper list exists to be clicked
   through to the paper. Every row resolves to a URL (DOI, then PMID, then
   PMCID, then Europe PMC), so the link is never decoration. */
.paper-title {
  display: inline-block; max-width: 62ch;
  color: var(--ink); font-weight: 500; line-height: 1.4; text-decoration: none;
}
a.paper-title:hover { color: var(--accent); text-decoration: underline; }
.paper-title-icon {
  width: 12px; height: 12px; margin-left: .25rem;
  vertical-align: baseline; opacity: .45;
}
a.paper-title:hover .paper-title-icon { opacity: 1; }

/* Provenance sits under the papers and stays shut: it explains where the
   corpus came from, which matters, but not before the corpus itself. */
.provenance > summary { cursor: pointer; list-style: none; }
.provenance > summary::-webkit-details-marker { display: none; }
.provenance > summary h2::after {
  content: " ▸"; color: var(--muted); font-size: .8em;
}
.provenance[open] > summary h2::after { content: " ▾"; }

/* --- knowledge graph --------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.page:has(.kg-page) {
  padding-left: 0;
  padding-right: 0;
  padding-top: 0;
}
.kg-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 7.5rem);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-alt) 55%, transparent), transparent 220px),
    var(--ground);
}

/* --- filter bar --------------------------------------------------------
   Sticky so the controls stay reachable while the graph is scrolled. Each
   control is a popover keyed off .kg-menu, which keeps the bar one row deep
   no matter how many facets the server offers. */
.kg-filterbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  gap: .7rem;
  padding: .9rem 1.15rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--surface) 94%, var(--ground));
  backdrop-filter: blur(6px);
}
.kg-filterbar-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.kg-filterbar-head h1 {
  font-family: var(--display);
  font-size: 1.4rem;
  margin: .1rem 0 0;
  letter-spacing: -.02em;
}
.kg-filterbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Natural-language query bar */
.kg-nl-chat-wrap {
  display: grid;
  gap: .45rem;
}
.kg-nl-label {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.kg-nl-row {
  display: flex;
  gap: .5rem;
  align-items: stretch;
}
.kg-nl-input {
  flex: 1;
  min-width: 0;
  padding: .55rem .75rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  font-size: .95rem;
  color: var(--ink);
}
.kg-nl-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .5rem;
  font-size: .82rem;
}
.kg-nl-example {
  padding: .2rem .55rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: .78rem;
  cursor: pointer;
}
.kg-nl-example:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.kg-nl-reply {
  padding: .55rem .75rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--rule));
  font-size: .9rem;
}
.kg-nl-reply.is-error {
  background: color-mix(in srgb, var(--danger, #c0392b) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--danger, #c0392b) 30%, var(--rule));
}
.kg-nl-reply.is-clarify .kg-nl-options {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .5rem;
}
.kg-nl-option {
  padding: .35rem .65rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: .82rem;
}

.kg-menu-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: .65rem 1rem;
}
.kg-filter-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: .45rem .55rem .5rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, var(--surface-alt));
  min-width: min(100%, 12rem);
}
.kg-filter-group-label {
  margin: 0;
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.kg-filter-group-menus {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}
/* Slots hold the JS-injected menus without introducing a nesting level that
   would break the row's wrapping. */
.kg-menu-slot {
  display: contents;
}
.kg-menu {
  position: relative;
}
.kg-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .38rem .7rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  white-space: nowrap;
}
.kg-menu-trigger::after {
  content: "▾";
  font-size: .7rem;
  color: var(--muted);
}
.kg-menu-trigger:hover { background: var(--accent-soft); }
.kg-menu-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.kg-menu-trigger.is-active {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--rule));
}
.kg-menu-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 .3rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--surface);
  font-family: var(--mono);
  font-size: .66rem;
}
.kg-menu-badge[hidden] { display: none; }
.kg-menu-pop {
  position: absolute;
  top: calc(100% + .35rem);
  left: 0;
  z-index: 40;
  width: min(20rem, 78vw);
  display: grid;
  gap: .55rem;
  padding: .7rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--e2);
}
/* Menus near the right edge open leftwards so the popover stays on screen. */
.kg-menu.is-flipped .kg-menu-pop {
  left: auto;
  right: 0;
}
.kg-menu-pop[hidden] { display: none; }
.kg-menu-note {
  margin: 0;
  font-size: .72rem;
  color: var(--muted);
}
.kg-menu-clear {
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: .74rem;
  padding: 0;
  cursor: pointer;
}
.kg-active-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.kg-active-chips:empty { display: none; }
.kg-eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}
.kg-search input,
.kg-range-row input[type="number"] {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: .45rem .6rem;
  font: inherit;
}
.kg-search input:focus,
.kg-range-row input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}
.kg-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
}
.kg-checklist li label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .45rem;
  align-items: center;
  padding: .42rem .55rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  font-size: .8rem;
}
.kg-checklist li:last-child label { border-bottom: 0; }
.kg-checklist li label:hover { background: var(--accent-soft); }
.kg-checklist .count {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--muted);
}
.kg-hits {
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  max-height: 160px;
  overflow: auto;
  box-shadow: var(--e2);
}
.kg-hit {
  display: flex;
  justify-content: space-between;
  gap: var(--sp2);
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: .45rem .65rem;
  font: inherit;
  cursor: pointer;
}
.kg-hit:hover { background: var(--accent-soft); }
.kg-hit .mono { color: var(--muted); font-size: .72rem; }
/* Already-chosen results stay in the list and read as toggles, so a second
   click removes rather than silently re-adding. */
.kg-hit.is-selected {
  background: var(--accent-soft);
  font-weight: 600;
}
.kg-hit.is-selected::before {
  content: "✓";
  color: var(--accent);
  margin-right: .35rem;
}
.kg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.kg-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .18rem .5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--rule));
  font-size: .74rem;
  color: var(--ink);
}
.kg-chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-size: .95rem;
}
.kg-range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.kg-range-row label {
  display: grid;
  gap: .25rem;
  font-size: .72rem;
  color: var(--muted);
}
.kg-dirty { margin: 0; font-size: .72rem; color: var(--warn); }

.kg-workspace {
  min-width: 0;
  padding: 1rem 1.15rem 2rem;
  display: grid;
  gap: .9rem;
}
.kg-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.kg-toolbar h2 {
  font-family: var(--display);
  font-size: 1.35rem;
  margin: .1rem 0 .25rem;
}
.kg-toolbar-side {
  display: grid;
  gap: .55rem;
  justify-items: end;
}
.kg-status {
  margin: 0;
  font-size: .78rem;
  color: var(--muted);
}
.kg-status.warn { color: var(--warn); font-weight: 600; }
.kg-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
  justify-content: flex-end;
}
.kg-seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 9px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--e1);
}
.kg-seg button {
  border: 0;
  border-right: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  padding: .35rem .6rem;
  font: inherit;
  cursor: pointer;
}
.kg-seg button:last-child { border-right: 0; }
.kg-seg button:hover,
.kg-seg button[aria-pressed="true"] { background: var(--accent-soft); }
.kg-degree {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .76rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 9px;
  padding: .25rem .55rem;
}
.kg-degree input[type="range"] { width: 88px; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--rule);
}

.kg-explore {
  display: grid;
  gap: .9rem;
  min-width: 0;
}
.kg-explore:fullscreen,
.kg-explore:-webkit-full-screen {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 1rem 1.15rem;
  background: var(--ground);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.kg-explore:fullscreen .kg-toolbar,
.kg-explore:-webkit-full-screen .kg-toolbar {
  flex: 0 0 auto;
}
.kg-explore:fullscreen .kg-canvas-row,
.kg-explore:-webkit-full-screen .kg-canvas-row {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}
.kg-explore:fullscreen .kg-stage,
.kg-explore:-webkit-full-screen .kg-stage,
.kg-explore:fullscreen .kg-drawer,
.kg-explore:-webkit-full-screen .kg-drawer {
  height: 100%;
  max-height: none;
  min-height: 0;
}
.kg-canvas-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: .85rem;
  align-items: stretch;
  min-height: 560px;
}
.kg-graph {
  min-width: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--e2);
  display: flex;
  flex-direction: column;
}
.kg-stage {
  position: relative;
  flex: 1 1 auto;
  height: min(68vh, 760px);
  min-height: 520px;
  background:
    radial-gradient(ellipse 70% 55% at 18% 22%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(ellipse 55% 45% at 82% 78%, color-mix(in srgb, var(--info) 12%, transparent), transparent 55%),
    linear-gradient(160deg, var(--surface) 0%, var(--surface-alt) 100%);
}
.kg-sigma { width: 100%; height: 100%; }
.kg-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp5);
  text-align: center;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  color: var(--ink-soft);
  font-size: .95rem;
  pointer-events: none;
  backdrop-filter: blur(2px);
}
.kg-overlay.is-error { color: var(--crit); }
.kg-legend {
  position: absolute;
  left: .85rem;
  bottom: .85rem;
  max-width: min(300px, 72%);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: .65rem .75rem;
  font-size: .74rem;
  box-shadow: var(--e2);
  backdrop-filter: blur(6px);
}
.kg-legend .legend-title {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .4rem;
}
.kg-legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .28rem; }
.kg-legend li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: .45rem;
  align-items: center;
}
.kg-legend i {
  width: 10px; height: 10px; border-radius: 999px; display: block;
}
.kg-legend .is-bridge { color: #b45309; font-weight: 600; }
.kg-legend .legend-note { margin: .45rem 0 0; color: var(--muted); }
.kg-tooltip {
  position: absolute;
  right: .85rem;
  top: .85rem;
  max-width: 280px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: .7rem .8rem;
  box-shadow: var(--e2);
  pointer-events: none;
  backdrop-filter: blur(6px);
}
.kg-tooltip h3 { margin: .25rem 0; font-size: 1rem; }
.kg-tooltip .metric { margin: .15rem 0; font-size: .8rem; }

.kg-drawer {
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--e2);
  min-height: 520px;
  max-height: min(68vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.kg-drawer-empty {
  padding: 1.4rem 1.15rem;
  display: grid;
  gap: .45rem;
  align-content: start;
}
.kg-drawer-empty h3 {
  font-family: var(--display);
  margin: 0;
  font-size: 1.2rem;
}
.kg-drawer-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.kg-drawer-head {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: flex-start;
  padding: .85rem 1rem .55rem;
  border-bottom: 1px solid var(--rule);
}
.kg-drawer-trail {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  align-items: center;
  min-width: 0;
}
.kg-drawer-crumb {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  padding: 0;
  cursor: pointer;
}
.kg-drawer-crumb:not(.is-active)::after {
  content: " ›";
  color: var(--rule-strong);
}
.kg-drawer-crumb.is-active {
  color: var(--ink);
  font-weight: 700;
  font-size: .95rem;
  cursor: default;
}
.kg-drawer-close {
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.kg-drawer-close:hover { color: var(--ink); }
.kg-drawer-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--surface-alt) 55%, var(--surface));
}
.kg-drawer-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .74rem;
  padding: .35rem .55rem;
  border-radius: 999px;
  cursor: pointer;
}
.kg-drawer-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--e1);
  font-weight: 600;
}
.kg-drawer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: .85rem 1rem 1rem;
}
.kg-drawer-foot {
  border-top: 1px solid var(--rule);
  padding: .7rem 1rem;
}
.kg-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .45rem;
  margin-bottom: .7rem;
}
.kg-epi {
  margin: 0 0 .85rem;
  padding: .65rem .7rem .55rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-alt) 70%, transparent);
}
.kg-epi-head {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem .75rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: .55rem;
}
.kg-epi .kg-eyebrow { margin: 0; }
.kg-epi .hint { margin: .15rem 0 0; }
.kg-epi .kg-stats { margin-bottom: 0; }
.kg-epi-pop select {
  max-width: 11.5rem;
  font: inherit;
  font-size: .78rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: .3rem .45rem;
}
.kg-stat {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: .45rem .55rem;
  background: var(--surface-alt);
}
.kg-stat-label {
  display: block;
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.kg-stat-value {
  font-size: .95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kg-prose {
  font-size: .82rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: .45rem 0;
}
.kg-drawer-table { width: 100%; font-size: .76rem; border-collapse: collapse; }
.kg-drawer-table th,
.kg-drawer-table td { padding: .35rem .3rem; border-bottom: 1px solid var(--rule); text-align: left; }
.kg-drawer-table th { color: var(--muted); font-weight: 600; }
.kg-drawer-link {
  border: 0;
  background: transparent;
  color: var(--accent-press);
  font: inherit;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.kg-drawer-link:hover { text-decoration: underline; }
.kg-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.kg-card {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: .55rem .65rem;
  background: var(--surface-alt);
}
.kg-card-head {
  display: flex;
  justify-content: space-between;
  gap: .4rem;
  align-items: flex-start;
  font-size: .84rem;
}
.kg-card-sub { margin: .2rem 0 0; font-size: .74rem; }
.kg-expr {
  display: grid;
  gap: .35rem;
}
.kg-expr-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: .45rem;
  align-items: center;
  font-size: .74rem;
}
.kg-expr-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.kg-expr-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.kg-expr-row.is-high .kg-expr-fill { background: var(--good); }
.kg-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: .78rem;
  display: grid;
  gap: .25rem;
}

.kg-articles {
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--e1);
  overflow: hidden;
}
.kg-articles-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: .9rem 1.05rem;
  border-bottom: 1px solid var(--rule);
}
.kg-articles-head h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: .1rem 0 .2rem;
}
.kg-articles-body { padding: 0; }
.kg-articles-body table { width: 100%; font-size: .82rem; }
.kg-articles-body th,
.kg-articles-body td { padding: .55rem .85rem; }
.kg-pager {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.kg-pager button {
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: 8px;
  padding: .25rem .55rem;
  font: inherit;
  cursor: pointer;
}
.kg-pager button:disabled { opacity: .45; cursor: not-allowed; }
.hint { margin: 0; font-size: .78rem; color: var(--muted); }
.hint .warn { color: var(--warn); }

@media (max-width: 1200px) {
  .kg-canvas-row { grid-template-columns: 1fr; }
  .kg-drawer { max-height: none; min-height: 360px; }
  .kg-explore:fullscreen .kg-canvas-row,
  .kg-explore:-webkit-full-screen .kg-canvas-row {
    overflow: auto;
  }
  .kg-explore:fullscreen .kg-stage,
  .kg-explore:-webkit-full-screen .kg-stage {
    min-height: min(70vh, 640px);
  }
}
@media (max-width: 900px) {
  /* The bar grows past a couple of rows on narrow screens; pinning it there
     would eat the viewport the graph needs. */
  .kg-filterbar { position: static; }
  .kg-menu-pop { width: min(20rem, 90vw); }
}

/* --- global search results --------------------------------------------- */
.search-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(14rem, 18rem);
  gap: var(--sp3);
  align-items: start;
}
@media (max-width: 960px) {
  .search-layout { grid-template-columns: 1fr; }
}
.search-empty { max-width: 36rem; }
.search-empty h3 { margin: 0 0 .35rem; font-size: 1rem; }

.entity-match-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: var(--sp3);
}
.entity-match-head {
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .35rem;
}
.entity-match-link {
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  padding: .35rem 0;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
}
.entity-match-link:hover { color: var(--accent); }
.entity-match-link.is-static { cursor: default; }
.entity-match-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: .1rem;
  font-size: .82rem;
}
.entity-match-text strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}
.chip-active {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}
.chip-active:hover { filter: brightness(0.97); }

.lit-list { margin: 0; }
.lit-row {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.lit-row:last-child { border-bottom: 0; }
.lit-title {
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: .3rem;
}
.lit-title a { color: var(--ink); text-decoration: none; }
.lit-title a:hover { color: var(--accent); }
.lit-title em,
.lit-snippet em {
  font-style: normal;
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 .1em;
}
[data-theme="dark"] .lit-title em,
[data-theme="dark"] .lit-snippet em {
  background: rgba(250, 204, 21, .28);
}
.lit-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .55rem;
  font-size: .76rem;
  margin-bottom: .25rem;
}
.lit-snippet {
  margin: .35rem 0 0;
  font-size: .8rem;
  line-height: 1.45;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.facet + .facet { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--rule); }
.facet-head {
  margin: 0 0 .4rem;
  font-size: .72rem;
  font-family: var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.facet-row a {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .28rem .35rem;
  margin: 0 -.35rem;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  font-size: .8rem;
}
.facet-row a:hover { background: var(--accent-soft); }
.facet-row.is-active a {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.facet-key {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.facet-count { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.facet-row.is-active .facet-count { color: var(--accent); }

.badge-lit, .badge-gene, .badge-disease, .badge-drug, .badge-trial, .badge-company {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .02em;
}
