/* ---------- design tokens ---------- */
:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #faf6ee;
  --ink: #2e2a24;
  --ink-soft: #6b6358;
  --line: #e3dccd;
  --accent: #3f6b4f;       /* forest green */
  --accent-dark: #2f5340;
  --accent-soft: #e7efe8;
  --gold: #b9893f;
  --danger: #b4452f;
  --shadow: 0 2px 8px rgba(46, 42, 36, 0.08), 0 8px 24px rgba(46, 42, 36, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label { font-size: 13px; color: var(--ink-soft); }

/* ---------- buttons ---------- */
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
}
.primary-btn:hover { background: var(--accent-dark); }
.primary-btn.small { padding: 7px 12px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--ink-soft);
}
.ghost-btn:hover { background: var(--surface-2); }

.danger-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
}
.danger-btn:hover { background: var(--danger); color: #fff; }

/* ---------- auth ---------- */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 30% 20%, #e9efe6, var(--bg));
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-brand { font-size: 40px; }
.auth-card h1 { font-size: 28px; margin: 6px 0 4px; }
.auth-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 22px; }
.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.google-btn:hover { background: var(--surface-2); }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--ink-soft);
  font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}
.email-form { display: flex; flex-direction: column; gap: 10px; }
.auth-toggle { font-size: 13px; color: var(--ink-soft); margin-top: 14px; }
.auth-toggle a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-error {
  margin-top: 14px;
  background: #f7e4df;
  color: var(--danger);
  border-radius: 8px;
  padding: 9px;
  font-size: 13px;
}
.google-note {
  margin-top: 14px; font-size: 12px; color: var(--ink-soft);
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: 8px; padding: 9px;
}

/* ---------- app shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600; }
.brand span { vertical-align: middle; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--accent-soft); color: var(--accent-dark); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.user-chip img {
  width: 30px; height: 30px; border-radius: 50%;
  object-fit: cover; background: var(--accent-soft);
  border: 1px solid var(--line);
}
.user-chip img:not([src]), .user-chip img[src=""] { display: none; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* ---------- tree ---------- */
.tree-toolbar, .dir-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tree-toolbar select { width: auto; min-width: 180px; display: inline-block; }
.tree-toolbar label { display: flex; align-items: center; gap: 8px; }
.hint { font-size: 12px; color: var(--ink-soft); }

.tree-canvas {
  /* the canvas is the viewport for the graph: overflow hidden so dragging
     moves a transformed inner layer, not scrollbars */
  overflow: hidden;
  padding: 0;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 460px;
  height: calc(100vh - 210px);
  cursor: grab;
}

/* The tree sizes to its content and centres when it fits. width:max-content is
   what makes the canvas scrollable to the *left* edge too — otherwise a
   centred flex row that overflows clips its start unreachably. */
.tree {
  width: max-content;
  margin-left: auto;
  margin-right: auto;
}

/* nested-list tree with connector lines */
.tree ul {
  display: flex;
  justify-content: center;
  padding-top: 22px;
  position: relative;
  list-style: none;
}
.tree li {
  list-style: none;
  position: relative;
  padding: 22px 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
/* vertical + horizontal connectors */
.tree li::before, .tree li::after {
  content: '';
  position: absolute;
  top: 0;
  width: 50%;
  height: 22px;
  border-top: 2px solid var(--line);
}
.tree li::before { left: 0; border-right: 2px solid var(--line); }
.tree li::after { right: 0; }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:first-child::before, .tree li:last-child::after { border: none; }
.tree li:last-child::before { border-right: 2px solid var(--line); }
.tree ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  height: 22px;
  border-left: 2px solid var(--line);
}
.tree > ul { padding-top: 0; }
.tree > ul::before { display: none; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree > ul > li { padding-top: 0; }

/* a couple unit */
.couple { display: flex; align-items: stretch; gap: 0; }
.couple .union {
  width: 18px;
  align-self: center;
  border-top: 2px solid var(--gold);
}

.node {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 150px;
  box-shadow: var(--shadow);
  transition: transform .08s ease, border-color .08s ease;
}
.node:hover { transform: translateY(-1px); border-color: var(--accent); }
.node.spouse-node { border-style: dashed; }
.node.deceased { opacity: .82; }
.node-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--accent-dark); font-size: 14px;
}
.node-info { min-width: 0; }
.node-name { font-weight: 600; font-size: 13px; line-height: 1.25; }
.node-meta { font-size: 11px; color: var(--ink-soft); }

