/* ==========================================================================
   FAMILY TREE - GIAO DIỆN GIA PHẢ CỔ TRUYỀN v4.3.0
   ========================================================================== */

/* RESET & GLOBAL */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Roboto', Arial, sans-serif;
    overflow: hidden;
}

/* ============================================
   1. NỀN TRANG WEB - DÙNG bg2.webp
   ============================================ */
body {
    background: #f5e6c8 url('../images/bg2.webp') center center no-repeat !important;
    background-size: cover !important;
    background-attachment: fixed !important;
}

/* ============================================
   2. HEADER - THANH ĐIỀU KHIỂN
   ============================================ */
.family-tree-controls {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 44px !important;
    /* Thấp hơn chút nữa */
    z-index: 9999 !important;

    background: #5d0000 url('../images/ui/header_bg.jpg') center bottom no-repeat !important;
    background-size: cover !important;

    border-bottom: 2px solid #d4af37 !important;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5) !important;

    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 12px !important;
}

/* Tiêu đề - Luôn ở chính giữa tuyệt đối */
.main-title {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    margin: 0 !important;
    color: #f1c40f !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    text-shadow: 1px 1px 2px #000 !important;
    font-family: 'Roboto', Arial, sans-serif !important;
    z-index: 1 !important;
    white-space: nowrap !important;
}

/* Đảm bảo nút điều khiển luôn ở bên phải */
.tree-btn-group {
    display: flex !important;
    gap: 4px !important;
    margin-left: auto !important;
    position: relative !important;
    z-index: 2 !important;
}

.divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 3px;
}

/* NÚT HEADER - SIÊU NHỎ */
.tree-control-btn {
    background: #7b1113 !important;
    color: #ffd700 !important;
    border: 1px solid #ffd700 !important;
    border-radius: 3px !important;
    padding: 0 5px !important;
    height: 22px !important;
    /* Siêu thấp */
    font-size: 10px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: background 0.2s ease, opacity 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    gap: 2px !important;
    font-family: 'Roboto', Arial, sans-serif !important;
    justify-content: center !important;
}

.tree-control-btn:hover {
    background: #a01515 !important;
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.4) !important;
}

.tree-control-btn.active {
    background: #f1c40f !important;
    color: #5d0000 !important;
}

/* Icon trong nút */
.tree-control-btn span {
    color: #ffd700 !important;
    font-size: 13px !important;
}

.tree-control-btn.active span {
    color: #5d0000 !important;
}


/* ============================================
   3. VÙNG CÂY GIA PHẢ (CANVAS)
   ============================================ */
#tree {
    width: 100% !important;
    height: 100vh !important;
    margin: 0 !important;
    padding-top: 44px !important;
    /* Khớp header mới */
    background: transparent !important;
    overflow: hidden !important;
}

#tree svg {
    background: transparent !important;
}

/* ===== FIX NỀN ĐEN - SVG RECT BACKGROUND ===== */
.chart-bg {
    fill: transparent !important;
    fill-opacity: 0 !important;
}

.chart-container {
    background: transparent !important;
}

/* ============================================
   4. NODE/CARD (SVG)
   ============================================ */
.node {
    cursor: pointer;
}

.box {
    fill: #fffbef;
    stroke: #8b4513;
    stroke-width: 2px;
    rx: 6;
    ry: 6;
    filter: drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.3));
    transition: all 0.2s;
}

.box:hover {
    stroke: #d4af37;
    stroke-width: 3px;
}

.box--male {
    stroke: #b71c1c !important;
    /* Đỏ */
    stroke-width: 3px !important;
}

.box--female {
    stroke: #d4af37 !important;
    /* Vàng */
    stroke-width: 3px !important;
}

.node-name {
    font-size: 13px;
    font-weight: 700;
    fill: #b71c1c !important;
    /* Tên màu đỏ */
    text-transform: uppercase;
    font-family: 'Roboto', Arial, sans-serif;
}

.node-subtext {
    font-size: 11px;
    fill: #5d4037 !important;
    font-family: 'Roboto', Arial, sans-serif;
}

.node-spouse-list {
    font-size: 10.5px;
    font-weight: 700;
    fill: #8a5264 !important;
    font-family: 'Roboto', Arial, sans-serif;
}

.age-badge-bg {
    fill: #ffd966 !important;
    stroke: #b71c1c !important;
    stroke-width: 1.6px !important;
    rx: 8;
    ry: 8;
}

.age-badge-text {
    fill: #b71c1c !important;
    font-size: 8.5px !important;
    font-weight: 400 !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

/* BADGE - Đời */
.badge-bg {
    fill: #7b1113 !important;
    /* Nền đỏ đậm */
    rx: 4;
    ry: 4;
}

.badge-text {
    fill: #f1c40f !important;
    /* Chữ vàng */
    font-size: 10px !important;
    font-weight: 700 !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

.link {
    fill: none;
    stroke: #5d4037;
    stroke-width: 2px;
    opacity: 0.7;
}

.add-member-btn {
    cursor: pointer !important;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.add-member-btn:hover {
    opacity: 1 !important;
}

.add-member-btn circle {
    fill: #2e7d32 !important;
    stroke: #fff !important;
    stroke-width: 2px !important;
}

.add-member-btn text {
    fill: #fff !important;
    font-size: 14px !important;
    font-weight: bold !important;
}

/* ============================================
   5. POPUP MODAL - ẢNH MỚI modal_frame.png
   ============================================ */
.ft-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.75) !important;
    z-index: 99999 !important;
    display: none !important;
    /* Luôn ẩn mặc định */
    align-items: center !important;
    justify-content: center !important;
}

/* Khi cần hiện thì ép flex */
.ft-modal.active {
    display: flex !important;
}

/* BỎ NỀN POPUP - CHỈ DÙNG MÀU NỀN */
.ft-modal-content {
    background: #fdf5e6 !important;
    background-image: none !important;

    border: 4px double #7b1113 !important;
    border-radius: 8px !important;
    outline: 2px solid #d4af37 !important;
    outline-offset: -8px !important;

    padding: 35px 30px 25px !important;

    width: 90% !important;
    max-width: 520px !important;
    max-height: 85vh !important;
    overflow-y: auto !important;

    position: relative !important;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6) !important;
}

