/* Neuro-Link design system — shared by the public site and the research portal.
   Tokens first; components below. Light palette on :root, dark palette via prefers-color-scheme. */

:root {
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --font-serif: "Source Serif Pro", Georgia, "Times New Roman", serif;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --surface-3: #e6ebf4;
  --border: #d9e0ec;
  --border-strong: #b8c3d6;
  --text: #16213a;
  --text-2: #3b4863;
  --muted: #66728a;
  --primary: #1f3a8a;
  --primary-hover: #182f73;
  --primary-soft: #e3e9fb;
  --primary-contrast: #ffffff;
  --accent: #0f9b8e;
  --accent-strong: #0b7a70;   /* filled accent surfaces (buttons): white text ≥ 4.5:1 */
  --accent-contrast: #ffffff;
  --accent-soft: #dcf4f1;
  --navy: #13254f;

  --good: #177245;  --good-soft: #dcf3e6;
  --warn: #9a5b00;  --warn-soft: #fdf0d6;
  --bad:  #b42318;  --bad-soft:  #fde4e1;
  --info: #1d5fbf;  --info-soft: #e1ecfb;
  --neutral: #5b6477; --neutral-soft: #eceff4;

  --chart-grid: #e4e9f2;
  --chart-axis: #8a94a6;
  --chart-1: #2f6fdf; --chart-2: #e07b1a; --chart-3: #0f9b8e; --chart-4: #d64545;
  --chart-5: #7c5cd6; --chart-6: #3d9a3a; --chart-7: #d6479b; --chart-8: #c9a227;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --sidebar-w: 256px;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1322;
    --surface: #141c2f;
    --surface-2: #1a2438;
    --surface-3: #223049;
    --border: #2a3753;
    --border-strong: #3a4a6b;
    --text: #e6ebf5;
    --text-2: #c3cbdc;
    --muted: #8d98ae;
    --primary: #7c9cff;
    --primary-hover: #97b0ff;
    --primary-soft: #1f2c52;
    --primary-contrast: #0d1322;
    --accent: #39c6b6;
    --accent-strong: #39c6b6;
    --accent-contrast: #0d1322;   /* dark ink on the light dark-mode accent (≈ 8.8:1) */
    --accent-soft: #123a38;
    --navy: #0a1430;
    --good: #4cc38a;  --good-soft: #12321f;
    --warn: #f0b64a;  --warn-soft: #3a2a0c;
    --bad:  #ff7b6e;  --bad-soft:  #3d1613;
    --info: #74a7ff;  --info-soft: #14284a;
    --neutral: #9aa4b8; --neutral-soft: #222c40;
    --chart-grid: #26324a;
    --chart-axis: #7c879d;
    --chart-1: #6b9bff; --chart-2: #f39a45; --chart-3: #39c6b6; --chart-4: #ff7b7b;
    --chart-5: #a78bfa; --chart-6: #6cc36a; --chart-7: #f06bb7; --chart-8: #e2c04f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* ── Base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: 15px; line-height: 1.55;
  color: var(--text); background: var(--bg);
}
img, svg { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 1.85rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 650; }
h3 { font-size: 1.1rem; font-weight: 650; }
h4 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 1em; }
small, .small { font-size: .85em; }
code, kbd, pre, .mono { font-family: var(--font-mono); font-size: .9em; }
/* Wordmarks CogniMune and PhenArI (brand() / company() in neurolink/__init__.py): italic, regular weight with two bold
   capitals wherever they appear, also in bold headings and upper-case eyebrows. */
