:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --danger: #b23b31;
  --danger-soft: #f8e4e1;
  --male: #3c6ea8;
  --female: #b5517a;
  --other: #7a6aa8;
  --multi: #c08a1e;
  --multi-soft: #fbf1dc;
  --band-a: #eef2f7;
  --band-b: #f6f8fb;
  --card: #ffffff;
  --card-in: #f8fafc;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
  --radius: 10px;
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: light;
}
/* Dark theme: follows the device unless the person picks bright/dark with the toggle (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0f172a; --surface: #1e293b; --surface-2: #273449; --ink: #f1f5f9; --ink-2: #cbd5e1; --ink-3: #94a3b8;
    --line: #334155; --line-2: #475569; --accent: #6fbf95; --accent-ink: #10221a; --accent-soft: #233a2e;
    --danger: #e0786d; --danger-soft: #3d2420; --male: #7aa8dc; --female: #e08aae; --other: #b2a4de;
    --multi: #e3b04f; --multi-soft: #3a3020; --band-a: #172033; --band-b: #131c2e; --card: #1e293b; --card-in: #1b2537;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
    --bg: #0f172a; --surface: #1e293b; --surface-2: #273449; --ink: #f1f5f9; --ink-2: #cbd5e1; --ink-3: #94a3b8;
    --line: #334155; --line-2: #475569; --accent: #6fbf95; --accent-ink: #10221a; --accent-soft: #233a2e;
    --danger: #e0786d; --danger-soft: #3d2420; --male: #7aa8dc; --female: #e08aae; --other: #b2a4de;
    --multi: #e3b04f; --multi-soft: #3a3020; --band-a: #172033; --band-b: #131c2e; --card: #1e293b; --card-in: #1b2537;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--sans); font-weight: 700; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font: inherit; font-size: .9rem; cursor: pointer; border-radius: 8px; padding: .45rem .85rem;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--ink-3); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--surface); }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.small, .btn.small { padding: .2rem .55rem; font-size: .8rem; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 8px; padding: .45rem .6rem; width: 100%; min-width: 0;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--ink-2); margin-bottom: .2rem; font-weight: 500; }
.field { margin-bottom: .8rem; }
.field .help { font-size: .78rem; color: var(--ink-3); margin-top: .2rem; }
.check { display: flex; gap: .5rem; align-items: center; }
.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-family: var(--sans); font-weight: 600; font-size: 1rem; margin: .6rem 0 .5rem; padding-top: .6rem; border-top: 1px solid var(--line); color: var(--ink); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: .55rem .75rem; border-radius: 8px; margin-bottom: .8rem; font-size: .9rem; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; position: relative; z-index: 5;
}
.brand { font-family: var(--sans); font-weight: 700; font-size: 1.15rem; display: flex; align-items: center; gap: .5rem; color: var(--ink); text-decoration: none; }
.brand svg { color: var(--accent); }
.topbar .spacer { flex: 1; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; letter-spacing: .02em; padding: .1rem .5rem;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}
.badge.gray { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.multi { background: var(--multi-soft); color: var(--multi); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.tree-id { font-family: var(--mono); font-weight: 600; font-size: .85rem; background: var(--surface-2); border: 1px solid var(--line); padding: .1rem .45rem; border-radius: 6px; }

/* ---------- pages ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tree-card { display: flex; flex-direction: column; gap: .4rem; }
.tree-card .meta { font-size: .85rem; color: var(--ink-2); }
.tree-card .actions { margin-top: auto; padding-top: .5rem; display: flex; gap: .5rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th, table.list td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-weight: 600; color: var(--ink-2); font-size: .8rem; }
.table-wrap { overflow-x: auto; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; font-size: 1.5rem; margin-bottom: .3rem; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px; max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal header { padding: 1rem 1.2rem .4rem; display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: .6rem 1.2rem; overflow-y: auto; }
.modal footer { padding: .8rem 1.2rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; }

.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; z-index: 60; font-size: .9rem; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- tree page ---------- */
body.tree-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.tree-title { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.tree-title h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.from-banner { background: var(--accent-soft); color: var(--ink); font-size: .85rem; padding: .35rem 1rem; border-bottom: 1px solid var(--line); }
.branch-banner { background: var(--surface-2); display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.member-search { margin-bottom: 1.5rem; }
.member-search form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.member-search input { width: 180px; }
.member-search .results { margin-top: .8rem; display: flex; flex-direction: column; gap: .4rem; }
.member-search .hit { display: flex; align-items: center; gap: .7rem; padding: .5rem .7rem; flex-wrap: wrap; }
.member-search .hit .who { flex: 1; min-width: 180px; }
.member-search .hit img, .member-search .hit .ph { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; }
.member-search .hit .ph { background: var(--surface-2); display: grid; place-items: center; font-weight: 700; color: var(--ink-2); }
.searchbar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.searchbar input { width: 150px; padding: .35rem .55rem; font-size: .88rem; }
.searchbar input[type=date] { width: 145px; }
.search-results { position: absolute; top: 100%; right: 1rem; width: 340px; max-width: calc(100vw - 2rem); max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 20; }
.search-results .item { display: flex; gap: .6rem; align-items: center; padding: .5rem .7rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results .item:hover { background: var(--surface-2); }
.search-results .empty { padding: .8rem; color: var(--ink-3); font-size: .9rem; }

.workspace { flex: 1; position: relative; min-height: 0; display: flex; }
#canvas { flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none; }
#canvas.dragging { cursor: grabbing; }
#canvas svg { width: 100%; height: 100%; display: block; user-select: none; }
.zoom-ctrl { position: absolute; left: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .3rem; z-index: 4; }
.zoom-ctrl button { width: 36px; height: 36px; justify-content: center; padding: 0; box-shadow: var(--shadow); }
.legend { position: absolute; right: 1rem; bottom: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; font-size: .78rem; color: var(--ink-2); display: flex; gap: .8rem; flex-wrap: wrap; box-shadow: var(--shadow); z-index: 4; max-width: calc(100% - 6rem); }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.empty-tree { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--ink-2); padding: 1rem; }

#genLabels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.gen-label { position: absolute; left: 10px; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: .2rem .55rem; line-height: 1.25; box-shadow: var(--shadow); }
.gen-label b { display: block; font: 700 10px var(--sans); letter-spacing: .12em; color: var(--ink-3); }
.gen-label span { font: italic 13px var(--serif); color: var(--ink); }

/* svg */
.band-a { fill: var(--band-a); } .band-b { fill: var(--band-b); }
.band-label { font: 700 11px var(--sans); letter-spacing: .12em; fill: var(--ink-3); }
.band-sub { font: italic 13px var(--serif); fill: var(--ink-2); }
.edge { fill: none; stroke: var(--line-2); stroke-width: 1.6; }
.edge.marriage { stroke: var(--ink-3); stroke-width: 2; }
.edge.marriage.ended { stroke-dasharray: 5 4; }
.edge.cross { stroke-dasharray: 3 4; stroke: var(--ink-3); }
.edge.multi { stroke: var(--multi); stroke-width: 2; }
.edge.adopted { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; }
.multi-box { fill: var(--multi-soft); stroke: var(--multi); stroke-width: 1.5; stroke-dasharray: 6 4; }
.multi-pill { fill: var(--multi); }
.multi-pill-text { font: 700 11px var(--sans); fill: #fff; letter-spacing: .04em; }
.ring { fill: var(--surface); stroke: var(--ink-3); stroke-width: 1.5; }
.node { cursor: pointer; }
.node .box { fill: var(--card); stroke: var(--line-2); stroke-width: 1; filter: drop-shadow(0 1px 2px rgba(40,35,20,.12)); }
.node.married-in .box { fill: var(--card-in); stroke-dasharray: 4 3; }
.node.co-parent .box { stroke-dasharray: 1 4; stroke-linecap: round; }
.node.deceased .box { fill: var(--surface-2); }
.node:hover .box { stroke: var(--accent); }
.node.selected .box { stroke: var(--accent); stroke-width: 2.5; }
.node.hl .box { stroke: var(--multi); stroke-width: 3; }
.node .strip { }
.node .name { font: 600 13px var(--sans); fill: var(--ink); }
.node .no { font: 600 11px var(--mono); fill: var(--accent); }
.node .years { font: 12px var(--sans); fill: var(--ink-2); }
.node .initials { font: 700 15px var(--sans); fill: #fff; }
.node .cross-badge { fill: var(--ink); }
.node .cross-mark { font: 700 17px var(--serif); fill: #fff; }
.male-fill { fill: var(--male); } .female-fill { fill: var(--female); } .other-fill { fill: var(--other); }

/* ---------- side panel ---------- */
.panel { width: 440px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
@media (max-width: 900px) { .panel { position: absolute; inset: 0 0 0 auto; width: min(440px, 100%); z-index: 10; box-shadow: var(--shadow); } }
.panel-head { padding: 1rem 1rem .6rem; display: flex; gap: .9rem; align-items: flex-start; border-bottom: 1px solid var(--line); }
.panel-head .avatar { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface-2); display: grid; place-items: center; font: 700 1.6rem var(--sans); color: #fff; }
.panel-head h2 { margin: 0 0 .2rem; font-size: 1.2rem; }
.panel-head .sub { font-size: .85rem; color: var(--ink-2); }
.panel-head .badges { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .35rem; }
.panel-head .gen-counts { margin-top: .45rem; font-size: .82rem; color: var(--ink-2); }
.panel-head .gen-counts ul { list-style: none; margin: 0 0 .2rem; padding: 0; }
.panel-head .gen-counts li { display: flex; gap: .4rem; align-items: baseline; }
.panel-head .gen-counts li strong { color: var(--ink); margin-left: auto; }
.panel-head .gen-counts li .muted { margin-left: 0; }
.tabs { display: flex; gap: .1rem; padding: 0 .6rem; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.tabs button { border: 0; border-radius: 0; background: transparent; padding: .6rem .6rem; color: var(--ink-2); border-bottom: 2px solid transparent; font-size: .85rem; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.panel-body { padding: 1rem; overflow-y: auto; flex: 1; }
.panel-actions { display: flex; gap: .4rem; flex-wrap: wrap; padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2); }
dl.details { display: grid; grid-template-columns: 140px 1fr; gap: .45rem .8rem; margin: 0; font-size: .9rem; }
dl.details dt { color: var(--ink-3); }
dl.details dd { margin: 0; word-break: break-word; }
.section-title { font-family: var(--sans); font-weight: 600; font-size: 1rem; margin: 1.2rem 0 .5rem; display: flex; align-items: center; gap: .5rem; }
.section-title:first-child { margin-top: 0; }
.section-title .spacer { flex: 1; }
.linklike { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; background: none; border: 0; padding: 0; font: inherit; }
.photo-current { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.photo-grid figure { margin: 0; font-size: .72rem; color: var(--ink-3); }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li { padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.item-list li:last-child { border-bottom: 0; }
.item-list .head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.item-list .head .spacer { flex: 1; }
.fact-date { font-size: .78rem; color: var(--ink-3); }
.doc-status { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; font-size: .85rem; margin-top: 1rem; }
.doc-status span::before { content: '○ '; color: var(--ink-3); }
.doc-status span.ok::before { content: '● '; color: var(--accent); }
/* ---------- dashboard ---------- */
.dash { max-width: 1200px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat-label { font-size: .78rem; color: var(--ink-3); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.stat-value { font: 700 1.8rem/1.2 var(--sans); color: var(--ink); }
.stat-sub { font-size: .78rem; color: var(--ink-3); }
.dash-trees { display: grid; gap: .8rem; }
.dash-tree { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; background: var(--surface-2); display: flex; flex-direction: column; gap: .45rem; }
.dash-tree-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.dash-tree-head h3 { margin: 0; font-size: 1.1rem; }
.dash-metrics { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; font-size: .88rem; color: var(--ink-2); }
.dash-metrics b { color: var(--ink); }
.completeness { display: flex; gap: .6rem; align-items: center; font-size: .8rem; }
.completeness-bar { flex: 0 1 220px; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.completeness-bar div { height: 100%; background: var(--accent); }
.dash-missing { font-size: .82rem; color: var(--multi); }
.dash-people { font-size: .85rem; }
.warn-text { color: var(--danger); font-weight: 600; }
.dash-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .2rem; }
.dash-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 1.2rem; margin-top: 1.2rem; align-items: start; }
@media (max-width: 860px) { .dash-cols { grid-template-columns: 1fr; } }

/* ---------- reports ---------- */
.reports-layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 58px); }
.reports-nav { border-right: 1px solid var(--line); background: var(--surface); padding: 1rem; }
.reports-nav select { margin-bottom: .8rem; }
.nav-group { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 1rem 0 .3rem; }
.nav-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: .4rem .6rem; border-radius: 8px; white-space: normal; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.reports-main { padding: 1.2rem 1.4rem; min-width: 0; }
.report-params { display: flex; flex-wrap: wrap; gap: 0 .8rem; }
.report-params .field { min-width: 180px; }
.report-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .3rem 0 .7rem; }
.report-bar .spacer { flex: 1; }
.report-bar input[type=search] { width: 200px; padding: .35rem .55rem; }
.report-table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 260px); overflow: auto; }
.report-table th { position: sticky; top: 0; background: var(--surface); z-index: 1; padding: 0; }
.report-table td { font-size: .85rem; }
.th-sort { border: 0; background: transparent; font-weight: 600; font-size: .8rem; color: var(--ink-2); padding: .5rem; width: 100%; justify-content: flex-start; border-radius: 0; }
.cell-bad { color: var(--danger); font-weight: 700; }
.cell-ok { color: var(--accent); }
@media (max-width: 760px) { .reports-layout { grid-template-columns: 1fr; } .reports-nav { border-right: 0; border-bottom: 1px solid var(--line); } }

/* ---------- audit log ---------- */
.audit-table td { font-size: .84rem; vertical-align: top; }
.audit-row { cursor: pointer; }
.audit-row:hover td, .audit-row.open td { background: var(--surface-2); }
.audit-sum { max-width: 380px; word-break: break-word; }
.audit-expand td { background: var(--surface-2); padding: .3rem .8rem .9rem; }
.audit-detail table { max-width: 640px; background: var(--surface); }
.audit-detail .before { color: var(--danger); text-decoration: line-through; }
.audit-detail .after { color: var(--accent); }
.act { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.act-members { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.act-files { background: var(--multi-soft); color: var(--multi); border-color: transparent; }
.act-security, .act-access { background: color-mix(in srgb, var(--male) 15%, transparent); color: var(--male); border-color: transparent; }
.act-billing { background: color-mix(in srgb, var(--other) 15%, transparent); color: var(--other); border-color: transparent; }
.act-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- billing ---------- */
.invoice-card { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; margin-top: .6rem; background: var(--surface-2); display: flex; flex-direction: column; gap: .25rem; }
.invoice-card.overdue { border-color: var(--danger); }
details summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.lock-screen { max-width: 520px; margin: 3rem auto; text-align: center; }
.print-only { display: none; }
@media print {
  .no-print, .topbar, .toast, .modal-backdrop { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  .invoice-doc { max-width: 720px; margin: 0 auto; font-size: 12pt; }
  .invoice-doc .list th, .invoice-doc .list td { border-bottom: 1px solid #ccc; }
}

/* ---------- import ---------- */
.import-status:empty { display: none; }
.import-status { margin-bottom: .8rem; font-size: .9rem; }
.ok-box { background: var(--accent-soft); color: var(--ink); padding: .55rem .75rem; border-radius: 8px; }
.import-table td { font-size: .85rem; }
.import-table tr.has-error td { background: var(--danger-soft); }
.import-table tr.has-warning td { background: var(--multi-soft); }
.import-table .err { color: var(--danger); }
.import-table .warn { color: var(--multi); }
.warn-box { background: var(--multi-soft); color: var(--ink); padding: .55rem .75rem; border-radius: 8px; }
.naming-rules { margin: 0 0 .9rem; padding-left: 1.2rem; font-size: .88rem; }
.naming-rules li { margin: .2rem 0; }
.drop-zone { border: 2px dashed var(--line-2); border-radius: 12px; padding: 1.4rem; text-align: center; cursor: pointer; margin-bottom: .9rem; background: var(--surface-2); }
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin-bottom: .8rem; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.photo-import-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; }
.pcard { border: 1px solid var(--line); border-radius: 10px; padding: .5rem; background: var(--surface); display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; }
.pcard.off { opacity: .55; }
.pcard.failed { border-color: var(--danger); }
.pcard img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.pcard .fname { font-family: var(--mono); font-size: .72rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .badge { align-self: flex-start; }
.pcard .unmatched { color: var(--danger); font-size: .78rem; margin-bottom: .2rem; }
.pcard input, .pcard select { font-size: .8rem; padding: .3rem .4rem; }
.pcard .st { font-weight: 600; }
.pcard .st.ok { color: var(--accent); }
.pcard .st.err { color: var(--danger); font-weight: 400; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 0 .25rem; border-radius: 4px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 70; cursor: zoom-out; padding: 1rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.no-save { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none; }
.doc-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 70; display: flex; flex-direction: column; }
.doc-bar { display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.doc-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-pages { flex: 1; overflow: auto; padding: 1rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.doc-page { max-width: 100%; height: auto; background: #fff; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.doc-status { color: #fff; margin: 2rem auto; }
@media print { .doc-viewer { display: none !important; } }
/* view-only members: the browser's own Print / Save as PDF comes out with a notice instead of the tree */
@media print {
  body.view-only > * { display: none !important; }
  body.view-only::before { content: "Printing this family tree is available to tree admins only."; display: block; padding: 2rem; font: 14pt var(--sans); color: #000; }
}

/* ---------- theme toggle, password eye, collapsible top bar ---------- */
.icon-btn { padding: .4rem .5rem; justify-content: center; }
.theme-btn.floating { position: fixed; top: .8rem; right: .8rem; z-index: 40; box-shadow: var(--shadow); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 2.6rem; }
.pw-toggle {
  position: absolute; top: 50%; right: .3rem; transform: translateY(-50%); border: 0; background: transparent;
  color: var(--ink-3); padding: .3rem; border-radius: 6px;
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }
.topbar-menu { display: contents; }
.menu-btn { display: none; }
.topbar.compact .menu-btn { display: inline-flex; }
.topbar.compact .tree-title { flex: 1; min-width: 0; }
.topbar.compact .tree-title + .spacer { display: none; }
.topbar.compact .searchbar { order: 20; width: 100%; }
.topbar.compact .searchbar input { flex: 1 1 110px; width: auto; }
.topbar.compact .searchbar input[type=date] { flex: 1 1 140px; width: auto; }
/* compact: the menu is a dropdown anchored under the Menu button (top is set in ui.js) */
.topbar.compact .topbar-menu {
  position: absolute; top: 100%; right: .5rem; z-index: 30;
  width: max-content; min-width: 210px; max-width: calc(100vw - 1rem); max-height: calc(100vh - 5rem); overflow-y: auto;
  display: none; flex-direction: column; align-items: stretch; gap: .35rem;
  padding: .5rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.topbar.compact.menu-open .topbar-menu { display: flex; }
.topbar.compact .topbar-menu > *, .topbar.compact .topbar-menu .row > * { width: 100%; justify-content: flex-start; }
.topbar.compact .topbar-menu .row { flex-direction: column; align-items: stretch; gap: .35rem; }
.topbar.compact .topbar-menu .muted, .topbar.compact .topbar-menu .badge { text-align: left; align-self: flex-start; width: auto; padding: .1rem .3rem; }
.topbar.compact .search-results { left: .5rem; right: .5rem; width: auto; }

/* ---------- login screens ---------- */
.login-card { max-width: 400px; }
.login-links { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; font-size: .88rem; }
.login-links button { font-size: .88rem; }
.login-steps { margin: 0 0 .9rem; padding-left: 1.2rem; font-size: .88rem; color: var(--ink-2); }
.login-card .full-btn { width: 100%; justify-content: center; }
.code-input { font-family: var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.code-show { font: 700 1.6rem var(--mono); letter-spacing: .12em; text-align: center; padding: .7rem; border: 2px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--ink); margin: .6rem 0; user-select: all; }
.help-requests { border: 1px solid var(--multi); background: var(--multi-soft); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: 1.2rem; }
.help-requests h3 { margin: 0 0 .4rem; }
.change-requests { margin-bottom: 1.2rem; }
.change-requests .pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .3rem 0; }
.change-requests .request-reply { border-left: 3px solid var(--line); padding: .2rem 0 .2rem .7rem; margin: .4rem 0; }
.change-requests summary { cursor: pointer; color: var(--ink-2); font-size: .9rem; }

/* ---------- tablets & phones ---------- */
@media (max-width: 900px) {
  .page { padding: 1rem .9rem 2.5rem; }
  .reports-main { padding: 1rem; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 1.35rem; }
  .topbar { padding: .5rem .75rem; gap: .5rem; }
  .brand { font-size: 1.05rem; }
  .tree-title h1 { font-size: 1rem; }
  .tree-title .badge { display: none; }
  .page { padding: .8rem .6rem 2rem; }
  .card { padding: .9rem .85rem; }
  .legend { display: none; }
  .zoom-ctrl { left: .6rem; bottom: .6rem; }
  .panel { width: 100%; border-left: 0; }
  .panel-head .avatar { width: 64px; height: 64px; }
  dl.details { grid-template-columns: 110px 1fr; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-width: 100% !important; max-height: 94dvh; border-radius: 14px 14px 0 0; }
  .modal footer { position: sticky; bottom: 0; background: var(--surface); }
  .modal footer button { flex: 1; justify-content: center; }
  .reports-nav { padding: .7rem; }
  .reports-nav .nav-item { display: inline-block; width: auto; }
  .report-bar input[type=search] { width: 100%; }
  .report-params .field { min-width: 0; flex: 1 1 140px; }
  .stat-value { font-size: 1.45rem; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .photo-import-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  table.list th, table.list td { padding: .4rem .35rem; }
  .toast { left: .75rem; right: .75rem; transform: none; text-align: center; }
}
/* touch screens: bigger targets, and 16px inputs so phones don't zoom in on focus */
@media (pointer: coarse) {
  button, .btn { min-height: 40px; }
  button.small, .btn.small { min-height: 34px; }
  .pw-toggle, .tabs button { min-height: 0; }
  input, select, textarea { font-size: 16px; min-height: 40px; }
  .check input { min-height: 0; }
  .zoom-ctrl button { width: 44px; height: 44px; }
}

/* ---------- public pages: Home, About, FAQ, Contact ---------- */
.site-nav { display: flex; gap: .25rem; align-items: center; }
.site-nav a { color: var(--ink-2); text-decoration: none; padding: .4rem .65rem; border-radius: 8px; font-size: .92rem; }
.site-nav a:hover { background: var(--surface-2); color: var(--ink); }
.site-nav a[aria-current=page] { color: var(--accent); font-weight: 600; }
.topbar.compact .site-nav { flex-direction: column; align-items: stretch; width: 100%; }
.site-main { max-width: 980px; margin: 0 auto; padding: 2.5rem 1rem 3rem; }
.site-main.narrow { max-width: 760px; }
.site-main h1 { font-size: 2rem; }
.lede { font-size: 1.1rem; color: var(--ink-2); max-width: 62ch; }
.hero { text-align: center; padding: 2.5rem 0 2rem; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); max-width: 18ch; margin: 0 auto .6rem; }
.hero .lede { margin: 0 auto 1.4rem; }
.hero .ctas { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.btn.large { padding: .65rem 1.2rem; font-size: 1rem; }
.section { margin-top: 2.6rem; }
.section > h2 { font-size: 1.45rem; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.feature-grid .card h3 { margin-bottom: .3rem; }
.feature-grid .card p { margin: 0; color: var(--ink-2); font-size: .93rem; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; counter-reset: step; }
.steps li { counter-increment: step; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; margin-bottom: .4rem; }
.steps li strong { display: block; margin-bottom: .2rem; }
.steps li span { color: var(--ink-2); font-size: .93rem; }
.cta-band { margin-top: 2.6rem; text-align: center; background: var(--accent-soft); border-radius: var(--radius); padding: 1.8rem 1rem; }
.cta-band p { color: var(--ink-2); margin: 0 0 1rem; }
.prose p, .prose li { color: var(--ink-2); max-width: 68ch; }
.prose h2 { margin-top: 2rem; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; }
.faq summary { cursor: pointer; padding: .85rem 1.1rem; font-weight: 600; list-style-position: outside; margin-left: 1rem; }
.faq details[open] summary { border-bottom: 1px solid var(--line); }
.faq details > div { padding: .7rem 1.1rem .9rem; color: var(--ink-2); }
.faq details > div p { margin: 0 0 .5rem; } .faq details > div p:last-child { margin: 0; }
.faq h2 { font-size: 1.15rem; margin: 1.8rem 0 .7rem; }
.contact-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.2rem; align-items: start; }
.contact-grid aside p { color: var(--ink-2); font-size: .93rem; }
.contact-form .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 720px) { .contact-grid { grid-template-columns: 1fr; } .site-main { padding-top: 1.5rem; } }
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 2rem; }
.site-footer .inner { max-width: 980px; margin: 0 auto; padding: 1.2rem 1rem; display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; justify-content: space-between; font-size: .88rem; color: var(--ink-3); }
.site-footer nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.site-footer nav a { color: var(--ink-2); text-decoration: none; }
.site-footer nav a:hover, .site-footer nav a[aria-current=page] { color: var(--accent); }
.login-wrap { align-content: center; gap: 1rem; }
.login-site-links { display: flex; gap: 1.1rem; justify-content: center; flex-wrap: wrap; font-size: .88rem; }
.login-site-links a { color: var(--ink-2); text-decoration: none; }
.login-site-links a:hover { color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.price-panel { max-width: 860px; margin: 0 auto; }
.price-controls { display: grid; grid-template-columns: 2fr 1fr; gap: 0 1rem; }
.price-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-top: .4rem; }
.price-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: var(--surface-2); }
.price-card.strong { background: var(--accent-soft); border-color: transparent; }
.price-card .label { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.price-card .amount { font-family: var(--sans); font-size: 1.6rem; font-weight: 600; margin: .25rem 0; font-variant-numeric: tabular-nums; }
.price-card.strong .amount { color: var(--accent); }
.price-card .note { font-size: .85rem; color: var(--ink-2); }
@media (max-width: 720px) { .price-controls, .price-cards { grid-template-columns: 1fr; } }
.pay-methods { display: grid; gap: .6rem; }
.pay-method { border-left: 3px solid var(--accent); padding: .3rem 0 .3rem .7rem; }
.pay-method strong { display: block; }
.pay-chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .35rem; }

/* ---------- Hovia brand (part of the Hovia family of apps) ---------- */
.brand .hovia-mark { width: 1.35em; height: 1.35em; flex-shrink: 0; }
.brand .hovia-word { font-family: Georgia, 'Palatino Linotype', serif; font-weight: 400; letter-spacing: -.01em; color: var(--ink); }
.brand .product-name { color: var(--accent); font-weight: 600; }
.hovia-family { max-width: 980px; margin: 0 auto; padding: 0 1rem 1.1rem; font-size: .82rem; color: var(--ink-3); display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.login-wrap .hovia-family { justify-content: center; padding-bottom: 0; }
.hovia-family a { color: var(--ink-2); text-decoration: none; }
.hovia-family a:hover { color: var(--accent); }