/* ---------- directory ---------- */
.dir-toolbar input { max-width: 360px; }

/* The directory is rendered as a sortable table inside #dir-grid. (The
   element keeps its old id so we don't have to chase the reference around.)
   In spreadsheet mode the scroll container does both axes — that's what
   makes the sticky header (top) and sticky Name column (left) work. */
.dir-table-scroll {
  overflow: auto;
  max-height: calc(100vh - 240px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dir-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dir-table thead th {
  text-align: left;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.dir-table th.sortable { cursor: pointer; user-select: none; }
.dir-table th.sortable:hover { color: var(--accent); }
.dir-table th.sort-active { color: var(--accent-dark); }
.dir-table .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  opacity: 0.7;
}
.dir-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--surface-2);
  vertical-align: middle;
}
.dir-table tbody tr { cursor: pointer; transition: background 0.08s ease; }
.dir-table tbody tr:hover { background: var(--accent-soft); }
.dir-table tbody tr:last-child td { border-bottom: none; }

.dir-name-cell { display: flex; align-items: center; gap: 10px; }
.dir-name-inner { min-width: 0; }
.dir-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.dir-sub { font-size: 11px; color: var(--ink-soft); }
.dir-row-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-dark);
  border: 1px solid var(--line);
  object-fit: cover;
  flex-shrink: 0;
}
.dir-gen-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.dir-contact a {
  text-decoration: none;
  margin-right: 4px;
  font-size: 14px;
}
.dir-contact a:hover { opacity: 0.6; }

/* -------- spreadsheet mode -------- */

.dir-sheet td, .dir-sheet th {
  white-space: nowrap;
  min-width: 110px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header row sticks to the top while scrolling. */
.dir-sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
}

/* Name column sticks to the left edge. */
.dir-sheet .dir-sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  min-width: 200px;
  max-width: 240px;
  /* Soft shadow so scrolling content doesn't blur into the sticky column. */
  box-shadow: 6px 0 8px -6px rgba(46, 42, 36, 0.18);
}
.dir-sheet thead .dir-sticky-col {
  z-index: 3;                /* corner cell: sticky on both axes */
  background: var(--surface-2);
}
.dir-sheet tbody tr:hover .dir-sticky-col {
  background: var(--accent-soft);
}

/* Cells the user can click to edit. */
.dir-sheet td.editable { cursor: text; position: relative; }
.dir-sheet td.editable:hover { background: var(--accent-soft); }
.dir-sheet .dir-name.editable {
  cursor: text;
  padding: 2px 5px;
  border-radius: 4px;
  display: inline-block;
}
.dir-sheet .dir-name.editable:hover { background: var(--accent-soft); }

/* Avatar gets its own hit area (opens the full modal). */
.dir-avatar-clickable { cursor: pointer; transition: transform .12s ease; }
.dir-avatar-clickable:hover { transform: scale(1.08); border-color: var(--accent); }

/* The inline editor that replaces a cell's content while editing. */
.cell-edit {
  width: 100%;
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 2px rgba(63, 107, 79, 0.18);
}
.cell-edit-check { width: 18px; height: 18px; padding: 0; box-shadow: none; }

.dir-empty { color: var(--ink-soft); }
.dir-living-yes { color: var(--accent); font-weight: 600; }
.dir-living-no { color: var(--ink-soft); font-style: italic; }

/* #dir-grid is now just a plain block wrapper around the table — let it
   take the full width of its parent, not the legacy 260px grid column. */
