/* ========== BASE STYLES ========== */
:root {
    --primary: #a88b5c;
    --primary-dark: #8c6d46;
    --text-dark: #5c3a21;
    --bg-light: #fdfbf5;
    --line-color: #a88b5c;
    --line-width: 2px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-light);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4c0a1' fill-opacity='0.2'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    min-height: 100vh;
}

.font-serif-display {
    font-family: 'Playfair Display', serif;
}

/* ========== SEARCH BAR ========== */
.search-container {
    max-width: 600px;
    margin: 0 auto 24px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 16px 24px;
    font-size: 1.1rem;
    border: 3px solid var(--primary);
    border-radius: 50px;
    outline: none;
    transition: all 0.3s;
}

.search-input:focus {
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 4px rgba(168, 139, 92, 0.2);
}

.search-input::placeholder {
    color: #a88b5c;
}

/* ========== SEARCH DROPDOWN ========== */
.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-dropdown.show {
    display: block;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-result-item {
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: #f8f5f0;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.search-result-name {
    font-weight: 700;
    color: var(--text-dark);
    font-size: 1rem;
}

.search-result-generation {
    background: var(--primary);
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.search-result-info {
    font-size: 0.85rem;
    color: #666;
    line-height: 1.4;
}

.search-result-spouse {
    color: #8c6d46;
    font-style: italic;
}

.search-no-results {
    padding: 20px;
    text-align: center;
    color: #999;
}

.search-summary {
    padding: 12px 20px;
    background: #f8f5f0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    color: var(--text-dark);
    font-weight: 600;
}

/* ========== ACCESSIBILITY IMPROVEMENTS ========== */
/* Compact mode cho card - giảm kích thước để cây không quá rộng */
.tree li .member {
    min-width: 180px; /* Giảm từ 240px */
    max-width: 200px; /* Thêm max-width */
    padding: 10px 12px; /* Giảm padding */
}

.tree li .member .generation-tag {
    font-size: 0.65rem;
    padding: 2px 8px;
    margin-bottom: 2px;
}

.tree li .member .name {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.2;
    /* Prevent text overflow */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tree li .member .spouse {
    font-size: 0.8rem;
    line-height: 1.2;
}

.tree li .member .details,
.tree li .member .anniversary {
    font-size: 0.7rem;
    line-height: 1.2;
}

.tree li .member .parent-note {
    font-size: 0.65rem;
    line-height: 1.1;
    font-style: italic;
}

/* Giảm spacing giữa các thành phần trong card */
.tree li .member {
    gap: 2px; /* Giảm từ 4px */
}

/* ========== TREE STRUCTURE - COMPACT ========== */
.tree {
    --spacing: 1.2rem; /* Giảm từ 1.8rem để cây gọn hơn */
    /* Không dùng flex-wrap - giữ layout cây chuẩn */
    display: inline-block;
    min-width: max-content;
}

.tree ul {
    position: relative;
    padding-top: calc(2 * var(--spacing));
    display: flex;
    justify-content: center;
    /* BỎ flex-wrap - đây là nguyên nhân gây vỡ layout */
    /* flex-wrap: wrap; */
}

.tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    padding: calc(var(--spacing) * 0.8) 6px 0 6px; /* Giảm padding */
}

/* Đường nối */
.tree li::before, .tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: var(--line-width) solid var(--line-color);
    width: 50%;
    height: var(--spacing);
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: var(--line-width) solid var(--line-color);
}

.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: var(--line-width) solid var(--line-color);
    border-radius: 0 8px 0 0;
}

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

.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: var(--line-width) solid var(--line-color);
    width: 0;
    height: calc(2 * var(--spacing));
}

/* ========== MEMBER CARD ========== */
.tree li .member {
    border: 2px solid var(--primary); /* Giảm từ 3px */
    background-color: #fffaf0;
    border-radius: 10px; /* Giảm từ 12px */
    display: flex;
    flex-direction: column;
    gap: 2px; /* Giảm từ 4px */
    box-shadow: 0 2px 4px -1px rgb(0 0 0 / 0.1);
    transition: all 0.3s;
    position: relative;
    margin-bottom: 12px; /* Giảm từ 20px */
    cursor: pointer;
}

