@import url("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap");

:root {
  --primary: #8f1d24;
  --primary-dark: #641219;
  --primary-light: #fbf1ed;
  --gold: #b58a3a;
  --text: #2f2925;
  --muted: #756c64;
  --border: #e8ddd1;
  --bg: #f7f3ed;
  --card: #fffdf9;
  --male: #356b91;
  --female: #a34c72;
  --ok: #2f7957;
  --danger: #b63b3b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background:
    radial-gradient(circle at 15% 0%, rgba(181,138,58,.07), transparent 28rem),
    linear-gradient(180deg, #fbf8f3 0%, var(--bg) 100%);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color .2s ease, background .2s ease, opacity .2s ease;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  background:
    linear-gradient(135deg, rgba(78,13,20,.98), rgba(143,29,36,.98));
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  box-shadow: 0 4px 18px rgba(68,25,15,.16);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(181,138,58,.55);
}

.topbar .brand {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  padding: 15px 0;
  letter-spacing: .2px;
  text-shadow: 0 1px 2px rgba(0,0,0,.18);
}

.topbar .brand:hover {
  text-decoration: none;
}

.topbar .brand .accent {
  color: #e5c56f;
}

.mainnav {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.mainnav a {
  color: rgba(255,255,255,.88);
  padding: 16px 13px;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.mainnav a:hover {
  color: #fff;
  text-decoration: none;
  background: rgba(255,255,255,.08);
}

.mainnav a.active {
  color: #fff;
  border-bottom-color: #e5c56f;
  background: rgba(255,255,255,.06);
}

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,.9);
  font-size: 14px;
  padding: 10px 0;
}

.userbox .role-badge {
  background: linear-gradient(135deg, #d6b35d, #a77a28);
  color: #3f2e09;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .4px;
  box-shadow: inset 0 1px rgba(255,255,255,.35);
}

.userbox a {
  color: #ffe2e0;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 30px 18px 64px;
}

.container.wide {
  max-width: 1400px;
}

.card {
  background: rgba(255,253,249,.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 22px;
  box-shadow:
    0 5px 18px rgba(74,48,27,.055),
    0 1px 2px rgba(74,48,27,.04);
}

.card h2,
.card h3 {
  margin-bottom: 14px;
  color: var(--primary-dark);
  font-family: "Playfair Display", Georgia, serif;
  letter-spacing: -.1px;
}

.page-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 29px;
  line-height: 1.25;
  color: var(--primary-dark);
  margin-bottom: 6px;
}

.page-sub {
  color: var(--muted);
  margin-bottom: 22px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.grid4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

@media (max-width: 800px) {
  .grid2,
  .grid3,
  .grid4 {
    grid-template-columns: 1fr;
  }
}

.stat {
  background: rgba(255,253,249,.98);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: 11px;
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(74,48,27,.045);
  transition: transform .2s ease, box-shadow .2s ease;
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(74,48,27,.08);
}

.stat .num {
  font-size: 29px;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.2;
}

.stat .label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
  color: #463c35;
}

.form-group .hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
}

input[type=text],
input[type=password],
input[type=email],
input[type=date],
input[type=number],
select,
textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid #d7cabe;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fffefa;
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

input[type=text]:hover,
input[type=password]:hover,
input[type=email]:hover,
input[type=date]:hover,
input[type=number]:hover,
select:hover,
textarea:hover {
  border-color: #c9b8a8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(143,29,36,.10);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .form-row,
  .form-row3 {
    grid-template-columns: 1fr;
  }
}

.btn {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), #a82b32);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 3px 8px rgba(101,18,25,.16);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.btn:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  text-decoration: none;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 5px 13px rgba(101,18,25,.2);
}

.btn.small {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: 7px;
}

.btn.gray {
  background: #817970;
  box-shadow: 0 3px 7px rgba(50,40,30,.12);
}

.btn.gray:hover {
  background: #68615a;
}

.btn.green {
  background: var(--ok);
}

.btn.green:hover {
  background: #276548;
}

.btn.red {
  background: var(--danger);
}

.btn.red:hover {
  background: #982e2e;
}

.btn.outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(143,29,36,.55);
  box-shadow: none;
}

.btn.outline:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
  box-shadow: none;
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fffefa;
  overflow: hidden;
}

