/* Hallmark · genre: editorial-heritage · macrostructure: Workbench (header đầy đủ + canvas cây) · theme: custom (light / serif-display / warm)
 * nav: N1 full-width header gỗ lim, viền đồng (di động: header gọn + thanh tab đáy) · footer: none (app) · enrichment: hoạ tiết mây mờ trên header
 * pre-emit critique: P5 H5 E4 S5 R4 V4
 */
* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: clip; }
body {
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  margin: 0; background: var(--color-paper); color: var(--color-ink);
  font: 400 var(--text-base)/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 650; letter-spacing: -0.02em; margin: 0; font-style: normal; }
svg.lucide { width: 18px; height: 18px; stroke-width: 1.9; flex: none; }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.lede { color: var(--color-ink-2); margin: var(--space-2xs) 0 0; font-size: var(--text-md); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2xs); white-space: nowrap;
  height: 40px; padding: 0 var(--space-sm); border-radius: var(--radius-pill); border: 1px solid transparent;
  font-weight: 600; font-size: var(--text-sm);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); color: var(--color-accent-ink); }
.btn-primary:hover { background: var(--color-accent-2); }
.btn-ghost { background: var(--color-surface); border-color: var(--color-rule); color: var(--color-ink); }
.btn-ghost:hover { border-color: var(--color-rule-2); background: var(--color-paper-2); }
.btn-danger { background: var(--color-surface); border-color: var(--color-rule); color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-soft); border-color: var(--color-danger); }
.btn-sm { height: 34px; padding: 0 var(--space-xs); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-pill);
  border: 0; background: transparent; color: var(--color-ink-2);
  transition: background var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--color-paper-3); color: var(--color-ink); }

/* ---------- thanh trên ---------- */
.bar {
  position: fixed; z-index: 20; top: var(--space-sm); left: var(--space-sm); right: var(--space-sm);
  display: flex; align-items: center; gap: var(--space-xs); pointer-events: none;
}
.bar > * { pointer-events: auto; }
/* nền mờ sau thanh trên ở các trang cuộn (giả-phần-tử: không làm hỏng thanh tab fixed bên trong) */
.bar::before {
  content: ''; position: absolute; z-index: -1; inset: calc(-1 * var(--space-sm)) calc(-1 * var(--space-sm)) -10px;
  background: oklch(98.6% 0.004 250 / 0.86); backdrop-filter: blur(12px); border-bottom: 1px solid var(--color-rule);
  display: none;
}
body:not([data-tab="tree"]) .bar::before { display: block; }
.nav-pill {
  display: flex; align-items: center; gap: var(--space-2xs); padding: 6px; padding-left: var(--space-xs);
  background: oklch(100% 0 0 / 0.88); backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--color-rule); border-radius: var(--radius-pill); box-shadow: var(--shadow-md);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: var(--space-2xs); text-decoration: none; color: inherit; padding-right: var(--space-2xs); }
.mark { width: 30px; height: 30px; }
.mark rect { fill: var(--color-accent); }
.mark path { stroke: var(--color-accent-ink); stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand-txt b { font-family: var(--font-display); font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-txt small { color: var(--color-ink-3); font-size: 11.5px; }
.tabs { display: flex; gap: 2px; padding-left: var(--space-2xs); border-left: 1px solid var(--color-rule); }
.tabs button {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; white-space: nowrap;
  border: 0; border-radius: var(--radius-pill); background: none; color: var(--color-ink-2); font-weight: 500; font-size: var(--text-sm);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tabs button:hover { background: var(--color-paper-2); color: var(--color-ink); }
.tabs button.on { background: var(--color-ink); color: var(--color-paper); }
.tabs svg.lucide { width: 16px; height: 16px; }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2xs); min-width: 0; }
.search {
  min-width: 0;
  position: relative; display: flex; align-items: center; gap: var(--space-2xs); width: 300px; height: 44px; padding: 0 6px 0 var(--space-xs);
  background: oklch(100% 0 0 / 0.92); backdrop-filter: blur(14px); border: 1px solid var(--color-rule);
  border-radius: var(--radius-pill); box-shadow: var(--shadow-md); color: var(--color-ink-3);
}
.search:focus-within { border-color: var(--color-accent); box-shadow: 0 0 0 4px var(--color-accent-soft), var(--shadow-md); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--color-ink); font-size: var(--text-sm); }
.search input::placeholder { color: var(--color-ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.kbd { font: 500 12px var(--font-body); color: var(--color-ink-3); border: 1px solid var(--color-rule); border-radius: 6px; padding: 1px 7px; background: var(--color-paper-2); }
.bar #btn-login { height: 44px; box-shadow: var(--shadow-md); }
.user {
  display: flex; align-items: center; gap: var(--space-2xs); height: 44px; padding: 0 4px 0 5px;
  background: oklch(100% 0 0 / 0.92); border: 1px solid var(--color-rule); border-radius: var(--radius-pill); box-shadow: var(--shadow-md);
}
.user-me { display: flex; align-items: center; gap: var(--space-2xs); border: 0; background: none; padding: 0; border-radius: var(--radius-pill); }
.user-me:hover .user-name { color: var(--color-accent-2); }
.user a.icon-btn { color: var(--color-ink-2); }
.user-av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--color-accent-soft); color: var(--color-accent-2); font-weight: 650; font-size: 13px; }
.user-name { font-weight: 600; font-size: var(--text-sm); white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

/* popover tìm kiếm */
.pop {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 30; max-height: min(420px, 60vh); overflow-y: auto;
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px;
}
.pop button {
  display: flex; align-items: center; gap: var(--space-xs); width: 100%; text-align: left; border: 0; background: none;
  padding: 8px; border-radius: var(--radius-sm); color: var(--color-ink);
}
.pop button:hover, .pop button.act { background: var(--color-paper-2); }
.pop .who { min-width: 0; }
.pop .who b { display: block; font-weight: 600; font-size: var(--text-sm); }
.pop .who small { display: block; color: var(--color-ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop .empty { padding: var(--space-sm); color: var(--color-ink-3); font-size: var(--text-sm); }

/* ---------- avatar ---------- */
.av {
  --ring: var(--color-nam); --bg: var(--color-nam-soft);
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  background: var(--bg); color: var(--ring); font: 650 14px/1 var(--font-display); letter-spacing: 0;
  box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 3.5px var(--ring);
}
.av.nu { --ring: var(--color-nu); --bg: var(--color-nu-soft); }
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av.dead { filter: grayscale(0.7); opacity: .9; }
.av.sm { width: 30px; height: 30px; font-size: 11px; box-shadow: 0 0 0 1.5px var(--color-surface), 0 0 0 2.5px var(--ring); }
.av.lg { width: 92px; height: 92px; font-size: 30px; box-shadow: 0 0 0 4px var(--color-surface), 0 0 0 6px var(--ring); }

/* ---------- vùng cây ---------- */
main { position: fixed; inset: 0; }
.tab { display: none; position: absolute; inset: 0; }
.tab.on { display: block; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; background: var(--color-paper); }
.viewport:active { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.band { position: absolute; border-radius: var(--radius-lg); background: color-mix(in oklch, var(--gs) 70%, transparent); }
.gen-label {
  position: absolute; font: 600 12px/1 var(--font-display); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-ink-3);
  display: flex; flex-direction: column; gap: 4px;
}
.gen-label b { font: 650 28px/1 var(--font-display); color: var(--color-rule-2); letter-spacing: -0.02em; text-transform: none; }
.links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.links path { fill: none; stroke: color-mix(in oklch, var(--g) 55%, var(--color-rule-2)); stroke-width: 1.8; }
.links path.hl { stroke: var(--g); stroke-width: 3.2; }

.node {
  position: absolute; padding: 0 10px 12px; text-align: center; user-select: none; cursor: pointer;
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: 18px; box-shadow: var(--shadow-sm);
  touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  transition: box-shadow var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.node:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--color-rule-2); }
.node.sel { box-shadow: 0 0 0 3px var(--color-surface), 0 0 0 6px var(--g), var(--shadow-lg); }
.node.flash { animation: flash 1s var(--ease-out) 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 4px var(--color-surface), 0 0 0 12px var(--gs), var(--shadow-md); } }
.node.drop, .vcard.drop { box-shadow: 0 0 0 3px var(--color-surface), 0 0 0 6px var(--color-ok); }
.node.dragging, .vcard.dragging { opacity: .35; }
/* dải màu đầu thẻ: màu của đời, một mảng tròn sáng làm điểm nhấn */
.node-band {
  height: 54px; margin: 0 -10px; border-radius: 17px 17px 0 0; padding: 8px 10px;
  display: flex; justify-content: space-between; align-items: flex-start; color: var(--color-accent-ink);
  background-color: var(--g);
  background-image: radial-gradient(circle at 88% -30%, oklch(100% 0 0 / 0.2) 0 38%, transparent 39%), radial-gradient(circle at -6% 130%, oklch(0% 0 0 / 0.1) 0 30%, transparent 31%);
}
.node-gen { display: inline-flex; align-items: center; gap: 4px; font: 600 11px/1 var(--font-display); letter-spacing: .03em; text-transform: uppercase; }
.node-gen b { font-size: 16px; letter-spacing: 0; }
.node-gen svg.lucide { width: 14px; height: 14px; }
.node-kids { display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 7px; border-radius: var(--radius-pill); background: oklch(100% 0 0 / 0.22); font: 650 11.5px/1 var(--font-display); }
.node-kids svg.lucide { width: 12px; height: 12px; }
.node-av { position: relative; width: 64px; margin: -32px auto 8px; }
.node-av .av { width: 64px; height: 64px; font-size: 20px; box-shadow: 0 0 0 4px var(--color-surface), 0 6px 16px oklch(24% 0.02 258 / 0.18); }
.node-av .av.sp { position: absolute; right: -18px; bottom: -2px; width: 30px; height: 30px; font-size: 10px; box-shadow: 0 0 0 3px var(--color-surface); }
.node-name { font: 650 15px/1.25 var(--font-display); letter-spacing: -0.015em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.node-role { display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; padding: 2px 9px; border-radius: var(--radius-pill); background: var(--gs); color: var(--g); font-size: 11.5px; font-weight: 650; }
.node-role svg.lucide { width: 12px; height: 12px; }
.node-meta { margin-top: 4px; font-size: 12.5px; color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.node-sp { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 2px; font-size: 11.5px; color: var(--color-ink-3); white-space: nowrap; overflow: hidden; }
.node-sp svg.lucide { width: 11px; height: 11px; color: var(--color-nu); flex: none; }
/* cấp bậc theo chức danh */
.rank-to { --g: var(--color-gold-deep); --gs: var(--color-gold-soft); }
.node.rank-to { border: 2px solid var(--color-gold); }
.node.rank-ho { border: 2px solid var(--g); }
.node.rank-chi { border: 1.5px solid color-mix(in oklch, var(--g) 50%, var(--color-rule)); }
.toggle {
  position: absolute; left: 50%; bottom: -15px; transform: translateX(-50%); z-index: 2;
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: var(--radius-pill); white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  border: 1.5px solid var(--g); background: var(--color-surface); color: var(--g); font: 650 12.5px/1 var(--font-display); box-shadow: var(--shadow-sm);
}
.toggle:hover { background: var(--gs); }
.toggle.closed { background: var(--g); color: var(--color-accent-ink); padding: 0 8px 0 11px; }
.toggle.closed:hover { filter: brightness(0.93); }
.toggle svg.lucide { width: 14px; height: 14px; }

/* dock + ghi chú nổi */
.dock {
  position: absolute; left: 50%; bottom: var(--space-md); transform: translateX(-50%); z-index: 15;
  display: flex; gap: 6px; padding: 6px; max-width: calc(100% - 2 * var(--space-sm)); overflow-x: auto; scrollbar-width: none;
  background: oklch(100% 0 0 / 0.9); backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--color-rule); border-radius: var(--radius-pill); box-shadow: var(--shadow-lg);
}
.seg { display: flex; gap: 2px; padding: 2px; border-radius: var(--radius-pill); background: var(--color-paper-2); flex: none; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; white-space: nowrap;
  border: 0; border-radius: var(--radius-pill); background: none; color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 500;
}
.seg button:hover { color: var(--color-ink); }
.seg button.on, .seg button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-sm); font-weight: 600; }
.seg.zoom button { padding: 0 10px; }
.float-note {
  position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 14; max-width: calc(100% - 2 * var(--space-sm));
  display: flex; align-items: center; gap: var(--space-xs); padding: 8px 8px 8px var(--space-sm);
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-pill); box-shadow: var(--shadow-md);
  font-size: var(--text-sm); color: var(--color-ink-2);
}
.float-note.edit { padding-right: var(--space-sm); background: var(--color-accent-soft); border-color: oklch(85% 0.06 256); color: var(--color-accent-2); }
.float-note b { color: var(--color-ink); }
.drag-ghost {
  left: 0; top: 0; display: flex; align-items: center; gap: 6px;
  position: fixed; pointer-events: none; z-index: 60; padding: 6px 14px; border-radius: var(--radius-pill);
  background: var(--color-ink); color: var(--color-paper); font-weight: 600; font-size: var(--text-sm); box-shadow: var(--shadow-lg);
}

