:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --border: #e0dbd0;
  --text: #22302b;
  --muted: #6b7772;
  --accent: #2f6f5e;
  --accent-2: #e3efe9;
  --danger: #b3413b;
  --male: #4a7fb5;
  --female: #c0587e;
  --other: #8a7bb0;
  --unknown: #8d9793;
  --line: #9aa59f;
  --line-hl: #2f6f5e;
  --shadow: 0 1px 2px rgba(30, 40, 35, .06), 0 4px 14px rgba(30, 40, 35, .06);
  --radius: 10px;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b19;
    --surface: #1f2522;
    --surface-2: #262d2a;
    --border: #34403b;
    --text: #e4ebe7;
    --muted: #94a19b;
    --accent: #6fbfa6;
    --accent-2: #243a33;
    --danger: #e0706a;
    --male: #6f9fd3;
    --female: #dc7fa3;
    --other: #a99ad0;
    --unknown: #7f8a86;
    --line: #5c6964;
    --line-hl: #6fbfa6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { fill: var(--accent); stroke: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-2); color: var(--accent); }
.global-search { margin-left: auto; position: relative; width: min(320px, 40vw); }
.global-search input { width: 100%; }

.suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
.suggest button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; background: none; color: var(--text); text-align: left; cursor: pointer; font: inherit;
}
.suggest button:hover, .suggest button.active { background: var(--surface-2); }
.suggest .empty { padding: 8px 10px; color: var(--muted); }

/* ---------- forms & buttons ---------- */
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
input[type=color] { padding: 2px; height: 36px; width: 60px; }
input[type=checkbox] { accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 500; cursor: pointer;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10201b; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger.primary, form footer .btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: .88em; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem;
  width: 30px; height: 30px; border-radius: 6px; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .78rem; color: var(--muted); }