.tree li .member:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 20px -3px rgb(0 0 0 / 0.15), 0 6px 8px -4px rgb(0 0 0 / 0.1);
    border-color: var(--primary-dark);
}

.tree li .member .name {
    color: var(--text-dark);
}

.tree li .member .spouse {
    color: #6b5344;
}

.tree li .member .details {
    color: var(--primary-dark);
}

.tree li .member .anniversary {
    color: var(--text-dark);
    font-style: italic;
}

/* Generation tag */
.generation-tag {
    background-color: var(--primary);
    color: white;
    padding: 3px 10px; /* Giảm padding */
    font-size: 0.75rem; /* Giảm font */
    font-weight: 600;
    border-radius: 16px; /* Giảm border-radius */
    position: absolute;
    top: -12px; /* Giảm từ -14px */
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* ========== PASSED AWAY STYLE - CLEAN ========== */
.passed-away {
    border-color: #5c3a21 !important;
    /* Same background as living members - no dark background */
    background-color: #fffaf0;
    position: relative;
}

/* Subtle gray text only - no icon */
.passed-away .name {
    color: #6b5344;
    font-weight: 600;
}

/* Cross symbols for birth/death years */
.passed-away .details {
    color: #888;
    font-size: 0.85rem;
}

/* ========== AGE DISPLAY (ÂM/DƯƠNG) ========== */
.age-display {
    display: flex;
    gap: 4px;
    align-items: center;
    font-size: 0.65rem;
    margin-top: 2px;
}

.age-item {
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.65rem;
}

.age-lunar {
    background: rgba(168, 139, 92, 0.15);
    color: var(--primary-dark);
}

.age-solar {
    background: rgba(107, 83, 68, 0.08);
    color: #6b5344;
}

.age-active {
    box-shadow: 0 0 0 1px var(--primary);
}

/* ========== TOGGLE BUTTON ========== */
.toggle-btn {
    position: absolute;
    bottom: -14px; /* Giảm từ -18px */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    width: 28px; /* Giảm từ 32px */
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem; /* Giảm từ 1rem */
    font-weight: 700;
    cursor: pointer;
    z-index: 10;
    border: 2px solid var(--bg-light); /* Giảm từ 3px */
    transition: all 0.2s;
}

.toggle-btn:hover {
    background-color: var(--primary-dark);
    transform: translateX(-50%) scale(1.15);
}

.tree ul.collapsed {
    display: none;
}

/* ========== HIGHLIGHT ========== */
.tree .member.highlight {
    border-color: #c53030;
    box-shadow: 0 0 16px rgba(197, 48, 48, 0.5);
}

.tree li.highlight > .member {
    border-color: #c53030;
    box-shadow: 0 0 16px rgba(197, 48, 48, 0.5);
}

.tree li.highlight::after,
.tree li.highlight::before,
.tree ul.highlight::before {
    border-color: #c53030 !important;
}

/* ========== GENDER ICONS ========== */
.name[data-gender]::after, .spouse[data-gender]::after {
    font-family: 'Times New Roman', serif;
    font-weight: bold;
    margin-left: 6px;
    font-size: 1.2em;
}

.name[data-gender="male"]::after, .spouse[data-gender="male"]::after {
    content: '♂';
    color: #2b6cb0;
}

.name[data-gender="female"]::after, .spouse[data-gender="female"]::after {
    content: '♀';
    color: #c53030;
}

/* ========== TREE CONTAINER WITH DRAG SCROLL ========== */
#family-tree-container {
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    /* Enable native scroll for iOS - this is the key! */
    overflow: auto;
    -webkit-overflow-scrolling: touch;  /* Enable momentum scroll on iOS */
    overscroll-behavior: contain;
    max-width: 100%;
    /* Make container scrollable on both axes */
    height: 80vh;  /* Fixed height for desktop */
    min-height: 60vh;  /* Minimum height for mobile */
    /* ADD: Ensure container is at correct z-index */
    position: relative;
    z-index: 1;
}

/* Mobile: full viewport height for better scroll experience */
@media (max-width: 768px) {
    #family-tree-container {
        height: 100vh;
        min-height: 100vh;
    }
}

