/* =========================================================
   Nasab — tema zamrud & emas
   ========================================================= */
:root {
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-ar: 'Amiri', 'Traditional Arabic', serif;
  --sidebar-w: 256px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a110e;
  --bg-2: #0e1814;
  --surface: #121d19;
  --surface-2: #18261f;
  --surface-3: #1f2f28;
  --border: #243630;
  --text: #ecf2ee;
  --text-2: #b6c4bc;
  --muted: #7d8f86;
  --primary: #2fb383;
  --primary-2: #43c897;
  --primary-ink: #04130d;
  --primary-soft: rgba(47, 179, 131, .13);
  --gold: #dbb75e;
  --gold-soft: rgba(219, 183, 94, .13);
  --male: #3987e5;
  --female: #d55181;
  --danger: #e66767;
  --danger-soft: rgba(230, 103, 103, .13);
  --warn: #e0a93a;
  --tree-link: #3a5248;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .25);
  --pattern-op: .05;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f0e6;
  --bg-2: #ebe5d5;
  --surface: #fffdf8;
  --surface-2: #f6f1e5;
  --surface-3: #ede6d4;
  --border: #e0d6bf;
  --text: #17201c;
  --text-2: #46534c;
  --muted: #76827b;
  --primary: #0f6b4f;
  --primary-2: #13855f;
  --primary-ink: #ffffff;
  --primary-soft: rgba(15, 107, 79, .1);
  --gold: #a87a1c;
  --gold-soft: rgba(184, 137, 43, .14);
  --male: #2a78d6;
  --female: #c8467a;
  --danger: #c43d3d;
  --danger-soft: rgba(196, 61, 61, .1);
  --warn: #b7791f;
  --tree-link: #c9bc9c;
  --shadow: 0 12px 30px rgba(60, 45, 10, .12);
  --shadow-sm: 0 2px 10px rgba(60, 45, 10, .08);
  --pattern-op: .07;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.w-full { width: 100%; }
.ar { font-family: var(--font-ar); direction: rtl; }
::selection { background: var(--gold-soft); }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 22px 16px;
  overflow: hidden;
  z-index: 30;
}
.sidebar::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  opacity: var(--pattern-op);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23d9b45a' stroke-width='1.2'%3E%3Cpath d='M40 4l10 26 26 10-26 10-10 26-10-26L4 40l26-10z'/%3E%3Crect x='22' y='22' width='36' height='36' transform='rotate(45 40 40)'/%3E%3Ccircle cx='40' cy='40' r='9'/%3E%3C/g%3E%3C/svg%3E");
}
.sidebar > * { position: relative; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--primary), #0b4a37);
  color: #f1d27f; box-shadow: 0 6px 18px rgba(15, 107, 79, .35);
}
.brand-logo svg { width: 30px; height: 30px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.brand-arabic { font-family: var(--font-ar); color: var(--gold); font-size: 15px; line-height: 1.1; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  color: var(--text-2); font-weight: 600;
  transition: background .2s, color .2s;
}
.nav a .ico { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; background: var(--surface); color: var(--muted); font-size: 14px; transition: inherit; }
.nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.active .ico { background: var(--primary); color: var(--primary-ink); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.family-chip { padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; }
.family-chip b { display: block; color: var(--gold); font-size: 13.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { min-width: 0; }
.topbar h1 { font-size: 20px; font-weight: 800; }
.page-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-search { margin-left: auto; width: min(340px, 40vw); }
.icon-btn.menu-btn { display: none; }
.view { padding: 26px 28px 60px; flex: 1; min-width: 0; animation: fadeUp .35s var(--ease); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- komponen dasar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 650; cursor: pointer;
  transition: transform .15s, background .2s, border-color .2s, box-shadow .2s;
  white-space: nowrap; text-decoration: none !important;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--primary-ink); border-color: transparent; box-shadow: 0 6px 16px rgba(15, 107, 79, .28); }
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-gold { background: var(--gold); color: #1d1503; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: inline-grid; place-items: center; font-size: 16px; color: var(--text); }
.icon-btn:hover { border-color: var(--primary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title h3 { font-size: 15.5px; font-weight: 750; }
.card-title .hint { font-size: 12px; color: var(--muted); }

.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.badge.green { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.male { color: var(--male); }
.badge.female { color: var(--female); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

input.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea.input { min-height: 92px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.invalid { border-color: var(--danger); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 650; color: var(--text-2); }
label.field small { font-weight: 500; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-section { grid-column: span 2; font-size: 11.5px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); font-weight: 800; padding-top: 8px; border-top: 1px dashed var(--border); margin-top: 4px; }
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 650; color: var(--text-2); font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.on { background: var(--surface-3); }

/* ---------- avatar ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; flex-shrink: 0; background: var(--surface-2); color: var(--male); border: 2px solid currentColor; overflow: hidden; font-size: 15px; }
.avatar.P { color: var(--female); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.wafat { border-style: dashed; border-color: var(--gold); }
.avatar.lg { width: 104px; height: 104px; font-size: 34px; border-width: 3px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; border-width: 1.5px; }

/* ---------- picker ---------- */
.picker { position: relative; }
.picker-input { padding-left: 36px !important; }
.picker::before { content: '⌕'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 17px; pointer-events: none; }
.picker-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; display: none; }
.picker.has-value .picker-clear { display: block; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 300px; overflow: auto; padding: 6px; display: none;
}
.picker.open .picker-list { display: block; }
.picker-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.picker-item:hover, .picker-item.hl { background: var(--surface-2); }
.picker-item .nm { font-weight: 650; font-size: 13.5px; }
.picker-item .sb { font-size: 11.5px; color: var(--muted); }
.picker-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- beranda ---------- */
.hero {
  position: relative; overflow: hidden;
  border-radius: 22px; padding: 30px 32px; margin-bottom: 20px;
  background: radial-gradient(120% 140% at 100% 0%, rgba(219, 183, 94, .22), transparent 55%), linear-gradient(135deg, #0f6b4f, #0a3f2f 70%);
  color: #f3f7f4; box-shadow: var(--shadow);
}
.hero::after {
  content: ''; position: absolute; right: -40px; top: -40px; width: 320px; height: 320px; opacity: .12;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23f1d27f' stroke-width='.8'%3E%3Cpath d='M50 2l13 35 35 13-35 13-13 35-13-35L2 50l35-13z'/%3E%3Crect x='22' y='22' width='56' height='56' transform='rotate(45 50 50)'/%3E%3Crect x='22' y='22' width='56' height='56'/%3E%3Ccircle cx='50' cy='50' r='18'/%3E%3Ccircle cx='50' cy='50' r='30'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}
.hero > * { position: relative; z-index: 1; }
.hero .ar { font-size: 26px; color: #f1d27f; line-height: 1.6; }
.hero h2 { font-size: 28px; font-weight: 800; margin: 4px 0 6px; }
.hero p { margin: 0; color: rgba(243, 247, 244, .82); max-width: 720px; }
.hero-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.hero .btn { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .2); }
.hero .btn:hover { background: rgba(255, 255, 255, .18); }
.hero .btn-gold { background: #e5c26a; color: #1d1503; border: 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden; }
.stat .lbl { font-size: 12px; color: var(--muted); font-weight: 650; display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--text-2); }
.stat .ic { position: absolute; right: 14px; top: 12px; font-size: 22px; opacity: .22; }

.split-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; gap: 2px; margin: 10px 0 8px; background: var(--surface); }
.split-bar span { display: block; height: 100%; }
.split-bar span:first-child { border-radius: 99px 0 0 99px; }
.split-bar span:last-child { border-radius: 0 99px 99px 0; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }

.bars { position: relative; }
.bars svg { width: 100%; display: block; overflow: visible; }
.bars .bar { transition: opacity .15s; cursor: default; }
.bars .bar:hover { opacity: .8; }
.chart-tip {
  position: fixed; z-index: 100; pointer-events: none; padding: 8px 11px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 12.5px; display: none;
}
.chart-tip b { display: block; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px dashed var(--border); color: var(--text); border-radius: 8px; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); text-decoration: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t1 { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .right { text-align: right; font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.list-row .right b { display: block; font-size: 15px; color: var(--gold); }

.quote { border-left: 3px solid var(--gold); padding: 6px 0 6px 16px; }
.quote .ar { font-size: 22px; color: var(--gold); line-height: 1.8; }
.quote p { margin: 6px 0 4px; color: var(--text-2); font-style: italic; }
.quote small { color: var(--muted); }

.empty {
  text-align: center; padding: 60px 20px; border: 1.5px dashed var(--border); border-radius: 22px; background: var(--surface);
}
.empty .big { font-size: 54px; margin-bottom: 8px; }
.empty h2 { font-size: 22px; margin-bottom: 6px; }
.empty p { color: var(--text-2); max-width: 520px; margin: 0 auto 18px; }
.empty .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- anggota ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .input { width: auto; }
.toolbar .search { flex: 1; min-width: 220px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.person-card {
  display: flex; gap: 13px; padding: 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); transition: transform .2s var(--ease), border-color .2s, box-shadow .2s; position: relative;
}
.person-card:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: var(--shadow); text-decoration: none; }
.person-card .info { min-width: 0; flex: 1; }
.person-card .nm { font-weight: 750; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-card .lq { color: var(--gold); font-size: 11.5px; font-weight: 700; }
.person-card .ns { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 8px; }
.person-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.count-line { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }

/* ---------- profil ---------- */
.profile-head {
  display: flex; gap: 24px; align-items: center; padding: 26px; border-radius: 22px; margin-bottom: 18px;
  background: linear-gradient(135deg, var(--surface), var(--surface-2)); border: 1px solid var(--border); position: relative; overflow: hidden;
}
.profile-head::after { content: ''; position: absolute; right: -60px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(var(--gold-soft), transparent 70%); }
.profile-head .info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.profile-head .lq { color: var(--gold); font-weight: 750; font-size: 13px; }
.profile-head h2 { font-size: 28px; font-weight: 800; }
.profile-head .badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.profile-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.nasab-line { font-size: 14px; color: var(--text-2); line-height: 1.9; }
.nasab-line a { color: var(--text); font-weight: 650; border-bottom: 1px dotted var(--muted); }
.nasab-line a:hover { color: var(--primary); text-decoration: none; }
.nasab-line .bin { color: var(--gold); font-weight: 700; margin: 0 4px; font-size: 12.5px; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.kv dd .hj { display: block; font-size: 12px; color: var(--gold); }

.rel-group { margin-bottom: 14px; }
.rel-group h4 { font-size: 11.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 13px; font-weight: 600; }
.pchip:hover { border-color: var(--primary); text-decoration: none; }
.pchip small { color: var(--muted); font-weight: 500; }
.pchip-x { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 0 0 4px; font-size: 14px; }
.pchip-x:hover { color: var(--danger); }
.add-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; border: 1.5px dashed var(--border); background: transparent; color: var(--muted); cursor: pointer; font-weight: 650; font-size: 12.5px; }
.add-chip:hover { border-color: var(--primary); color: var(--primary); }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 14px; }
.tl-item::before { content: ''; position: absolute; left: -21px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.tl-item.gold::before { border-color: var(--gold); }
.tl-item .yr { font-weight: 800; color: var(--gold); font-size: 12.5px; }
.tl-item .tx { font-size: 13.5px; }

/* ---------- pohon ---------- */
.tree-wrap { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 480px; }
.tree-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tree-toolbar .picker { width: 260px; }
.tree-stage {
  flex: 1; position: relative; border-radius: 20px; overflow: hidden; border: 1px solid var(--border);
  background-color: var(--bg-2);
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 22px 22px;
}
.tree-svg { display: block; cursor: grab; touch-action: none; user-select: none; }
.tree-svg.dragging { cursor: grabbing; }
.tree-node { cursor: pointer; }
.tree-node .node-bg { transition: stroke .2s, filter .2s; }
.tree-node:hover .node-bg { stroke: var(--primary); }
.tree-node.selected .node-bg { stroke: var(--gold); stroke-width: 3; filter: drop-shadow(0 6px 14px rgba(219, 183, 94, .35)); }
.tree-node.on-path .node-bg { stroke: var(--gold); }
.tree-node:focus { outline: none; }
.tree-node:focus-visible .node-bg { stroke: var(--primary); stroke-width: 3; }
.tree-link.on-path { stroke: var(--gold); stroke-width: 3; }
.tree-more { cursor: pointer; }
.tree-controls { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.tree-legend { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 14px; font-size: 12px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); padding: 7px 12px; border-radius: 10px; flex-wrap: wrap; }
.tree-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.zoom-lbl { font-size: 11px; text-align: center; color: var(--muted); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(400px, 92vw); z-index: 70;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(105%); transition: transform .3s var(--ease); overflow-y: auto; padding: 22px;
}
.drawer.open { transform: none; }
.drawer-close { position: absolute; right: 14px; top: 14px; }
.drawer-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 10px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.drawer-head h3 { font-size: 20px; }

/* ---------- hubungan ---------- */
.rel-pick { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: end; }
.rel-result { margin-top: 18px; }
.rel-big { text-align: center; padding: 26px 18px; border-radius: 20px; background: linear-gradient(135deg, var(--surface-2), var(--surface)); border: 1px solid var(--border); }
.rel-big .q { color: var(--text-2); font-size: 14px; }
.rel-big .term { font-size: 30px; font-weight: 800; color: var(--gold); margin: 6px 0; letter-spacing: -.3px; }
.rel-big .det { color: var(--text-2); font-size: 13.5px; }
.mahram { display: flex; gap: 14px; align-items: flex-start; padding: 18px; border-radius: 16px; border: 1px solid var(--border); }
.mahram .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; font-weight: 800; }
.mahram.mahram-yes .ic { background: var(--primary-soft); color: var(--primary); }
.mahram.mahram-no .ic { background: var(--danger-soft); color: var(--danger); }
.mahram.mahram-pair .ic { background: var(--gold-soft); color: var(--gold); }
.mahram.mahram-na .ic { background: var(--surface-2); color: var(--muted); }
.mahram h4 { font-size: 16px; margin-bottom: 4px; }
.mahram p { margin: 0; color: var(--text-2); font-size: 13.5px; }
.mahram ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.path .arrow { color: var(--muted); font-size: 13px; }
.path .pchip.lca { border-color: var(--gold); background: var(--gold-soft); }
.note { font-size: 12.5px; color: var(--muted); padding: 12px 14px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); }

/* ---------- haul ---------- */
.haul-card { display: grid; grid-template-columns: 76px 1fr auto; gap: 16px; align-items: center; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .2s; }
.haul-card:hover { border-color: var(--gold); text-decoration: none; }
.haul-date { text-align: center; border-radius: 12px; background: var(--gold-soft); padding: 8px 4px; color: var(--gold); }
.haul-date .d { font-size: 24px; font-weight: 800; line-height: 1; }
.haul-date .m { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.haul-card .nm { font-weight: 750; font-size: 15px; }
.haul-card .sb { font-size: 12.5px; color: var(--text-2); }
.haul-card .cd { text-align: right; }
.haul-card .cd b { font-size: 20px; display: block; color: var(--text); }
.haul-card .cd small { color: var(--muted); }
.haul-card.today { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.haul-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 90; display: none; }
.modal-root.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 8, 6, .55); backdrop-filter: blur(3px); animation: fade .2s; }
.modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(720px, 94vw); max-height: 92vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); animation: pop .25s var(--ease);
}
.modal.sm { width: min(460px, 94vw); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } }
.photo-field { display: flex; align-items: center; gap: 14px; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 11px 18px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow); font-weight: 600; font-size: 13.5px; animation: fadeUp .25s var(--ease); display: flex; gap: 8px; align-items: center; }
.toast.ok { border-color: var(--primary); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- data page ---------- */
.data-actions { display: flex; flex-direction: column; gap: 10px; }
.data-row { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.data-row .grow { flex: 1; }
.data-row h4 { font-size: 14.5px; }
.data-row p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- responsif ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .g-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .3s var(--ease); box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 25; display: none; }
  .sidebar.open + .sidebar-backdrop { display: block; }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar-search { display: none; }
  .view { padding: 18px 16px 50px; }
  .g-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2, .form-section { grid-column: span 1; }
  .profile-head { flex-direction: column; text-align: center; }
  .profile-head .badges, .profile-head .actions { justify-content: center; }
  .rel-pick { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
  .tree-wrap { height: calc(100vh - 120px); }
  .haul-card { grid-template-columns: 60px 1fr; }
  .haul-card .cd { grid-column: span 2; text-align: left; }
  .kv { grid-template-columns: 110px 1fr; }
}

/* ---------- cetak ---------- */
@media print {
  .sidebar, .topbar, .profile-head .actions, .add-chip, .pchip-x, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .view { padding: 0; }
  .card, .profile-head { box-shadow: none; break-inside: avoid; }
}

/* ---------- foto, siluet, poligami ---------- */
.avatar .sil { width: 100%; height: 100%; display: block; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-btn { border: 0; padding: 0; background: none; cursor: zoom-in; border-radius: 50%; display: block; }
.avatar-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.avatar-btn .avatar { transition: transform .2s var(--ease), box-shadow .2s; }
.avatar-btn:hover .avatar { transform: scale(1.04); box-shadow: 0 8px 22px rgba(0, 0, 0, .25); }
.photo-badge { position: absolute; right: 0; bottom: 2px; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--surface); background: var(--primary); color: var(--primary-ink); cursor: pointer; font-size: 15px; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.photo-badge:hover { filter: brightness(1.1); }
.photo-view { width: min(340px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 22px; overflow: hidden; background: var(--surface-2); color: var(--male); border: 3px solid currentColor; }
.photo-view.P { color: var(--female); }
.photo-view img, .photo-view .sil { width: 100%; height: 100%; object-fit: cover; display: block; }
.spouse-chip { display: inline-flex; align-items: center; gap: 2px; }
.chip-edit { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 12px; }
.chip-edit:hover { color: var(--primary); border-color: var(--primary); }
.child-group { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--border); margin-bottom: 8px; }
.cg-head { font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.cg-head small { color: var(--muted); font-weight: 600; }
.child-group .pchip { background: var(--surface); }
.parent-chips:empty { display: none; }
.parent-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.pc-lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.pc { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 99px; padding: 4px 11px; font-size: 12px; font-weight: 650; cursor: pointer; }
.pc small { color: var(--gold); font-weight: 700; }
.pc:hover { border-color: var(--primary); }
.pc.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* ---------- pohon keluarga besar ---------- */
.tree-toggle { cursor: pointer; }
.tree-toggle:hover rect { filter: brightness(1.15); }
/* level detail: saat diperkecil, sembunyikan foto & baris kedua agar ringan */
.tree-svg.lod-mid .n-av, .tree-svg.lod-mid .n-t2, .tree-svg.lod-mid .n-t3, .tree-svg.lod-mid .n-alm, .tree-svg.lod-mid .tree-junction text { display: none; }
.tree-svg.lod-mid .n-name { font-size: 17px; transform: translate(0, -24px); }
.tree-svg.lod-far .n-av, .tree-svg.lod-far .n-name, .tree-svg.lod-far .n-t2, .tree-svg.lod-far .n-t3, .tree-svg.lod-far .n-alm, .tree-svg.lod-far .tree-junction, .tree-svg.lod-far .tree-toggle text { display: none; }
.tree-svg.lod-far .n-L .node-bg { fill: var(--male); fill-opacity: .55; }
.tree-svg.lod-far .n-P .node-bg { fill: var(--female); fill-opacity: .55; }
.tree-svg.lod-far .tree-link { stroke-width: 4; }

/* daftar silsilah (outline) */
.outline { border: 1px solid var(--border); border-radius: 20px; background: var(--surface); padding: 8px 6px; overflow: auto; flex: 1; }
.ol-row { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px calc(10px + var(--d) * 26px); border-radius: 10px; min-height: 44px; position: relative; flex-wrap: wrap; }
.ol-row::before { content: ''; position: absolute; left: calc(22px + (var(--d) - 1) * 26px); top: 0; bottom: 0; border-left: 1px dashed var(--border); display: var(--line, block); }
.ol-row[style*="--d:0"]::before { display: none; }
.ol-row:hover { background: var(--surface-2); }
.ol-row.hl { background: var(--gold-soft); box-shadow: 0 0 0 2px var(--gold) inset; }
.ol-chev { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; font-size: 12px; flex-shrink: 0; position: relative; z-index: 1; }
.ol-chev.none { visibility: hidden; }
.ol-chev:hover { border-color: var(--primary); color: var(--primary); }
.ol-name { font-weight: 700; color: var(--text); }
.ol-name:hover { color: var(--primary); text-decoration: none; }
.ol-lq { font-size: 11.5px; color: var(--gold); font-weight: 700; }
.ol-meta { font-size: 12px; color: var(--muted); }
.ol-sp { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.ol-count { margin-left: auto; font-size: 11.5px; color: var(--primary); font-weight: 700; background: var(--primary-soft); padding: 2px 8px; border-radius: 99px; }
.load-more { grid-column: 1 / -1; justify-self: center; margin: 8px 0; }
@media (max-width: 860px) {
  .tree-toolbar .seg button { padding: 6px 9px; }
  .tree-toolbar > div[id^="tr-root"], .tree-toolbar > div[id^="tr-find"] { flex: 1 1 100%; }
  .ol-row { padding-left: calc(8px + var(--d) * 16px); }
  .ol-row::before { left: calc(20px + (var(--d) - 1) * 16px); }
  .ol-sp { max-width: 100%; flex-basis: 100%; padding-left: 64px; }
  .ol-count { margin-left: 0; }
}

/* jalur dzurriyah lewat ibu */
.dz-line { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--gold-soft); border: 1px dashed var(--gold); }
.dz-label { font-size: 11px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--gold); margin-bottom: 2px; }
.dz-line .nasab-line { font-size: 13px; line-height: 1.8; }
.via-ibu { font-size: 11px; color: var(--female); font-weight: 700; }
.drawer .dz-line { text-align: left; }
