/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --card-w: 88px;
  --av-size: 48px;
  --line-color: #CBD5E1;
  --heart-color: #E879A0;
  --radius-card: 10px;
  --radius-modal: 14px;
  --shadow-modal: 0 8px 32px rgba(0,0,0,0.18);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #F8F7F4;
  color: #1A1A1A;
  min-height: 100vh;
}

/* ── Top bar ───────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #E5E7EB;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  z-index: 200;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: #111;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title span {
  font-weight: 400;
  color: #6B7280;
  font-size: 13px;
  margin-left: 6px;
}

/* Search */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #F3F4F6;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  padding: 5px 10px;
  transition: border-color .15s;
}
.search-wrap:focus-within { border-color: #6366F1; background: #fff; }
.search-wrap svg { width: 15px; height: 15px; flex-shrink: 0; stroke: #9CA3AF; }
.search-wrap input {
  border: none; background: transparent;
  font-size: 13px; color: #111; outline: none; width: 160px;
}

/* Zoom controls */
.zoom-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #F3F4F6;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  padding: 3px 6px;
}
.zoom-bar button {
  width: 26px; height: 26px;
  background: none; border: none; cursor: pointer;
  border-radius: 6px;
  font-size: 16px; line-height: 1;
  color: #374151;
  display: flex; align-items: center; justify-content: center;
}
.zoom-bar button:hover { background: #E5E7EB; }
.zoom-label { font-size: 12px; color: #6B7280; min-width: 36px; text-align: center; }

/* Icon buttons */
.icon-btn {
  width: 34px; height: 34px;
  background: #F3F4F6; border: 1px solid #E5E7EB;
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #374151;
  text-decoration: none;
}
.icon-btn:hover { background: #E5E7EB; }
.icon-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ── Tree canvas ───────────────────────────────────────────────────────── */
.canvas-viewport {
  position: fixed;
  top: 52px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}
.canvas-viewport:active { cursor: grabbing; }

.canvas-inner {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  padding: 40px 60px 80px;
}

/* ── Family blocks ─────────────────────────────────────────────────────── */
.family-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.couple-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
  position: relative;
}

.couple-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 18px;
  width: 22px;
  flex-shrink: 0;
}
.couple-connector .hline {
  width: 100%;
  height: 1.5px;
  background: var(--line-color);
}
.couple-connector .heart {
  position: absolute;
  font-size: 10px;
  color: var(--heart-color);
  margin-top: -18px;
}

.tree-vline {
  width: 1.5px;
  height: 28px;
  background: var(--line-color);
  margin: 0 auto;
}

/* ── Children row ──────────────────────────────────────────────────────── */
.children-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.children-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
  position: relative;
}

/* Horizontal line spanning all children */
.children-hline {
  position: absolute;
  top: 0;
  height: 1.5px;
  background: var(--line-color);
}

.child-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.child-drop {
  width: 1.5px;
  height: 20px;
  background: var(--line-color);
}

/* ── Person card ───────────────────────────────────────────────────────── */
.person-card {
  width: var(--card-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7px 6px 8px;
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: border-color .12s, transform .12s, box-shadow .12s;
  flex-shrink: 0;
}
.person-card:hover {
  border-color: #A5B4FC;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99,102,241,.12);
}
.person-card.deceased { opacity: 0.68; }
.person-card.highlighted {
  border-color: #6366F1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}

/* Avatar */
.avatar {
  width: var(--av-size);
  height: var(--av-size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1.5px solid #E5E7EB;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.male   { background: #EFF6FF; color: #1D4ED8; }
.avatar.female { background: #FDF2F8; color: #9D174D; }
.avatar.other  { background: #F0FDF4; color: #166534; }

.person-name {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  color: #111827;
  word-break: break-word;
}
.person-years {
  font-size: 9.5px;
  color: #6B7280;
  margin-top: 2px;
  text-align: center;
}

/* Collapse toggle */
.collapse-btn {
  margin-top: 5px;
  font-size: 10px;
  color: #9CA3AF;
  background: none;
  border: 1px solid #E5E7EB;
  border-radius: 99px;
  padding: 1px 6px;
  cursor: pointer;
  line-height: 1.6;
  transition: color .1s, border-color .1s;
}
.collapse-btn:hover { color: #374151; border-color: #9CA3AF; }

/* Group label above generation section */
.gen-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 6px;
}
.gen-group-label {
  font-size: 9px;
  color: #9CA3AF;
  background: #F3F4F6;
  border: 1px solid #E5E7EB;
  border-radius: 99px;
  padding: 1px 8px;
  margin-bottom: 6px;
  white-space: nowrap;
}

/* ── Bio Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}

.modal {
  background: #fff;
  border-radius: var(--radius-modal);
  width: 340px;
  max-width: 100%;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: modalIn .15s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-photo {
  width: 100%;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  font-weight: 700;
  position: relative;
}
.modal-photo img {
  width: 100%; height: 100%; object-fit: cover;
}
.modal-photo.male   { background: #EFF6FF; color: #1D4ED8; }
.modal-photo.female { background: #FDF2F8; color: #9D174D; }
.modal-photo.other  { background: #F0FDF4; color: #166534; }

.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  width: 30px; height: 30px;
  background: rgba(255,255,255,.88);
  border: 1px solid #E5E7EB;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #374151;
}
.modal-close:hover { background: #fff; }

.modal-body { padding: 14px 16px 18px; }
.modal-name { font-size: 18px; font-weight: 700; }
.modal-dates { font-size: 13px; color: #6B7280; margin-top: 2px; }

.badge-row { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
}
.badge-deceased { background: #F3F4F6; color: #4B5563; }
.badge-partner  { background: #FDF2F8; color: #9D174D; }

.modal-bio {
  margin-top: 10px;
  font-size: 13px;
  color: #374151;
  line-height: 1.65;
  border-top: 1px solid #F3F4F6;
  padding-top: 10px;
}

.modal-relations {
  margin-top: 8px;
  font-size: 12px;
  color: #6B7280;
  border-top: 1px solid #F3F4F6;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.modal-relations strong { color: #111; }

/* ── Minimap ───────────────────────────────────────────────────────────── */
.minimap {
  position: fixed;
  bottom: 16px; right: 16px;
  width: 130px; height: 72px;
  background: rgba(255,255,255,.9);
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  overflow: hidden;
  z-index: 300;
}
.minimap-content {
  position: absolute;
  inset: 0;
  opacity: .35;
}
.minimap-viewport {
  position: absolute;
  border: 2px solid #6366F1;
  border-radius: 3px;
  pointer-events: none;
  background: rgba(99,102,241,.08);
}

/* ── Loading & empty states ────────────────────────────────────────────── */
.state-center {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #6B7280;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid #E5E7EB;
  border-top-color: #6366F1;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Admin page ────────────────────────────────────────────────────────── */
.admin-wrap {
  max-width: 680px;
  margin: 72px auto 40px;
  padding: 0 16px;
}
.admin-section {
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.admin-section h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #F3F4F6;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}
input[type=text], input[type=number], select, textarea {
  width: 100%;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid #D1D5DB;
  border-radius: 7px;
  background: #fff;
  color: #111;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: #6366F1; }
textarea { resize: vertical; min-height: 72px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: opacity .12s;
}
.btn:hover { opacity: .88; }
.btn-primary { background: #6366F1; color: #fff; }
.btn-danger  { background: #EF4444; color: #fff; }
.btn-ghost   { background: #F3F4F6; color: #374151; border: 1px solid #E5E7EB; }

.member-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #F3F4F6;
  font-size: 13px;
}
.member-list-item:last-child { border-bottom: none; }
.member-list-item .mname { flex: 1; font-weight: 500; }
.member-list-item .myears { color: #6B7280; font-size: 12px; }

.upload-zone {
  border: 2px dashed #D1D5DB;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  color: #6B7280;
  transition: border-color .15s;
}
.upload-zone:hover { border-color: #6366F1; color: #6366F1; }
.upload-zone input { display: none; }

.photo-preview {
  width: 64px; height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #E5E7EB;
  display: none;
}

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: #1F2937;
  color: #fff;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 8px;
  z-index: 1000;
  animation: toastIn .2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Login screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: 14px;
  padding: 28px 28px 24px;
  width: 320px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
}
.login-card h1 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.login-card p  { font-size: 13px; color: #6B7280; margin-bottom: 18px; }
.login-card input { margin-bottom: 10px; }
.login-error { font-size: 12px; color: #EF4444; margin-top: 6px; }