.check, .field.check { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.form-error { margin: 0 20px 10px; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---------- modal ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.modal.wide { width: min(820px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(20, 28, 25, .45); }
dialog.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
dialog.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
dialog.modal .modal-body { padding: 8px 20px 16px; overflow: auto; }
dialog.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.seg button { border: 0; background: var(--surface); color: var(--muted); padding: 6px 14px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }

/* ---------- page ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.section { margin-top: 32px; }
.section > .section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.empty-state {
  text-align: center; padding: 50px 20px; color: var(--muted);
  border: 2px dashed var(--border); border-radius: 14px;
}
.empty-state h2 { color: var(--text); margin-bottom: 6px; }
.empty-state .btn { margin-top: 14px; }

.family-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.family-card {
  position: relative; display: block; padding: 18px 18px 16px 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); overflow: hidden;
}
.family-card:hover { text-decoration: none; border-color: var(--accent); }
.family-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--fc, var(--accent)); }
.family-card h3 { font-size: 1.15rem; margin-bottom: 4px; }
.family-card .meta { display: flex; gap: 14px; color: var(--muted); font-size: .88rem; margin-top: 10px; }
.family-card p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .actions { display: flex; gap: 4px; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); border-top: 0; }
table.data tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); font-size: .82rem; color: var(--text); border: 1px solid var(--border); }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--fc, var(--accent)); }
a.chip:hover { text-decoration: none; border-color: var(--accent); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.ok { background: var(--accent-2); color: var(--accent); }

/* ---------- avatars ---------- */
.avatar {
  --sz: 40px;
  width: var(--sz); height: var(--sz); flex: 0 0 var(--sz);
  border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center;
  font-weight: 700; font-size: calc(var(--sz) * .38); color: #fff; background: var(--unknown);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { --sz: 28px; }
.avatar.lg { --sz: 120px; }
.avatar.g-M { background: var(--male); }
.avatar.g-F { background: var(--female); }
.avatar.g-O { background: var(--other); }
.plink { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.plink:hover span { text-decoration: underline; }

/* ---------- family page ---------- */
.fam-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.fam-head .stripe { width: 8px; align-self: stretch; border-radius: 4px; background: var(--fc, var(--accent)); }
.fam-head .desc { margin: 6px 0 0; color: var(--muted); max-width: 70ch; white-space: pre-line; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 0; }
.tabs a { padding: 9px 16px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { padding-top: 18px; }

.page.full { max-width: none; padding: 16px 20px 0; height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column; }
.page.full .tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-top: 12px; }

/* ---------- tree ---------- */
.tree-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.tree-toolbar .grow { flex: 1; }
.tree-toolbar .tree-find { position: relative; width: 240px; }
.tree-toolbar .tree-find input { width: 100%; }
.tree-wrap { position: relative; flex: 1; min-height: 360px; display: flex; border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; background: var(--surface-2); }
.tree-host { position: relative; flex: 1; min-width: 0; }
.tree-viewport {
  position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--line) 35%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
.tree-viewport.panning { cursor: grabbing; }
.tree-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-world.animating { transition: transform .35s ease; }
.tree-edges { position: absolute; left: 0; top: 0; overflow: visible; }
.tree-nodes { position: absolute; left: 0; top: 0; }

.e-child, .e-partner { fill: none; stroke: var(--line); stroke-width: 1.6; }
.e-child.k-adoptive { stroke-dasharray: 7 4; }
.e-child.k-step { stroke-dasharray: 2 4; }
.e-child.k-foster { stroke-dasharray: 9 3 2 3; }
.e-child.secondary { opacity: .6; }
.e-partner { stroke-width: 2.4; stroke: color-mix(in srgb, var(--line) 80%, var(--text)); }
.e-partner.pk-partnership { stroke-dasharray: 8 5; }
.e-partner.pk-engagement { stroke-dasharray: 2 4; }
.e-partner.ps-divorced, .e-partner.ps-separated, .e-partner.ps-annulled { stroke: var(--line); stroke-dasharray: 3 5; stroke-width: 1.8; opacity: .8; }
.e-partner.implicit { stroke: var(--line); stroke-dasharray: 1 5; stroke-linecap: round; }
.e-child.hl, .e-partner.hl { stroke: var(--line-hl); stroke-width: 2.8; opacity: 1; }
.marker { cursor: pointer; }
.marker circle { fill: var(--surface); stroke: color-mix(in srgb, var(--line) 80%, var(--text)); stroke-width: 1.5; }
.marker text { text-anchor: middle; font-size: 13px; fill: var(--text); pointer-events: none; }
.marker.ps-divorced circle, .marker.ps-separated circle, .marker.ps-annulled circle { stroke-dasharray: 2 2; }
.marker.ps-divorced text, .marker.ps-separated text { fill: var(--danger); }
.marker:hover circle { stroke: var(--accent); stroke-width: 2.5; }

.tree-card {
  position: absolute; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); cursor: pointer; overflow: hidden;
  transition: box-shadow .15s, border-color .15s, opacity .15s;
}
.tree-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--unknown); }
.tree-card.g-M::before { background: var(--male); }
.tree-card.g-F::before { background: var(--female); }
.tree-card.g-O::before { background: var(--other); }
.tree-card:hover { border-color: var(--accent); }
.tree-card.deceased { background: color-mix(in srgb, var(--surface) 80%, var(--surface-2)); }
.tree-card.deceased .tc-av { filter: grayscale(.6); }
.tree-card.out { border-style: dashed; opacity: .78; }
.tree-card.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent), var(--shadow); opacity: 1; }
.tree-card.hl { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.has-sel .tree-card:not(.sel):not(.hl) { opacity: .55; }
.tc-av {
  width: 48px; height: 48px; flex: 0 0 48px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--unknown); font-size: 17px;
}
.g-M .tc-av { background: var(--male); }
.g-F .tc-av { background: var(--female); }
.g-O .tc-av { background: var(--other); }
.tc-av img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tc-info { min-width: 0; flex: 1; }
.tc-name { font-size: 14px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-dates { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.tc-fams { position: absolute; right: 7px; top: 6px; display: flex; gap: 3px; }
.tc-fams i { width: 8px; height: 8px; border-radius: 50%; }
.zoom-far .tree-card { box-shadow: none; }

.tree-zoom { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.tree-zoom button { width: 38px; height: 36px; border: 0; background: none; color: var(--text); font-size: 18px; cursor: pointer; }
.tree-zoom button + button { border-top: 1px solid var(--border); }
.tree-zoom button:hover { background: var(--surface-2); }
.tree-legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px 14px;
  padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border); font-size: 12px; color: var(--muted); pointer-events: none; max-width: calc(100% - 90px);
}
.tree-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-line { display: inline-block; width: 24px; border-top: 2.4px solid var(--line); }
.lg-line.dashed { border-top-style: dashed; }
.lg-line.ended { border-top: 2px dotted var(--line); }
.lg-line.adoptive { border-top: 2px dashed var(--line); width: 24px; }
.lg-line.step { border-top: 2px dotted var(--line); }
.tree-empty { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; pointer-events: none; }
.tree-empty > div { pointer-events: auto; background: var(--surface); padding: 28px 36px; border-radius: 14px; border: 1px solid var(--border); text-align: center; box-shadow: var(--shadow); }
.tree-empty .btn { margin-top: 12px; }

/* ---------- drawer ---------- */
.drawer {
  width: 340px; flex: 0 0 340px; background: var(--surface); border-left: 1px solid var(--border);
  overflow: auto; padding: 18px; position: relative;
}
.drawer[hidden] { display: none; }
.drawer .close { position: absolute; right: 10px; top: 10px; }
.drawer .who { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; margin-bottom: 14px; }
.drawer .who .avatar { --sz: 92px; }
.drawer h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.drawer .rel { display: flex; flex-direction: column; gap: 4px; }
.drawer .rel button { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--text); font: inherit; text-align: left; }
.drawer .rel button:hover { background: var(--surface-2); }
.drawer .facts { font-size: .9rem; display: grid; gap: 2px; }
.drawer .act-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
.drawer .act-grid .btn { justify-content: center; }

