/* ===== VARIABLES & SCREEN STYLES ===== */
:root {
    --bg-main: #f5f5f7;
    --bg-card: #ffffff;
    --text-main: #1d1d1f;
    --text-muted: #86868b;
    --border-light: #e8e8ed;
    --accent: #115e41;
    --radius-lg: 24px;
    --radius-md: 12px;
}

html { min-height: 100.1vh; box-sizing: border-box; }

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    margin: 0; padding: 12px;
    -webkit-font-smoothing: antialiased;
    min-height: 100%; box-sizing: border-box;
}

/* Navigation */
.navbar {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.01);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}
.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin-bottom: 12px;
}
.nav-links { display: flex; gap: 8px; }
.nav-link {
    flex: 1;
    text-align: center;
    padding: 10px;
    text-decoration: none;
    color: var(--text-main);
    background: var(--bg-main);
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}
.nav-link:hover:not(.active) { background-color: var(--border-light); }
.nav-link.active {
    background-color: var(--accent) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(17, 94, 65, 0.2);
}

/* Main Card */
.gold-card {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.01);
    box-sizing: border-box;
    max-width: 600px;
    margin: 0 auto 20px auto;
}
h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 20px 0; text-align: center; }

.historical-badge { background: var(--bg-main); color: var(--text-muted); padding: 12px 16px; border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 500; margin-bottom: 24px; text-align: center; }
.header-controls { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.input-group { display: flex; flex-direction: column; gap: 8px; }
.label-row { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
label { font-size: 0.9rem; font-weight: 600; color: var(--text-main); }

.btn { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #ffffff; font-weight: 600; border: none; padding: 16px; border-radius: 40px; cursor: pointer; box-sizing: border-box; width: 100%; font-size: 1.1rem; }
.btn-pill { background: var(--accent); color: #ffffff; font-weight: 600; border: none; padding: 14px; border-radius: 40px; cursor: pointer; text-align: center; flex: 1; }
.btn-pill-outline { background: transparent; color: var(--text-main); border: 1px solid #d2d2d7; font-weight: 600; padding: 14px; border-radius: 40px; cursor: pointer; text-align: center; flex: 1; }
.btn-pill-sm { background: transparent; color: var(--accent); border: 1px solid var(--border-light); font-size: 0.8rem; font-weight: 600; padding: 4px 12px; border-radius: 40px; cursor: pointer; }
.btn-icon-delete { background: transparent; border: none; cursor: pointer; padding: 4px; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon-delete svg { width: 20px; height: 20px; fill: none; stroke: var(--text-muted); stroke-width: 2; }
.btn-icon-delete:hover svg { stroke: #ff3b30; }

.delete-confirm-badge { color: #ff3b30 !important; background: #ffe5e5 !important; font-size: 0.8rem !important; font-weight: 700 !important; padding: 4px 10px !important; border-radius: 6px !important; white-space: nowrap; }
.action-buttons-row { display: flex; gap: 12px; margin-top: 8px; width: 100%; }

.touch-input { background: var(--bg-main); border: 1px solid transparent; color: var(--text-main); padding: 14px 16px; font-size: 1.05rem; font-weight: 500; border-radius: var(--radius-md); outline: none; transition: all 0.2s ease; box-sizing: border-box; width: 100%; }
.touch-input.active { background: var(--bg-card); border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1); }
.touch-select { width: 100%; background: var(--bg-main); border: 1px solid transparent; color: var(--text-main); padding: 12px 14px; font-size: 1rem; border-radius: var(--radius-md); box-sizing: border-box; }

.mobile-item-list { margin-bottom: 24px; }
.mobile-card-row { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: 16px; margin-bottom: 12px; display: flex !important; flex-direction: column !important; gap: 12px !important; box-sizing: border-box; }
.mobile-card-header { display: flex !important; justify-content: space-between !important; align-items: center !important; width: 100% !important; }
.mobile-card-index { font-weight: 700; color: var(--text-muted); font-size: 1.05rem; }

.mobile-card-inputs { display: flex !important; flex-direction: row !important; justify-content: space-between !important; gap: 12px !important; width: 100% !important; box-sizing: border-box !important; }
.mobile-input-split { width: 48% !important; box-sizing: border-box !important; }
.mobile-input-split .touch-select { width: 100% !important; height: 46px !important; padding: 0 12px !important; font-weight: 600; font-size: 0.95rem; border-radius: 10px; background-color: var(--bg-main); }
.mobile-input-split .touch-input { width: 100% !important; height: 46px !important; padding: 0 12px !important; font-size: 1.1rem; font-weight: 500; border-radius: 10px; text-align: right !important; background-color: var(--bg-main); }

.mobile-card-footer { display: flex !important; justify-content: flex-end !important; padding-top: 12px !important; border-top: 1px dashed var(--border-light) !important; width: 100% !important; }
.mobile-subtotal { font-weight: 700; font-size: 1.2rem; color: var(--text-main); }

.totals-container { margin-top: 24px; }
.grand-total-box { display: flex; justify-content: space-between; align-items: center; background: var(--bg-main); padding: 20px; border-radius: var(--radius-md); }
.total-label { font-size: 1.1rem; font-weight: 700; color: var(--text-main); }
.total-value { font-size: 1.6rem; font-weight: 800; color: var(--accent); }

.modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.3); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; z-index: 2000; }
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.numpad-modal { background: var(--bg-card); border-radius: var(--radius-lg); padding: 24px; width: 340px; position: relative; }
.numpad-display { font-size: 2rem; font-weight: 700; text-align: right; margin-top: 8px; }
.numpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.numpad-btn { background: var(--bg-main); border: none; font-size: 1.25rem; font-weight: 600; padding: 16px; border-radius: var(--radius-md); }
.numpad-btn.confirm { grid-column: span 3; background: var(--accent); color: #ffffff; }

.print-copies { display: none; }
.footer { text-align: center; padding: 20px; color: var(--text-muted); font-size: 0.8rem; max-width: 600px; margin: 0 auto; }

/* Inline overrides for action buttons */
.action-buttons-row { display: flex !important; align-items: center !important; justify-content: flex-end !important; gap: 12px !important; margin-top: 24px !important; width: 100% !important; }
.btn-clear-all, .btn-add-item { flex: 0 0 calc(100% / 6) !important; display: flex !important; align-items: center !important; justify-content: center !important; gap: 4px !important; padding: 12px 4px !important; font-size: 0.9rem !important; white-space: nowrap !important; }
.btn-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-pill .btn-icon { stroke: #ffffff; }
.btn-pill-outline .btn-icon { stroke: var(--text-main); }
.btn-pill-sm .btn-icon { stroke: var(--accent); width: 14px; height: 14px; }
.print-table-strict th:last-child, .print-table-strict td:last-child { text-align: right !important; }
.print-table-strict th:nth-child(2), .print-table-strict td:nth-child(2), .print-table-strict th:nth-child(3), .print-table-strict td:nth-child(3) { text-align: center !important; }

/* ==========================================================================
   MATHEMATICALLY ABSOLUTE A4 PRINT ENGINE OVERRIDES
   Splits A4 (210mm x 297mm) into two 148.5mm halves
   ========================================================================== */
@media print {
    @page { size: A4 portrait; margin: 0; }
    html, body { 
        width: 210mm !important; 
        height: 297mm !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        background: #ffffff; 
        color: #000000; 
        overflow: hidden; 
    }
    
    /* Hide all screen UI elements */
    .no-print, .screen-invoice, h1, .historical-badge, .header-controls, .totals-container, .action-buttons-row, .mobile-item-list, .btn, .modal-backdrop { 
        display: none !important; 
    }
    
    .gold-card { 
        border: none !important; 
        box-shadow: none !important; 
        padding: 0 !important; 
        margin: 0 !important; 
        background: transparent !important; 
    }
    
    /* Show and format print copies */
    .print-copies { 
        display: block !important; 
        width: 210mm !important; 
        height: 297mm !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        box-sizing: border-box; 
    }
    
    .copy-container { 
        display: flex !important;
        flex-direction: column !important;
        width: 210mm !important; 
        height: 297mm !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        box-sizing: border-box; 
    }
    
    /* Each copy is exactly half of A4 height */
    .invoice-copy { 
        display: flex !important; 
        flex-direction: column !important; 
        width: 210mm !important; 
        height: 148.5mm !important; 
        box-sizing: border-box !important; 
        margin: 0 !important; 
        padding: 15mm 15mm 15mm 15mm !important; 
        overflow: hidden !important; 
        page-break-inside: avoid !important; 
    }
    
    /* Dashed cut line between the two halves */
    .invoice-copy:first-child { 
        border-bottom: 1px dashed #000000 !important; 
    }
    
    .copy-header { 
        display: flex !important; 
        justify-content: space-between !important; 
        font-weight: 700; 
        font-size: 1.15rem; 
        border-bottom: 2px solid #000000; 
        padding-bottom: 4px; 
        margin-bottom: 6px; 
    }
    
    .gold-rate-print { 
        font-size: 0.95rem; 
        margin-bottom: 6px; 
        font-weight: 500; 
    }
    
    .print-table-strict { 
        display: table !important; 
        width: 100% !important; 
        border-collapse: collapse !important; 
        table-layout: fixed !important; 
        margin-bottom: 6px; 
    }
    .print-table-strict thead { display: table-header-group !important; }
    .print-table-strict tbody { display: table-row-group !important; }
    .print-table-strict tr { display: table-row !important; }
    
    .print-table-strict th, .print-table-strict td { 
        display: table-cell !important; 
        padding: 6px 4px !important; 
        text-align: left; 
        border-bottom: 1px solid #000000 !important; 
        font-size: 0.95rem; 
        white-space: nowrap !important; 
        overflow: hidden; 
        text-overflow: ellipsis; 
    }
    .print-table-strict th { 
        font-weight: 700; 
        border-bottom: 2px solid #000000 !important; 
    }
    
    .print-total-wrapper { 
        margin-top: auto !important; 
        display: flex !important; 
        justify-content: flex-end !important; 
        width: 100% !important; 
        padding-top: 10px !important; 
    }
    .total-box-content { 
        display: inline-block !important; 
        border: 2px solid #000000 !important; 
        border-radius: 4px !important; 
        padding: 8px 16px !important; 
        font-size: 1.2rem !important; 
        font-weight: 700 !important; 
        color: #000000 !important; 
        background: #ffffff !important; 
        white-space: nowrap !important; 
        box-sizing: border-box !important; 
    }
}