/* ========== Anti-flicker: ẩn nội dung cho đến khi Blazor hydrate xong ========== */
blazor-ssr { display: contents; }

/* ========== Base ========== */
:root {
    --primary: #1a7a4a;
    --primary-dark: #145c37;
    --primary-light: #2da05f;
    --gold: #d4ac0d;
    --gold-light: #f1c40f;
    --bg: #eef4f0;
    --bg-card: #ffffff;
    --text: #2c2c2c;
    --text-muted: #7f8c8d;
    --border: #cce0d5;
    --navbar-height: 58px;
    --sidebar-width: 220px;
    --sidebar-right-width: 260px;
}

html {
    overflow-y: scroll; /* luôn hiển thị scrollbar, tránh nhảy layout */
}

html, body {
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

/* ========== Navbar ========== */
.top-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: linear-gradient(135deg, #1a7a4a 0%, #145c37 100%);
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    gap: 16px;
}

.navbar-left-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white !important;
    font-size: 1.3rem;
    font-weight: 700;
    text-decoration: none !important;
    white-space: nowrap;
}

.brand-link i { font-size: 1.5rem; color: var(--gold-light); }

.navbar-toggle-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: rgba(255,255,255,0.9);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 1.2rem;
}

.navbar-toggle-btn:hover { background: rgba(255,255,255,0.25); }

.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    margin-left: auto;
}

.user-menu-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    border-radius: 20px;
    padding: 6px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.user-menu-btn:hover { background: rgba(255,255,255,0.25); }
.user-menu-btn::after { border-color: white transparent transparent; }

/* ========== Layout ========== */
.main-wrapper {
    max-width: 960px;
    margin: 0 auto;
    padding: calc(var(--navbar-height) + 16px) 20px 16px;
}

.main-content {
    flex: 1;
    min-width: 0;
}

/* ========== Sidebar Drawer (unified left/right) ========== */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1200;
    cursor: pointer;
}

.sidebar-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    background: var(--bg);
    z-index: 1300;
    overflow-y: auto;
    transition: transform 0.25s ease;
}

.sidebar-drawer-left {
    left: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0,0,0,0.15);
}

.sidebar-drawer-left.open { transform: translateX(0); }

.sidebar-drawer-right {
    right: 0;
    left: auto;
    transform: translateX(100%);
    box-shadow: -2px 0 16px rgba(0,0,0,0.15);
}

.sidebar-drawer-right.open { transform: translateX(0); }

.sidebar-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: white;
    position: sticky;
    top: 0;
    z-index: 1;
}

.sidebar-drawer .sidebar-nav { margin: 8px; }
.sidebar-drawer-body { padding: 8px; }

/* ========== Sidebar Navigation ========== */
.sidebar-nav {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.15s;
}

.sidebar-link:hover {
    background: rgba(192,57,43,0.08);
    color: var(--primary);
    text-decoration: none;
}

.sidebar-link i { font-size: 1.2rem; color: var(--primary); }

/* Phân tách nhóm menu */
.sidebar-group-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, #ddd, transparent);
    margin: 6px 12px;
}

/* Badge count đỏ cho sidebar */
.badge-count {
    background: #dc3545;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 7px;
    margin-left: auto;
    min-width: 20px;
    text-align: center;
    line-height: 1.4;
}

/* Badge count đỏ cho top navbar */
.badge-count-nav {
    position: absolute;
    top: 2px;
    right: -4px;
    background: #dc3545;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 5px;
    min-width: 16px;
    text-align: center;
    line-height: 1.3;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.sidebar-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.sidebar-heading {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.sidebar-item {
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.sidebar-item:last-child { border-bottom: none; }

/* ========== Feed / Content ========== */
.feed-container {
    max-width: 100%;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 16px;
}

.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
}

.empty-state i { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ========== Post Card ========== */
.post-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.post-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.post-author-info .fw-semibold { font-size: 0.95rem; }

.post-content p {
    margin-bottom: 8px;
    line-height: 1.6;
}

.post-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.post-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    object-fit: cover;
}

.post-stats {
    display: flex;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 8px 0;
    font-size: 0.85rem;
}

.post-actions {
    display: flex;
    gap: 4px;
}

.action-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s;
}

.action-btn:hover { background: rgba(0,0,0,0.05); color: var(--text); }
.action-btn.active { color: var(--primary); font-weight: 600; }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Reaction color overrides */
.action-btn.active[class*="love"] { color: #e0245e; }

/* ========== Post Edit Form ========== */
.post-edit-form {
    padding: 8px 0;
}

.post-edit-form textarea {
    resize: vertical;
    min-height: 60px;
}

/* ========== Comments ========== */
.comments-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.comment-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.comment-bubble {
    background: var(--bg);
    border-radius: 12px;
    padding: 8px 12px;
    flex: 1;
    font-size: 0.9rem;
}

.comment-composer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

/* ========== Album ========== */
.album-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.album-card {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.album-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.album-card-cover {
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--bg);
}

.album-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.album-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--text-muted);
}

