/* ============================================================
   Shajra-e-Sadri — interface styles
   Navy ink + brass thread. Serif for names, sans for controls.
   ============================================================ */

:root {
  --ink: #0c1f3f;
  --ink-2: #27385a;
  --text: #18233b;
  --muted: #5f6b80;
  --paper: #eef1f6;
  --surface: #ffffff;
  --line: #d3d9e4;
  --line-soft: #e4e8f0;
  --band: #f3f5f9;
  --brass: #b08a3e;
  --brass-ink: #7d5f1a;
  --focus: #2563eb;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --header-h: 64px;
  --status-h: 42px;
  --panel-w: 392px;
  --shadow: 0 1px 2px rgba(12, 31, 63, .08), 0 6px 18px rgba(12, 31, 63, .10);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
body.shajra-app {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--header-h);
  display: grid;
  grid-template-columns: auto minmax(220px, 560px) auto;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--ink);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark { display: grid; place-items: center; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text h1 {
  margin: 0; font: 600 21px/1.15 var(--serif); letter-spacing: .1px; color: #fff; white-space: nowrap;
}
.brand-text span { font-size: 12px; color: #aebbd3; white-space: nowrap; }

.search { position: relative; }
.search input {
  width: 100%; height: 42px;
  padding: 0 40px 0 42px;
  border: 1px solid transparent; border-radius: 11px;
  background: #fff; color: var(--text);
  font: 500 15px var(--sans);
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search input::placeholder { color: #7b879b; font-weight: 400; }
.search input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(176, 138, 62, .35); }
.search-icon { position: absolute; left: 14px; top: 12px; color: #6b778c; pointer-events: none; }
.search kbd {
  position: absolute; right: 11px; top: 10px;
  min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 6px;
  font: 600 11px var(--sans); color: #6b778c; background: #f6f8fb;
}
.search input:focus ~ kbd { display: none; }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: #fff; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: min(60vh, 420px); overflow: auto;
}
.suggest li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.suggest li[aria-selected="true"], .suggest li:hover { background: #eef2fa; }
.suggest .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.suggest .nm { font: 600 15px var(--serif); }
.suggest .sub { display: block; font-size: 12.5px; color: var(--muted); }
.suggest .more, .suggest .none { padding: 9px 10px; font-size: 13px; color: var(--muted); cursor: default; }
.suggest mark { background: rgba(176, 138, 62, .28); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--text);
  font: 600 13.5px var(--sans);
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: #f4f6fa; border-color: #b9c3d3; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #17305c; border-color: #17305c; }
.btn-brass { background: var(--brass); border-color: var(--brass); color: #1b1405; height: 42px; padding: 0 18px; }
.btn-brass:hover { background: #c29a48; border-color: #c29a48; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: rgba(12, 31, 63, .07); border-color: transparent; }
.btn-tool { height: 34px; padding: 0 12px; font-size: 13px; box-shadow: var(--shadow); }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: rgba(12, 31, 63, .08); }

/* ---------- workspace ---------- */

.workspace {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--header-h) - var(--status-h));
  height: calc(100dvh - var(--header-h) - var(--status-h));
  min-height: 440px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.workspace:fullscreen { height: 100vh; }

.lineage {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 7px 14px;
  background: #fbf7ec;
  border-bottom: 1px solid #eadfc2;
}
.lineage-label { flex: none; font-size: 12.5px; font-weight: 600; color: var(--brass-ink); }
.lineage-chips {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 4px;
  overflow-x: auto; scrollbar-width: none; white-space: nowrap;
}
.lineage-chips::-webkit-scrollbar { display: none; }
.lineage-chips button {
  flex: none; border: 1px solid #e6d9b6; background: #fff; color: var(--ink);
  border-radius: 999px; padding: 3px 11px; font: 600 13px var(--serif);
}
.lineage-chips button:hover { border-color: var(--brass); }
.lineage-chips button[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.lineage-chips .sep { flex: none; color: var(--brass); font-size: 14px; }

.stage {
  position: relative; flex: 1; min-height: 0;
  overflow: hidden; background: #fff;
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab;
}
.stage:focus-visible { outline-offset: -3px; }
.stage.is-dragging { cursor: grabbing; }
.tree-svg { display: block; width: 100%; height: 100%; }

/* tree drawing */
.band { fill: var(--band); }
.link { fill: none; stroke: #9eabbf; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.link-hot { fill: none; stroke: var(--brass); stroke-width: 3.2; stroke-linejoin: round; stroke-linecap: round; }
.node { cursor: pointer; outline: none; }
.node .card { fill: #fff; stroke: #c6cfdd; stroke-width: 1.2; transition: stroke .12s; }
.node:hover .card { stroke: #8795ad; }
.node.on-path .card { stroke: var(--brass); stroke-width: 1.8; }
.node.selected .card { stroke: var(--brass); stroke-width: 3; filter: drop-shadow(0 4px 9px rgba(176, 138, 62, .4)); }
.node:focus-visible .card { stroke: var(--focus); stroke-width: 3; }
.node .tile { stroke: rgba(255, 255, 255, .6); stroke-width: 1; opacity: .92; }
.node.selected .tile { stroke: var(--brass); stroke-width: 6; opacity: 1; }
.node.on-path .tile { stroke: var(--brass); stroke-width: 3; }
.nm { font-family: var(--serif); font-weight: 600; fill: var(--text); pointer-events: none; }
.meta { font: 500 11.5px var(--sans); fill: var(--muted); pointer-events: none; }
.toggle { cursor: pointer; }
.toggle .hit { fill: transparent; }
.toggle .dot { fill: #fff; stroke: #8795ad; stroke-width: 1.5; }
.toggle .sign { stroke: var(--ink-2); stroke-width: 2.2; stroke-linecap: round; fill: none; }
.toggle .pill { fill: var(--ink); }
.toggle .count { font: 600 11px var(--sans); fill: #fff; text-anchor: middle; pointer-events: none; }
.toggle:hover .pill { fill: var(--brass-ink); }
.toggle:hover .dot { stroke: var(--brass); }

/* generation ruler */
.ruler {
  position: absolute; z-index: 5; pointer-events: none; overflow: hidden;
  background: rgba(255, 255, 255, .88);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.ruler[data-orient="h"] { inset: 0 0 auto 0; height: 30px; border-bottom: 1px solid var(--line); }
.ruler[data-orient="v"] { inset: 0 auto 0 0; width: 70px; border-right: 1px solid var(--line); }
.ruler span {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font: 600 11.5px/20px var(--sans); color: var(--ink-2);
  padding: 0 10px; border-radius: 10px; background: var(--band);
}
.ruler[data-orient="h"] span { top: 5px; }
.ruler[data-orient="v"] span { left: 8px; }

/* canvas tools */
.toolbar {
  position: absolute; z-index: 6; top: 42px; left: 12px; right: 12px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; pointer-events: none;
}
.toolbar > * { pointer-events: auto; }
.stage[data-orient="v"] .toolbar { left: 82px; }

.seg, .stepper {
  display: inline-flex; align-items: center;
  height: 34px; background: #fff; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); overflow: hidden;
}
.seg button, .stepper button {
  height: 100%; padding: 0 12px; border: 0; background: transparent;
  font: 600 13px var(--sans); color: var(--ink-2);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:not([aria-pressed="true"]):hover, .stepper button:hover { background: #eef2fa; }
.stepper button { width: 34px; padding: 0; font-size: 17px; }
.stepper span { padding: 0 6px; font: 600 12.5px var(--sans); color: var(--ink-2); min-width: 92px; text-align: center; }

.zoom {
  position: absolute; z-index: 6; right: 14px; bottom: 14px;
  display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); overflow: hidden;
  transition: right .28s ease;
}
.zoom button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: transparent; color: var(--ink-2); }
.zoom button + button { border-top: 1px solid var(--line-soft); }
.zoom button:hover { background: #eef2fa; }
.stage.panel-open .zoom { right: calc(14px + var(--panel-w)); }

.minimap {
  position: absolute; z-index: 6; left: 14px; bottom: 14px;
  width: 188px; height: 124px;
  background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow);
  overflow: hidden;
}
.stage[data-orient="v"] .minimap { left: 84px; }
.minimap canvas { display: block; cursor: pointer; touch-action: none; }

/* ---------- member panel ---------- */

.panel {
  position: absolute; z-index: 20; top: 0; right: 0; bottom: 0;
  width: var(--panel-w); max-width: 100%;
  display: flex; flex-direction: column;
  background: #fff; border-left: 1px solid var(--line);
  box-shadow: -14px 0 34px rgba(12, 31, 63, .09);
  transform: translateX(104%); visibility: hidden;
  transition: transform .28s ease, visibility 0s .28s;
  cursor: default; user-select: text; -webkit-user-select: text;
}
.panel.is-open { transform: none; visibility: visible; transition: transform .28s ease, visibility 0s; }
.panel-bar { flex: none; display: flex; align-items: center; padding: 8px 10px 0; }
.panel-spacer { flex: 1; }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 22px 24px; overscroll-behavior: contain; }

.who { display: flex; gap: 16px; align-items: center; margin: 4px 0 18px; }
.avatar {
  flex: none; width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  color: #fff; font: 600 26px var(--serif);
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--g, var(--ink));
}
.avatar img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.who h2 { margin: 0 0 4px; font: 600 25px/1.15 var(--serif); color: var(--ink); overflow-wrap: anywhere; }
.gen-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 2px 11px 2px 9px; border-radius: 999px;
  background: var(--band); font: 600 12.5px var(--sans); color: var(--ink-2);
}
.gen-chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--g, var(--ink)); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 0 0 20px; border: 1px solid var(--line-soft); border-radius: 12px; overflow: hidden; }
.facts > div { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); }
.facts > div:nth-child(odd) { border-right: 1px solid var(--line-soft); }
.facts > div:nth-last-child(-n+2) { border-bottom: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-size: 14.5px; }
.facts dd button { border: 0; background: none; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-decoration-color: var(--brass); text-underline-offset: 3px; text-align: left; }
.facts .wide { grid-column: 1 / -1; border-right: 0 !important; }

.sec-title { margin: 22px 0 9px; font: 600 14px var(--sans); color: var(--ink-2); }
.kids { display: flex; flex-wrap: wrap; gap: 7px; }
.kids button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 12px; font: 600 13.5px var(--serif); color: var(--ink);
}
.kids button:hover { border-color: var(--brass); background: #fbf7ec; }

.descent { list-style: none; margin: 0; padding: 0 0 0 6px; }
.descent li { position: relative; padding: 0 0 10px 22px; }
.descent li::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: -2px; width: 2px; background: #e6d9b6; }
.descent li:last-child::before { display: none; }
.descent li::after { content: ""; position: absolute; left: 0; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--brass); }
.descent li[aria-current="true"]::after { background: var(--brass); }
.descent button { border: 0; background: none; padding: 0; text-align: left; font: 600 14.5px var(--serif); color: var(--ink); }
.descent button:hover { text-decoration: underline; text-decoration-color: var(--brass); }
.descent small { display: block; font: 400 12px var(--sans); color: var(--muted); }

.bio-link {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 11px; background: var(--ink); color: #fff; text-decoration: none;
  font-weight: 600; font-size: 14px;
}
.bio-link:hover { background: #17305c; }
.bio-role { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); }

.actions { display: grid; gap: 8px; margin-top: 22px; }
.actions .btn { width: 100%; justify-content: flex-start; }

/* ---------- loading ---------- */

.loading { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(255, 255, 255, .94); }
.loading[hidden] { display: none; }
.loading-box { text-align: center; max-width: 340px; padding: 24px; }
.spinner { width: 38px; height: 38px; margin: 0 auto 16px; border: 3px solid #e1e6ef; border-top-color: var(--brass); border-radius: 50%; animation: spin .9s linear infinite; }
.loading.is-error .spinner { display: none; }
.loading-title { margin: 0 0 4px; font: 600 20px var(--serif); color: var(--ink); }
.loading-text { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- status bar ---------- */

.statusbar {
  height: var(--status-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; background: #fff; font-size: 13px; color: var(--muted);
}
.statusbar a { color: var(--ink-2); font-weight: 600; text-decoration-color: var(--brass); text-underline-offset: 3px; }

/* ---------- toast & lightbox ---------- */

.toast {
  position: fixed; z-index: 200; left: 50%; bottom: 62px; transform: translateX(-50%);
  max-width: min(92vw, 460px); padding: 11px 18px; border-radius: 11px;
  background: var(--ink); color: #fff; font-size: 14px; box-shadow: var(--shadow);
}
.lightbox { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: rgba(8, 16, 32, .82); cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }

/* ---------- export dialog ---------- */

.dialog {
  width: min(580px, 94vw); max-height: 92vh; padding: 0;
  border: 0; border-radius: 16px; background: #fff; color: var(--text);
  box-shadow: 0 30px 80px rgba(8, 16, 32, .4);
}
.dialog::backdrop { background: rgba(8, 16, 32, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog form { display: flex; flex-direction: column; max-height: 92vh; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 4px 24px; }
.dialog-head h2 { margin: 0; font: 600 24px var(--serif); color: var(--ink); }
.dialog form > .opt, .dialog form > .opt-row, .dialog form > p, .dialog form > progress { margin-left: 24px; margin-right: 24px; }
.opt { border: 0; padding: 0; margin-top: 16px; min-width: 0; }
.opt legend { padding: 0; margin-bottom: 8px; font: 600 13px var(--sans); color: var(--ink-2); }
.opt-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.opt-row .opt { margin-left: 0; margin-right: 0; }
.choice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 14px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.choice:hover { border-color: #b9c3d3; }
.choice:has(input:checked) { border-color: var(--brass); background: #fbf7ec; box-shadow: 0 0 0 1px var(--brass); }
.choice input { margin-top: 4px; accent-color: var(--ink); }
.choice strong { display: block; font-size: 14.5px; }
.choice small { display: block; margin-top: 1px; color: var(--muted); font-size: 12.8px; line-height: 1.4; }
.choice.slim { padding: 9px 14px; margin-bottom: 6px; align-items: center; }
.choice.slim input { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 7px 14px; border: 1px solid var(--line); border-radius: 9px;
  font: 600 13.5px var(--sans); cursor: pointer;
}
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip input:disabled + span { opacity: .4; cursor: not-allowed; }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--ink); width: 16px; height: 16px; }
.estimate { margin-top: 18px; margin-bottom: 0; padding: 11px 14px; border-radius: 10px; background: var(--band); font-size: 13.5px; color: var(--ink-2); }
.estimate.warn { background: #fdf1e3; color: #7a3d00; }
.estimate.bad { background: #fdeaea; color: #8a1c1c; }
.dialog progress { display: block; width: calc(100% - 48px); height: 8px; margin-top: 12px; accent-color: var(--brass); }
.dialog-error { margin-top: 10px; margin-bottom: 0; color: #a11d1d; font-size: 13.5px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 18px 24px 20px; }
.grow { flex: 1; }

/* ---------- about ---------- */

.about { max-width: 720px; margin: 0 auto; padding: 44px 20px 64px; }
.about h2 { margin: 0 0 10px; font: 600 26px var(--serif); color: var(--ink); }
.about h2 + p { margin: 0 0 34px; color: var(--ink-2); }
.about dt { margin-top: 18px; font: 600 17px var(--serif); color: var(--ink); }
.about dd { margin: 3px 0 0; color: var(--ink-2); }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  :root { --header-h: 112px; --status-h: 40px; }
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand export" "search search";
    gap: 10px 12px; padding: 10px 14px; align-content: center;
  }
  .brand { grid-area: brand; }
  .search { grid-area: search; }
  #exportBtn { grid-area: export; }
  .brand-text h1 { font-size: 19px; }
  .hint { display: none; }
  .statusbar { padding: 0 14px; }

  .panel {
    top: auto; left: 0; right: 0; width: auto; height: min(52%, 440px);
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 34px rgba(12, 31, 63, .14);
    transform: translateY(104%);
  }
  .panel.is-open { transform: none; }
  .panel-bar::before { content: ""; position: absolute; left: 50%; top: 7px; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--line); }
  /* while the sheet is open, keep the tree visible: hide floating chrome (pinch still zooms) */
  .stage.panel-open .zoom, .stage.panel-open .minimap, .stage.panel-open .toolbar { display: none; }
  /* one scrollable row instead of three wrapped rows: keep the tree visible on phones */
  .toolbar { top: 38px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; pointer-events: auto; padding: 2px 2px 8px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: none; }
  .toolbar .btn-tool { padding: 0 10px; }
  .stepper span { min-width: 70px; }
  .minimap { width: 150px; height: 100px; }
  .opt-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .btn-brass span { display: none; }
  .btn-brass { padding: 0 12px; }
  .seg button { padding: 0 9px; font-size: 12.5px; }
  .dialog-foot { flex-wrap: wrap; }
  .dialog-foot .grow { display: none; }
  .dialog-foot #excelBtn { order: 3; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .panel, .zoom { transition: none; }
  .spinner { animation-duration: 2.4s; }
}
