:root {
  --bg-page: #f8f4ec;
  --bg-surface: #ffffff;
  --bg-warm: #fcf9f2;
  --bg-subtle: #f1eadc;
  --border: #e3d8c4;
  --border-strong: #cbbba0;
  --ink: #221c15;
  --ink-muted: #6c5f4e;
  --accent: #8e241b;
  --accent-hover: #701a12;
  --accent-soft: #fbece9;
  --gold: #b8861d;
  --gold-soft: #fdf5df;
  --male: #2b5d88;
  --male-bg: #eef5fb;
  --female: #b5455d;
  --female-bg: #fdf1f4;
  --danger: #b91c1c;
  --shadow-sm: 0 2px 8px rgba(45, 32, 16, 0.07);
  --shadow-md: 0 8px 24px rgba(45, 32, 16, 0.12);
  --shadow-lg: 0 18px 48px rgba(34, 24, 12, 0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

html, body {
  height: 100%;
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

.small {
  font-size: 0.86rem;
}

.tiny {
  font-size: 0.76rem;
}

.mt-xs { margin-top: 6px; }
.mt-sm { margin-top: 10px; }
.mb-sm { margin-bottom: 10px; }
.mb-md { margin-bottom: 14px; }

.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }

/* ==================== BUTTONS & INPUTS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 0.96rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: var(--bg-surface);
  color: var(--ink);
  border-color: var(--border-strong);
}
.btn-outline:hover {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #991b1b;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-subtle);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(142, 36, 27, 0.12);
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}
.field-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.form-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 0.85rem;
}

.info-box {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-warm);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}
.info-box-warn {
  background: #fff9ec;
  border-color: #ecd194;
}

/* ==================== LOCK SCREEN ==================== */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #fdf8ee 0%, #ede3cf 100%);
}
.lock-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.lock-emblem {
  font-size: 3rem;
  margin-bottom: 8px;
}
.lock-card h1 {
  font-family: 'Noto Serif', Georgia, serif;
  color: var(--accent);
  font-size: 1.5rem;
  margin-bottom: 4px;
}
.lock-card form {
  margin-top: 20px;
  text-align: left;
}

/* ==================== APP SHELL & TOPBAR ==================== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-icon {
  font-size: 1.65rem;
  line-height: 1;
}
.brand-text h1 {
  font-family: 'Noto Serif', Georgia, serif;
  font-size: 1.12rem;
  color: var(--accent);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}
.brand-sub {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
  min-width: 260px;
}

.search-box {
  position: relative;
  width: 230px;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 7px 10px 7px 32px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-warm);
  font-family: inherit;
  font-size: 0.86rem;
  outline: none;
}
.search-box input:focus {
  background: #fff;
  border-color: var(--accent);
}
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 300px;
  overflow-y: auto;
  z-index: 60;
}
.search-item {
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--bg-subtle);
  font-size: 0.86rem;
}
.search-item:hover {
  background: var(--bg-warm);
}
.search-item-rel {
  font-size: 0.74rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #825b0b;
  font-weight: 600;
  white-space: nowrap;
}

.me-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gold-soft);
  border: 1px solid #e7cd8a;
  padding: 4px 10px;
  border-radius: 999px;
}
.me-picker label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #7c5607;
  white-space: nowrap;
}
.me-picker select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  max-width: 180px;
  outline: none;
  cursor: pointer;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* ==================== BANNERS ==================== */
.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 7px 14px;
  font-size: 0.83rem;
  flex-wrap: wrap;
  z-index: 20;
}
.banner-gold {
  background: var(--gold-soft);
  border-bottom: 1px solid #e7cf8e;
  color: #5c3f05;
}
.banner-soft {
  background: var(--accent-soft);
  border-bottom: 1px solid #efc6bf;
  color: #6b1b13;
}

/* ==================== WORKSPACE & FAMILY CHART ==================== */
.workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-color: var(--bg-page);
  background-image: radial-gradient(#d8ccb7 1px, transparent 1px);
  background-size: 22px 22px;
}