.wm { font-style: italic; font-weight: 400; text-transform: none; padding-right: .06em; }   /* italic correction */
.wm b { font-weight: 800; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
pre { background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
           clip-path: inset(50%); white-space: nowrap; border: 0; }
/* Skip link: visually hidden until focused (keyboard users jump past the navigation). */
.skip-link { position: absolute; left: 12px; top: -100px; z-index: 100; padding: 8px 14px; border-radius: var(--radius-sm);
             background: var(--primary); color: var(--primary-contrast); font-weight: 650; box-shadow: var(--shadow-lg); }
.skip-link:focus { top: calc(env(safe-area-inset-top, 0px) + 8px); text-decoration: none; }
.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -.18em; stroke: currentColor; fill: none;
        stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
main[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }

/* ── Layout helpers ───────────────────────────────────────────────────── */
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding-inline: 20px; }
.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 28px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}
@media (max-width: 560px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; font-weight: 550;
  line-height: 1.2; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-accent { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
.btn-accent:hover { background: color-mix(in srgb, var(--accent-strong) 88%, var(--text)); border-color: color-mix(in srgb, var(--accent-strong) 88%, var(--text)); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-lg { padding: 12px 20px; font-size: 1rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
            border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        box-shadow: var(--shadow-sm); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
               padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; }
.card-header .sub { color: var(--muted); font-size: .85rem; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
               border-radius: 0 0 var(--radius) var(--radius); }
.card.highlight { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }

/* ── Stat tiles ───────────────────────────────────────────────────────── */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 14px 16px; box-shadow: var(--shadow-sm); min-width: 0; display: block; color: inherit; }
a.stat:hover { border-color: var(--border-strong); text-decoration: none; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.stat .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.stat.tone-good .value { color: var(--good); }
.stat.tone-warn .value { color: var(--warn); }
.stat.tone-bad .value { color: var(--bad); }

/* ── Badges & pills ───────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
         font-size: .76rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
         background: var(--neutral-soft); color: var(--neutral); }
.badge.tone-good { background: var(--good-soft); color: var(--good); }
.badge.tone-warn { background: var(--warn-soft); color: var(--warn); }
.badge.tone-bad { background: var(--bad-soft); color: var(--bad); }
.badge.tone-info { background: var(--info-soft); color: var(--info); }
.badge.tone-muted { background: var(--neutral-soft); color: var(--neutral); }
.badge .dot, .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .8rem;
        font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: 0; margin-right: 6px; }

/* ── Alerts ───────────────────────────────────────────────────────────── */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm);
         border: 1px solid transparent; background: var(--info-soft); color: var(--text); margin-bottom: 16px; }
.alert .icon { margin-top: 3px; }
.alert-success { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.alert-success .icon { color: var(--good); }
.alert-warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-warning .icon { color: var(--warn); }
.alert-danger, .alert-error { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-danger .icon, .alert-error .icon { color: var(--bad); }
.alert-info .icon { color: var(--info); }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 0 4px; font-size: 1.1rem; }
.flash-stack { margin-bottom: 8px; }

/* ── Tables ───────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; position: relative; /* containing block for .sr-only etc. → clipped, no page scroll */ }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .76rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
            background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table tbody tr:hover { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
.table td.num, .table th.num { text-align: right; }
.table.compact th, .table.compact td { padding: 6px 10px; }
.table tr.row-muted td { color: var(--muted); }
.table tr.row-bad td { background: color-mix(in srgb, var(--bad-soft) 60%, transparent); }
.table tr.row-good td { background: color-mix(in srgb, var(--good-soft) 50%, transparent); }
/* Wrap-friendly headers for wide numeric tables: <table class="table wrap-head"> */
.table.wrap-head th, .table th.wrap { white-space: normal; }
.table th.sortable { cursor: pointer; user-select: none; }
/* Sort cue: non-breaking space keeps the arrow attached to the last word; empty alt text (after "/") hides it from
   screen readers, which get aria-sort instead (set by app.js). */
.table th.sortable::after { content: "\00a0↕"; content: "\00a0↕" / ""; opacity: .35; }
.table th.sort-asc::after { content: "\00a0↑"; content: "\00a0↑" / ""; opacity: .9; }
.table th.sort-desc::after { content: "\00a0↓"; content: "\00a0↓" / ""; opacity: .9; }
.table th.sortable:focus-visible { outline-offset: -2px; }
.card .table th:first-child, .card .table td:first-child { padding-left: 18px; }
.card .table th:last-child, .card .table td:last-child { padding-right: 18px; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: .85rem; font-weight: 600; color: var(--text-2); }
.field .req { color: var(--bad); }
.field .help { font-size: .8rem; color: var(--muted); }
.field .error { font-size: .8rem; color: var(--bad); font-weight: 550; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=search],
input[type=file], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: .92rem; line-height: 1.35;
}
input[type=file] { padding: 6px; background: var(--surface-2); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { min-width: 150px; }
.toolbar .field.grow { flex: 1; min-width: 200px; }

/* ── Page header / breadcrumbs ────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 1.55rem; }
.page-header .subtitle { color: var(--muted); margin: 4px 0 0; max-width: 72ch; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* One line, never wraps: earlier crumbs shrink (ellipsis) before the current one does. */
.breadcrumbs { display: flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); flex-wrap: nowrap;
               white-space: nowrap; overflow: hidden; min-width: 0; }
.breadcrumbs > * { flex: 0 1 auto; min-width: 1.5em; overflow: hidden; text-overflow: ellipsis; }
.breadcrumbs > :last-child { flex-shrink: 0; max-width: 75%; }
.breadcrumbs > .sep { flex: none; overflow: visible; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs .sep { opacity: .5; }

/* ── Tabs ─────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button { padding: 9px 14px; border: 0; background: none; font: inherit; font-size: .9rem; font-weight: 550;
                         color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs .active, .tabs [aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Progress ─────────────────────────────────────────────────────────── */
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.progress.tone-good > span { background: var(--good); }
.progress.tone-warn > span { background: var(--warn); }
.progress.tone-bad > span { background: var(--bad); }

/* ── Empty states / key-value / description lists ─────────────────────── */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 18px; margin: 0; font-size: .92rem; }
.kv dt { color: var(--muted); font-weight: 550; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ── Pagination ───────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: flex-end; padding: 12px 18px; flex-wrap: wrap; font-size: .88rem; }
.pagination a, .pagination span { padding: 4px 10px; border-radius: var(--radius-sm); border: 1px solid transparent; color: var(--text-2); }
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination .current { border-color: var(--border-strong); background: var(--surface); font-weight: 650; color: var(--text); }
.pagination .info { margin-right: auto; color: var(--muted); border: 0; }

/* ── Charts ───────────────────────────────────────────────────────────── */
.chart { position: relative; width: 100%; min-height: 120px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font-sans); }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .axis path, .chart .axis line { stroke: var(--chart-axis); }
.chart .grid line { stroke: var(--chart-grid); }
.chart .grid path { display: none; }
.chart .axis-label { fill: var(--text-2); font-size: 12px; font-weight: 600; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--text-2); margin-top: 8px; }
.chart-legend .item { display: inline-flex; align-items: center; gap: 6px; cursor: default; }
.chart-legend .item.off { opacity: .4; }
.chart-legend .key { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.chart-empty { display: flex; align-items: center; justify-content: center; min-height: 160px; color: var(--muted); font-size: .9rem;
               border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.nl-tooltip { position: fixed; z-index: 1000; pointer-events: none; background: var(--navy); color: #fff; padding: 8px 10px;
              border-radius: 6px; font-size: 12px; line-height: 1.4; box-shadow: var(--shadow-lg); max-width: 320px; opacity: 0;
              transition: opacity .08s; }
.nl-tooltip.show { opacity: 1; }
.nl-tooltip b { font-weight: 650; }
.nl-tooltip .t-muted { opacity: .75; }
.loading { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.loading::before { content: ""; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--primary);
                   border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Portal shell ─────────────────────────────────────────────────────── */
.portal-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex: none; background: var(--navy); color: #c9d3ea; display: flex; flex-direction: column;
           position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 30; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; color: #fff; font-weight: 700; font-size: 1.05rem;
                  border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand small { display: block; font-weight: 500; font-size: .72rem; color: #93a3c6; letter-spacing: .02em; }
.sidebar nav { padding: 8px 10px 16px; flex: 1; }
.nav-heading { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #7f8fb4; padding: 14px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: #c9d3ea; font-size: .88rem; font-weight: 500; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(124,156,255,.18); color: #fff; }
.nav-link.active .icon { color: #9fb6ff; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; }
.sidebar-foot a { color: #aab7d6; display: inline-flex; gap: 8px; align-items: center; }
.portal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--surface);
          border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-title { flex: 1; min-width: 0; }
.sidebar-toggle { display: none; }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.user-menu .who { text-align: right; line-height: 1.2; }
.user-menu .who small { display: block; color: var(--muted); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-flex;
          align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.portal-content { padding: 24px; width: 100%; max-width: 1480px; flex: 1; }
.portal-footer { padding: 12px 24px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: .78rem; line-height: 1.45; }
.portal-footer .icon { margin-right: 4px; }
.portal-footer strong { color: var(--text-2); font-weight: 650; }
.sidebar-backdrop { display: none; }
@media (max-width: 980px) {
  /* Off-canvas drawer: hidden (not just translated) while closed so its links leave the tab order and the a11y tree;
     visibility flips after the slide-out transition. */
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); visibility: hidden;
             transition: transform .2s, visibility 0s linear .2s; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: none; visibility: visible; transition: transform .2s, visibility 0s; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .sidebar-toggle { display: inline-flex; }
  .portal-content { padding: 16px; }
  .portal-footer { padding: 12px 16px 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .user-menu { gap: 6px; }
  .user-menu .who { display: none; }
  /* Breadcrumb: parent + current only. */
  .topbar .breadcrumbs > :nth-last-child(n+4) { display: none; }
  /* Demo-data pill collapses to its icon (text stays available to screen readers; title explains on hover). */
  .topbar .pill-warn { padding: 6px; }
  .topbar .pill-warn .pill-text { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden;
                                  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
}
.topbar .pill { flex: none; }

/* ── Public site ──────────────────────────────────────────────────────── */
.site-header { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--surface) 92%, transparent);
               backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); }
.site-header .container { display: flex; align-items: center; gap: 20px; height: 64px; }
.site-brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.1rem; color: var(--text); }
.site-brand:hover { text-decoration: none; }
.site-brand small { font-weight: 500; color: var(--muted); font-size: .75rem; display: block; line-height: 1.1; }
.site-nav { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.site-nav a { padding: 8px 11px; border-radius: 7px; color: var(--text-2); font-weight: 550; font-size: .92rem; }
.site-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.site-nav a.active { color: var(--primary); background: var(--primary-soft); }
.site-nav .btn { margin-left: 8px; }
.site-nav a.btn-primary, .site-nav a.btn-primary:hover { color: var(--primary-contrast); background: var(--primary); }
.site-nav a.btn-primary:hover { background: var(--primary-hover); }
.site-nav-toggle { display: none; margin-left: auto; }
@media (max-width: 920px) {
  .site-nav-toggle { display: inline-flex; flex: none; }
  .site-nav { display: none; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column; align-items: stretch;
              background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 20px 16px; box-shadow: var(--shadow); }
  body.nav-open .site-nav { display: flex; }
  .site-nav .btn { margin: 8px 0 0; }
}
.hero { background: radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
                    linear-gradient(160deg, var(--navy) 0%, #1f3a8a 55%, #22407e 100%);
        color: #e8eefc; padding: 72px 0 80px; }
.hero h1 { color: #fff; font-size: clamp(2rem, 4.2vw, 3.1rem); letter-spacing: -.02em; max-width: 20ch; }
.hero p.lead { font-size: 1.15rem; color: #cbd6f2; max-width: 62ch; }
.hero .eyebrow { color: #8fe3d8; }
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: .78rem; font-weight: 700; color: var(--accent); margin-bottom: 10px; display: block; }
.section { padding: 64px 0; }
.section.alt { background: var(--surface); border-block: 1px solid var(--border); }
.section-head { max-width: 760px; margin-bottom: 32px; }
.section-head p { color: var(--text-2); font-size: 1.05rem; }
.lead { font-size: 1.1rem; color: var(--text-2); }
.prose { max-width: 76ch; }
.prose p, .prose li { color: var(--text-2); }
.prose h2 { margin-top: 1.6em; }
.prose h3 { margin-top: 1.3em; }
.feature { padding: 22px; }
.feature .ficon { width: 42px; height: 42px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
                  background: var(--primary-soft); color: var(--primary); margin-bottom: 12px; }
.feature .ficon .icon { width: 22px; height: 22px; }
.figure { margin: 0; }
.figure figcaption { color: var(--muted); font-size: .85rem; margin-top: 8px; }
.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 14px 18px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.math { font-family: var(--font-serif); font-size: 1.05rem; overflow-x: auto; padding: 8px 0; }
math { font-size: 1.08em; }
math[display="block"] { margin: 12px 0; overflow-x: auto; overflow-y: hidden; }
.timeline { position: relative; display: grid; gap: 14px; }
.site-footer { background: var(--navy); color: #aab7d6; padding: 40px 0 28px; margin-top: 0; font-size: .88rem; }
.site-footer a { color: #d7e0f5; }
.site-footer .cols { display: grid; gap: 24px; grid-template-columns: 2fr 1fr 1fr; }
.site-footer h4 { color: #fff; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.site-footer .legal { border-top: 1px solid rgba(255,255,255,.1); margin-top: 28px; padding-top: 16px; font-size: .8rem; color: #8392b8; }
@media (max-width: 760px) { .site-footer .cols { grid-template-columns: 1fr; } .section { padding: 44px 0; } .hero { padding: 48px 0 56px; } }

/* ── Auth ─────────────────────────────────────────────────────────────── */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px;
              background: linear-gradient(160deg, var(--navy), #1f3a8a); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px; }
.auth-card .brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.2rem; margin-bottom: 20px; color: var(--text); }
.auth-card .fine { font-size: .8rem; color: var(--muted); margin-top: 18px; }

/* ── Error pages ──────────────────────────────────────────────────────── */
.error-page { min-height: 70vh; display: grid; place-items: center; text-align: center; padding: 40px 20px; }
.error-page .code { font-size: 4rem; font-weight: 800; color: var(--primary); line-height: 1; }

/* ── Print ────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .site-header, .skip-link, .sidebar-backdrop, .no-print { display: none !important; }
  /* Keep the research-use / FDA disclaimer on printed pages; drop the footer navigation. */
  .site-footer { background: none !important; color: #000; padding: 12px 0 0; border-top: 1px solid #999; }
  .site-footer .cols { display: none !important; }
  .site-footer .legal { color: #000; border: 0; margin: 0; padding: 0; font-size: 9pt; }
  .portal-footer { color: #000; border-top: 1px solid #999; padding: 8px 0 0; }
  .portal-content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
