/* ====================================================
   DESAIN LAYOUT UTAMA (ANTI-SCROLL LAYAR UTAMA)
   ==================================================== */
body { 
    margin: 0; 
    padding: 0;
    display: block; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    height: 100vh; 
    height: 100dvh; /* Kunci ukuran layar HP dinamis */
    background: #2b2b2b; 
    overflow: hidden; 
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* Layout Wrapper Utama menggunakan flexbox horizontal */
.main-wrapper {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Paksa wrapper mengikuti tinggi layar asli HP */
    position: relative;
    overflow: hidden;
}

/* Panel Kiri: Daftar Isi (Desktop: Menetap, Mobile: Melayang) */
#sidebar { 
    width: 280px; 
    background: #1e1e1e; 
    color: #fff; 
    padding: 20px 15px; 
    overflow-y: auto; 
    box-shadow: 4px 0 15px rgba(0,0,0,0.4);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 99;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#sidebar h3 { 
    border-bottom: 2px solid #3a3a3a; 
    padding-bottom: 12px; 
    margin-top: 0; 
    color: #e0b034; 
    font-size: 18px;
    letter-spacing: 0.5px;
}

#list-bab {
    flex: 1;
    overflow-y: auto;
}

.bab-item { 
    padding: 14px 12px; 
    cursor: pointer; 
    border-bottom: 1px solid #2a2a2a; 
    font-size: 14px; 
    border-radius: 6px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    color: #ccc;
}
.bab-item:hover, .bab-item:active { 
    background: #333; 
    color: #e0b034; 
    transform: translateX(3px);
}

/* Panel Kanan: Wadah Konten Utama (Header, Viewport, Toolbar) */
#viewer-container { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
    height: 100dvh; /* Kunci container utama agar tidak melar akibat kanvas */
    position: relative; 
    background: #232323;
    overflow: hidden;
}

/* ====================================================
   HEADER & NAVBAR ATAS
   ==================================================== */
#app-header {
    background: #111;
    color: #fff;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between; 
    box-shadow: 0 3px 10px rgba(0,0,0,0.5);
    z-index: 10;
    height: 56px; /* Tinggi konstan */
}

#app-title {
    font-weight: bold;
    font-size: 16px;
    color: #e0b034; 
    letter-spacing: 0.5px;
}

/* Tombol Menu Hamburger */
#btn-menu { 
    background: #e0b034; 
    color: #111; 
    border: none; 
    font-size: 14px;
    font-weight: bold;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    display: none; /* Sembunyi di Desktop */
    transition: background 0.2s;
}
#btn-menu:hover { background: #f0c24a; }

/* ====================================================
   AREA TENGAH: VIEWPORT CANVAS (ANTI-LUBER & RESPONSIVE)
   ==================================================== */
#canvas-viewport { 
    flex: 1; 
    min-height: 0; /* JURUS RAHASIA: Memaksa flexbox agar areanya bisa mengecil di HP */
    overflow: auto; 
    display: flex; 
    justify-content: center; 
    align-items: flex-start; 
    padding: 10px; 
    background: #2b2b2b;
    -webkit-overflow-scrolling: touch; 
}

/* KUNCI UTAMA RESPONSIVITAS KANVAS */
canvas { 
    background: white; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.6); 
    display: block;
    max-width: 100% !important; /* Memaksa lebar kanvas tidak boleh melebihi layar HP */
    height: auto !important;     /* Membiarkan tinggi kanvas menyesuaikan rasio PDF */
    border-radius: 4px;
    transition: transform 0.2s ease;
}

/* ====================================================
   UI GLOBAL BUTTONS STYLE
   ==================================================== */
button { 
    cursor: pointer; 
    padding: 8px 14px; 
    background: #3a3a3a; 
    color: #fff; 
    border: 1px solid #4a4a4a; 
    border-radius: 6px;
    font-weight: bold;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
button:hover { background: #4a4a4a; border-color: #5a5a5a; }
button:active { transform: scale(0.95); }

/* ====================================================
   TOOLBAR / NAVIGASI BAWAH
   ==================================================== */
#toolbar { 
    background: #111; 
    padding: 10px 15px; 
    color: white; 
    display: flex; 
    gap: 10px; 
    align-items: center; 
    justify-content: center; 
    box-shadow: 0 -4px 15px rgba(0,0,0,0.5);
    z-index: 10;
    height: 60px; 
    width: 100%;
    max-width: 100%; /* Mencegah meluber keluar dari container utama */
    box-sizing: border-box; /* Memastikan padding dihitung di dalam lebar 100% */
    flex-shrink: 0; 
}

#toolbar span {
    font-weight: 500;
}

.page-controller {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: bold;
}

/* Kotak Input Lompat Halaman */
/* Mengubah tampilan input page-num agar menyatu seperti teks biasa tapi bisa diketik */
#page-num {
    width: 45px;
    padding: 5px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0b034; /* Warna emas khas aplikasi kamu */
    text-align: center;
    font-weight: bold;
    font-size: 14px;
    -moz-appearance: textfield; /* Sembunyikan panah up/down bawaan browser */
}
#page-num::-webkit-outer-spin-button,
#page-num::-webkit-inner-spin-button {
    -webkit-appearance: none; /* Sembunyikan panah up/down di Chrome/Safari */
    margin: 0;
}
#page-num:focus {
    border-color: #e0b034;
    background: #333;
    outline: none;
}

/* Indikator Persentase Bacaan */
#progress-baca {
    color: #e0b034;
    font-weight: bold;
    min-width: 45px;
    text-align: center;
}

/* Overlay Hitam Belakang Sidebar di HP */
#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(3px); /* Efek blur modern di HP */
    z-index: 98;
}

/* ====================================================
   MEDIA QUERY KHUSUS HP (SCREEN MAKSIMAL 768px)
   ==================================================== */
@media (max-width: 768px) {
    #btn-menu { 
        display: block; /* Tampilkan tombol hamburger di HP */
    }
    
    /* Sembunyikan sidebar ke kiri luar layar dengan posisi fixed melayang */
    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        transform: translateX(-100%);
        height: 100%;
    }

    /* Kelas pemicu dinamis saat menu diklik di HP */
    #sidebar.aktif { 
        transform: translateX(0); 
    }
    #sidebar-overlay.show { 
        display: block; 
    }

    /* Optimalisasi Toolbar Bawah di HP agar muat & presisi */
    #toolbar {
        justify-content: space-between; /* Tombol kiri, tengah, kanan terbagi adil */
        padding: 10px 12px;
        gap: 5px;
    }

    #toolbar button {
        padding: 8px 12px; /* Ukuran tombol lebih ramah sentuhan jari */
    }

    #goto-page {
        width: 45px;
        padding: 5px;
    }
    
    #canvas-viewport { 
        padding: 8px; /* Memperlebar ruang kanvas di layar HP yang sempit */
    }
}