:root {
  --paper: #F5EFE0;
  --paper-alt: #ECE1C8;
  --canvas-line: #DDD0AE;
  --ink: #2A2318;
  --ink-soft: #6B6153;
  --ink-faint: #9A8F7A;
  --branch: #48583C;
  --branch-light: #93A47A;
  --gold: #B0813C;
  --gold-soft: #E7D6A4;
  --brick: #9C4636;
  --card: #FFFCF4;
  --shadow: rgba(41,33,20,0.22);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Work Sans', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 1px 1px, rgba(41,33,20,0.05) 1px, transparent 0) 0 0/16px 16px,
    var(--paper);
}
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.serif { font-family: 'Fraunces', serif; }

.btn {
  font-family: 'Work Sans', sans-serif;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
  background: none;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--branch); outline-offset: 2px; }
.btn-primary { background: var(--branch); color: var(--paper); }
.btn-primary:hover { background: #3c4a32; }
.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover { background: #9c6f30; }
.btn-outline { background: transparent; color: var(--ink); border-color: rgba(42,35,24,0.3); }
.btn-outline:hover { background: rgba(42,35,24,0.06); }
.btn-danger { background: transparent; color: var(--brick); border-color: var(--brick); }
.btn-danger:hover { background: rgba(156,70,54,0.08); }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 7px 10px; }
.btn-ghost:hover { background: rgba(42,35,24,0.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; justify-content: center; }

.input, select.input, textarea.input {
  font-family: 'Work Sans', sans-serif;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(42,35,24,0.22);
  background: #fff;
  font-size: 14px;
  color: var(--ink);
}
.input:focus { outline: 2px solid var(--branch); outline-offset: 1px; border-color: var(--branch); }
.label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; display: block; }
.field { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* header */
.ft-header {
  padding: 14px 18px; border-bottom: 1px solid var(--canvas-line);
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
}
.ft-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ft-brand-badge { width: 38px; height: 38px; border-radius: 50%; background: var(--branch); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--paper); font-size: 17px; }
.ft-brand-name { font-size: 18px; font-weight: 700; line-height: 1.15; }
.ft-brand-sub { font-size: 11.5px; color: var(--ink-faint); }
.ft-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ft-search-wrap { position: relative; }
.ft-search-wrap .input { padding-left: 32px; width: 170px; }
.ft-search-icon { position: absolute; left: 10px; top: 10px; color: var(--ink-faint); pointer-events: none; }
.ft-search-results { position: absolute; top: 110%; left: 0; right: 0; background: var(--card); border-radius: 10px; box-shadow: 0 10px 24px var(--shadow); border: 1px solid var(--gold-soft); z-index: 50; overflow: hidden; }
.ft-search-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; }
.ft-search-item:hover { background: var(--paper-alt); }
.ft-viewtoggle { display: flex; background: var(--paper-alt); border-radius: 999px; padding: 3px; }
.ft-viewtoggle .btn { padding: 7px 12px; }
.ft-viewtoggle .btn.active { background: var(--card); box-shadow: 0 1px 4px var(--shadow); }

.ft-banner { background: #F5DCD5; color: var(--brick); font-size: 12.5px; padding: 8px 18px; display: flex; gap: 6px; align-items: center; flex: 0 0 auto; }

.ft-footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: #F0F7FF;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(to right, #8EC5F2 0%, #2E6BC7 55%, #0B2A5E 100%);
  text-shadow: 0 1px 2px rgba(0,0,0,0.18);
}

/* canvas / tree */
#view-root { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.ft-canvas { overflow: auto; position: relative; flex: 1; }

.ft-zoom-controls {
  position: fixed; top: 96px; right: 16px; z-index: 40;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--canvas-line);
  border-radius: 10px; box-shadow: 0 4px 14px var(--shadow);
  overflow: hidden;
}
.ft-zoom-controls button {
  all: unset; cursor: pointer; box-sizing: border-box;
  width: 40px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; color: var(--ink);
  border-bottom: 1px solid var(--canvas-line);
}
.ft-zoom-controls button:last-child { border-bottom: none; }
.ft-zoom-controls button:hover { background: var(--paper-alt); }
.ft-zoom-controls button.zoom-pct { font-size: 11px; font-weight: 700; color: var(--ink-soft); }

.ft-hover-dock {
  position: fixed; right: 16px; bottom: 16px; z-index: 55;
  background: var(--card); border: 1px solid var(--gold-soft);
  border-radius: 14px; box-shadow: 0 10px 28px var(--shadow);
  padding: 12px 16px; max-width: 240px;
  pointer-events: none;
  opacity: 0; transform: translateY(8px);
  transition: opacity .15s ease, transform .15s ease;
}
.ft-hover-dock.show { opacity: 1; transform: translateY(0); }
.ft-hover-dock-name { font-family: 'Fraunces', serif; font-weight: 700; font-size: 15px; margin-bottom: 6px; color: var(--ink); }
.ft-hover-dock-row { font-size: 12.5px; color: var(--ink-soft); line-height: 1.6; }
.ft-hover-dock-row strong { color: var(--ink); font-weight: 600; }
@media (max-width: 560px) {
  .ft-hover-dock { right: 10px; bottom: 10px; max-width: 190px; padding: 10px 14px; }
  .ft-hover-dock-name { font-size: 13.5px; }
  .ft-hover-dock-row { font-size: 11.5px; }
}
.ft-canvas-inner { position: relative; width: max-content; min-width: 100%; padding: 28px 40px 60px 20px; }
#ft-zoom-content { width: max-content; }
.ft-lines { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 1; }
.ft-line-branch { fill: none; stroke: var(--branch); stroke-width: 2.25; stroke-linecap: round; opacity: .8; }

