/* Family admin: neutral surfaces, warm gold accent, light and dark themes; no external fonts. */
:root, [data-theme="light"] {
  --bg: #F6F4EF; --surface: #FFFFFF; --surface-2: #FAF8F3; --line: #E7E1D4; --ink: #24201A; --muted: #7A7264;
  --accent: #B8862F; --accent-ink: #FFFFFF; --accent-soft: #F4E7CC; --good: #2F8F5B; --bad: #C2412D; --warn: #B7791F;
  --c1: #B8862F; --c2: #4F7CAC; --c3: #6A9F58; --c4: #B4566C; --c5: #7E6BB0; --c6: #3F9E9A;
  --shadow: 0 1px 2px rgba(36,32,26,.05), 0 6px 24px rgba(36,32,26,.06);
}
[data-theme="dark"] {
  --bg: #15130F; --surface: #1E1B16; --surface-2: #24211B; --line: #332E25; --ink: #F1ECE2; --muted: #A69D8D;
  --accent: #E0AF55; --accent-ink: #1A160F; --accent-soft: #3A2F1B; --good: #5BC28A; --bad: #EF7A63; --warn: #E3A64B;
  --c1: #E0AF55; --c2: #7FA9D6; --c3: #8DC27B; --c4: #DB8299; --c5: #A797DA; --c6: #6CC7C2;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: url("/assets/icon-64.png") center / cover no-repeat; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: var(--muted); border: 0; background: none; width: 100%; text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.nav-item.active .icon { stroke: var(--accent); }
.nav-foot { margin-top: auto; }
.nav-form { margin: 0; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.main { padding: 24px 32px 48px; min-width: 0; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.custom { display: flex; align-items: center; gap: 6px; padding: 2px 6px; border-radius: 999px; border: 1px solid transparent; }
.custom.on { border-color: var(--ink); }
.custom input, .field { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 8px; }

.view { display: flex; flex-direction: column; gap: 16px; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-title { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tile { display: flex; flex-direction: column; gap: 4px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .spark { margin-top: 6px; height: 34px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge.up { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.badge.down { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.badge.flat { color: var(--muted); background: var(--surface-2); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.pill.good { color: var(--good); } .pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); }

.note { padding: 10px 14px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--line); color: var(--muted); }
.note-error { color: var(--bad); border-color: var(--bad); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.skeleton i { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
td.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 14px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .14; }
.chart .hover-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip { position: fixed; pointer-events: none; z-index: 10; background: var(--ink); color: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); white-space: pre; }
.hbar { display: grid; grid-template-columns: minmax(80px, 160px) 1fr auto; align-items: center; gap: 10px; padding: 4px 0; font-size: 13px; }
.hbar .track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel-step { display: grid; grid-template-columns: 180px 1fr 120px; gap: 12px; align-items: center; padding: 6px 0; }
.funnel-bar { height: 28px; border-radius: 8px; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent)); min-width: 2px; }
.heat td { text-align: center; font-variant-numeric: tabular-nums; border-radius: 6px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.media-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.tree-wrap { overflow: auto; max-height: 560px; border-radius: 12px; background: var(--surface-2); }
.tree .link { fill: none; stroke: var(--muted); stroke-width: 1.5; opacity: .6; }
.tree .spouse { stroke: var(--accent); stroke-dasharray: 4 3; opacity: .9; }
.tree .node rect { fill: var(--surface); stroke: var(--line); }
.tree .node.me rect { stroke: var(--accent); stroke-width: 2; }
.tree .node text { fill: var(--ink); font-size: 12px; }
.tree .node .years { fill: var(--muted); font-size: 11px; }
.tree .node .initial { fill: var(--accent); font-weight: 700; font-size: 14px; }
.scene-info { margin: -4px 0 10px; font-size: 12px; }
.scene-layout { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.scene-stage { position: relative; flex: 1 1 280px; max-width: 420px; min-width: 0; }
.scene-canvas { display: block; width: 100%; height: auto; border-radius: 14px; background: #EFE4CC; }
.scene-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--ink); color: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); white-space: pre; }
.scene-tip[hidden] { display: none; }
.scene-side { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.scene-person { display: flex; flex-direction: column; gap: 12px; }
.scene-person-head { display: flex; align-items: center; gap: 12px; }
.scene-person-name { font-weight: 700; font-size: 16px; }
.scene-avatar { width: 56px; height: 56px; flex: none; border-radius: 50%; overflow: hidden; display: grid; place-items: center; font-weight: 800; font-size: 22px; background: #D5E3EC; color: #3E5F7A; }
.scene-avatar.female { background: #F2DAD2; color: #9A4B3F; }
.scene-avatar img { width: 100%; height: 100%; object-fit: cover; }
.scene-bio { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.scene-video { position: relative; }
.scene-video img { display: block; }
.scene-video span { position: absolute; left: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgba(0,0,0,.55); border-radius: 6px; padding: 1px 6px; }
@media (max-width: 640px) { .scene-stage { max-width: none; flex-basis: 100%; } }

.login-body { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.login { width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { margin: 6px 0 0; font-size: 22px; }
.login p { margin: 0; }
.login input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.login-mark { width: 40px; height: 40px; border-radius: 12px; background: url("/assets/icon-64.png") center / cover no-repeat; }
.login-error { color: var(--bad); }
@media (prefers-color-scheme: dark) { .login-body { --bg: #15130F; --surface: #1E1B16; --surface-2: #24211B; --line: #332E25; --ink: #F1ECE2; --muted: #A69D8D; --accent-soft: #3A2F1B; } }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around; padding: 6px; border-right: 0; border-top: 1px solid var(--line); z-index: 5; }
  /* sign-out stays in the bottom bar (icon only); the theme switch and labels give way */
  .brand, .nav-theme, .nav-item span { display: none; }
  .nav-foot { margin-top: 0; }
  .nav-item { justify-content: center; width: auto; padding: 10px; }
  .main { padding: 16px 16px 84px; }
  .funnel-step { grid-template-columns: 1fr; gap: 4px; }
  .kv { grid-template-columns: 1fr; }
}
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.donut > svg.chart { width: 160px; height: 160px; flex: none; }
