/* ============================================================
   شجرة عائلة أبو حجلة — التصميم العام
   Palette: deep heritage green + parchment + gold
   ============================================================ */

:root {
  --paper: #f3eee3;
  --paper-2: #ece5d4;
  --surface: #fffdf6;
  --surface-2: #faf6ea;
  --ink: #21322a;
  --muted: #6f7d6e;
  --faint: #98a48f;
  --line: #e2dbc6;
  --line-2: #d3ceba;

  --green: #1e5c43;
  --green-deep: #123b2c;
  --green-darker: #0c2b20;
  --green-soft: #e4eee2;
  --green-ring: rgba(30, 92, 67, 0.28);

  --gold: #c19a3f;
  --gold-deep: #a37f2c;
  --gold-soft: #f3e7c6;

  --rose: #a85d68;
  --rose-soft: #f5e6e4;

  --danger: #a94b31;
  --danger-soft: #f6e2da;

  --shadow-sm: 0 2px 8px rgba(24, 44, 32, 0.08);
  --shadow-md: 0 10px 30px rgba(24, 44, 32, 0.13);
  --shadow-lg: 0 24px 60px rgba(18, 43, 32, 0.25);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;

  --topbar-h: 66px;
  --font: "Cairo", "Segoe UI", system-ui, sans-serif;
  --font-display: "Amiri", "Cairo", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  overflow-x: hidden;
}
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.3; }
p { margin: 0; }
a { color: var(--green); text-decoration: none; }
button { font-family: inherit; }
img, svg { vertical-align: middle; }
mark { background: var(--gold-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ============ buttons & inputs ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--green);
  color: #fdfbf3;
  font-weight: 700; font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s;
  text-decoration: none;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--green-deep); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.green { background: var(--green); }
.btn.green:hover { background: var(--green-deep); }
.btn.ghost {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 253, 246, 0.32);
  color: #f6f1df;
  backdrop-filter: blur(4px);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.18); }
.btn.outline {
  background: transparent; color: var(--green);
  border-color: var(--line-2);
}
.btn.outline:hover { background: var(--green-soft); border-color: var(--green); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8e3b25; }
.btn.small { padding: 7px 14px; font-size: 0.85rem; }
.btn.tiny { padding: 4px 12px; font-size: 0.78rem; }
.btn.tiny.ghost { background: transparent; border-color: var(--line-2); color: var(--muted); }
.btn.tiny.ghost:hover { color: var(--green); border-color: var(--green); background: var(--green-soft); }

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--green); border-color: var(--green); background: var(--green-soft); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.field input, .field select {
  font-family: inherit; font-size: 0.92rem;
  padding: 9px 13px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.field input:focus, .field select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-ring);
}
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f7d6e' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 34px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 0.72rem; color: var(--faint); }
.muted { color: var(--muted); }

.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--faint); pointer-events: none;
}
.search-wrap input { padding-right: 36px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--line-2);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem; font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--green); color: var(--green); }
.chip.active {
  background: var(--green); border-color: var(--green);
  color: #fdfbf3;
  box-shadow: 0 3px 10px rgba(30, 92, 67, 0.3);
}

/* ============ topbar ============ */
.topbar, .site-header {
  min-height: var(--topbar-h);
  background:
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cpath d='M28 4l5.4 12.3L46 10l-6.3 12.6L52 28l-12.3 5.4L46 46l-12.6-6.3L28 52l-5.4-12.3L10 46l6.3-12.6L4 28l12.3-5.4L10 10l12.6 6.3z' fill='none' stroke='rgba(243,231,198,0.07)' stroke-width='1.2'/%3E%3C/svg%3E"),
    linear-gradient(120deg, var(--green-darker), var(--green-deep) 55%, #17452f);
  color: #f6f1df;
  position: sticky; top: 0; z-index: 60;
  box-shadow: 0 4px 20px rgba(12, 35, 25, 0.35);
}
.topbar-inner, .header-inner {
  max-width: 1700px; margin: 0 auto;
  height: var(--topbar-h);
  padding: 0 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-text { min-width: 0; }
.brand-emblem {
  width: 42px; height: 42px; flex: none;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--gold), var(--gold-deep));
  color: var(--green-darker);
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 4px 12px rgba(0, 0, 0, 0.3);
}
.brand-emblem svg { width: 26px; height: 26px; }
.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.34rem; font-weight: 700;
  color: #fbf7ea;
  letter-spacing: 0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-text p {
  font-size: 0.72rem; color: rgba(246, 241, 223, 0.66);
  margin-top: -3px;
  white-space: nowrap;
}
.topbar-nav, .header-nav { display: flex; align-items: center; gap: 9px; flex: none; }

