/* ==========================================================================
   BuildMart POS - Style & Global Layout Configuration
   ========================================================================== */

:root {
    --primary: #0f172a;
    --accent: #f27a1a;
    --bg-main: #f8fafc;
    --border-color: #cbd5e1;
    --text-main: #1e293b;
    --font-kh: 'Kantumruy Pro', 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-kh);
}

body {
    background-color: #f1f5f9;
    color: var(--text-main);
    overflow-x: hidden;
}

.pos-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ផ្នែកខាងឆ្វេង៖ បញ្ជីទំនិញ */
.product-catalog-panel {
    width: 45%;
    background: white;
    padding: 0.7rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.catalog-header h2 {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 700;
}

/* ប្រអប់ Excel Auto Importer Dropzone */
.excel-dropzone {
    background: #f8fafc;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
    transition: all 0.2s ease;
}
.excel-dropzone.dragover {
    border-color: var(--accent);
    background: #fff3e6;
}
.excel-dropzone p {
    font-size: 0.85rem;
    color: #475569;
}
.excel-dropzone label {
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}
.dropzone-icon {
    font-size: 1.3rem;
    display: block;
    margin-bottom: 0.15rem;
}
.btn-download-json {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    margin-top: 0.5rem;
    font-weight: 600;
}

.search-wrapper input {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    margin-bottom: 1rem;
}
.search-wrapper input:focus {
    border-color: var(--accent);
}

.table-scroll-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.catalog-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.catalog-table th {
    background: #f1f5f9;
    padding: 0.75rem;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border-color);
}
.catalog-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}
.catalog-code {
    background: #e2e8f0;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Inter';
    font-weight: 600;
}
.badge {
    background: #f1f5f9;
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    font-size: 0.8rem;
}
.catalog-price {
    font-weight: 600;
    color: var(--primary);
}

/* ផ្នែកខាងស្តាំ៖ វិក្កយបត្រ */
.checkout-sidebar {
    width: 55%;
    background: #edf2f7;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.customer-box h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.input-row input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    outline: none;
}

/* ទម្រង់សន្លឹកវិក្កយបត្រ */
.invoice-sheet {
    background: white;
    flex: 1;
    border-radius: 6px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}
