/* Mobile-first. Base styles target ~360px phones; wider screens get a top nav. */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #5f6661;
  --line: #e2ded4;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --warn: #a15c00;
  --warn-bg: #fff4e0;
  --bad: #a52a2a;
  --bad-bg: #fdecec;
  --good: #2f6b4f;
  --good-bg: #e7f3ec;
  --radius: 12px;
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816; --surface: #1e2320; --text: #e9ece9; --muted: #a3aaa5; --line: #323a35;
    --brand: #6fbf95; --brand-ink: #0f1411; --warn: #f0b35a; --warn-bg: #33270f;
    --bad: #f08c8c; --bad-bg: #3a1c1c; --good: #6fbf95; --good-bg: #17301f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .92rem; }

.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { font-weight: 800; letter-spacing: .08em; text-decoration: none; color: var(--text); }
.topnav { display: none; gap: 20px; }
.topnav a { text-decoration: none; color: var(--muted); }
.topnav a.on { color: var(--brand); font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

/* Bottom tab bar on phones */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--surface);
  border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: .75rem; gap: 2px;
}
.tabbar a.on { color: var(--brand); font-weight: 600; }
.tabbar svg { width: 22px; height: 22px; }

@media (min-width: 768px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 24px; }
  main { padding: 24px; }
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.list { list-style: none; padding: 0; margin: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list a.row, .list .row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; min-height: var(--tap); text-decoration: none; color: var(--text);
}
.row .sub { color: var(--muted); font-size: .88rem; }

/* Forms: one column, full-width inputs, 16px+ font so iOS doesn't zoom */
form .field { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .88rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=date], input[type=datetime-local], input[type=month],
input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
textarea { min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; }
.check input { width: 24px; height: 24px; margin-top: 2px; flex: none; }
.otp { letter-spacing: .4em; font-size: 1.4rem !important; text-align: center; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; min-width: 0; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.split { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .split { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap);
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--brand); font: inherit; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; cursor: pointer;
}
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.linkbtn { background: none; border: 0; color: var(--brand); font: inherit; padding: 0; cursor: pointer; text-decoration: underline; }

.flash { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.flash.info { background: var(--good-bg); color: var(--good); }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.flash.dev { background: var(--warn-bg); color: var(--warn); font-family: ui-monospace, monospace; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 12px 14px 12px 32px; margin: 0 0 16px; }

.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--line); color: var(--text); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.kv { display: grid; grid-template-columns: 1fr; gap: 2px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; margin-top: 8px; }
.kv dd { margin: 0; }
@media (min-width: 560px) { .kv { grid-template-columns: 160px 1fr; } .kv dt { margin-top: 0; } }

.steps { list-style: none; padding: 0; margin: 0; }
.steps li { padding: 8px 0 8px 32px; position: relative; }
.steps li::before { content: ""; position: absolute; left: 6px; top: 13px; width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid var(--line); background: var(--surface); }
.steps li.done::before { background: var(--brand); border-color: var(--brand); }
.steps li.now::before { border-color: var(--brand); }