/* ---------- cây dọc ---------- */
.listview { position: absolute; inset: 0; overflow-y: auto; padding: 92px var(--space-sm) 140px; }
.vtree { --ind: 32px; max-width: 900px; margin: 0 auto; }
.vrow { position: relative; padding: 5px 0 5px calc(var(--d) * var(--ind)); }
.vl, .ve { position: absolute; top: 0; bottom: 0; left: calc(var(--i) * var(--ind) + var(--ind) / 2 - 1px); --lc: color-mix(in oklch, var(--g) 55%, var(--color-rule)); }
.vl { width: 2px; background: var(--lc); }
.ve { width: calc(var(--ind) / 2 + 1px); border-left: 2px solid var(--lc); }
.ve.last { border-left-color: transparent; }
.ve::after { content: ''; position: absolute; left: -2px; top: 0; width: 100%; height: 50%; border-left: 2px solid var(--lc); border-bottom: 2px solid var(--lc); border-bottom-left-radius: 12px; }
.vcard {
  position: relative; display: flex; align-items: center; gap: var(--space-xs); min-height: 68px; padding: 8px 10px 8px 0; overflow: hidden;
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: 16px; box-shadow: var(--shadow-sm); cursor: pointer;
  -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  transition: box-shadow var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.vcard:hover { border-color: var(--color-rule-2); box-shadow: var(--shadow-md); }
.vcard.sel { border-color: var(--g); box-shadow: 0 0 0 3px var(--gs), var(--shadow-md); }
.vc-spine {
  align-self: stretch; width: 46px; margin: -8px 0; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background-color: var(--g); color: var(--color-accent-ink); line-height: 1;
  background-image: radial-gradient(circle at 100% 0, oklch(100% 0 0 / 0.2) 0 45%, transparent 46%);
}
.vc-spine b { font: 700 21px/1 var(--font-display); }
.vc-spine small { font: 600 9.5px/1 var(--font-body); letter-spacing: .1em; text-transform: uppercase; opacity: .85; }
.vc-spine svg.lucide { width: 20px; height: 20px; }
.vcard .av { width: 46px; height: 46px; font-size: 15px; }
.vc-body { flex: 1; min-width: 0; }
.vc-name { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 8px; font: 650 15.5px/1.3 var(--font-display); letter-spacing: -0.01em; }
.vc-role { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--gs); color: var(--g); font: 650 11.5px/1.3 var(--font-body); }
.vc-role svg.lucide { width: 12px; height: 12px; }
.vc-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; font-size: 13px; color: var(--color-ink-3); }
.vc-sp { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.vc-sp svg.lucide { width: 12px; height: 12px; color: var(--color-nu); }
.vc-sp .nm:hover { color: var(--color-accent-2); text-decoration: underline; }
.vc-kids {
  flex: none; display: inline-flex; align-items: center; gap: 3px; height: 36px; padding: 0 8px 0 12px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--g); background: var(--g); color: var(--color-accent-ink); font: 700 14px/1 var(--font-display);
}
.vc-kids span { font: 500 11.5px var(--font-body); opacity: .9; }
.vc-kids svg.lucide { width: 16px; height: 16px; transition: transform var(--dur-short) var(--ease-out); }
.vc-kids.open { background: var(--gs); color: var(--g); }
.vc-kids.open svg.lucide { transform: rotate(180deg); }
.vc-grip { flex: none; display: grid; place-items: center; width: 34px; height: 44px; margin-left: -4px; border-radius: 10px; color: var(--color-ink-3); background: var(--color-paper-2); touch-action: none; cursor: grab; }
.vc-grip svg.lucide { width: 18px; height: 18px; }

/* ---------- hồ sơ (sheet) ---------- */
.sheet {
  position: fixed; z-index: 25; top: 76px; right: var(--space-sm); bottom: var(--space-sm); width: min(400px, calc(100% - 2 * var(--space-sm)));
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow-y: auto; padding: var(--space-md); padding-top: var(--space-lg);
  transform: translateX(calc(100% + 40px)); transition: transform var(--dur-mid) var(--ease-out); visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
.sheet-x { position: absolute; top: 10px; right: 10px; z-index: 3; }
.prof-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.prof-head h2 { font-size: var(--text-xl); margin-top: var(--space-xs); overflow-wrap: anywhere; }
.prof-head .role { font-size: var(--text-sm); font-weight: 600; color: var(--color-accent-2); }
.prof-head .sub { color: var(--color-ink-3); font-size: var(--text-sm); }
.quick { display: flex; justify-content: center; gap: var(--space-2xs); margin-top: var(--space-sm); flex-wrap: wrap; }
.facts { margin: var(--space-md) 0 0; padding: 0; list-style: none; border-top: 1px solid var(--color-rule); }
.facts li { display: flex; gap: var(--space-xs); padding: 10px 2px; border-bottom: 1px solid var(--color-rule); font-size: var(--text-sm); }
.facts svg.lucide { color: var(--color-ink-3); margin-top: 1px; width: 17px; height: 17px; }
.facts span { color: var(--color-ink-3); width: 92px; flex: none; }
.facts b { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.rel { margin-top: var(--space-md); }
.rel h3 { font: 600 12px/1 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-ink-3); margin: var(--space-md) 0 6px; }
.people { display: flex; flex-direction: column; }
.person-row {
  display: flex; align-items: center; gap: var(--space-xs); padding: 7px 6px; margin: 0 -6px; border: 0; background: none; border-radius: var(--radius-sm);
  text-align: left; width: calc(100% + 12px);
}
.person-row:hover { background: var(--color-paper-2); }
.person-row b { font-weight: 600; font-size: var(--text-sm); display: block; }
.person-row small { color: var(--color-ink-3); font-size: 12.5px; }
.person-row > svg.lucide { margin-left: auto; color: var(--color-ink-3); width: 16px; height: 16px; }
.thumbs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); cursor: zoom-in; display: block; }
.edit-actions { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-top: var(--space-md); padding-top: var(--space-md); border-top: 1px solid var(--color-rule); }

/* ---------- trang nội dung ---------- */
.page { overflow-y: auto; padding: 100px var(--space-sm) var(--space-2xl); }
.wrap { max-width: 1040px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-sm); margin-bottom: var(--space-lg); flex-wrap: wrap; }
.page-head h1 { font-size: var(--text-2xl); overflow-wrap: anywhere; min-width: 0; }
.note { display: flex; align-items: center; gap: var(--space-2xs); color: var(--color-ink-2); font-size: var(--text-sm); margin: 0 0 var(--space-md); }

