/* Vilares / Villares family archive
   Palette: cool paper, ink navy, azulejo blue accent; status colours moss / blue / ochre / brick.
   Type: a bookish serif for people's names and headings, the system sans for the interface. */

:root {
  --paper: #F2F4F6;
  --surface: #FFFFFF;
  --sunken: #E8ECF0;
  --ink: #16202A;
  --ink-soft: #4B5967;
  --rule: #D3DAE1;
  --rule-strong: #AEB9C4;
  --accent: #1D4F91;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1EAF6;
  --moss: #3F7340;
  --ochre: #8E6511;
  --brick: #A3432F;
  --focus: #1D4F91;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121A22;
    --surface: #19232D;
    --sunken: #0E151B;
    --ink: #E6ECF2;
    --ink-soft: #A3B0BD;
    --rule: #2C3946;
    --rule-strong: #475667;
    --accent: #7FA8DE;
    --accent-ink: #0E1B2C;
    --accent-soft: #1D2E44;
    --moss: #86B87F;
    --ochre: #D7B25A;
    --brick: #E08A74;
    --focus: #9BBDE8;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 32px; letter-spacing: -0.01em; }
h2 { font-size: 21px; margin-top: 1.6em; }
h3 { font-size: 16px; margin-top: 1.2em; font-family: var(--sans); font-weight: 650; }
p { margin: 0 0 .8em; max-width: 72ch; }
code { font-size: 13px; background: var(--sunken); padding: 1px 4px; border-radius: 3px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none;
  font-family: var(--serif); font-size: 19px; font-weight: 600; }
.brand-mark { width: 26px; height: 26px; fill: var(--accent); stroke: var(--accent); stroke-width: 2.2;
  stroke-linecap: round; }
.brand-mark path { fill: none; }
.mainnav { display: flex; gap: 4px; }
.mainnav a { color: var(--ink-soft); text-decoration: none; padding: 6px 10px; border-radius: var(--radius); font-weight: 550; }
.mainnav a:hover { color: var(--ink); background: var(--sunken); }
.mainnav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.topsearch { margin-left: auto; }
.topsearch input { width: 220px; }
.signout { margin-left: 4px; }

/* ---------------------------------------------------------------- page */
.page { max-width: 1120px; margin: 0 auto; padding: 28px 24px 64px; }
.page.narrow { max-width: 560px; }
.page.form-page { max-width: 820px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin-bottom: 0; }
.count { font-family: var(--sans); font-size: 15px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; }
.crumbs { margin: 0 0 6px; font-size: 14px; }
.crumbs a::before { content: "‹ "; }
.lead { font-size: 16px; color: var(--ink-soft); }
.columns { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; }
.columns > section > h2:first-child { margin-top: .6em; }
.empty { padding: 28px; background: var(--surface); border: 1px dashed var(--rule-strong); border-radius: var(--radius); }
.empty h2 { margin-top: 0; }
.danger-zone { max-width: none; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 14px; }
.danger-zone a, .danger-text { color: var(--brick); }

/* ---------------------------------------------------------------- figures (dashboard) */
.figures { display: flex; flex-wrap: wrap; gap: 0; margin: 20px 0 8px; border: 1px solid var(--rule);
  border-radius: var(--radius); background: var(--surface); }
.figures > div { flex: 1 1 140px; padding: 14px 18px; border-right: 1px solid var(--rule); }
.figures > div:last-child { border-right: 0; }
.figures dt { color: var(--ink-soft); font-size: 13px; }
.figures dd { margin: 2px 0 0; font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.figures dd a { color: var(--ink); text-decoration: none; }
.figures dd a:hover { color: var(--accent); }
.todo { padding-left: 18px; }
.todo li { margin-bottom: 4px; }
ul.plain { list-style: none; padding: 0; margin: 0 0 1em; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--rule); }

/* ---------------------------------------------------------------- branch tree list */
.branch-tree { list-style: none; margin: 0; padding: 0; }
.branch-tree .branch-tree { margin-left: 11px; padding-left: 18px; border-left: 1px solid var(--rule-strong); }
.branch-tree li { padding: 6px 0; }
.branch-tree a { font-family: var(--serif); font-size: 16px; font-weight: 600; }
.branch-tree .muted { font-size: 13px; margin-left: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--c); margin-right: 8px; vertical-align: -1px; }
.swatch.large { width: 18px; height: 18px; border-radius: 4px; margin-right: 12px; vertical-align: 1px; }

