/* =========================================================
   GIA PHẢ HỌ TRẦN — Phong cách sơn son thếp vàng, giấy dó
   ========================================================= */
:root {
  --paper: #f3e8cf;
  --paper-2: #ecdfc0;
  --surface: #fbf6ea;
  --surface-2: #f6eedb;
  --ink: #2a1a10;
  --muted: #6e5843;
  --faint: #9a8670;
  --red: #8b1a12;
  --red-2: #a3281b;
  --red-deep: #5a0e09;
  --gold: #b8892f;
  --gold-2: #d7ad55;
  --gold-light: #ecd08a;
  --jade: #2f6b4f;
  --danger: #a1261b;
  --line: rgba(105, 65, 25, 0.18);
  --line-strong: rgba(105, 65, 25, 0.32);
  --shadow-sm: 0 1px 2px rgba(60, 30, 10, .12);
  --shadow: 0 6px 18px -6px rgba(70, 30, 8, .28), 0 2px 4px rgba(70, 30, 8, .08);
  --shadow-lg: 0 24px 50px -18px rgba(70, 25, 5, .45), 0 8px 16px -8px rgba(70, 25, 5, .25);
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Playfair Display', 'Times New Roman', serif;
  --font-body: 'Be Vietnam Pro', 'Segoe UI', system-ui, sans-serif;
  --font-han: 'Noto Serif TC', 'PMingLiU', serif;
  --text-xs: .75rem; --text-sm: .875rem; --text-base: 1rem; --text-lg: 1.125rem; --text-xl: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --hoivan: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M2 2H22V22H6V6H18V18H10V10H14' fill='none' stroke='%23d7ad55' stroke-width='1.6'/%3E%3C/svg%3E");
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body { overscroll-behavior-y: none; } /* chặn kéo xuống ở đầu trang làm tải lại trang (pull-to-refresh) */
body {
  margin: 0; font-family: var(--font-body); color: var(--ink); font-size: var(--text-base); line-height: 1.55;
  background: var(--paper);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(201,154,59,.12), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img, video { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: #fff; padding: 8px 12px; border-radius: 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: rgba(139,26,18,.08); padding: 1px 6px; border-radius: 4px; }
.han { font-family: var(--font-han); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Nút & biểu mẫu ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: var(--text-sm);
  transition: transform .18s var(--ease), background .18s, box-shadow .18s, border-color .18s; white-space: nowrap;
}
.btn:hover { background: #fff; box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-red { background: linear-gradient(180deg, var(--red-2), var(--red)); color: #fbe9c2; border-color: var(--red-deep); }
.btn-red:hover { background: linear-gradient(180deg, #b1301f, var(--red-2)); }
.btn-gold { background: linear-gradient(180deg, #e7c46d, #c2923a); color: #3a1c06; border-color: #9a6c1f; box-shadow: inset 0 1px 0 rgba(255,255,255,.4); }
.btn-gold:hover { background: linear-gradient(180deg, #f0d184, #cc9c41); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(139,26,18,.06); box-shadow: none; }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: var(--text-xs); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.link { background: none; border: 0; padding: 0; color: var(--red); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.form { display: grid; gap: 14px; }
.form label, .field { display: grid; gap: 6px; font-size: var(--text-sm); font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: #fffdf7; color: var(--ink); font-weight: 400; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,59,.25); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--red); }
input[type=range] { padding: 0; min-height: 0; accent-color: var(--gold); border: 0; background: none; }
.form-error { color: var(--danger); font-size: var(--text-sm); margin: 0; min-height: 1.2em; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px; position: relative; overflow: hidden; }
.login-bg { position: absolute; inset: 0; background: url('../assets/temple.jpg') center / cover no-repeat; transform: scale(1.04); animation: drift 30s ease-in-out infinite alternate; }
.login-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(30,8,3,.35), rgba(30,8,3,.75)); }
@keyframes drift { to { transform: scale(1.1) translate(-1.5%, -1%); } }
.login-card {
  position: relative; width: min(440px, 100%); padding: 40px 32px 28px; border-radius: 18px; text-align: center;
  background: linear-gradient(180deg, rgba(251,246,234,.97), rgba(243,232,207,.97));
  border: 2px solid var(--gold); box-shadow: 0 30px 80px -20px rgba(0,0,0,.6), inset 0 0 0 6px rgba(251,246,234,.9), inset 0 0 0 7px rgba(139,26,18,.35);
  animation: rise .8s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.login-seal {
  width: 72px; height: 72px; margin: -76px auto 10px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--red-2), var(--red-deep)); color: var(--gold-light); font-family: var(--font-han); font-size: 40px;
  border: 3px solid var(--gold); box-shadow: var(--shadow-lg); transform: rotate(-4deg);
}
.login-han { font-family: var(--font-han); color: var(--gold); letter-spacing: .5em; margin: 6px 0 0; font-size: 1.1rem; padding-left: .5em; }
.login-title { font-family: var(--font-display); color: var(--red); font-size: clamp(1.9rem, 1.4rem + 2vw, 2.4rem); letter-spacing: .02em; }
.login-sub { color: var(--muted); margin: 8px 0 22px; font-size: var(--text-sm); }
.login .form { text-align: left; }
.login-switch { text-align: center; font-size: var(--text-sm); margin: 0; color: var(--muted); }
.demo-hint { display: grid; gap: 2px; font-size: var(--text-xs); color: var(--muted); background: rgba(201,154,59,.12); border: 1px dashed rgba(184,137,47,.6); border-radius: 10px; padding: 10px 12px; }
.demo-hint strong { color: var(--red); }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; color: #fbe9c2;
  background: linear-gradient(180deg, #7d150e, #5a0e09);
  box-shadow: 0 6px 20px -8px rgba(60,10,5,.6);
}
.topbar::after { content: ''; display: block; height: 10px; background: var(--hoivan) repeat-x center / 10px 10px, linear-gradient(#4a0b07, #4a0b07); border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold); }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: 10px 20px 6px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-seal { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-family: var(--font-han); font-size: 24px; color: #4a0b07; background: linear-gradient(160deg, #f0d184, #b8892f); border: 1px solid #f6e2a6; flex: none; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; letter-spacing: .02em; color: #f7e1a8; white-space: nowrap; }
.brand-sub { font-family: var(--font-han); font-size: .8rem; letter-spacing: .4em; color: var(--gold-2); }
.userbox { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(236,208,138,.35); color: #fbe9c2; border-radius: 999px; padding: 4px 12px 4px 4px; min-height: 40px; }
.user-btn:hover { background: rgba(255,255,255,.14); }
.user-name { font-size: var(--text-sm); font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 50; }
.user-menu-head { padding: 10px 12px; display: grid; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: var(--text-sm); }
.user-menu-head span { color: var(--muted); font-size: var(--text-xs); }
.user-menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; background: none; border: 0; border-radius: 8px; font-size: var(--text-sm); }
.user-menu button:hover { background: rgba(139,26,18,.07); }
.tabs { max-width: 1440px; margin: 0 auto; display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; background: none; border: 0; color: rgba(251,233,194,.78); padding: 10px 14px 12px; font-weight: 600; font-size: var(--text-sm); white-space: nowrap; border-radius: 8px 8px 0 0; transition: color .2s, background .2s;
}
.tabs button:hover { color: #fff3d0; background: rgba(255,255,255,.06); }
.tabs button.active { color: #3d1a04; background: linear-gradient(180deg, #f0d184, #c99a3b); }
.tab-ico { display: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Thanh tab ở đáy màn hình trên điện thoại */
@media (max-width: 760px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-width: none; margin: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 0;
    background: linear-gradient(180deg, #6b120c, #4a0b07);
    border-top: 2px solid var(--gold); box-shadow: 0 -8px 24px -10px rgba(40,8,4,.7);
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    /* Đẩy thanh tab lên lớp đồ hoạ riêng để Safari iOS không nhấp nháy / giật khi cuộn trang hoặc khi thanh địa chỉ co giãn */
    transform: translate3d(0, 0, 0); -webkit-transform: translate3d(0, 0, 0); -webkit-backface-visibility: hidden; backface-visibility: hidden; will-change: transform;
    touch-action: pan-x; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  }
  .tabs::before { content: ''; position: absolute; left: 0; right: 0; top: -6px; height: 4px; background: var(--hoivan) repeat-x center / 8px 8px; opacity: .9; pointer-events: none; }
  .tabs button {
    flex: 0 0 calc((100vw - 8px) / 5); min-width: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 6px 2px; border-radius: 12px; font-size: 11px; line-height: 1.1; color: rgba(251,233,194,.72);
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  .tabs button .tab-ico { display: block; }
  .tabs button.active { color: #3d1a04; background: linear-gradient(180deg, #f0d184, #c99a3b); box-shadow: 0 4px 10px -4px rgba(0,0,0,.5); }
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom)); }
}
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--gold-light); background: linear-gradient(160deg, var(--red-2), var(--red-deep)); border: 2px solid var(--gold); overflow: hidden; flex: none; font-family: var(--font-display); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; border-width: 1.5px; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; border-width: 3px; }
.avatar.nu { background: linear-gradient(160deg, #b0563c, #6d2414); }
.avatar.spouse { background: linear-gradient(160deg, #6d5a3f, #3e3021); }
.avatar.is-default { background: #e8d29f; }
.avatar.mat img { filter: sepia(.35) saturate(.85); }
.avatar.mat.is-default img { filter: sepia(.55) saturate(.8) brightness(.95); }
.chip-gio b { font-weight: 800; color: inherit; }
.card3d.deceased .chip-gio { background: rgba(240,209,132,.24); border-color: rgba(240,209,132,.7); color: #fff1c8; font-weight: 600; }
.gio-line { margin-top: 4px; font-size: 14px; color: #f7e1a8; }
.gio-line b { font-weight: 800; font-size: 15px; color: #ffe39a; letter-spacing: .01em; }
.gio-b { font-weight: 800; color: var(--red); }
.dc-side { display: grid; justify-items: center; gap: 8px; }
.avatar.dc-ava { width: 74px; height: 74px; border-width: 2px; box-shadow: 0 8px 14px -8px rgba(0,0,0,.6); }
.avatar.up-ava { width: 46px; height: 46px; }
.death-date .d { font-weight: 800; }

main { max-width: 1440px; margin: 0 auto; padding: 24px 20px 40px; min-height: calc(100dvh - 200px); outline: none; }
.view { display: none; animation: fade .35s var(--ease); }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.foot { text-align: center; color: var(--muted); font-size: var(--text-xs); padding: 18px 16px 28px; border-top: 1px solid var(--line); }

/* ---------- Tiêu đề trang ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 18px; }
.page-head h2 { font-family: var(--font-display); font-size: var(--text-xl); color: var(--red); display: flex; align-items: center; gap: 12px; }
.page-head h2 .han { font-size: .7em; color: var(--gold); letter-spacing: .25em; font-weight: 600; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: var(--text-sm); max-width: 70ch; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar select, .toolbar input { width: auto; min-height: 38px; padding: 6px 10px; font-size: var(--text-sm); }
.toolbar .search { min-width: 220px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: var(--text-xs); font-weight: 600; background: rgba(139,26,18,.08); color: var(--red); border: 1px solid rgba(139,26,18,.18); white-space: nowrap; }
.chip.gold { background: rgba(201,154,59,.16); color: #7a5512; border-color: rgba(184,137,47,.4); }
.chip.jade { background: rgba(47,107,79,.12); color: var(--jade); border-color: rgba(47,107,79,.3); }
.chip.ink { background: rgba(42,26,16,.08); color: var(--ink); border-color: var(--line); }
button.chip { cursor: pointer; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel-pad { padding: 18px; }
.panel-title { font-weight: 700; font-size: var(--text-lg); color: var(--red); margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .han { font-size: 2rem; color: var(--gold); display: block; margin-bottom: 8px; }
.ornament-rule { height: 12px; background: var(--hoivan) repeat-x center / 12px 12px; opacity: .55; margin: 8px 0 16px; filter: hue-rotate(-10deg) saturate(1.2) brightness(.7); }

/* ---------- Cây gia phả ---------- */
.tree-wrap { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line-strong); background: #e9dcbc; box-shadow: var(--shadow); height: min(76vh, 900px); min-height: 420px; touch-action: none; cursor: grab; }
.tree-wrap.dragging { cursor: grabbing; }
.tree-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.tree-canvas svg { display: block; }
.tree-canvas .gp-node:hover rect:first-child { filter: brightness(1.08) drop-shadow(0 4px 8px rgba(80,20,5,.35)); }
/* Thanh menu con của cây gia phả */
.tree-shell { position: relative; border-radius: 14px; border: 1px solid var(--line-strong); box-shadow: var(--shadow); background: #e9dcbc; }
.tree-shell .tree-wrap { border: 0; box-shadow: none; border-radius: 0 0 14px 14px; height: 70vh; min-height: 320px; }
.tree-bar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: linear-gradient(180deg, #fbf4e2, #f1e3c0); border-bottom: 1px solid var(--line-strong); border-radius: 14px 14px 0 0;
}
.tb-title { font-family: var(--font-display); font-size: 1.25rem; color: var(--red); margin: 0 6px 0 4px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.tb-title .han { font-size: .75em; color: var(--gold); letter-spacing: .2em; font-weight: 600; }
.tb-search { flex: 1 1 auto; min-width: 0; max-width: 380px; position: relative; display: flex; align-items: center; margin-right: auto; }
.tb-search svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.tb-search input { width: 100%; min-height: 38px; padding: 6px 12px 6px 34px; border-radius: 999px; font-size: var(--text-sm); }
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-zoom { padding-left: 8px; border-left: 1px solid var(--line-strong); }
.tb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 12px; border-radius: 10px;
  background: rgba(255,255,255,.65); border: 1px solid var(--line-strong); color: var(--ink); font-weight: 600; font-size: var(--text-sm); white-space: nowrap;
}
.tb-btn:hover { background: #fff; border-color: var(--gold); }
.tb-btn svg { width: 18px; height: 18px; flex: none; }
.tb-btn.sq { width: 38px; padding: 0; }
.tb-btn.gold { background: linear-gradient(180deg, #f0d184, #c99a3b); border-color: #b8892f; color: #3d1a04; }
.pop-menu { position: relative; }
.pop-panel {
  position: absolute; left: 0; top: calc(100% + 8px); z-index: 30; width: 320px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 14px; display: grid; gap: 12px;
}
.pop-panel.right { left: auto; right: 0; }
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pop-head h4 { margin: 0; font-size: var(--text-sm); color: var(--red); }
.pop-x { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: none; font-size: 18px; line-height: 1; color: var(--muted); }
.pop-panel .field select { width: 100%; }
.pop-panel .check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.exp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.exp-grid .btn { justify-content: center; width: 100%; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; }
.seg button { border: 0; background: none; border-radius: 8px; padding: 7px 8px; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--red); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
/* Toàn màn hình */
.tree-shell.full { position: fixed; inset: 0; z-index: 90; border-radius: 0; border: 0; }
.tree-shell.full .tree-bar { border-radius: 0; padding-top: calc(8px + env(safe-area-inset-top)); }
.tree-shell.full .tree-wrap { border-radius: 0; }
body.tree-fs { overflow: hidden; }
@media (max-width: 1024px) { .tb-title { display: none; } }
@media (max-width: 760px) {
  #view-tree { margin: -8px -4px 0; }
  .tree-bar { gap: 6px; padding: 6px; }
  .tb-search { max-width: none; }
  .tb-zoom { padding-left: 0; border-left: 0; }
  .tb-lbl, .hide-mob { display: none; }
  .tb-btn { width: 38px; padding: 0; }
  /* Bảng nổi dạng tấm trượt từ đáy lên */
  .pop-panel, .pop-panel.right {
    position: fixed; left: 8px; right: 8px; top: auto; width: auto; max-width: none;
    bottom: calc(84px + env(safe-area-inset-bottom)); max-height: calc(100dvh - 160px); overflow-y: auto;
    box-shadow: 0 0 0 100vmax rgba(30,8,4,.45), var(--shadow-lg); animation: sheet .22s var(--ease);
  }
  .tree-shell.full .pop-panel { bottom: calc(8px + env(safe-area-inset-bottom)); }
}
@keyframes sheet { from { transform: translateY(16px); opacity: 0; } }

/* ---------- Thẻ nổi 3D ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 22px; }
.card3d {
  --rx: 0deg; --ry: 0deg; position: relative; border-radius: 16px; padding: 18px 16px 16px; text-align: center; cursor: pointer;
  background: linear-gradient(165deg, #fffaf0 0%, #f7ecd3 100%);
  border: 1px solid rgba(184,137,47,.55);
  transform-style: preserve-3d; transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry)) translateZ(0);
  transition: transform .5s var(--ease), box-shadow .5s var(--ease);
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 10px 22px -12px rgba(80,30,5,.45), 0 2px 0 #e2cf9f, 0 4px 0 #d6bf88, 0 6px 14px -4px rgba(80,30,5,.3);
}
.card3d::before { content: ''; position: absolute; inset: 6px; border-radius: 11px; border: 1px solid rgba(139,26,18,.16); pointer-events: none; }
.card3d::after { content: ''; position: absolute; inset: 0; border-radius: 16px; background: radial-gradient(400px 200px at var(--mx, 50%) var(--my, 0%), rgba(255,255,255,.55), transparent 50%); opacity: 0; transition: opacity .3s; pointer-events: none; }
.card3d:hover { box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 30px 50px -18px rgba(80,25,5,.55), 0 2px 0 #e2cf9f, 0 4px 0 #d6bf88, 0 8px 0 #c9ae70; transition: transform .12s linear, box-shadow .4s var(--ease); }
.card3d:hover::after { opacity: 1; }
.card3d .lift { transform: translateZ(28px); }
.card3d .lift-sm { transform: translateZ(20px); }
.card3d.deceased { background: linear-gradient(165deg, #8f2016 0%, #5a0e09 100%); color: #f7e6b8; border-color: var(--gold); }
.card3d.deceased::before { border-color: rgba(236,208,138,.4); }
.card3d.deceased .muted { color: #e6cf9c; }
.card3d.deceased .chip { background: rgba(236,208,138,.15); color: var(--gold-light); border-color: rgba(236,208,138,.35); }
.card3d .avatar { margin: 0 auto 10px; width: 76px; height: 76px; font-size: 28px; box-shadow: 0 10px 18px -8px rgba(0,0,0,.5); }
.card3d h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 2px; }
.card3d .meta { font-size: var(--text-xs); }
.card3d .chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.card-corner { position: absolute; top: 10px; right: 12px; font-family: var(--font-han); font-size: 13px; color: var(--gold); opacity: .9; }
.card3d.deceased .card-corner { color: var(--gold-light); }

/* ---------- Lịch giỗ ---------- */
.death-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 22px; }
.death-card { text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 18px; align-items: start; }
.death-date { width: 74px; flex: none; border-radius: 12px; overflow: hidden; text-align: center; border: 1px solid var(--gold); background: #fffaf0; color: var(--ink); box-shadow: 0 8px 14px -8px rgba(0,0,0,.5); }
.death-date .m { background: linear-gradient(180deg, var(--red-2), var(--red-deep)); color: var(--gold-light); font-size: 11px; font-weight: 700; padding: 4px 0; letter-spacing: .05em; }
.death-date .d { font-family: var(--font-display); font-size: 30px; font-weight: 700; color: var(--red); line-height: 1.1; padding: 4px 0 0; }
.death-date .l { font-size: 10px; color: var(--muted); padding-bottom: 6px; }
.countdown { font-weight: 700; font-size: var(--text-sm); }
.countdown.soon { color: #ffd98a; }
.upcoming-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 26px; }
.upcoming-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: linear-gradient(90deg, rgba(201,154,59,.2), rgba(201,154,59,.04)); border: 1px solid rgba(184,137,47,.45); }
.upcoming-item .big { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; color: var(--red); min-width: 52px; text-align: center; line-height: 1; }
.upcoming-item .big small { display: block; font-family: var(--font-body); font-size: 10px; color: var(--muted); font-weight: 600; }

/* ---------- Từ đường ---------- */
.temple-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 22px; align-items: start; }
@media (max-width: 1024px) { .temple-grid { grid-template-columns: 1fr; } }
.altar { position: relative; aspect-ratio: 1214 / 1150; border-radius: 16px; overflow: hidden; background: #1b0704 url('../assets/altar.jpg') center 0 / cover no-repeat; border: 3px solid var(--gold); box-shadow: var(--shadow-lg), inset 0 0 120px rgba(0,0,0,.55); isolation: isolate; }
.altar::before { content: ''; position: absolute; inset: 0; background: radial-gradient(60% 50% at 50% 55%, transparent, rgba(10,2,0,.45)); pointer-events: none; z-index: 1; }
.altar-dim { position: absolute; inset: 0; background: rgba(10,2,0,.25); transition: opacity 2s; z-index: 1; pointer-events: none; }
.altar.lit .altar-dim { opacity: 0; }
.altar-glow { position: absolute; left: 50%; top: 60%; width: 70%; height: 50%; transform: translate(-50%, -50%); background: radial-gradient(closest-side, rgba(255,170,60,.35), transparent); opacity: 0; transition: opacity 2s; z-index: 2; pointer-events: none; mix-blend-mode: screen; }
.altar.lit .altar-glow { opacity: 1; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .7; } }
.flame-glow { position: absolute; width: 7%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(closest-side, rgba(255,200,90,.9), rgba(255,140,40,.25), transparent); mix-blend-mode: screen; z-index: 2; animation: flicker 1.6s infinite alternate; pointer-events: none; }
@keyframes flicker { 0% { opacity: .65; transform: scale(.92); } 40% { opacity: 1; transform: scale(1.06); } 70% { opacity: .8; } 100% { opacity: .95; transform: scale(1); } }
.bowl-wrap { position: absolute; left: 50%; bottom: 25.5%; width: 25%; transform: translateX(-50%); z-index: 4; }
.bowl-wrap svg { width: 100%; height: auto; overflow: visible; }
.incense-stick { transform-box: fill-box; transform-origin: 50% 100%; }
.stick-body { transform-box: fill-box; transform-origin: 50% 100%; }
.burning .stick-body { animation: burn var(--burn, 180s) linear forwards; }
@keyframes burn { to { transform: scaleY(.28); } }
.ember { opacity: 0; }
.burning .ember { opacity: 1; animation: ember 1.2s ease-in-out infinite alternate; }
@keyframes ember { to { filter: brightness(1.6); } }
.smoke { position: absolute; left: 50%; bottom: 90%; width: 60%; height: 320%; transform: translateX(-50%); z-index: 3; pointer-events: none; opacity: 0; transition: opacity 3s; }
.altar.burning .smoke { opacity: 1; }
.smoke span { position: absolute; bottom: 0; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(closest-side, rgba(235,230,220,.55), transparent); filter: blur(3px); animation: smoke 7s linear infinite; opacity: 0; }
@keyframes smoke {
  0% { transform: translate(0, 0) scale(.6); opacity: 0; }
  10% { opacity: .75; }
  50% { transform: translate(var(--dx, 12px), -45%) scale(2.2); opacity: .45; }
  100% { transform: translate(calc(var(--dx, 12px) * -1.2), -100%) scale(4); opacity: 0; }
}
.offerings { position: absolute; left: 0; right: 0; bottom: 27%; height: 14%; z-index: 4; pointer-events: none; }
.offering { position: absolute; bottom: 0; font-size: clamp(22px, 3.4vw, 40px); animation: place .9s var(--ease) both; filter: drop-shadow(0 6px 6px rgba(0,0,0,.5)); }
@keyframes place { from { opacity: 0; transform: translateY(-30px) scale(.8); } }
.altar-caption { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; padding: 40px 18px 16px; background: linear-gradient(transparent, rgba(20,4,1,.85)); color: #f7e1a8; text-align: center; font-size: var(--text-sm); }
.altar-caption strong { font-family: var(--font-display); font-size: 1.15rem; display: block; color: var(--gold-light); }
.altar-plaque { position: absolute; top: 3%; left: 50%; transform: translateX(-50%); z-index: 5; font-family: var(--font-han); color: var(--gold-light); font-size: clamp(16px, 2.6vw, 30px); letter-spacing: .5em; padding-left: .5em; text-shadow: 0 2px 6px rgba(0,0,0,.6); opacity: 0; }
.temple-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.temple-actions .btn { border-radius: 12px; min-height: 64px; flex-direction: column; gap: 4px; font-size: var(--text-xs); }
.temple-actions .btn .ico { font-size: 22px; line-height: 1; }
.temple-actions .btn-red.main { grid-column: 1 / -1; min-height: 56px; flex-direction: row; font-size: var(--text-base); }
.music-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: linear-gradient(90deg, #3b0a06, #5a0e09); color: #f7e1a8; }
.music-bar .eq { display: flex; gap: 3px; align-items: flex-end; height: 18px; }
.music-bar .eq i { width: 3px; background: var(--gold-light); border-radius: 2px; height: 30%; }
.music-bar.on .eq i { animation: eq 1.1s ease-in-out infinite alternate; }
.music-bar.on .eq i:nth-child(2) { animation-delay: .2s; } .music-bar.on .eq i:nth-child(3) { animation-delay: .4s; } .music-bar.on .eq i:nth-child(4) { animation-delay: .1s; }
@keyframes eq { to { height: 100%; } }
.music-bar input[type=range] { flex: 1; min-width: 60px; }
.music-opts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--text-xs); color: var(--muted); margin-top: 8px; }
.music-opts label { display: inline-flex; align-items: center; gap: 6px; }
.prayer { white-space: pre-wrap; font-size: var(--text-sm); line-height: 1.8; max-height: 300px; overflow: auto; padding: 14px 16px; background: #fffaf0; border-radius: 10px; border: 1px solid var(--line); font-family: var(--font-body); }
.log-list { display: grid; gap: 8px; max-height: 340px; overflow: auto; }
.log-item { display: flex; gap: 10px; align-items: flex-start; font-size: var(--text-sm); padding: 8px 10px; border-radius: 10px; background: #fffaf0; border: 1px solid var(--line); }
.log-item .ico { font-size: 18px; line-height: 1.2; }
.temple-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.temple-stats div { text-align: center; padding: 10px; border-radius: 10px; background: #fffaf0; border: 1px solid var(--line); }
.temple-stats b { display: block; font-family: var(--font-display); font-size: 1.4rem; color: var(--red); }
.temple-stats span { font-size: var(--text-xs); color: var(--muted); }

/* ---------- Xưng hô ---------- */
.kin-pick { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: end; }
@media (max-width: 560px) { .kin-pick { grid-template-columns: 1fr; } .kin-swap { justify-self: center; } }
.kin-result { display: grid; gap: 14px; margin-top: 18px; }
.kin-say { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; padding: 16px; border-radius: 14px; background: linear-gradient(135deg, #fffaf0, #f4e6c6); border: 1px solid rgba(184,137,47,.5); box-shadow: var(--shadow); }
.kin-say .term { font-family: var(--font-display); font-size: 1.5rem; color: var(--red); font-weight: 700; line-height: 1.2; }
.kin-path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--text-sm); }
.kin-path .arrow { color: var(--gold); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: rgba(201,154,59,.1); }
tr:hover td { background: rgba(255,255,255,.5); }
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); background: #fffdf7; }

/* ---------- Phả ký ---------- */
.forum-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
@media (max-width: 960px) { .forum-grid { grid-template-columns: 1fr; } .forum-side { order: -1; } }
.composer { padding: 16px; display: grid; gap: 10px; }
.composer textarea { min-height: 90px; }
.media-previews { display: flex; flex-wrap: wrap; gap: 8px; }
.media-previews .pv { position: relative; width: 96px; height: 96px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.media-previews .pv img, .media-previews .pv video { width: 100%; height: 100%; object-fit: cover; }
.media-previews .pv button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 14px; line-height: 1; }
.media-previews .pv .tag { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 1px 6px; border-radius: 4px; }
.progress { height: 6px; border-radius: 99px; background: var(--paper-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--red)); width: 0; transition: width .2s; }
.post { padding: 18px; display: grid; gap: 12px; }
.post + .post { margin-top: 16px; }
.post-head { display: flex; gap: 12px; align-items: center; }
.post-head .who { flex: 1; min-width: 0; }
.post-head .who strong { display: block; }
.post-head .who span { font-size: var(--text-xs); color: var(--muted); }
.post h3 { font-size: var(--text-lg); color: var(--red); }
.post .content { white-space: pre-wrap; font-size: .95rem; }
.post.pinned { border-color: rgba(184,137,47,.7); box-shadow: 0 0 0 3px rgba(201,154,59,.18), var(--shadow-sm); }
.media-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.media-grid > * { border-radius: 10px; overflow: hidden; background: #111; aspect-ratio: 4 / 3; }
.media-grid img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; transition: transform .4s var(--ease); }
.media-grid img:hover { transform: scale(1.04); }
.media-grid video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.media-grid.one { grid-template-columns: 1fr; }
.media-grid.one > * { aspect-ratio: auto; max-height: 520px; }
.media-grid.one img { object-fit: contain; max-height: 520px; background: #1a0b05; }
.post-actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 8px; }
.post-actions .btn.liked { color: var(--red); background: rgba(139,26,18,.08); }
.comments { display: grid; gap: 8px; }
.comment { display: flex; gap: 10px; align-items: flex-start; }
.comment .bubble { background: var(--surface-2); border: 1px solid var(--line); padding: 8px 12px; border-radius: 4px 14px 14px 14px; font-size: var(--text-sm); flex: 1; min-width: 0; }
.comment .bubble strong { font-size: var(--text-xs); color: var(--red); }
.comment-form { display: flex; gap: 8px; }
.comment-form input { min-height: 38px; }

/* ---------- Sự kiện & lịch ---------- */
.events-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 1100px) { .events-grid { grid-template-columns: 1fr; } }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-head h3 { font-family: var(--font-display); color: var(--red); font-size: 1.25rem; text-align: center; }
.cal-head h3 small { display: block; font-family: var(--font-body); font-size: var(--text-xs); color: var(--muted); font-weight: 500; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: var(--text-xs); font-weight: 700; color: var(--muted); padding: 6px 0; }
.cal .dow.sun { color: var(--red); }
.cal .day { position: relative; min-height: 78px; border-radius: 10px; padding: 6px 7px; background: #fffaf0; border: 1px solid var(--line); text-align: left; display: flex; flex-direction: column; gap: 2px; transition: transform .15s var(--ease), box-shadow .15s; }
.cal .day:hover { transform: translateY(-2px); box-shadow: var(--shadow); z-index: 1; }
.cal .day.out { opacity: .4; }
.cal .day.today { outline: 2px solid var(--red); outline-offset: -2px; }
.cal .day.sel { background: linear-gradient(160deg, #fff3d6, #f1dca5); border-color: var(--gold); box-shadow: var(--shadow); }
.cal .day .s { font-weight: 700; font-size: 1.05rem; line-height: 1; }
.cal .day.sun .s { color: var(--red); }
.cal .day .l { font-size: 11px; color: var(--muted); }
.cal .day .l.first { color: var(--red); font-weight: 700; }
.cal .day .marks { margin-top: auto; display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
.cal .day .dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.tot { background: var(--jade); } .dot.binh { background: var(--gold); } .dot.xau { background: #b4483a; }
.cal .day .hd { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold-2); box-shadow: 0 0 0 2px rgba(201,154,59,.25); }
.cal .day .ev { font-size: 10px; line-height: 1.25; color: #fff; background: var(--red); border-radius: 4px; padding: 1px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.cal .day .ev.gio { background: #6d5a3f; }
.cal.lv .day.lv-tot { background: linear-gradient(160deg, #f1f7ef, #e2efdf); border-color: rgba(47,107,79,.35); }
.cal.lv .day.lv-xau { background: linear-gradient(160deg, #fbf0ec, #f3dfd8); }
@media (max-width: 640px) { .cal .day { min-height: 58px; padding: 4px; } .cal .day .ev { display: none; } .cal .day .s { font-size: .95rem; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--text-xs); color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.day-detail { display: grid; gap: 12px; }
.day-detail .big-date { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.day-detail .bd { width: 92px; text-align: center; border-radius: 14px; overflow: hidden; border: 1px solid var(--gold); background: #fffaf0; box-shadow: var(--shadow); }
.day-detail .bd .m { background: linear-gradient(180deg, var(--red-2), var(--red-deep)); color: var(--gold-light); font-size: 12px; padding: 4px; font-weight: 700; }
.day-detail .bd .d { font-family: var(--font-display); font-size: 42px; color: var(--red); font-weight: 700; line-height: 1.1; }
.day-detail .bd .w { font-size: 11px; color: var(--muted); padding-bottom: 6px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: var(--text-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.verdict { padding: 12px 14px; border-radius: 12px; font-size: var(--text-sm); border: 1px solid; }
.verdict.tot { background: rgba(47,107,79,.1); border-color: rgba(47,107,79,.35); color: #1f4d38; }
.verdict.binh { background: rgba(201,154,59,.12); border-color: rgba(184,137,47,.4); color: #6b4a10; }
.verdict.xau { background: rgba(161,38,27,.08); border-color: rgba(161,38,27,.3); color: #7c1d14; }
.gio-list { display: flex; flex-wrap: wrap; gap: 6px; }
.event-item { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px; border-radius: 12px; background: #fffaf0; border: 1px solid var(--line); transition: box-shadow .2s, transform .2s var(--ease); }
.event-item:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.event-item + .event-item { margin-top: 10px; }
.event-item.past { opacity: .6; }
.event-item h4 { margin: 0; font-size: var(--text-base); }
.event-item p { margin: 2px 0 0; font-size: var(--text-xs); color: var(--muted); }
.good-days { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Thống kê ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { padding: 16px; border-radius: 14px; background: linear-gradient(160deg, #fffaf0, #f4e8cb); border: 1px solid rgba(184,137,47,.4); box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.kpi::after { content: attr(data-han); position: absolute; right: 10px; bottom: -6px; font-family: var(--font-han); font-size: 44px; color: rgba(184,137,47,.16); }
.kpi span { font-size: var(--text-xs); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi b { display: block; font-family: var(--font-display); font-size: 2rem; color: var(--red); line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi small { font-size: var(--text-xs); color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.charts .panel { padding: 16px; }
.charts .wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 280px; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }

/* ---------- Quản trị ---------- */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.subtabs button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: var(--text-sm); }
.subtabs button.active { background: var(--red); color: var(--gold-light); border-color: var(--red-deep); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.badge-pending { background: #fff1cf; color: #8a5a00; border: 1px solid #e9c46a; }

/* ---------- Hộp thoại ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(30,10,4,.55); backdrop-filter: blur(3px); animation: fadeIn .25s; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-box { position: relative; width: min(760px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; border: 2px solid var(--gold); box-shadow: 0 40px 80px -20px rgba(0,0,0,.6); padding: 26px; animation: pop .35s var(--ease); }
.modal-box.wide { width: min(980px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-x { position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; line-height: 1; z-index: 2; }
.modal h2 { font-family: var(--font-display); color: var(--red); font-size: var(--text-xl); margin-bottom: 4px; padding-right: 40px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.profile-head { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; margin-bottom: 16px; }
.profile-head .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.section-title { font-size: var(--text-sm); font-weight: 700; color: var(--red); text-transform: uppercase; letter-spacing: .08em; margin: 18px 0 8px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--gold), transparent); }
.person-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(10,4,2,.92); display: grid; place-items: center; padding: 20px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: calc(100dvh - 40px); border-radius: 8px; }
.lightbox .modal-x { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(440px, calc(100% - 24px)); }
.toast { background: #2a120a; color: #fbe9c2; border: 1px solid var(--gold); border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow-lg); font-size: var(--text-sm); animation: pop .3s var(--ease); }
.toast.err { background: #5a0e09; }
.toast a { color: var(--gold-light); font-weight: 700; }
.skeleton { background: linear-gradient(90deg, var(--paper-2), #f7efdc, var(--paper-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 640px) {
  main { padding: 16px 12px 32px; }
  .topbar-inner { padding: 8px 12px 4px; }
  .brand-title { font-size: 1.05rem; }
  .user-name { display: none; }
  .user-btn { padding: 4px; }
  .modal-box { padding: 20px 16px; }
  .kv { grid-template-columns: 110px 1fr; }
  .toolbar .search { min-width: 0; flex: 1 1 100%; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
  .card3d { padding: 14px 10px; }
  .card3d .avatar { width: 60px; height: 60px; font-size: 22px; }
  .tree-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea svg { width: 100%; height: auto; }
  @page { margin: 8mm; }
  .topbar, .foot, .toolbar, .tree-bar, .page-head { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .tree-wrap { height: auto; border: 0; box-shadow: none; overflow: visible; }
  .tree-canvas { position: static; transform: none !important; }
  .tree-canvas svg { width: 100% !important; height: auto !important; }
}

/* ---------- Ảnh nền từ đường cho toàn bộ các tab ---------- */
#app::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; transform: translateZ(0); -webkit-transform: translateZ(0);
  background:
    linear-gradient(180deg, rgba(248,240,222,.80) 0%, rgba(246,236,214,.74) 45%, rgba(240,226,196,.80) 100%),
    url('../assets/temple.jpg') center / cover no-repeat;
}
#app::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; transform: translateZ(0); -webkit-transform: translateZ(0);
  background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(90,30,10,.18) 100%);
}
.page-head p, .muted-count, #mCount { text-shadow: 0 1px 0 rgba(255,250,238,.7); }
.page-head p { color: #5a4636; }
.upcoming-item { background: linear-gradient(90deg, rgba(252,241,214,.94), rgba(251,246,234,.86)); }

/* ---------- Thanh chức năng cố định trong cửa sổ chi tiết ---------- */
.modal-box.with-bar { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.modal-box.with-bar > .modal-x { display: none; }
.modal-box.with-bar #modalBody { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 22px 26px 26px; }
.modal-bar {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 14px; z-index: 3;
  background: linear-gradient(180deg, #7d150e, #5a0e09); color: #fbe9c2; border-bottom: 2px solid var(--gold);
  box-shadow: 0 6px 14px -8px rgba(40,8,4,.6);
}
.mb-who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.mb-who > div { display: grid; min-width: 0; line-height: 1.25; }
.mb-who strong { font-size: 15px; color: #f7e1a8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-who small { font-size: 12px; color: #e6cf9c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-who small b { color: #ffe39a; font-weight: 800; }
.mb-who .avatar { border-color: var(--gold-light); }
.mb-acts { display: flex; gap: 6px; flex: none; }
.mb-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px; white-space: nowrap;
  background: rgba(255,255,255,.1); border: 1px solid rgba(236,208,138,.45); color: #fbe9c2; font-weight: 600; font-size: 13px;
}
.mb-btn:hover { background: rgba(255,255,255,.2); }
.mb-btn svg { width: 16px; height: 16px; flex: none; }
.mb-btn.gold, .mb-btn.red { background: linear-gradient(180deg, #f0d184, #c99a3b); border-color: #f6e2a6; color: #3d1a04; }
.mb-close { width: 36px; padding: 0; justify-content: center; font-size: 22px; line-height: 1; flex: none; }
.mb-back { flex: none; }
@media (max-width: 860px) { .mb-acts .mb-btn span { display: none; } .mb-acts .mb-btn { width: 36px; padding: 0; justify-content: center; } }
@media (max-width: 640px) {
  .modal { padding: 8px; }
  .modal-box.with-bar { max-height: calc(100dvh - 16px); }
  .modal-box.with-bar #modalBody { padding: 16px 14px 20px; }
  .modal-bar { flex-wrap: wrap; padding: 8px; row-gap: 8px; }
  .mb-back span { display: none; } .mb-back { width: 36px; padding: 0; justify-content: center; }
  /* Các nút chia đều một hàng; biểu tượng trên, chữ dưới để luôn vừa khung (kể cả khi có 4 nút) */
  .mb-acts { order: 3; width: 100%; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
  .mb-acts .mb-btn { width: auto; min-width: 0; min-height: 50px; padding: 5px 4px; border-radius: 12px; flex-direction: column; justify-content: center; gap: 3px; }
  .mb-acts .mb-btn svg { width: 18px; height: 18px; }
  .mb-acts .mb-btn span { display: block; max-width: 100%; font-size: 11.5px; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 640px) { .sp-table th:nth-child(4), .sp-table td:nth-child(4) { display: none; } .sp-table th, .sp-table td { padding: 8px 6px; font-size: 13px; } }

/* ---------- Chế độ khách & đăng nhập dạng lớp phủ ---------- */
.login.as-overlay { position: fixed; inset: 0; z-index: 150; overflow-y: auto; min-height: 0; align-items: start; padding-top: max(56px, 8vh); }
.login.as-overlay .login-bg { position: fixed; }
.login.as-overlay .login-bg::after { background: linear-gradient(180deg, rgba(30,8,3,.55), rgba(30,8,3,.82)); }
body.login-open { overflow: hidden; }
.login-x { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.6); color: var(--ink); font-size: 22px; line-height: 1; }
.login-x:hover { background: #fff; }
.btn-ghost-light { background: transparent; border: 1px solid rgba(139,26,18,.35); color: var(--red); }
.btn-ghost-light:hover { background: rgba(139,26,18,.06); }
.login-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 16px; border-radius: 999px; font-weight: 700; color: #3a1c06; background: linear-gradient(180deg, #e7c46d, #c2923a); border: 1px solid #f6e2a6; box-shadow: 0 2px 10px -3px rgba(0,0,0,.5); }
.login-btn:hover { filter: brightness(1.06); }
.login-btn[hidden], .user-btn[hidden] { display: none; }
.guest-cta { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; border-left: 4px solid var(--gold); }
.guest-cta p { margin: 4px 0 0; font-size: var(--text-sm); }
@media (max-width: 760px) {
  .login-btn span { display: none; }
  .login-btn { width: 40px; padding: 0; justify-content: center; }
  .guest-cta { flex-direction: column; align-items: stretch; }
}

/* ---------- Biên tập nhánh ---------- */
.branch-grant { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.bg-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 14px; background: linear-gradient(180deg, rgba(251,246,234,.96), rgba(243,232,207,.96)); border: 1px solid var(--gold); box-shadow: var(--shadow); }
.bg-item strong { display: block; color: var(--red); font-family: var(--font-display); }
.bg-item small { color: var(--muted); }
.branch-pick { display: grid; gap: 10px; padding: 12px; border-radius: 12px; background: rgba(201,154,59,.1); border: 1px dashed rgba(184,137,47,.6); }
.branch-pick[hidden] { display: none; }
.branch-pick p { margin: 0; font-size: 13px; }
.am-sub { display: none; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
@media (max-width: 760px) {
  .am-table th:nth-child(2), .am-table td:nth-child(2),
  .am-table th:nth-child(3), .am-table td:nth-child(3),
  .am-table th:nth-child(4), .am-table td:nth-child(4),
  .am-table th:nth-child(5), .am-table td:nth-child(5) { display: none; }
  .am-sub { display: block; }
  .am-table .row-actions { display: grid; grid-template-columns: repeat(2, auto); justify-content: end; gap: 4px; }
  .am-table td:last-child { width: 1%; }
}

/* ---------- Nút đóng rõ ràng cho bảng Xuất file / Hiển thị ---------- */
.pop-x.strong { width: auto; height: 34px; padding: 0 12px 0 10px; display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; border: 1px solid rgba(139,26,18,.35); background: rgba(139,26,18,.07); color: var(--red); font-size: 20px; font-weight: 700; flex: none; }
.pop-x.strong span { font-size: 13px; }
.pop-x.strong:hover { background: rgba(139,26,18,.14); }
.pop-back { justify-content: center; }
.pop-back svg { width: 16px; height: 16px; }
@media (min-width: 761px) { .pop-back { display: none; } }
@media (max-width: 760px) {
  .pop-head { position: sticky; top: -14px; margin: -14px -14px 0; padding: 12px 14px 10px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 1; border-radius: 14px 14px 0 0; }
}
/* Hộp kết quả xuất tệp */
.exp-done { display: grid; gap: 12px; }
.exp-prev { border: 1px solid var(--line); border-radius: 12px; background: var(--paper-2); padding: 8px; display: grid; place-items: center; max-height: 46vh; overflow: hidden; }
.exp-prev img { max-width: 100%; max-height: calc(46vh - 16px); object-fit: contain; }
.exp-file { width: 96px; height: 120px; border-radius: 8px; background: linear-gradient(160deg, var(--red-2), var(--red-deep)); display: grid; place-items: center; color: var(--gold-light); font-weight: 800; font-size: 22px; border: 2px solid var(--gold); }
.exp-acts { flex-wrap: wrap; }
.exp-acts .btn svg { width: 16px; height: 16px; }
@media (max-width: 760px) { .exp-acts { flex-direction: column-reverse; align-items: stretch; } .exp-acts .btn { justify-content: center; } }

/* ---------- Thanh menu con dính (tab Thành viên) ---------- */
.m-head { margin-bottom: 12px; }
.sub-bar {
  position: sticky; top: var(--topbar-h, 96px); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin: 0 0 18px;
  background: linear-gradient(180deg, rgba(251,244,226,.97), rgba(241,227,192,.97));
  border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow);
  transition: border-radius .2s, box-shadow .2s, margin .2s;
}
.sub-bar.stuck { border-radius: 0 0 14px 14px; border-top-color: transparent; box-shadow: 0 10px 24px -12px rgba(60,20,5,.55); }
.sub-bar .tb-search { max-width: 460px; }
.sb-count { font-size: 13px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.sb-count b { color: var(--red); font-size: 15px; }
.tb-btn { position: relative; }
.sb-badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-style: normal; font-weight: 700; display: grid; place-items: center; border: 2px solid #fbf4e2; }
.sb-badge[hidden], .sb-top[hidden] { display: none; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filter-grid .field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.filter-grid select { width: 100%; }
@media (max-width: 760px) {
  .sub-bar { gap: 6px; padding: 6px; margin-left: -4px; margin-right: -4px; }
  .sub-bar .tb-search { max-width: none; }
  .sb-cl { display: none; }
  .filter-grid { grid-template-columns: 1fr; }
}

/* ---------- Đăng ký thành viên ---------- */
.login-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: var(--text-sm); margin-top: 4px; }
.login-or::before, .login-or::after { content: ''; flex: 1; height: 1px; background: var(--line-strong); }
.reg-note { margin: 0; font-size: 13px; line-height: 1.45; }
#tabs [data-tab] { position: relative; }
.tab-badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #d4321f; color: #fff; font-size: 11px; font-style: normal; font-weight: 700; display: grid; place-items: center; border: 2px solid #f6e2a6; }
.tab-badge[hidden] { display: none; }

/* ---------- Đăng nhập trên điện thoại: không bị bàn phím che ---------- */
.login.as-overlay { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.login.as-overlay .login-card { margin-bottom: 24px; }
@media (max-width: 760px) {
  .login.as-overlay { padding: 52px 12px calc(32px + env(safe-area-inset-bottom)); }
  .login-card { padding: 34px 20px 22px; }
  .login-seal { width: 60px; height: 60px; font-size: 32px; margin-top: -64px; }
  .login-sub { margin: 6px 0 16px; }
  .login .form { gap: 12px; }
}
/* Khi bàn phím đang mở: gọn phần đầu khung để ô nhập và nút Đăng nhập nằm trong vùng nhìn thấy */
.login.as-overlay.kb { padding-top: 14px; padding-bottom: 50vh; }
.login.kb .login-seal, .login.kb .login-han, .login.kb .login-sub { display: none; }
.login.kb .login-card { padding-top: 18px; animation: none; }
.login.kb .login-title { font-size: 1.5rem; margin-bottom: 10px; }

/* ---------- Ảnh trang trí cây gia phả ---------- */
.deco-row { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.deco-row:first-child { border-top: 0; padding-top: 0; }
.deco-thumb { width: 76px; height: 76px; border-radius: 10px; border: 1px dashed var(--line-strong); background: var(--paper-2); display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.deco-thumb img { width: 100%; height: 100%; object-fit: contain; }
.deco-thumb svg { width: 26px; height: 26px; }
.deco-info { display: grid; gap: 3px; min-width: 0; align-content: start; font-size: 13px; }
.deco-info b { color: var(--red); font-size: 14px; }
.deco-info .faint { font-size: 12px; line-height: 1.35; }
.deco-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.deco-acts .btn { cursor: pointer; }
.deco-row.busy { opacity: .55; pointer-events: none; }
#tBgOp { width: 100%; accent-color: var(--red); }
#tDecoPop { max-height: min(78vh, 640px); overflow-y: auto; }

/* Nháy nhẹ khung thông tin ngày sau khi bấm chọn ngày trên lịch */
.day-detail.flash { animation: dayFlash 1s ease-out; }
@keyframes dayFlash { 0% { box-shadow: 0 0 0 3px rgba(201,154,59,.9), var(--shadow); } 100% { box-shadow: 0 0 0 3px rgba(201,154,59,0), var(--shadow); } }

/* ---------- Tab Xưng hô: một khung cố định vừa màn hình ---------- */
.kin-frame { display: flex; flex-direction: column; gap: 14px; max-width: 980px; margin: 0 auto; overflow: hidden; }
.kin-frame .kin-pick { flex: none; }
.kin-frame .kin-result { margin-top: 0; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; align-content: start; padding-right: 2px; }
.kin-says { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 760px) { .kin-says { grid-template-columns: 1fr; } }
body.kin-fit .foot { display: none; }
body.kin-fit main { padding-bottom: 0; min-height: 0; }
@media (max-width: 760px) { body.kin-fit { padding-bottom: 0; } }
@media (max-width: 760px) { #view-kinship .page-head p { display: none; } }

/* ---------- Trạng thái trống ---------- */
.tree-empty { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; gap: 10px; text-align: center; padding: 24px; }
.tree-empty[hidden] { display: none; }
.tree-empty .han { font-size: 54px; color: var(--gold); line-height: 1; }
.tree-empty h3 { margin: 0; color: var(--red); font-size: 20px; }
.tree-empty p { margin: 0; max-width: 420px; color: var(--muted); font-size: 14px; }
.btn-danger-solid { background: #a31d12; color: #fff; border: 0; }
.btn-danger-solid:hover:not(:disabled) { background: #861409; }
.btn-danger-solid:disabled { opacity: .5; cursor: not-allowed; }
.danger-zone { border-color: rgba(163,29,18,.35); }