/* lịch giỗ */
.next-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-md);
  padding: var(--space-md); margin-bottom: var(--space-lg); border-radius: var(--radius-lg);
  background: var(--color-graphite); color: var(--color-paper); cursor: pointer;
}
.next-card .big { font: 700 56px/0.9 var(--font-display); letter-spacing: -0.04em; }
.next-card .big small { display: block; font: 500 13px/1.4 var(--font-body); letter-spacing: 0; color: oklch(80% 0.01 256); margin-top: 6px; }
.next-card h2 { font-size: var(--text-xl); overflow-wrap: anywhere; }
.next-card p { margin: 4px 0 0; color: oklch(80% 0.01 256); font-size: var(--text-sm); }
.next-card .pill { background: var(--color-accent); color: var(--color-accent-ink); }
.month { margin-bottom: var(--space-lg); }
.month h2 { font-size: var(--text-lg); margin-bottom: var(--space-xs); }
.rows { background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-lg); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 52px auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm); border-top: 1px solid var(--color-rule); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--color-paper-2); }
.date { text-align: center; line-height: 1; }
.date b { display: block; font: 650 24px/1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.date span { font-size: 11.5px; color: var(--color-ink-3); }
.row .info { min-width: 0; }
.row .info b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .info small { color: var(--color-ink-3); font-size: 13px; }
.pill { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--color-paper-2); color: var(--color-ink-2); }
.pill.near { background: var(--color-accent-soft); color: var(--color-accent-2); }

/* kho ảnh */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: var(--space-md); }
.album { border: 0; background: none; padding: 0; text-align: left; color: inherit; }
.album .cover {
  aspect-ratio: 4 / 3; border-radius: var(--radius-lg); background: var(--color-paper-3) center / cover; border: 1px solid var(--color-rule);
  display: grid; place-items: center; color: var(--color-ink-3); transition: transform var(--dur-short) var(--ease-out), box-shadow var(--dur-short) var(--ease-out);
}
.album:hover .cover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.album .cover svg.lucide { width: 28px; height: 28px; }
.album b { display: block; margin-top: var(--space-xs); font-family: var(--font-display); font-weight: 600; }
.album small { color: var(--color-ink-3); font-size: 13px; }
.back { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--color-ink-2); font-weight: 500; padding: 0; margin-bottom: var(--space-sm); }
.back:hover { color: var(--color-accent-2); }
.dropzone {
  display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-md); margin-bottom: var(--space-md);
  border: 1.5px dashed var(--color-rule-2); border-radius: var(--radius-lg); background: var(--color-surface); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.dropzone:hover, .dropzone.over { border-color: var(--color-accent); background: var(--color-accent-soft); }
.dz-ic { width: 48px; height: 48px; border-radius: var(--radius-md); background: var(--color-accent-soft); color: var(--color-accent-2); display: grid; place-items: center; flex: none; }
.dropzone b { display: block; }
.dropzone small { color: var(--color-ink-3); }
.progress { height: 4px; background: var(--color-paper-3); border-radius: var(--radius-pill); overflow: hidden; margin-top: 8px; }
.progress > span { height: 100%; width: 0; background: var(--color-accent); transition: width var(--dur-short) var(--ease-out); }
.photos { columns: 4 220px; column-gap: var(--space-xs); }
.photo { break-inside: avoid; margin-bottom: var(--space-xs); position: relative; cursor: zoom-in; border-radius: var(--radius-md); overflow: hidden; background: var(--color-paper-3); }
.photo img { width: 100%; display: block; transition: transform var(--dur-mid) var(--ease-out); }
.photo:hover img { transform: scale(1.03); }
.photo .tagc { position: absolute; left: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 4px; background: oklch(20% 0.02 258 / 0.7); color: var(--color-paper); font-size: 12px; border-radius: var(--radius-pill); padding: 2px 9px; }
.photo .tagc svg.lucide { width: 13px; height: 13px; }
.empty-state { text-align: center; padding: var(--space-2xl) var(--space-sm); color: var(--color-ink-3); border: 1px dashed var(--color-rule-2); border-radius: var(--radius-lg); }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 45; display: grid; grid-template-columns: minmax(0, 1fr) 340px; background: oklch(16% 0.012 258); color: var(--color-paper); }
.lb-img { touch-action: none; /* vuốt ngang/xuống do JS xử lý */ position: relative; display: grid; place-items: center; padding: var(--space-lg); min-height: 0; }
.lb-img img { max-width: 100%; max-height: calc(100vh - 2 * var(--space-lg)); object-fit: contain; border-radius: var(--radius-sm); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; background: oklch(100% 0 0 / 0.1); color: var(--color-paper); }
.lb-nav:hover { background: oklch(100% 0 0 / 0.2); }
.lb-side { background: var(--color-surface); color: var(--color-ink); padding: var(--space-lg) var(--space-md); overflow-y: auto; position: relative; }
.lb-side .count { color: var(--color-ink-3); font-size: var(--text-sm); }
.lb-side h3 { font: 600 12px/1 var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--color-ink-3); margin: var(--space-md) 0 var(--space-2xs); }
.lb-side .desc { margin: var(--space-2xs) 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 6px 0 12px; border-radius: var(--radius-pill); border: 1px solid var(--color-rule); background: var(--color-paper); font-size: 13px; cursor: pointer; }
.tag:hover { border-color: var(--color-rule-2); }
.tag .rm { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; color: var(--color-ink-3); }
.tag .rm:hover { background: var(--color-danger-soft); color: var(--color-danger); }
.tag .rm svg.lucide { width: 13px; height: 13px; }
.tag-pick { position: relative; margin-top: var(--space-2xs); }
.tag-pick input, .field input, .field select, .field textarea, .row-form input, .row-form select {
  width: 100%; height: 42px; border: 1px solid var(--color-rule); background: var(--color-surface); border-radius: 10px; padding: 0 12px; outline: none;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; }
.tag-pick input:focus, .field :is(input, select, textarea):focus, .row-form :is(input, select):focus { border-color: var(--color-accent); box-shadow: 0 0 0 4px var(--color-accent-soft); }
.field [aria-invalid="true"] { border-color: var(--color-danger); }
.lb-x { position: absolute; top: 12px; right: 12px; }

/* hỏi đáp */
.chat-page { padding: 0; overflow: hidden; }
.chat-wrap { height: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; padding: 88px var(--space-sm) var(--space-md); }
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-md) 2px; }
.chat-hello { margin: auto 0; padding-bottom: var(--space-lg); }
.chat-hello h1 { font-size: var(--text-2xl); }
.suggest { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-top: var(--space-md); }
.suggest button { border: 1px solid var(--color-rule); background: var(--color-surface); border-radius: var(--radius-pill); padding: 8px 14px; font-size: var(--text-sm); color: var(--color-ink-2); text-align: left; }
.suggest button:hover { border-color: var(--color-accent); color: var(--color-accent-2); }
.msg { max-width: 88%; line-height: 1.6; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--color-accent); color: var(--color-accent-ink); padding: 10px 16px; border-radius: 20px 20px 6px 20px; }
.msg.bot { align-self: flex-start; display: flex; gap: var(--space-xs); }
.msg.bot .bot-av { width: 30px; height: 30px; border-radius: 9px; background: var(--color-accent-soft); color: var(--color-accent-2); display: grid; place-items: center; flex: none; margin-top: 2px; }
.msg.bot .bot-av svg.lucide { width: 16px; height: 16px; }
.msg.bot .txt { white-space: pre-wrap; padding-top: 4px; }
.msg.bot a { color: var(--color-accent-2); font-weight: 600; text-decoration: none; background: var(--color-accent-soft); padding: 0 4px; border-radius: 4px; }
.msg.bot a:hover { text-decoration: underline; }
.msg.typing .txt { color: var(--color-ink-3); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--color-ink-3); animation: dot 1.2s var(--ease-in-out) infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { opacity: .25; } }
.composer {
  display: flex; align-items: center; gap: var(--space-2xs); padding: 6px 6px 6px var(--space-sm);
  background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-pill); box-shadow: var(--shadow-md);
}
.composer:focus-within { border-color: var(--color-accent); box-shadow: 0 0 0 4px var(--color-accent-soft), var(--shadow-md); }
.composer input { flex: 1; min-width: 0; border: 0; outline: none; background: none; height: 40px; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--color-accent); color: var(--color-accent-ink); display: grid; place-items: center; }
.send:hover { background: var(--color-accent-2); }
.send:disabled { opacity: .5; }

