/* --- CSS VARIABLES & THEMES --- */
:root {
    --primary: #0f172a;
    --accent: #db2777; 
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #cbd5e1;
    --danger: #dc2626;
    --secondary-btn: #64748b;
    --text-muted: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

/* Dark Mode Variables */
body.dark-mode {
    --primary: #f1f5f9;
    --bg: #0f172a; 
    --card-bg: #1e293b; 
    --border: #334155;
    --secondary-btn: #94a3b8;
    --text-muted: #94a3b8;
    --modal-overlay: rgba(0, 0, 0, 0.7);
}

body.dark-mode .form-group label { color: var(--primary); }
body.dark-mode .col-code { color: #ffffff; }

/* Transition */
body, .card, input, .btn, th, td, .card-header, label, .guide-icon, .toggle-btn, .col-code {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--primary); margin: 0; padding: 20px; }
.container { max-width: 1400px; margin: 0 auto; }

/* HEADER */
header { 
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; 
    padding-bottom: 20px; border-bottom: 1px solid var(--border);
    position: relative; z-index: 60;
}
.header-content { text-align: left; }
h1 { font-weight: 800; font-size: 1.8rem; margin-bottom: 5px; margin-top: 0; }
p { color: var(--text-muted); margin: 0; }

.header-controls { display: flex; gap: 10px; }
.toggle-btn {
    background: transparent; border: 2px solid var(--border); color: var(--primary);
    padding: 8px 12px; border-radius: 20px; cursor: pointer; font-size: 0.9rem; font-weight: 600;
    display: flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif;
}
.toggle-btn:hover { background: var(--border); }
.toggle-icon { font-size: 1.2rem; }

/* INPUT PANEL */
.input-panel {
    background: var(--card-bg); padding: 25px; border-radius: 12px;
    border: 1px solid var(--border); margin-bottom: 30px; box-shadow: var(--shadow);
    position: relative; z-index: 50;
}
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
.form-group { position: relative; }
.label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }

.form-group label { 
    font-size: 0.75rem; font-weight: 700; color: #000000; 
    text-transform: uppercase; margin: 0; 
}

.guide-icon {
    background: var(--border); color: var(--text-muted); border-radius: 50%; width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: bold;
    cursor: pointer; z-index: 55; position: relative;
}
.guide-icon:hover { background: var(--accent); color: white; }

.form-group input {
    width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px;
    font-family: 'JetBrains Mono'; font-weight: 600; background: var(--card-bg); color: var(--primary);
    box-sizing: border-box; 
}
.form-group.has-error input { border-color: var(--danger); background-color: rgba(220, 38, 38, 0.1); }
.error-msg { color: var(--danger); font-size: 0.7rem; margin-top: 4px; display: none; }
.form-group.has-error .error-msg { display: block; }