/* ---------------------------------------------------------------- chips, status */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px 1px 7px; margin: 1px 0;
  border-radius: 999px; font-size: 12.5px; text-decoration: none; color: var(--ink);
  background: color-mix(in srgb, var(--c) 13%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.status { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: var(--radius); border: 1px solid; white-space: nowrap; }
.status-confirmado { color: var(--moss); border-color: currentColor; }
.status-provavel { color: var(--accent); border-color: currentColor; }
.status-possivel { color: var(--ochre); border-style: dashed; }
.status-contestado { color: var(--brick); border-style: dashed; }
.conf { font-size: 13px; }
.conf-alta { color: var(--moss); }
.conf-media { color: var(--ink); }
.conf-baixa { color: var(--ochre); }
.cite { font-size: 11.5px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); text-decoration: none; white-space: nowrap; }
.cite-none { background: transparent; color: var(--ink-soft); border: 1px dashed var(--rule-strong); }
.cite-none:hover { color: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- buttons */
.button {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550;
  text-decoration: none; cursor: pointer; line-height: 1.3;
}
.button:hover { border-color: var(--ink-soft); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.danger { background: var(--brick); border-color: var(--brick); color: #fff; }
.button.small { padding: 4px 10px; font-size: 13.5px; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.signout .link-button { color: var(--ink-soft); text-decoration: none; }
.signout .link-button:hover { color: var(--ink); }
form.inline { display: inline; }
.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- forms */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: var(--radius); padding: 7px 10px; width: 100%; min-height: 36px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
fieldset { border: 0; border-top: 1px solid var(--rule); margin: 0 0 18px; padding: 14px 0 0; }
legend { font-family: var(--serif); font-size: 18px; font-weight: 600; padding-right: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px 16px; margin-bottom: 16px; }
.field { grid-column: span 6; }
.field.w-half { grid-column: span 3; }
.field.w-third { grid-column: span 2; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.req { color: var(--brick); }
.help { font-size: 13px; color: var(--ink-soft); margin: 4px 0 0; }
.error-text { font-size: 13px; color: var(--brick); margin: 4px 0 0; font-weight: 550; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--brick); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; min-height: 0; }
.stack > .field { margin-bottom: 14px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--paper); border-top: 1px solid var(--rule); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.inline-form select, .inline-form input { width: auto; }
.inline-form.compact { margin: 0; }
.inline-form.compact select { min-height: 30px; padding: 3px 8px; font-size: 13.5px; }
.add-member .picker { flex: 1 1 260px; }
.inline-form .picker-input { width: 100%; }
.side .inline-form select { flex: 1 1 150px; }
.add-member label { font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 18px; }
.filters input[type=search] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }
.callout { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; }
.callout p { margin-bottom: 10px; }

/* person picker */
.picker { position: relative; }
.picker-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 2px); margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(15 25 35 / 16%); max-height: 300px; overflow: auto;
}
.picker-results li { padding: 6px 12px; cursor: pointer; }
.picker-results li[aria-selected="true"], .picker-results li:hover { background: var(--accent-soft); }
.picker-results .picker-empty { color: var(--ink-soft); cursor: default; }

/* ---------------------------------------------------------------- notices */
.flashes { max-width: 1120px; margin: 16px auto 0; padding: 0 24px; }
.flash, .notice { margin: 0 0 8px; padding: 9px 14px; border-radius: var(--radius); border-left: 4px solid var(--moss);
  background: var(--surface); max-width: none; }
.flash-warn, .notice-warn { border-left-color: var(--ochre); }
.flash-error, .notice-error { border-left-color: var(--brick); }
.impact { padding-left: 20px; }

/* ---------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th { font-size: 13px; font-weight: 600; color: var(--ink-soft); background: var(--sunken); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .row-end { text-align: right; white-space: nowrap; }
.table .muted { font-size: 13.5px; margin-top: 2px; }
.pager { display: flex; gap: 16px; align-items: center; margin-top: 14px; }
a.person { font-family: var(--serif); font-weight: 600; font-size: 1.04em; color: var(--ink); text-decoration-color: var(--rule-strong); }
a.person:hover { color: var(--accent); }
.span { color: var(--ink-soft); font-size: 13.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- person page */
.person-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: flex-start;
  padding-bottom: 18px; border-bottom: 1px solid var(--rule); }