.dir-grid { display: block; width: 100%; }
.dir-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s ease, border-color .08s ease;
}
.dir-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.dir-card-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.dir-card-head .node-avatar { width: 46px; height: 46px; font-size: 16px; }
.dir-card h3 { font-size: 16px; }
.dir-card .sub { font-size: 12px; color: var(--ink-soft); }
.dir-line { font-size: 13px; display: flex; gap: 7px; padding: 3px 0; color: var(--ink); }
.dir-line .ic { width: 16px; text-align: center; flex-shrink: 0; }
.dir-line a { color: var(--accent); text-decoration: none; }
.dir-line a:hover { text-decoration: underline; }
.dir-added { margin-top: 10px; font-size: 11px; color: var(--ink-soft); border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(46, 42, 36, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.modal-head h2 { font-size: 18px; }
.modal-close {
  background: transparent; border: none; font-size: 22px;
  color: var(--ink-soft); line-height: 1;
}
.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--surface-2);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 4px; }
.field textarea { resize: vertical; min-height: 64px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* view mode */
.person-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.person-hero .node-avatar { width: 64px; height: 64px; font-size: 22px; }
.person-hero h2 { font-size: 22px; }
.person-hero .sub { color: var(--ink-soft); font-size: 13px; }
.detail-row { display: flex; gap: 10px; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--surface-2); }
.detail-row .k { color: var(--ink-soft); width: 110px; flex-shrink: 0; font-size: 13px; }
.detail-row a { color: var(--accent); text-decoration: none; }

