#family-tree-container {
    /*margin-top: 10px;*/
    overflow: hidden;
    position: relative;
    /*border: 1px solid #ccc;*/
    /* padding: 20px; */
}

#tree-loading {
    font-weight: bold;
    padding: 10px;
}

#family-tree-wrapper {
    cursor: grab;
    overflow: auto; cursor:grab; height:650px; position:relative;
    /* reserve more space on the left so level labels sit outside the tree */
    padding-left: 120px;
}

#family-tree {
    transform-origin: top left;
    transition: transform 0.2s ease-in-out;
    position: relative;
    width: fit-content;
}

/* Node wrapper */
.node-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin-top: 20px; /* giảm khoảng cách giữa các cấp */
}

/* Vợ/Chồng */
.spouse-group {
    display: flex;
    gap: 5px; /* giảm khoảng cách */
    padding: 5px; /* giảm padding */
    align-items: center;
    /* border-bottom: 2px solid #555; */
    position: relative;
}

/* Children wrapper */
.children {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 5px;
    position: relative;
}


.children::before {
    content: "";
    position: absolute;
    top: 0;
    left: var(--conn-left, 50%);
    right: var(--conn-right, 50%);
    height: 4px;
    border-top: 4px solid #fff;
    z-index: 1;
}


/* Đường thẳng từ cha xuống con */
.children .node-wrapper::before {
    content: "";
    position: absolute;
    top: -18px; 
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 18px;
    border-left: 4px solid #fff;
}

/* Mũi tên sắc nét */
.children .node-wrapper::after {
    content: "";
    position: absolute;
    top: -4px; 
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 10px solid #fff; /* màu mũi tên */
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2)); /* mũi tên nổi hơn */
}



/* Person Box */
.person-box {
    text-align: center;
    padding: 10px;
    background: #f8f8f8;
    border: 2px solid #555;
    border-radius: 8px;
    min-width: 80px;
    position: relative;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center; /* ảnh và tên cân giữa */
}

.person-box:hover {
    transform: scale(1.05);
    border-color: #2196f3;
}

/* Avatar */
.avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 5px; /* khoảng cách giữa ảnh và tên */
}

.avatar.placeholder {
    background: #ddd;
}

/* Controls */
 #tree-controls {
        position: absolute;
        top: 10px;
        right: 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        z-index: 50;
    }

    /* Style nút */
    .zoom-btn {
        width: 25px;
        height: 25px;
        border: none;
        border-radius: 50%;
        /* background: #a7aaad; */
         color: #fff; 
        font-size: 15px;
        font-weight: bold;
        cursor: pointer;

        display: flex;
        align-items: center;
        justify-content: center;

        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
        transition: background 0.2s, transform 0.15s;
    }

    /* Hover */
    .zoom-btn:hover {
        /* background: #a7aaad; */
        transform: scale(1.08);
    }

    /* Click effect */
    .zoom-btn:active {
        transform: scale(0.95);
    }

.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease-in-out;
}

.popup-content {
    background: #fff;
    padding: 25px 30px;
    border-radius: 16px;
    width: 340px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    position: relative;
    text-align: center;
    animation: zoomIn 0.3s ease;
}

.popup-close {
    position: absolute;
    top: 10px;
    right: 14px;
    font-size: 22px;
    cursor: pointer;
    color: #888;
    transition: 0.2s;
}
.popup-close:hover {
    color: #e74c3c;
}

.popup-title {
    margin-bottom: 15px;
    font-size: 20px;
    color: #333;
}

.popup-buttons {
    margin-bottom: 15px;
}
.popup-buttons .btn {
    margin: 4px;
}

.popup-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.popup-form input, 
.popup-form select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 14px;
    transition: border 0.2s;
}
.popup-form input:focus, 
.popup-form select:focus {
    border-color: #007bff;
    outline: none;
}

/* Nút bấm phong cách hiện đại */
.btn {
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 14px;
    cursor: pointer;
    color: white;
    transition: background 0.2s, transform 0.1s;
}
.btn:hover {
    transform: scale(1.05);
}
.btn-primary { background: #007bff; }
.btn-info { background: #17a2b8; }
.btn-warning { background: #ffc107; color: #333; }
.btn-danger { background: #e74c3c; }
.btn-success { background: #28a745; }

/* Hiệu ứng */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes zoomIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}


/* --- FORM BÊN TRONG POPUP --- */
.popup-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f9fafc;
    border-radius: 12px;
    padding: 16px;
    text-align: left;
    animation: fadeSlideIn 0.3s ease-in-out;
}

/* Tiêu đề form */
.form-title {
    text-align: center;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

/* Nhóm label + input */
.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 13px;
    color: #555;
    margin-bottom: 4px;
    font-weight: 500;
}

.popup-form input,
.popup-form select {
    padding: 10px;
    border: 1px solid #ccd1d9;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.popup-form input:focus,
.popup-form select:focus {
    border-color: #007bff;
    box-shadow: 0 0 4px rgba(0,123,255,0.3);
    outline: none;
}

/* Nút thêm thành viên */
.btn.w-100 {
    width: 100%;
    font-weight: 500;
    letter-spacing: 0.3px;
    padding: 10px;
    margin-top: 10px;
}

/* Hiệu ứng vào form */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}




/* ========================================
   HIỂN THỊ Thứ tự ĐỜI Ở BÊN TRÁI 
======================================== */
/* Cột hiển thị các đời ở bên trái */
#family-tree-levels {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    transform-origin: top left;
    /* ensure labels sit above tree members */
    z-index: 200;
}

.level-label {
    position: absolute;
    /* left is set dynamically via JS to hug the leftmost node */
    font-size: 18px;
    font-weight: bold;
    color: white;
    white-space: nowrap;
    z-index: 210;
    pointer-events: none;
}

/* --- CHỈ ÁP DỤNG TRÊN MOBILE (< 768px) --- */
@media (max-width: 768px) {
    #family-tree-levels {
        left: -150px !important;
    }
}