.person-name { font-size: 40px; margin-bottom: 4px; }
.vitals { font-size: 16px; margin-bottom: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin: 0; }
.sex { font-size: 13px; color: var(--ink-soft); }
.person-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 48px; }
.family h2, .side h2 { margin-top: 1.1em; }
.family h3 { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 18px 0 6px; }
ul.kin, ul.records { list-style: none; margin: 0; padding: 0; }
ul.kin li, ul.records li { padding: 6px 0; border-bottom: 1px solid var(--rule); }
ul.kin.compact li { padding: 3px 0; }
.meta { font-size: 13px; color: var(--ink-soft); }
.row-actions { float: right; font-size: 13px; }
.row-actions a { color: var(--ink-soft); }
.row-actions a:hover { color: var(--accent); }
.row-actions .link-button { color: var(--ink-soft); font-size: 13px; }
.group-label { font-size: 13px; margin: 10px 0 2px; color: var(--ink-soft); }
.add-row { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; margin: 8px 0 0; }
.prose { max-width: 68ch; line-height: 1.6; font-family: var(--serif); font-size: 16px; }
.block { margin-top: 34px; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.block-head h2 { margin: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 12px 0 18px; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; }
.source-title { max-width: 30ch; }

/* ---------------------------------------------------------------- tree page */
.tree-body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.tree-body .flashes { position: absolute; right: 16px; top: 64px; z-index: 30; margin: 0; }
.tree-page { flex: 1; display: flex; min-height: 0; }
.tree-app { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tree-toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--rule); }
.tb-group { display: flex; align-items: center; gap: 8px; }
.tb-group label { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.tb-group select { width: auto; min-height: 32px; padding: 4px 8px; }
.tb-root .picker { width: 300px; }
.tb-root .picker-input { min-height: 32px; padding: 4px 10px; }
.seg { gap: 0; }
.seg button { font: inherit; font-size: 13.5px; padding: 5px 12px; border: 1px solid var(--rule-strong); background: var(--surface);
  color: var(--ink-soft); cursor: pointer; margin-left: -1px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; }
.tree-legend { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 24px; border-bottom: 1px solid var(--rule);
  background: var(--paper); }
.tree-legend[hidden] { display: none; }
.legend-label { font-size: 13px; color: var(--ink-soft); margin-right: 4px; }
.lchip { display: inline-flex; align-items: stretch; border-radius: 999px; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); background: color-mix(in srgb, var(--c) 12%, var(--surface)); }
.lchip button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--ink); cursor: pointer; padding: 3px 10px; }
.lchip .lname::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 7px; }
.lchip .lname[aria-pressed="true"] { background: var(--c); color: #fff; }
.lchip .lname[aria-pressed="true"]::before { background: #fff; }
.lchip .lfold { border-left: 1px solid color-mix(in srgb, var(--c) 45%, transparent); padding: 3px 9px; font-weight: 700; }
.tree-stage { position: relative; flex: 1; min-height: 0;
  background-color: var(--paper);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 11%, transparent) 1px, transparent 1.2px);
  background-size: 22px 22px; }
#tree-svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#tree-svg:active { cursor: grabbing; }
.tree-message { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--surface);
  padding: 14px 18px; border-radius: var(--radius); border: 1px solid var(--rule); max-width: 420px; text-align: center; }
.tree-hint { margin: 0; padding: 6px 24px; font-size: 12.5px; color: var(--ink-soft); background: var(--surface);
  border-top: 1px solid var(--rule); max-width: none; }