/* ---------- person page ---------- */
.person-hero { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 26px; }
.person-hero .avatar.lg { cursor: pointer; box-shadow: var(--shadow); }
.person-hero .info { flex: 1; min-width: 260px; }
.person-hero .facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin-top: 10px; font-size: .95rem; }
.person-hero .facts dt { color: var(--muted); }
.person-hero .facts dd { margin: 0; }
.person-hero .notes { margin-top: 12px; white-space: pre-line; max-width: 75ch; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card > .card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card .row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.card .row:first-of-type { border-top: 0; }
.card .row .grow { flex: 1; min-width: 0; }
.card .group-label { font-size: .8rem; color: var(--muted); margin: 10px 0 2px; font-weight: 600; }
.card .none { color: var(--muted); font-size: .9rem; padding: 4px 0; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 6px 0 10px 12px; }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 11px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .when { font-size: .82rem; color: var(--muted); }
.timeline .actions { float: right; }

/* ---------- media ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.media-item { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.media-item .thumb { aspect-ratio: 1; display: grid; place-items: center; background: var(--surface-2); cursor: pointer; overflow: hidden; }
.media-item .thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.media-item .thumb:hover img { transform: scale(1.04); }
.media-item .thumb .ficon { font-size: 40px; color: var(--muted); }
.media-item .cap { padding: 6px 9px; font-size: .84rem; }
.media-item .cap .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item .menu { position: absolute; top: 6px; right: 6px; display: none; gap: 2px; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.media-item:hover .menu, .media-item:focus-within .menu { display: flex; }
.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-2); }

.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 12, .92); display: flex; flex-direction: column; color: #eee; }
.lightbox .lb-main { flex: 1; min-height: 0; display: grid; place-items: center; padding: 20px 70px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: calc(100vh - 150px); border-radius: 6px; box-shadow: 0 8px 40px rgba(0, 0, 0, .5); }
.lightbox .lb-info { padding: 12px 24px 18px; text-align: center; }
.lightbox .lb-info a { color: #9fd9c6; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .1); border: 0; color: #fff; font-size: 28px; width: 48px; height: 64px; border-radius: 8px; cursor: pointer; }
.lightbox .lb-nav:hover { background: rgba(255, 255, 255, .2); }
.lightbox .lb-prev { left: 12px; }
.lightbox .lb-next { right: 12px; }
.lightbox .lb-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: #fff; font-size: 26px; cursor: pointer; }

/* ---------- picker ---------- */
.picker { position: relative; }
.picker input { width: 100%; }
.picker .picked { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-2); }
.picker .picked .grow { flex: 1; }
.tagged { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tagged .chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; }