/* ============ app layout ============ */
.app {
  display: grid;
  grid-template-columns: 330px 1fr;
  height: calc(100dvh - var(--topbar-h));
  max-width: 1700px;
  margin: 0 auto;
}

/* ============ side panel ============ */
.side-panel {
  border-left: 1px solid var(--line);
  background: var(--surface-2);
  overflow-y: auto;
  display: flex; flex-direction: column;
  z-index: 55;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(18, 40, 29, 0.45);
  z-index: 89;
  backdrop-filter: blur(2px);
}

.stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  padding: 16px 16px 4px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 14px 9px;
  display: flex; flex-direction: column; gap: 0;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute; right: 0; top: 10px; bottom: 10px;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--green);
}
.stat.gold::before { background: var(--gold); }
.stat.rose::before { background: var(--rose); }
.stat.gray::before { background: var(--faint); }
.stat b { font-size: 1.3rem; font-weight: 800; color: var(--green-deep); line-height: 1.25; }
.stat span { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.stat.wide { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 10px; }

.filters { padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 13px; }
.filters-head { display: flex; align-items: center; justify-content: space-between; }
.filters-head h2 { font-size: 0.98rem; font-weight: 800; color: var(--green-deep); }

/* results */
.results-panel {
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(var(--surface), var(--surface-2));
}
.results-head h2 { font-size: 0.88rem; font-weight: 800; color: var(--gold-deep); }
.results { display: flex; flex-direction: column; gap: 8px; }
.result-card {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.14s;
  text-align: start;
  width: 100%;
  font-family: inherit;
  color: inherit;
}
.result-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow-sm);
  transform: translateX(-2px);
}
.result-card .rc-main { flex: 1; min-width: 0; }
.result-card .rc-name { font-weight: 700; font-size: 0.92rem; }
.result-card .rc-name .en { font-size: 0.72rem; color: var(--faint); font-weight: 600; }
.result-card .rc-meta { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results-more { font-size: 0.76rem; color: var(--muted); text-align: center; padding: 4px; }

.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.95rem;
  color: #fff;
  background: linear-gradient(140deg, #2e7d58, var(--green-deep));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
  position: relative;
  overflow: hidden;
}
.avatar.F { background: linear-gradient(140deg, #c07a84, #8e4550); }
.avatar.dead { filter: grayscale(0.75) brightness(1.05); }
/* photo overlays the initial; onerror removes it and the initial shows through */
.avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.avatar.has-photo { border: 2px solid var(--green); box-shadow: none; }
.avatar.F.has-photo { border-color: var(--rose); }
.avatar.dead.has-photo { border-color: #9aa48f; }

.panel-foot {
  margin-top: auto;
  padding: 14px 18px;
  font-size: 0.7rem; color: var(--faint);
  border-top: 1px solid var(--line);
  text-align: center;
}

/* ============ tree area ============ */
.tree-area {
  display: flex; flex-direction: column;
  min-width: 0;
  position: relative;
}
.crumbs-bar {
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 246, 0.8);
  backdrop-filter: blur(6px);
  overflow-x: auto;
  scrollbar-width: thin;
}
.crumbs { display: flex; align-items: center; gap: 4px; white-space: nowrap; min-height: 30px; }
.crumb {
  display: inline-flex; align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem; font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.14s;
  font-family: inherit;
}
.crumb:hover { color: var(--green); background: var(--green-soft); }
.crumb.current {
  color: #fdfbf3;
  background: var(--green);
  cursor: default;
  box-shadow: 0 3px 10px rgba(30, 92, 67, 0.3);
}
.crumb.current:hover { color: #fdfbf3; background: var(--green); }
.crumb-sep { color: var(--line-2); font-size: 0.85rem; flex: none; }

.tree-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(30, 60, 45, 0.075) 1.1px, transparent 1.1px),
    var(--paper);
  background-size: 26px 26px, auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tree-viewport.dragging { cursor: grabbing; }
.stage {
  position: absolute; top: 0; left: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.stage.anim { transition: transform 0.55s cubic-bezier(0.22, 1, 0.3, 1); }

.edges {
  position: absolute; top: 0; left: 0;
  width: 1px; height: 1px;
  overflow: visible;
}
.edge {
  fill: none;
  stroke: #b7b08d;
  stroke-width: 2;
  opacity: 0;
  animation: edgeIn 0.5s ease 0.1s forwards;
}
.edge.main { stroke: var(--gold); stroke-width: 2.6; }
@keyframes edgeIn { to { opacity: 0.8; } }

/* ---------- tree nodes ---------- */
.tnode {
  position: absolute;
  background: var(--surface);
  border: 1.5px solid var(--line-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
  animation: nodeIn 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
  display: flex; flex-direction: row; align-items: center;
}
/* avatars inside tree cards */
.avatar.tn-ava { width: 44px; height: 44px; font-size: 1rem; margin-inline-start: 12px; }
.avatar.tn-ava-lg { width: 58px; height: 58px; font-size: 1.4rem; }
.avatar.tn-ava-sm { width: 26px; height: 26px; font-size: 0.72rem; margin-inline-start: 10px; }
.tnode.focus .avatar.tn-ava { border-color: var(--gold); }
.tnode.dead .avatar { filter: grayscale(0.7) brightness(1.03); }
@keyframes nodeIn {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.tnode:hover { box-shadow: var(--shadow-md); border-color: var(--green); z-index: 5; }
.tnode::before {
  /* gender accent — start edge */
  content: "";
  position: absolute; top: -1.5px; bottom: -1.5px; right: -1.5px;
  width: 5px;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  background: var(--green);
}
.tnode.F::before { background: var(--rose); }
.tnode.dead { background: #f6f3ea; }
.tnode.dead .tn-name { color: #5d6b5d; }

.tn-body { padding: 8px 16px 7px 12px; flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.tn-name {
  font-weight: 800; font-size: 0.95rem;
  color: var(--green-deep);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.4;
}
.tn-en {
  font-size: 0.68rem; color: var(--faint); font-weight: 600;
  direction: ltr; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3;
}
.tn-meta {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
  flex-wrap: nowrap;      /* keep meta on ONE line so it never spills below the card */
  min-width: 0; max-width: 100%;
  overflow: hidden;       /* chips shrink/clip inside the fixed-height card, never spill */
}
.tn-years {
  font-size: 0.66rem; color: var(--muted); font-weight: 700; direction: ltr;
  white-space: nowrap;
  flex: 0 0 auto;   /* lifespan always shows in full */
}
.tn-kids {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.66rem; font-weight: 800;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 1px 8px;
  line-height: 1.6;
  flex: 0 0 auto;         /* the kids chip keeps its size; years ellipsizes if tight */
  white-space: nowrap;
}
/* deceased cards: reserve room at the bottom-start for the متوفّى badge */
.tnode.dead .tn-body { padding-bottom: 20px; }
.tn-dead-badge {
  position: absolute;
  bottom: 7px; inset-inline-end: 12px;
  font-size: 0.58rem; font-weight: 800;
  color: #8a8069;
  background: #ece6d6;
  border: 1px solid #dcd4c1;
  border-radius: 999px;
  padding: 0 7px;
  line-height: 1.55;
  pointer-events: none;
  z-index: 2;
}
.tn-info {
  position: absolute;
  top: 6px; left: 6px;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(30, 92, 67, 0.09);
  color: var(--green);
  font-size: 0.8rem; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 3;
  font-family: Georgia, serif;
  font-style: italic;
}
.tnode:hover .tn-info, .tnode.focus .tn-info { opacity: 1; }
@media (hover: none) { .tn-info { opacity: 1; } }
.tn-info:hover { background: var(--gold); color: #fff; }

/* focus node */
.tnode.focus {
  background: linear-gradient(150deg, #205f45, var(--green-deep) 70%);
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(193, 154, 63, 0.25), var(--shadow-lg);
  z-index: 6;
}
.tnode.focus::before { background: var(--gold); }
.tnode.focus .tn-name { color: #fbf7ea; font-size: 1.14rem; font-family: var(--font-display); }
.tnode.focus .tn-en { color: rgba(246, 241, 223, 0.55); }
.tnode.focus .tn-years { color: rgba(246, 241, 223, 0.75); }
.tnode.focus .tn-kids { background: rgba(193, 154, 63, 0.28); color: var(--gold-soft); }
.tnode.focus .tn-dead-badge { background: rgba(255, 255, 255, 0.14); color: #ddd5bd; }
.tnode.focus .tn-info { background: rgba(255, 255, 255, 0.15); color: var(--gold-soft); }
.tnode.focus .tn-info:hover { background: var(--gold); color: var(--green-darker); }

/* ancestor pill */
.tnode.anc {
  flex-direction: row; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: none;
}
.tnode.anc::before { display: none; }
.tnode.anc .tn-body { padding: 3px 14px; flex-direction: row; align-items: baseline; gap: 8px; justify-content: center; }
.tnode.anc .tn-name { font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.tnode.anc:hover .tn-name { color: var(--green); }
.tnode.anc .tn-gen { font-size: 0.62rem; color: var(--faint); font-weight: 700; flex: none; }

/* compact spouse hint inside context cards («⚭ آمنة») — lives in the one-line
   meta row and shrinks/ellipsizes so it can never overflow the card bounds */
.tn-sp {
  display: inline-block;
  font-size: 0.64rem; font-weight: 700;
  color: var(--muted);
  flex: 0 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.6;
}
.tnode.focus .tn-sp { color: rgba(246, 241, 223, 0.7); }

/* ---------- spouse cards beside the focus (couple layout) ---------- */
.tnode.spouse .tn-name { font-size: 0.92rem; }
.tnode.spouse.out {
  border-style: dashed;
  background: var(--surface-2);
  cursor: default;
}
.tnode.spouse.out:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.tnode.spouse.out::before { opacity: 0.55; }
.tn-sp-note { font-size: 0.62rem; color: var(--faint); font-weight: 700; line-height: 1.4; }

/* marriage connector + ⚭ marker */
.edge.marry {
  stroke: var(--gold);
  stroke-width: 2.4;
  animation: edgeIn 0.5s ease 0.1s forwards;
}
.marry-badge {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--gold);
  color: var(--gold-deep);
  font-size: 0.82rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 7;
  line-height: 1;
}

/* «+N» pill for extra spouses */
.tnode.spmore {
  border-radius: 999px;
  justify-content: center;
  background: var(--gold-soft);
  border-color: var(--gold);
  box-shadow: none;
}
.tnode.spmore::before { display: none; }
.tnode.spmore:hover { border-color: var(--gold-deep); box-shadow: var(--shadow-sm); }
.tn-spmore { font-size: 0.82rem; font-weight: 800; color: var(--gold-deep); }

/* role tag (e.g. الوالد) */
.tn-role {
  position: absolute;
  top: -10px; inset-inline-start: 12px;
  font-size: 0.6rem; font-weight: 800;
  background: var(--gold);
  color: #fff;
  padding: 1px 10px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  z-index: 2;
  line-height: 1.7;
}
.tn-role.sp { background: var(--rose); }

/* zoom dock */
.zoom-dock {
  position: absolute;
  bottom: 18px; inset-inline-end: 18px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 20;
}
.dock-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--green-deep);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
}
.dock-btn:hover { background: var(--green-soft); border-color: var(--green); transform: translateY(-1px); }
.dock-btn.home { background: var(--green); color: #fdfbf3; border-color: var(--green-deep); }
.dock-btn.home:hover { background: var(--green-deep); }

.legend {
  position: absolute;
  bottom: 18px; inset-inline-start: 18px;
  display: flex; align-items: center; gap: 13px;
  padding: 7px 14px;
  background: rgba(255, 253, 246, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  z-index: 20;
  font-size: 0.7rem; color: var(--muted); font-weight: 700;
}
.legend .lg { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend .dot.m { background: var(--green); }
.legend .dot.f { background: var(--rose); }
.legend .dot.d { background: #b3ac93; }
.legend .hint-drag { color: var(--faint); border-inline-start: 1px solid var(--line); padding-inline-start: 13px; }

/* loading / error */
.tree-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--paper);
  z-index: 30;
  color: var(--muted); font-weight: 700;
}
.loader {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 4px solid var(--green-soft);
  border-top-color: var(--green);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tree-error {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--danger); font-weight: 700;
  z-index: 29;
  padding: 20px; text-align: center;
}

/* ============ drawer ============ */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(14, 33, 24, 0.5);
  z-index: 80;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(430px, 94vw);
  background: var(--surface);
  z-index: 81;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  animation: drawerIn 0.34s cubic-bezier(0.22, 1, 0.3, 1);
}
@keyframes drawerIn { from { transform: translateX(-40px); opacity: 0; } }
.drawer-close {
  position: absolute;
  top: 14px; inset-inline-start: 14px;
  z-index: 5;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
  color: #f0ead6;
}
.drawer-close:hover { background: rgba(255, 255, 255, 0.28); color: #fff; border-color: rgba(255, 255, 255, 0.4); }
.drawer-body { display: flex; flex-direction: column; min-height: 100%; }

.dr-hero {
  background:
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cpath d='M28 4l5.4 12.3L46 10l-6.3 12.6L52 28l-12.3 5.4L46 46l-12.6-6.3L28 52l-5.4-12.3L10 46l6.3-12.6L4 28l12.3-5.4L10 10l12.6 6.3z' fill='none' stroke='rgba(243,231,198,0.08)' stroke-width='1.2'/%3E%3C/svg%3E"),
    linear-gradient(150deg, #205f45, var(--green-darker));
  color: #fbf7ea;
  padding: 34px 26px 22px;
  text-align: center;
}
.dr-hero .avatar {
  width: 72px; height: 72px;
  font-size: 1.7rem;
  margin: 0 auto 12px;
  border: 3px solid rgba(243, 231, 198, 0.4);
}
.dr-hero .avatar.has-photo { border-color: rgba(243, 231, 198, 0.6); }
.dr-hero h2 { font-family: var(--font-display); font-size: 1.55rem; font-weight: 700; }
.dr-hero .dr-en { direction: ltr; font-size: 0.85rem; color: rgba(246, 241, 223, 0.6); font-weight: 600; }
.dr-badges { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.dr-badge {
  font-size: 0.7rem; font-weight: 800;
  padding: 2px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  color: #f0ead6;
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.dr-badge.gold { background: rgba(193, 154, 63, 0.3); color: var(--gold-soft); border-color: rgba(193, 154, 63, 0.4); }
.dr-actions { display: flex; gap: 8px; justify-content: center; margin-top: 15px; }
.dr-actions .btn { font-size: 0.8rem; padding: 6px 15px; }
.dr-actions .btn.gold { background: var(--gold); color: #fff; }
.dr-actions .btn.gold:hover { background: var(--gold-deep); }

.dr-section { padding: 18px 24px 4px; }
.dr-section h3 {
  font-size: 0.78rem; font-weight: 800;
  color: var(--gold-deep);
  letter-spacing: 0.3px;
  margin-bottom: 9px;
  display: flex; align-items: center; gap: 8px;
}
.dr-section h3::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.dr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.dr-item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 12px;
}
.dr-item.wide { grid-column: 1 / -1; }
.dr-item .k { font-size: 0.66rem; color: var(--faint); font-weight: 700; }
.dr-item .v { font-size: 0.88rem; font-weight: 700; color: var(--ink); word-break: break-word; }
.dr-item .v.ltr { direction: ltr; text-align: right; }
.dr-item .v a { color: var(--green); text-decoration: underline; text-underline-offset: 3px; }
.v-empty { color: var(--faint); font-weight: 600; }

.dr-lineage { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; }
.dr-lineage .crumb { font-size: 0.76rem; padding: 3px 10px; background: var(--surface-2); border-color: var(--line); }
.dr-lineage .crumb:hover { background: var(--green-soft); }
.dr-lineage .crumb.current { background: var(--green); }

/* spouses display (public + admin drawers) */
.spouse-list { display: flex; flex-wrap: wrap; gap: 7px; padding-bottom: 8px; }
.spouse-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  font-family: inherit; font-size: 0.85rem; font-weight: 700;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  line-height: 1.5;
}
.spouse-chip.in {
  cursor: pointer;
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--gold-deep);
  transition: all 0.14s;
}
.spouse-chip.in:hover {
  background: var(--gold); color: #fff; border-color: var(--gold-deep);
  box-shadow: var(--shadow-sm);
}
.spouse-chip .sp-ico { font-size: 0.78rem; }
.spouse-chip.out { color: var(--muted); }

.dr-children { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.dr-child {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.13s;
  width: 100%;
  text-align: start;
  font-family: inherit;
  color: inherit;
}
.dr-child:hover { border-color: var(--green); background: var(--green-soft); }
.dr-child .avatar { width: 30px; height: 30px; font-size: 0.8rem; }
.dr-child b { font-size: 0.86rem; display: block; line-height: 1.3; }
.dr-child .meta { font-size: 0.68rem; color: var(--muted); }
/* which-wife caption under a child's name (shown only when the person has >1 spouse) */
.dr-child .meta.mother { display: block; color: var(--gold-deep); font-weight: 700; }
.dr-empty { color: var(--faint); font-size: 0.82rem; padding: 2px 0 10px; }
.dr-foot { padding: 12px 24px 28px; }

/* ============ toast ============ */
.toast {
  position: fixed;
  bottom: 26px; right: 50%;
  transform: translateX(50%);
  background: var(--green-deep);
  color: #fdfbf3;
  font-weight: 700; font-size: 0.9rem;
  padding: 11px 26px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes toastIn { from { transform: translateX(50%) translateY(20px); opacity: 0; } }

/* ============ responsive ============ */
.only-mobile { display: none !important; }

@media (max-width: 980px) {
  .only-mobile { display: inline-flex !important; }
  .panel-head.only-mobile { display: flex !important; }
  .app { grid-template-columns: 1fr; }
  .side-panel {
    position: fixed;
    top: 0; bottom: 0; right: 0;
    width: min(360px, 92vw);
    transform: translateX(105%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.3, 1);
    box-shadow: var(--shadow-lg);
    border-left: none;
    z-index: 90;
  }
  .side-panel.open { transform: translateX(0); }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 1.08rem; }
  .topbar-inner, .header-inner { padding: 0 14px; }
  .btn { padding: 8px 13px; font-size: 0.84rem; }
  .legend .hint-drag { display: none; }
  .legend { font-size: 0.65rem; gap: 9px; padding: 6px 11px; bottom: 14px; }
  .drawer {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 86dvh;
    border-radius: 22px 22px 0 0;
    animation: sheetIn 0.34s cubic-bezier(0.22, 1, 0.3, 1);
  }
  @keyframes sheetIn { from { transform: translateY(60px); opacity: 0; } }
  .zoom-dock { bottom: 64px; }
  .crumbs-bar { padding: 8px 12px; }
}
