/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --brand-1:      #7c8bfa;   /* light indigo — gradients, subtle accents */
  --brand-2:      #5b6ef0;   /* primary indigo — buttons, active states */
  --brand-3:      #4453d8;   /* dark indigo — hover/pressed */

  --bg-canvas:    #f4f5fb;   /* lavender-tinted page background */
  --card-bg:      #ffffff;
  --card-border:  #eaecf2;
  --card-shadow:  0 1px 2px rgba(30,35,80,.04), 0 10px 28px -14px rgba(30,35,80,.10);

  --text-main:    #2a3547;
  --text-soft:    #67718a;
  --text-faint:   #9aa1b5;

  --danger:       #f16a5c;   /* soft coral, not stark red */
  --danger-dark:  #d9503f;
  --success:      #2ca58d;
  --success-dark: #228a72;
  --gold:         #ffa534;
  --wife-tag:     #f16a5c;

  /* pastel accent surfaces — stat-style highlights, empty states, pickers */
  --pastel-peach:  #fde7cf;
  --pastel-peach-ink: #d97e2c;
  --pastel-blue:   #dbeafc;
  --pastel-blue-ink: #2f7dd1;
  --pastel-pink:   #fde1ea;
  --pastel-pink-ink: #d9507a;
  --pastel-mint:   #d7f5ec;
  --pastel-mint-ink: #1f9a7d;
  --pastel-lavender: #e6e6fb;
  --pastel-lavender-ink: #5b5fd0;

  --font-display: 'Poppins', 'Nunito Sans', sans-serif;
  --font-body:    'Nunito Sans', 'Poppins', sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 8px;
}

/* ============================================================
   VIEW TRANSITIONS — smooth cross-fades between pages and HTMX swaps.
   Pure progressive enhancement: browsers that don't support the View
   Transitions API just skip straight to the old instant swap, no fallback
   code needed. Costs nothing server-side — this is 100% client-side.
   ============================================================ */
@view-transition {
  navigation: auto; /* smooth cross-fade on normal full-page navigations too */
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.18s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
::view-transition-old(root) {
  animation-name: family-register-fade-out;
}
::view-transition-new(root) {
  animation-name: family-register-fade-in;
}
@keyframes family-register-fade-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-4px); }
}
@keyframes family-register-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }

body {
  background: var(--bg-canvas);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--brand-1); color: #fff; }

:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

/* ============================================================
   APP SHELL — sidenav + topbar + content
   ============================================================ */
body.with-sidenav { display: flex; min-height: 100vh; }

.sidenav {
  width: 250px;
  min-height: 100vh;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--card-border);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  padding: 0 0 20px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}

.sidenav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--text-main);
  border-bottom: 1px solid var(--card-border);
}
.brand-text { line-height: 1.2; }

.sidenav-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
}
.profile-name { font-weight: 600; font-size: 13.5px; color: var(--text-main); }

.sidenav-list { display: flex; flex-direction: column; padding: 14px 12px; gap: 3px; flex: 1; }

.sidenav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  position: relative;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.sidenav-link:hover { background: var(--pastel-lavender); color: var(--brand-3); text-decoration: none; }
.sidenav-link.active { background: var(--brand-2); color: #fff; box-shadow: 0 4px 10px -4px rgba(91,110,240,.55); }
.sidenav-link.as-button { font-family: var(--font-body); }
.nav-ico { font-size: 14px; width: 16px; text-align: center; opacity: .85; }

.sidenav-foot { padding: 10px 12px; border-top: 1px solid var(--card-border); display: flex; flex-direction: column; gap: 2px; }
.sidenav-foot form { margin: 0; }

/* ---- main column ---- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 26px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-title h1 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0; color: var(--text-main); }

.topbar-search { flex: 1; max-width: 340px; display: flex; align-items: center; gap: 8px; background: #f4f5f7; border-radius: 20px; padding: 8px 16px; }
.topbar-search .search-ico { color: var(--text-faint); font-size: 14px; }
.topbar-search input {
  border: none; background: transparent; outline: none;
  font-family: var(--font-body); font-size: 13.5px; color: var(--text-main);
  width: 100%;
}

.topbar-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.icon-btn {
  position: relative;
  color: var(--text-soft);
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.icon-btn:hover { color: var(--brand-2); text-decoration: none; }
.icon-badge {
  position: absolute; top: -6px; right: -8px;
  min-width: 15px; height: 15px;
  background: var(--danger);
  color: #fff;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

.app-content { padding: 24px 26px 50px; }

.page-banner {
  background: linear-gradient(90deg, var(--pastel-blue) 0%, #eef3fd 100%);
  border-radius: var(--radius);
  padding: 22px 28px;
  margin-bottom: 20px;
}
.page-banner-title { font-family: var(--font-display); font-size: 21px; font-weight: 700; margin: 0 0 4px; color: var(--text-main); }
.page-banner-trail { font-family: var(--font-body); font-size: 13px; color: var(--text-soft); }
.page-banner-trail .dot { color: var(--text-faint); margin: 0 2px; }

/* ============================================================
   CARDS (formerly "ledger")
   ============================================================ */
.card, .ledger {
  background: var(--card-bg);
  color: var(--text-main);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
}
.card-pad, .ledger-pad { padding: 22px 24px; }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h3 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 3px; color: var(--text-main); }
.card-lede { font-size: 12.5px; color: var(--text-faint); }

