:root {
  --bg: #f6f2e9;
  --surface: #fffdf8;
  --surface-2: #f2eadc;
  --ink: #2b241e;
  --muted: #73675d;
  --line: #dfd3c2;
  --red: #8f221e;
  --red-dark: #681713;
  --gold: #c99a35;
  --gold-soft: #f2dfae;
  --green: #2f6d4f;
  --blue: #2d5874;
  --danger: #a22d2d;
  --shadow: 0 14px 40px rgba(73, 43, 17, .10);
  --radius: 18px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at top right, #fff8df 0, transparent 30%), var(--bg); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.55; }
a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-dark); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 74px; display: flex; align-items: center; gap: 24px; padding: 10px max(24px, calc((100vw - 1240px)/2)); background: rgba(255,253,248,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 260px; color: var(--ink); }
.brand-mark, .seal { display: grid; place-items: center; color: #f7e6b4; background: linear-gradient(145deg, var(--red), var(--red-dark)); border: 2px solid var(--gold); box-shadow: inset 0 0 0 3px rgba(255,255,255,.15); }
.brand-mark { width: 48px; height: 48px; border-radius: 50%; font-size: 26px; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; }
.main-nav { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.main-nav a, .link-button { padding: 9px 11px; border-radius: 10px; color: var(--ink); background: none; border: 0; }
.main-nav a:hover, .link-button:hover { background: var(--surface-2); }
.main-nav .nav-primary { color: white; background: var(--red); }
.logout-form { margin: 0; }
.page-shell { width: min(1240px, calc(100% - 32px)); min-height: calc(100vh - 150px); margin: 0 auto; padding: 34px 0 58px; }
.footer { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 20px 0 32px; border-top: 1px solid var(--line); color: var(--muted); display: flex; justify-content: space-between; gap: 20px; font-size: 13px; }
.hero { display: grid; grid-template-columns: 1.35fr .75fr; gap: 38px; align-items: center; padding: 44px 0 50px; }
.hero h1 { max-width: 780px; margin: 12px 0 20px; font-family: Georgia, serif; font-size: clamp(40px, 6vw, 72px); line-height: 1.03; letter-spacing: -.035em; }
.hero p { max-width: 760px; color: var(--muted); font-size: 19px; }
.hero-actions, .modal-actions, .response-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.heritage-card, .card, .stat-card, .auth-card, .suggestion-card { background: rgba(255,253,248,.95); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.heritage-card { padding: 28px; }
.seal { width: 76px; height: 76px; border-radius: 50%; font-size: 40px; margin-bottom: 20px; }
.heritage-card h2, .card h2 { margin-top: 0; font-family: Georgia, serif; }
.evidence-list, .clean-list { list-style: none; padding: 0; margin: 0; }
.evidence-list li { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.evidence-list li:last-child { border-bottom: 0; }
.evidence-list strong, .evidence-list span { display: block; }
.evidence-list span { color: var(--muted); font-size: 14px; }
.feature-grid, .stat-grid, .admin-menu, .suggestion-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.card { padding: 24px; }
.card p { color: var(--muted); }
.page-heading { margin-bottom: 26px; }
.page-heading h1 { margin: 6px 0 8px; font-family: Georgia, serif; font-size: clamp(32px, 4vw, 48px); line-height: 1.08; }
.page-heading p { max-width: 850px; margin: 0; color: var(--muted); }
.split-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.eyebrow { color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.content-narrow { width: min(880px, 100%); margin: 0 auto; }
.auth-wrap { min-height: 68vh; display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); padding: 34px; }
.auth-card h1 { font-family: Georgia, serif; font-size: 40px; margin: 5px 0 18px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 18px; font-size: 14px; }
.form-stack { display: grid; gap: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.form-grid h2 { margin-bottom: 0; }
.span-2 { grid-column: 1 / -1; }
label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
label small, td small { display: block; color: var(--muted); font-weight: 400; }
input, select, textarea { width: 100%; border: 1px solid #cfc0ad; border-radius: 11px; padding: 11px 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,53,.18); }
textarea { resize: vertical; }
.check-row { grid-template-columns: 22px 1fr; align-items: start; font-weight: 500; }
.check-row input { width: 18px; height: 18px; margin-top: 3px; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 43px; padding: 10px 17px; border-radius: 11px; border: 1px solid transparent; font-weight: 800; }
.button.primary { color: white; background: linear-gradient(135deg, var(--red), var(--red-dark)); }
.button.ghost { color: var(--red); background: var(--surface); border-color: var(--line); }
.button.danger { color: white; background: var(--danger); }
.button.small { min-height: 34px; padding: 7px 11px; font-size: 13px; }
.button.full { width: 100%; }
.alert { margin-bottom: 20px; padding: 13px 16px; border-radius: 12px; border: 1px solid; }
.alert.success { color: #194d34; background: #e9f7ef; border-color: #b6dec7; }
.alert.error, .field-error { color: #7b1e1e; background: #fff0ef; border-color: #ecc0bd; }
.field-error { margin-top: 2px; padding: 5px 8px; border-radius: 7px; font-size: 12px; font-weight: 600; }
.privacy-note { padding: 13px 15px; color: #5c4a2f; background: #fff6dc; border: 1px solid #ead49a; border-radius: 11px; }
.stat-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; }
.stat-card { padding: 20px; display: grid; gap: 3px; }
.stat-card strong { font-family: Georgia, serif; font-size: 34px; color: var(--red); }
.stat-card span { color: var(--muted); }
.stat-card a { margin-top: 8px; font-weight: 700; }
.two-column, .compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 20px; margin-top: 20px; }
.clean-list li { position: relative; padding: 8px 0 8px 22px; }
.clean-list li::before { content: "◆"; position: absolute; left: 0; top: 9px; color: var(--gold); font-size: 10px; }
.clean-list.numbered { counter-reset: item; }
.clean-list.numbered li { counter-increment: item; padding-left: 32px; }
.clean-list.numbered li::before { content: counter(item); width: 22px; height: 22px; display: grid; place-items: center; color: white; background: var(--red); border-radius: 50%; font-size: 11px; }
.badge, .mini-badge, .evidence { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 11px; font-weight: 800; white-space: nowrap; background: var(--surface-2); }
.badge.verified, .badge.approved, .badge.finalized { color: #195238; background: #dff2e6; }
.badge.pending, .badge.reviewing, .badge.admin_review { color: #725115; background: #fff0c8; }
.badge.branch_head { color: #69400a; background: #f4dda3; }
.badge.rejected { color: #7b1e1e; background: #fae1df; }
.evidence.historical_confirmed { color: #174d34; background: #dff2e6; }
.evidence.genealogy_tradition { color: #6e4a0f; background: #f5e4b8; }
.evidence.hypothesis { color: #27506a; background: #dfedf5; }
.evidence.unverified { color: #6f6258; background: #eee9e2; }
.danger-zone { margin-top: 28px; padding-top: 20px; border-top: 1px solid #efc4c4; }
.danger-text { color: var(--danger); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.tree-toolbar { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 16px; }
.tree-browser { min-height: 260px; padding: 22px; background: linear-gradient(90deg, rgba(201,154,53,.07) 1px, transparent 1px), var(--surface); background-size: 28px 28px; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.tree-loading, .empty-state { padding: 30px; text-align: center; color: var(--muted); }
.tree-node { min-width: 420px; }
.tree-node-row { display: flex; align-items: center; gap: 9px; padding: 6px 0; }
.folder-toggle, .icon-button { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--red); font-weight: 900; }
.person-chip { min-width: 330px; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 4px 14px rgba(60,35,15,.06); }
.person-chip.root { border-color: var(--gold); background: #fff8e7; }
.person-chip strong, .person-chip small { display: block; }
.person-chip small { color: var(--muted); }
.person-chip .evidence { margin-left: auto; }
.gender-icon { width: 28px; height: 28px; display: grid; place-items: center; color: white; background: var(--red); border-radius: 50%; }
.tree-node-children { margin-left: 48px; padding-left: 16px; border-left: 1px dashed #cbb897; }
.relation-group h4 { margin: 8px 0 4px; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.relation-items { display: grid; gap: 1px; }
.modal { width: min(760px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 30px 90px rgba(30,20,10,.3); }
.modal::backdrop { background: rgba(31,24,19,.55); backdrop-filter: blur(3px); }
.modal form { padding: 25px; }
.modal-head { display: flex; justify-content: space-between; align-items: start; }
.modal-head h2 { margin: 4px 0; }
.modal-actions { justify-content: flex-end; }
.table-card { margin-top: 20px; padding: 0; overflow: hidden; }
.table-card h2 { padding: 22px 24px 0; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 13px 16px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
th { color: var(--muted); background: #faf5eb; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.mini-badge { margin-left: 7px; color: var(--red); background: var(--gold-soft); }
.row-actions { display: flex; align-items: center; gap: 4px; }
.suggestion-grid { grid-template-columns: repeat(2, 1fr); }
.suggestion-card { display: flex; gap: 16px; padding: 20px; }
.score-ring { flex: 0 0 68px; height: 68px; display: grid; place-items: center; align-content: center; border: 5px solid var(--gold-soft); outline: 1px solid var(--gold); border-radius: 50%; }
.score-ring strong { font-size: 21px; color: var(--red); line-height: 1; }
.score-ring span { font-size: 10px; color: var(--muted); }
.suggestion-body { flex: 1; }
.suggestion-body h3 { margin: 0 0 4px; }
.suggestion-body p { margin: 0 0 8px; color: var(--muted); }
.reason-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.reason-row span { padding: 3px 8px; border-radius: 999px; background: var(--surface-2); font-size: 11px; }
.inline-request { display: flex; gap: 8px; }
.inline-request input { min-width: 0; }
.preview-card h3 { margin-bottom: 14px; }
.preview-card h3 small { color: var(--muted); font-weight: 400; }
.card-head { display: flex; justify-content: space-between; gap: 12px; }
.preview-rel { display: grid; grid-template-columns: 100px 1fr; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.preview-rel span { color: var(--muted); }
.chat-log { max-height: 420px; overflow: auto; display: grid; gap: 10px; padding: 4px; }
.chat-message { max-width: 88%; padding: 10px 12px; border-radius: 13px 13px 13px 3px; background: var(--surface-2); }
.chat-message.mine { margin-left: auto; border-radius: 13px 13px 3px 13px; background: #f5e4b8; }
.chat-message p { margin: 4px 0; color: var(--ink); }
.chat-message small { color: var(--muted); }
.chat-form { display: grid; gap: 8px; margin-top: 14px; }
.admin-menu { margin-top: 20px; }
.admin-menu a { color: var(--ink); }
.admin-menu a:hover { transform: translateY(-2px); transition: .18s ease; }
.compact-form { display: flex; gap: 7px; align-items: center; min-width: 430px; }
.compact-form.vertical { min-width: 220px; flex-wrap: wrap; }
.compact-form.vertical input { flex-basis: 100%; }
code { font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.error-page { min-height: 100vh; display: grid; place-items: center; align-content: center; text-align: center; gap: 12px; padding: 24px; }
.error-page .seal { margin: 0 auto; }
.error-page h1 { font-family: Georgia, serif; font-size: 40px; margin: 8px 0 0; }
@media (max-width: 980px) {
  .topbar { position: static; flex-wrap: wrap; }
  .brand { min-width: auto; }
  .main-nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .hero, .two-column, .compare-grid { grid-template-columns: 1fr; }
  .feature-grid, .admin-menu { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .suggestion-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page-shell { width: min(100% - 20px, 1240px); padding-top: 22px; }
  .topbar { padding: 10px; gap: 8px; }
  .brand small { display: none; }
  .hero { padding-top: 20px; }
  .feature-grid, .stat-grid, .admin-menu, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .split-heading, .tree-toolbar, .footer { align-items: stretch; flex-direction: column; }
  .person-chip { min-width: 260px; }
  .tree-node { min-width: 350px; }
  .inline-request { flex-direction: column; }
  .auth-card, .card { padding: 20px; }
}

/* 1.0.0-r1: các thành viên cùng thế hệ hiển thị trên một hàng ngang. */
.tree-generation-row {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  width: max-content;
  min-width: 100%;
}
.tree-root-generation { padding-bottom: 8px; }
.tree-generation-row > .tree-node { min-width: 420px; flex: 0 0 auto; }
.relation-group { margin-top: 12px; }
.relation-group > .tree-generation-row { min-width: max-content; }
.relation-items { display: flex; gap: 18px; }
.tree-node-children { min-width: max-content; }
@media (max-width: 720px) {
  .tree-generation-row { gap: 12px; }
  .tree-generation-row > .tree-node { min-width: 350px; }
}