.album-card-body {
    padding: 10px 12px 12px;
}

.album-card-name {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.album-card-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.album-card-meta {
    display: flex;
    align-items: center;
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.album-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg);
    transition: transform 0.15s, box-shadow 0.15s;
}

.album-thumb:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.album-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.album-thumb-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.55));
    color: #fff;
    padding: 16px 6px 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.album-thumb:hover .album-thumb-overlay {
    opacity: 1;
}

/* Lightbox */
.album-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.album-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
    cursor: default;
}

.album-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1.3rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.album-lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.album-lightbox-delete {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(220,53,69,0.9);
    border: none;
    color: #fff;
    font-size: 0.9rem;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    z-index: 1;
}

.album-lightbox-delete:hover {
    background: #dc3545;
}

.album-thumb-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(220,53,69,0.85);
    color: #fff;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    padding: 0;
    z-index: 2;
    transition: background 0.15s;
}

.album-thumb:hover .album-thumb-delete {
    display: flex;
}

.album-thumb-delete:hover {
    background: #dc3545;
}

/* ========== News Page ========== */
.news-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    min-height: calc(100vh - var(--navbar-height) - 40px);
}

.news-sidebar {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - var(--navbar-height) - 40px);
    position: sticky;
    top: calc(var(--navbar-height) + 20px);
    align-self: start;
}

.news-sidebar-header h5 {
    margin: 0 0 12px;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 1.1rem;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
}

.news-headline {
    display: flex;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}

.news-headline:last-child {
    border-bottom: none;
}

.news-headline:hover {
    background: rgba(0,0,0,0.03);
}

.news-headline.active {
    background: rgba(26,122,74,0.08);
    border-left: 3px solid var(--primary);
}

.news-headline-thumb {
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 6px;
    object-fit: cover;
}

.news-headline-body {
    flex: 1;
    min-width: 0;
}

.news-headline-title {
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
}

.news-headline-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.news-main {
    min-width: 0;
}

.news-composer-wrap {
    margin-bottom: 20px;
}

.news-article {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 28px 32px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.news-article-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.news-article-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1.3;
    margin: 0 0 12px;
}

.news-article-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.news-article-images {
    margin-bottom: 20px;
}

.news-article-img {
    width: 100%;
    max-height: 480px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
}

.news-article-content {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
    margin-bottom: 20px;
}

.news-article-content p {
    margin-bottom: 12px;
}

.news-article-footer {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

@media (max-width: 768px) {
    .news-layout {
        grid-template-columns: 1fr;
    }

    .news-sidebar {
        position: static;
        max-height: none;
        overflow-y: visible;
    }

    .news-article {
        padding: 16px;
    }

    .news-article-title {
        font-size: 1.25rem;
    }
}

/* ========== Post Composer ========== */
.post-composer {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.composer-header {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.composer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 8px;
}

/* ========== Composer Image Preview ========== */
.composer-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 4px;
}

.composer-preview-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
    background: var(--bg);
}

.composer-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.composer-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    line-height: 1;
    padding: 0;
    transition: background 0.15s;
}

.composer-preview-remove:hover {
    background: rgba(0,0,0,0.85);
}

/* ========== File Attachments ========== */
.composer-file-list,
.post-files {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.composer-file-item,
.post-file-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.9rem;
    gap: 4px;
}