.dash-grid { display: grid; grid-template-columns: 340px 1fr; gap: 22px; align-items: start; }
.dash-grid > .card:only-child { grid-column: 1 / -1; }
.main-card-full { min-height: 60vh; }
.settings-stack { display: flex; flex-direction: column; gap: 20px; max-width: 640px; }

.style-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.style-option {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  position: relative;
}
.style-option input { position: absolute; top: 12px; right: 12px; width: auto; }
.style-option.active { border: 2px solid var(--brand-2); background: #f6fbfd; }
.style-option-title { font-family: var(--font-display); font-weight: 600; font-size: 13.5px; color: var(--text-main); }
.style-option-desc { font-size: 12px; color: var(--text-faint); line-height: 1.4; }

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  body.with-sidenav { flex-direction: column; }
  .sidenav { width: 100%; height: auto; min-height: 0; position: relative; }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  background: var(--brand-2);
  color: #fff;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-3); transform: translateY(-1px); box-shadow: 0 4px 10px -4px rgba(68,83,216,.45); }
.btn:active { transform: translateY(0); }
.btn.btn-primary { background: var(--brand-2); }
.btn.btn-primary:hover { background: var(--brand-3); }
.btn.btn-seal { background: var(--danger); }
.btn.btn-seal:hover { background: var(--danger-dark); }
.btn.btn-ghost { background: transparent; color: var(--brand-2); border-color: var(--brand-1); }
.btn.btn-ghost:hover { background: var(--pastel-lavender); color: var(--brand-3); box-shadow: none; transform: none; }
.btn.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.btn-danger:hover { background: var(--danger); color: #fff; }
.btn.btn-danger-solid { background: var(--danger); }
.btn.btn-danger-solid:hover { background: var(--danger-dark); }
.btn.btn-success { background: var(--success); }
.btn.btn-success:hover { background: var(--success-dark); }
.btn.btn-small { font-size: 12.5px; padding: 7px 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================================================
   REGISTER LIST
   ============================================================ */
.person-list { list-style: none; margin: 0; padding: 0; max-height: 62vh; overflow-y: auto; }

.person-row {
  border-radius: var(--radius-sm);
  border-bottom: 1px solid #f0f1f3;
}
.person-row:hover, .person-row.active { background: #f6f8fa; }

.person-row .name { font-weight: 600; font-size: 13.5px; color: var(--text-main); }
.person-row .meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); }

.person-row-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.person-row-link:hover { text-decoration: none; }

/* The dedicated Family Register page has room to spare — lay people out as
   a responsive grid of cards instead of one long narrow column. */
.filters-panel {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  margin: 14px 0;
  padding: 10px 14px;
}
.filters-panel summary {
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-soft);
  list-style: none;
}
.filters-panel summary::-webkit-details-marker { display: none; }
.filters-panel summary::before { content: '▸ '; color: var(--text-faint); }
.filters-panel[open] summary::before { content: '▾ '; }
.filters-form {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  align-items: flex-end;
}
.filters-form .field { min-width: 150px; flex: 1 1 150px; }

.person-list-full {
  max-height: none;
  overflow: visible;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 4px 10px;
}
.person-list-full .person-row { border-bottom: none; border-radius: var(--radius-sm); }
.person-list-full .person-row:hover { background: #f6f8fa; }

/* ============================================================
   SEAL AVATAR (signature element, kept from the ledger motif)
   ============================================================ */
.seal {
  --size: 38px;
  width: var(--size);
  height: var(--size);
  min-width: var(--size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2) 65%, var(--brand-3) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--size) * 0.42);
  box-shadow: 0 2px 6px -2px rgba(68,83,216,.45);
  position: relative;
  flex-shrink: 0;
}
.seal.seal-lg { --size: 60px; }
.seal.seal-tiny { --size: 26px; font-size: 12px; }
.seal.seal-profile { --size: 34px; }
.seal.seal-female { background: linear-gradient(135deg, #ff8aa0, var(--danger) 65%, var(--danger-dark) 100%); }
.seal.seal-photo { background: var(--card-border); padding: 0; overflow: hidden; }
.seal.seal-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }

/* ============================================================
   MAIN PANEL / PERSON DETAIL
   ============================================================ */
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--card-border);
}