/* BUTTON AREA */
.button-area {
    grid-column: 1 / -1; margin-top: 25px; display: flex; gap: 10px; flex-wrap: wrap;
    position: relative; z-index: 55;
}
.btn {
    padding: 12px 20px; flex-grow: 1; font-weight: 700; border-radius: 8px; cursor: pointer;
    font-family: 'Inter', sans-serif; font-size: 0.9rem; border: 2px solid transparent;
}
.btn-calc { background: var(--primary); color: var(--bg); border-color: var(--primary); }
.btn-calc:hover { background: var(--accent); border-color: var(--accent); color: white; }
.btn-print { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-print:hover { background: var(--primary); color: var(--bg); }
.btn-reset { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-reset:hover { background: var(--primary); color: var(--bg); }

/* LAYOUT PATTERNS */
.grid-patterns { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 30px; position: relative; z-index: 1; }

.card {
    background: var(--card-bg); border-radius: 12px; border: 1px solid var(--border);
    overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.card-header {
    padding: 15px; background: var(--border); border-bottom: 1px solid var(--border);
    font-weight: 700; text-align: center; color: var(--primary);
}

.img-area {
    position: relative; width: 100%; background: #fff; border-bottom: 1px solid var(--border);
    min-height: 400px; z-index: 5;
}
body.dark-mode .img-area img { opacity: 0.9; filter: contrast(1.1); }
.img-area img { width: 100%; height: auto; display: block; transition: 0.3s; }

.lbl {
    position: absolute; transform: translate(-50%, -50%);
    padding: 3px 8px; border-radius: 4px; border: 1px solid #ffffff;
    font-family: 'JetBrains Mono'; font-size: 11px; font-weight: 700;
    white-space: nowrap; z-index: 10;
    color: #000000 !important; background: #ffffff !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15); 
    transition: all 0.3s ease; pointer-events: none;
}
.lbl.req { z-index: 20; font-weight: 800; border-color: var(--accent); } 

/* TABEL */
.table-container { 
    padding: 0; 
    max-height: 600px; 
    overflow-y: auto; 
    overflow-x: hidden;
}
table { 
    width: 100%; 
    border-collapse: collapse; 
    font-size: 0.8rem;
    table-layout: fixed;
}
th { 
    text-align: left; 
    padding: 10px 8px; 
    background: var(--border); 
    color: var(--primary);
    border-bottom: 2px solid var(--border); 
    position: sticky; top: 0; z-index: 25; vertical-align: top;
}
td { 
    padding: 8px 8px;
    border-bottom: 1px solid var(--border); 
    vertical-align: middle; 
}

tr.section-row td { background: var(--border); font-weight: 700; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 10px; }
.col-code { 
    font-family: 'JetBrains Mono'; font-weight: 700; color: #000000; 
    width: 13%;
}
td:nth-child(2), th:nth-child(2) { width: 57%; word-wrap: break-word; white-space: normal; }
.col-res { 
    font-family: 'JetBrains Mono'; font-weight: 700; text-align: right; 
    white-space: nowrap; width: 30%; 
}
tr.highlight-row td { background-color: rgba(219, 39, 119, 0.1); color: var(--accent); }

/* MODAL */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay); z-index: 100;
    display: none; justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.3s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-content {
    background: var(--card-bg); padding: 25px; border-radius: 12px; max-width: 500px; width: 90%;
    box-shadow: var(--shadow); position: relative; transform: translateY(20px); transition: transform 0.3s ease;
        z-index: 101;
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-close {
    position: absolute; top: 15px; right: 20px; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); z-index: 102;
}
.modal-body h3 { margin-top: 0; color: var(--primary); }
.modal-img-container {
    width: 100%; height: 250px; background: var(--border); margin: 15px 0; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.modal-img-container img { max-width: 100%; max-height: 100%; object-fit: contain; }
.modal-desc { font-size: 0.9rem; line-height: 1.5; color: var(--primary); }


/* ============================================
    CSS KHUSUS PRINT / PDF (PERBAIKAN UTAMA)
    ============================================ */
@media print {
    /* 1. Atur Halaman */
    @page {
        margin: 1cm; /* Margin kertas */
        size: auto;
    }

    /* 2. Sembunyikan Elemen Tidak Perlu */
    header, .input-panel, .button-area, .guide-icon, .modal-overlay, .error-msg {
        display: none !important;
    }

    /* 3. Reset Container Utama */
    body {
        background: white;
        color: black;
        padding: 0;
        margin: 0;
        font-family: 'Inter', serif; /* Serif lebih mudah dibaca di kertas */
        -webkit-print-color-adjust: exact; /* Paksa cetak warna background jika ada */
        print-color-adjust: exact;
    }

    .container {
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    /* 4. Layout Kartu (Agar tidak terpotong) */
    .grid-patterns {
        display: block; /* Ubah grid jadi block agar turun ke bawah secara alami */
        gap: 0;
    }

    .card {
        break-inside: avoid; /* Mencegah kartu terpotong di tengah */
        page-break-inside: avoid;
        border: 1px solid #000; /* Border hitam tajam */
        box-shadow: none;
        margin-bottom: 25px; /* Jarak antar pola */
        display: block;
        
        /* OPSI: Paksa 1 Pola per Halaman agar rapi */
        page-break-after: always; 
    }
    
    /* Jangan page-break setelah kartu terakhir */
    .card:last-child {
        page-break-after: auto;
    }

    .card-header {
        background: #ddd !important; /* Abu-abu terang untuk header */
        color: #000 !important;
        border-bottom: 1px solid #000;
        text-align: center;
        font-size: 1.2rem;
        padding: 10px;
    }

    /* 5. Perbaikan Gambar & Label */
    .img-area {
        border-bottom: 1px solid #000;
        /* Pastikan gambar tidak terlalu besar */
        max-height: 50vh; 
        overflow: hidden;
    }
    .img-area img {
        max-height: 50vh;
        width: auto;
        margin: 0 auto;
    }
    
    /* Label di atas gambar */
    .lbl {
        border: 1px solid #000 !important;
        background: #fff !important;
        color: #000 !important;
        box-shadow: none !important;
        font-weight: bold !important;
    }

    /* 6. Perbaikan Tabel (PENTING: Hilangkan Scrollbar) */
    .table-container {
        max-height: none !important; /* Biarkan tabel memanjang ke bawah */
        overflow: visible !important; /* Hilangkan scrollbar */
        height: auto !important;
        display: block;
    }

    table {
        width: 100%;
        font-size: 10pt; /* Ukuran font cetak yang nyaman */
        page-break-inside: auto;
    }
    
    tr {
        page-break-inside: avoid; /* Usahakan baris tidak terpotong */
        page-break-after: auto;
    }

    th, td {
        border: 1px solid #ccc !important;
        padding: 6px 8px;
        color: #000 !important;
    }

    th {
        background-color: #eee !important;
        font-weight: bold;
        border-bottom: 2px solid #000 !important;
    }
    
    /* Styling khusus baris */
    tr.section-row td {
        background-color: #f4f4f4 !important;
        border-top: 2px solid #000;
        font-weight: bold;
        color: #000 !important;
    }
    
    tr.highlight-row td {
        background-color: #fff !important; /* Hilangkan warna pink saat print */
        font-weight: bold; /* Ganti dengan bold */
    }
    
    /* Reset warna teks kode */
    .col-code { color: #000 !important; }
}
/* --- ANIMASI TAMBAHAN UNTUK TAMPILAN LAYAR (SCREEN ONLY) --- */
@media screen {

    /* 1. Animasi Kartu Muncul (Fade In Up) */
    @keyframes fadeInUp {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .card {
        /* Kartu akan muncul pelan-pelan */
        animation: fadeInUp 0.6s ease-out forwards;
        opacity: 0; /* Mulai transparan */
    }
    
    /* Memberi jeda waktu (stagger) agar munculnya berurutan 1, 2, 3 */
    .card:nth-child(1) { animation-delay: 0.1s; }
    .card:nth-child(2) { animation-delay: 0.2s; }
    .card:nth-child(3) { animation-delay: 0.3s; }

    /* 2. Efek Focus pada Input (Glow Effect) */
    .form-group input:focus {
        outline: none;
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(219, 39, 119, 0.2); /* Efek cincin pink */
        transform: translateY(-2px); /* Sedikit naik */
    }

    /* 3. Efek Tombol Ditekan (Active) */
    .btn:active {
        transform: scale(0.98); /* Sedikit mengecil saat diklik */
    }

    /* 4. Smooth Scrolling untuk seluruh halaman */
    html {
        scroll-behavior: smooth;
    }
}