:root {
  --paper: #f7f7f2;
  --surface: #ffffff;
  --surface-strong: #eef5f1;
  --ink: #252422;
  --muted: #6f6b63;
  --line: #d8d7cf;
  --teal: #0f5f5c;
  --teal-soft: #d8ebe5;
  --rust: #d85a3a;
  --gold: #f2b84b;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(37, 36, 34, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15, 95, 92, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(216, 90, 58, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 44px 44px;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

img {
  max-width: 100%;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 42px);
  border-bottom: 1px solid rgba(37, 36, 34, 0.1);
  background: rgba(247, 247, 242, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: max-content;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--rust));
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand small {
  color: var(--muted);
  margin-top: 3px;
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--muted);
  font-weight: 700;
}

.user-pill,
.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  font-size: 0.88rem;
  font-weight: 700;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.button.primary {
  color: #fff;
  background: var(--teal);
}

.button.secondary {
  color: var(--teal);
  border-color: rgba(15, 95, 92, 0.28);
  background: var(--teal-soft);
}

.button.ghost {
  color: var(--muted);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.7);
}

.button.danger {
  color: #fff;
  background: var(--danger);
}

.button.small {
  min-height: 34px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.button.wide {
  width: 100%;
}

.flash {
  width: min(1100px, calc(100% - 36px));
  margin: 16px auto 0;
  padding: 12px 16px;
  border: 1px solid rgba(15, 95, 92, 0.2);
  border-radius: 8px;
  color: var(--teal);
  background: var(--teal-soft);
  font-weight: 800;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 28px clamp(18px, 4vw, 42px);
  color: var(--muted);
  font-size: 0.9rem;
}

.login-page,
.page {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 140px);
  padding: clamp(24px, 6vw, 72px);
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1fr);
  width: min(900px, 100%);
  overflow: hidden;
  border: 1px solid rgba(37, 36, 34, 0.12);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-copy {
  min-height: 440px;
  padding: clamp(30px, 5vw, 56px);
  color: #fff;
  background:
    linear-gradient(135deg, rgba(15, 95, 92, 0.94), rgba(216, 90, 58, 0.82)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 1px, transparent 1px 18px);
}

.login-copy h1 {
  margin: 8px 0 0;
  font-size: clamp(2rem, 5vw, 4rem);
}

.form-stack,
.admin-form {
  display: grid;
  gap: 18px;
  padding: clamp(24px, 4vw, 42px);
}

.form-stack {
  align-content: center;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 95, 92, 0.13);
}

.form-error {
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--danger);
  background: #fff0ed;
  font-weight: 800;
}

.field-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.field-hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(37, 36, 34, 0.07);
  font-size: 0.75rem;
}

.eyebrow {
  margin: 0;
  color: var(--rust);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tree-page {
  padding: clamp(18px, 3vw, 34px);
}

.tree-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 18px;
  width: min(1420px, 100%);
}

