/* Reset dan dasar */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    padding: 20px;
}

/* Kontainer utama */
.organigram-container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    overflow-x: auto; /* Memungkinkan scroll horizontal */
}

/* Chart wrapper */
.organigram-chart {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
}

/* Node (setiap kotak jabatan) - SEKARANG HANYA JADI WADAH */
.node {
    display: inline-flex;
    /* Hapus semua style visual dari sini */
    min-width: 140px;
    position: relative;
    padding: 15px; /* Beri padding agar content tidak mepet */
}

/* Ini adalah kotak visual yang akan kita beri efek */
.node-content {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: #fff; /* Default background */
    border: 1px solid #ccc;
    border-radius: 8px;
    width: 100%;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.node:hover .node-content {
    transform: translateY(-8px) scale(1.05);
    box-shadow: 0 12px 24px rgba(0,0,0,0.15);
    cursor: pointer;
}

.profile-pic {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
    transition: transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Efek kilatan cahaya */
.profile-pic::after {
    content: '';
    position: absolute;
    top: 0;
    transform: translateX(-150%);
    width: 100%; /* Lebih lebar */
    height: 100%;
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0) 100%); /* Lebih terang */
    transition: transform 0.5s 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Delay setelah flip selesai */
}

.node:hover .profile-pic {
    transform: rotateY(180deg);
}

.node:hover .profile-pic::after {
    transform: translateX(150%);
}

.node p {
    margin: 0;
    font-weight: 600;
    color: #333;
}

/* Struktur Hirarki */
.level {
    display: flex;
    justify-content: center;
    position: relative;
    margin-top: 50px;
}

.branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin: 0 20px;
}

.sub-level {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap; /* Secara default, paksa tetap sejajar */
    position: relative;
    margin-top: 50px;
    padding: 0 20px; /* Beri padding agar garis tidak mentok */
}

/* Khusus untuk grup RT, izinkan untuk wrap (turun baris) */
.sub-level.rt-group {
    flex-wrap: wrap;
    max-width: 800px; /* Batasi lebar agar wrap lebih rapi */
}

/* --- GARIS KONEKTOR (LOGIKA BARU) --- */

/* Garis vertikal TURUN dari sebuah node */
.node::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translate(-50%, 100%);
    width: 2px;
    height: 26px; /* Setengah dari margin-top level */
    background-color: #ccc;
}

/* Garis vertikal NAIK dari sebuah node */
.node::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    transform: translate(-50%, -100%);
    width: 2px;
    height: 26px; /* Setengah dari margin-top level */
    background-color: #ccc;
}

/* Garis HORIZONTAL di atas sebuah level/sub-level */
.level > .branch::before,
.branch > .sub-level::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -25px; /* Sejajar dengan ujung garis vertikal */
    height: 2px;
    background-color: #ccc;
}

/* --- PENGECUALIAN & PENYESUAIAN -- */

/* CEO (paling atas) tidak punya garis ke atas */
.ceo::before { display: none; }

/* Garis horizontal utama yang menghubungkan 2 cabang di bawah CEO */
.organigram-chart > .level:first-of-type + .level::before {
    content: '';
    position: absolute;
    background-color: #ccc;
    height: 2px;
    top: -25px; /* Posisi vertikal garis */
    left: 22%;  /* Mulai dari tengah cabang kiri */
    right: 25%; /* Berakhir di tengah cabang kanan */
}

/* Garis vertikal NAIK dari node utama di setiap cabang (Yayasan & Pengurus) */
.branch > .node::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -25px;
    transform: translateX(-50%);
    width: 2px;
    height: 25px;
    background-color: #ccc;
}

/* Sembunyikan garis horizontal individual di atas setiap cabang */
.organigram-chart > .level:first-of-type + .level > .branch::before {
    display: none;
}

/* Atur garis horizontal untuk sub-level */
.branch > .sub-level::before {
    left: 15%;
    right: 15%;
}

/* Node di dalam sub-level tidak butuh garis ke bawah */
.sub-level .node::after { display: none; }

/* Node parent (Yayasan/Pengurus) butuh garis ke bawah untuk menyambung ke sub-levelnya */
.branch > .node::after { display: block; }

/* Jika hanya ada 1 anak di sub-level, jangan gambar garis horizontal */
.sub-level:has(.node:only-child)::before {
    display: none;
}

/* Node dengan class no-line tidak punya garis konektor (DIPAKSA) */
.node.no-line::after, .node.no-line::before {
    display: none !important;
}

/* --- POPUP --- */
.image-popup { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); justify-content: center; align-items: center; }
.image-popup.active { display: flex; }
.popup-image {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 10px;
    position: relative; /* Penting untuk pseudo-element */
    overflow: hidden; /* Sembunyikan kilatan di luar gambar */
}

/* Efek kilatan cahaya di popup */
.popup-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0) 100%);
    transform: translateX(-100%); /* Mulai dari kiri luar */
    transition: transform 0.6s ease-out; /* Durasi kilatan */
}

.image-popup.active .popup-image::after {
    transform: translateX(100%); /* Gerakkan kilatan ke kanan */
}
.close-button { position: absolute; top: 15px; right: 35px; color: #fff; font-size: 45px; font-weight: bold; cursor: pointer; }

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .level, .branch, .sub-level {
        flex-direction: column;
        margin-top: 30px;
    }
    .branch { margin: 0; }
    .sub-level { margin-top: 30px; }

    /* Sembunyikan semua garis horizontal */
    .level::before, .branch > .sub-level::before {
        display: none;
    }

    /* Atur ulang garis vertikal */
    .node::after { height: 15px; }
    .node::before { height: 15px; }
    .level > .branch:not(:last-child) > .node::after { display: block; }
}

/* --- ATURAN WARNA (DIPINDAHKAN KE BAWAH UNTUK PRIORITAS) --- */

/* Warna untuk RW07 */
.ceo .node-content {
    background-color: #e0f2f7; /* Biru Pastel */
    border-color: #0078d4; /* Border biru Microsoft */
}

/* Warna untuk Pengurus RW07 */
#pengurus-rw-node .node-content {
    background-color: #e0f2f7 !important; /* Biru Pastel */
    border-color: #0078d4 !important;  /* Border biru Microsoft */
}

/* Warna untuk Yayasan Poren */
#yayasan-poren-node .node-content {
    background-color: #e0ffe0 !important; /* Hijau Pastel */
    border-color: #4CAF50 !important; /* Border hijau */
}

/* Warna untuk DKM, Madrasah, Garda Lestari (anak-anak Yayasan Poren) */
#yayasan-poren-node + .sub-level > .node > .node-content {
    background-color: #e0ffe0 !important; /* Hijau Pastel */
    border-color: #4CAF50 !important; /* Border hijau */
}

/* Warna untuk semua RT */
.sub-level.rt-group .node-content {
    background-color: #fffacd; /* Krem */
    border-color: #f0e68c; /* Border kuning khaki */
}

.footer .container {
    padding: 0; /* Remove horizontal padding */
    max-width: 100%; /* Ensure it takes full width */
}