.rel-section { margin-top: 18px; }
.rel-section h3 { font-size: 14px; margin-bottom: 8px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.rel-group { margin-bottom: 12px; }
.rel-group-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.rel-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 4px 6px 4px 10px;
  font-size: 13px; margin: 0 6px 6px 0;
}
.rel-chip .rel-remove {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.rel-chip .rel-remove:hover { color: var(--danger); }

/* Marriage date suffix on spouse chips — click to edit. */
.rel-chip .rel-suffix {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid #cfe0d2;
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  font-family: inherit;
}
.rel-chip .rel-suffix:hover { background: var(--accent); color: #fff; }
.rel-add { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.rel-add select { flex: 1; }
.link-btn {
  background: transparent; border: 1px dashed var(--line);
  color: var(--accent); border-radius: 8px; padding: 5px 10px; font-size: 13px;
}
.link-btn:hover { background: var(--accent-soft); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state p { margin-bottom: 14px; }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); }

/* ---------- family switcher ---------- */
.family-switch select {
  width: auto;
  min-width: 170px;
  font-weight: 600;
  background: var(--surface-2);
}

/* ---------- onboarding ---------- */
.onboard-wrap { max-width: 760px; margin: 30px auto; text-align: center; }
.onboard-wrap h2 { font-size: 26px; margin-bottom: 6px; }
.onboard-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 26px;
  text-align: left;
}
.onboard-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.onboard-card h3 { font-size: 18px; }
.onboard-card p { font-size: 13px; color: var(--ink-soft); }
.onboard-card .primary-btn { margin-top: auto; }

.pending-list {
  margin-top: 26px;
  text-align: left;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.pending-list h4 { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.pending-row { font-size: 14px; padding: 4px 0; }

/* ---------- family / members panel ---------- */
.family-panel { max-width: 720px; margin: 0 auto; }
.fam-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.fam-header h2 { font-size: 24px; }
.fam-sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 8px; }
.fam-head-row { margin-bottom: 18px; min-height: 26px; }
.fam-head-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(120deg, #f3e7d6, var(--accent-soft));
  border: 1px solid var(--gold);
  color: var(--accent-dark);
  border-radius: 18px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.fam-head-badge:hover { background: var(--gold); color: #fff; }
.fam-head-empty { font-size: 12px; }

.invite-expiry {
  margin-left: 10px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 10px;
  text-transform: none;
  letter-spacing: 0;
}
.invite-expiry.expiry-ok   { background: var(--accent-soft); color: var(--accent-dark); }
.invite-expiry.expiry-warn { background: #f6e8cc; color: #8a6a23; }
.invite-expiry.expiry-bad  { background: #f7e0db; color: var(--danger); }

.invite-box {
  background: var(--accent-soft);
  border: 1px solid #cfe0d2;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
}
.invite-box .label { font-size: 12px; color: var(--accent-dark); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.invite-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.invite-code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 17px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  letter-spacing: .06em;
}

.member-section h3 {
  font-size: 13px; color: var(--ink-soft); text-transform: uppercase;
  letter-spacing: .04em; margin: 22px 0 10px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.member-row .node-avatar { width: 40px; height: 40px; font-size: 15px; }
.member-info { flex: 1; min-width: 0; }
.member-info .nm { font-weight: 600; font-size: 14px; }
.member-info .em { font-size: 12px; color: var(--ink-soft); }
.member-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge.admin { background: var(--gold); color: #fff; }
.badge.you { background: var(--accent-soft); color: var(--accent-dark); }
.badge.pending { background: #f0e2c8; color: #8a6a23; }

.member-seen { color: var(--ink-soft); font-size: 11px; }

/* ---------- activity feed ---------- */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.activity-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background .1s ease, border-color .1s ease;
}
.activity-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.activity-item:not([data-person-id]) { cursor: default; }
.activity-item:not([data-person-id]):hover { background: var(--surface); border-color: var(--line); }
.activity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  justify-self: center;
}
.activity-text { color: var(--ink); }
.activity-text em { font-style: normal; color: var(--accent-dark); font-weight: 600; }
.activity-time { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }

/* ---------- "Is this you?" identity prompt ---------- */
.id-prompt-banner {
  background: var(--accent-soft);
  border: 1px solid #cfe0d2;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--accent-dark);
}
.id-prompt-candidate {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.id-prompt-avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--accent-dark);
  object-fit: cover;
  flex-shrink: 0;
}
.id-prompt-name { font-size: 17px; font-weight: 600; font-family: 'Fraunces', serif; }
.id-prompt-meta { font-size: 12px; color: var(--ink-soft); }
.id-prompt-others { margin-top: 10px; }
.id-prompt-others .hint { display: block; margin-bottom: 6px; }
.id-prompt-other {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 5px;
  cursor: pointer;
  text-align: left;
}
.id-prompt-other:hover { border-color: var(--accent); background: var(--accent-soft); }
.id-prompt-other-name { font-weight: 600; flex-shrink: 0; }
.id-prompt-other .hint { margin-left: auto; text-align: right; }

/* Search section inside the identity prompt — only path forward when fuzzy
   match found nothing, and a convenient escape hatch when it found someone
   wrong. */
.id-prompt-search {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.id-prompt-search input { width: 100%; margin-top: 6px; }
.id-prompt-search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  max-height: 280px;
  overflow-y: auto;
}

/* The big top-match card is now also clickable. */
.id-prompt-candidate {
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.id-prompt-candidate:hover { background: var(--accent-soft); border-color: var(--accent-dark); }

/* ---------- "Confirm your details" verify banner ---------- */
.verify-banner {
  background: linear-gradient(120deg, var(--accent-soft), #f3e7d6);
  border-left: 3px solid var(--gold);
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--accent-dark);
  grid-column: 1 / -1;     /* span the whole form grid when present */
}

/* ---------- find box (tree) ---------- */
.find-box { position: relative; width: 320px; max-width: 60vw; }
.find-box input { width: 100%; }
.find-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
  z-index: 30;
  padding: 4px;
}
.find-result {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
}
.find-result:hover { background: var(--accent-soft); }
.find-result .node-avatar { width: 28px; height: 28px; font-size: 11px; }
.find-result .fr-meta { color: var(--ink-soft); font-size: 11px; }
.find-empty { padding: 10px; font-size: 13px; color: var(--ink-soft); }

/* ---------- tree extras ---------- */
.tree-canvas .tree + .tree {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px dashed var(--line);
}
.node-name .nick { color: var(--ink-soft); font-weight: 500; }
.union-tag {
  display: inline-block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 600;
  color: var(--gold);
  background: #f6edda;
  border-radius: 10px;
  padding: 1px 7px;
}
.node.highlight {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(185, 137, 63, 0.45), var(--shadow);
}

/* ---------- photo upload field ---------- */
.photo-field { display: flex; gap: 14px; align-items: flex-start; }
.photo-preview {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--accent-dark);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.photo-controls { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.photo-controls input[type="file"] { font-size: 12px; padding: 6px; }
.photo-upload-status { font-size: 12px; color: var(--ink-soft); }

/* ---------- relationship editor extras ---------- */
.rel-prefix { color: var(--ink-soft); font-weight: 600; font-size: 11px; }
.rel-other-parent { margin-bottom: 6px; }
.rel-group .hint { display: block; margin-top: 4px; }

/* =====================================================================
   GRAPH CANVAS — pannable bubble layout around the focal person
   ===================================================================== */
.graph-viewport {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.graph-viewport.graph-grabbing { cursor: grabbing; }

.graph-content {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
}

.graph-edges {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}
.graph-edge { fill: none; }
.graph-edge-parent {
  stroke: rgba(80, 100, 90, 0.35);
  stroke-width: 1.8;
}
.graph-edge-spouse {
  stroke: var(--gold);
  stroke-dasharray: 4 5;
  stroke-width: 1.4;
  opacity: 0.7;
}

/* One bubble = one person */
.bubble {
  position: absolute;
  top: 0;
  left: 0;
  /* Position is set inline as `translate(x, y) translate(-50%, -50%)` so the
     element's centre lands at (x, y). CSS transition then animates moves. */
  transform: translate(-50%, -50%);
  transition: transform 0.55s cubic-bezier(0.22, 0.8, 0.2, 1),
              opacity 0.4s ease,
              filter 0.4s ease;
  width: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  text-align: center;
}

/* Proximity-based dimming: the closer to the focal, the brighter. Distant
   relatives fade and pick up a soft blur so the close family is what you
   read first. Hovering any bubble snaps it back to full clarity. */
.bubble[data-dist="0"],
.bubble[data-dist="1"],
.bubble[data-dist="2"] { opacity: 1; }
.bubble[data-dist="3"] { opacity: 0.55; }
.bubble[data-dist="4"] { opacity: 0.32; filter: blur(0.4px); }
.bubble[data-dist="5"] { opacity: 0.2;  filter: blur(0.8px); }
.bubble:hover {
  opacity: 1 !important;
  filter: none !important;
  z-index: 10;
}
.bubble-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--accent-dark);
  font-size: 16px;
  object-fit: cover;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.bubble:hover .bubble-avatar {
  transform: scale(1.08);
  border-color: var(--accent);
}
.bubble-name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 8px;
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow);
}
.bubble-name .nick { color: var(--ink-soft); font-weight: 500; }
.bubble-sub {
  font-size: 10px;
  color: var(--ink-soft);
  background: rgba(255, 253, 248, 0.85);
  padding: 1px 6px;
  border-radius: 6px;
}
.bubble-deceased .bubble-avatar {
  opacity: 0.75;
  border-style: dashed;
}

/* Focal person — gold ring + lifted */
.bubble-focal .bubble-avatar {
  width: 72px;
  height: 72px;
  font-size: 20px;
  border-color: var(--gold);
  border-width: 3px;
  box-shadow: 0 0 0 5px rgba(185, 137, 63, 0.22), 0 4px 14px rgba(46, 42, 36, 0.18);
}
.bubble-focal .bubble-name {
  font-weight: 700;
  border-color: var(--gold);
  font-size: 13px;
}

/* Lineage tints (subtle) */
.bubble-paternal .bubble-avatar { background: #e6edf0; border-color: #b8c8cc; }
.bubble-maternal .bubble-avatar { background: #f4e6ea; border-color: #d6b6bc; }

/* =====================================================================
   HOURGLASS view (legacy — unused after the canvas rewrite, kept for now
   in case we revive an alternate layout)
   ===================================================================== */
.hourglass {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- ancestors half (recursive father/mother blocks) ---------- */
.ancestors-block {
  display: flex;
  justify-content: center;
  padding-bottom: 22px;       /* room for the trunk going down to the focal */
  position: relative;
}
/* Trunk: from the bottom of the parents-couple down to the center-row */
.ancestors-block::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  height: 22px;
  border-left: 2px solid var(--line);
}

.anc-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 6px;
}

/* Parents block above a person */
.anc-parents {
  display: flex;
  flex-direction: row;
  gap: 28px;
  justify-content: center;
  align-items: flex-end;
  position: relative;
  margin-bottom: 22px;        /* room for vertical stub down to this person's node */
}
/* Vertical stub from parents-couple down to this person's node */
.anc-parents::after {
  content: '';
  position: absolute;
  bottom: -22px;
  left: 50%;
  height: 22px;
  border-left: 2px solid var(--line);
}
/* The root parents-couple sits at the bottom of the block — the trunk
   handled by .ancestors-block::after takes over from here. */
.anc-parents.anc-root { margin-bottom: 0; }
.anc-parents.anc-root::after { display: none; }

/* Marriage line: a horizontal bar between the two nodes of a pair, drawn as
   two half-lines extending into the gap from each adjacent node. */
.anc-parents.anc-pair > .anc-cell {
  position: relative;
}
.anc-parents.anc-pair > .anc-cell:first-child > .node::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  width: 14px;                /* half of the 28px parent gap */
  border-top: 2px solid var(--line);
}
.anc-parents.anc-pair > .anc-cell:last-child > .node::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  width: 14px;
  border-top: 2px solid var(--line);
}

/* Empty placeholder cell — keeps spacing for an unknown parent slot */
.anc-cell-empty { min-width: 80px; }

/* ---------- center row ---------- */
.center-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 22px 12px;          /* top padding so the ancestor trunk overlaps cleanly */
  position: relative;
}
.center-siblings {
  display: flex;
  gap: 12px;
  align-items: center;
}
.center-siblings-left { justify-content: flex-end; }
.center-siblings-right { justify-content: flex-start; }
.center-siblings > .node { opacity: 0.9; }  /* siblings slightly de-emphasized */
.focal-couple { display: flex; align-items: stretch; }
.focal-node {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(185, 137, 63, 0.35), var(--shadow);
}
.focal-node .node-name { font-weight: 700; }

/* ---------- descendants half ---------- */
.descendants-block {
  margin-top: 0;
  padding-top: 0;
  position: relative;
}
/* Trunk: from the focal node down into the descendants tree */
.descendants-block::before {
  content: '';
  position: absolute;
  top: -22px;
  left: 50%;
  height: 22px;
  border-left: 2px solid var(--line);
}
/* Re-enable the standard sibling-bar connectors at the top of the descendants
   block (the focal's children). The base .tree CSS hides these for top-level
   <li>s — fine when rendering many unrelated families as roots, but here the
   focal's children ARE siblings, so they need the horizontal bar joining them. */
.descendants-block > ul { padding-top: 22px; }
.descendants-block > ul > li { padding-top: 22px; }
.descendants-block > ul > li::before,
.descendants-block > ul > li::after {
  display: block;
}
.descendants-block > ul > li:only-child::before,
.descendants-block > ul > li:only-child::after {
  display: none;
}

/* ---------- breadcrumbs ---------- */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 12px;
}
.bc-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 3px 12px 3px 4px;
  color: var(--ink);
}
.bc-chip.bc-current {
  background: var(--accent-soft);
  border-color: #cfe0d2;
  color: var(--accent-dark);
  font-weight: 600;
}
.bc-clickable {
  cursor: pointer;
  background: var(--surface-2);
  font-family: inherit;
  font-size: inherit;
}
.bc-clickable:hover { background: var(--surface); border-color: var(--accent); }
.bc-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-dark);
  border: 1px solid var(--line);
  object-fit: cover;
}
.bc-sep { color: var(--ink-soft); font-size: 11px; padding: 0 2px; }
.bc-reset {
  background: transparent;
  border: 1px dashed var(--accent);
  color: var(--accent-dark);
  border-radius: 16px;
  padding: 3px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.bc-reset:hover { background: var(--accent-soft); }

/* ---------- "Show more" buttons ---------- */
.show-more-btn {
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 20px;
  padding: 5px 16px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  margin: 6px 0;
}
.show-more-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- sibling / children ordering list ---------- */
.order-list { display: flex; flex-direction: column; gap: 4px; margin: 2px 0 6px; }
.order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
}
.order-row.is-self { border-color: var(--accent); background: var(--accent-soft); }
.order-num {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: var(--ink-soft);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.order-row.is-self .order-num { background: var(--accent); }
.order-name { flex: 1; min-width: 0; cursor: pointer; }
.order-name:hover { color: var(--accent); }
.order-yrs { color: var(--ink-soft); font-size: 11px; }
.order-ctrls { display: flex; gap: 3px; flex-shrink: 0; }
.order-btn {
  width: 23px;
  height: 23px;
  line-height: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.order-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.order-btn:disabled { opacity: 0.35; cursor: default; }
.order-btn.rm:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.order-foot { margin-top: 2px; }

/* =====================================================================
   MOBILE / TABLET RESPONSIVE
   ===================================================================== */

@media (max-width: 768px) {
  /* Topbar becomes a 3-row grid: brand+actions on row 1, family switcher on
     row 2, tabs spanning row 3. Much easier to scan on a phone. */
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "brand   actions"
      "family  family"
      "tabs    tabs";
    column-gap: 10px;
    row-gap: 8px;
    padding: 10px 14px;
  }
  .brand { grid-area: brand; font-size: 17px; }
  .brand span { display: none; }              /* keep just the 🌳 emoji */
  .topbar-right {
    grid-area: actions;
    margin-left: 0;
    justify-self: end;
    gap: 8px;
  }
  .family-switch { grid-area: family; }
  .family-switch select { width: 100%; }
  .tabs { grid-area: tabs; width: 100%; gap: 4px; }
  .tab { flex: 1; text-align: center; }
  .user-chip span { display: none; }          /* avatar-only on phone */
  #logout-btn { padding: 7px 11px; font-size: 12px; }
  #add-person-btn { padding: 7px 11px; }

  main { padding: 14px; }

  /* Forms + modals + onboarding stack to a single column. */
  .form-grid { grid-template-columns: 1fr; }
  .onboard-cards { grid-template-columns: 1fr; }
  .modal { max-width: 100%; border-radius: 12px; }
  .modal-overlay { padding: 16px 8px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot button { flex: 1 1 calc(50% - 5px); }

  /* Tree toolbar: search takes the full width. */
  .tree-toolbar { gap: 10px; }
  .find-box { width: 100%; max-width: none; }
  .tree-toolbar .hint { display: none; }      /* free up vertical space */

  /* Directory: keep all columns visible — user scrolls the spreadsheet
     horizontally. The sticky Name column means you don't lose context. */
  .dir-table-scroll { max-height: calc(100vh - 220px); }

  /* Family panel — stack member-row actions onto their own line so the
     names/emails aren't crushed. */
  .member-row { flex-wrap: wrap; }
  .member-actions { flex-basis: 100%; justify-content: flex-end; }
}

@media (max-width: 480px) {
  .topbar { padding: 8px 10px; }
  main { padding: 12px; }

  /* Smaller bubbles so more of the family fits without zooming. */
  .bubble { width: 110px; }
  .bubble-avatar { width: 48px; height: 48px; font-size: 13px; }
  .bubble-focal .bubble-avatar { width: 56px; height: 56px; font-size: 15px; }
  .bubble-name { font-size: 11px; max-width: 110px; }
  .bubble-sub { font-size: 10px; }

  /* Tighter spreadsheet on small phones (rows still scroll horizontally). */
  .dir-table thead th { padding: 7px 8px; font-size: 10px; }
  .dir-table tbody td { padding: 6px 8px; }
  .dir-row-avatar { width: 28px; height: 28px; font-size: 10px; }
  .dir-sheet .dir-sticky-col { min-width: 150px; max-width: 180px; }

  /* Breadcrumbs wrap and stay readable. */
  .breadcrumbs { font-size: 11px; }
  .bc-reset { padding: 2px 8px; }

  /* Modal headings a touch smaller. */
  .modal-head h2 { font-size: 16px; }
}

/* On true touch devices, give the canvas a hint that the page itself
   shouldn't pan when the user is interacting with bubbles / pinch-zooming. */
@media (hover: none) and (pointer: coarse) {
  .tree-canvas { touch-action: none; }
}