.tree-toolbar h1,
.section-heading h1,
.message-panel h1 {
  margin: 6px 0 0;
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1.05;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-actions input {
  width: min(280px, 52vw);
}

/* Panel ho so co dinh da bo: no an mat 320px chieu ngang cua cay. Ho so gio hien
   trong hop noi khi bam vao thanh vien. */
.tree-workspace {
  display: block;
  width: min(1760px, 100%);
  margin: 0 auto;
}

/* Cao theo man hinh chu khong co dinh 620px: man hinh cang lon thi cay cang thoang,
   khong con bi bo trong mot khung chat. */
.tree-canvas {
  position: relative;
  height: calc(100vh - 230px);
  min-height: 520px;
  overflow: auto;
  border: 1px solid rgba(37, 36, 34, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
}

/* Vung cuon co kich thuoc = kich thuoc that cua cay **nhan voi ty le zoom**, de thanh
   cuon dai dung. `transform: scale()` khong lam thay doi kich thuoc layout, nen neu
   khong co lop nay thi phong to xong se khong cuon toi phan tran ra ngoai. */
.tree-viewport {
  position: relative;
  margin: 0 auto;
}

.tree-stage {
  position: relative;
  transform-origin: 0 0;
}

#tree-links {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.tree-canvas.panning {
  cursor: grabbing;
  user-select: none;
}

.tree-hint {
  position: sticky;
  bottom: 0;
  left: 0;
  z-index: 4;
  margin: 0;
  padding: 6px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.86);
  font-size: 0.74rem;
  font-weight: 600;
  pointer-events: none;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.zoom-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.zoom-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.zoom-level {
  min-width: 48px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

/* `width: max-content`: board rong dung bang hang rong nhat. Khong dat `min-width: 100%`
   nua - board gio nam trong `.tree-stage`, ma kich thuoc stage lai duoc tinh tu board,
   nen `100%` se thanh phu thuoc vong. Cay hep hon khung thi `.tree-viewport` tu can giua. */
.tree-board {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 96px;
  width: max-content;
  padding: 42px 34px 58px;
}

.generation-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.generation-label {
  position: sticky;
  left: 16px;
  z-index: 3;
  display: inline-flex;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--teal);
  background: var(--teal-soft);
  font-size: 0.82rem;
  font-weight: 900;
}

.generation-members {
  display: flex;
  justify-content: center;
  gap: 84px;
  min-height: 148px;
  flex-wrap: nowrap;
}

/* Vo chong (ke ca con dau, con re) dung sat nhau thanh mot khoi; khoang cach
   giua cac gia dinh rong hon de nhin ra ranh gioi tung nhanh.
   Khe ho giua hai vo chong phai du rong: duong net dut noi ho duoc ke trong khe nay,
   va truc doc xuong con cung di xuyen qua chinh giua no. */
.family-unit {
  display: flex;
  align-items: stretch;
  gap: 26px;
}

/* Cha me cua nguoi ket hon vao dong ho (gia dinh ben vo / ben chong). Ho la mot
   nhanh khac han, khong phai con chau cua cay nay - tach xa them de duong noi cua
   ho khong bi doc lan voi duong noi cua nhanh chinh.
   Khong dung `margin`: layout dinh vi tuyet doi bang toa do, JS doc bien nay de
   cong them khoang cach. Dat bang margin thi lan re-layout sau se doc nham. */
.family-unit.detached {
  --detached-gap: 34px;
}

.person-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 8px;
  width: 154px;
  min-height: 148px;
  padding: 14px 12px 12px;
  border: 1px solid rgba(37, 36, 34, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(37, 36, 34, 0.08);
  transition: transform 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.person-card:hover,
.person-card.selected {
  border-color: var(--teal);
  transform: translateY(-2px);
}

.person-card.muted {
  opacity: 0.34;
}

/* Thanh vien da mat: the xam lai, anh dai dien chuyen trang den. Van doc ro,
   khong lam ho mo di nhu the bi loc bo.
   Khong dat `border-color` o day: rule nay nam sau `.person-card.selected` nen se
   de len vien teal luc chon the. */
.person-card.deceased {
  background: #ecebe6;
}

.person-card.deceased .person-name {
  color: #5c5952;
}

.person-card.deceased .person-avatar {
  filter: grayscale(1);
  opacity: 0.82;
}

.person-card.match {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold), 0 12px 28px rgba(37, 36, 34, 0.08);
}

/* The duoc chon tu o tim kiem: nhay nhe vai giay de mat de bat duoc vi tri
   sau khi canvas cuon toi. */
.person-card.pinpoint {
  border-color: var(--teal);
  animation: pinpoint-pulse 900ms ease-out 2;
}

@keyframes pinpoint-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 95, 92, 0.55), 0 12px 28px rgba(37, 36, 34, 0.08);
    transform: translateY(-2px) scale(1);
  }
  60% {
    box-shadow: 0 0 0 14px rgba(15, 95, 92, 0), 0 12px 28px rgba(37, 36, 34, 0.08);
    transform: translateY(-2px) scale(1.06);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(15, 95, 92, 0), 0 12px 28px rgba(37, 36, 34, 0.08);
    transform: translateY(-2px) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .person-card.pinpoint {
    animation: none;
    box-shadow: 0 0 0 3px var(--teal), 0 12px 28px rgba(37, 36, 34, 0.08);
  }
}

