:root {
  --bg: #f6f3ee; --panel: #ffffff; --ink: #1f2328; --muted: #5f6670; --line: #e3ddd3;
  --brand: #4a3728; --brand-ink: #ffffff; --accent: #8a5a2b; --focus: #1b6ac9;
  --ok: #1d6b3a; --ok-bg: #e3f3e8; --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #a12a2a; --bad-bg: #fbe5e3;
  --neutral-bg: #eceae6; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.app { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.app.public { grid-template-columns: 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: var(--brand); color: var(--brand-ink); }
.brand { color: var(--brand-ink); font-weight: 700; font-size: 1.15rem; text-decoration: none; letter-spacing: .02em; }
.topbar-user { margin-left: auto; font-size: .9rem; opacity: .9; }
.menu-toggle { background: transparent; border: 0; color: inherit; font-size: 1.4rem; padding: 4px 8px; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar a { display: block; padding: 10px 14px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--brand); color: var(--brand-ink); }
.sidebar .sep { border-top: 1px solid var(--line); margin: 8px 6px; }
.main { padding: 24px clamp(14px, 3vw, 36px); max-width: 1200px; width: 100%; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { font-size: 2rem; font-weight: 700; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
button, .button { font: inherit; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: 9px 16px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .button.secondary { background: #fff; color: var(--brand); }
button.danger { background: var(--bad); border-color: var(--bad); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; text-decoration: underline; }
button:disabled { opacity: .55; cursor: not-allowed; }
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: .95rem; }
.help { font-weight: 400; color: var(--muted); font-size: .85rem; margin: 2px 0 0; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid #c9c1b4; border-radius: 8px; background: #fff; color: var(--ink); }
textarea { min-height: 110px; resize: vertical; }
input[type=checkbox] { width: auto; margin-right: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); column-gap: 16px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 8px; margin-top: 10px; }
.notice { background: var(--warn-bg); color: #5a3d00; border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.info { background: #e8f0fb; color: #1d3c66; border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--neutral-bg); color: var(--ink); white-space: nowrap; }
.badge.source_backed { background: var(--ok-bg); color: var(--ok); }
.badge.indication { background: var(--warn-bg); color: var(--warn); }
.badge.refuted { background: var(--bad-bg); color: var(--bad); text-decoration: line-through; }
.badge.sensitive { background: #efe3f7; color: #5b2a7a; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); padding: 12px 2px; }
.list > li:last-child { border-bottom: 0; }
.person-link { font-weight: 600; text-decoration: none; color: var(--ink); }
.person-link:hover { text-decoration: underline; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0; overflow-x: auto; }
.tabs button { background: none; color: var(--ink); border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 10px 14px; white-space: nowrap; }
.tabs button[aria-selected=true] { border-bottom-color: var(--brand); font-weight: 700; }
.claim { border-left: 4px solid var(--line); padding: 8px 12px; margin: 10px 0; background: #fff; }
.claim.source_backed { border-left-color: var(--ok); }
.claim.indication { border-left-color: #d9a400; }
.claim.refuted { border-left-color: var(--bad); opacity: .75; }
.citation { font-size: .875rem; color: var(--muted); margin: 4px 0 0 0; padding-left: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.bad { background: var(--bad); }
.dialog { border: 0; border-radius: var(--radius); padding: 22px; width: min(680px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(20,15,10,.45); }
.auth-box { max-width: 440px; margin: 6vh auto; }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, monospace; font-size: .85rem; }
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl-item { position: relative; margin: 0 0 14px; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.tl-item.context::before { background: #9aa0a6; }
.tl-item.context { color: var(--muted); font-style: italic; }
.tl-date { font-weight: 700; font-variant-numeric: tabular-nums; }
.tree-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.tree-node rect { fill: #fff; stroke: #b9ab97; stroke-width: 1.5; }
.tree-node.root rect { stroke: var(--brand); stroke-width: 3; }
.tree-node.m rect { fill: #eef4fb; }
.tree-node.w rect { fill: #fbf0f3; }
.tree-node text { font-size: 13px; fill: var(--ink); }
.tree-node text.sub { font-size: 11px; fill: var(--muted); }
.tree-node { cursor: pointer; }
.tree-edge { stroke: #8f8273; stroke-width: 1.5; fill: none; }
.tree-edge.spouse { stroke-dasharray: 5 4; }
.tree-edge.unverified, .tree-edge.indication { stroke-dasharray: 2 3; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; padding: 8px 0 8px 40px; position: relative; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; text-align: center; line-height: 28px; font-weight: 700; }
.pre { white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: .85rem; background: #faf8f4; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 420px; overflow: auto; }
.hidden { display: none !important; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-block; }
  .sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 260px; z-index: 40; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { padding: 18px 14px; }
  h1 { font-size: 1.35rem; }
}
@media print {
  .topbar, .sidebar, .no-print, .tabs { display: none !important; }
  .app { display: block; }
  .card { box-shadow: none; border: 0; }
}
@media (min-width: 861px) { .menu-toggle { display: none; } }
.row > select, .row > input[type=search], .row > input:not([type=checkbox]) { flex: 1 1 200px; width: auto; }
.row > label { margin: 0; }
.app > * { min-width: 0; }
td, th { overflow-wrap: anywhere; }
@media (max-width: 860px) { .topbar-user { font-size: .8rem; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
.doc-image { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 10px; }
blockquote.citation { margin: 4px 0; font-style: italic; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; }
fieldset label { font-weight: 400; margin: 4px 0; }
details > summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
select[multiple] { min-height: 90px; }
.tl-item.place::before { background: #4a7bb7; }