.post-file-item {
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.post-file-item:hover {
    background: var(--hover);
    color: inherit;
}

.post-file-item i.bi-download {
    font-size: 0.8rem;
    opacity: 0.5;
}

/* ========== Avatars ========== */
.avatar-wrap {
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: #c8ddd1; /* cùng màu SVG fallback — không bao giờ trắng/nhảy */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.avatar-wrap.avatar-xs { width: 28px; height: 28px; min-width: 28px; }
.avatar-wrap.avatar-sm { width: 36px; height: 36px; min-width: 36px; }
.avatar-wrap.avatar-md { width: 42px; height: 42px; min-width: 42px; }
.avatar-wrap.avatar-lg { width: 64px; height: 64px; min-width: 64px; }
.avatar-wrap.avatar-profile { width: 100px; height: 100px; min-width: 100px; }

.avatar-wrap .avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Compat — giữ cho code cũ chưa dùng Avatar component */
.avatar-xs {
    width: 28px; height: 28px; min-width: 28px;
    border-radius: 50%; object-fit: cover; flex-shrink: 0;
    background: #c8ddd1;
}
.avatar-sm {
    width: 36px; height: 36px; min-width: 36px;
    border-radius: 50%; object-fit: cover; flex-shrink: 0;
    background: #c8ddd1;
}
.avatar-md {
    width: 42px; height: 42px; min-width: 42px;
    border-radius: 50%; object-fit: cover; flex-shrink: 0;
    background: #c8ddd1;
}

/* ========== Member Cards ========== */
.members-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

/* Avatar bên trong member card trải full width */
.member-card .avatar-wrap {
    width: 100% !important;
    height: 90px !important;
    border-radius: 0 !important;
    min-width: unset !important;
}

.member-card {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: transform 0.15s, box-shadow 0.15s;
}

.member-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.member-card-link {
    display: block;
    text-decoration: none !important;
    color: var(--text) !important;
}

.member-avatar {
    width: 100%;
    height: 90px;
    object-fit: cover;
}

.member-info {
    padding: 10px;
}

.member-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

/* ========== Announcement Images ========== */
.ann-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.ann-img {
    height: 140px;
    max-width: 220px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    border: 1px solid var(--border);
}

.ann-img:hover { opacity: 0.88; transform: scale(1.02); }

/* Thumbnail trong form thêm thông báo */
.ann-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.btn-remove-img {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e74c3c;
    color: white;
    border: none;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Lightbox */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-img {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.lightbox-close {
    position: fixed;
    top: 16px;
    right: 24px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-close:hover { background: rgba(255,255,255,0.3); }

/* ========== Announcement Cards ========== */
.announcement-card {
    display: flex;
    gap: 12px;
    background: var(--bg-card);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
}

.announcement-card.pinned {
    border-left-color: var(--gold);
    background: #fffdf0;
}

.announcement-icon { font-size: 1.5rem; flex-shrink: 0; }

.announcement-badge-giỗ { background-color: #c0392b !important; }
.announcement-badge-họp { background-color: #2980b9 !important; }
.announcement-badge-sự.kiện { background-color: #27ae60 !important; }
.announcement-badge-thông.báo { background-color: #e67e22 !important; }

/* ========== Sidebar Event Items ========== */
.sidebar-event-item {
    cursor: pointer;
    border-radius: 6px;
    padding: 7px 4px !important;
    transition: background 0.15s;
}

.sidebar-event-item:hover {
    background: rgba(0,0,0,0.04);
}

.sidebar-event-thumb-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.sidebar-event-thumb {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--border);
}

/* ========== Event Detail Popup ========== */
.event-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 9990;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.event-popup {
    background: var(--bg-card);
    border-radius: 14px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 12px 48px rgba(0,0,0,0.25);
    padding: 24px;
    position: relative;
}

.event-popup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.event-popup-header h5 {
    font-weight: 700;
    color: var(--primary-dark);
    margin: 0;
}

.event-popup-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.event-popup-close:hover {
    background: rgba(0,0,0,0.08);
    color: var(--text);
}

.event-popup-date {
    display: flex;
    align-items: center;
    background: #f0f7f3;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 0.95rem;
    text-transform: capitalize;
}

.event-popup-content {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
    margin-bottom: 16px;
}

.event-popup-content p {
    margin-bottom: 8px;
}

.event-popup-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.event-popup-images img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.15s, opacity 0.15s;
}

.event-popup-images img:hover {
    transform: scale(1.03);
    opacity: 0.9;
}

.event-popup-footer {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

@media (max-width: 576px) {
    .event-popup {
        max-width: 100%;
        padding: 16px;
        border-radius: 10px;
    }
}

/* ========== Family Tree Filter ========== */
.filter-bar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.tree-node-dimmed { opacity: 0.3; }
.branch-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    margin-bottom: 12px;
    background: #e8f4ee;
    border: 1px solid #b8dcc8;
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--primary-dark);
}

/* ========== Generation Section ========== */
.generation-section {
    margin-bottom: 24px;
}

.generation-title {
    color: var(--primary-dark);
    font-weight: 700;
    padding: 8px 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

/* Thanh phân đời trong trang Thành viên */
.generation-block {}

.generation-divider {
    display: flex;
    align-items: center;
    gap: 12px;
}

.generation-divider::before,
.generation-divider::after {
    content: '';
    flex: 1;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

.generation-divider-label {
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
    background: var(--bg);
    padding: 4px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========== Wide Layout (Gia phả full-width) ========== */
.wide-wrapper {
    padding: calc(var(--navbar-height) + 8px) 10px 8px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.wide-content {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ========== Family Tree Toolbar ========== */
.tree-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

/* ========== Family Tree Zoom Controls ========== */
.tree-zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    justify-content: flex-end;
}

.zoom-level {
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 42px;
    text-align: center;
    color: var(--text-muted);
}

/* ========== Family Tree ========== */
.family-tree-container {
    overflow: auto;
    padding: 8px 0 12px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    touch-action: pan-x pan-y;
    flex: 1;
    min-height: 0; /* allow shrinking in flex */
}

/* Gia phả feed container fills wide-content */
.wide-content > .feed-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.wide-content > .feed-container > .family-tree-container {
    flex: 1;
}

.tree-root-row {
    display: flex;
    gap: 12px;
    flex-wrap: nowrap;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 8px 12px;
    width: max-content;
}

/* Mỗi đơn vị gia đình */
.tree-unit {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 0 2px;
}

/* Hàng vợ/chồng */
.couple-row {
    display: flex;
    align-items: center;
    gap: 0;
}

/* Ô người trong cây */
.tree-node-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 68px;
    padding: 5px 4px;
    border-radius: 8px;
    text-decoration: none !important;
    color: inherit !important;
    border: 1.5px solid;
    transition: box-shadow 0.2s, transform 0.15s;
    cursor: pointer;
}

.tree-node-box:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
    transform: translateY(-1px);
    text-decoration: none !important;
}

.tree-node-box.male  { background: #e8f4ff; border-color: #4a9fd5; }
.tree-node-box.female { background: #fff0f5; border-color: #e87fa0; }

.tree-node-box.deceased {
    opacity: 0.7;
    border-style: dashed;
    position: relative;
}
.tree-node-box.deceased::after {
    content: "\271D";
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 9px;
    color: #888;
    line-height: 1;
}

/* Tên và năm trong ô */
.tree-name {
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    margin-top: 2px;
    line-height: 1.2;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-years {
    font-size: 9px;
    color: #888;
    text-align: center;
}

/* Dây kết nối giữa vợ và chồng */
.couple-link {
    width: 20px;
    height: 14px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.couple-link::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 5px;
    border-top: 1.5px solid var(--primary);
    border-bottom: 1.5px solid var(--primary);
    background: transparent;
}

.couple-heart {
    position: relative;
    font-size: 9px;
    color: #e74c3c;
    z-index: 1;
    background: white;
    padding: 0 1px;
    line-height: 1;
}

/* Con dâu / con rể trong tab Gia đình của MemberDetail */
.child-with-spouse {
    display: flex;
    align-items: flex-start;
    gap: 0;
    flex-wrap: wrap;
}

.child-spouse-connector {
    display: flex;
    align-items: center;
    padding: 0 6px;
    align-self: center;
}

.couple-connector-line {
    width: 18px;
    height: 0;
    border-top: 2px solid var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-top: 4px;
}

.couple-heart-sm {
    font-size: 14px;
    color: #e74c3c;
    padding: 0 3px;
}

.badge-dau {
    background-color: #fce4ec;
    color: #c2185b;
    border: 1px solid #f48fb1;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.badge-re {
    background-color: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* Badge con dâu / con rể dưới tên trong cây */
.inlaw-badge {
    font-size: 8px;
    font-weight: 600;
    padding: 0px 4px;
    border-radius: 6px;
    margin-top: 1px;
    letter-spacing: 0.02em;
}

.inlaw-badge.dau { background: #fce4ec; color: #c2185b; border: 1px solid #f48fb1; }
.inlaw-badge.re  { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }

/* Đường dọc từ cặp vợ chồng xuống */
.tree-down-line {
    width: 1.5px;
    height: 14px;
    background: #bbb;
    flex-shrink: 0;
}

/* Hàng con cái */
.tree-children-row {
    display: flex;
    align-items: flex-start;
    gap: 0;
}

/* Bọc từng con */
.tree-child-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    flex: 1 0 auto;
    min-width: 74px;
}

/* Thanh ngang nối con cái */
.tree-child-wrap::before {
    content: '';
    position: absolute;
    top: 0;
    height: 1.5px;
    background: #bbb;
}

.tree-child-wrap:first-child::before  { left: 50%;  right: -1px; }
.tree-child-wrap:last-child::before   { left: -1px; right: 50%; }
.tree-child-wrap:not(:first-child):not(:last-child)::before { left: -1px; right: -1px; }
.tree-child-wrap:only-child::before   { display: none; }

/* Đường dọc từ thanh ngang xuống từng con */
.tree-drop-line {
    width: 1.5px;
    height: 12px;
    background: #bbb;
    flex-shrink: 0;
}

/* ========== Image Upload ========== */
.image-upload-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.upload-preview {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border);
}

/* ========== Profile Page ========== */
.profile-page {}

.profile-cover {
    height: 250px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    background-size: cover;
    background-position: center;
    border-radius: 0 0 12px 12px;
    position: relative;
}

.profile-edit-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
}

.profile-header {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    padding: 0 16px 16px;
    margin-top: -50px;
}

.profile-avatar-wrapper {
    flex-shrink: 0;
}

.profile-avatar, .avatar-wrap.avatar-profile {
    width: 100px;
    height: 100px;
    min-width: 100px;
    border-radius: 50%;
    border: 4px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.profile-name { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.profile-meta { display: flex; gap: 16px; color: var(--text-muted); font-size: 0.9rem; }

/* Profile 2-column body */
.profile-body {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    padding: 16px 0;
}

.profile-left-col {
    position: sticky;
    top: calc(var(--navbar-height) + 12px);
    align-self: start;
}

.profile-right-col {
    min-width: 0;
}

@media (max-width: 768px) {
    .profile-body {
        grid-template-columns: 1fr;
    }
    .profile-left-col {
        position: static;
    }
}

/* Profile gallery grid */
.profile-gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    border-radius: 8px;
    overflow: hidden;
}

.profile-gallery-item {
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
}

.profile-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.profile-gallery-item:hover img {
    transform: scale(1.05);
}

.info-row {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.info-row:last-child { border-bottom: none; }

.bio-content { line-height: 1.7; }

.family-section {}

/* ========== Home Articles ========== */
.home-article {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.home-article-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 16px 20px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.home-article-title {
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.home-article-header .text-muted {
    color: rgba(255,255,255,0.75) !important;
}

.home-article-body {
    padding: 20px;
    line-height: 1.8;
    font-size: 1rem;
}

.home-article-body h1,
.home-article-body h2,
.home-article-body h3 {
    color: var(--primary-dark);
    margin-top: 1.2em;
    margin-bottom: 0.5em;
}

.home-article-body p { margin-bottom: 0.9em; }

.home-article-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

.home-article-body ul, .home-article-body ol {
    padding-left: 1.5em;
    margin-bottom: 0.9em;
}

.home-article-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 16px;
}

.home-article-img {
    height: 160px;
    max-width: 240px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.home-article-actions {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: #fafafa;
}

/* ========== Auth Layout ========== */
.auth-layout {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, #0e4226 50%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 420px;
}

.auth-brand {
    text-align: center;
    color: white;
}

.auth-brand i { font-size: 3rem; color: var(--gold-light); display: block; margin-bottom: 8px; }
.auth-brand h1 { font-size: 2rem; font-weight: 700; margin-bottom: 4px; }
.auth-brand p { opacity: 0.85; }

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* ========== Home Hero ========== */
.home-hero {
    min-height: calc(100vh - var(--navbar-height));
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.hero-content { max-width: 600px; padding: 32px; }

.hero-icon {
    font-size: 5rem;
    color: var(--primary);
    display: block;
    margin-bottom: 16px;
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 12px;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.hero-features {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    color: var(--text);
}

.feature-item i {
    font-size: 1.3rem;
    color: var(--primary);
}

/* ========== Admin ========== */
.admin-container {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.form-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--border);
    padding-bottom: 6px;
    margin-bottom: 4px;
    margin-top: 8px;
}

.font-mono { font-family: 'Courier New', monospace; font-size: 0.9rem; }

/* ========== Search & Filter ========== */
.search-filter-bar { }

/* ========== Utility ========== */
.x-small { font-size: 0.75rem; }
.btn-ghost {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.btn-ghost:hover { background: rgba(0,0,0,0.05); }

/* ========== Buttons override ========== */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary-dark);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-primary:focus {
    box-shadow: 0 0 0 0.2rem rgba(192,57,43,0.35);
}

/* ========== Bootstrap overrides ========== */
.nav-tabs .nav-link.active {
    border-color: var(--border) var(--border) white;
}

/* ========== Blazor error UI ========== */
#blazor-error-ui {
    background: #145c37;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: white;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ========== Desktop: Right sidebar pinned (MainLayout only) ========== */
@media (min-width: 992px) {
    .sidebar-drawer-right.desktop-pin.open {
        position: fixed;
        top: var(--navbar-height);
        bottom: 0;
        right: 0;
        width: var(--sidebar-right-width);
        max-width: var(--sidebar-right-width);
        transform: none;
        box-shadow: -1px 0 4px rgba(0,0,0,0.06);
        z-index: 100;
    }
    .sidebar-drawer-right.desktop-pin.open .sidebar-drawer-header {
        display: none;
    }
    /* Centering dùng calc() thay vì auto → CSS transition hoạt động mượt */
    .main-wrapper {
        margin-left: auto;
        margin-right: max(0px, calc((100% - 960px) / 2));
        transition: margin-right 0.3s ease;
    }
    .main-wrapper.sidebar-right-open {
        /* Center trong phần còn lại (viewport - sidebar) */
        margin-right: calc(var(--sidebar-right-width) + max(0px, (100% - var(--sidebar-right-width) - 960px) / 2));
    }
    /* Overlay không cần cho right sidebar trên desktop */
    .sidebar-overlay-right.desktop-pin { display: none !important; }
}

/* ========== Responsive ========== */
@media (max-width: 576px) {
    .main-wrapper { padding: calc(var(--navbar-height) + 8px) 8px 8px; }
    .profile-header { flex-direction: column; align-items: center; text-align: center; }
    .profile-meta { flex-direction: column; align-items: center; }
}

/* ========== Validation ========== */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid var(--primary); }
.validation-message { color: var(--primary); }

.blazor-error-boundary {
    background: #145c37;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "Đã xảy ra lỗi."
}

.darker-border-checkbox.form-check-input { border-color: #929292; }

/* ========== Skeleton loading (chống layout shift) ========== */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton-line {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e0e0e0 25%, #eeeeee 50%, #e0e0e0 75%);
    background-size: 400px 100%;
    animation: shimmer 1.4s infinite;
    margin-bottom: 8px;
}

.skeleton-line.short { width: 60%; }

/* Skeleton card — cùng kích thước MemberCard thật */
.member-card-skeleton {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.skeleton-avatar {
    width: 100%;
    height: 90px;
    background: linear-gradient(90deg, #e0e0e0 25%, #eeeeee 50%, #e0e0e0 75%);
    background-size: 400px 100%;
    animation: shimmer 1.4s infinite;
}

/* ========== Search Page ========== */
.search-box-large .form-control {
    font-size: 1.1rem;
    border-left: none;
    box-shadow: none;
}

.search-box-large .input-group-text {
    border-right: none;
}

.search-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.search-hint {
    color: var(--text-muted);
}

.nav-search-btn {
    padding: 6px 10px;
    text-decoration: none !important;
}

/* ========== Quill Rich Text Editor ========== */
.quill-editor-container {
    background: white;
    border-radius: 0 0 6px 6px;
}

.ql-toolbar.ql-snow {
    border-radius: 6px 6px 0 0;
    border-color: #dee2e6;
    background: #f8f9fa;
}

.ql-container.ql-snow {
    border-color: #dee2e6;
    border-radius: 0 0 6px 6px;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
}

.ql-editor {
    min-height: inherit;
}

.ql-editor.ql-blank::before {
    color: #adb5bd;
    font-style: normal;
}

/* ========== Ổn định layout — tránh co giãn ========== */
.main-content {
    min-height: calc(100vh - var(--navbar-height) - 32px);
}

.sidebar-card {
    min-height: 80px;
}

/* Feed ổn định */
.feed-container {
    min-height: 400px;
}

/* Tránh AuthorizeView gây flash */
.auth-checking {
    visibility: hidden;
    min-height: 40px;
}

/* Smooth page transitions */
.main-content > * {
    animation: fadeIn 0.15s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0.6; }
    to   { opacity: 1; }
}

/* ========== RichTextEditor: Quill footer & source view ========== */
.quill-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    overflow: hidden;
}
.quill-wrapper .quill-editor-container {
    border: none !important;
    border-radius: 0 !important;
}
.quill-wrapper .ql-toolbar {
    border: none !important;
    border-bottom: 1px solid #dee2e6 !important;
}
.quill-wrapper .ql-container {
    border: none !important;
}
.quill-source-view {
    font-family: 'Consolas', 'Courier New', monospace !important;
    font-size: 12px !important;
    border: none !important;
    border-radius: 0 !important;
    resize: vertical;
    background: #f8f9fa;
    color: #333;
}
.quill-footer {
    padding: 6px 10px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    display: flex;
    align-items: center;
}

/* ========== Family Tab: Person Row ========== */
.family-group {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.family-group-title {
    padding: 8px 14px;
    background: #f4f8f5;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.family-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
}
.family-row:last-child { border-bottom: none; }
.family-row:hover { background: #f0f7f4; }
.family-row.expanded { background: #e8f4ee; }
.family-row-body { flex: 1; min-width: 0; }
.family-row-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.family-row-name { font-weight: 600; font-size: 14px; }
.family-row-year {
    font-size: 12px;
    color: #888;
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 8px;
}

/* Chi tiết mở rộng khi bấm */
.family-detail-panel {
    padding: 12px 14px 14px 54px;
    background: #f9fffe;
    border-bottom: 1px solid #e0efe8;
    animation: fadeIn 0.12s ease-in;
}
.fdi-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.fdi-chip {
    font-size: 12px;
    background: #eef5f0;
    border: 1px solid #d0e8d8;
    border-radius: 20px;
    padding: 3px 10px;
    color: #2d6a4f;
    display: flex;
    align-items: center;
}
.fdi-bio {
    font-size: 13px;
    color: #444;
    margin-top: 6px;
    max-height: 120px;
    overflow-y: auto;
    padding-right: 4px;
}

/* Con dâu / Con rể trong tab gia đình */
.family-inlaw-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding-left: 14px;
}
.family-inlaw-connector {
    color: #e74c3c;
    font-size: 14px;
    padding-top: 12px;
    flex-shrink: 0;
}

/* Khối con */
.family-child-block {
    border-bottom: 1px solid #f0f0f0;
}
.family-child-block:last-child { border-bottom: none; }

/* Cháu (con của con) */
.family-grandchildren {
    margin-left: 28px;
    margin-top: 2px;
    border-left: 2px solid #c8e6c9;
    padding-left: 10px;
    margin-bottom: 4px;
}
.family-sub-title {
    font-size: 11px;
    font-weight: 700;
    color: #388e3c;
    padding: 4px 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Chắt (con của cháu) */
.family-gc-block { }
.family-greatgrandchildren {
    margin-left: 22px;
    border-left: 2px dashed #a5d6a7;
    padding-left: 10px;
    margin-bottom: 4px;
}

/* ========== Member Popup (Gia phả detail popup) ========== */
.member-popup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1040;
}

.member-popup-card {
    position: fixed;
    z-index: 1050;
    width: 300px;
    max-height: 80vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    border: 1px solid #e0e0e0;
    display: none;
    flex-direction: column;
    animation: popupFadeIn 0.15s ease-out;
    overflow: hidden;
}

@keyframes popupFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}

.popup-header-info {
    flex: 1;
    min-width: 0;
}

.popup-header-info .fw-bold {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-close-sm {
    width: 0.6rem;
    height: 0.6rem;
    padding: 0.4rem;
}

.popup-body {
    padding: 0.6rem 0.75rem;
    overflow-y: auto;
    flex: 1;
    font-size: 0.88rem;
}

.popup-row {
    padding: 2px 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.popup-row i {
    font-size: 0.85rem;
    width: 16px;
    text-align: center;
}

.popup-family {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #f0f0f0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.popup-family-label {
    font-size: 0.8rem;
    color: #888;
    margin-top: 4px;
}

.popup-family-item {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.popup-family-item:hover {
    background: #f0f7f0;
    color: var(--primary-color, #2c5f2d);
}

.popup-family-item i {
    font-size: 0.8rem;
    width: 14px;
    text-align: center;
}

.popup-footer {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid #f0f0f0;
}

/* ========== Lunar Calendar ========== */
.lunar-today-banner {
    background: linear-gradient(135deg, #1a237e 0%, #4a148c 100%);
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

.lunar-today-banner i {
    font-size: 1.1rem;
    color: #ffd54f;
}

.lunar-preview {
    color: var(--primary) !important;
    font-style: italic;
    margin-top: 0.25rem;
}

/* ========== Tree toggle / collapse ========== */
.tree-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.7rem;
    color: var(--primary);
    cursor: pointer;
    margin: 2px auto;
    transition: background 0.2s;
}
.tree-toggle-btn:hover {
    background: var(--primary);
    color: white;
}
.tree-collapse-count {
    font-size: 0.65rem;
    color: var(--text-muted);
}
.tree-toggle-btn:hover .tree-collapse-count {
    color: rgba(255,255,255,0.8);
}

/* ========== Tree search highlight ========== */
.tree-node-highlight {
    box-shadow: 0 0 0 3px var(--gold), 0 0 12px rgba(212, 172, 13, 0.4) !important;
    animation: tree-highlight-pulse 1.5s ease-in-out infinite;
}
@keyframes tree-highlight-pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 0 12px rgba(212, 172, 13, 0.4); }
    50% { box-shadow: 0 0 0 5px var(--gold-light), 0 0 20px rgba(241, 196, 15, 0.6); }
}

/* ========== Tree search bar ========== */
.tree-search-bar {
    display: flex;
    align-items: center;
    padding: 8px 0;
    flex-wrap: wrap;
    gap: 8px;
}

/* ========== Dâu/Rể badges in popup ========== */
.badge-dau {
    background-color: #f8d7da;
    color: #842029;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 10px;
}
.badge-re {
    background-color: #cfe2ff;
    color: #084298;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 10px;
}

/* ========== SearchableSelect ========== */
.searchable-select { position: relative; }
.searchable-select-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 1050;
    max-height: 250px; overflow-y: auto;
    background: #fff; border: 1px solid #dee2e6; border-radius: 0 0 .375rem .375rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.searchable-select-item {
    padding: 6px 12px; cursor: pointer; font-size: 0.875rem;
}
.searchable-select-item:hover { background: #f0f0f0; }
.searchable-select-item.active { background: #e8f0fe; font-weight: 600; }