/* quản trị */
.admin-grid { display: grid; gap: var(--space-md); grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); }
.panel { background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-lg); padding: var(--space-md); min-width: 0; }
.panel h2 { display: flex; align-items: center; gap: var(--space-2xs); font-size: var(--text-lg); margin-bottom: var(--space-sm); }
.panel h2 svg.lucide { color: var(--color-ink-3); }
.row-form { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-bottom: var(--space-sm); }
.row-form > * { flex: 1 1 140px; }
.row-form .btn { flex: 0 0 auto; height: 42px; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.tbl td { padding: 10px 4px; border-top: 1px solid var(--color-rule); vertical-align: middle; }
.tbl small { color: var(--color-ink-3); }
.tbl select { height: 34px; border: 1px solid var(--color-rule); border-radius: 8px; padding: 0 8px; background: var(--color-surface); }
.changes { list-style: none; margin: 0; padding: 0; max-height: 440px; overflow-y: auto; }
.changes li { padding: 10px 0; border-top: 1px solid var(--color-rule); font-size: var(--text-sm); }
.changes li:first-child { border-top: 0; }
.changes li.undone { color: var(--color-ink-3); text-decoration: line-through; }
.changes small { display: block; color: var(--color-ink-3); font-size: 12.5px; text-decoration: none; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--space-sm); background: var(--color-scrim); }
.modal-box { width: min(540px, 100%); max-height: calc(100vh - 2 * var(--space-sm)); overflow-y: auto; background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-md); }
.modal-box h3 { font-size: var(--text-lg); margin-bottom: var(--space-sm); }
.modal-box p { margin: 0 0 var(--space-xs); color: var(--color-ink-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-xs); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--color-ink-2); min-width: 0; }
.field.full { grid-column: 1 / -1; }
.switch { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-xs); font-size: var(--text-sm); font-weight: 500; cursor: pointer; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: var(--radius-pill); background: var(--color-rule-2); position: relative; margin: 0; cursor: pointer; transition: background var(--dur-fast) var(--ease-out); flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--color-surface); box-shadow: var(--shadow-sm); transition: transform var(--dur-fast) var(--ease-out); }
.switch input:checked { background: var(--color-accent); }
.switch input:checked::after { transform: translateX(16px); }
.sub-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-xs); padding: var(--space-sm); background: var(--color-paper-2); border-radius: var(--radius-md); }
.sub-grid .field.full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2xs); margin-top: var(--space-md); }
.err { color: var(--color-danger); font-size: var(--text-sm); margin-top: var(--space-2xs); min-height: 1em; }
.hint { font-size: 12.5px; color: var(--color-ink-3); margin-top: var(--space-xs); }
.hint code { font-family: var(--font-body); font-weight: 600; color: var(--color-ink-2); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 70; max-width: calc(100% - 2 * var(--space-sm));
  display: flex; align-items: center; gap: var(--space-2xs); padding: 10px 16px; border-radius: var(--radius-pill);
  background: var(--color-graphite); color: var(--color-paper); font-size: var(--text-sm); box-shadow: var(--shadow-lg);
}
.toast.bad { background: var(--color-danger); }

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

/* màu theo đời */
.g1 { --g: var(--gen-1); --gs: var(--gen-1-soft); } .g2 { --g: var(--gen-2); --gs: var(--gen-2-soft); }
.g3 { --g: var(--gen-3); --gs: var(--gen-3-soft); } .g4 { --g: var(--gen-4); --gs: var(--gen-4-soft); }
.g5 { --g: var(--gen-5); --gs: var(--gen-5-soft); } .g6 { --g: var(--gen-6); --gs: var(--gen-6-soft); }
.gen-pill { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: var(--radius-pill); background: var(--gs); color: var(--g); font: 650 11px/1 var(--font-display); white-space: nowrap; margin-right: 6px; vertical-align: 1px; flex: none; }
.indent { background: color-mix(in oklch, var(--g) 35%, var(--color-rule)) !important; }

/* chọn đời trên thanh điều khiển */
.depth-seg { align-items: center; padding: 3px 4px 3px 10px; gap: 4px; }
.depth-lbl { font-size: 12.5px; font-weight: 600; color: var(--color-ink-3); margin-right: 2px; }
.seg .dg {
  width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: 50%;
  font: 650 13.5px/1 var(--font-display); color: var(--g); background: var(--color-surface);
  box-shadow: inset 0 0 0 1.5px color-mix(in oklch, var(--g) 45%, transparent);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.seg .dg:hover { background: var(--gs); color: var(--g); }
.seg .dg.in { background: var(--gs); box-shadow: inset 0 0 0 1.5px var(--g); }
.seg .dg.cur, .seg .dg.cur:hover { background: var(--g); color: var(--color-accent-ink); box-shadow: none; }
.dock-btn { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--color-paper-2); color: var(--color-ink-2); }
.dock-btn:hover { background: var(--color-paper-3); color: var(--color-ink); }

/* dòng dõi trong hồ sơ */
.lineage { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px; margin-top: var(--space-sm); }
.lin { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border: 0; border-radius: var(--radius-pill); background: var(--gs); color: var(--g); font-weight: 600; font-size: 12.5px; }
.lin .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--g); }
.lin.me { background: var(--g); color: var(--color-accent-ink); }
.lin.me .dot { background: var(--color-accent-ink); }
.lineage .sep svg.lucide { width: 13px; height: 13px; color: var(--color-ink-3); }

/* lịch tháng */
.cal { background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-lg); padding: var(--space-sm); }
.cal-head { display: flex; align-items: center; gap: var(--space-2xs); margin-bottom: var(--space-sm); }
.cal-title { flex: 1; text-align: center; min-width: 0; }
.cal-title h2 { font-size: var(--text-xl); }
.cal-title small { color: var(--color-ink-3); font-size: 13px; }
.cal-grid { touch-action: pan-y; /* vuốt ngang để JS đổi tháng, không bị trình duyệt huỷ */ display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { text-align: center; font-size: 12px; font-weight: 600; color: var(--color-ink-3); padding: 4px 0; }
.cal-cell {
  position: relative; min-height: 96px; padding: 6px 6px 4px; border: 1px solid var(--color-rule); border-radius: 10px; background: var(--color-surface);
  display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 2px; color: var(--color-ink); min-width: 0;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.cal-cell.pad { border: 0; background: none; }
.cal-cell:hover { border-color: var(--color-rule-2); background: var(--color-paper); }
.cal-cell .sd { font: 650 16px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.cal-cell.sun .sd { color: var(--color-danger); }
.cal-cell .ld { position: absolute; top: 7px; right: 7px; font-size: 11px; color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.cal-cell .ld.mark { color: var(--color-danger); font-weight: 650; }
.cal-cell.today { border-color: var(--color-accent); box-shadow: inset 0 0 0 1px var(--color-accent); }
.cal-cell.today .sd { color: var(--color-accent-2); }
.cal-cell.sel { background: var(--color-accent-soft); border-color: var(--color-accent); }
.cal-cell.has { background: var(--color-paper); }
.cal-names { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; min-width: 0; }
.cn { display: block; font-size: 11.5px; font-weight: 600; color: var(--g); background: var(--gs); border-radius: 5px; padding: 1px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-names .more { font-size: 11px; color: var(--color-ink-3); padding-left: 4px; }
.cal-dots { display: none; gap: 3px; justify-content: center; margin-top: auto; }
.cal-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--g); }
.cal-legend { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: var(--space-sm) 2px 0; font-size: 12.5px; color: var(--color-ink-3); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend .mk { width: 14px; height: 2px; background: var(--color-danger); }
.cal-legend .dt { width: 8px; height: 8px; border-radius: 50%; background: var(--gen-3); box-shadow: 10px 0 0 var(--gen-5); margin-right: 10px; }
.day-card { margin-top: var(--space-md); }
.day-head { display: flex; flex-direction: column; margin-bottom: var(--space-xs); }
.day-head b { font: 650 var(--text-lg)/1.3 var(--font-display); }
.day-head small { color: var(--color-ink-3); }
.day-card .row { grid-template-columns: auto auto minmax(0, 1fr) auto; }
.day-card .row > svg.lucide { color: var(--color-ink-3); }

/* kho ảnh theo gia đình */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs); margin-bottom: var(--space-lg); }
.fam-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; padding: 2px; }
.fam-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px 0 4px; white-space: nowrap; flex: none;
  border: 1px solid var(--color-rule); background: var(--color-surface); border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: 500;
}
.fam-chip small { color: var(--color-ink-3); font-weight: 600; }
.fam-chip:hover { border-color: var(--color-rule-2); }
.fam-chip.on { border-color: var(--color-accent); background: var(--color-accent-soft); color: var(--color-accent-2); }
.fam-group { margin-bottom: var(--space-xl); }
.fam-head { display: flex; align-items: center; gap: var(--space-xs); margin-bottom: var(--space-sm); }
.fam-head .av.sm { width: 36px; height: 36px; font-size: 12px; }
.fam-name { flex: 1; min-width: 0; }
.fam-name h2 { font-size: var(--text-lg); overflow-wrap: anywhere; }
.fam-name small { color: var(--color-ink-3); font-size: 13px; }
.fam-ic { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--color-accent-soft); color: var(--color-accent-2); flex: none; }
.fam-tag { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; margin-bottom: var(--space-2xs); color: var(--color-ink-2); font-weight: 600; font-size: var(--text-sm); }
.fam-tag:hover { color: var(--color-accent-2); }
.fam-tag .fam-ic, .fam-tag .av.sm { width: 26px; height: 26px; }
.fam-tag .fam-ic svg.lucide { width: 14px; height: 14px; }
.choice { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.choice label { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border: 1px solid var(--color-rule); border-radius: 10px; cursor: pointer; color: var(--color-ink); font-size: var(--text-sm); }
.choice label:has(input:checked) { border-color: var(--color-accent); background: var(--color-accent-soft); }
.choice input { accent-color: var(--color-accent); width: 18px; height: 18px; margin: 0; }
.link-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 2px 0; color: var(--color-accent-2); font-size: 12.5px; font-weight: 500; }
.link-btn svg.lucide { width: 13px; height: 13px; }
.sheet-grip { display: none; }
.hint-touch { display: none; }
@media (pointer: coarse) { .hint-desk { display: none; } .hint-touch { display: inline; } }

/* màn hình vừa: thu gọn ô tìm kiếm để header không chồng lấn */
@media (max-width: 1320px) and (min-width: 1101px) {
  .search { width: 210px; }
  .kbd, .brand-txt small { display: none; }
  .tabs button { padding: 0 11px; }
}

/* màn hình cảm ứng: vùng chạm to hơn */
@media (pointer: coarse) {
  .toggle { height: 34px; padding: 0 14px; font-size: 13px; bottom: -17px; }
  .seg button { height: 40px; }
  .person-row { padding: 10px 6px; }
}