.f3.f3-canvas {
  width: 100%;
  height: 100%;
  --background-color: transparent;
  --text-color: var(--ink);
  --male-color: var(--male);
  --female-color: var(--female);
  font-family: 'Be Vietnam Pro', sans-serif;
}

.f3 svg.main_svg {
  background: transparent !important;
}

.f3 path.link {
  stroke: #a68f70 !important;
  stroke-width: 2.2px !important;
}

.f3 path.link.f3-path-to-main {
  stroke: var(--accent) !important;
  stroke-width: 3.2px !important;
}

/* Custom Vietnamese Person Card inside family-chart */
.f3 .card_cont {
  overflow: visible !important;
}

.vn-card {
  width: 176px;
  height: 78px;
  background: #ffffff;
  border-radius: 11px;
  border: 1.8px solid var(--border-strong);
  box-shadow: 0 3px 12px rgba(45, 32, 16, 0.09);
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  position: relative;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  color: var(--ink);
  text-align: center;
}

.vn-card.has-avatar {
  justify-content: flex-start;
  text-align: left;
}

.vn-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(45, 32, 16, 0.16);
}

.vn-card.is-male {
  border-color: #7ea3c4;
  border-top: 4px solid var(--male);
}
.vn-card.is-female {
  border-color: #d79aa8;
  border-top: 4px solid var(--female);
}
.vn-card.is-deceased {
  background: #f5f2ec;
  border-style: dashed;
}
.vn-card.is-me {
  border-color: var(--gold) !important;
  border-top-color: var(--gold) !important;
  background: #fffdf5;
  box-shadow: 0 0 0 3px rgba(184, 134, 29, 0.25), 0 5px 16px rgba(45, 32, 16, 0.14);
}
.vn-card.is-selected {
  box-shadow: 0 0 0 3px rgba(142, 36, 27, 0.32), 0 8px 20px rgba(45, 32, 16, 0.18);
}

.vn-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}
.vn-card.is-male .vn-card-avatar {
  background: var(--male-bg);
  color: var(--male);
}
.vn-card.is-female .vn-card-avatar {
  background: var(--female-bg);
  color: var(--female);
}
.vn-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.vn-card-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.vn-card.has-avatar .vn-card-body {
  align-items: flex-start;
}

.vn-card-kinship {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #7c5206;
  border: 1px solid #ead193;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vn-card.is-me .vn-card-kinship {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}

.vn-card-name {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vn-card-meta {
  font-size: 0.71rem;
  color: var(--ink-muted);
  white-space: nowrap;
  line-height: 1.2;
}

.vn-card-more {
  position: absolute;
  top: 5px;
  right: 7px;
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-soft);
  padding: 0 5px;
  border-radius: 6px;
}

.vn-card-drag {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  border: 2px solid #fff;
  touch-action: none;
  user-select: none;
  z-index: 5;
}
.vn-card-drag:active {
  cursor: grabbing;
  transform: scale(1.1);
}

.vn-card.is-drop-target {
  box-shadow: 0 0 0 4px rgba(184, 134, 29, 0.45), 0 10px 26px rgba(45, 32, 16, 0.22) !important;
}

.vn-card-collapse-btn {
  position: absolute;
  left: 50%;
  bottom: -13px;
  transform: translateX(-50%);
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.69rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(45, 32, 16, 0.14);
  white-space: nowrap;
  z-index: 6;
  transition: all 0.14s ease;
}
.vn-card-collapse-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.vn-card-collapse-btn.is-collapsed {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}
.vn-card-collapse-btn.is-collapsed:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.fab-btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.fab-btn-accent:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* ==================== CONTEXT MENU (CHUỘT PHẢI) ==================== */
.context-menu {
  position: fixed;
  z-index: 260;
  min-width: 235px;
  max-width: 280px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgba(34, 24, 12, 0.24);
  padding: 6px 0;
  font-size: 0.85rem;
  user-select: none;
}
.ctx-header {
  padding: 8px 14px 7px;
  border-bottom: 1px solid var(--bg-subtle);
  background: var(--bg-warm);
}
.ctx-header-name {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctx-header-sub {
  font-size: 0.74rem;
  color: var(--accent);
  font-weight: 600;
}
.ctx-item {
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.1s;
}
.ctx-item:hover {
  background: var(--bg-warm);
  color: var(--accent);
}
.ctx-item.ctx-danger {
  color: var(--danger);
}
.ctx-item.ctx-danger:hover {
  background: #fef2f2;
  color: #991b1b;
}
.ctx-sep {
  height: 1px;
  background: var(--bg-subtle);
  margin: 4px 0;
}

/* ==================== SNAP TRAY & DRAG-TO-SNAP ==================== */
.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}
.btn-snap-toggle.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: #6b4604;
}

