/* Family Intake — iPad-first styles. Navy, white, and quiet grays. */

:root {
  --navy: #1b2a4a;
  --navy-700: #263a63;
  --navy-100: #dfe5ef;
  --navy-50: #eef1f6;
  --ink: #1d2433;
  --muted: #5b6474;
  --line: #d5dae2;
  --line-strong: #b9c0cc;
  --bg: #f4f5f7;
  --white: #ffffff;
  --error: #b42318;
  --error-bg: #fef3f2;
  --warn: #8a4b00;
  --warn-bg: #fff6e6;
  --warn-line: #f0d29b;
  --ok: #1f6e43;
  --ok-bg: #edf7f1;
  --radius: 12px;
  --radius-sm: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --focus: 0 0 0 3px rgba(38, 58, 99, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--serif); color: var(--navy); font-weight: 600; line-height: 1.25; }
h1 { font-size: 32px; margin: 0 0 8px; }
h2 { font-size: 24px; margin: 0 0 4px; }
h3 { font-size: 20px; margin: 0 0 4px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- Top bar, notice, progress ---------- */

.topbar { background: var(--navy); color: var(--white); padding-top: env(safe-area-inset-top); }
.topbar-inner {
  max-width: 900px; margin: 0 auto; min-height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { width: 44px; height: 44px; flex: none; }
.welcome-logo { width: 132px; height: 132px; display: block; margin: 0 auto 18px; }
.office { font-family: var(--serif); font-size: 21px; letter-spacing: 0.01em; }
.staff-button {
  background: transparent; color: #c9d2e3; border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px; font: inherit; font-size: 15px; padding: 8px 18px; min-height: 40px;
}

.notice-bar {
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--warn-line);
  text-align: center; font-size: 15px; padding: 8px 24px;
}

.progress { background: var(--white); border-bottom: 1px solid var(--line); }
.progress ol {
  list-style: none; margin: 0 auto; padding: 14px 24px; max-width: 900px;
  display: flex; gap: 8px;
}
.progress li { flex: 1; min-width: 0; }
.progress button {
  width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: none; border: 0; padding: 4px 0; font: inherit; color: var(--muted); text-align: left;
  min-height: 52px;
}
.progress button:disabled { cursor: default; }
.progress .bar { display: block; width: 100%; height: 6px; border-radius: 3px; background: var(--line); }
.progress .label { font-size: 15px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.progress .num {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%; font-size: 13px; font-weight: 600;
  border: 1.5px solid var(--line-strong); color: var(--muted);
}
.progress .done .bar { background: var(--navy-700); }
.progress .done .num { background: var(--navy-700); border-color: var(--navy-700); color: var(--white); }
.progress .current .bar { background: var(--navy); }
.progress .current .label { color: var(--navy); font-weight: 600; }
.progress .current .num { border-color: var(--navy); color: var(--navy); }

/* ---------- Main layout ---------- */

main { flex: 1; width: 100%; outline: none; }
.page { max-width: 760px; margin: 0 auto; padding: 32px 24px 48px; }
@media (min-width: 1100px) { .page { max-width: 840px; } }

.page-header { margin-bottom: 24px; }
.page-header p { color: var(--muted); font-size: 18px; margin: 6px 0 0; }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px;
}
.card > h2, .card > h3 { margin-bottom: 16px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }

.center-screen {
  max-width: 620px; margin: 0 auto; padding: 72px 24px; text-align: center;
}
.center-screen .card { text-align: left; }

/* ---------- Form fields ---------- */

.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field legend, .label {
  display: block; font-weight: 600; font-size: 17px; margin-bottom: 6px; color: var(--ink); padding: 0;
}
.optional { font-weight: 400; color: var(--muted); font-size: 15px; }
.hint { color: var(--muted); font-size: 15px; margin: -2px 0 8px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

input[type="text"], input[type="tel"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; font: inherit; font-size: 18px; color: var(--ink);
  background: var(--white); border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  min-height: 56px; padding: 12px 14px; -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px;
}
textarea { min-height: 150px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy); box-shadow: var(--focus); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--error); }
.error-text { color: var(--error); font-size: 15px; margin-top: 6px; display: flex; gap: 6px; align-items: flex-start; }
.error-text::before { content: "!"; flex: none; display: inline-flex; width: 18px; height: 18px; border-radius: 50%; background: var(--error); color: #fff; font-size: 12px; font-weight: 700; align-items: center; justify-content: center; margin-top: 2px; }

.row { display: grid; gap: 16px; }
.row .field { margin-bottom: 0; }
.row + .field, .row + .row { margin-top: 20px; }
.row-city { grid-template-columns: 1fr 200px 150px; }
.row-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 700px) {
  .row-city { grid-template-columns: 1fr 1fr; }
  .row-city .field:first-child { grid-column: 1 / -1; }
  .row-2 { grid-template-columns: 1fr; }
}

