/*
 * Utmanz — family tree (shajra) page.
 *
 * One chart on every screen and on paper: a top-down genealogy chart drawn
 * right-to-left (the eldest on the right, as Urdu is read). site.js scales the
 * chart to fit its card — no scrollbars — with zoom, pinch and drag-to-pan.
 * Without JavaScript the card simply scrolls.
 */
:root { --tree-line: #C9B48A; --tree-gap: 34px; }

/* ---------- Person bar (compact header) ---------- */
.person-bar { position: relative; color: #fff; background: linear-gradient(160deg, var(--em-900), var(--em-950)); border-bottom: 1px solid rgba(217, 184, 114, .25); }
.person-bar::before { content: ""; position: absolute; inset: 0; background-image: var(--pattern); background-size: 72px; opacity: .07; pointer-events: none; }
.person-bar .container { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding-top: 16px; padding-bottom: 18px; }
.person-bar .crumbs { margin: 0 0 2px; font-size: 12.5px; }
.pb-names { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 18px; direction: rtl; justify-content: flex-end; }
.pb-name { margin: 0; font: 400 clamp(24px, 2.6vw, 32px)/1.9 var(--f-ur); color: #fff; }
.pb-father { margin: 0; font: 400 17px/1.9 var(--f-ur); color: var(--gold-200); }
.pb-father a { color: var(--gold-400); border-bottom: 1px solid rgba(217, 184, 114, .4); }
.pb-father a:hover { color: #fff; }
.pb-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex: none; }
.person-bar .chip { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); color: rgba(255, 255, 255, .86); font-size: 12.5px; padding: 4px 10px; }
.person-bar .chip.gold { background: rgba(201, 162, 90, .16); border-color: rgba(217, 184, 114, .35); color: var(--gold-200); }
.pb-actions { display: flex; gap: 8px; }
.btn-sm { min-height: 36px; padding: 0 16px; font-size: 13.5px; }
.btn-sm svg { width: 15px; height: 15px; }

/* ---------- Tree card (full page width) ---------- */
.tree-shell { margin: 20px 0 0; padding: 0 24px; }
.tree-panel { width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-md); overflow: hidden; }
.tree-panel:fullscreen { border-radius: 0; border: 0; display: flex; flex-direction: column; }
.tree-panel:fullscreen .tree-viewport { flex: 1; }

.tree-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #fff, var(--ivory)); }
.tree-tools .group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 40px; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: #fff; color: var(--em-800); font: 600 13.5px/1 var(--f-ui); cursor: pointer; transition: background .2s var(--ease), border-color .2s var(--ease); }
.tool:hover { background: var(--em-50); border-color: var(--em-200); color: var(--em-900); }
.tool svg { width: 17px; height: 17px; }
.tool[hidden] { display: none; }
.zoom-label { min-width: 52px; text-align: center; font: 600 13px/1 var(--f-ui); color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; border: 1px solid var(--line-strong); background: #fff; }
.legend i.focus { background: var(--em-800); border-color: var(--em-800); }
.legend i.father { background: var(--gold-100); border-color: var(--gold-400); }
.legend i.daughter { background: #FBF3F1; border-color: #E2C3BA; }

/* ---------- Stage ---------- */
.tree-viewport { position: relative; overflow: auto; max-height: 80vh;
  background: radial-gradient(circle at 1px 1px, rgba(14, 74, 58, .07) 1px, transparent 0) 0 0 / 22px 22px, var(--paper); }
.tree-canvas { width: max-content; padding: 32px 28px 40px; }
.js .tree-viewport { overflow: hidden; max-height: none; touch-action: pan-y; }
.js .tree-viewport.can-pan { cursor: grab; touch-action: none; }
.js .tree-viewport.is-dragging { cursor: grabbing; user-select: none; }
.js .tree-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.js .tree-canvas.is-animating { transition: transform .28s var(--ease); }
.tree-hint { position: absolute; right: 14px; bottom: 12px; z-index: 2; padding: 6px 12px; border-radius: 999px; background: rgba(5, 34, 27, .78); color: #fff; font: 500 12px/1.2 var(--f-ui); pointer-events: none; opacity: 0; transition: opacity .3s var(--ease); }
.tree-viewport.can-pan .tree-hint { opacity: 1; }

/* ---------- Chart ---------- */
.tree ul { position: relative; display: flex; justify-content: center; margin: 0; padding: var(--tree-gap) 0 0; list-style: none; }
.tree > ul { padding-top: 0; }
.tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: var(--tree-gap) 10px 0; list-style: none; }
.tree > ul > li { padding-top: 0; }
/* half-lines from each child up to the family bar */
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; width: 50%; height: var(--tree-gap); border-top: 2px solid var(--tree-line); }
.tree li::before { inset-inline-start: 0; }
.tree li::after { inset-inline-start: 50%; border-inline-start: 2px solid var(--tree-line); }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-inline-end: 2px solid var(--tree-line); border-start-end-radius: 12px; }
.tree li:first-child::after { border-start-start-radius: 12px; }
.tree li:only-child { padding-top: 0; }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
/* line from a parent down to its children's bar */
.tree ul ul::before { content: ""; position: absolute; top: 0; inset-inline-start: 50%; height: var(--tree-gap); border-inline-start: 2px solid var(--tree-line); }
.tree li:only-child > .person, .tree li:only-child > .family-group { margin-top: var(--tree-gap); }
.tree > ul > li:only-child > .person { margin-top: 0; }

/* ---------- Person node ---------- */
.person {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 150px; max-width: 230px; padding: 12px 18px 14px; border-radius: 16px;
  background: #fff; border: 1px solid var(--line-strong); color: var(--ink); text-align: center;
  box-shadow: 0 1px 2px rgba(10, 49, 40, .06); transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}
a.person:hover { transform: translateY(-2px); border-color: var(--em-600); box-shadow: var(--shadow-md); color: var(--ink); }
.person-role { font: 600 10.5px/1 var(--f-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); direction: ltr; }
.person-name { font: 400 19px/1.95 var(--f-ur); direction: rtl; color: var(--em-900); }
.person-spouse { display: inline-flex; align-items: center; gap: 6px; margin-top: 2px; padding: 2px 10px; border-radius: 999px; font: 400 13.5px/1.9 var(--f-ur); direction: rtl; background: var(--gold-100); color: var(--gold-700); border: 1px solid var(--gold-200); }
a.person-spouse:hover { background: var(--gold-200); color: var(--em-950); }
.person-spouse svg { width: 12px; height: 12px; }
.person.is-father { background: linear-gradient(180deg, var(--gold-100), #fff); border-color: var(--gold-400); }
.person.is-father .person-role { color: var(--gold-700); }
.person.is-daughter { background: #FBF3F1; border-color: #E2C3BA; }
.person.is-daughter .person-role { color: #9A5B4C; }
.person.is-focus {
  min-width: 190px; padding: 16px 22px 18px; background: linear-gradient(165deg, var(--em-700), var(--em-900));
  border: 0; color: #fff; box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--gold-500), var(--shadow-lg);
}
.person.is-focus .person-role { color: var(--gold-400); }
.person.is-focus .person-name { font-size: 24px; color: #fff; }
.person.is-focus .person-spouse { background: rgba(255, 255, 255, .1); border-color: rgba(217, 184, 114, .45); color: var(--gold-200); }
.person.is-focus .person-spouse:hover { background: rgba(255, 255, 255, .18); color: #fff; }

/* Notes: three lines in the chart; click for the full text (the chart re-fits) */
.person-note { width: 230px; margin: 8px 0 0; padding: 6px 12px; border-radius: 10px; font: 400 13.5px/2 var(--f-ur); direction: rtl; color: var(--ink-2); background: var(--parchment); border: 1px dashed var(--line-strong); text-align: center; }
.person-note[data-note] { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; cursor: pointer; }
.person-note[data-note].is-open { display: block; -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }

/* ---------- Large families: compact groups (fixed widths — identical on every screen) ---------- */
.tree ul.family-grid {
  display: grid; grid-template-columns: repeat(4, 160px); gap: 14px; justify-content: center;
  margin-top: var(--tree-gap); padding: 40px 22px 22px;
  border: 1.5px dashed var(--tree-line); border-radius: 20px; background: rgba(250, 247, 240, .75);
}
.tree ul.family-grid::before { top: calc(-1 * var(--tree-gap) - 2px); }
.tree ul.family-grid::after,
.family-group::before {
  content: attr(data-label); position: absolute; top: 13px; left: 50%; transform: translateX(-50%);
  font: 600 11px/1 var(--f-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--gold-700); direction: ltr; white-space: nowrap;
}
.tree ul.family-grid > li { padding: 0; }
.tree ul.family-grid > li::before, .tree ul.family-grid > li::after { display: none; }
.tree ul.family-grid .person, .family-group .person { width: 100%; min-width: 0; max-width: none; margin-top: 0; }
.tree ul.family-grid .person-note { width: 100%; }
.family-group {
  position: relative; display: grid; grid-template-columns: repeat(3, 160px); gap: 12px;
  padding: 40px 18px 18px; border: 1.5px dashed var(--tree-line); border-radius: 20px; background: rgba(250, 247, 240, .75);
}

/* ---------- Silsila (line of forefathers) ---------- */
.silsila-card { margin: 28px 24px 96px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-md); overflow: hidden; }
.silsila-head { padding: 26px 32px 22px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--ivory), #fff); }
.silsila-head h2 { margin: 10px 0 6px; font: 600 32px/1.1 var(--f-display); color: var(--em-900); }
.silsila-head p { margin: 0; color: var(--muted); font-size: 15px; }
.silsila-head p .ur { font-size: 17px; color: var(--em-800); }
/* trunk down the middle; generations branch off alternately (earliest at the top) */
.lineage { position: relative; list-style: none; margin: 0; padding: 40px 32px 48px;
  background: radial-gradient(circle at 1px 1px, rgba(14, 74, 58, .06) 1px, transparent 0) 0 0 / 22px 22px; }
.lineage::before { content: ""; position: absolute; top: 40px; bottom: 76px; left: 50%; width: 3px; transform: translateX(-50%); border-radius: 3px; background: linear-gradient(180deg, var(--gold-200), var(--tree-line) 12%, var(--tree-line) 88%, var(--em-600)); }
.lineage li { position: relative; display: flex; width: 50%; min-height: 64px; }
.lineage li:nth-child(odd) { justify-content: flex-end; padding-right: 44px; }
.lineage li:nth-child(even) { margin-left: 50%; padding-left: 44px; }
.lineage li + li { margin-top: -18px; }
.lineage li::before { content: ""; position: absolute; top: 31px; width: 44px; border-top: 2px solid var(--tree-line); }
.lineage li:nth-child(odd)::before { right: 0; }
.lineage li:nth-child(even)::before { left: 0; }
.lineage .dot { position: absolute; top: 25px; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--gold-500); z-index: 1; }
.lineage li:nth-child(odd) .dot { right: -7px; }
.lineage li:nth-child(even) .dot { left: -7px; }
.lineage li:first-child .dot { background: var(--gold-500); }
.lineage-node { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; width: min(100%, 440px); padding: 10px 18px 12px; border-radius: 14px; background: #fff; border: 1px solid var(--line-strong); color: var(--ink); box-shadow: 0 1px 2px rgba(10, 49, 40, .05); transition: transform .2s var(--ease), border-color .2s var(--ease), box-shadow .2s var(--ease); }
a.lineage-node:hover { transform: translateY(-2px); border-color: var(--em-600); box-shadow: var(--shadow-md); color: var(--ink); }
.lineage-node .gen-no { font: 600 10.5px/1 var(--f-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); direction: ltr; align-self: flex-start; }
.lineage-node .nm { width: 100%; font: 400 20px/1.95 var(--f-ur); direction: rtl; text-align: right; color: var(--em-900); white-space: normal; overflow-wrap: anywhere; }
.lineage-node.is-father { background: linear-gradient(180deg, var(--gold-100), #fff); border-color: var(--gold-400); }
.lineage-node.is-father .gen-no { color: var(--gold-700); }
.lineage-node.is-self { background: linear-gradient(165deg, var(--em-700), var(--em-900)); border: 0; box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--gold-500), var(--shadow-md); }
.lineage-node.is-self .gen-no { color: var(--gold-400); }
.lineage-node.is-self .nm { color: #fff; font-size: 24px; }
.lineage li.is-self .dot { background: var(--em-700); border-color: var(--gold-400); box-shadow: 0 0 0 4px var(--gold-100); }

/* ---------- Small screens: same chart, compact chrome ---------- */
@media screen and (max-width: 900px) {
  .person-bar .container { flex-direction: column; align-items: stretch; gap: 8px; padding-top: 12px; padding-bottom: 14px; }
  .pb-names { justify-content: flex-start; }
  .pb-side { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
}
@media screen and (max-width: 760px) {
  .pb-name { font-size: 24px; }
  .pb-father { font-size: 15px; }
  .person-bar .chips { display: none; }
  .pb-side { justify-content: flex-start; }
  .tree-shell { padding: 0 10px; margin-top: 14px; }
  .tree-tools { padding: 10px; }
  .legend { display: none; }
  .tool { height: 38px; padding: 0 10px; }
  .silsila-card { margin: 20px 10px 64px; }
  .silsila-head { padding: 20px 18px 16px; }
  .silsila-head h2 { font-size: 26px; }
  .lineage { padding: 24px 14px 30px; }
  /* silsila on a phone: one side only — trunk on the right */
  .lineage::before { left: auto; right: 22px; transform: none; bottom: 60px; }
  .lineage li, .lineage li:nth-child(odd), .lineage li:nth-child(even) { width: 100%; margin-left: 0; padding: 0 44px 0 0; justify-content: flex-start; }
  .lineage li + li { margin-top: 10px; }
  .lineage li::before, .lineage li:nth-child(odd)::before, .lineage li:nth-child(even)::before { left: auto; right: 23px; width: 21px; }
  .lineage li .dot, .lineage li:nth-child(odd) .dot, .lineage li:nth-child(even) .dot { left: auto; right: 16px; }
  .lineage-node { width: 100%; }
}

/* ---------- Print: exactly what is on screen (site.js scales the stage to the page) ---------- */
.print-head { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { background: #fff !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .site-header, .site-footer, .person-bar, .tree-tools, .tree-hint, .skip-link { display: none !important; }
  /* centred logo, then the person and the date */
  .print-head { display: block !important; text-align: center; margin: 0 0 4mm; padding-bottom: 3mm; border-bottom: 1px solid var(--gold-500); }
  .print-logo { display: block; height: 22mm; width: auto; margin: 0 auto 1mm; }
  .print-person { margin: 0; font: 400 17px/1.9 var(--f-ur); color: var(--em-900); direction: rtl; }
  .print-meta { margin: 0; font: 500 10px/1.4 var(--f-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
  .tree-shell { text-align: center; }
  .print-mini { display: block !important; height: 13mm; width: auto; margin: 0 auto 4mm; }
  .tree-shell { margin: 0 !important; padding: 0 !important; }
  .tree-panel { width: auto !important; display: inline-block; box-shadow: none !important; border: 1px solid var(--line) !important; border-radius: 12px; }
  .silsila-card { margin: 0 !important; break-before: page; box-shadow: none; }
  .lineage li { break-inside: avoid; }
}
.print-mini { display: none; }
@media print {
  .silsila-head { text-align: center; }
  .silsila-head .eyebrow::before { display: none; }
}