.person-identity { display: flex; gap: 16px; align-items: center; }

.person-identity h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text-main);
}

.person-identity .life { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); }
.birth-name-note { font-size: 12.5px; color: var(--text-soft); font-style: italic; margin: 1px 0 2px; }

.gen-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 10px;
  border: none;
  border-radius: 20px;
  background: var(--pastel-lavender);
  color: var(--pastel-lavender-ink);
  margin-top: 4px;
}

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 20px;
  margin-bottom: 20px;
}
.fact { border-left: 2px solid var(--pastel-lavender); padding-left: 10px; }
.fact .label { font-family: var(--font-body); font-size: 11.5px; font-weight: 600; color: var(--text-faint); }
.fact .value { font-size: 14px; margin-top: 2px; color: var(--text-main); }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 26px 0 12px;
}
.section-heading h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}
.section-heading h3::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--danger);
  border-radius: 50%;
  display: inline-block;
}

.union-card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #fafbfc;
}
.union-card .union-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.wife-order {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--pastel-pink-ink);
  background: var(--pastel-pink);
  padding: 3px 9px;
  border-radius: 10px;
}
.order-btn {
  border: 1px solid var(--card-border);
  background: #fff;
  color: var(--text-faint);
  border-radius: 4px;
  font-size: 9px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  margin-left: 3px;
}
.order-btn:hover { color: var(--brand-2); border-color: var(--brand-2); }
.union-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-top: 3px; }

.children-list { list-style: none; margin: 10px 0 0; padding: 12px 0 0; border-top: 1px dashed var(--card-border); display: flex; flex-wrap: wrap; gap: 8px; }
.child-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 5px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
}
.child-chip:hover { background: #f6f8fa; }
.child-chip .seal { --size: 22px; }
.birth-order-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  background: #f0f2f5;
  border-radius: 8px;
  min-width: 15px;
  height: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.chip-unlink {
  border: none; background: transparent; color: var(--text-faint);
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0 4px;
  margin-left: 2px;
}
.chip-unlink:hover { color: var(--danger); }

.empty-note { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); font-style: normal; }

.notes-block { font-size: 13.5px; color: var(--text-main); background: #fafbfc; border-left: 3px solid var(--brand-2); padding: 10px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.lock-hint { font-family: var(--font-body); font-size: 12.5px; color: var(--text-soft); }
.owner-note { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.owner-note.mine { color: var(--success-dark); }

/* welcome state */
.welcome { text-align: center; padding: 60px 20px; }
.welcome h2 { font-family: var(--font-display); font-size: 21px; margin-bottom: 8px; color: var(--text-main); }
.welcome p { color: var(--text-soft); max-width: 440px; margin: 0 auto 20px; }

/* ============================================================
   FORMS
   ============================================================ */
form.record-form { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; min-width: 0; }
.form-row .field { min-width: 0; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-family: var(--font-body); font-size: 13px; font-weight: 600; color: var(--text-main); }
.field input, .field select, .field textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 11px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-main);
  min-width: 0;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand-1); outline-offset: 0; border-color: transparent; }
.field textarea { resize: vertical; min-height: 64px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin: 0 0 4px; color: var(--text-main); }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-shell { max-width: 420px; margin: 40px auto; }
.auth-heading { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 0 0 4px; color: var(--text-main); }
.auth-lede { color: var(--text-soft); font-size: 13.5px; margin-bottom: 20px; }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--text-soft); }

/* ============================================================
   ROLE BADGES / ALERTS / REQUESTS / ACCOUNTS TABLE
   ============================================================ */
.role-badge {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  color: var(--text-soft);
  background: var(--pastel-lavender);
}
.role-badge.role-super_admin { background: var(--pastel-pink); color: var(--pastel-pink-ink); }
.role-badge.role-admin { background: var(--pastel-mint); color: var(--pastel-mint-ink); }
.role-badge.role-regular { background: #eef0f5; color: var(--text-soft); }

.request-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px; height: 16px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 9.5px;
  padding: 0 4px;
  font-family: var(--font-mono);
  margin-left: 3px;
}