.snap-tray {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 64px;
  width: 300px;
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 38;
  overflow: hidden;
  backdrop-filter: blur(8px);
}

.snap-tray-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px 10px;
  background: linear-gradient(135deg, #fdf6e4 0%, #f7ebd2 100%);
  border-bottom: 1px solid var(--border);
}
.snap-tray-header h3 {
  font-family: 'Noto Serif', Georgia, serif;
  font-size: 1rem;
  color: var(--accent);
}

.snap-guide {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 8px 10px;
  background: var(--bg-warm);
  border-bottom: 1px solid var(--border);
}
.sg-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  text-align: center;
}

.quick-tray-form {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.quick-tray-row {
  display: flex;
  gap: 5px;
}
.quick-tray-form input,
.quick-tray-form select {
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.8rem;
  min-width: 0;
  flex: 1;
}
.quick-tray-form select {
  flex: 0 0 66px;
}

.snap-tray-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.snap-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.snap-filter {
  width: 100%;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.8rem;
}

.snap-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.snap-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.snap-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.snap-item:active {
  cursor: grabbing;
}
.snap-item.is-unlinked {
  background: #fffbf0;
  border-color: #e2be67;
  border-left: 4px solid var(--gold);
}
.snap-item.is-male {
  border-left: 4px solid var(--male);
}
.snap-item.is-female {
  border-left: 4px solid var(--female);
}
.snap-item.is-unlinked.is-male,
.snap-item.is-unlinked.is-female {
  border-left-color: var(--gold);
}
.snap-grip {
  color: var(--ink-muted);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
}
.snap-item-info {
  flex: 1;
  min-width: 0;
}
.snap-item-name {
  font-size: 0.83rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.snap-item-sub {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

/* Lớp phủ 4 vùng nam châm hiển thị đè chính xác lên thẻ đích khi kéo */
.snap-overlay {
  position: fixed;
  z-index: 180;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  border: 2.5px solid var(--accent);
  box-shadow: 0 12px 32px rgba(142, 36, 27, 0.28);
  background: rgba(255, 250, 240, 0.92);
  backdrop-filter: blur(2px);
}
.snap-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink);
  transition: background 0.1s, color 0.1s;
  padding: 2px 4px;
  text-align: center;
}
.snap-zone-top {
  height: 32%;
  border-bottom: 1px dashed var(--border-strong);
}
.snap-zone-mid {
  height: 36%;
  display: flex;
}
.snap-zone-left {
  width: 50%;
  border-right: 1px dashed var(--border-strong);
}
.snap-zone-right {
  width: 50%;
}
.snap-zone-bottom {
  height: 32%;
  border-top: 1px dashed var(--border-strong);
}
.snap-zone.active {
  background: var(--accent);
  color: #fff;
  font-size: 0.82rem;
}

.drag-ghost {
  position: fixed;
  z-index: 250;
  pointer-events: none;
  padding: 8px 13px;
  border-radius: 999px;
  background: #221c15;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
  transform: translate(14px, 14px);
}
.drag-ghost.is-snapping {
  background: var(--accent);
}

/* ==================== FLOATING CONTROLS ==================== */
.floating-controls {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 20;
}

.fab-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.fab-btn:hover {
  background: var(--bg-warm);
  border-color: var(--accent);
}

.legend-pill {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--ink-muted);
  box-shadow: var(--shadow-sm);
  z-index: 15;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-male { background: var(--male); }
.dot-female { background: var(--female); }
.dot-me { background: var(--gold); }
.dot-deceased { background: #9b9284; border: 1px dashed #444; }

/* ==================== DETAIL DRAWER ==================== */
.drawer {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 380px;
  max-width: calc(100% - 24px);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  background: linear-gradient(135deg, #fcf8f0 0%, #f5ecdc 100%);
  border-bottom: 1px solid var(--border);
}

.drawer-title-group h2 {
  font-family: 'Noto Serif', Georgia, serif;
  font-size: 1.18rem;
  color: var(--ink);
  margin-top: 4px;
}

.kinship-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.drawer-body {
  padding: 15px 16px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar-lg {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--bg-subtle);
  color: var(--accent);
  border: 3px solid var(--border);
  overflow: hidden;
}
.avatar-lg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-upload-btn {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}

.avatar-remove-btn {
  position: absolute;
  right: -2px;
  top: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}
.avatar-remove-btn:hover {
  background: #991b1b;
}

.life-line {
  font-weight: 600;
  font-size: 0.92rem;
}

.kinship-explain {
  background: #fffaf0;
  border-color: #ead39c;
}
.info-box-title {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-bottom: 4px;
}
.kinship-detail-text {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
  margin-bottom: 6px;
}
.kinship-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--ink-muted);
}
.chain-step {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--ink);
}