/* NÚT ĐÓNG */
.ft-close-modal {
    position: absolute !important;
    top: 10px !important;
    right: 15px !important;
    font-size: 24px !important;
    color: #7b1113 !important;
    cursor: pointer !important;
    font-weight: bold !important;
    z-index: 10 !important;
}

.ft-close-modal:hover {
    color: #d00 !important;
}

/* TIÊU ĐỀ POPUP */
#ft-modalTitle {
    text-align: center !important;
    color: #7b1113 !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    margin: 0 0 18px 0 !important;
    padding-bottom: 8px !important;
    border-bottom: 2px solid #d4af37 !important;
    letter-spacing: 1px !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

/* FORM */
.ft-modal-body {
    margin-top: 5px;
}

.ft-form-group {
    margin-bottom: 10px !important;
}

.ft-form-group label {
    display: block !important;
    margin-bottom: 3px !important;
    font-weight: 600 !important;
    color: #5d4037 !important;
    font-size: 12px !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

/* INPUT FIELDS */
.ft-form-group input[type="text"],
.ft-form-group input[type="number"],
.ft-form-group input[type="file"],
.ft-form-group select,
.ft-form-group textarea {
    width: 100% !important;
    padding: 7px 9px !important;
    border: 1px solid #a1887f !important;
    border-radius: 4px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    font-size: 16px !important;
    /* Fix zoom on mobile focus */
    color: #333 !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

.ft-form-group input:focus,
.ft-form-group select:focus {
    outline: none !important;
    border-color: #d4af37 !important;
    background: #fff !important;
}

/* GRID LAYOUT */
.ft-form-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
}

.ft-form-row-3 {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 8px !important;
}

.ft-form-row .ft-form-group,
.ft-form-row-3 .ft-form-group {
    margin-bottom: 0 !important;
}

/* TABS CHỌN LOẠI */
.ft-relation-selector {
    display: flex !important;
    gap: 6px !important;
    margin-bottom: 15px !important;
}

.ft-rel-btn {
    flex: 1 !important;
    padding: 7px 4px !important;
    text-align: center !important;
    background: #f5f5f5 !important;
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    color: #555 !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

.ft-rel-btn:hover {
    background: #eee !important;
}

.ft-rel-btn.active {
    background: #7b1113 !important;
    color: #fff !important;
    border-color: #5d0000 !important;
}

/* NÚT HÀNH ĐỘNG */
.ft-modal-actions {
    margin-top: 18px !important;
    padding-top: 10px !important;
    border-top: 1px solid #ddd !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 8px !important;
}

.ft-primary-btn,
.ft-secondary-btn {
    padding: 7px 20px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    cursor: pointer !important;
    border: none !important;
    font-family: 'Roboto', Arial, sans-serif !important;
}

.ft-primary-btn {
    background: #b71c1c !important;
    color: #fff !important;
}

.ft-primary-btn:hover {
    background: #d32f2f !important;
}

.ft-secondary-btn {
    background: #8d6e63 !important;
    color: #fff !important;
}

.ft-secondary-btn:hover {
    background: #6d4c41 !important;
}

/* RESPONSIVE */
@media (max-width: 768px) {

    /* HEADER 2 DÒNG TRÊN MOBILE */
    .family-tree-controls {
        height: auto !important;
        flex-direction: column !important;
        padding: 8px 10px !important;
        gap: 6px !important;
    }

    .main-title {
        position: static !important;
        transform: none !important;
        left: auto !important;
        top: auto !important;
        font-size: 14px !important;
        letter-spacing: 0.5px !important;
        order: 1 !important;
        text-align: center !important;
        width: 100% !important;
    }

    .tree-btn-group {
        position: static !important;
        margin-left: 0 !important;
        order: 2 !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 3px !important;
    }

    .tree-control-btn {
        padding: 0 6px !important;
        height: 26px !important;
        font-size: 11px !important;
    }

    .tree-control-btn span {
        font-size: 12px !important;
    }

    .divider {
        display: none !important;
    }

    /* Tree margin for taller header */
    #tree {
        padding-top: 85px !important;
    }

    .ft-modal-content {
        width: 95% !important;
        padding: 30px 18px 18px !important;
    }

    #ft-modalTitle {
        font-size: 14px !important;
    }

    .ft-form-row,
    .ft-form-row-3 {
        grid-template-columns: 1fr !important;
    }
}

/* Màn hình rất nhỏ */
@media (max-width: 400px) {
    .main-title {
        font-size: 12px !important;
    }

    .tree-control-btn {
        padding: 0 5px !important;
        height: 24px !important;
        font-size: 10px !important;
    }

    .tree-control-btn span {
        font-size: 11px !important;
    }
}