#family-tree-container.grabbing {
    cursor: grabbing;
}

/* Nút bấm lớn hơn, dễ chạm */
.control-btn {
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 8px;
    min-height: 48px; /* Cho người dùng mobile */
    touch-action: manipulation;
}

/* ========== TREE TABS ========== */
.tree-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.tree-tab {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: 3px solid var(--primary);
    border-radius: 12px;
    background: white;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.tree-tab:hover {
    background: #f8f5f0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.tree-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(168, 139, 92, 0.4);
    position: relative;
}

.tree-tab.active::before {
    content: '✓';
    margin-right: 6px;
    font-weight: bold;
}

.tree-tab.active:hover {
    background: var(--primary-dark);
}

/* Inactive tab - make more subtle */
.tree-tab:not(.active) {
    opacity: 0.7;
}

.tree-tab:not(.active):hover {
    opacity: 1;
}

/* ========== EXPORT MODE ========== */
body.exporting .controls-container,
body.exporting .toggle-btn,
body.exporting .search-container,
body.exporting .help-btn {
    display: none !important;
}

body.exporting .member {
    box-shadow: none !important;
}

/* ========== HELP MODAL ========== */
.help-modal {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.help-modal.show {
    display: flex !important;
}

.help-modal.show {
    display: flex;
}

.help-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.help-content h2 {
    color: var(--text-dark);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.help-content ul {
    list-style: none;
    padding: 0;
}

.help-content li {
    padding: 12px 0;
    border-bottom: 1px solid #eee;
    font-size: 1.1rem;
    line-height: 1.6;
}

.help-content li::before {
    content: "✓ ";
    color: var(--primary);
    font-weight: bold;
}

.close-help {
    margin-top: 20px;
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
}

.close-help:hover {
    background: var(--primary-dark);
}

.zoom-controls {
    position: fixed;
    bottom: 24px;
    right: 100px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 99;
}

.zoom-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #38a169;
    color: white;
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.2s;
}

.zoom-btn:hover {
    background: #2f855a;
    transform: scale(1.1);
}

.zoom-level {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dark);
    font-weight: 600;
}

/* ========== FLOATING HELP BUTTON ========== */
.help-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.help-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

/* ========== SCROLL HINT ========== */
.scroll-hint {
    text-align: center;
    color: var(--primary-dark);
    font-size: 0.9rem;
    margin-bottom: 12px;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ========== STATS FLOATING BAR ========== */
.stats-floating-bar {
    position: fixed;
    top: 20px;
    left: 20px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 16px 20px;
    z-index: 98;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid var(--primary);
}

.stats-floating-bar:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
}

.stats-floating-bar.compact-mobile {
    padding: 10px 12px;
    border-radius: 12px;
    min-width: 90px;
}

.stats-floating-bar.compact-mobile .icon {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.stats-floating-bar.compact-mobile .count {
    font-size: 1.2rem;
}

.stats-floating-bar.compact-mobile .label {
    font-size: 0.65rem;
}

.stats-floating-bar.compact-mobile .stats-toggle-btn {
    width: 22px;
    height: 22px;
    font-size: 0.8rem;
    top: -6px;
    right: -6px;
}

.stats-floating-bar .icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.stats-floating-bar .count {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1;
}

.stats-floating-bar .label {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
}

.stats-toggle-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-dark);
    color: white;
    border: 2px solid white;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== DASHBOARD SIDEBAR ========== */
.dashboard-sidebar {
    position: fixed;
    top: 0;
    left: -400px !important;
    width: 380px;
    height: 100vh;
    background: white;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    z-index: 2000;
    transition: left 0.3s ease-out;
    overflow-y: auto;
}

.dashboard-sidebar.show {
    left: 0 !important;
}

.dashboard-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    display: none;
}

.dashboard-overlay.show {
    display: block;
}

/* ========== ANNIVERSARY SIDEBAR (Right side) ========== */
.anniversary-sidebar {
    position: fixed;
    top: 0;
    right: -400px !important;
    width: 380px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
    z-index: 2000;
    transition: right 0.3s ease-out;
    overflow-y: auto;
}