.alert {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  border-left: 3px solid var(--danger);
  background: #fdeceb;
  color: #9c2b30;
}
.alert.alert-ok { border-left-color: var(--success); background: #e8f6f1; color: #1e6f5c; }

.request-card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #fafbfc;
}
.request-card .request-line { font-size: 13.5px; margin-bottom: 4px; }
.request-card .request-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); margin-bottom: 10px; }

.user-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.user-table th { text-align: left; font-family: var(--font-body); font-size: 12.5px; font-weight: 700; color: var(--text-soft); padding: 10px 10px; border-bottom: 1px solid var(--card-border); }
.user-table td { padding: 12px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.user-table tr:hover td { background: #f9fafb; }

@media (max-width: 640px) {
  .user-table thead { display: none; }
  .user-table, .user-table tbody, .user-table tr, .user-table td { display: block; width: 100%; }
  .user-table tr { border: 1px solid var(--card-border); border-radius: var(--radius-sm); margin-bottom: 10px; padding: 4px 10px; }
  .user-table td { border-bottom: none; padding: 8px 4px; }
  .user-table td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-faint);
    margin-bottom: 2px;
  }
  .user-table td:empty { display: none; }
}

/* ============================================================
   FAMILY TREE
   ============================================================ */
.tree-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; max-width: 100%; overflow-x: auto; }

.ancestor-trail { font-family: var(--font-body); font-size: 12.5px; font-weight: 600; color: var(--text-soft); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ancestor-trail a { text-decoration: none; border-bottom: 1px dotted var(--text-faint); cursor: pointer; color: var(--text-soft); }
.ancestor-trail a:hover { color: var(--danger); border-bottom-color: var(--danger); }

.tree-scroll {
  overflow: hidden;
  height: 72vh;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, #fafbfc 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(#fafbfc 1px, transparent 1px) 0 0 / 24px 24px,
    #fff;
  cursor: grab;
  position: relative;
  touch-action: none;
}
.tree-scroll:active { cursor: grabbing; }

.tree-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; min-width: 0; max-width: 100%; overflow-x: auto; }

.depth-toolbar { display: flex; align-items: center; gap: 2px; background: var(--pastel-lavender); border-radius: 20px; padding: 3px; }
.depth-btn {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  padding: 5px 12px;
  border-radius: 16px;
  cursor: pointer;
  text-decoration: none;
}
.depth-btn:hover { color: var(--brand-3); text-decoration: none; }
.depth-btn.active { background: #fff; color: var(--brand-2); box-shadow: 0 1px 3px rgba(20,30,40,.12); }

.zoom-toolbar { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.zoom-btn {
  border: 1px solid var(--card-border);
  background: #fff;
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  width: 26px; height: 26px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.zoom-btn:hover { color: var(--brand-2); border-color: var(--brand-2); }
.zoom-btn.zoom-btn-reset { width: auto; padding: 0 10px; font-size: 12px; font-family: var(--font-body); font-weight: 600; }
.zoom-btn.zoom-btn-reset.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }

[data-rearrange="on"] .tree-node-wrap[id] { cursor: grab; }
[data-rearrange="on"] .tree-node-wrap[id]:hover { outline: 2px dashed var(--brand-1); outline-offset: 6px; border-radius: 14px; }
.tree-node-wrap.dragging { cursor: grabbing !important; opacity: .85; }
.tree-node-wrap.dragging .person-card { cursor: grabbing !important; }
.zoom-level { font-family: var(--font-body); font-size: 12px; font-weight: 600; color: var(--text-faint); min-width: 38px; text-align: center; }

#tree-zoom-layer { position: relative; display: inline-block; transform-origin: 0 0; }
#tree-lines { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }
.tree-link { stroke: var(--text-faint); stroke-width: 2; fill: none; }

/* ============================================================
   FAMILY REPORT VIEW
   ============================================================ */
.report-section { margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--card-border); }
.report-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.report-section-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--text-main); margin: 0 0 4px; }
.report-section-main .report-section-title { font-size: 19px; }

.report-viewport { position: relative; overflow: auto; padding: 20px 10px; }
.report-columns { display: flex; align-items: center; justify-content: center; gap: 90px; position: relative; min-height: 160px; }
.report-lines-svg { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }

.report-col { display: flex; flex-direction: column; justify-content: center; gap: 22px; z-index: 1; }
.report-focus-col { z-index: 1; }