.brand-side h1 { font-size: 1.2rem; color: var(--primary); }
.store-name { font-size: 0.9rem; font-weight: bold; }
.store-sub { font-size: 0.75rem; color: #64748b; }
.meta-side { text-align: right; font-size: 0.8rem; }

.invoice-customer-card {
    background: #f8fafc;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.invoice-items-wrapper { flex: 1; }
.invoice-items-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; table-layout: fixed; }
.invoice-items-table th { border-bottom: 1px solid var(--text-main); padding: 0.4rem 0; text-align: left; }
.invoice-items-table td { padding: 0.5rem 0; border-bottom: 1px dashed #e2e8f0; overflow: hidden; word-break: break-word; }

/* រៀបចំប្រវែងទទឹងជួរតារាងវិក្កយបត្រឱ្យទូលាយ ការពារការធ្លាក់លេខ */
.invoice-items-table th:nth-child(1), .invoice-items-table td:nth-child(1) { width: 6%; text-align: center; }
.invoice-items-table th:nth-child(2), .invoice-items-table td:nth-child(2) { width: 44%; }
.invoice-items-table th:nth-child(3), .invoice-items-table td:nth-child(3) { width: 10%; text-align: center; }
.invoice-items-table th:nth-child(4), .invoice-items-table td:nth-child(4) { width: 10%; text-align: center; }
.invoice-items-table th:nth-child(5), .invoice-items-table td:nth-child(5) { width: 12%; text-align: right; }
.invoice-items-table th:nth-child(6), .invoice-items-table td:nth-child(6) { width: 10%; text-align: center; }
.invoice-items-table th:nth-child(7), .invoice-items-table td:nth-child(7) { width: 15%; text-align: right; }
.invoice-items-table th:nth-child(8), .invoice-items-table td:nth-child(8) { width: 6%; text-align: center; }

.invoice-summary-box {
    border-top: 2px solid var(--primary);
    padding-top: 0.5rem;
    margin-top: 0.75rem;
    position: relative;
}
.summary-line { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 0.35rem; align-items: center; }
.discount-input-wrapper input { width: 60px; text-align: center; padding: 0.25rem; border: 1px solid var(--border-color); border-radius: 4px; }
.grand-total-line { font-size: 1.1rem; font-weight: 700; color: var(--accent); border-top: 1px solid #e2e8f0; padding-top: 0.35rem; }

.invoice-footer { text-align: center; font-size: 0.75rem; margin-top: 0.75rem; color: #64748b; }

.btn-print-invoice {
    width: 100%; background: var(--accent); color: white; border: none; padding: 0.75rem; font-weight: 700; border-radius: 6px; cursor: pointer; margin-top: 0.75rem;
}
.btn-print-invoice:hover { background: var(--primary); }

.btn-open-modal {
    background: var(--primary); color: white; border: none; padding: 0.5rem 1rem; border-radius: 6px; font-weight: 600; font-size: 0.85rem; cursor: pointer;
}
.btn-open-modal:hover { background: var(--accent); }

.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-card { background: white; width: 100%; max-width: 480px; border-radius: 8px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); overflow: hidden; animation: slideUp 0.2s ease-out; }
@keyframes slideUp { from { transform: translateY(20px); } to { transform: translateY(0); } }

.modal-card-header { background: var(--primary); color: white; padding: 1rem; display: flex; justify-content: space-between; align-items: center; }
.modal-card-header h3 { font-size: 1rem; }
.btn-close-modal-x { background: transparent; color: white; border: none; font-size: 1.5rem; cursor: pointer; }

#addProductForm { padding: 1.25rem; }
.form-group { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: #334155; text-align: left; }
.form-group input { padding: 0.6rem; border: 1px solid var(--border-color); border-radius: 4px; font-size: 0.9rem; outline: none; }
.form-group input:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.modal-card-footer { padding: 1rem 0 0 0; display: flex; justify-content: flex-end; gap: 0.5rem; }
.btn-cancel { background: #e2e8f0; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-weight: 500; }
.btn-submit { background: var(--accent); color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-weight: 600; }

.main-panel {
    display: none;
    background: #f8fafc;
    min-height: 100vh;
    animation: fadeIn 0.2s ease-in-out;
}

.main-panel.active {
    display: block !important;
}

.detail-split-layout {
    display: grid;
    grid-template-columns: 45% 53%;
    gap: 2%;
    align-items: start;
    margin-top: 15px;
}

#fullCustomerHistoryRows tr {
    transition: all 0.2s;
}
#fullCustomerHistoryRows tr:hover {
    background-color: #f1f5f9 !important;
}

#invoicePrintPreviewArea {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
}

.btn-print-preview {
    background: #16a34a;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}
.btn-print-preview:hover {
    background: #15803d;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}
/* ==========================================================================
   ⚙️ ដំណោះស្រាយស្វ័យប្រវត្តិ (Auto Elastic Page Height Fix) វែងខ្លីតាមទំនិញជាក់ស្តែង
   ========================================================================== */
.print-only { display: none; }

@media print {
    /* ១. បើកឱ្យកម្ពស់រត់សេរី (Auto) និងបង្ហាញទិន្នន័យហៀរទៅទំព័របន្ទាប់បើទំនិញច្រើន */
    html, body {
        background: white !important;
        color: black !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important; /* កែមកជា auto ដើម្បីឱ្យវែងខ្លីតាមសាច់កូដ */
        overflow: visible !important; /* បើកឱ្យធ្លាក់ទៅទំព័រទី ២ បើទំនិញច្រើន */
    }

    /* ២. លុបបំបាត់រាល់ការកម្រិតកម្ពស់ចាស់ៗនៃ Container ធំៗ */
    .pos-container, 
    .main-panel, 
    .checkout-sidebar, 
    #panelCustomerDetail, 
    .detail-split-layout {
        display: block !important;
        float: none !important;
        position: relative !important;
        width: 100% !important;
        height: 400px !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* ៣. លាក់រាល់ឧបករណ៍ ប៊ូតុង និងផ្នែកដែលមិនពាក់ព័ន្ធទាំងអស់ */
    .no-print, 
    #mySidebar, 
    #sidebarOverlay, 
    .top-action-bar, 
    .product-catalog-panel, 
    .customer-box, 
    .sidebar-actions,
    .btn-print-preview,
    #previewPlaceholder,
    #panelCustomerDetail > div:first-child, 
    #panelCustomerDetail > div:nth-child(2),
    .detail-split-layout > div:first-child, 
    button, 
    input,
    .invoice-items-table th:last-child, 
    .invoice-items-table td:last-child { 
        display: none !important; 
        visibility: hidden !important;
    }

    /* ៤. កំណត់ឱ្យសន្លឹកវិក្កយបត្រលាតសន្ធឹងតាមធម្មជាតិ */
    .invoice-sheet, #actualInvoiceCard, #invoicePrintPreviewArea {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }

    .invoice-items-table {
        width: 100% !important;
        table-layout: fixed !important;
    }

    .invoice-items-table td, .invoice-items-table th {
        overflow: visible !important;
        word-break: break-word !important;
    }

    .print-only {
        display: block !important;
    }

    /* ៥. ការពារការបាក់បែកអក្សរចំកណ្តាលជួរ (កាត់ផ្ដាច់អក្សរពាក់កណ្តាលទំព័រ) */
    .invoice-items-table tr {
        page-break-inside: avoid !important;
    }

    /* ៦. កំណត់ទំហំរឹមក្រដាសឱ្យត្រូវស្តង់ដារម៉ាស៊ីនព្រីន */
    @page {
        size: auto;
        margin: 8mm 10mm 8mm 10mm; /* រឹមសមល្មមសម្រាប់ម៉ាស៊ីនព្រីន */
    }
}