.section-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
}
.inline-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.quick-add-btn {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-warm);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.quick-add-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.quick-add-link {
  background: #f2f6fb;
  border-color: #b7cde2;
}

.details-list {
  display: grid;
  grid-template-columns: 112px 1fr;
  row-gap: 7px;
  column-gap: 10px;
  font-size: 0.86rem;
  background: var(--bg-warm);
  padding: 11px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.details-list dt {
  color: var(--ink-muted);
  font-weight: 600;
}
.details-list dd {
  color: var(--ink);
  word-break: break-word;
}
.details-list a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.rels-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rel-group-title {
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 4px;
}
.rel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.rel-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.rel-chip-unlink {
  margin-left: 2px;
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 2px;
}

/* ==================== MODALS ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 18, 12, 0.52);
  backdrop-filter: blur(2px);
}
.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-warm);
}
.modal-header h3 {
  font-family: 'Noto Serif', Georgia, serif;
  font-size: 1.08rem;
  color: var(--accent);
}
.modal-body {
  padding: 18px;
  overflow-y: auto;
}
.modal-footer-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

/* Compare Result */
.compare-result {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.compare-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-warm);
  border: 1px solid var(--border);
}
.compare-big {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin: 4px 0;
}

/* Tabs & Tables */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 8px 13px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.list-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}
.list-toolbar input {
  flex: 1;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-family: inherit;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.data-table th,
table.data-table td {
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid var(--bg-subtle);
}
table.data-table th {
  background: var(--bg-warm);
  font-weight: 700;
  color: var(--ink-muted);
}
table.data-table tr:hover td {
  background: #fdfaf4;
}
.clickable-row {
  cursor: pointer;
}

.audit-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--bg-subtle);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.84rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #221c15;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 300;
}