.report-group { display: flex; flex-direction: column; }
.report-group .report-row { border-radius: 0; }
.report-group .report-row:first-child { border-radius: 10px 10px 0 0; }
.report-group .report-row:last-child { border-radius: 0 0 10px 10px; border-top: none; }
.report-group .report-row:only-child { border-radius: 10px; }

.report-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
  padding: 9px 14px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.report-row:hover { filter: brightness(0.98); }
.report-row .seal { --size: 32px; }
.report-row-m { background: #eaf4fb; border-color: #bcdcf2; }
.report-row-f { background: #fdecf1; border-color: #f3bdd1; }
.report-row-focus {
  background: #fff;
  border: 2px solid var(--brand-2);
  min-width: 250px;
  cursor: default;
}
.report-name { font-family: var(--font-display); font-weight: 600; font-size: 13.5px; color: var(--text-main); }
.report-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); margin-top: 1px; }

@media (max-width: 760px) {
  .report-columns { flex-direction: column; gap: 40px; }
}

/* ---- Tree style variants, chosen by the Super Admin in App settings ---- */

[data-tree-style="curved"] .person-card { border-radius: 16px; border-color: var(--brand-1); }
[data-tree-style="curved"] .tree-link { stroke: var(--brand-2); stroke-width: 1.5; }
[data-tree-style="curved"] .couple-link { background: none; }

[data-tree-style="minimal"] .person-card {
  flex-direction: column;
  gap: 4px;
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 4px;
  min-width: 88px;
  text-align: center;
}
[data-tree-style="minimal"] .person-card:hover { border: none; box-shadow: none; background: #f6f8fa; border-radius: 12px; }
[data-tree-style="minimal"] .person-card .pyears { display: none; }
[data-tree-style="minimal"] .person-card .pname { font-size: 12px; }
[data-tree-style="minimal"] .tree-link { stroke: var(--card-border); stroke-width: 1; }
[data-tree-style="minimal"] .spouse-tag { position: static; margin-top: 2px; }
#tree-cards { position: relative; margin: 24px; }

.branch-collapsed {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--brand-2);
  background: #eef8fb;
  border: 1px dashed var(--brand-1);
  border-radius: 14px;
  padding: 5px 12px;
  cursor: pointer;
  margin-top: 2px;
  white-space: nowrap;
}
.branch-collapsed:hover { background: #dff3f9; }

.tree-node-wrap { display: flex; flex-direction: column; align-items: center; }

.person-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 8px 12px 8px 8px;
  cursor: pointer;
  min-width: 168px;
  transition: box-shadow .12s ease, border-color .12s ease;
}
.person-card:hover { border-color: var(--brand-2); box-shadow: 0 4px 10px -4px rgba(20,30,40,.25); }
.person-card .seal { --size: 30px; }
.person-card .pname { font-size: 13px; font-weight: 600; line-height: 1.25; color: var(--text-main); }
.person-card .pyears { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }

.unions-row { display: flex; align-items: flex-start; gap: 34px; }

.couple-unit { display: flex; flex-direction: column; align-items: center; }

.couple-row { display: flex; align-items: center; gap: 0; position: relative; }
.couple-link {
  /* Invisible spacer — the actual husband-wife line is drawn by D3/SVG
     between the two cards' real rendered positions, in tree.php's script. */
  width: 26px;
  height: 2px;
  flex-shrink: 0;
}

/* Used only for a collapsed branch's simple single connector down to the
   "N more descendants" button — real branches get their lines from JS/SVG. */
.descend-line { width: 2px; background: var(--text-faint); height: 24px; margin: 0 auto; }
.descend-spacer { height: 24px; }
.branch-row { display: flex; gap: 30px; padding-top: 4px; position: relative; }
.branch-item { display: flex; flex-direction: column; align-items: center; padding-top: 20px; position: relative; }

.spouse-tag {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--pastel-pink-ink);
  background: var(--pastel-pink);
  padding: 2px 8px;
  border-radius: 8px;
  margin-top: 3px;
}

.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

@media (max-width: 600px) {
  .app-content { padding: 16px; }
  .fact-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 12px 16px; gap: 12px; }
  .topbar-search { display: none; }

  /* Deterministic stacking rather than relying on flex-wrap to decide —
     that computation is exactly the kind of thing Safari and Chrome have
     historically disagreed on for nested flex containers, so this forces
     an unambiguous vertical layout instead of hoping wrap kicks in. */
  .tree-toolbar { flex-direction: column; align-items: stretch; }
  .tree-controls { flex-direction: column; align-items: stretch; gap: 10px; }
  .depth-toolbar, .zoom-toolbar { max-width: 100%; overflow-x: auto; }
}