.stat { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat .card { margin: 0; }
.stat b { display: block; font-size: 1.6rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips a { white-space: nowrap; }
details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }
.steps.card { padding: 12px 16px; }

/* ---------------------------------------------------------------- family tree */
.center { text-align: center; }
.tree-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.tree-head h1 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg a { min-height: 40px; padding: 8px 14px; display: flex; align-items: center; text-decoration: none; color: var(--muted); font-weight: 600; }
.seg a.on { background: var(--brand); color: var(--brand-ink); }

.fam { display: flex; flex-direction: column; align-items: stretch; }
.gen-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; text-align: center; }
.row-cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: flex-end; }
.parent-col { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1 1 140px; max-width: 260px; }
.grand { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; position: relative; padding-bottom: 8px; }
.grand::after { content: ""; position: absolute; bottom: 0; left: 50%; height: 8px; border-left: 2px solid var(--line); }
.stem { align-self: center; width: 0; height: 20px; border-left: 2px solid var(--line); margin: 4px 0; }
.couple { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.spouse { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.amp { color: var(--muted); font-size: .8rem; }
@media (min-width: 560px) {
  .couple { flex-direction: row; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; }
  .spouse { flex-direction: row; gap: 12px; }
}
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
.hscroll .pcard { flex: none; scroll-snap-align: start; }
.grid-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.pcard {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: var(--tap); min-width: 0;
}
.pcard:hover, .pcard:focus-visible { border-color: var(--brand); }
.pcard.g-male { border-left-color: #6b8fb5; }
.pcard.g-female { border-left-color: #c48a6a; }
.pcard.dead { opacity: .72; }
.pcard.dead .pname::before { content: "† "; color: var(--muted); }
.pcard.self { box-shadow: 0 0 0 2px var(--brand); }
.pcard.sm { padding: 6px 10px; font-size: .85rem; max-width: 160px; }
.pcard.lg { border-width: 2px; border-left-width: 6px; border-color: var(--brand); padding: 12px 16px; min-width: 180px; }
.pcard.lg .pname { font-size: 1.1rem; }
.pname { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.pmeta { color: var(--muted); font-size: .8rem; }
.pmeta:empty { display: none; }
.pbadges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pbadges:empty { display: none; }
.dot.member { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.tag { font-size: .7rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; }
.legend { margin-top: 20px; font-size: .8rem; }

/* descendants chart */
.chart-wrap { position: relative; }
.chart {
  height: calc(100vh - 260px); min-height: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; touch-action: none; cursor: grab; user-select: none;
}
.chart:active { cursor: grabbing; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart-tools { position: absolute; right: 8px; bottom: 8px; z-index: 2; display: flex; gap: 6px; }
.chart-tools .btn { min-width: 44px; padding: 6px 10px; background: var(--surface); }
.t-edge { fill: none; stroke: var(--line); stroke-width: 2; }
.t-edge.unconfirmed { stroke-dasharray: 5 4; }
.t-node rect { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.t-node.g-male rect.bar { fill: #6b8fb5; stroke: none; }
.t-node.g-female rect.bar { fill: #c48a6a; stroke: none; }
.t-node rect.bar { fill: var(--line); stroke: none; }
.t-node.dead { opacity: .7; }
.t-node.self rect.box, .t-node.focus rect.box { stroke: var(--brand); stroke-width: 2.5; }
.t-node a:focus-visible rect.box { stroke: var(--brand); stroke-width: 3; }
.t-name { font: 600 13px system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", sans-serif; fill: var(--text); }
.t-meta { font: 11px system-ui, -apple-system, sans-serif; fill: var(--muted); }
.t-member { fill: var(--good); }
.t-toggle circle { fill: var(--surface); stroke: var(--brand); stroke-width: 1.5; }
.t-toggle text { font: 700 11px system-ui, sans-serif; fill: var(--brand); text-anchor: middle; }
.t-toggle { cursor: pointer; }
.t-toggle:focus-visible circle { stroke-width: 3; }
.chart-msg { position: absolute; left: 8px; bottom: 8px; right: 168px; margin: 0; font-size: .85rem; color: var(--bad); }
.chart-msg:empty { display: none; }

/* ---------------------------------------------------------------- finance */
.money, .num { font-variant-numeric: tabular-nums; }
.bad-text { color: var(--bad); }
.good-text { color: var(--good); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.month-pick input { width: auto; min-height: 40px; }
.table-wrap { overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ledger th, .ledger td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.ledger .num { text-align: right; }
.ledger tfoot th { border-bottom: 0; }
.ledger.compact td { padding: 4px 6px; border: 0; color: var(--muted); }
.ledger td.cr { padding-left: 28px; }
.inline-details summary { min-height: 32px; font-weight: 600; color: var(--bad); font-size: .85rem; }
.inline-details[open] { flex-basis: 100%; }
.inline-details form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; min-width: 220px; }
.receipt-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.receipt-no { font-family: ui-monospace, Menlo, monospace; font-weight: 700; white-space: nowrap; }
.book .amounts { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.sign-lines { display: flex; justify-content: space-between; gap: 24px; margin-top: 40px; }
.sign-lines span { flex: 1; border-top: 1px solid var(--line); padding-top: 4px; font-size: .85rem; color: var(--muted); }

@media print {
  .topbar, .tabbar, .no-print, .flash.info { display: none !important; }
  body { background: #fff; padding: 0; }
  .receipt { border: 1px solid #999; }
}

/* ---------------------------------------------------------------- how are we related */
.pickers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.pickers .card { margin: 0; }
.swap { align-self: center; min-height: 40px; }
.answer { border-left: 6px solid var(--brand); }
.answer-main { font-size: 1.15rem; line-height: 1.4; margin: 0 0 6px; text-wrap: balance; }
.answer-main .kin { font-weight: 700; color: var(--brand); }
.answer-sub { margin: 4px 0 0; color: var(--muted); }
.path { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; align-items: center; }
.path-step { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 340px; }
.path-step .pcard { width: 100%; }
.path-link { font-size: .8rem; color: var(--muted); padding: 6px 0 6px 14px; border-left: 2px solid var(--line); margin: 2px 0; align-self: center; }
.path-link.unconfirmed { border-left-style: dashed; color: var(--bad); }
@media (min-width: 700px) {
  .pickers { flex-direction: row; align-items: stretch; }
  .pickers .card { flex: 1; min-width: 0; }
}
.ml-term { margin: 2px 0 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.ml-term .ml { font-family: "Noto Sans Malayalam", "Manjari", "Kartika", system-ui, sans-serif; font-size: 1.25rem; font-weight: 700; color: var(--brand); }
.ml-term .latin { color: var(--muted); font-style: italic; }

/* Malayalam terms editor */
.term-row { border: 0; box-shadow: inset 0 1px 0 var(--line); padding: 14px 0 8px; margin: 0; }
.term-row:first-of-type { box-shadow: none; padding-top: 0; }
.term-row legend { float: left; width: 100%; }
.term-row legend + * { clear: both; }
.term-row legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.term-fields { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .term-fields { grid-template-columns: 1fr 1fr; } }
.term-fields .field { margin-bottom: 8px; }
.term-opts { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.ml-input { font-family: "Noto Sans Malayalam", "Manjari", system-ui, sans-serif; font-size: 18px !important; }
.has-error input { border-color: var(--bad); }
.field-error { color: var(--bad); margin: 0 0 8px; font-size: .9rem; }
.save-bar { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); padding: 8px 0; background: var(--bg); }
@media (min-width: 768px) { .save-bar { bottom: 0; } }

/* logins and roles */
.role-list { padding-left: 20px; margin: 8px 0; }
.role-list li { margin-bottom: 6px; }
.acct-row { padding-bottom: 8px; }
.role-change summary { min-height: 36px; font-size: .9rem; color: var(--brand); }
.role-change form { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.role-change select { width: auto; min-width: 180px; }

/* meetings */
.quorum { border-left: 6px solid var(--line); }
.quorum.ok { border-left-color: var(--good); }
.quorum.no { border-left-color: var(--bad); }
.me-panel { border-left: 6px solid var(--brand); }
.vote-box { border: 2px solid var(--brand); border-radius: var(--radius); padding: 12px; margin: 8px 0; background: var(--surface); }
.vote-title { font-size: 1.05rem; margin: 0 0 4px; }
.vote-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.vote-buttons .btn { min-height: 56px; font-size: 1.05rem; }
.vote-mini, .mark-present { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.vote-mini .btn, .mark-present .btn { min-height: 40px; padding: 6px 10px; font-size: .85rem; }
.agenda { margin: 0; padding-left: 22px; }
.agenda-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.agenda-item:last-child { border-bottom: 0; }
.deadline { padding: 6px 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input[type=date] { width: auto; }
.meeting-card { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); border-left: 6px solid var(--warn); }
.meeting-card.live { border-left-color: var(--good); background: var(--good-bg); }
.meeting-cta { color: var(--brand); font-weight: 700; margin-top: 4px; }
.quarters { display: flex; gap: 6px; flex-wrap: wrap; }
.seats { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
@media (min-width: 700px) { .seats { grid-template-columns: 1fr 1fr; } }
.seats .card { margin: 0; }
.seat details { margin-top: 6px; }
.appoint-form { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 8px; }
.casting { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.casting .btn { min-height: 36px; padding: 4px 10px; }

/* ---------------------------------------------------------------- photos / avatars */
.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
  border-radius: 50%; background: var(--line); color: var(--muted); font-weight: 700; letter-spacing: .02em;
  width: 40px; height: 40px; font-size: .85rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av-sm { width: 32px; height: 32px; font-size: .72rem; }
.av-md { width: 40px; height: 40px; }
.av-lg { width: 56px; height: 56px; font-size: 1.05rem; }
.av-xl { width: 96px; height: 96px; font-size: 1.8rem; }
.pcard { flex-direction: row; align-items: center; gap: 10px; }
.ptext { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pcard.dead .avatar { filter: grayscale(1); }
.with-avatar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.profile-head h1 { margin: 0; }
.profile-photo { width: 120px; height: 120px; border-radius: 16px; object-fit: cover; flex: none; background: var(--line); }
@media (min-width: 560px) { .profile-photo { width: 160px; height: 160px; } }
.photo-edit summary { font-weight: 600; }
.photo-edit input[type=file] { padding: 8px; }
.t-av-bg { fill: var(--line); }
.t-av-text { font: 700 11px system-ui, sans-serif; fill: var(--muted); text-anchor: middle; }
.t-node.dead image { filter: grayscale(1); }
.nomination .excluded, .nomination .problems { margin: 4px 0; padding-left: 20px; font-size: .85rem; }
.nomination .problems { color: var(--warn); }
.sign-list { list-style: none; padding: 0; margin: 4px 0 8px; display: grid; grid-template-columns: 1fr; gap: 2px; }
@media (min-width: 560px) { .sign-list { grid-template-columns: 1fr 1fr; } }
.accept-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.accept-form input { width: auto; }
.steps .inline-form { margin-top: 4px; }
.asset { padding: 8px 0; }
.steps li.bad-step::before { background: var(--bad); border-color: var(--bad); }