.subsection { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 22px; }
.section-title { font-family: var(--serif); color: var(--navy); font-size: 20px; margin: 0 0 14px; font-weight: 600; }

/* Choice cards (radio buttons) */
.choices { display: grid; gap: 10px; }
.choices.cols-2 { grid-template-columns: 1fr 1fr; }
.choices.cols-3 { grid-template-columns: repeat(3, 1fr); }
.choices.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) {
  .choices.cols-3, .choices.cols-4 { grid-template-columns: 1fr 1fr; }
}
.choice { position: relative; display: block; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
  display: flex; align-items: center; gap: 12px; min-height: 58px; height: 100%;
  padding: 12px 16px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--white); font-size: 17px; line-height: 1.3; cursor: pointer;
}
.choice span::before {
  content: ""; flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--white);
}
.choice input:checked + span { border-color: var(--navy); background: var(--navy-50); color: var(--navy); font-weight: 600; }
.choice input:checked + span::before { border-color: var(--navy); background: radial-gradient(var(--navy) 0 5px, var(--white) 6px); }
.choice input:focus-visible + span { box-shadow: var(--focus); }
.has-error .choice span { border-color: #e3a29b; }

/* Toggle row (checkbox) */
.field > .toggle, .toggle { display: flex; margin: 0; font-weight: 400; align-items: center; gap: 14px; min-height: 56px; cursor: pointer; font-size: 17px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .box {
  flex: none; width: 28px; height: 28px; border-radius: 6px; border: 2px solid var(--line-strong); background: var(--white);
  display: inline-flex; align-items: center; justify-content: center;
}
.toggle input:checked + .box { background: var(--navy); border-color: var(--navy); }
.toggle input:checked + .box::after { content: ""; width: 8px; height: 14px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.toggle input:focus-visible + .box { box-shadow: var(--focus); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 28px; border-radius: var(--radius-sm); border: 1.5px solid transparent;
  font: inherit; font-size: 18px; font-weight: 600; cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:active { background: var(--navy-700); }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--line-strong); }
.btn-quiet { background: transparent; color: var(--navy); min-height: 48px; padding: 0 14px; }
.btn-danger { background: var(--error); color: var(--white); }
.btn-danger-outline { background: var(--white); color: var(--error); border-color: #e3a29b; }
.btn-small { min-height: 44px; padding: 0 16px; font-size: 16px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-add {
  width: 100%; min-height: 64px; border: 2px dashed var(--line-strong); background: var(--white);
  color: var(--navy); font-size: 18px; font-weight: 600; border-radius: var(--radius);
}
.btn-add .plus { font-size: 26px; line-height: 1; font-weight: 400; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.4); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- Step navigation footer ---------- */

.step-nav {
  position: sticky; bottom: 0; z-index: 5;
  background: rgba(255,255,255,0.97); border-top: 1px solid var(--line);
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
}
.step-nav-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 12px; justify-content: space-between; align-items: center; }
@media (min-width: 1100px) { .step-nav-inner { max-width: 840px; } }
.step-nav .btn-primary { min-width: 200px; }

/* ---------- Children ---------- */

.person-card { background: var(--white); border: 1.5px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.person-card.open { border-color: var(--navy-100); box-shadow: 0 2px 10px rgba(27,42,74,0.06); }
.person-card.has-error { border-color: #e3a29b; }
.person-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; }
.person-head .who { flex: 1; min-width: 0; }
.person-head .who .name { font-weight: 600; font-size: 19px; overflow-wrap: anywhere; }
.person-head .who .meta { color: var(--muted); font-size: 15px; }
.person-index {
  flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--navy-50); color: var(--navy);
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.person-body { padding: 4px 20px 22px; border-top: 1px solid var(--line); }
.person-body > .field:first-child { margin-top: 18px; }
.person-actions { display: flex; gap: 8px; flex: none; }
.descendants { background: var(--bg); border-radius: var(--radius); padding: 18px; margin-top: 8px; }
.descendants .person-card { margin-bottom: 12px; }
.badge {
  display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  background: var(--navy-50); color: var(--navy); vertical-align: middle; margin-left: 6px;
}
.badge-deceased { background: #ececee; color: #444b57; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.card-done-row { display: flex; justify-content: flex-end; margin-top: 18px; }

/* ---------- Alerts ---------- */

.alert { border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; border: 1px solid; }
.alert h3 { font-family: var(--sans); font-size: 18px; margin: 0 0 6px; color: inherit; }
.alert p:last-child, .alert ul:last-child { margin-bottom: 0; }
.alert-error { background: var(--error-bg); border-color: #f3c1bb; color: #7a1c13; }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-line); color: #5f3500; }
.alert-ok { background: var(--ok-bg); border-color: #b9dcc8; color: #154d2f; }
.alert-info { background: var(--navy-50); border-color: var(--navy-100); color: var(--navy); }
.alert ul { margin: 8px 0 0; padding-left: 0; list-style: none; }
.alert li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-top: 1px solid rgba(0,0,0,0.06); }
.alert li:first-child { border-top: 0; }

/* ---------- Review ---------- */

.summary { margin: 0; }
.summary-row { display: grid; grid-template-columns: 190px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.summary-row:first-child { border-top: 0; padding-top: 0; }
.summary dt { color: var(--muted); font-size: 16px; }
.summary dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 700px) { .summary-row { grid-template-columns: 1fr; gap: 2px; } }
.flag { color: var(--warn); font-weight: 600; }
.review-child { border-top: 1px solid var(--line); padding: 16px 0; }
.review-child:first-of-type { border-top: 0; padding-top: 0; }
.review-child-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.review-child-head .name { font-weight: 600; font-size: 19px; }
.review-descendants { margin: 8px 0 0 0; padding: 12px 16px; background: var(--bg); border-radius: var(--radius-sm); }
.review-descendants .summary-row { grid-template-columns: 170px 1fr; }

.tree-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfbfc; padding: 12px; }
.tree-wrap svg { display: block; margin: 0 auto; }
.tree-legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 14px; color: var(--muted); margin-top: 10px; }
.tree-legend .swatch { display: inline-block; width: 28px; height: 0; border-top: 2px solid var(--navy-700); vertical-align: middle; margin-right: 6px; }
.tree-legend .swatch.dashed { border-top-style: dashed; }
.tree-legend .swatch.box-deceased { width: 18px; height: 14px; border: 1.5px dashed #8a919d; background: #eef0f3; }

.disclaimer { font-size: 15px; color: var(--muted); background: var(--white); border-left: 4px solid var(--navy-100); padding: 14px 18px; border-radius: var(--radius-sm); }

/* ---------- Completion / staff screens ---------- */

.done-icon {
  width: 76px; height: 76px; border-radius: 50%; background: var(--ok-bg); color: var(--ok);
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 18px;
}
.done-icon.neutral { background: var(--navy-50); color: var(--navy); }
.done-icon svg { width: 38px; height: 38px; }
.reference { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 17px; letter-spacing: 0.04em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.welcome-list { padding-left: 22px; margin: 0 0 12px; }
.welcome-list li { margin-bottom: 6px; }
.prototype-tools { margin-top: 28px; border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; text-align: left; background: var(--white); }
.prototype-tools .row { grid-template-columns: 1fr auto; align-items: end; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(17, 25, 43, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--white); border-radius: 16px; width: 100%; max-width: 520px; padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25); max-height: calc(100vh - 48px); overflow-y: auto;
}
.modal h2 { margin-bottom: 10px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 auto; }
.countdown { font-size: 44px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; text-align: center; margin: 8px 0; }

.alert:focus { outline: none; }
#begin { min-width: 260px; }
