/* ============================================================
   FAMILY TREE — styles
   Palette: paper #F4F7F5 · pine ink #22302B · action green #1E6B4E
   Generation ring colors are set from app.js as --gc
   ============================================================ */

:root {
  --paper: #f4f7f5;
  --ink: #22302b;
  --ink-soft: #5c6b64;
  --card: #ffffff;
  --pine: #1e6b4e;
  --pine-dark: #14523b;
  --danger: #c23b3b;
  --line: #dde5e0;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(34, 48, 43, 0.08);
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}
h1, h2 { font-family: var(--font-display); margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 999px;
  padding: 10px 18px; font-size: 15px; font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--pine); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--pine-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a52f2f; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }
.link-btn {
  display: block; margin: 14px auto 0; background: none; border: none;
  color: var(--pine); font-size: 14px; font-weight: 600; text-decoration: underline;
}
:where(button, input, select, textarea, a):focus-visible {
  outline: 3px solid #7db8a0; outline-offset: 2px;
}

/* ---------- Lock screen ---------- */
.lock {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e4efe8 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #eae4f0 0%, transparent 55%),
    var(--paper);
}
.lock-card {
  width: 100%; max-width: 420px; background: var(--card);
  border-radius: 24px; padding: 40px 36px; box-shadow: 0 12px 40px rgba(34,48,43,0.14);
  text-align: center; position: relative;
  animation: rise 0.5s ease both;
}
.lang-btn {
  position: absolute; top: 14px; right: 14px;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 5px 13px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
}
.lang-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.lock-leaves { display: flex; justify-content: center; gap: 8px; margin-bottom: 18px; }
.lock-leaves span {
  width: 14px; height: 22px; border-radius: 50% 50% 50% 0;
  transform: rotate(45deg);
}
.lock-leaves span:nth-child(1) { background: #c2900f; }
.lock-leaves span:nth-child(2) { background: #d4653f; }
.lock-leaves span:nth-child(3) { background: #c74b77; }
.lock-leaves span:nth-child(4) { background: #4a6cd4; }
.lock-leaves span:nth-child(5) { background: #1d93a6; }
.lock-card h1 { font-size: 30px; font-weight: 800; }
.lock-sub { color: var(--ink-soft); margin: 8px 0 24px; }
.lock-error { color: var(--danger); font-weight: 600; margin: 14px 0 0; }

/* ---------- Fields ---------- */
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 13px; background: #fbfdfc;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--pine); outline: none; }
textarea { resize: vertical; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px 10px; flex-wrap: wrap;
}
.topbar-title h1 { font-size: 26px; font-weight: 800; }
.who { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.who .admin-badge {
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 2px 10px; margin-left: 6px; font-size: 11px; letter-spacing: 0.04em;
}
.topbar-actions { display: flex; gap: 10px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 8px 28px 16px;
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(var(--paper) 85%, transparent);
}
.search-wrap { position: relative; flex: 1 1 260px; max-width: 420px; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-soft); }
#searchInput {
  width: 100%; border: 1.5px solid var(--line); border-radius: 999px;
  padding: 11px 16px 11px 40px; background: var(--card); box-shadow: var(--shadow);
}
#searchInput:focus { border-color: var(--pine); outline: none; }
.filters { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filter { display: flex; flex-direction: column; gap: 3px; }
.filter-label {
  font-size: 11px; font-weight: 800; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.07em; padding-left: 8px;
}
.filters select, .age-filter input {
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--card);
  padding: 9px 12px; font-size: 14px; box-shadow: var(--shadow);
}
.age-filter { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.age-filter input { width: 86px; }
.result-count { font-size: 13px; font-weight: 700; color: var(--pine); }

/* ---------- Tree ---------- */
#treeArea { padding: 6px 0 90px; }
.tree-scroller { position: relative; overflow-x: auto; }
#connectors {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 1;
}
#treeLanes { position: relative; z-index: 2; min-width: min-content; width: max-content; margin: 0 auto; }
#treeZoom { position: relative; transform-origin: top left; }
.zoom-ctrl {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 5px 8px; box-shadow: var(--shadow);
}
.zoom-ctrl button {
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: var(--paper); color: var(--ink);
  font-size: 17px; font-weight: 800; line-height: 1;
}
.zoom-ctrl button:hover { background: var(--pine); color: #fff; }
.zoom-ctrl span { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); min-width: 42px; text-align: center; }

.lane {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 28px 28px 28px 0; margin: 0 0 56px;
  border-radius: 0 22px 22px 0;
  background: color-mix(in srgb, var(--gc) 7%, transparent);
  border-left: 6px solid var(--gc);
  min-width: min-content;
}
.lane-label {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gc); padding: 4px 2px; margin-left: 10px;
  align-self: stretch; display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.lane-cards {
  display: flex; flex-wrap: nowrap; gap: 46px; flex: 1;
  padding-bottom: 12px; justify-content: flex-start; align-items: flex-start;
}
.family-group {
  display: flex; flex-wrap: nowrap; gap: 46px; align-items: flex-start; flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 20px; padding: 18px 20px;
}
.couple { display: flex; align-items: center; }
.marriage-wrap { position: relative; display: flex; align-items: center; flex: 0 0 auto; }
.marriage {
  width: 34px; height: 4px; border-radius: 2px;
  background: var(--gc); opacity: 0.65;
}
.add-couple-child-btn {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 25px; height: 25px; border-radius: 50%;
  background: var(--card); border: 2.5px solid var(--gc); color: var(--gc);
  font-size: 15px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(34,48,43,0.18);
  transition: transform 0.13s ease, background 0.13s ease, color 0.13s ease;
}
.add-couple-child-btn:hover {
  transform: translate(-50%, -50%) scale(1.35);
  background: var(--gc); color: #fff;
}

/* ---------- Person card ---------- */
.person {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px 12px; width: 168px; text-align: center;
  box-shadow: var(--shadow); border: 1.5px solid transparent;
  cursor: pointer; position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease, border-color 0.15s ease;
}
.person:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(34,48,43,0.16); }
.person.dimmed { opacity: 0.16; filter: grayscale(0.6); }
.person.hit { border-color: var(--gc); }
.avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 10px;
  border: 3.5px solid var(--gc);
  background: color-mix(in srgb, var(--gc) 18%, #fff);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 22px; color: var(--gc);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.person-name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.person-name mark { background: color-mix(in srgb, var(--gc) 30%, #fff); border-radius: 3px; padding: 0 1px; }
.person-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }
.mine-dot {
  position: absolute; top: 10px; right: 10px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--pine);
}
.add-child-btn, .add-sibling-btn, .add-sibling-btn-left, .add-parent-btn {
  position: absolute;
  width: 26px; height: 26px;
  background: none; border: none; box-shadow: none;
  color: var(--gc);
  font-size: 20px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 0 5px #fff, 0 0 2px #fff;
  opacity: 0.75;
  transition: transform 0.14s ease, opacity 0.14s ease;
}
.add-child-btn:hover, .add-sibling-btn:hover, .add-sibling-btn-left:hover, .add-parent-btn:hover { opacity: 1; }
.add-child-btn { left: 50%; bottom: -13px; transform: translateX(-50%); }
.add-child-btn:hover { transform: translateX(-50%) scale(1.6); }
.add-sibling-btn { right: -14px; top: 70%; transform: translateY(-50%); }
.add-sibling-btn:hover { transform: translateY(-50%) scale(1.6); }
.add-sibling-btn-left { left: -14px; top: 70%; transform: translateY(-50%); }
.add-sibling-btn-left:hover { transform: translateY(-50%) scale(1.6); }
.add-parent-btn { left: 50%; top: -13px; transform: translateX(-50%); }
.add-parent-btn:hover { transform: translateX(-50%) scale(1.6); }
.person.dimmed .add-child-btn, .person.dimmed .add-sibling-btn, .person.dimmed .add-sibling-btn-left, .person.dimmed .add-parent-btn { display: none; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 90px 24px; }
.empty h2 { font-size: 26px; font-weight: 800; margin-bottom: 10px; }
.empty p { color: var(--ink-soft); margin: 0 0 22px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(24, 34, 29, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade 0.18s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card); border-radius: 22px; padding: 30px 30px 24px;
  width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto;
  position: relative; animation: rise 0.22s ease both;
}
.modal-sm { max-width: 400px; }
.modal h2 { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.modal-close {
  position: absolute; top: 14px; right: 14px; border: none; background: var(--paper);
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px; color: var(--ink-soft);
}
.modal-close:hover { color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-error { color: var(--danger); font-weight: 600; margin: 10px 0 0; }

/* ---------- Add/Edit form ---------- */
.form-grid { display: flex; gap: 22px; }
.form-fields { flex: 1; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-picker { flex: 0 0 130px; text-align: center; }
.photo-preview {
  width: 120px; height: 120px; border-radius: 50%;
  border: 3px dashed var(--line); background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: 13px; font-weight: 600;
  overflow: hidden; margin: 0 auto 10px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-btns { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Detail modal ---------- */
.detail-head { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.detail-avatar {
  width: 96px; height: 96px; border-radius: 50%; flex: 0 0 auto;
  border: 4px solid var(--gc); overflow: hidden;
  background: color-mix(in srgb, var(--gc) 18%, #fff);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 30px; color: var(--gc);
}
.detail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.detail-head h2 { margin: 0 0 4px; }
.gen-chip {
  display: inline-block; font-size: 12px; font-weight: 700;
  background: color-mix(in srgb, var(--gc) 14%, #fff); color: var(--gc);
  border: 1.5px solid var(--gc); border-radius: 999px; padding: 3px 12px;
}
.detail-rows { border-top: 1.5px solid var(--line); }
.detail-rows div { display: flex; justify-content: space-between; gap: 14px; padding: 10px 2px; border-bottom: 1.5px solid var(--line); font-size: 14.5px; }
.detail-rows dt { color: var(--ink-soft); font-weight: 600; }
.detail-rows dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-weight: 600; font-size: 14.5px;
  padding: 12px 22px; border-radius: 999px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  animation: rise 0.25s ease both;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar, .toolbar { padding-left: 14px; padding-right: 14px; }
  .form-grid { flex-direction: column; align-items: center; }
  .two-col { grid-template-columns: 1fr; }
  .person { width: 138px; }
  .avatar { width: 60px; height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Loading spinner on buttons ---------- */
.btn.loading { pointer-events: none; position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Partner autocomplete + incomplete badge ---------- */
.partner-field { position: relative; }
.suggest-box {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 22px rgba(34,48,43,0.16); z-index: 40;
  max-height: 186px; overflow-y: auto;
}
.suggest-box button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 10px 13px; font-size: 14px; color: var(--ink);
}
.suggest-box button:hover { background: var(--paper); }
.check-row { margin: -2px 0 14px; font-size: 13.5px; color: var(--ink-soft); }
.check-row label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check-row input { margin-top: 2px; accent-color: var(--pine); }
.warn-badge {
  position: absolute; top: 8px; left: 8px; width: 20px; height: 20px;
  border-radius: 50%; background: #e0a422; color: #fff;
  font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.incomplete-note {
  background: #faf3e0; border: 1.5px solid #e0a422; color: #8a6614;
  border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600;
  margin: 0 0 14px;
}

/* ---------- In-law (spouse from another family) cards ---------- */
.person.in-law { width: 132px; padding: 10px 12px 9px; }
.person.in-law .avatar {
  width: 52px; height: 52px; font-size: 17px;
  border-color: #b9c4be; color: #7d8c85;
  background: #eef2ef;
}
.person.in-law .person-name { font-size: 13.5px; }
.person.in-law .person-meta { font-size: 11.5px; }

/* ---------- Suggestions ---------- */
.sug-badge {
  position: absolute; top: 7px; right: 26px;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: #3d6fd4; color: #fff;
  font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.sug-list { margin-top: 16px; }
.sug-list h3 {
  font-family: var(--font-display); font-size: 15px; margin: 0 0 8px;
  color: #3d6fd4;
}
.sug-item {
  background: #eef3fc; border: 1.5px solid #c9d8f4; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; position: relative;
}
.sug-item p { margin: 0 0 4px; font-size: 14px; }
.sug-item span { font-size: 12px; color: #5674a8; font-weight: 600; }
.sug-del {
  position: absolute; top: 8px; right: 8px;
  border: none; background: none; color: #5674a8; font-size: 13px;
  padding: 2px 5px; border-radius: 6px;
}
.sug-del:hover { background: #d9e4f7; }
.sug-form { margin-top: 12px; }
.sug-form textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 10px 12px; background: #fbfdfc; resize: vertical;
}
.sug-form .modal-actions { margin-top: 10px; }
.detail-avatar a, .detail-avatar img { display: block; width: 100%; height: 100%; }
.detail-avatar a { cursor: zoom-in; }

/* ---------- Cross-tree navigation ---------- */
.back-tree {
  display: inline-flex; align-items: center;
  font-size: 14px; padding: 9px 18px; margin-bottom: 8px;
}
.tree-jump { margin-top: 14px; }

.partner-hint { margin: 0 0 6px; font-size: 13px; font-weight: 700; color: var(--pine); }

.toolbar-add { margin-left: auto; }
.tree-name-hint {
  margin: 10px 0 8px; font-size: 13.5px; color: var(--ink-soft);
  background: var(--paper); border-radius: 12px; padding: 10px 12px;
}

.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: #edf1ee; color: #93a09a; cursor: not-allowed; border-style: dashed;
}

/* ---------- Sibling chips ---------- */
.sib-field { position: relative; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: #e7efe9; border: 1.5px solid var(--pine); color: var(--pine-dark);
  border-radius: 999px; padding: 4px 11px; font-size: 13px; font-weight: 700;
}
.chip.new { background: #faf3e0; border-color: #e0a422; color: #8a6614; }
.chip button { border: none; background: none; color: inherit; font-weight: 800; padding: 0; font-size: 13px; }
#sibNewRow { margin: -4px 0 14px; }
#sibNewRow .btn { margin-top: 2px; }

/* ---------- Help ---------- */
.help-body h2 { margin-bottom: 4px; }
.help-body h3 {
  font-family: var(--font-display); font-size: 16px; color: var(--pine-dark);
  margin: 18px 0 6px;
}
.help-body p, .help-body li { font-size: 14.5px; line-height: 1.55; color: var(--ink); }
.help-body ul { margin: 4px 0 4px 20px; padding: 0; }
.help-body .contact {
  margin-top: 20px; background: #e7efe9; border: 1.5px solid var(--pine);
  border-radius: 14px; padding: 12px 16px; font-weight: 600;
}
.help-body .contact a { color: var(--pine-dark); }

.chip.current { background: #f0f2f1; border-color: #b9c4be; color: #5c6b64; }
