:root {
  --green: #173a2b;
  --green-2: #244c39;
  --green-3: #315d48;
  --cream: #f6f0e4;
  --cream-2: #fffdf8;
  --cream-3: #efe8da;
  --gold: #b58a45;
  --gold-soft: #e7d6b9;
  --text: #26312b;
  --muted: #6a706b;
  --border: #ddd3c2;
  --danger: #8e433b;
  --shadow: 0 18px 45px rgba(23, 58, 43, 0.12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--cream);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
body.dialog-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.is-hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top left, rgba(181, 138, 69, .22), transparent 35%),
    radial-gradient(circle at bottom right, rgba(255, 255, 255, .08), transparent 30%),
    linear-gradient(145deg, var(--green), #0f2b20 55%, var(--green-2));
}
.login-card {
  width: min(100%, 470px);
  background: var(--cream-2);
  border: 1px solid rgba(181, 138, 69, .45);
  border-radius: 24px;
  padding: 38px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .25);
}
.brand-logo { width: 48px; height: 48px; object-fit: contain; }
.brand-logo-large { width: 82px; height: 82px; display: block; margin-bottom: 20px; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 750;
  font-size: 12px;
}
h1, h2, h3 { color: var(--green); margin-top: 0; }
h1 { font-size: clamp(30px, 6vw, 42px); line-height: 1.05; margin-bottom: 16px; }
h2 { font-size: clamp(28px, 4vw, 38px); margin-bottom: 8px; }
h3 { font-size: 19px; margin-bottom: 9px; }
.login-intro, .page-heading p, .panel p { color: var(--muted); line-height: 1.6; }
.login-form { margin-top: 28px; display: grid; gap: 9px; }
.login-form label { font-weight: 650; color: var(--green); margin-top: 8px; }
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(181, 138, 69, .15); }
select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}
select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(181, 138, 69, .15);
}
textarea { resize: vertical; min-height: 96px; }
.form-error { min-height: 20px; margin: 4px 0 0; color: var(--danger); font-size: 14px; }
.privacy-note { margin: 22px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.button {
  border: 0;
  border-radius: 11px;
  padding: 11px 16px;
  font-weight: 700;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover { background: var(--green-2); }
.button-secondary { color: var(--green); background: rgba(255,255,255,.88); }
.button-danger { color: var(--danger); background: #fff7f5; border-color: rgba(142, 67, 59, .35); }
.button-danger:hover { background: #fbe9e6; }
.button-small { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 268px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px 22px;
  color: #fff;
  background:
    radial-gradient(circle at 40px 30px, rgba(181, 138, 69, .16), transparent 160px),
    var(--green);
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand strong { display: block; font-size: 19px; }
.sidebar-brand span { display: block; color: #d6e0d9; font-size: 12px; margin-top: 2px; }
.main-nav { display: grid; gap: 6px; }
.nav-button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 11px 13px;
  color: #dce5df;
  background: transparent;
  text-align: left;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-button:hover, .nav-button.is-active { color: #fff; background: rgba(255,255,255,.12); }
.nav-icon { width: 20px; text-align: center; color: var(--gold-soft); font-size: 18px; }
.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 11px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.14); }
.avatar { width: 39px; height: 39px; border-radius: 50%; display: grid; place-items: center; color: var(--green); background: var(--gold-soft); font-weight: 800; }
.sidebar-user-text { min-width: 0; }
.sidebar-user-text strong, .sidebar-user-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-text span { margin-top: 2px; color: #d6e0d9; font-size: 12px; }
.sidebar-scrim { display: none; }

.main-content { min-width: 0; padding: 48px clamp(24px, 5vw, 72px); }
.mobile-header { display: none; }
.content-view { max-width: 1180px; margin: 0 auto; }
.page-heading { margin-bottom: 28px; }
.page-heading p { margin: 0; }
.hero-heading { padding-right: min(8vw, 90px); }
.page-heading-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 18px 0 28px; }
.stat-card, .panel, .person-card, .detail-card, .detail-nav {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--cream-2);
  box-shadow: 0 4px 18px rgba(23, 58, 43, .045);
}
.stat-card { padding: 22px; }
.stat-card strong { display: block; margin: 4px 0; color: var(--green); font-size: 34px; line-height: 1; }
.stat-card span:last-child { color: var(--muted); font-size: 13px; }
.stat-label { color: var(--gold); text-transform: uppercase; letter-spacing: .07em; font-weight: 750; font-size: 11px; }
.panel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.panel { padding: 24px; }
.panel-muted { background: var(--cream-3); }
.action-panel { display: flex; align-items: flex-start; gap: 18px; }
.panel-icon { flex: 0 0 48px; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; color: #fff; background: var(--green); font-size: 24px; }
.dashboard-search { display: grid; grid-template-columns: minmax(0, .8fr) minmax(280px, 1.2fr); gap: 28px; align-items: center; margin-bottom: 18px; }
.dashboard-search h3 { margin: 5px 0 5px; }
.dashboard-search p { margin: 0; }
.dashboard-search-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
.count-badge, .access-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 750;
}
.count-badge { color: var(--green); background: var(--gold-soft); }
.page-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.search-box { position: relative; margin-bottom: 18px; }
.search-box input { padding-right: 84px; }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; border-radius: 8px; padding: 7px 9px; color: var(--green); background: #f0e8d9; font-size: 12px; font-weight: 700; }
.person-list { display: grid; gap: 10px; }
.person-card {
  width: 100%;
  padding: 17px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  color: inherit;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
button.person-card { cursor: pointer; }
button.person-card:hover { transform: translateY(-1px); border-color: #bda982; box-shadow: 0 8px 24px rgba(23, 58, 43, .08); }
button.person-card:focus-visible { outline: 3px solid rgba(181, 138, 69, .35); outline-offset: 2px; }
.person-card.is-restricted { cursor: default; opacity: .82; }
.person-monogram { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--green); font-weight: 800; }
.person-summary { min-width: 0; flex: 1; }
.person-summary strong { display: block; color: var(--green); font-size: 16px; }
.person-summary span { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
.access-badge.full { color: #22593d; background: #dbeadd; }
.access-badge.restricted { color: #785e2e; background: #efe2c9; }
.empty-state { padding: 30px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; }
.empty-state.compact { padding: 18px; margin-bottom: 0; }
.error-state { color: var(--danger); background: #fff9f7; }
.back-button { border: 0; background: transparent; color: var(--green); padding: 0; margin-bottom: 20px; font-weight: 700; }
.back-button:hover { text-decoration: underline; }
.detail-layout { display: grid; gap: 18px; }
.detail-hero {
  border-radius: 20px;
  padding: 28px;
  color: #fff;
  background:
    radial-gradient(circle at right top, rgba(181, 138, 69, .24), transparent 210px),
    linear-gradient(135deg, var(--green), var(--green-2));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  box-shadow: var(--shadow);
}
.detail-hero h2 { color: #fff; margin-bottom: 8px; }
.detail-hero p { margin: 4px 0; color: #dce5df; }
.profile-photo-button { border: 0; padding: 0; border-radius: 17px; background: transparent; }
.profile-photo-button:focus-visible, .photo-button:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 3px; }
.profile-photo { width: 132px; height: 132px; border-radius: 16px; object-fit: cover; background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.28); display: block; }
.detail-nav { display: flex; gap: 7px; padding: 10px; overflow-x: auto; scrollbar-width: thin; position: sticky; top: 10px; z-index: 8; }
.detail-nav a { flex: 0 0 auto; text-decoration: none; border-radius: 999px; padding: 8px 11px; color: var(--green); background: #f3ede2; font-size: 12px; font-weight: 750; }
.detail-nav a:hover { background: var(--gold-soft); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.detail-card { padding: 22px; min-width: 0; scroll-margin-top: 80px; }
.detail-card.full-width { grid-column: 1 / -1; }
.detail-card h3 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-action-button { margin: 0 0 14px; }
.detail-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.detail-list li { padding-bottom: 12px; border-bottom: 1px solid #eee6da; }
.detail-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-list strong { color: var(--green); display: block; }
.detail-list span, .detail-list p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 3px 0 0; }
.managed-card-heading { flex-wrap: wrap; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.inline-actions .button { margin: 0; }
.source-link { width: 100%; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; }
.source-link strong { text-decoration: underline; text-decoration-color: rgba(23, 58, 43, .28); text-underline-offset: 3px; }
.source-link:hover strong, .source-link:focus-visible strong { text-decoration-color: currentColor; }
.source-link:focus-visible { outline: 3px solid rgba(180, 131, 43, .35); outline-offset: 5px; border-radius: 4px; }
.source-dialog-content { display: grid; gap: 18px; }
.source-dialog-content h3 { margin: 4px 0 -6px; }
.source-summary { margin: 0; }
.source-external-link { width: fit-content; text-decoration: none; }
.source-management-actions, .document-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.source-management-actions { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.source-upload-form { display: grid; grid-template-columns: minmax(160px, 1.3fr) minmax(130px, .7fr) minmax(180px, 1fr) auto; align-items: end; gap: 9px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: #faf6ee; }
.source-upload-form input { min-width: 0; }
.source-upload-error { grid-column: 1 / -1; margin: 0; }
.document-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.document-list li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid #eee6da; }
.document-list li:last-child { border-bottom: 0; }
.document-list strong { display: block; color: var(--green); overflow-wrap: anywhere; }
.document-list span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.document-list .document-missing { flex: 0 0 auto; color: var(--danger); text-align: right; }
.family-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.family-group { padding: 14px; border-radius: 13px; background: #faf6ee; }
.family-group h4 { color: var(--gold); margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.family-link { border: 0; padding: 0; color: var(--green); background: transparent; font-weight: 750; text-align: left; }
.family-link:hover { text-decoration: underline; }
.muted-text { color: var(--muted); font-size: 13px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 14px; }
.photo-card { margin: 0; }
.photo-button { width: 100%; border: 0; padding: 0; border-radius: 12px; overflow: hidden; background: #e8e0d2; display: block; }
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; transition: transform .2s ease; }
.photo-button:hover img { transform: scale(1.025); }
.photo-missing { width: 100%; aspect-ratio: 4/3; border-radius: 12px; display: grid; place-items: center; padding: 14px; color: var(--muted); background: #eee7dc; text-align: center; font-size: 12px; }
.photo-card figcaption { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.photo-card-actions { display: flex; gap: 6px; margin-top: 8px; }
.photo-card-actions .button { flex: 1; padding: 7px 9px; font-size: 11px; }
.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kv { padding: 12px; border-radius: 11px; background: #f3ede2; }
.kv span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.kv strong { display: block; margin-top: 3px; color: var(--green); }
.person-notes { color: var(--muted); line-height: 1.6; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid #eee6da; }
.detail-loading { min-height: 260px; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--muted); }
.detail-loading span { width: min(100%, 680px); height: 18px; border-radius: 8px; background: linear-gradient(90deg, #ece4d8, #f8f3eb, #ece4d8); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.detail-loading span:nth-child(2) { width: min(82%, 560px); }
.detail-loading span:nth-child(3) { width: min(63%, 430px); }
.detail-loading p { margin: 10px 0 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 40; max-width: 360px; padding: 13px 16px; color: #fff; background: var(--green); border-radius: 10px; box-shadow: var(--shadow); }

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 22, 16, .62);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(100%, 560px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  border: 1px solid rgba(181, 138, 69, .38);
  border-radius: 20px;
  padding: 26px;
  background: var(--cream-2);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .28);
}
.modal-card-wide { width: min(100%, 780px); }
.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.modal-heading h2 { margin-bottom: 0; font-size: 28px; }
.icon-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--green);
  background: #fff;
  font-size: 24px;
  line-height: 1;
}
.editor-form {
  display: grid;
  gap: 16px;
}
.editor-form label {
  display: grid;
  gap: 7px;
  color: var(--green);
  font-weight: 650;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.checkbox-row {
  grid-template-columns: auto 1fr !important;
  align-items: center;
  justify-content: start;
  width: fit-content;
}
.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}
.form-section {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: #faf6ee;
}
.form-section h3 { margin-bottom: 5px; }
.form-section legend { padding: 0 6px; color: var(--green); font-family: Georgia, serif; font-size: 18px; font-weight: 700; }
.life-event-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.editor-form small { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.4; }
.editor-form select[multiple] { min-height: 132px; }
.form-help {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.field-label { font-weight: 700; }
.is-muted-field { opacity: .72; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding-top: 4px;
}
.detail-hero .button-secondary {
  border: 1px solid rgba(255,255,255,.25);
  color: var(--green);
  background: rgba(255,255,255,.92);
}

.photo-dialog { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 32px; background: rgba(10, 22, 16, .88); backdrop-filter: blur(5px); }
.photo-dialog-figure { margin: 0; max-width: min(1200px, 96vw); max-height: 92vh; display: grid; gap: 12px; justify-items: center; }
.photo-dialog-figure img { max-width: 100%; max-height: calc(92vh - 70px); object-fit: contain; border-radius: 10px; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.photo-dialog-figure figcaption { color: #f4efe7; text-align: center; font-size: 13px; line-height: 1.5; }
.photo-dialog-close { position: fixed; right: 24px; top: 20px; width: 44px; height: 44px; border: 1px solid rgba(255,255,255,.28); border-radius: 50%; color: #fff; background: rgba(255,255,255,.08); font-size: 28px; line-height: 1; }
.photo-dialog-close:hover { background: rgba(255,255,255,.16); }



/* Stamboom */
.tree-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}
.tree-root-field {
  min-width: min(100%, 360px);
  display: grid;
  gap: 6px;
}
.tree-root-field label {
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
}
.tree-root-field select {
  min-height: 43px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 36px 9px 11px;
  color: var(--text);
  background: var(--cream-2);
  font: inherit;
}
.tree-root-field select:focus-visible {
  outline: 3px solid rgba(181, 138, 69, .25);
  outline-offset: 2px;
}
.tree-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tree-secondary {
  border-color: #cdbd9f;
  color: var(--green);
  background: #f5eee2;
}
.tree-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 12px;
}
.tree-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tree-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  background: var(--green);
  box-shadow: inset 0 0 0 3px var(--gold-soft);
}
.tree-legend-line {
  width: 24px;
  height: 0;
  display: inline-block;
  border-top: 2px solid #8ba08f;
}
.tree-legend-line.partner {
  border-color: var(--gold);
  border-top-style: dashed;
}
.tree-status {
  min-height: 20px;
  margin: 0 0 9px;
}
.tree-viewport {
  position: relative;
  min-height: 520px;
  overflow: auto;
  cursor: grab;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)),
    radial-gradient(circle at 1px 1px, rgba(23,58,43,.13) 1px, transparent 0);
  background-size: auto, 24px 24px;
  box-shadow: 0 8px 28px rgba(23, 58, 43, .06);
}
.tree-viewport.is-panning {
  cursor: grabbing;
  user-select: none;
}
.tree-viewport:focus-visible {
  outline: 3px solid rgba(181, 138, 69, .28);
  outline-offset: 3px;
}
.tree-canvas {
  position: relative;
  min-width: 100%;
  width: max-content;
  min-height: 518px;
  padding: 48px 58px 62px;
}
.tree-lines {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}
.tree-parent-line {
  fill: none;
  stroke: #8ba08f;
  stroke-width: 2;
}
.tree-partner-line {
  fill: none;
  stroke: var(--gold);
  stroke-width: 2.2;
  stroke-dasharray: 6 5;
}
.tree-generation {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 0 auto 54px;
  min-width: max-content;
}
.tree-generation:last-child {
  margin-bottom: 0;
}
.tree-generation-label {
  position: sticky;
  left: 12px;
  justify-self: start;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(246,240,228,.9);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .04em;
}
.tree-generation-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  min-width: max-content;
}
.tree-node {
  position: relative;
  z-index: 2;
  width: 210px;
  padding-block: 19px;
}
.tree-person {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: 112px;
  border: 1px solid #d7ccb7;
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  color: var(--text);
  background: #fffdf8;
  box-shadow: 0 6px 18px rgba(23,58,43,.08);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
button.tree-person:hover {
  transform: translateY(-2px);
  border-color: #bda982;
  box-shadow: 0 9px 24px rgba(23,58,43,.12);
}
button.tree-person:focus-visible {
  outline: 3px solid rgba(181,138,69,.35);
  outline-offset: 3px;
}
.tree-person.is-root {
  border: 2px solid var(--gold);
  background:
    linear-gradient(#fffdf8, #fffdf8) padding-box,
    linear-gradient(135deg, var(--gold), var(--green)) border-box;
  box-shadow: 0 10px 28px rgba(181,138,69,.17);
}
.tree-toggle {
  position: absolute;
  left: 50%;
  z-index: 6;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 7px;
  padding: 0;
  color: #fffdf8;
  background: var(--green);
  box-shadow: 0 4px 12px rgba(23,58,43,.14);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  transform: translateX(-50%);
}
.tree-toggle:hover {
  background: #214f3c;
  transform: translateX(-50%) scale(1.06);
}
.tree-toggle:focus-visible {
  outline: 3px solid rgba(181,138,69,.35);
  outline-offset: 2px;
}
.tree-toggle-ancestors { top: 0; }
.tree-toggle-descendants { bottom: 0; }
.tree-toggle.is-blocked {
  color: var(--green);
  background: var(--cream);
}
.tree-person-code {
  display: block;
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
}
.tree-person-name {
  display: block;
  color: var(--green);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
}
.tree-person-life {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.tree-person-role {
  display: inline-flex;
  margin-top: 8px;
  border-radius: 999px;
  padding: 4px 7px;
  color: #4f5e54;
  background: #edf0eb;
  font-size: 10px;
  font-weight: 750;
}
.tree-blocked {
  display: block;
  margin-top: 8px;
  color: #7b5f2f;
  font-size: 11px;
  font-weight: 750;
}
.tree-empty {
  min-width: min(620px, 80vw);
  margin: 88px auto;
}
.tree-loading {
  min-width: min(620px, 80vw);
  margin: 95px auto;
  text-align: center;
  color: var(--muted);
}
.detail-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.detail-hero .button-ghost {
  border: 1px solid rgba(255,255,255,.32);
  color: #fff;
  background: rgba(255,255,255,.09);
}
.detail-hero .button-ghost:hover {
  background: rgba(255,255,255,.16);
}

.sidebar-actions { display: grid; gap: 8px; }
.sidebar-actions .button { width: 100%; }
.sidebar-actions #edit-mode-button.is-active {
  border-color: var(--gold-soft);
  color: var(--green);
  background: var(--gold-soft);
}
.security-banner { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 0 0 22px; padding: 16px 18px; border: 1px solid #c99c49; border-radius: 14px; background: #fff6df; }
.security-banner strong, .security-banner span { display: block; }
.security-banner span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.security-modal-card { max-width: 650px; }
.security-explanation { font-weight: 700; }
.security-steps { padding-left: 22px; line-height: 1.6; }
.two-factor-qr { display: block; width: min(260px, 80vw); height: auto; margin: 16px auto; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.manual-secret { text-align: center; color: var(--muted); line-height: 1.6; }
.manual-secret code { display: inline-block; max-width: 100%; margin-top: 5px; padding: 7px 9px; border-radius: 7px; color: var(--green); background: var(--cream-2); font-weight: 800; letter-spacing: .08em; overflow-wrap: anywhere; user-select: all; }
.security-success { display: grid; gap: 4px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid #8db69d; border-radius: 12px; color: var(--green); background: #edf7f0; }
.security-success span { color: var(--muted); font-size: 13px; }
.recovery-code-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0 20px; }
.recovery-code-list code { display: block; padding: 10px; border: 1px solid var(--border); border-radius: 8px; text-align: center; background: var(--cream-2); font-size: 14px; font-weight: 800; letter-spacing: .05em; user-select: all; }
.danger-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.danger-section h3 { margin: 0; }
.access-panel { margin-bottom: 22px; }
.admin-access-area { margin-top: 22px; }
.access-management-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h3 { margin: 3px 0 0; }
.management-list { display: grid; gap: 10px; }
.management-empty { margin: 4px 0; }
.management-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--cream-2); }
.management-row > div:first-child { min-width: 0; }
.management-row strong, .management-row span { display: block; }
.management-row span { margin-top: 3px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.management-row.is-inactive { opacity: .62; }
.management-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; flex: 0 0 auto; }
.compact-form { display: grid; gap: 11px; padding: 14px; margin-bottom: 16px; border-radius: 12px; background: rgba(23,58,43,.045); }
.compact-form label, .permission-form label { display: grid; gap: 5px; }
.compact-form label > span, .permission-form label > span { color: var(--muted); font-size: 12px; font-weight: 750; }
.permission-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 11px; align-items: end; }
.permission-form .button { min-height: 44px; }
.photo-person-picker { display: grid; gap: 7px; }
.photo-person-picker > label > span { font-weight: 700; }
.checkbox-picker { max-height: 210px; overflow: auto; border: 1px solid var(--border); border-radius: 11px; background: #fff; padding: 5px; }
.checkbox-picker-tall { max-height: 360px; }
.picker-option { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px !important; min-height: 40px; padding: 8px 9px; border-radius: 8px; cursor: pointer; }
.picker-option:hover { background: var(--cream-2); }
.picker-option:has(input:disabled) { cursor: not-allowed; opacity: .58; }
.picker-option input { width: 18px; height: 18px; margin: 0; flex: 0 0 auto; accent-color: var(--green); }
.picker-option span { font-size: 14px; }
.person-request-button { margin-left: auto; }
.history-list { display: grid; gap: 10px; margin-top: 14px; }
.history-entry { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 14px; border: 1px solid var(--border); border-left: 4px solid #6c7748; border-radius: 11px; background: var(--cream-2); }
.history-entry > div:first-child { min-width: 0; }
.history-entry strong, .history-label, .history-meta { display: block; }
.history-label { margin-bottom: 3px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.history-meta { margin-top: 6px; color: var(--muted); font-size: 12px; }
.history-values { margin: 5px 0 0; color: #4b554e; font-size: 13px; overflow-wrap: anywhere; }
.history-action-delete, .history-action-unlink { border-left-color: #8e433b; }
.history-action-create, .history-action-link { border-left-color: #52705a; }
.history-action-restore { border-left-color: #2f6f9f; background: #f3f8fb; }


@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; width: 268px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.is-open { transform: translateX(0); }
  .security-banner { align-items: stretch; flex-direction: column; }
  .recovery-code-list { grid-template-columns: 1fr; }
  .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(10, 22, 16, .4); }
  .mobile-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
  .mobile-brand { display: flex; align-items: center; gap: 9px; color: var(--green); }
  .mobile-brand .brand-logo { width: 36px; height: 36px; }
  .mobile-brand strong, .mobile-brand span { display: block; }
  .mobile-brand span { margin-top: 1px; color: var(--muted); font-size: 10px; }
  .icon-button { border: 1px solid var(--border); background: var(--cream-2); color: var(--green); border-radius: 9px; padding: 8px 11px; font-weight: 700; }
  .main-content { padding-top: 22px; }
  .stats-grid { grid-template-columns: 1fr; }
  .panel-grid, .detail-grid { grid-template-columns: 1fr; }
  .access-management-grid { grid-template-columns: 1fr; }
  .source-upload-form { grid-template-columns: 1fr 1fr; }
  .source-upload-form input[type="file"] { grid-column: 1 / -1; }
  .permission-form { grid-template-columns: 1fr 1fr; }
  .history-entry { align-items: stretch; flex-direction: column; }
  .history-entry .button { align-self: flex-start; }
  .tree-toolbar { align-items: stretch; flex-direction: column; }
  .tree-root-field { min-width: 0; }
  .tree-canvas { padding-inline: 24px; }
  .tree-node { width: 190px; }
  .tree-person { width: 100%; }

  .detail-card.full-width { grid-column: auto; }
  .dashboard-search { grid-template-columns: 1fr; gap: 16px; }
  .detail-nav { top: 8px; }
}

@media (max-width: 620px) {
  .login-shell { padding: 16px; }
  .login-card { padding: 26px 22px; border-radius: 18px; }
  .main-content { padding: 18px 15px 34px; }
  .page-heading-row { align-items: start; flex-direction: column; }
  .page-heading-actions { width: 100%; justify-content: space-between; }
  .form-grid, .life-event-grid { grid-template-columns: 1fr; }
  .modal-shell { padding: 12px; }
  .modal-card { max-height: calc(100vh - 24px); padding: 21px 18px; border-radius: 17px; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dashboard-search-form { grid-template-columns: 1fr; }
  .person-card { align-items: flex-start; flex-wrap: wrap; }
  .person-summary { min-width: calc(100% - 64px); }
  .access-badge { margin-left: 60px; }
  .person-request-button { margin-left: 60px; }
  .management-row, .management-row-wrap { align-items: flex-start; flex-direction: column; }
  .management-actions { justify-content: flex-start; }
  .source-upload-form { grid-template-columns: 1fr; }
  .source-upload-form input[type="file"], .source-upload-error { grid-column: auto; }
  .document-list li { align-items: flex-start; flex-direction: column; }
  .permission-form { grid-template-columns: 1fr; }
  .detail-hero { grid-template-columns: 1fr; padding: 22px; }
  .profile-photo { width: 110px; height: 110px; grid-row: 1; }
  .family-groups, .kv-grid { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-dialog { padding: 20px 12px; }
  .photo-dialog-close { right: 12px; top: 12px; }
  .tree-toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .tree-generation-row { gap: 18px; }
  .tree-node { width: 172px; }
  .tree-person { width: 100%; min-height: 106px; padding: 12px; }
  .tree-canvas { padding: 26px 18px 38px; }
}