.anniversary-sidebar.show {
    right: 0 !important;
}

.anniversary-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1998;
    display: none;
}

.anniversary-overlay.show {
    display: block;
}

.anniversary-header {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    padding: 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.anniversary-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.anniversary-header .subtitle {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 4px;
}

.anniversary-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.anniversary-close:hover {
    background: rgba(255,255,255,0.3);
}

.anniversary-content {
    padding: 16px;
}

.anniversary-month {
    margin-bottom: 20px;
}

.anniversary-month-title {
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Màu sắc cho từng tháng */
.anniversary-month-title[data-month="1"] { background: linear-gradient(135deg, #e74c3c, #c0392b); } /* Tết - Đỏ */
.anniversary-month-title[data-month="2"] { background: linear-gradient(135deg, #e67e22, #d35400); } /* Giêng - Cam */
.anniversary-month-title[data-month="3"] { background: linear-gradient(135deg, #f39c12, #d68910); } /* Hai - Vàng */
.anniversary-month-title[data-month="4"] { background: linear-gradient(135deg, #27ae60, #229954); } /* Ba - Xanh lá */
.anniversary-month-title[data-month="5"] { background: linear-gradient(135deg, #3498db, #2980b9); } /* Tư - Xanh dương */
.anniversary-month-title[data-month="6"] { background: linear-gradient(135deg, #9b59b6, #8e44ad); } /* Năm - Tím */
.anniversary-month-title[data-month="7"] { background: linear-gradient(135deg, #1abc9c, #17a589); } /* Sáu - Xanh ngọc */
.anniversary-month-title[data-month="8"] { background: linear-gradient(135deg, #e91e63, #c2185b); } /* Bảy - Hồng */
.anniversary-month-title[data-month="9"] { background: linear-gradient(135deg, #00bcd4, #0097a7); } /* Tám - Xanh lơ */
.anniversary-month-title[data-month="10"] { background: linear-gradient(135deg, #ff9800, #f57c00); } /* Chín - Cam đậm */
.anniversary-month-title[data-month="11"] { background: linear-gradient(135deg, #795548, #5d4037); } /* Mười - Nâu */
.anniversary-month-title[data-month="12"] { background: linear-gradient(135deg, #607d8b, #455a64); } /* Chạp - Xám */

.anniversary-month-title .month-name {
    flex: 1;
}

.anniversary-month-title .count {
    background: rgba(255,255,255,0.3);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
}

.anniversary-item {
    background: #f9f7f4;
    border-left: 3px solid var(--primary);
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 0 8px 8px 0;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.anniversary-item.today {
    background: #fff3cd;
    border-left-color: #f39c12;
}

.anniversary-item .day {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
    min-width: 40px;
    text-align: center;
}

.anniversary-item.today .day {
    color: #f39c12;
}

.anniversary-item .info {
    flex: 1;
}

.anniversary-item .name {
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 2px;
}

.anniversary-item .relation {
    font-size: 0.8rem;
    color: #7f8c8d;
}

.anniversary-item .generation {
    display: inline-block;
    background: rgba(168, 139, 92, 0.15);
    color: var(--primary-dark);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    margin-left: 6px;
}

/* Floating button for anniversaries */
.anniversary-floating-btn {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.anniversary-floating-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.5);
}

.anniversary-floating-btn.compact-mobile {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
    right: 12px;
    bottom: 78px;
}

.anniversary-floating-btn.compact-mobile .anniversary-badge {
    font-size: 0.6rem;
    min-width: 16px;
    padding: 1px 5px;
}

.anniversary-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f39c12;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.dashboard-header {
    background: var(--primary);
    color: white;
    padding: 24px 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.dashboard-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-family: 'Playfair Display', serif;
}

.dashboard-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.dashboard-close:hover {
    background: rgba(255,255,255,0.3);
}

.dashboard-content {
    padding: 20px;
}

.dashboard-section {
    margin-bottom: 28px;
}

.dashboard-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dashboard-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.dashboard-stat-card {
    background: #f8f5f0;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.dashboard-stat-card.large {
    grid-column: span 2;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.dashboard-stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.dashboard-stat-card.large .dashboard-stat-value {
    font-size: 2.5rem;
}

.dashboard-stat-label {
    font-size: 0.8rem;
    opacity: 0.8;
}

.age-range-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.age-range-card {
    background: #f8f5f0;
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    border: 1px solid rgba(168, 139, 92, 0.18);
    transition: all 0.2s;
}

.age-range-card:hover {
    background: #f1ece4;
}

.age-range-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-dark);
}

.age-range-count {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-top: 4px;
}

.age-range-members {
    display: none;
    margin-top: 8px;
    padding: 8px;
    background: #fff;
    border-radius: 8px;
    border: 1px dashed rgba(168, 139, 92, 0.35);
    font-size: 0.8rem;
    color: #5c3a21;
    line-height: 1.45;
}

.age-range-members.show {
    display: block;
}

.age-range-member-item {
    padding: 2px 0;
}

/* ========== AGE TOGGLE SWITCH ========== */
.age-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: #f8f5f0;
    border-radius: 12px;
    margin-bottom: 16px;
}

.age-toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
}

.age-toggle-switch {
    display: flex;
    background: white;
    border-radius: 20px;
    padding: 3px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.age-toggle-btn {
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: transparent;
    color: #666;
}

.age-toggle-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.age-toggle-btn:hover:not(.active) {
    background: rgba(168, 139, 92, 0.1);
}

/* Generation bars */
.generation-bar {
    margin-bottom: 10px;
}

.generation-bar-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.generation-bar-track {
    height: 24px;
    background: #eee;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.generation-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 12px;
    transition: width 0.5s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: white;
    font-weight: 600;
}

/* ========== 12 CON GIAP STYLES ========== */
.zodiac-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #f9f7f4;
    border-radius: 10px;
    transition: all 0.2s;
}

.zodiac-row:hover {
    background: #f0ede8;
    transform: translateX(4px);
}

.zodiac-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
    font-weight: 600;
    color: var(--text-dark);
}

.zodiac-emoji {
    font-size: 1.3rem;
}

.zodiac-name {
    font-size: 0.9rem;
}

.zodiac-bar-container {
    flex: 1;
    height: 8px;
    background: #e8e4dd;
    border-radius: 4px;
    overflow: hidden;
}

.zodiac-bar {
    height: 100%;
    background: linear-gradient(90deg, #ffd700 0%, #ffb347 100%);
    border-radius: 4px;
    transition: width 0.6s ease-out;
}

.zodiac-count {
    min-width: 70px;
    text-align: right;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.85rem;
}

.no-data {
    text-align: center;
    color: #999;
    padding: 20px;
    font-size: 0.9rem;
}

.zodiac-members {
    margin-top: 8px;
    padding: 12px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0ddd5;
}

.zodiac-members-list {
    display: grid;
    gap: 8px;
}

.zodiac-member-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f9f7f4;
    border-radius: 6px;
    font-size: 0.85rem;
}

.member-gender {
    font-size: 1rem;
    font-weight: 700;
}

.member-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-dark);
}

.member-canchi {
    font-size: 0.75rem;
    color: var(--primary-dark);
    background: rgba(168, 139, 92, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
}

.spouse-badge {
    font-size: 0.7rem;
    color: #718096;
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Gender pie chart (simplified) */
.gender-chart {
    display: flex;
    height: 100px;
    border-radius: 12px;
    overflow: hidden;
}

.gender-male, .gender-female {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
}

.gender-male {
    background: linear-gradient(135deg, #4299e1 0%, #2b6cb0 100%);
    color: white;
}

.gender-female {
    background: linear-gradient(135deg, #fc8181 0%, #c53030 100%);
    color: white;
}

/* Upcoming anniversaries */
.anniversary-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #f8f5f0;
    border-radius: 10px;
    margin-bottom: 8px;
}

.anniversary-date {
    background: var(--primary);
    color: white;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    min-width: 50px;
}

.anniversary-info {
    flex: 1;
}

.anniversary-name {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.9rem;
}

.anniversary-relation {
    font-size: 0.8rem;
    color: #666;
}

/* ========== TREE TABS RESPONSIVE ========== */
@media (max-width: 768px) {
    .tree-tabs {
        flex-direction: column;
        gap: 8px;
    }

    .tree-tab {
        width: 100%;
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .tree li .member {
        min-width: 200px;
        padding: 10px 12px;
    }

    .tree li .member .name {
        font-size: 1rem;
    }

    .tree li .member .spouse,
    .tree li .member .details,
    .tree li .member .announcement {
        font-size: 0.85rem;
    }

    .control-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .controls-container {
        gap: 8px !important;
    }

    h1 {
        font-size: 1.8rem !important;
    }

    /* Navigation controls trên mobile */
    .zoom-controls {
        right: 70px;
        bottom: 16px;
    }

    .zoom-btn {
        width: 44px;
        height: 44px;
    }

    .help-btn {
        width: 56px;
        height: 56px;
        font-size: 1.5rem;
        bottom: 16px;
        right: 16px;
    }
}

@media (max-width: 480px) {
    .tree li .member {
        min-width: 160px;
        padding: 8px 10px;
    }

    .nav-controls {
        bottom: 80px;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .search-input {
        font-size: 1rem;
        padding: 14px 20px;
    }
}

/* Responsive dashboard */
@media (max-width: 480px) {
    .dashboard-sidebar {
        width: 100%;
        left: -100%;
    }

    .anniversary-sidebar {
        width: 100%;
        right: -100%;
    }

    .stats-floating-bar {
        top: auto;
        bottom: 74px;
        left: 12px;
    }

    .stats-floating-bar .icon {
        font-size: 1.1rem;
    }

    .stats-floating-bar .count {
        font-size: 1.2rem;
    }

    .stats-floating-bar .label {
        font-size: 0.65rem;
    }

    .anniversary-floating-btn {
        bottom: 74px;
        right: 12px;
        width: 42px;
        height: 42px;
        font-size: 1.15rem;
    }

    .anniversary-badge {
        font-size: 0.6rem;
        padding: 1px 5px;
        min-width: 16px;
    }

    .dashboard-content,
    .anniversary-content {
        padding: 12px;
    }

    .dashboard-stat-card {
        padding: 10px;
    }

    .dashboard-stat-value {
        font-size: 1.25rem;
    }

    .dashboard-stat-card.large .dashboard-stat-value {
        font-size: 1.7rem;
    }

    .dashboard-stat-label {
        font-size: 0.72rem;
    }

    .age-range-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== TAILwind REPLACEMENT CLASSES ========== */
/* Title centering */
.max-w-7xl {
    max-width: 80rem;
    margin-left: auto;
    margin-right: auto;
}

.mx-auto {
    margin-left: auto;
    margin-right: auto;
}

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

/* Header title specific */
h1.text-2xl, h1.text-3xl {
    text-align: center;
    width: 100%;
    display: block;
}

/* Mobile fix for title */
@media (max-width: 768px) {
    h1.text-2xl, h1.text-3xl {
        text-align: center !important;
        padding-left: 0;
        margin-left: 0;
    }
}

/* ========== GENERATION BUTTONS ========== */
.generation-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.gen-btn {
    padding: 8px 14px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 2px solid var(--primary);
    border-radius: 8px;
    background: white;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s;
}

.gen-btn:hover {
    background: #f8f5f0;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(168, 139, 92, 0.3);
}

.gen-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Hide ancestor buttons by default, show only when ancestor tab is active */
.gen-btn-ancestor {
    display: none;
}

/* Show thai buttons by default */
.gen-btn-thai {
    display: inline-block;
}

/* When ancestor tab is active */
#tab-ancestor.active ~ .generation-buttons .gen-btn-ancestor,
body:has(#tab-ancestor.active) .gen-btn-ancestor {
    display: inline-block;
}

body:has(#tab-ancestor.active) .gen-btn-thai {
    display: none;
}

/* Fallback for older browsers - show all */
.generation-buttons:has(.gen-btn-ancestor) .gen-btn-thai {
    display: inline-block;
}

@media (max-width: 480px) {
    .generation-filter {
        flex-wrap: wrap;
    }
    .generation-select {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}