/* cards */
.link { fill: none; stroke: var(--rule-strong); stroke-width: 1.4; transition: opacity .2s; }
.link.uncertain { stroke-dasharray: 5 4; }
.link.nonbio { stroke: #7A3E6E; }
.node { cursor: pointer; transition: opacity .2s; }
.node .card { fill: var(--surface); stroke: var(--rule-strong); stroke-width: 1; }
.node:hover .card { stroke: var(--ink-soft); }
.node:focus { outline: none; }
.node:focus-visible .card, .node.selected .card { stroke: var(--accent); stroke-width: 2.2; }
.node.status-possivel .card, .node.status-contestado .card { stroke-dasharray: 5 3; }
.node.status-contestado .card { stroke: var(--brick); }
.node.dup .card { fill: var(--sunken); stroke-dasharray: 2 3; }
.node.masked .card { fill: var(--sunken); }
.node .name { font: 600 14.5px var(--serif); fill: var(--ink); }
.node.masked .name { font-style: italic; fill: var(--ink-soft); }
.node .years, .node .partner { font: 12px var(--sans); fill: var(--ink-soft); }
.node .marr { font-size: 15px; }
.node .toggle circle { fill: var(--surface); stroke: var(--rule-strong); stroke-width: 1.2; }
.node .toggle text { font: 700 11px var(--sans); fill: var(--ink); pointer-events: none; }
.node .toggle:hover circle { fill: var(--accent); stroke: var(--accent); }
.node .toggle:hover text { fill: var(--accent-ink); }
.node.dim, .link.dim { opacity: .28; }
.node.lit .card { stroke-width: 1.8; }

/* side panel */
.tree-panel { position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(360px, calc(100% - 24px)); overflow: auto;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 20px 20px;
  box-shadow: 0 12px 32px rgb(15 25 35 / 18%); }
.tree-panel[hidden] { display: none; }
.tree-panel h2 { margin: 0 28px 2px 0; font-size: 22px; }
.tree-panel h3 { font-size: 13px; color: var(--ink-soft); margin: 14px 0 4px; }
.tree-panel ul { margin: 0; padding-left: 18px; }
.tree-panel li { margin-bottom: 3px; }
.panel-sub { color: var(--ink-soft); }
.panel-bio { font-family: var(--serif); line-height: 1.55; }
.panel-branches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.panel-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 24px; line-height: 1;
  color: var(--ink-soft); cursor: pointer; padding: 4px 8px; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 820px) {
  .columns, .person-grid { grid-template-columns: 1fr; gap: 8px; }
  .topbar { padding: 10px 16px; gap: 10px 14px; }
  .topsearch { margin-left: 0; flex: 1 1 100%; order: 5; }
  .topsearch input { width: 100%; }
  .page { padding: 20px 16px 48px; }
  .person-name { font-size: 32px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field, .field.w-half { grid-column: span 2; }
  .field.w-third { grid-column: span 1; }
  .table { display: block; overflow-x: auto; }
  .tree-toolbar, .tree-legend { padding: 8px 16px; }
  .tb-root { flex: 1 1 100%; min-width: 0; }
  .tb-root .picker { flex: 1; width: auto; min-width: 0; }
  .tree-hint { display: none; }
  .tree-body .topsearch, .tree-body .signout { display: none; }
  .tree-toolbar { gap: 8px 12px; }
  .tree-toolbar .tb-group:last-child { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .tree-toolbar .button.small { white-space: nowrap; padding: 4px 8px; font-size: 13px; }
  .tree-legend { flex-wrap: nowrap; overflow-x: auto; }
  .lchip { flex: none; }
  .figures > div { border-right: 0; border-bottom: 1px solid var(--rule); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
fieldset > .help { margin: -2px 0 12px; }

/* account link in the top bar */
.topbar .whoami { color: var(--ink-soft); font-size: 14px; text-decoration: none; margin-left: auto; padding: 0 4px; }
.topbar .whoami:hover { text-decoration: underline; }
.topsearch + .whoami { margin-left: 0; }