table.data th {
  background: linear-gradient(180deg, #fcf4ed, #f8eee6);
  color: var(--primary-dark);
  text-align: left;
  padding: 11px 13px;
  font-size: 13.5px;
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data tr:hover td {
  background: #fffaf4;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fffefa;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
}

.badge.admin {
  background: #f9efd8;
  color: #815c0d;
}

.badge.member {
  background: #e8f1f8;
  color: #2c6389;
}

.badge.on {
  background: #e5f4eb;
  color: var(--ok);
}

.badge.off {
  background: #fbe8e8;
  color: var(--danger);
}

.badge.nam {
  background: #e8f1f8;
  color: var(--male);
}

.badge.nu {
  background: #f8e7ef;
  color: var(--female);
}

.badge.gio {
  background: #f9efd8;
  color: #815c0d;
}

.alert {
  padding: 13px 16px;
  border-radius: 9px;
  margin-bottom: 18px;
  font-size: 14.5px;
  border-width: 1px;
  border-style: solid;
}

.alert.success {
  background: #e8f5ed;
  color: #255f44;
  border-color: #bfe2cc;
}

.alert.error {
  background: #fbe9e9;
  color: #7e2929;
  border-color: #efc1c1;
}

.alert.info {
  background: #e9f1f8;
  color: #2b5277;
  border-color: #bfd5e8;
}

.auth-wrap {
  max-width: 450px;
  margin: 58px auto;
  padding: 0 18px;
}

.auth-card {
  background: rgba(255,253,249,.98);
  border: 1px solid var(--border);
  border-top: 5px solid var(--primary);
  border-radius: 15px;
  padding: 34px;
  box-shadow: 0 14px 42px rgba(63,37,20,.11);
}

.auth-card h1 {
  text-align: center;
  color: var(--primary-dark);
  font-family: "Playfair Display", Georgia, serif;
  font-size: 25px;
  margin-bottom: 5px;
}

.auth-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-links {
  text-align: center;
  margin-top: 17px;
  font-size: 14px;
  color: var(--muted);
}

.tree-scroller {
  overflow: auto;
  padding: 34px 14px;
  background:
    radial-gradient(circle at center, rgba(181,138,58,.055), transparent 38rem),
    #fffefa;
  border: 1px solid var(--border);
  border-radius: 13px;
  box-shadow: inset 0 1px rgba(255,255,255,.7);
}

/* [TREE_FIX_V1] Cây rộng hơn màn hình: cho khối cây nở theo nội dung để không bị cắt/che phần bên trái */
.tree {
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
}

.tree ul {
  padding-top: 26px;
  position: relative;
  display: flex;
  justify-content: center;
}

.tree li {
  list-style: none;
  text-align: center;
  position: relative;
  padding: 26px 7px 0;
}

.tree li::before,
.tree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  width: 50%;
  height: 26px;
  border-top: 2px solid #cbbda9;
}

.tree li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid #cbbda9;
}

.tree li:only-child::after,
.tree li:only-child::before {
  display: none;
}

.tree li:only-child {
  padding-top: 0;
}

.tree li:first-child::before,
.tree li:last-child::after {
  border: 0 none;
}

.tree li:last-child::before {
  border-right: 2px solid #cbbda9;
  border-radius: 0 7px 0 0;
}

.tree li:first-child::after {
  border-radius: 7px 0 0 0;
}

.tree ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid #cbbda9;
  width: 0;
  height: 26px;
}

.tree .node {
  display: inline-block;
  background: #fffefa;
  border: 2px solid var(--male);
  border-radius: 11px;
  padding: 9px 13px;
  min-width: 140px;
  position: relative;
  box-shadow: 0 4px 11px rgba(54,39,25,.09);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.tree .node:hover {
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(54,39,25,.14);
  transform: translateY(-2px);
}

.tree .node.nu {
  border-color: var(--female);
}

.tree .node.dead {
  background: #f5f0e8;
  opacity: .9;
}

.tree .node .nava {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 2px auto 5px;
  border: 2px solid #e4d8ca;
  background: #fff;
  box-shadow: 0 2px 6px rgba(50,35,20,.09);
}

.tree .node .nname {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.tree .node .nyears {
  font-size: 12px;
  color: var(--muted);
}

.tree .node .nspouse {
  font-size: 12px;
  color: var(--primary);
  margin-top: 2px;
}

.gen-label {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 5px;
  border: 1px solid rgba(143,29,36,.08);
}

.actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 17px;
}

.toolbar form {
  display: flex;
  gap: 8px;
}

.muted {
  color: var(--muted);
}

.text-center {
  text-align: center;
}

.mt-16 {
  margin-top: 16px;
}

.days-chip {
  display: inline-block;
  min-width: 70px;
  text-align: center;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid rgba(143,29,36,.08);
  border-radius: 8px;
  font-weight: 700;
  padding: 5px 10px;
  font-size: 13px;
}

.days-chip.today {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(101,18,25,.16);
}

footer.sitefooter {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 28px 0 34px;
  border-top: 1px solid rgba(232,221,209,.7);
  margin-top: 10px;
}

@media (max-width: 900px) {
  .topbar {
    padding: 0 16px;
  }

  .mainnav a {
    padding: 13px 10px;
    font-size: 14px;
  }

  .container {
    padding-top: 24px;
  }
}

@media (max-width: 620px) {
  .topbar {
    position: relative;
    display: block;
  }

  .topbar .brand {
    padding: 13px 0 8px;
  }

  .mainnav {
    overflow-x: auto;
    flex-wrap: nowrap;
    margin: 0 -4px;
    padding-bottom: 2px;
  }

  .mainnav a {
    flex: 0 0 auto;
    padding: 10px 9px;
    font-size: 13px;
  }

  .userbox {
    padding: 8px 0 12px;
  }

  .container {
    padding: 22px 12px 48px;
  }

  .card {
    padding: 18px;
    border-radius: 11px;
  }

  .page-title {
    font-size: 25px;
  }

  .auth-wrap {
    margin: 30px auto;
    padding: 0 12px;
  }

  .auth-card {
    padding: 25px 20px;
  }

  .toolbar form {
    width: 100%;
  }

  .toolbar form input,
  .toolbar form select {
    min-width: 0;
  }

  .tree-scroller {
    padding: 26px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