/* ---------- connections ---------- */
.conn-card { margin-bottom: 14px; }
.conn-card ul { margin: 6px 0 0; padding-left: 18px; }
.conn-card li { margin: 2px 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: 9px 18px; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast.err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand span { display: none; }
  .nav a { padding: 6px 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .drawer { position: absolute; inset: auto 0 0 0; width: auto; max-height: 60%; border-left: 0; border-top: 1px solid var(--border); z-index: 5; }
  .page { padding: 16px 16px 40px; }
  .page.full { padding: 12px 12px 0; }
  .tree-legend { display: none; }
}

/* ---------- gatherings ---------- */
.gath-list { display: grid; gap: 10px; }
.gath-card {
  display: flex; align-items: center; gap: 16px; padding: 12px 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.gath-card:hover { text-decoration: none; border-color: var(--accent); }
.gath-card .grow { flex: 1; min-width: 0; }
.gath-date { display: flex; flex-direction: column; align-items: center; min-width: 76px; padding: 6px 8px; border-radius: 8px; background: var(--accent-2); color: var(--accent); }
.gath-date b { font-size: 1.3rem; line-height: 1.1; }
.gath-date span { font-size: .75rem; }
.gath-stats { display: flex; gap: 14px; color: var(--muted); font-size: .9rem; }
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.att {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; text-align: left; cursor: pointer; font: inherit;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; opacity: .75;
}
.att:hover { border-color: var(--accent); opacity: 1; }
.att .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.att .tick { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border); display: grid; place-items: center; color: transparent; font-size: 13px; }
.att.on { opacity: 1; background: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.att.on .tick { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- import: duplicity ---------- */
.dup-list { display: grid; gap: 10px; }
.dup { display: grid; grid-template-columns: minmax(200px, 1fr) 2fr; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.dup-src { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; align-content: flex-start; }
.dup-src > .small { width: 100%; }
.dup-opts { display: grid; gap: 4px; }
.dup-opt { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; }
.dup-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-2); }
.dup-opt input { margin-top: 5px; }
.dup-opt .grow { flex: 1; min-width: 0; }
.dup-opt .avatar { vertical-align: middle; }
@media (max-width: 760px) { .dup { grid-template-columns: 1fr; } }

/* ---------- prihlásenie a účty ---------- */
body.logged-out .nav, body.logged-out .global-search, body.logged-out .user-menu { display: none; }
.auth-page { min-height: calc(100vh - var(--topbar-h)); display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.35rem; }
.auth-card .btn.primary { justify-content: center; padding: 10px; margin-top: 4px; }
.auth-card .form-error { margin: 0; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; color: var(--accent); }
.auth-brand svg { fill: var(--accent); stroke: var(--accent); }
.auth-card code, .page code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 12px 3px 3px; cursor: pointer; font: inherit; }
.user-btn:hover { border-color: var(--accent); }
.user-btn .avatar { background: var(--accent); }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 4px 0; display: flex; flex-direction: column; }
.menu-pop a, .menu-pop button { padding: 8px 14px; color: var(--text); background: none; border: 0; text-align: left; font: inherit; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); text-decoration: none; }
.menu-pop button { border-top: 1px solid var(--border); }

