/* --- NEW: Responsive Scroll Wrapper --- */
.tree-wrapper {
    width: 100%;
    overflow-x: auto;
    /* Allows smooth horizontal scrolling on phones */
    -webkit-overflow-scrolling: touch;
    /* Momentum scrolling for iOS */
    text-align: center;
    padding: 50px 0;
}

.org-tree {
    display: inline-block;
    margin: 0 auto;
    text-align: center;
    min-width: 1100px;
    /* Forces the chart to hold its shape on small screens */
    padding: 0 40px;
    /* Adds breathing room so cards don't touch the screen edge */
}

.org-tree ul {
    display: flex;
    justify-content: center;
    position: relative;
    padding-top: 35px;
    margin: 0;
    padding-left: 0;
}

.org-tree li {
    list-style-type: none;
    position: relative;
    padding: 35px 10px 0 10px;
    text-align: center;
}

/* --- Standard Connecting lines --- */
.org-tree li::before,
.org-tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 1.5px solid #d0d0d0;
    width: 50%;
    height: 35px;
    z-index: -1;
}

.org-tree li::after {
    right: auto;
    left: 50%;
    border-left: 1.5px solid #d0d0d0;
}

.org-tree li:only-child::after,
.org-tree li:only-child::before {
    display: none;
}

.org-tree li:only-child {
    padding-top: 0;
}

.org-tree li:first-child::before,
.org-tree li:last-child::after {
    border: 0 none;
}

.org-tree li:last-child::before {
    border-right: 1.5px solid #d0d0d0;
    border-radius: 0 5px 0 0;
}

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

/* Standard downward line for normal groups */
.org-tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 1.5px solid #d0d0d0;
    width: 0;
    height: 35px;
    z-index: -1;
    transform: translateX(-50%);
}

/* --- Guaranteed Lines & Spacing --- */

/* 1. The Main Vertical Trunk Line */
.org-tree ul.trunk-container {
    padding-top: 230px;
}

.org-tree ul.trunk-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 1.5px;
    height: 230px;
    background-color: #d0d0d0;
    border: none;
    transform: translateX(-50%);
}

/* 2. Position the Penasihat node to the side */
.org-tree .staff-node {
    position: absolute;
    top: 20px;
    left: 50%;
    margin-left: -280px;
    width: 240px;
    padding: 0;
    z-index: 10;
}

/* 3. Draw the horizontal connecting line for Penasihat */
.org-tree .staff-node::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    width: 40px;
    height: 1.5px;
    background-color: #d0d0d0;
    border: none;
    z-index: -1;
}

.org-tree .staff-node::before {
    display: none !important;
}

/* 4. Clean up standard lines on the bottom row wrapper */
.org-tree li.regular-branches-wrapper {
    padding-top: 0;
}

.org-tree li.regular-branches-wrapper::before,
.org-tree li.regular-branches-wrapper::after {
    display: none;
}

.org-tree li.regular-branches-wrapper>ul {
    padding-top: 0;
}

.org-tree li.regular-branches-wrapper>ul::before {
    display: none;
}

/* --- Styling the clickable boxes --- */
.org-tree li a {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    background: #fff;
    padding: 20px 25px;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    width: 240px;
    box-sizing: border-box;
}

.org-tree li a:hover {
    background: #ffffff;
    border-color: #bbdefb;
    transform: translateY(-5px);
    box-shadow: 0 8px 18px rgba(33, 150, 243, 0.1);
}

/* --- Avatar styling --- */
.avatar-container {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #e1e1e1;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 12px;
    position: relative;
    border: 4px solid transparent;
    transition: border-color 0.3s ease;
}

.avatar-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-container::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    bottom: -4px;
    left: -4px;
    border: 1.5px solid #b0bec5;
    border-radius: 50%;
    box-sizing: content-box;
}

/* Text formatting */
.name {
    font-weight: bold;
    font-size: 15px;
    color: #1a1a1a;
    display: block;
    margin-bottom: 5px;
    text-align: center;
}

.title {
    font-size: 12px;
    color: #757575;
    display: block;
    text-align: center;
    line-height: 1.4;
}

