:root {
    --text-main: #000000; --text-muted: #111111;
    --accent: #e74c3c; --bg-body: #f4f6f8; --nav-bg: #2c3e50;
    --success: #27ae60; --warning: #f39c12;
    --edit-bg: rgba(0, 0, 0, 0.03); --edit-border: rgba(0, 0, 0, 0.2);
    /* Warna lalai jika tidak ditetapkan dalam HTML */
    --primary: #3498db; 
    --vault-bg: linear-gradient(135deg, #2c3e50, #3498db);
}

body { font-family: 'Montserrat', sans-serif; margin: 0; padding: 0; background: var(--bg-body); color: var(--text-main); }
::placeholder { color: #888888; font-weight: 500; text-transform: none; }

/* NAVBAR */
.navbar { background: var(--nav-bg); padding: 0 20px; display: flex; align-items: center; overflow-x: auto; white-space: nowrap; box-shadow: 0 4px 10px rgba(0,0,0,0.1); position: sticky; top: 0; z-index: 1000;}
.nav-brand { color: white; font-weight: 800; font-size: 18px; margin-right: 30px; padding: 15px 0; letter-spacing: 1px;}
.nav-brand span { color: var(--warning); }
.nav-item { color: #bdc3c7; font-weight: 600; font-size: 13px; padding: 18px 15px; cursor: pointer; transition: 0.3s; border-bottom: 3px solid transparent; text-decoration: none; display: inline-block;}
.nav-item:hover { color: white; }
.nav-item.active { color: white; border-bottom-color: var(--primary); background: rgba(255,255,255,0.05); }

/* CRM SPLIT LAYOUT */
.crm-container { display: flex; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; }
.crm-left { flex: 1; min-width: 300px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.05); height: max-content; position: sticky; top: 80px;}
.crm-right { flex: 2.5; min-width: 400px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.05); }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 12px; font-weight: 700; color: #555; margin-bottom: 5px; text-transform: uppercase;}
.form-control { width: 100%; padding: 10px; border: 2px solid #eee; border-radius: 6px; font-family: 'Montserrat'; font-size: 13px; box-sizing: border-box; transition: 0.3s;}
.form-control:focus { border-color: var(--primary); outline: none; }

.btn { padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; font-family: 'Montserrat'; font-weight: 700; font-size: 13px; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px;}
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--accent); color: white; }
.btn-outline { background: transparent; border: 2px solid #ddd; color: #555; }
.btn-outline:hover { background: #eee; }

/* TABLE STYLES */
.table-responsive { width: 100%; overflow-x: auto; }
table.crm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.crm-table th { background: #f8f9fa; padding: 12px; text-align: left; border-bottom: 2px solid #ddd; color: #555; font-weight: 700; font-size: 11px; text-transform: uppercase;}
table.crm-table td { padding: 12px; border-bottom: 1px solid #eee; vertical-align: middle; }
table.crm-table tr:hover { background: #fdfdfd; }

/* VAULT SECTION */
#vault-section { display: none; padding: 20px; max-width: 1400px; margin: 0 auto; animation: fadeIn 0.3s; }
.vault-header { background: var(--vault-bg); color: white; padding: 30px; border-radius: 8px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 20px rgba(0,0,0,0.1);}
.vault-stat-box { background: rgba(255,255,255,0.1); padding: 15px 20px; border-radius: 6px; text-align: right; border: 1px solid rgba(255,255,255,0.2);}
.vault-actions { background: white; padding: 15px 20px; border-radius: 8px; margin-bottom: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); display: flex; gap: 10px; flex-wrap: wrap;}

/* UNIFIED DOCUMENT EDITOR */
#editor-section { display: none; padding: 20px; padding-bottom: 100px; background: #e0e0e0; min-height: 100vh; animation: fadeIn 0.3s; }
.document-box { max-width: 850px; margin: 0 auto; background: white; padding: 60px; box-shadow: 0 20px 50px rgba(0,0,0,0.15); font-family: Arial, sans-serif; color: #000; position: relative;}

.doc-input, .doc-textarea { border: 1px dashed transparent; background: transparent; font-family: Arial; color: #000; transition: 0.2s; padding: 4px; font-size: 12px;}
.doc-input:hover, .doc-textarea:hover { background: var(--edit-bg); border: 1px dashed var(--edit-border); }
.doc-input:focus, .doc-textarea:focus { background: white; border: 1px solid var(--primary); outline: none; }
.doc-textarea { resize: none; overflow: hidden; width: 100%; box-sizing: border-box; }

.floating-bar { position: fixed; bottom: 0; left: 0; width: 100%; background: white; padding: 15px 20px; box-shadow: 0 -5px 20px rgba(0,0,0,0.1); display: flex; justify-content: center; gap: 15px; z-index: 2000; box-sizing: border-box;}

/* PAYSLIP SPECIFIC (Payroll) */
.payslip-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 20px; }
.payslip-table th { background: #f0f0f0; padding: 8px; border: 1px solid #000; text-align: left; }
.payslip-table td { padding: 8px; border: 1px solid #000; vertical-align: middle; }

/* AGEING & SOA STYLES */
.ageing-box, #soa-section { display: none; padding: 20px; max-width: 1400px; margin: 0 auto; animation: fadeIn 0.3s; }
.ageing-box.active { display: block; }
#soa-section { padding-bottom: 100px; background: #e0e0e0; min-height: 100vh; }
.ageing-table-print { font-family: Arial, sans-serif; width: 100%; border-collapse: collapse;}
.ageing-table-print th { background-color: #f0f0f0; border: 1px solid #000; padding: 6px; font-size: 11px; text-align: center; }
.ageing-table-print td { border: 1px dotted #ccc; padding: 6px; font-size: 11px; vertical-align: middle; }
.ageing-table-print tfoot td { border: 1px solid #000; font-weight: bold; background-color: #f9f9f9; }
.soa-table th { padding: 8px; border: 1px solid #000; text-align: left; font-size: 12px; background: #f0f0f0;}
.soa-table td { padding: 8px; border-right: 1px solid #000; border-left: 1px solid #000; font-size: 12px;}

/* MODAL */
.modal { display: none; position: fixed; z-index: 2005; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); backdrop-filter: blur(3px); }
.modal-content { background: white; margin: 5% auto; padding: 30px; border-radius: 8px; width: 90%; max-width: 600px; box-shadow: 0 20px 50px rgba(0,0,0,0.3); animation: fadeIn 0.3s; max-height: 90vh; overflow-y: auto;}
.close-btn { float: right; font-size: 24px; cursor: pointer; font-weight: bold; color: #888; }
.close-btn:hover { color: #e74c3c; }

/* UTILITIES */
.rich-text-editor { box-sizing: border-box; width: 100%; min-height: 50px; border: 1px dashed transparent; padding: 8px; font-family: Arial; font-size: 12px; outline: none; transition: 0.2s; background: transparent; }
.rich-text-editor:hover { background: var(--edit-bg); border: 1px dashed var(--edit-border); }
.rich-text-editor:focus { background: white; border: 1px solid var(--primary); }

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { appearance: textfield; -moz-appearance: textfield; }

/* HIDE SIGNATURES CLASS */
body.no-signatures #pv-signatures, body.no-signatures #cndn-signatures, body.no-signatures #doc-auto-sign,
body.no-signatures #po-signature-new, body.no-signatures #po-exclusive-layout > div:last-child,
body.no-signatures #do-signatures, body.no-signatures #quo-signature, body.no-signatures #inv-signature,
body.no-signatures #or-signature, body.no-signatures #cndn-custom-footer > div:last-child,
body.no-signatures #do-custom-footer > div:last-child, body.no-signatures #or-custom-footer > div > div:last-child {
    display: none !important;
}

/* ==========================================
   CUSTOM SCROLLBAR UNTUK PANEL KIRI (MODEN)
   ========================================== */

/* 1. Untuk Firefox */
.crm-left {
    scrollbar-width: thin; 
    scrollbar-color: #bdc3c7 transparent; 
}

/* 2. Untuk Chrome, Edge, Safari */
.crm-left::-webkit-scrollbar {
    width: 6px; /* Jadikan scrollbar lebih kurus dan kemas */
}

.crm-left::-webkit-scrollbar-track {
    background: transparent; /* Jadikan laluan belakang lutsinar */
}

.crm-left::-webkit-scrollbar-thumb {
    background: #bdc3c7; /* Warna kelabu cerah yang sangat lembut */
    border-radius: 10px; /* Hujung yang membulat */
}

.crm-left::-webkit-scrollbar-thumb:hover {
    background: #3498db; /* Bertukar warna tema (biru) apabila tetikus lalu! */
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* =====================================
   MOBILE RESPONSIVE RULES 
===================================== */
.menu-toggle { display: none; color: white; font-size: 24px; cursor: pointer; padding: 5px 10px; }
.nav-links-container { display: flex; align-items: center; flex: 1; }

@media screen and (max-width: 768px) {
    .navbar { flex-wrap: wrap; padding: 10px 15px; overflow: visible; }
    .nav-brand { flex: 1; margin-right: 0; }
    .menu-toggle { display: block; }
    .nav-links-container { display: none; width: 100%; flex-direction: column; background: var(--nav-bg); padding-bottom: 15px; }
    .nav-links-container.show { display: flex; }
    .nav-item { border-bottom: 1px solid rgba(255,255,255,0.05); padding: 12px 15px; display: block; width: 100%; box-sizing: border-box; }
    
    .crm-container { flex-direction: column; padding: 10px; width: 100%; box-sizing: border-box; overflow: hidden; }
    .crm-left { position: static; width: 100%; min-width: 0; padding: 15px;}
    .crm-right { padding: 15px; min-width: 0 !important; width: 100%; box-sizing: border-box; }
    
    .vault-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .vault-stat-box { width: 100%; text-align: left; box-sizing: border-box; }
    .vault-actions button { flex: 1; min-width: 45%; font-size: 11px; padding: 8px; }
    
    .table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 5px; }
    .crm-table td:last-child { white-space: nowrap; }
    .crm-table td, .crm-table th, #editor-section table { font-size: 11px !important; padding: 8px 5px !important;}
    
    .document-box { padding: 20px; }
    .doc-input, .doc-textarea, .rich-text-editor { font-size: 11px !important; }
    .bill-ac { width: 80px !important; }
    #th-desc { width: auto !important; }
    .payslip-table td, .payslip-table th { padding: 4px; font-size: 10px; }
}

/* =====================================
   PRINT RULES 
===================================== */
.print-mirror { display: none !important; white-space: pre-wrap; word-wrap: break-word; }
.bill-ac { width: 120px !important; }
#th-desc { width: auto !important; min-width: 200px; }

@media print {
    body { 
        background: white; 
        padding: 0; 
        margin: 0; 
        -webkit-print-color-adjust: exact !important; /* Paksa Chrome/Safari/Edge print warna */
        print-color-adjust: exact !important;         /* Paksa Firefox print warna */
    }
    
    .navbar, .crm-container, #vault-section, .floating-bar, .no-print, button, .modal, .hide-on-print { display: none !important; }
    body > div { display: none !important; }
    
    body.printing-invoice > #editor-section,
    body.printing-payslip > #editor-section { display: block !important; padding: 0 !important; min-height: auto !important; background: white; }
    body.printing-soa > #soa-section { display: block !important; padding: 0 !important; min-height: auto !important; }
    body.printing-aging > #tab-aging { display: block !important; padding: 0 !important; min-height: auto !important; }

    .document-box { box-shadow: none !important; padding: 0 !important; margin: 0 !important; max-width: 100% !important; border:none !important;}
    
    textarea, input.item-desc, input.po-svc-desc, input.po-mat-desc, #doc-attn,
    #pv-supp-bank, #pv-supp-acname, #pv-supp-acno, #po-supp-name, #po-ship-name,
    #cndn-bank-name, #cndn-bank-ac, input.pv-acno, input.pv-acname { display: none !important; }
    
    .print-mirror { display: block !important; }
    input { border: none !important; background: transparent !important; padding: 0 !important; margin: 0 !important; }
    .doc-input { padding: 0 !important; margin: 0 !important; }
    .hide-border-print { border: none !important; background: transparent !important; }
    input::placeholder, textarea::placeholder, .rich-text-editor:empty:before { color: transparent !important; }
    
    #doc-date, #doc-no, #doc-extra-input { text-align: right !important; }
    #doc-co-name, #doc-co-addr { text-align: left !important; }
    .ageing-table-print tfoot { display: table-row-group !important; }
    .bill-ac { display: table-cell !important; width: 100px !important; }

    body.printing-invoice .document-box * { color: #000 !important; }
    body.printing-invoice .table-responsive table { border: none !important; }
    body.printing-invoice .table-responsive th { border-top: 1px solid #000 !important; border-bottom: 1px solid #000 !important; border-right: none !important; border-left: none !important; background: transparent !important; }
    body.printing-invoice .table-responsive td { border: none !important; }
    body.printing-invoice #doc-items tr { border-bottom: none !important; }
    body.printing-invoice #doc-discount { display: none !important; }
    body.printing-invoice #doc-disc-print { display: inline !important; }
    body.printing-invoice #po-services-body tr, body.printing-invoice #po-materials-body tr { border-bottom: none !important; }
    
    .rich-text-editor { border: none !important; padding: 0 !important; margin: 0 !important; }
}