/* Ghost Biographer — Family Tree pages (sort + tree)
   Shared tokens live in design.css and memory_lens.css */

/* ── memory_lens_family_sort ── */
/* ── Layout ──────────────────────────────────────────────────────── */
.sort-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100dvh - 160px);
  gap: 10px;
  padding: 10px 14px 14px;
  overflow: hidden;
  box-sizing: border-box;
}
.sort-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.sort-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

/* ── Unplaced pool (left) ────────────────────────────────────────── */
.pool-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  gap: 6px;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}
.pool-panel.drag-over {
  border-color: #7c3aed;
  background: oklch(0.97 0.008 290);
}
.pool-hd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  flex-shrink: 0;
}
#pool-count {
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-muted);
}
.pool-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.pool-empty {
  text-align: center;
  padding: 24px 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* ── Generation ladder (right) ───────────────────────────────────── */
.ladder-panel {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 4px;
}
.section-hd {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 10px 2px 3px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.section-hd:first-child { border-top: none; padding-top: 2px; margin-top: 0; }

.bucket {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  transition: border-color .15s, background .15s;
  min-height: 46px;
}
.bucket.drag-over {
  border-color: #7c3aed;
  background: oklch(0.97 0.008 290);
}
.bucket-hd {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.bucket-label { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
.bucket-count {
  font-size: 10px;
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}
.bucket-chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Face chip ───────────────────────────────────────────────────── */
.face-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 3px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  cursor: grab;
  user-select: none;
  max-width: 160px;
  transition: box-shadow .12s, border-color .12s;
}
.face-chip:hover { border-color: #7c3aed; box-shadow: 0 2px 8px rgba(0,0,0,.09); }
.face-chip.dragging { opacity: .28; cursor: grabbing; }
.face-chip.in-pool { max-width: none; width: 100%; }

.fc-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  position: relative;
}
.fc-avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
  display: none;
}
.fc-name {
  font-size: 12px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.face-chip.in-pool .fc-name { font-size: 13px; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.sort-btn {
  padding: 6px 13px;
  border-radius: 7px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex; align-items: center; gap: 4px;
  text-decoration: none;
}
.sort-btn-primary { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.sort-btn-primary:hover { background: #6d28d9; border-color: #6d28d9; }
.sort-btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.sort-btn-outline { background: transparent; border-color: var(--border); color: var(--text-muted); }
.sort-btn-outline:hover { border-color: #7c3aed; color: #7c3aed; }
#sort-status { font-size: 12px; color: var(--text-muted); }

/* ── Context menu ────────────────────────────────────────────────── */
.ctx-menu {
  position: fixed; z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  padding: 4px; min-width: 200px;
}
.ctx-menu[hidden] { display: none; }
.ctx-item {
  display: block; width: 100%;
  padding: 8px 14px; border-radius: 6px;
  background: none; border: none;
  text-align: left; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.ctx-item:hover { background: var(--surface-2); }
.ctx-item.danger { color: #ef4444; }

/* ── Edges modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  width: 580px; max-width: 95vw;
  max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
}
.modal-hd {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 700; flex: 1; color: var(--text); }
.modal-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); border: none; cursor: pointer;
  font-size: 15px; color: var(--text-muted);
}
.modal-body {
  padding: 10px 16px; overflow-y: auto;
  flex: 1; display: flex; flex-direction: column; gap: 5px;
}
.modal-empty {
  text-align: center; padding: 28px;
  color: var(--text-muted); font-size: 14px; font-style: italic;
}

/* edge rows */
.edge-row {
  border-radius: 7px;
  background: var(--surface-2);
  overflow: hidden;
}
.edge-normal-row {
  display: grid;
  grid-template-columns: 20px 1fr 1fr auto auto;
  gap: 8px; align-items: center;
  padding: 8px 10px;
}
.edge-dir { font-size: 14px; color: var(--text-muted); }
.edge-reltype { font-size: 13px; font-weight: 600; color: var(--text); }
.edge-peer { font-size: 12px; color: var(--text-muted); }
.edge-edit-btn, .edge-del-btn {
  padding: 3px 8px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 12px; color: var(--text);
}
.edge-del-btn { background: #fef2f2; border-color: #fecaca; color: #ef4444; }
.edge-edit-form {
  display: none; padding: 8px 10px;
  align-items: center; gap: 6px;
}
.edge-row.editing .edge-normal-row { display: none; }
.edge-row.editing .edge-edit-form { display: flex; }
.edge-type-input {
  flex: 1; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; background: var(--surface); color: var(--text);
}
.edge-save-btn { padding: 4px 10px; background: #7c3aed; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; }
.edge-cancel-btn { padding: 4px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 12px; }

/* ── memory_lens_family_tree ── */
/* ── Layout ──────────────────────────────────────────────────────── */
.tree-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100dvh - 160px);
  gap: 10px;
  padding: 10px 14px 14px;
  overflow: hidden;
  box-sizing: border-box;
}
.tree-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.tree-body {
  overflow-y: auto;
  overflow-x: auto;
  padding: 4px;
}

/* ── Generation rows ─────────────────────────────────────────────── */
.gen-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.gen-section-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 6px 0 0;
  border-top: 1px solid var(--border);
}
.gen-section:first-child .gen-section-label { border-top: none; }

.gen-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}
.gen-row-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 90px;
  padding-top: 6px;
  flex-shrink: 0;
}

/* ── Person card ─────────────────────────────────────────────────── */
.person-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
  min-width: 72px; max-width: 110px;
}
.person-card:hover { border-color: #7c3aed; box-shadow: 0 2px 10px rgba(0,0,0,.1); }

.pc-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  position: relative;
  flex-shrink: 0;
}
.pc-avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
  display: none;
}
.pc-name {
  font-size: 12px; font-weight: 500; color: var(--text);
  text-align: center; word-break: break-word;
  line-height: 1.3; max-width: 90px;
}
.pc-role {
  font-size: 10px; color: var(--text-muted);
  text-align: center;
}

/* ── Detail panel (flyout) ────────────────────────────────────────── */
.detail-panel {
  position: fixed;
  right: 16px; top: 90px;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  padding: 14px 16px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.detail-panel[hidden] { display: none; }
.detail-hd { display: flex; align-items: center; gap: 8px; }
.detail-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
  position: relative;
}
.detail-avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%; display: none;
}
.detail-name { font-size: 15px; font-weight: 700; color: var(--text); }
.detail-role { font-size: 12px; color: var(--text-muted); }
.detail-close {
  margin-left: auto; width: 24px; height: 24px;
  background: var(--surface-2); border: none;
  border-radius: 50%; cursor: pointer; font-size: 13px;
  color: var(--text-muted); flex-shrink: 0;
}

/* ── Empty state ─────────────────────────────────────────────────── */
.tree-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 15px;
}
.tree-empty a { color: #7c3aed; text-decoration: none; font-weight: 600; }
.tree-empty a:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.tree-btn {
  padding: 6px 13px;
  border-radius: 7px; border: 2px solid transparent;
  cursor: pointer; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
  text-decoration: none; line-height: 1;
}
.tree-btn-outline { background: transparent; border-color: var(--border); color: var(--text-muted); }
.tree-btn-outline:hover { border-color: #7c3aed; color: #7c3aed; }
#tree-status { font-size: 12px; color: var(--text-muted); }