/* ---------- di động ---------- */
@media (max-width: 1100px) {
  .bar { top: var(--space-2xs); left: var(--space-2xs); right: var(--space-2xs); }
  .bar::before { display: block; inset: calc(-1 * var(--space-2xs)) calc(-1 * var(--space-2xs)) -8px; }
  /* backdrop-filter tạo containing block → thanh tab fixed bị kẹt trong pill */
  .nav-pill { padding: 4px; border-radius: var(--radius-pill); backdrop-filter: none; background: var(--color-surface); }
  .brand { padding-right: 0; }
  .brand-txt, .kbd { display: none; }
  .search { width: auto; flex: 1; height: 42px; }
  .bar-right { flex: 1; }
  .bar #btn-login { height: 42px; padding: 0 12px; }
  .bar #btn-login span, .user-name { display: none; }
  .user { height: 42px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; border: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; background: oklch(100% 0 0 / 0.94); backdrop-filter: blur(14px); border-top: 1px solid var(--color-rule);
  }
  /* ô nhập 16px để iPhone không tự phóng to khi gõ */
  input, select, textarea, .search input, .composer input { font-size: 16px !important; }
  .depth-lbl { display: none; }
  .depth-seg { padding: 3px; }
  .seg .dg { width: 34px; height: 34px; }
  .page-head { margin-bottom: var(--space-md); }
  .vtree { --ind: 18px; }
  .vcard { gap: 10px; min-height: 62px; }
  .vc-spine { width: 38px; }
  .vc-spine b { font-size: 18px; }
  .vcard .av { width: 40px; height: 40px; font-size: 13px; }
  .vc-name { font-size: 15px; }
  .vc-kids { height: 34px; padding: 0 6px 0 10px; font-size: 13.5px; }
  .vc-kids span { display: none; }
  .page-head .seg { width: 100%; }
  .page-head .seg button { flex: 1; justify-content: center; }
  .page-head .lede { font-size: 15px; }
  /* lịch tháng gọn: chấm màu thay tên */
  .cal { padding: var(--space-2xs); border-radius: var(--radius-md); }
  .cal-head .cal-today { display: none; }
  .cal-title h2 { font-size: var(--text-lg); }
  .cal-title small { font-size: 11.5px; display: block; }
  .cal-grid { gap: 2px; }
  .cal-cell { min-height: 54px; padding: 5px 0 5px; align-items: center; border-radius: 8px; }
  .cal-cell .sd { font-size: 15px; }
  .cal-cell .ld { position: static; font-size: 10px; }
  .cal-names { display: none; }
  .cal-dots { display: flex; }
  .day-card .row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .day-card .row .av { display: none; }
  /* hỏi đáp */
  .chat-hello h1 { font-size: 26px; }
  .chat-hello .lede { font-size: 15px; }
  .suggest { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: var(--space-sm) calc(-1 * var(--space-sm)) 0; padding: 0 var(--space-sm); }
  .suggest button { flex: none; white-space: nowrap; }
  .msg { max-width: 94%; font-size: 15px; }
  .chat-wrap { height: 100dvh; }
  .composer { position: sticky; bottom: 0; }
  /* kho ảnh */
  .fam-group { margin-bottom: var(--space-lg); }
  .album .cover { aspect-ratio: 1; border-radius: var(--radius-md); }
  .dropzone { padding: var(--space-sm); gap: var(--space-xs); }
  .dz-ic { width: 40px; height: 40px; }
  .photos { columns: 2; column-gap: 6px; }
  .photo { margin-bottom: 6px; border-radius: var(--radius-sm); }
  .lb-side .count { padding-right: 40px; }
  .tabs button { flex-direction: column; height: auto; padding: 6px 4px; gap: 2px; font-size: 11.5px; flex: 1; border-radius: var(--radius-md); }
  .tabs button.on { background: var(--color-accent-soft); color: var(--color-accent-2); }
  .tabs svg.lucide { width: 20px; height: 20px; }
  .dock { bottom: 84px; flex-wrap: wrap; justify-content: center; border-radius: 26px; overflow: visible; width: max-content; max-width: calc(100% - 16px); }
  .dock .seg button span { display: none; }
  .dock .seg.zoom { display: none; } /* di động: chụm 2 ngón để phóng to */
  .float-note { top: 62px; border-radius: var(--radius-md); font-size: 13px; padding: 8px 12px; width: max-content; max-width: calc(100% - 16px); line-height: 1.35; }
  .user { padding: 0 2px 0 4px; gap: 2px; }
  .user-av { width: 30px; height: 30px; }
  .sheet-grip { display: grid; place-items: center; position: sticky; top: calc(-1 * var(--space-lg)); height: 28px; margin: calc(-1 * var(--space-lg)) calc(-1 * var(--space-md)) 0; background: var(--color-surface); z-index: 2; touch-action: none; }
  .sheet-grip span { width: 44px; height: 5px; border-radius: 99px; background: var(--color-rule-2); }
  .sheet .prof-head { touch-action: pan-x; }
  .filters .seg { width: 100%; }
  .albums { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-sm); }
  .album b { font-size: 14.5px; overflow-wrap: anywhere; }
  .page-head .btn-primary { width: 100%; justify-content: center; }
  .filters .seg button { flex: 1; justify-content: center; }
  .sheet { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 88vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; transform: translateY(105%); padding-bottom: 96px; }
  .page { padding: 72px var(--space-sm) 110px; }
  .listview { padding: 64px var(--space-2xs) 150px; }
  .chat-wrap { padding: 64px var(--space-sm) 84px; }
  .toast { bottom: 150px; }
  .lightbox { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .lb-img { padding: var(--space-sm); }
  .lb-img img { max-height: 60vh; }
  .lb-side { max-height: 40vh; padding: var(--space-md) var(--space-sm); }
  .next-card { grid-template-columns: auto minmax(0, 1fr); }
  .next-card .pill { grid-column: 1 / -1; justify-self: start; }
  .row { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .row .av { display: none; }
  .row .info b { white-space: normal; }
  .next-card { gap: var(--space-sm); }
  .next-card .big { font-size: 40px; }
  .form-grid, .sub-grid { grid-template-columns: minmax(0, 1fr); }
}

/* vùng chạm tối thiểu ~40px cho ngón tay (kiểm thử điện thoại 14/10/2026) */
.search input { align-self: stretch; }
.back { min-height: 40px; }
.fam-tag { min-height: 36px; }
.user-me { min-height: 40px; min-width: 40px; justify-content: center; }
@media (max-width: 1100px) { .brand { min-height: 40px; min-width: 40px; justify-content: center; } }
@media (pointer: coarse) { .vc-kids { min-height: 38px; min-width: 52px; } }

/* ===== chế độ sửa cây (15/10/2026) ===== */
.edit-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; flex: none; white-space: nowrap;
  border: 1.5px solid var(--color-accent); border-radius: var(--radius-pill); background: var(--color-surface); color: var(--color-accent-2);
  font-size: var(--text-sm); font-weight: 600; transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.edit-toggle:hover { background: var(--color-accent-soft); }
.edit-toggle[aria-pressed="true"] { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-paper); }
.edit-toggle[aria-pressed="true"]:hover { background: var(--color-ink-2); }
.edit-toggle svg.lucide { width: 17px; height: 17px; }

.edit-bar {
  position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 14; max-width: calc(100% - 2 * var(--space-sm));
  display: flex; align-items: center; gap: var(--space-sm); padding: 6px 6px 6px 16px;
  background: var(--color-surface); border: 1.5px solid var(--color-accent); border-radius: var(--radius-pill); box-shadow: var(--shadow-lg);
}
.eb-state { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.eb-state b { font: 650 14px/1.2 var(--font-display); white-space: nowrap; }
.eb-state small { color: var(--color-ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); flex: none; align-self: center; box-shadow: 0 0 0 4px var(--color-accent-soft); animation: ebpulse 2s ease-in-out infinite; }
@keyframes ebpulse { 50% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .eb-dot { animation: none; } }
.eb-tools { display: flex; gap: 4px; flex: none; }
.eb-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 0; border-radius: var(--radius-pill);
  background: var(--color-paper-2); color: var(--color-ink); font-size: 13.5px; font-weight: 550; text-decoration: none; white-space: nowrap;
}
.eb-btn:hover:not(:disabled) { background: var(--color-paper-3); }
.eb-btn:disabled { opacity: .4; cursor: default; }
.eb-btn svg.lucide { width: 16px; height: 16px; }
.eb-help { width: 36px; padding: 0; justify-content: center; }

/* thẻ khi đang sửa: viền nét đứt màu nhấn, biết là chạm vào được */
body.editing .node.menu-on, body.editing .vcard.menu-on { outline: 3px solid var(--color-accent); outline-offset: 3px; }
body.editing .node:hover, body.editing .vcard:hover { outline: 2px solid color-mix(in oklch, var(--color-accent) 50%, transparent); outline-offset: 3px; }
.pm-head .av { flex: none; width: 38px; height: 38px; }
body.editing .vc-sp .nm { text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }

/* menu thao tác trên một người */
.pmenu {
  position: fixed; z-index: 60; width: 264px; padding: 6px; background: var(--color-surface);
  border: 1px solid var(--color-rule); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pmin var(--dur-fast) var(--ease-out);
}
@keyframes pmin { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.pm-head { display: flex; align-items: center; gap: 10px; padding: 8px 6px 10px 8px; border-bottom: 1px solid var(--color-rule); margin-bottom: 4px; }
.pm-head .pm-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pm-head b { font: 650 14.5px/1.25 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-head small { color: var(--color-ink-3); font-size: 12px; }
.pm-list { display: flex; flex-direction: column; }
.pm-list button {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--color-ink); font-size: 14px; text-align: left;
}
.pm-list button:hover, .pm-list button:focus-visible { background: var(--color-paper-2); outline: none; }
.pm-list button svg.lucide { width: 18px; height: 18px; color: var(--color-ink-3); }
.pm-list button.danger { color: var(--color-danger); margin-top: 4px; border-top: 1px solid var(--color-rule); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.pm-list button.danger svg.lucide { color: var(--color-danger); }

/* thông báo có nút Hoàn tác */
.toast.has-act { padding-right: 6px; }
.toast-act { margin-left: 8px; height: 32px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: oklch(100% 0 0 / 0.16); color: inherit; font-weight: 650; font-size: 13.5px; white-space: nowrap; }
.toast-act:hover { background: oklch(100% 0 0 / 0.26); }

.help-list { list-style: none; padding: 0; margin: 0 0 var(--space-sm); display: grid; gap: 12px; }
.help-list li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.5; }
.help-list svg.lucide { flex: none; width: 20px; height: 20px; margin-top: 2px; color: var(--color-accent-2); }
.mv-list { display: flex; flex-direction: column; gap: 2px; max-height: 46vh; overflow-y: auto; margin-top: var(--space-xs); }
.mv-list button { display: flex; align-items: center; gap: 10px; padding: 8px; border: 0; border-radius: var(--radius-sm); background: none; text-align: left; }
.mv-list button:hover { background: var(--color-paper-2); }
.mv-list .who { display: flex; flex-direction: column; min-width: 0; }
.mv-list small { color: var(--color-ink-3); font-size: 12.5px; }

@media (max-width: 1100px) {
  .edit-bar { top: 62px; padding: 6px 6px 6px 12px; gap: 8px; border-radius: var(--radius-md); width: calc(100% - 16px); }
  .eb-state { flex-direction: column; gap: 1px; flex: 1; }
  .eb-state .eb-dot { display: none; }
  .eb-state small { white-space: normal; font-size: 11.5px; line-height: 1.3; }
  .eb-btn span { display: none; }
  .eb-btn { width: 38px; padding: 0; justify-content: center; }
  .edit-toggle span { display: inline; }
}
/* điện thoại: menu thành khay trượt từ đáy */
@media (max-width: 700px) {
  /* khay nằm TRÊN thanh tab dưới đáy (z-index cao hơn), có lớp mờ phía sau */
  .pmenu { z-index: 95; left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; padding: 8px; border-radius: 20px; animation-name: pmup; box-shadow: 0 0 0 100vmax oklch(20% 0.02 258 / 0.28), var(--shadow-lg); }
  @keyframes pmup { from { transform: translateY(30px); opacity: 0; } }
  .pm-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .pm-list button { min-height: 48px; background: var(--color-paper); }
  .pm-list button.danger { grid-column: 1 / -1; border-top: 0; margin-top: 0; border-radius: var(--radius-sm); background: var(--color-danger-soft, oklch(96% 0.03 25)); justify-content: center; }
}

/* thanh "Đang sửa" không che đầu danh sách dọc */
body.editing .listview { padding-top: 150px; }
@media (max-width: 1100px) { body.editing .listview { padding-top: 136px; } }
/* thông báo căn giữa bằng left:50% chỉ co được tới nửa màn hình → đặt bề rộng theo nội dung */
.toast { width: max-content; max-width: min(560px, calc(100% - 24px)); }
.toast > span { min-width: 0; }

/* ===================================================================
   GIAO DIỆN TRANG NGHIÊM (16/10/2026) — header đầy đủ, gỗ lim + đồng + son
   =================================================================== */
h1, h2, h3 { letter-spacing: 0; font-weight: 600; }
body { font-size: var(--text-base); }
.btn { border-radius: var(--radius-sm); }
.btn-ghost { background: var(--color-surface); }
/* chữ số và chip nhỏ dùng phông không chân cho gọn */
.toggle, .node-kids, .vc-kids, .seg .dg, .cal-cell .sd, .node-gen, .vc-spine b, .eb-btn, .tabs button { font-family: var(--font-ui); }

/* ---------- header đầy đủ ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: var(--hdr);
  display: flex; align-items: center; gap: var(--space-md); padding: 0 var(--space-md);
  pointer-events: auto; color: var(--color-wood-ink);
  background-color: var(--color-wood);
  /* hoạ tiết mây cổ thật mờ + vân gỗ dọc */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='68' viewBox='0 0 120 68'%3E%3Cg fill='none' stroke='%23d9b46a' stroke-width='1.1' stroke-linecap='round' opacity='0.13'%3E%3Cpath d='M8 44c0-7 9-9 13-4 2-8 14-8 15 0 5-3 11 1 9 6H10c-2 0-2-1-2-2z'/%3E%3Cpath d='M18 40c1-3 5-3 6 0M30 38c1-3 5-3 6 0'/%3E%3Cpath d='M70 20c0-6 8-8 11-3 2-7 12-7 13 0 4-2 9 1 8 5H72c-1 0-2-1-2-2z'/%3E%3Cpath d='M79 17c1-2 4-2 5 0'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, oklch(100% 0 0 / 0.04), transparent 40%, oklch(0% 0 0 / 0.12));
  border-bottom: 1px solid var(--color-gold-deep);
  box-shadow: 0 2px 0 var(--color-wood), 0 3px 0 var(--color-gold-deep), 0 8px 18px oklch(20% 0.03 45 / 0.18);
}
.bar::before { display: none !important; }
.brand { gap: 12px; padding-right: 0; flex: none; }
.mark { width: 40px; height: 40px; }
.mark .m-seal { fill: var(--color-accent); }
.mark .m-ring { fill: none; stroke: var(--color-gold); stroke-width: 1.6; }
.mark path { stroke: oklch(92% 0.06 85); stroke-width: 2.2; }
.brand-txt b { font: 600 20px/1.1 var(--font-display); color: var(--color-wood-ink); letter-spacing: 0.01em; }
.brand-txt small { color: var(--color-wood-ink-2); font-size: 12px; letter-spacing: .02em; margin-top: 2px; }
.tabs { gap: 2px; padding: 0 0 0 var(--space-md); border-left: 1px solid oklch(100% 0 0 / 0.14); height: 100%; align-items: stretch; }
.tabs button {
  position: relative; height: 100%; padding: 0 16px; border-radius: 0; background: none;
  color: var(--color-wood-ink-2); font-size: 15px; font-weight: 500;
}
.tabs button:hover { background: oklch(100% 0 0 / 0.06); color: var(--color-wood-ink); }
.tabs button.on { background: none; color: var(--color-gold); font-weight: 600; }
.tabs button.on::after { content: ''; position: absolute; left: 14px; right: 14px; bottom: 10px; height: 2px; border-radius: 2px; background: var(--color-gold); }
.bar-right { gap: var(--space-xs); }
.search {
  width: 300px; height: 42px; background: oklch(100% 0 0 / 0.08); border: 1px solid oklch(100% 0 0 / 0.16);
  box-shadow: none; backdrop-filter: none; color: var(--color-wood-ink-2); border-radius: var(--radius-sm);
}
.search:focus-within { border-color: var(--color-gold); box-shadow: 0 0 0 3px oklch(72% 0.11 80 / 0.25); background: oklch(100% 0 0 / 0.12); }
.search input { color: var(--color-wood-ink); }
.search input::placeholder { color: var(--color-wood-ink-2); }
.kbd { background: oklch(100% 0 0 / 0.08); border-color: oklch(100% 0 0 / 0.18); color: var(--color-wood-ink-2); }
.bar #btn-login { height: 42px; box-shadow: none; background: transparent; border: 1px solid var(--color-gold-deep); color: var(--color-gold); }
.bar #btn-login:hover { background: oklch(72% 0.11 80 / 0.12); }
.user { height: 42px; background: transparent; border: 0; box-shadow: none; padding: 0; gap: 2px; }
.user-av { background: var(--color-gold); color: var(--color-wood); font-family: var(--font-display); }
.user-name { color: var(--color-wood-ink); }
.user-me:hover .user-name { color: var(--color-gold); }
.bar .icon-btn, .user a.icon-btn { color: var(--color-wood-ink-2); }
.bar .icon-btn:hover { background: oklch(100% 0 0 / 0.08); color: var(--color-wood-ink); }
.bar :focus-visible { outline-color: var(--color-gold); }
.pop { top: calc(100% + 10px); }
.pop button { color: var(--color-ink); }

/* ---------- nội dung bắt đầu ngay dưới header ---------- */
main { top: var(--hdr); }
.float-note, .edit-bar { top: 14px; }
.listview { padding-top: 20px; }
body.editing .listview { padding-top: 92px; }
.page { padding-top: var(--space-lg); }
.chat-wrap { padding-top: var(--space-md); height: 100%; }
.sheet { top: calc(var(--hdr) + 12px); }
.viewport { background: var(--color-paper); }

/* ---------- thẻ người: trang trọng hơn ---------- */
.node { border-radius: 12px; border-color: var(--color-rule-2); }
.node-band { border-radius: 11px 11px 0 0; }
.node.rank-to { border: 2px solid var(--color-gold-deep); box-shadow: 0 0 0 4px var(--color-gold-soft), var(--shadow-md); }
.vcard { border-radius: 10px; }
.node-name, .vc-name { font-family: var(--font-display); font-weight: 600; letter-spacing: 0; }
.prof-head h2 { font-family: var(--font-display); }
.dock { background: oklch(99% 0.006 85 / 0.94); border-color: var(--color-rule-2); }
.edit-toggle { border-radius: var(--radius-sm); }
.edit-toggle[aria-pressed="true"] { background: var(--color-wood); border-color: var(--color-wood); color: var(--color-wood-ink); }
.page-head h1, .chat-hello h1 { font-weight: 600; }

/* ---------- màn hình vừa: thu gọn để header không chồng lấn ---------- */
@media (max-width: 1320px) and (min-width: 1101px) {
  .bar { gap: var(--space-sm); padding: 0 var(--space-sm); }
  .search { width: 220px; }
  .tabs { padding-left: var(--space-sm); }
  .tabs button { padding: 0 12px; }
  .tabs svg.lucide { display: none; }
}