.ft-row { display: flex; align-items: flex-start; position: relative; z-index: 2; margin-bottom: 76px; }
.ft-row-label { position: sticky; left: 0; z-index: 3; width: 92px; flex: 0 0 92px; font-family: 'Fraunces', serif; font-size: 13px; font-weight: 600; font-style: italic; color: var(--gold); background: var(--paper); padding-top: 22px; border-right: 1px dashed var(--canvas-line); margin-right: 18px; align-self: stretch; }
.ft-row-units { display: flex; gap: 34px; align-items: flex-start; }
.ft-unit { display: flex; align-items: flex-start; gap: 12px; }

.ft-node { all: unset; cursor: pointer; position: relative; display: block; }
.ft-node:focus-visible { outline: 2px solid var(--branch); outline-offset: 2px; }

.ft-card {
  width: clamp(112px, 15vw, 148px);
  display: flex; flex-direction: column;
  border-radius: 13px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid rgba(42,35,24,0.10);
  box-shadow: 0 3px 10px var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, outline-color .15s ease;
}
.ft-card:hover { transform: translateY(-3px); box-shadow: 0 10px 22px var(--shadow); }
.ft-card.highlight { outline: 3px solid var(--gold); outline-offset: 2px; }

.ft-card-photo { width: 100%; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--paper-alt); }
.ft-card-photo img { width: 100%; height: 100%; object-fit: cover; }
.ft-card-initials { font-family: 'Fraunces', serif; font-weight: 700; color: #fff; font-size: clamp(20px, 4vw, 30px); }

.ft-card-footer { background: var(--branch); color: var(--paper); padding: 7px 9px 9px; text-align: center; }
.ft-card-name { display: block; font-size: clamp(11.5px, 2.1vw, 13px); font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ft-card-sub { display: block; font-size: 10.5px; opacity: .8; margin-top: 2px; }

.ft-card-death { position: absolute; top: 6px; left: 6px; background: rgba(20,16,10,.6); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; }
.ft-card-edit { position: absolute; top: 6px; right: 6px; background: var(--gold); color: #fff; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; cursor: pointer; box-shadow: 0 2px 6px var(--shadow); }

/* list view */
.ft-list-wrap { flex: 1; overflow-y: auto; padding: 16px 18px; }
.ft-list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 10px; }
.ft-list-card { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 10px; border-radius: 12px; cursor: pointer; border: 1px solid var(--canvas-line); }
.ft-list-card:hover { border-color: var(--gold); }
.ft-list-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ft-list-sub { font-size: 11.5px; color: var(--ink-faint); }

/* avatar */
.avatar { border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-family: 'Fraunces', serif; font-weight: 700; color: #fff; flex-shrink: 0; }

/* pratinjau foto bulat di form tambah/ubah anggota (bukan kartu pohon) */
.ft-photo-wrap { border-radius: 50%; border: 3px solid var(--gold); box-shadow: 0 3px 10px var(--shadow); display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--card); position: relative; flex-shrink: 0; }
.ft-photo-img { width: 100%; height: 100%; object-fit: cover; }
.ft-initials { font-family: 'Fraunces', serif; font-weight: 600; color: #fff; font-size: 18px; }

/* popover */
.ft-popover { position: fixed; z-index: 60; background: var(--card); border-radius: 16px; box-shadow: 0 14px 36px var(--shadow); border: 1px solid var(--gold-soft); padding: 14px; width: 240px; animation: ftPop .14s ease; }
@keyframes ftPop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }

/* modal */
.ft-modal-overlay { position: fixed; inset: 0; background: rgba(30,24,14,.45); display: flex; align-items: center; justify-content: center; z-index: 80; padding: 16px; backdrop-filter: blur(2px); }
.ft-modal { background: var(--card); border-radius: 18px; max-width: 520px; width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,.35); position: relative; }
.ft-modal.narrow { max-width: 380px; }
.ft-modal-header { padding: 20px 22px 0; display: flex; justify-content: space-between; align-items: flex-start; }
.ft-modal-body { padding: 18px 22px 22px; }

.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--paper-alt); border: 1px solid rgba(176,129,60,.35); color: var(--ink); border-radius: 999px; padding: 5px 12px 5px 5px; font-size: 12.5px; font-weight: 600; cursor: pointer; margin: 3px 5px 3px 0; }
.chip:hover { background: var(--gold-soft); }
.pill { background: var(--paper-alt); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; display: inline-block; margin: 0 6px 6px 0; }

.error-box { background: #F5DCD5; color: var(--brick); padding: 9px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; display: flex; gap: 6px; align-items: center; }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; text-align: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 100; box-shadow: 0 10px 24px var(--shadow); }

.centered-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }

::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--canvas-line); border-radius: 8px; }

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