/* --- MOBILE RESPONSIVE: FOOLPROOF VERTICAL LIST --- */
@media (max-width: 768px) {

    /* 1. Reset all containers to strict vertical blocks */
    .org-tree {
        padding: 10px;
        width: 100%;
        min-width: auto;
        box-sizing: border-box;
    }

    .tree-wrapper {
        padding: 10px;
        overflow-x: hidden;
    }

    .org-tree ul {
        display: block !important;
        /* Forces vertical stacking, kills overlaps */
        padding: 0;
        margin: 0;
    }

    .org-tree li {
        display: block !important;
        /* Forces vertical stacking */
        padding: 0;
        margin: 0 0 15px 0;
        /* 15px gap between all cards */
        position: relative;
        text-align: left;
        width: 100%;
    }

    .org-tree li:last-child {
        margin-bottom: 0;
    }

    /* Prevents line from dangling at the bottom */

    /* 2. Annihilate ALL desktop connecting lines and spacing */
    .org-tree *::before,
    .org-tree *::after {
        display: none !important;
    }

    .org-tree ul.trunk-container {
        padding-top: 0 !important;
    }

    /* 3. Reset specific desktop hacks (staff node offset) */
    .org-tree .staff-node {
        position: static !important;
        margin: 0 0 15px 0 !important;
        width: 100% !important;
    }

    .org-tree li.regular-branches-wrapper {
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 4. Format the Cards for Mobile (Avatar left, Text right) */
    .org-tree li a {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        width: 100% !important;
        padding: 12px 15px !important;
        box-sizing: border-box !important;
        height: auto !important;
        /* Allows box to grow naturally */
    }

    .org-tree .avatar-container {
        width: 50px !important;
        height: 50px !important;
        margin: 0 15px 0 0 !important;
        flex-shrink: 0 !important;
    }

    .org-tree .name {
        text-align: left !important;
        margin-bottom: 2px !important;
    }

    .org-tree .title {
        text-align: left !important;
    }

    /* 5. Draw simple, unbroken mobile hierarchy lines */
    /* Indent the whole trunk container and draw one long line down the left */
    .org-tree ul.trunk-container {
        margin-left: 25px !important;
        /* Push everything right */
        padding-left: 15px !important;
        /* Space between line and cards */
        border-left: 2px solid #b0bec5 !important;
        /* The main continuous vertical line */
    }

    /* Draw the horizontal ticks connecting the vertical line to the cards */
    .org-tree ul.trunk-container>li.staff-node::before,
    .org-tree li.regular-branches-wrapper>ul>li::before {
        display: block !important;
        content: '' !important;
        position: absolute !important;
        left: -15px !important;
        /* Reaches back to touch the vertical border */
        top: 37px !important;
        /* Points exactly to the middle of the avatar */
        width: 15px !important;
        border-top: 2px solid #b0bec5 !important;
    }

    /* Prevent nested ULs from indenting twice */
    .org-tree li.regular-branches-wrapper>ul {
        padding-left: 0 !important;
        margin-left: 0 !important;
        border: none !important;
    }
}

/* --- MOBILE RESPONSIVE: THE ULTIMATE FIX --- */
@media (max-width: 768px) {

    /* 1. Reset the entire canvas and force Top-to-Bottom Flow */
    .tree-wrapper {
        padding: 20px 10px;
        overflow-x: hidden;
    }

    .org-tree {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .org-tree ul {
        display: block !important;
        position: static !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .org-tree li {
        display: block !important;
        position: relative !important;
        padding: 0 !important;
        margin: 0 0 15px 0 !important;
        width: 100% !important;
    }

    /* 2. Kill ALL desktop lines and offsets completely */
    .org-tree li::before,
    .org-tree li::after,
    .org-tree ul::before,
    .org-tree ul::after,
    .org-tree .staff-node::before,
    .org-tree .staff-node::after {
        display: none !important;
        content: none !important;
    }

    .org-tree ul.trunk-container {
        padding-top: 0 !important;
    }

    .org-tree .staff-node {
        position: static !important;
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* 3. The Cards: CSS Grid forces perfect Avatar + Text layout without overlapping */
    .org-tree li a {
        display: grid !important;
        grid-template-columns: 50px 1fr !important;
        grid-template-rows: auto auto !important;
        column-gap: 15px !important;
        row-gap: 2px !important;
        background: #fff !important;
        padding: 15px !important;
        border-radius: 10px !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
        width: 100% !important;
        box-sizing: border-box !important;
        height: auto !important;
        transform: none !important;
    }

    .org-tree .avatar-container {
        grid-column: 1 / 2 !important;
        grid-row: 1 / 3 !important;
        width: 50px !important;
        height: 50px !important;
        margin: 0 !important;
    }

    .org-tree .name {
        grid-column: 2 / 3 !important;
        grid-row: 1 / 2 !important;
        text-align: left !important;
        margin: 0 !important;
        align-self: end !important;
        font-size: 15px !important;
    }

    .org-tree .title {
        grid-column: 2 / 3 !important;
        grid-row: 2 / 3 !important;
        text-align: left !important;
        margin: 0 !important;
        align-self: start !important;
        font-size: 12px !important;
    }

    /* 4. Mobile Hierarchy Lines (File Directory Style) */
    .org-tree ul.trunk-container {
        margin-left: 20px !important;
        padding-left: 15px !important;
        border-left: 2px solid #b0bec5 !important;
    }

    .org-tree li.regular-branches-wrapper>ul {
        margin-left: 0 !important;
        padding-left: 0 !important;
        border-left: none !important;
    }

    .org-tree li.regular-branches-wrapper {
        margin-bottom: 0 !important;
    }

    /* Draw the horizontal connection to each card */
    .org-tree ul.trunk-container>li.staff-node::before,
    .org-tree li.regular-branches-wrapper>ul>li::before {
        display: block !important;
        content: '' !important;
        position: absolute !important;
        left: -15px !important;
        top: 40px !important;
        width: 15px !important;
        height: 2px !important;
        background-color: #b0bec5 !important;
        z-index: 1 !important;
    }
}