/* ═══════════════════════════ RESET + PRIMITIVES ═══════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  /* .app already has its own height:100dvh + overflow:hidden, but that only
     helps if nothing inside it ever overflows those bounds — and the
     header/footer are plain grid rows, not position:fixed, so if the page
     itself becomes scrollable they scroll away too. This is the actual
     lock: the page can never scroll, full stop, no matter what happens
     inside .app. */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button { background: none; border: 0; padding: 0; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}

[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--line-strong); background-clip: content-box; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  /* The mockup's buttons are rounded-2xl (16px-ish), not a full pill — only
     chips/badges/icon-buttons stay pill-shaped. */
  border-radius: var(--r-lg);
  font-size: var(--fs-base);
  font-weight: 600;
  border: 1px solid transparent;
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t-base) var(--ease-out), border-color var(--t-fast), opacity var(--t-fast);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Solid, not a gradient — a gold gradient on a button kept landing
   somewhere between "banded" and "washed out" depending on theme; a flat
   fill is simple and reads the same in both. Colour itself comes from
   --btn-primary-* rather than --gold directly — the mockup's primary
   button is solid dark-slate in light mode and solid amber in dark mode,
   not just two shades of the same gold. */
.btn--primary  { background: var(--btn-primary-bg); color: var(--btn-primary-text); box-shadow: var(--sh-2); font-weight: 700; }
.btn--primary:hover { background: var(--btn-primary-bg-hover); }
.btn--ghost    { background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--quiet    { background: var(--surface-2); color: var(--text); }
.btn--quiet:hover { background: var(--surface-3); }
.btn--danger   { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--ok       { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.btn--ok:hover { background: var(--ok); color: #06281a; }
.btn--sm       { min-height: 32px; padding: 0 12px; font-size: var(--fs-sm); }
.btn--block    { width: 100%; }
.btn--google {
  width: 100%;
  background: #fff;
  color: #1f1f1f;
  box-shadow: var(--sh-2);
  min-height: 48px;
  font-weight: 600;
}
.btn--google:hover { background: #f4f6fa; }
.google-g { display: inline-flex; }

/* ── Icon buttons ────────────────────────────────────────────────────────── */
.iconbtn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--r-pill);
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn svg { pointer-events: none; }

/* ── Avatars ─────────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  /* Matches the mockup's fallback avatar — see .node__photo in tree.css
     for the full reasoning: a flat wash of the page background with fixed
     slate-400 initials, not a painted-on dark badge. */
  background: var(--bg);
  color: #94a3b8;
  font-weight: 700;
  letter-spacing: .02em;
  overflow: hidden;
  flex: none;
  background-size: cover;
  background-position: center;
}
.avatar--sm  { width: 30px; height: 30px; font-size: var(--fs-xs); }
.avatar--md  { width: 46px; height: 46px; font-size: var(--fs-sm); }
.avatar--lg  { width: 96px; height: 96px; font-size: var(--fs-xl); }
.avatar--xl  { width: 132px; height: 132px; font-size: var(--fs-2xl); }
.avatar--deceased { filter: grayscale(1) contrast(.92); }

/* ── Chips / badges ──────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
}
.chip--gold   { background: rgba(245,158,11,.16); color: var(--gold); }
.chip--ghost  { background: var(--ghost-soft); color: var(--ghost); }
.chip--ok     { background: var(--ok-soft); color: var(--ok); }
.chip--danger { background: var(--danger-soft); color: var(--danger); }
.chip--info   { background: var(--info-soft); color: var(--info); }
.chip--memory { background: rgba(160,170,200,.16); color: var(--text-muted); }
.chip--number {
  background: var(--surface-3);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  cursor: pointer;
  border: 1px solid var(--line);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.chip--number:hover { border-color: var(--gold); color: var(--gold); }
.chip--number__copy { display: inline-flex; opacity: .55; }
.chip--number:hover .chip--number__copy { opacity: 1; }

.badge-count {
  position: absolute;
  top: 2px; right: 0;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}
.field__label .req { color: var(--gold); }
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--surface-3);
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: right 18px center, right 13px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.field__hint { margin-top: 5px; font-size: var(--fs-xs); color: var(--text-dim); }
.field__hint--ok    { color: var(--ok); }
.field__hint--error { color: var(--danger); }

/* ── Password field with a show/hide toggle ───────────────────────────────── */
.password-field { position: relative; }
.password-field .input { padding-right: 42px; }
.password-toggle {
  position: absolute;
  top: 50%; right: 4px;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  transition: color var(--t-fast), background var(--t-fast);
}
.password-toggle:hover { color: var(--text); background: var(--surface-3); }
.field.is-error .input, .field.is-error .select, .field.is-error .textarea { border-color: var(--danger); }
.field.is-valid .input, .field.is-valid .select { border-color: var(--ok); }

/* ── Gender toggle (two tap targets, not a dropdown) ─────────────────────── */
.gender-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gender-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.gender-btn:hover { border-color: var(--line-strong); }
.gender-btn.is-active { border-color: var(--gold); background: rgba(245,158,11,.14); color: var(--gold); }

/* ── Segmented button group — same idea as gender-toggle, generalized for
   any small set of mutually-exclusive choices (date precision,
   relationship) so none of them need to open a dropdown. Default lays
   buttons out in a single row (grid-auto-columns); .seg-toggle--wrap lets
   a longer set (e.g. 4+ relationship options with longer labels) wrap to
   two columns instead of squeezing into one row. ───────────────────────── */
.seg-toggle { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg-toggle--wrap { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.seg-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 6px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  text-align: center;
  line-height: 1.25;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.seg-btn:hover:not(:disabled) { border-color: var(--line-strong); }
.seg-btn.is-active { border-color: var(--gold); background: rgba(245,158,11,.14); color: var(--gold); }
.seg-btn:disabled, .seg-btn.is-unavailable { opacity: .4; cursor: not-allowed; }

/* Relationship picker (Add Person, step 2) — an icon-in-circle above the
   label instead of a bare text pill, so "Parent / Spouse / Sibling / Child"
   reads at a glance rather than as four identical grey boxes. */
.seg-btn--relation {
  flex-direction: column;
  gap: 7px;
  min-height: 76px;
  padding: 12px 6px 10px;
}
.seg-btn__icon {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
}
.seg-btn--relation.is-active .seg-btn__icon { background: rgba(245,158,11,.18); color: var(--gold); }

/* ── Suggestion dropdown (e.g. the "Lives in" field) ──────────────────────────
   A real tap-friendly dropdown instead of a native <datalist>, which mobile
   browsers render inconsistently (or not at all). */
.suggest { position: relative; }
.suggest-results {
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  max-height: 240px;
  overflow-y: auto;
  padding: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
  z-index: 5;
}
.suggest-result {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  text-align: left;
  font-size: var(--fs-sm);
  color: var(--text);
  transition: background var(--t-fast);
}
.suggest-result:hover { background: var(--surface-3); }
.suggest-empty {
  padding: 8px 10px 2px;
  font-size: var(--fs-xs);
  color: var(--text-dim);
}
.suggest-request {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  text-align: left;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--gold);
  background: rgba(245,158,11,.10);
  transition: background var(--t-fast);
}
.suggest-request svg { flex: none; }
.suggest-request:hover { background: rgba(245,158,11,.20); }

/* ── Phone country picker (registration) ──────────────────────────────────── */
.phone-input { display: flex; gap: 8px; }
.phone-input__country {
  display: flex; align-items: center; gap: 6px; flex: none;
  height: 44px; padding: 0 10px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.phone-input__country:hover { border-color: var(--line-strong); }
.phone-input__country[aria-expanded="true"] { border-color: var(--gold); background: var(--surface-3); }
.phone-input__flag { display: inline-flex; line-height: 1; }
.flag-swatch { display: block; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.25); flex: none; object-fit: cover; }
.phone-input__dial { font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.phone-input__national { flex: 1; min-width: 0; }

.phone-country-panel {
  position: relative;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
}
.phone-country-panel__search { margin-bottom: 6px; }
.phone-country-panel__list { max-height: 220px; overflow-y: auto; }
.phone-country-option {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border-radius: var(--r-sm);
  text-align: left;
  font-size: var(--fs-sm);
  color: var(--text);
  transition: background var(--t-fast);
}
.phone-country-option:hover, .phone-country-option.is-active { background: var(--surface-3); }
.phone-country-option__flag { font-size: 16px; line-height: 1; flex: none; }
.phone-country-option__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-country-option__dial { color: var(--text-dim); font-size: var(--fs-xs); flex: none; }
.phone-country-panel__empty { padding: 10px; text-align: center; color: var(--text-dim); font-size: var(--fs-sm); }

.phone-otp-block { margin-top: 10px; }
.phone-otp-row { display: flex; gap: 8px; }
.phone-otp-row .input { letter-spacing: .12em; }
.phone-otp-status { margin: 6px 0 0; font-size: var(--fs-xs); color: var(--text-dim); min-height: 1em; }
.phone-otp-status--ok    { color: var(--ok); }
.phone-otp-status--error { color: var(--danger); }
.login-send-code { width: 100%; margin-top: 8px; }
.login-send-code[disabled] { opacity: .6; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  cursor: pointer;
  font-size: var(--fs-base);
}
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--gold); flex: none; }
.check span small { display: block; color: var(--text-dim); font-size: var(--fs-xs); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.muted   { color: var(--text-muted); }
.dim     { color: var(--text-dim); }
.small   { font-size: var(--fs-sm); }
.tiny    { font-size: var(--fs-xs); }
.center  { text-align: center; }
.row     { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.wrap    { flex-wrap: wrap; }
.grow    { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; border: 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Debug panel (assets/js/debug.js) ────────────────────────────────────── */
.debug-panel {
  position: fixed;
  left: 8px; right: 8px; bottom: 8px;
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  background: rgba(10, 12, 24, .94);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  /* Below modals/sheets/toasts (z-modal/z-sheet/z-toast, all 10+) on
     purpose — this must never sit on top of an open form and silently eat
     the tap meant for its submit button. Still above the canvas/nav (both
     8) so it's visible the rest of the time; log entries keep recording
     either way, whether the panel itself is currently covered by a dialog
     or not. A literal integer, not calc(var(--z-modal) - 0.5): z-index is
     an integer property, and a browser that won't accept the fractional
     used value rounds it right back up to 10 — indistinguishable from no
     gap at all, which is the exact bug this rule exists to prevent. */
  z-index: 9;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
}
.debug-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  color: #f2f4fa;
}
.debug-panel__header strong { flex: 1; font-family: var(--font); font-size: var(--fs-xs); }
.debug-panel__btn {
  background: rgba(255,255,255,.1);
  color: #f2f4fa;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--r-sm);
  padding: 3px 8px;
  font-size: 10px;
  cursor: pointer;
}
.debug-panel__btn:hover { background: rgba(255,255,255,.18); }
.debug-panel__list {
  overflow-y: auto;
  padding: 6px 10px 10px;
  color: #b7c0dd;
}
.debug-row { padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.debug-row--api { color: #7dd3fc; }
.debug-row--store { color: #a7f3d0; }
.debug-row--create { color: #fde68a; }
.debug-row--render { color: #d8b4fe; }
.debug-row--add-form { color: #fbcfe8; }
.debug-row--crash { color: #fca5a5; font-weight: 700; }
.debug-row--debug { color: #94a3b8; font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