.tree-search {
  position: relative;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 30;
  max-height: 340px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-results[hidden] {
  display: none;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.search-result:hover,
.search-result.active {
  background: var(--teal-soft);
}

.search-avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  overflow: hidden;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--gold));
  font-size: 0.76rem;
  font-weight: 900;
}

.search-avatar.female {
  background: linear-gradient(135deg, var(--rust), var(--gold));
}

.search-avatar.other,
.search-avatar.unknown {
  background: linear-gradient(135deg, #6d6a75, var(--teal));
}

.search-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.result-name {
  font-size: 0.9rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.result-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.search-empty,
.search-more {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.person-avatar,
.detail-avatar,
.member-inline img,
.avatar-fallback {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--gold));
  font-weight: 900;
}

.person-avatar {
  width: 66px;
  height: 66px;
  font-size: 1.15rem;
}

.person-avatar.female,
.detail-avatar.female {
  background: linear-gradient(135deg, var(--rust), var(--gold));
}

.person-avatar.other,
.detail-avatar.other,
.person-avatar.unknown,
.detail-avatar.unknown {
  background: linear-gradient(135deg, #6d6a75, var(--teal));
}

.person-avatar img,
.detail-avatar img,
.member-inline img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.person-name {
  width: 100%;
  min-height: 38px;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 900;
  line-height: 1.22;
  text-align: center;
  overflow-wrap: anywhere;
}

.person-years {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Tuoi hien tai, hoac "Hưởng thọ / Hưởng dương" voi nguoi da mat.
   Khong dung dang vien bo tron: "Hưởng thọ ~88 tuổi" dai hon be rong the (154px), vien
   bo tron se bi tran ra ngoai. De chu thuong, cho phep xuong dong. */
.person-age {
  width: 100%;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.person-card.deceased .person-age {
  color: #5c5952;
}

.tree-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.parent-line {
  stroke: rgba(15, 95, 92, 0.46);
  stroke-width: 2.5;
}

.spouse-line {
  stroke: rgba(216, 90, 58, 0.56);
  stroke-width: 2;
  stroke-dasharray: 6 6;
}

.message-panel,
.admin-content,
.admin-sidebar,
.admin-form,
.table-wrap,
.account-item {
  border: 1px solid rgba(37, 36, 34, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 14px 42px rgba(37, 36, 34, 0.08);
}

/* Ho so thanh vien: hop noi phia tren, chi hien khi bam vao mot the tren cay. */
.member-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 24px;
}

.member-modal[hidden] {
  display: none;
}

.member-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(37, 36, 34, 0.42);
  backdrop-filter: blur(2px);
}

.member-modal-card {
  position: relative;
  z-index: 1;
  width: min(540px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px 24px 24px;
  border: 1px solid rgba(37, 36, 34, 0.12);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.member-modal-card h2 {
  margin: 6px 40px 18px 0;
  font-size: 1.45rem;
  line-height: 1.15;
}

.member-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.member-modal-close:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.detail-content {
  display: grid;
  gap: 14px;
}

.detail-avatar {
  width: 92px;
  height: 92px;
  font-size: 1.45rem;
}

.detail-row {
  display: grid;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-row span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.detail-row strong {
  overflow-wrap: anywhere;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  color: var(--muted);
  font-weight: 900;
}

.admin-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 20px;
  width: min(1240px, calc(100% - 36px));
  margin: 24px auto 44px;
  align-items: start;
}

.admin-sidebar {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 6px;
  padding: 12px;
}

.admin-sidebar a {
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 900;
}

.admin-sidebar a.active,
.admin-sidebar a:hover {
  color: var(--teal);
  background: var(--teal-soft);
}

.admin-content {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 3vw, 28px);
}

.section-heading {
  display: grid;
  gap: 4px;
}

.row-heading {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  display: grid;
  gap: 10px;
  min-height: 118px;
  padding: 18px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), #228c72);
}

.stat-card:nth-child(2) {
  background: linear-gradient(135deg, var(--rust), #a9412b);
}

.stat-card:nth-child(3) {
  background: linear-gradient(135deg, #4c6f4f, var(--teal));
}

.stat-card:nth-child(4) {
  color: var(--ink);
  background: linear-gradient(135deg, var(--gold), #ffd789);
}

.stat-card span {
  font-weight: 800;
  opacity: 0.86;
}

.stat-card strong {
  font-size: 2.6rem;
  line-height: 1;
}

.quick-actions,
.form-actions,
.table-actions,
.account-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-form {
  box-shadow: none;
}

.compact-form {
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.relation-grid,
.user-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.span-2 {
  grid-column: span 2;
}

.current-avatar {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.current-avatar img {
  width: 70px;
  height: 70px;
  border-radius: 999px;
  object-fit: cover;
}

.table-search {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.table-search input {
  width: min(320px, 100%);
}

.table-search-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  box-shadow: none;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.member-inline {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.member-inline img,
.avatar-fallback {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.table-actions {
  justify-content: flex-end;
  min-width: 142px;
}

.toggle-list {
  display: grid;
  gap: 12px;
  padding: 0 clamp(24px, 4vw, 42px) clamp(24px, 4vw, 42px);
}

.toggle-row,
.toggle-mini {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}

.toggle-row input,
.toggle-mini input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.account-list {
  display: grid;
  gap: 14px;
}

.account-item {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 120px 1.1fr 130px auto;
  align-items: end;
  gap: 12px;
  padding: 16px;
  box-shadow: none;
}

.message-panel {
  width: min(680px, 100%);
  padding: clamp(24px, 5vw, 48px);
}

.narrow-page {
  min-height: calc(100vh - 140px);
}

@media (max-width: 1080px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  .admin-sidebar {
    display: flex;
    overflow: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .relation-grid,
  .user-grid,
  .account-item {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-header,
  .tree-toolbar,
  .row-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header {
    position: static;
  }

  .main-nav,
  .toolbar-actions,
  .quick-actions {
    justify-content: flex-start;
  }

  .login-panel,
  .form-grid,
  .stats-grid,
  .relation-grid,
  .user-grid,
  .account-item {
    grid-template-columns: 1fr;
  }

  .login-copy {
    min-height: 220px;
  }

  .span-2 {
    grid-column: auto;
  }

  /* O tim kiem chiem tron chieu ngang, keo theo danh sach goi y (absolute, left/right 0)
     cung rong bang man hinh thay vi bi nen lai con mot manh nho. */
  .tree-search {
    flex: 1 1 100%;
  }

  .toolbar-actions input {
    width: 100%;
  }

  .tree-page {
    padding: 14px;
  }

  /* Tren dien thoai canvas phai thap hon khung nhin, neu khong nguoi dung vuot de cuon
     trang lai bi ket lai trong canvas. */
  .tree-canvas {
    height: 72vh;
    min-height: 380px;
  }

  .tree-board {
    gap: 56px;
    padding: 24px 16px 36px;
  }

  .generation-row {
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 10px;
  }

  /* Giu do chenh lech: khoang cach giua cac gia dinh phai ro rang hon khoang cach
     giua vo va chong, neu khong bo cuc theo gia dinh mat y nghia. */
  .generation-members {
    gap: 56px;
  }

  .family-unit {
    gap: 16px;
  }

  .family-unit.detached {
    --detached-gap: 12px;
  }

  .person-card {
    width: 128px;
    padding: 12px 8px 10px;
  }

  .person-avatar {
    width: 54px;
    height: 54px;
    font-size: 1rem;
  }

  .person-name {
    min-height: 34px;
    font-size: 0.86rem;
  }

  .person-years {
    font-size: 0.72rem;
  }

  .app-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Dien thoai nho: thu nho the them mot nac de mot hang chua duoc nhieu nguoi hon,
   bot phai cuon ngang. */
@media (max-width: 480px) {
  .tree-board {
    gap: 48px;
    padding: 20px 12px 30px;
  }

  .generation-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .generation-label {
    justify-self: start;
    left: 12px;
  }

  .generation-members {
    gap: 22px;
  }

  .person-card {
    width: 112px;
    min-height: 132px;
  }

  .person-avatar {
    width: 46px;
    height: 46px;
    font-size: 0.86rem;
  }

  .person-name {
    min-height: 32px;
    font-size: 0.8rem;
  }
}