.page.narrow { max-width: 760px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: ui-monospace, monospace; font-size: .85rem; }
tr.inactive td { opacity: .55; }
.warn-box { margin-top: 10px; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.hist { align-items: flex-start; }
.hist-when { width: 130px; flex: 0 0 130px; }
.hist.reverted .grow > div:first-child { text-decoration: line-through; color: var(--muted); }
.hist-detail ul { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 760px) {
  .user-btn .nm { display: none; }
  .hist { flex-wrap: wrap; }
  .hist-when { width: 100%; flex: none; }
}

/* ---------- novinky ---------- */
.news-page { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.news-side { position: sticky; top: calc(var(--topbar-h) + 16px); }
.composer { margin-bottom: 16px; }
.composer-top { display: flex; gap: 10px; align-items: flex-start; }
.composer-top textarea { flex: 1; min-height: 54px; }
.composer-more { margin-top: 12px; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.form-sub { margin: 10px 0 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.feed { display: grid; gap: 14px; }
.post.pinned { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.post-head { display: flex; align-items: center; gap: 10px; }
.post-head .grow { flex: 1; min-width: 0; }
.post-kind { font-size: 22px; }
.post-title { margin: 10px 0 0; font-size: 1.1rem; }
.post-body { margin-top: 8px; white-space: normal; line-height: 1.55; overflow-wrap: anywhere; }
.post-imgs { display: grid; gap: 4px; margin-top: 10px; border-radius: 10px; overflow: hidden; }
.post-imgs.n1 { grid-template-columns: 1fr; }
.post-imgs.n2, .post-imgs.n4 { grid-template-columns: 1fr 1fr; }
.post-imgs.n3 { grid-template-columns: 2fr 1fr 1fr; }
.post-imgs button { position: relative; border: 0; padding: 0; cursor: pointer; background: var(--surface-2); aspect-ratio: 4 / 3; }
.post-imgs.n1 button { aspect-ratio: 16 / 10; }
.post-imgs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-imgs .more { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff; font-size: 1.6rem; font-weight: 700; }
.post-people { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.comments { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; display: grid; gap: 6px; }
.comment { font-size: .92rem; overflow-wrap: anywhere; }
.comment .icon-btn.sm { width: 22px; height: 22px; font-size: .8rem; }
.comment-form { display: flex; gap: 6px; }
.comment-form input { flex: 1; }
.up-row { align-items: flex-start !important; }
.up-date { display: flex; flex-direction: column; align-items: center; min-width: 38px; padding: 2px 4px; border-radius: 8px; background: var(--accent-2); color: var(--accent); font-size: .75rem; line-height: 1.1; }
.up-date b { font-size: 1.05rem; }
.side-links { display: grid; gap: 6px; }
.side-links .btn { justify-content: flex-start; }

/* ---------- kontakty ---------- */
.contacts-filter { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.contacts-filter input[type=search] { width: 280px; max-width: 100%; }
.contact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; margin-bottom: 14px; }
.contact { position: relative; display: flex; flex-direction: column; gap: 8px; }
.contact.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent-2) 50%, var(--surface)); }
.contact-check { position: absolute; top: 10px; right: 12px; }
.contact-who { display: flex; align-items: center; gap: 10px; color: var(--text); padding-right: 24px; }
.contact-who:hover { text-decoration: none; }
.contact-who > span { display: flex; flex-direction: column; min-width: 0; }
.contact-lines { display: grid; gap: 3px; font-size: .92rem; overflow-wrap: anywhere; }
.contact-lines.big { font-size: 1rem; gap: 6px; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.contact-card .contact-actions { margin-top: 10px; }

/* ---------- mapa ---------- */
.map-wrap { flex: 1; min-height: 380px; display: flex; border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.map-host { flex: 1; min-height: 380px; }
.loc-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.loc-map { height: 280px; border-radius: 10px; border: 1px solid var(--border); }
.map-pin { width: 40px; height: 40px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--unknown); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); display: grid; place-items: center; overflow: hidden; color: #fff; font-weight: 700; font-size: 13px; }
.map-pin > * { transform: rotate(45deg); }
.map-pin img { width: 140%; height: 140%; object-fit: cover; }
.map-pin.g-M { background: var(--male); }
.map-pin.g-F { background: var(--female); }
.map-pop { min-width: 180px; display: grid; gap: 3px; }
.leaflet-container { font: inherit; }

.inv-list { display: grid; gap: 2px; margin-top: 6px; max-height: 220px; overflow: auto; }
.inv-item { text-align: left; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; }
.inv-item:hover { border-color: var(--accent); }

@media (max-width: 900px) {
  .news-page { grid-template-columns: 1fr; }
  .news-side { position: static; order: -1; }
}

.auth-card input { width: 100%; }
.auth-card .form-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- bunky ---------- */
.family-card.cell { background: linear-gradient(135deg, color-mix(in srgb, var(--fc, var(--accent)) 8%, var(--surface)), var(--surface)); }
.section-head > div { min-width: 0; }
.section > .section-head { gap: 12px; flex-wrap: wrap; }
.cell-def { margin-top: 4px; font-size: .92rem; }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.ov-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.ov-stats b { display: block; font-size: 1.6rem; color: var(--accent); }
.ov-stats span { font-size: .8rem; color: var(--muted); }
.gen-row { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; margin: 4px 0; font-size: .9rem; }
.gen-row .bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.gen-row .bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.gen-row b { text-align: right; }

.org-card { min-width: 220px; display: grid; gap: 6px; padding: 10px 14px; }

.user-btn .nm { white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }


/* ---------- hierarchia buniek ---------- */
.cell-tree { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.cell-branch { display: grid; gap: 6px; }
.sub-fams { display: grid; gap: 4px; }
.sub-fam { display: flex; flex-direction: column; gap: 1px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); border-left: 4px solid var(--fc, var(--accent)); background: var(--surface); color: var(--text); }
.sub-fam:hover { text-decoration: none; border-color: var(--accent); }
.sub-fam.lvl1 { margin-left: 14px; }
.sub-fam.lvl2 { margin-left: 28px; }
.sub-fam.lvl3 { margin-left: 42px; }
.sub-list { display: grid; gap: 3px; max-height: 240px; overflow: auto; margin-top: 6px; }
.inv-item.on { border-color: var(--accent); background: var(--accent-2); }
.my-cells { display: grid; gap: 2px; }
.my-cell { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; color: var(--text); }
.my-cell:hover { background: var(--surface-2); text-decoration: none; }
.my-cell i { width: 9px; height: 9px; border-radius: 50%; background: var(--fc, var(--accent)); flex: 0 0 9px; }
.my-cell span { margin-left: auto; }
.my-cell.lvl1 { padding-left: 24px; }
.my-cell.lvl2 { padding-left: 40px; }
.my-cells-card { margin-bottom: 14px; }
/* ---------- časová os bunky ---------- */
.tl-filter { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.tl-type { cursor: pointer; opacity: .5; }
.tl-type.on { opacity: 1; border-color: var(--accent); }
.timeline.big li { padding-bottom: 14px; }
.timeline .tl-year { padding: 10px 0 4px; font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.timeline .tl-year::before { width: 14px; height: 14px; left: -25px; top: 14px; background: var(--accent); }
.timeline .tl-death::before { border-color: var(--muted); }
.timeline .tl-gathering::before, .timeline .tl-post::before { border-color: var(--female); }
.year-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.year-chips .chip { cursor: pointer; }
.year-chips .chip.on, .chip.on { border-color: var(--accent); background: var(--accent-2); color: var(--accent); }

.lock-note { margin-top: 6px; display: inline-block; padding: 4px 10px; border-radius: 8px; font-size: .88rem;
  background: color-mix(in srgb, var(--danger) 10%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }

.disk-bar { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.disk-bar i { display: block; height: 100%; background: var(--accent); }
.disk-bar.warn i { background: var(--danger); }
.disk-rows { display: grid; grid-template-columns: 1fr auto; gap: 3px 16px; margin-top: 8px; }
.disk-rows b { text-align: right; font-weight: 600; }

.space-label { font-size: .85rem; color: var(--muted); padding: 3px 10px; border-radius: 999px; background: var(--surface-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-label:empty { display: none; }
body.logged-out .space-label { display: none; }
.menu-space { display: flex; flex-direction: column; padding: 6px 14px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface-2); }
@media (max-width: 760px) { .space-label { display: none; } }