/* ==================== EXPORT POSTER, EVENTS & STATS ==================== */
.export-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.export-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-warm);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: all 0.15s;
}
.export-option-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.export-opt-icon {
  font-size: 1.65rem;
  line-height: 1;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.event-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fff;
}
.event-card.is-soon {
  background: #fffaf0;
  border-color: #e6c678;
}
.event-card-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.event-icon {
  font-size: 1.4rem;
}
.event-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--ink);
  white-space: nowrap;
}
.event-badge.is-today {
  background: var(--accent);
  color: #fff;
}
.event-badge.is-week {
  background: var(--gold);
  color: #fff;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stat-card {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-warm);
  border: 1px solid var(--border);
  text-align: center;
}
.stat-num {
  font-family: 'Noto Serif', Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.76rem;
  color: var(--ink-muted);
  margin-top: 3px;
}
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 48px;
  align-items: center;
  gap: 10px;
  font-size: 0.83rem;
}
.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--gold) 100%);
}
@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==================== ALBUM HÌNH KỶ NIỆM & LIGHTBOX ==================== */
.photo-upload-box {
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-warm);
  border: 1px dashed var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.photo-upload-box input[type="file"] {
  font-size: 0.8rem;
}
.photo-upload-box input[type="text"] {
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.82rem;
  min-width: 0;
  flex: 1;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 9px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  background: var(--bg-subtle);
  cursor: pointer;
  transition: transform 0.14s, border-color 0.14s;
}
.photo-thumb:hover {
  transform: scale(1.03);
  border-color: var(--accent);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 5px;
  background: linear-gradient(transparent, rgba(20, 14, 8, 0.78));
  color: #fff;
  font-size: 0.67rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-stage {
  position: relative;
  background: #1a1510;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  max-height: 62vh;
  overflow: hidden;
}
.lightbox-stage img {
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
  display: block;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}
.lightbox-nav:hover {
  background: #fff;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.pv-caption {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
}

/* ==================== MOBILE RESPONSIVE ==================== */
.connect-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 999px;
  background: #8e241b;
  color: #fff;
  font-size: 0.85rem;
  box-shadow: 0 8px 26px rgba(142, 36, 27, 0.35);
  max-width: calc(100% - 24px);
}
.connect-banner .btn-outline {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.45);
}

body.is-connecting-mode .vn-card {
  animation: pulseTarget 1.4s infinite ease-in-out;
}
@keyframes pulseTarget {
  0%, 100% { box-shadow: 0 0 0 2px rgba(184, 134, 29, 0.35), 0 4px 12px rgba(45, 32, 16, 0.12); }
  50% { box-shadow: 0 0 0 5px rgba(142, 36, 27, 0.35), 0 6px 18px rgba(45, 32, 16, 0.18); }
}

.fab-create-float {
  position: absolute;
  right: 16px;
  bottom: 58px;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(142, 36, 27, 0.36);
  transition: transform 0.15s, background 0.15s;
}
.fab-create-float:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.snap-connect-btn {
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-warm);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.snap-connect-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.quick-role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.quick-role-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-warm);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all 0.14s;
}
.quick-role-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.qr-icon {
  font-size: 1.35rem;
  line-height: 1;
}

@media (max-width: 1180px) {
  .legend-pill {
    display: none;
  }
  .fab-create-float {
    bottom: 16px;
  }
}

@media (max-width: 820px) {
  .snap-tray {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 44vh;
    border-radius: 18px 18px 0 0;
  }
  .snap-guide {
    display: none;
  }
  .fab-create-float {
    right: 12px;
    bottom: 58px;
    padding: 12px 15px;
  }
  .connect-banner {
    border-radius: 14px;
    font-size: 0.8rem;
    padding: 8px 12px;
  }
  .quick-role-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .context-menu {
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    top: auto !important;
    max-width: none;
    max-height: 75vh;
    overflow-y: auto;
    border-radius: 16px;
    padding-bottom: 10px;
  }
  .ctx-item {
    padding: 11px 16px;
    font-size: 0.92rem;
  }
}

@media (max-width: 820px) {
  .topbar {
    padding: 8px 10px;
    gap: 8px;
  }
  .brand-sub {
    display: none;
  }
  .brand-text h1 {
    font-size: 0.98rem;
    max-width: 190px;
  }
  .topbar-controls {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }
  .search-box {
    flex: 1;
    width: auto;
  }
  .me-picker select {
    max-width: 130px;
  }
  .btn-label {
    display: none;
  }
  .legend-pill {
    display: none;
  }
  .floating-controls {
    left: 10px;
    bottom: 10px;
    gap: 6px;
  }
  .fab-btn span {
    display: none;
  }
  .drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 76vh;
    border-radius: 18px 18px 0 0;
  }
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}