/* ---------- điện thoại / máy tính bảng ---------- */
@media (max-width: 1100px) {
  :root { --hdr: 56px; }
  .bar { top: 0; left: 0; right: 0; gap: var(--space-xs); padding: 0 var(--space-xs); box-shadow: 0 1px 0 var(--color-wood), 0 2px 0 var(--color-gold-deep), 0 6px 14px oklch(20% 0.03 45 / 0.16); }
  .mark { width: 36px; height: 36px; }
  .brand-txt { display: none; }
  .search { height: 40px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: auto; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border: 0; border-top: 1px solid var(--color-rule-2); background: var(--color-surface); backdrop-filter: none; justify-content: space-around;
    box-shadow: 0 -4px 16px oklch(26% 0.035 45 / 0.08);
  }
  .tabs button { flex: 1; min-width: 0; height: auto; padding: 6px 2px; gap: 2px; font-size: 12px; color: var(--color-ink-3); border-radius: var(--radius-md); }
  .tabs button:hover { background: var(--color-paper-2); color: var(--color-ink); }
  .tabs button.on { background: var(--color-gold-soft); color: var(--color-wood); }
  .tabs button.on::after { display: none; }
  .tabs svg.lucide { display: block; }
  .float-note, .edit-bar { top: 8px; }
  .listview { padding-top: 12px; }
  body.editing .listview { padding-top: 84px; }
  .page { padding-top: var(--space-md); }
  .chat-wrap { padding-top: var(--space-sm); height: 100%; }
  .sheet { top: auto; }
}

/* ===================================================================
   TÁI THIẾT KẾ (16/10/2026, lần 2): header gọn, menu tài khoản, trang chủ, hộp đăng nhập
   =================================================================== */
/* ---------- header gọn ---------- */
.bar { gap: var(--space-sm); padding: 0 var(--space-md); background-image: linear-gradient(180deg, oklch(100% 0 0 / 0.035), oklch(0% 0 0 / 0.1)); }
.mark { width: 34px; height: 34px; }
.brand-txt b { font-size: 18px; }
.tabs { padding-left: var(--space-sm); border-left-color: oklch(100% 0 0 / 0.12); }
.tabs button { padding: 0 13px; font-size: 14.5px; gap: 0; }
.tabs svg.lucide { display: none; }
.tabs button.on::after { bottom: 9px; left: 13px; right: 13px; }
.search { width: 210px; height: 36px; padding: 0 10px; transition: width var(--dur-short) var(--ease-out), background var(--dur-fast); }
.search:focus-within { width: 300px; }
.search svg.lucide { width: 16px; height: 16px; }
.login-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px 0 10px; border-radius: var(--radius-sm);
  border: 1px solid oklch(72% 0.11 80 / 0.55); background: transparent; color: var(--color-gold); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.login-btn:hover { background: oklch(72% 0.11 80 / 0.12); border-color: var(--color-gold); }
.login-btn svg.lucide { width: 18px; height: 18px; }
.user { position: relative; height: auto; }
.user-me { width: 40px; height: 40px; min-width: 0; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.user-me .user-av { width: 34px; height: 34px; font-size: 13px; box-shadow: 0 0 0 2px var(--color-wood), 0 0 0 3.5px oklch(72% 0.11 80 / 0.6); transition: box-shadow var(--dur-fast); }
.user-me:hover .user-av, .user-me[aria-expanded="true"] .user-av { box-shadow: 0 0 0 2px var(--color-wood), 0 0 0 3.5px var(--color-gold); }
.user-menu {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 40; width: 250px; padding: 6px;
  background: var(--color-surface); color: var(--color-ink); border: 1px solid var(--color-rule); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  animation: pmin var(--dur-fast) var(--ease-out);
}
.um-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--color-rule); }
.user-av.big { width: 40px; height: 40px; font-size: 15px; flex: none; }
.um-who { display: flex; flex-direction: column; min-width: 0; }
.um-who b { font: 600 15px/1.3 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-who small { color: var(--color-ink-3); font-size: 12.5px; }
.user-menu [role="menuitem"] {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--color-ink); font-size: 14px; text-decoration: none; text-align: left;
}
.user-menu [role="menuitem"]:hover, .user-menu [role="menuitem"]:focus-visible { background: var(--color-paper-2); outline: none; }
.user-menu [role="menuitem"] svg.lucide { width: 17px; height: 17px; color: var(--color-ink-3); }
.user-menu .danger { color: var(--color-danger); }
.user-menu .danger svg.lucide { color: var(--color-danger); }

/* ---------- hộp thoại: nút đóng, đăng nhập, tài khoản ---------- */
.modal-box { position: relative; }
.modal-x { position: absolute; top: 10px; right: 10px; }
.btn-lg { height: 48px; padding: 0 var(--space-md); font-size: 15.5px; }
.btn-block { width: 100%; justify-content: center; }
.auth { max-width: 380px; margin: 0 auto; padding: var(--space-xs) 0 var(--space-2xs); }
.auth-head { text-align: center; margin-bottom: var(--space-md); }
.auth-head .mark { width: 52px; height: 52px; margin: 0 auto var(--space-xs); display: block; }
.auth-head h3 { font-size: 26px; margin-bottom: 6px; }
.auth-head p { font-size: 14.5px; color: var(--color-ink-3); margin: 0 auto; max-width: 30ch; }
.auth-form { display: grid; gap: var(--space-sm); }
.auth-form .field { font-size: 13.5px; }
.inp { position: relative; display: flex; align-items: center; }
.inp > svg.lucide { position: absolute; left: 13px; width: 18px; height: 18px; color: var(--color-ink-3); pointer-events: none; }
.inp input { width: 100%; height: 48px; padding-left: 42px !important; font-size: 16px; }
.inp .eye { position: absolute; right: 4px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; color: var(--color-ink-3); border-radius: var(--radius-sm); }
.inp .eye:hover { color: var(--color-ink); background: var(--color-paper-2); }
.inp:has(.eye) input { padding-right: 46px !important; }
.auth-form .err { margin: -6px 0 0; text-align: center; }
.auth-demo { margin-top: var(--space-md); padding-top: var(--space-sm); border-top: 1px dashed var(--color-rule-2); text-align: center; }
.auth-demo > span { font-size: 12.5px; color: var(--color-ink-3); }
.auth-demo > div { display: flex; justify-content: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.auth-demo button { height: 34px; padding: 0 12px; border: 1px solid var(--color-rule); border-radius: var(--radius-pill); background: var(--color-paper); color: var(--color-ink-2); font-size: 13px; }
.auth-demo button:hover { border-color: var(--color-gold-deep); color: var(--color-ink); background: var(--color-gold-soft); }
.acct { padding-top: var(--space-2xs); }
.acct-head { display: flex; align-items: center; gap: var(--space-sm); padding-right: 40px; margin-bottom: var(--space-md); }
.user-av.xl { width: 60px; height: 60px; font-size: 21px; flex: none; }
.acct-head h3 { font-size: 22px; margin: 0 0 4px; }
.acct-head small { display: block; color: var(--color-ink-3); font-size: 13px; margin-top: 4px; }
.role-tag { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; background: var(--color-paper-2); color: var(--color-ink-2); }
.role-tag.r-admin { background: var(--color-accent-soft); color: var(--color-accent-2); }
.role-tag.r-editor { background: var(--color-gold-soft); color: var(--color-gold-ink); }
.acct-sec { padding: var(--space-sm) 0; border-top: 1px solid var(--color-rule); }
.acct-sec h4 { margin: 0 0 var(--space-xs); font: 600 12px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--color-ink-3); }
.acct-sec .btn { margin-top: var(--space-2xs); }
.acct-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 1px solid var(--color-rule); border-radius: var(--radius-md); background: var(--color-paper); text-align: left; }
.acct-row:hover { border-color: var(--color-rule-2); background: var(--color-paper-2); }
.acct-row > span:not(.av) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.acct-row b { font-weight: 600; }
.acct-row small { color: var(--color-ink-3); font-size: 12.5px; }
.acct-foot { display: flex; justify-content: space-between; gap: var(--space-2xs); padding-top: var(--space-sm); border-top: 1px solid var(--color-rule); }

/* ---------- trang chủ ---------- */
.home { padding: 0 0 var(--space-2xl); }
.hero {
  position: relative; padding: var(--space-xl) var(--space-sm) var(--space-lg); text-align: center; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 120%, oklch(72% 0.11 80 / 0.16), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='90' viewBox='0 0 180 90'%3E%3Cg fill='none' stroke='%23a8803a' stroke-width='1' stroke-linecap='round' opacity='0.16'%3E%3Cpath d='M12 60c0-9 12-12 17-5 3-10 19-10 20 0 6-4 14 1 12 8H15c-2 0-3-1-3-3z'/%3E%3Cpath d='M25 55c1-4 6-4 8 0M41 53c1-4 6-4 8 0'/%3E%3Cpath d='M105 28c0-8 11-10 15-4 3-9 17-9 18 0 5-3 12 1 11 7h-41c-2 0-3-1-3-3z'/%3E%3Cpath d='M117 24c1-3 5-3 6 0'/%3E%3C/g%3E%3C/svg%3E"),
    var(--color-paper);
  border-bottom: 1px solid var(--color-rule);
}
/* khung kiểu hoành phi: viền đồng kép, góc vát */
.hero-frame {
  position: relative; max-width: 760px; margin: 0 auto; padding: var(--space-lg) var(--space-md) var(--space-md);
  border: 1px solid var(--color-gold-deep); outline: 1px solid oklch(72% 0.11 80 / 0.45); outline-offset: 5px; border-radius: 4px;
  background: oklch(99% 0.008 85 / 0.75);
}
.eyebrow { margin: 0 0 var(--space-2xs); font: 600 12.5px var(--font-ui); letter-spacing: .22em; text-transform: uppercase; color: var(--color-gold-ink); }
.hero h1 { font: 700 clamp(2.1rem, 4.6vw + 0.6rem, 3.6rem)/1.1 var(--font-display); color: var(--color-wood); overflow-wrap: anywhere; min-width: 0; }
.hero-place { margin: var(--space-2xs) 0 0; color: var(--color-ink-2); font-size: var(--text-md); }
.hero-motto { display: flex; align-items: center; justify-content: center; gap: var(--space-xs); margin: var(--space-sm) 0 var(--space-md); }
.hero-motto b { font: 500 var(--text-lg) var(--font-display); color: var(--color-accent-2); }
.orn { width: 56px; height: 1px; background: linear-gradient(90deg, transparent, var(--color-gold-deep)); position: relative; }
.orn:last-child { transform: scaleX(-1); }
.orn::after { content: ''; position: absolute; right: -3px; top: -3px; width: 7px; height: 7px; transform: rotate(45deg); border: 1px solid var(--color-gold-deep); background: var(--color-paper); }
.hero-actions { display: flex; justify-content: center; gap: var(--space-xs); flex-wrap: wrap; }
.home-body { padding: var(--space-lg) var(--space-sm) 0; }
.home-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 var(--space-lg); border: 1px solid var(--color-rule); border-radius: var(--radius-md); background: var(--color-surface); }
.home-stats > div { padding: var(--space-sm) var(--space-md); display: flex; flex-direction: column-reverse; gap: 2px; }
.home-stats > div + div { border-left: 1px solid var(--color-rule); }
.home-stats dt { color: var(--color-ink-3); font-size: 13.5px; }
.home-stats dd { margin: 0; font: 600 34px/1.1 var(--font-display); color: var(--color-wood); font-variant-numeric: tabular-nums; }
.home-cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--space-lg); align-items: start; }
.home-intro h2, .home-card h2, .home-gens h2 { font-size: var(--text-lg); color: var(--color-wood); }
.home-intro h2 { margin-bottom: var(--space-xs); padding-bottom: var(--space-2xs); border-bottom: 1px solid var(--color-rule); }
.prose p { margin: 0 0 var(--space-xs); font-size: var(--text-md); line-height: 1.75; color: var(--color-ink-2); max-width: 62ch; }
.home-side { display: grid; gap: var(--space-md); }
.home-card { background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-md); padding: var(--space-sm); }
.hc-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-xs); margin-bottom: var(--space-2xs); }
.link-more { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--color-accent-2); font-size: 13.5px; font-weight: 600; white-space: nowrap; min-height: 36px; }
.link-more svg.lucide { width: 15px; height: 15px; }
.hc-list { display: flex; flex-direction: column; }
.hc-row { display: flex; align-items: center; gap: var(--space-xs); width: 100%; padding: 9px 4px; border: 0; border-top: 1px solid var(--color-rule); background: none; text-align: left; color: var(--color-ink); }
.hc-row:first-child { border-top: 0; }
.hc-row:hover { background: var(--color-paper); }
.hc-row > svg.lucide { color: var(--color-ink-3); }
.hc-date { width: 46px; flex: none; text-align: center; border: 1px solid var(--color-rule-2); border-radius: var(--radius-sm); padding: 3px 0; background: var(--color-paper); }
.hc-date b { display: block; font: 600 19px/1.1 var(--font-display); color: var(--color-accent-2); }
.hc-date small { display: block; font-size: 11px; color: var(--color-ink-3); }
.hc-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hc-who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-who small { color: var(--color-ink-3); font-size: 12.5px; }
.hc-soon { flex: none; font-size: 12.5px; font-weight: 600; color: var(--color-gold-ink); }
.home-gens { margin-top: var(--space-lg); background: var(--color-surface); border: 1px solid var(--color-rule); border-radius: var(--radius-md); padding: var(--space-sm) var(--space-md); }
.gen-bars { display: grid; gap: 8px; margin-top: var(--space-2xs); }
.gb { display: grid; grid-template-columns: 56px minmax(0, 1fr) 40px; align-items: center; gap: var(--space-xs); --g: var(--gen-1); }
.gb.g2 { --g: var(--gen-2); } .gb.g3 { --g: var(--gen-3); } .gb.g4 { --g: var(--gen-4); } .gb.g5 { --g: var(--gen-5); } .gb.g6 { --g: var(--gen-6); }
.gb-l { font-size: 13.5px; color: var(--color-ink-2); }
.gb-bar { height: 12px; border-radius: 3px; background: var(--color-paper-2); overflow: hidden; }
.gb-bar i { display: block; height: 100%; background: var(--g); border-radius: 3px; }
.gb-n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 1320px) and (min-width: 1101px) {
  .search { width: 170px; }
  .search:focus-within { width: 240px; }
  .tabs button { padding: 0 10px; }
}
@media (max-width: 1100px) {
  :root { --hdr: 54px; }
  .search, .search:focus-within { width: auto; flex: 1; height: 38px; }
  .tabs button { font-size: 11.5px; }
  .tabs svg.lucide { display: block; }
  .login-btn { height: 38px; padding: 0 10px; }
  .login-btn span { display: none; }
  .user-menu { position: fixed; top: calc(var(--hdr) + 6px); right: 8px; }
  .hero { padding: var(--space-md) var(--space-sm); }
  .hero-frame { padding: var(--space-md) var(--space-sm); outline-offset: 4px; }
  .hero-actions .btn { flex: 1 1 100%; justify-content: center; }
  .home-body { padding: var(--space-md) var(--space-sm) 120px; }
  .home-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-stats > div:nth-child(3) { border-left: 0; }
  .home-stats > div:nth-child(n+3) { border-top: 1px solid var(--color-rule); }
  .home-stats dd { font-size: 28px; }
  .home-cols { grid-template-columns: minmax(0, 1fr); gap: var(--space-md); }
  .home-gens { padding: var(--space-sm); }
  .acct-foot { flex-wrap: wrap; }
  .acct-foot .btn { flex: 1; justify-content: center; }
}
/* ô đang nhập: viền đồng (đỏ son chỉ dành cho lỗi / nút chính) */
.tag-pick input:focus, .field :is(input, select, textarea):focus, .row-form :is(input, select):focus, .cell:focus { border-color: var(--color-gold-deep); box-shadow: 0 0 0 3px oklch(72% 0.11 80 / 0.28); }
.composer:focus-within, .t-search:focus-within { border-color: var(--color-gold-deep); box-shadow: 0 0 0 3px oklch(72% 0.11 80 / 0.28), var(--shadow-md); }
a.btn { text-decoration: none; }
@media (max-width: 480px) { .orn { width: 22px; } .hero-motto b { font-size: var(--text-md); } }

/* nhãn vai trò trong họ — Đinh / Gái / Dâu / Rể (dùng chung trang chính + quản trị) */
.tg { display: inline-flex; align-items: center; height: 19px; padding: 0 7px; margin-right: 6px; border-radius: 4px; font: 650 11px/1 var(--font-ui); letter-spacing: .02em; vertical-align: 1px; white-space: nowrap; border: 1px solid transparent; }
.tg.t-dinh { background: oklch(93.5% 0.025 245); color: oklch(38% 0.08 245); border-color: oklch(84% 0.04 245); }
.tg.t-gai { background: oklch(94.5% 0.03 20); color: oklch(42% 0.12 20); border-color: oklch(85% 0.05 20); }
.tg.t-dau { background: oklch(95% 0.045 80); color: oklch(42% 0.09 65); border-color: oklch(84% 0.07 75); }
.tg.t-re { background: oklch(94% 0.03 155); color: oklch(38% 0.07 155); border-color: oklch(84% 0.04 155); }
.node-meta .tg { height: 17px; font-size: 10.5px; padding: 0 5px; margin-right: 5px; }
.pop .who b .tg { margin: 0 0 0 4px; }

/* bỏ dải màu dọc ở đầu thẻ (16/10/2026): số đời thành huy hiệu tròn nhỏ */
.vc-spine {
  align-self: center; width: 38px; height: 38px; margin: 0; border-radius: 50%; gap: 0;
  background: var(--gs); background-image: none; color: var(--g);
  box-shadow: inset 0 0 0 1.5px color-mix(in oklch, var(--g) 45%, transparent);
}
.vc-spine b { font: 600 16px/1 var(--font-ui); }
.vc-spine small { font-size: 7.5px; letter-spacing: .06em; margin-top: 1px; }
.vc-spine svg.lucide { width: 17px; height: 17px; }
.rank-to .vc-spine { background: var(--color-gold-soft); color: var(--color-gold-ink); box-shadow: inset 0 0 0 1.5px var(--color-gold-deep); }
.vcard { padding-left: 10px; border-radius: 12px; }
@media (max-width: 1100px) { .vc-spine { width: 34px; height: 34px; } .vc-spine b { font-size: 15px; } }
/* chọn vai trò trong form trang chính */
.role-row { border: 0; padding: 0; margin: 0; }
.role-row legend { padding: 0; margin-bottom: 6px; }
.req { color: var(--color-accent); }
.role-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.role-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1.5px solid var(--color-rule); border-radius: var(--radius-md); background: var(--color-surface); cursor: pointer; }
.role-chip input { position: absolute; opacity: 0; pointer-events: none; }
.role-chip .tg { margin: 0; height: 22px; font-size: 12.5px; }
.role-chip small { color: var(--color-ink-3); font-size: 12.5px; }
.role-chip:has(input:checked) { border-color: var(--color-gold-deep); background: var(--color-gold-soft); box-shadow: 0 0 0 3px oklch(72% 0.11 80 / 0.25); }
.role-chip:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 2px; }
