/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Open Sans', Arial, sans-serif;
    background: #f0f2f5;
    color: #333;
    display: flex;
    min-height: 100vh;
}

.login-gate {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f1a2f 0%, #1a2744 55%, #2a3e68 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 390px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 14px 38px rgba(0,0,0,0.32);
    padding: 26px 24px;
    text-align: center;
}

.login-card h2 {
    font-family: 'Montserrat', sans-serif;
    color: #1a2744;
    margin-bottom: 6px;
}

.login-card p {
    color: #666;
    font-size: 0.92rem;
    margin-bottom: 14px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#login-pin {
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    padding: 11px 12px;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 2px;
    font-family: 'Montserrat', sans-serif;
}

#login-pin:focus {
    outline: none;
    border-color: #1a2744;
    box-shadow: 0 0 0 2px rgba(26,39,68,0.12);
}

.login-error {
    color: #c0392b !important;
    margin: 4px 0 0 !important;
    font-size: 0.84rem !important;
    font-weight: 600;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 240px;
    background: #1a2744;
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}
.sidebar-header {
    padding: 28px 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h1 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 2px;
}
.sidebar-header p {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-top: 2px;
}
.cloud-sync-badge {
    margin: 12px 16px;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    text-align: center;
    font-weight: 600;
}
.sync-synced { background: #d4edda; color: #155724; }
.sync-error { background: #f8d7da; color: #721c24; }
.sync-loading { background: #fff3cd; color: #856404; }
.sync-offline { background: #e2e3e5; color: #383d41; }
.sidebar nav {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
}
.nav-btn {
    background: none;
    border: none;
    color: #ccc;
    text-align: left;
    padding: 13px 24px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-family: inherit;
}
.nav-btn:hover, .nav-btn.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.nav-btn.active {
    border-left: 3px solid #c89a3e;
    padding-left: 21px;
}

/* ===== MAIN ===== */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 32px 40px;
    min-height: 100vh;
}
.view { display: none; }
.view.active { display: block; }
.view h2 {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: #1a2744;
    margin-bottom: 24px;
}

/* ===== STATS ===== */
.stats-row {
    display: flex;
    gap: 18px;
    margin-bottom: 28px;
}
.stat-card {
    flex: 1;
    background: #fff;
    border-radius: 10px;
    padding: 22px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-top: 4px solid #1a2744;
}
.stat-card.stat-quotation { border-top-color: #c89a3e; }
.stat-card.stat-pending { border-top-color: #e67e22; }
.stat-card.stat-paid { border-top-color: #27ae60; }
.stat-num {
    font-family: 'Montserrat', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: #1a2744;
}
.stat-label {
    font-size: 0.85rem;
    color: #888;
    margin-top: 4px;
}
.sales-row .stat-num {
    font-size: 1.35rem;
}
.sales-row .stat-label {
    text-align: center;
}

/* ===== FILTER ROW ===== */
.filter-row {
    display: flex;
    gap: 14px;
    margin-bottom: 18px;
}
.filter-row input, .filter-row select {
    padding: 9px 14px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}
.filter-row input { flex: 1; }

.pagination-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
    color: #555;
    font-size: 0.88rem;
}

/* ===== TABLES ===== */
.invoice-table, .line-items-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin-bottom: 14px;
}
.invoice-table th, .line-items-table th {
    background: #1a2744;
    color: #fff;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 14px;
    text-align: left;
    font-family: 'Montserrat', sans-serif;
}
.invoice-table td, .line-items-table td {
    padding: 11px 14px;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}
.invoice-table tbody tr:hover { background: #f8f9fb; }

/* ===== STATUS BADGES ===== */
.badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-quotation { background: #fdf0d5; color: #b8860b; border: 1px solid #c89a3e; }
.badge-pending { background: #fef3e2; color: #d35400; border: 1px solid #e67e22; }
.badge-paid { background: #e8f8ef; color: #1e8449; border: 1px solid #27ae60; }

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 22px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #1a2744; color: #fff; }
.btn-primary:hover { background: #263a5e; }
.btn-outline { background: #fff; color: #1a2744; border: 1.5px solid #1a2744; }
.btn-outline:hover { background: #f0f2f5; }
.btn-danger { background: #e74c3c; color: #fff; font-size: 0.8rem; padding: 6px 12px; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { font-size: 0.8rem; padding: 6px 12px; }
.btn-edit { background: #3498db; color: #fff; font-size: 0.8rem; padding: 6px 12px; }
.btn-edit:hover { background: #2980b9; }
.btn-view { background: #1a2744; color: #fff; font-size: 0.8rem; padding: 6px 12px; }
.btn-view:hover { background: #263a5e; }
.btn-payment { background: #8e44ad; color: #fff; font-size: 0.8rem; padding: 6px 12px; }
.btn-payment:hover { background: #7d3c98; }
.btn-paid { background: #27ae60; color: #fff; font-size: 0.8rem; padding: 6px 12px; }
.btn-paid:hover { background: #1e8449; }

/* ===== FORMS ===== */
.form-row { display: flex; gap: 16px; margin-bottom: 16px; }
.form-group { flex: 1; display: flex; flex-direction: column; }
.form-group.flex-2 { flex: 2; }
.form-group.flex-full { flex: 1 1 100%; }
.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
}
.form-group input, .form-group select, .form-group textarea {
    padding: 9px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}
/* Quick-add client button row */
.client-field-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.client-field-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.client-field-inputs #inv-client-search { margin-bottom: 8px; }
.btn-add-client {
    white-space: nowrap;
    padding: 9px 14px;
    background: #1a2744;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    height: fit-content;
    margin-bottom: 0;
    transition: background 0.18s;
}
.btn-add-client:hover { background: #c89a3e; }

/* Quick-add client modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    padding: 20px;
}
.modal-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.28);
    padding: 28px 28px 20px;
    width: 100%;
    max-width: 620px;
}
.modal-card h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.15rem;
    color: #1a2744;
    margin: 0 0 18px;
}

#inv-client-search { margin-bottom: 8px; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: #1a2744;
    box-shadow: 0 0 0 2px rgba(26,39,68,0.1);
}
.form-actions { display: flex; gap: 12px; margin-top: 20px; }

/* Line items */
.line-items-table input, .line-items-table textarea {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 0.85rem;
    font-family: inherit;
    width: 100%;
}
.line-items-table textarea { resize: vertical; min-height: 38px; }
.line-items-table .remove-line { 
    background: none; border: none; color: #e74c3c; font-size: 1.2rem; cursor: pointer; 
}
.totals-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin: 18px 0;
}
.total-line { display: flex; gap: 24px; font-size: 0.95rem; margin-bottom: 6px; }
.total-line span:first-child { color: #888; }
.total-final { font-size: 1.15rem; font-weight: 700; color: #1a2744; background: #1a2744; color: #fff; padding: 8px 20px; border-radius: 4px; }
.total-final span { color: #fff; }

h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.05rem;
    color: #1a2744;
    margin: 22px 0 10px;
}

/* Warranty textarea */
#warranty-text {
    width: 100%;
    padding: 16px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
}
.hint { color: #888; font-size: 0.85rem; margin-bottom: 14px; }

.import-panel {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    background: #fff;
}

.import-panel input[type="file"] {
    width: 100%;
    margin-bottom: 10px;
}

#sql-import-text {
    width: 100%;
    padding: 12px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.86rem;
    line-height: 1.45;
    resize: vertical;
    margin-bottom: 10px;
}

#sql-import-result {
    margin-top: 8px;
    margin-bottom: 0;
    color: #1a2744;
    font-weight: 600;
}

#export-backup-result {
    margin-top: 8px;
    margin-bottom: 0;
    color: #1a2744;
    font-weight: 600;
}

#import-backup-result {
    margin-top: 8px;
    margin-bottom: 0;
    color: #1a2744;
    font-weight: 600;
}

.empty-msg { color: #999; text-align: center; padding: 40px; font-size: 0.95rem; }

.client-form {
    background: #fff;
    padding: 22px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin-bottom: 24px;
}

.client-form.collapsed {
    display: none;
}

.client-form-toggle-row {
    margin-bottom: 14px;
}

.clients-summary {
    margin-bottom: 14px;
}

.clients-summary-card {
    background: #fff;
    border-radius: 10px;
    border-top: 4px solid #1a2744;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 14px 16px;
    display: inline-flex;
    gap: 14px;
    align-items: baseline;
}

.clients-summary-label {
    color: #666;
    font-size: 0.86rem;
    font-weight: 600;
}

.clients-summary-value {
    color: #1a2744;
    font-family: 'Montserrat', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
}

.client-search-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

#search-clients {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
}

#sort-clients {
    min-width: 220px;
    padding: 9px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
}

.reports-controls {
    display: flex;
    gap: 14px;
    margin-bottom: 16px;
}

.reports-controls .form-group {
    max-width: 240px;
}

.reports-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.reports-chart-wrap {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 16px;
    position: relative;
}

#sales-report-chart {
    width: 100%;
    height: 320px;
    display: block;
}

.reports-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(26, 39, 68, 0.96);
    color: #fff;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.8rem;
    line-height: 1.35;
    box-shadow: 0 6px 16px rgba(0,0,0,0.22);
    white-space: nowrap;
    z-index: 2;
}

.reports-tooltip strong {
    display: block;
    font-size: 0.82rem;
    margin-bottom: 2px;
}

.client-name-link {
    background: none;
    border: none;
    color: #1a2744;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0;
}

.client-history-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.client-history-card {
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-top: 4px solid #1a2744;
}

.client-history-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #777;
    margin-bottom: 6px;
}

.client-history-value {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: #1a2744;
}

.client-history-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.client-invoice-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
}

.client-invoice-head {
    background: #1a2744;
    color: #fff;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.client-invoice-head strong {
    font-family: 'Montserrat', sans-serif;
    letter-spacing: 0.5px;
}

.client-invoice-meta {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
}

.client-invoice-body {
    padding: 16px 18px 18px;
}

.client-invoice-total {
    margin-top: 10px;
    text-align: right;
    font-weight: 700;
    color: #1a2744;
}

.payment-breakdown {
    margin-top: 18px;
}

.payment-breakdown h3 {
    margin: 10px 0;
}

.payment-empty {
    color: #888;
    font-size: 0.85rem;
}

.payment-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e8ebef;
    border-radius: 8px;
    overflow: hidden;
}

.payment-table th {
    background: #f4f7fb;
    color: #1a2744;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    padding: 10px 12px;
    text-align: left;
}

.payment-table td {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    font-size: 0.86rem;
}

/* ===== INVOICE PREVIEW (PRINT) ===== */
.preview-actions { margin-bottom: 20px; display: flex; gap: 12px; }

.invoice-preview {
    background: #fff;
    max-width: 800px;
    margin: 0 auto;
    padding: 0;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    border-radius: 4px;
    overflow: hidden;
}
.inv-header {
    background: #1a2744;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 32px 40px 28px;
}
.inv-header-left h1 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 1.8rem;
    letter-spacing: 3px;
}
.inv-header-left p { font-size: 0.82rem; opacity: 0.75; margin-top: 4px; }
.inv-header-right { text-align: right; }
.inv-header-right .inv-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 2px;
}
.inv-header-right p { font-size: 0.85rem; opacity: 0.85; margin-top: 4px; }

.inv-body { padding: 32px 40px; }
.inv-bill-to { margin-bottom: 28px; }
.inv-bill-to .label { color: #c89a3e; font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; }
.inv-bill-to .client-name { font-family: 'Montserrat', sans-serif; font-size: 1.3rem; font-weight: 700; color: #1a2744; margin: 4px 0; }
.inv-bill-to .project-name { color: #666; font-size: 0.9rem; }

.inv-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 28px;
}
.inv-items-table th {
    background: #1a2744;
    color: #fff;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 14px;
    text-align: left;
    font-family: 'Montserrat', sans-serif;
}
.inv-items-table th:nth-child(2),
.inv-items-table th:nth-child(3),
.inv-items-table th:nth-child(4) { text-align: center; }
.inv-items-table td {
    padding: 14px;
    border-bottom: 1px solid #eee;
    font-size: 0.88rem;
    vertical-align: top;
}
.inv-items-table td:nth-child(2),
.inv-items-table td:nth-child(3),
.inv-items-table td:nth-child(4) { text-align: center; }
.inv-item-desc { font-weight: 700; color: #1a2744; }
.inv-item-details { color: #666; font-size: 0.82rem; margin-top: 4px; white-space: pre-line; }

.inv-totals { text-align: right; margin-bottom: 24px; }
.inv-totals .subtotal { color: #666; font-size: 0.9rem; margin-bottom: 8px; }
.inv-pending-box {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    border: 2px solid #e67e22;
    color: #d35400;
    background: #fff7ef;
    padding: 8px 16px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    border-radius: 4px;
    margin: 4px 0 10px;
}
.inv-total-box {
    display: inline-flex;
    align-items: center;
    gap: 20px;
    background: #1a2744;
    color: #fff;
    padding: 12px 28px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    border-radius: 2px;
}

.inv-status-stamp {
    display: inline-block;
    padding: 8px 28px;
    border: 3px solid;
    border-radius: 4px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    transform: rotate(-4deg);
    margin: 20px 0;
}
.stamp-quotation { border-color: #c89a3e; color: #c89a3e; }
.stamp-pending { border-color: #e67e22; color: #e67e22; }
.stamp-paid { border-color: #27ae60; color: #27ae60; }

.inv-payment-details {
    margin: 0 40px 16px;
    padding: 16px 0 4px;
    border-top: 1px solid #e0e4ea;
}
.inv-payment-details h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #1a2744;
    margin-bottom: 4px;
}
.inv-payment-instructions {
    font-size: 0.78rem;
    color: #666;
    margin-bottom: 10px;
}
.inv-payment-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    table-layout: fixed;
}
.inv-payment-table colgroup col:nth-child(1) { width: 28%; }
.inv-payment-table colgroup col:nth-child(2) { width: 40%; }
.inv-payment-table colgroup col:nth-child(3) { width: 32%; }
.inv-payment-table th {
    background: #1a2744;
    color: #fff;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 7px 12px;
    text-align: left;
}
.inv-payment-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #e0e4ea;
    color: #333;
    word-break: break-word;
}
.inv-payment-table tr:last-child td { border-bottom: none; }

.inv-footer {
    text-align: center;
    padding: 20px 40px 28px;
    border-top: 3px solid #1a2744;
    margin-top: 10px;
}
.inv-footer p { font-size: 0.8rem; color: #888; }
.inv-footer .thanks { color: #1a2744; font-weight: 700; font-size: 0.85rem; margin-top: 6px; }
.inv-footer .quotation-validity-note {
    color: #d35400;
    font-weight: 700;
    font-size: 0.88rem;
    margin-bottom: 6px;
}

.inv-warranty-page {
    padding: 28px 40px;
    border-top: 2px dashed #d0d5dd;
    margin-top: 0;
}
.inv-warranty-page h3 {
    font-family: 'Montserrat', sans-serif;
    color: #1a2744;
    font-size: 1rem;
    margin-bottom: 4px;
}
.inv-warranty-page-header {
    margin-bottom: 16px;
    border-bottom: 2px solid #1a2744;
    padding-bottom: 12px;
}
.inv-warranty-ref {
    font-size: 0.82rem;
    color: #888;
    margin-top: 2px;
}
.inv-warranty-content {
    font-size: 0.82rem;
    color: #555;
    line-height: 1.7;
    white-space: pre-line;
}

/* ===== PRINT ===== */
@page {
    size: A4;
    margin: 0;
}

@media print {
    /* Force all background colors/images to print */
    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    html, body {
        width: 210mm;
        min-width: 210mm;
        max-width: 210mm;
        height: auto;
        background: #fff;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 12pt;
        overflow: visible !important;
    }
    body { display: block !important; }
    .sidebar, .no-print, .login-gate, .mobile-header, .sidebar-overlay { display: none !important; }
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
    }
    .view { display: none !important; }
    #view-preview {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        overflow: visible !important;
    }
    .invoice-preview {
        box-shadow: none;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        border-radius: 0;
        overflow: visible !important;
    }

    /* A4 layout adjustments */
    .inv-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        padding: 28px 36px 24px;
    }
    .inv-header-left, .inv-header-right {
        display: block !important;
        flex-shrink: 0;
    }
    .inv-header-left h1 { font-size: 1.8rem; }
    .inv-header-right { text-align: right; }
    .inv-header-right .inv-title { font-size: 1.8rem; }
    .inv-body { padding: 28px 36px; }
    .inv-bill-to { margin-bottom: 22px; }
    .inv-bill-to .client-name { font-size: 1.25rem; }
    .inv-items-table { width: 100% !important; border-collapse: collapse; }
    .inv-items-table td { padding: 12px 14px; font-size: 0.9rem; }
    .inv-items-table th {
        padding: 10px 14px;
        font-size: 0.75rem;
        background: #1a2744 !important;
        color: #fff !important;
    }
    .inv-item-details { font-size: 0.82rem; }
    .inv-totals {
        margin-bottom: 20px;
        text-align: right;
    }
    .inv-pending-box {
        font-size: 0.95rem;
        padding: 7px 14px;
        border: 2px solid #e67e22 !important;
        color: #d35400 !important;
        background: #fff7ef !important;
    }
    .inv-total-box {
        padding: 10px 24px;
        font-size: 1.05rem;
        background: #1a2744 !important;
        color: #fff !important;
    }
    .inv-footer {
        padding: 18px 36px 24px;
        margin-top: 8px;
        border-top: 3px solid #1a2744 !important;
    }
    .inv-footer p { font-size: 0.82rem; }

    /* Warranty on separate page */
    .inv-warranty-page {
        page-break-before: always;
        padding: 28px 36px;
    }
    .inv-warranty-page h3 { font-size: 1.2rem; margin-bottom: 16px; }
    .inv-warranty-page .inv-warranty-content { font-size: 0.85rem; line-height: 1.7; }

    /* Payment details */
    .inv-payment-details {
        margin: 0 36px 14px !important;
        padding: 14px 0 4px !important;
        border-top: 1px solid #ccc !important;
    }
    .inv-payment-table th {
        background: #1a2744 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 6px 10px !important;
    }
    .inv-payment-table td { padding: 6px 10px !important; }

    /* Prevent awkward page breaks */
    .inv-items-table { page-break-inside: avoid; }
    .inv-totals { page-break-inside: avoid; }
    .inv-payment-details { page-break-inside: avoid; }
    .inv-footer { page-break-inside: avoid; }
    .payment-table .no-print { display: none !important; }
}

/* ===== RESPONSIVE ===== */
/* ===== MOBILE HEADER ===== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    background: #1a2744;
    color: #fff;
    z-index: 200;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.hamburger-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 6px;
    line-height: 1;
}
.mobile-title {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 2px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99;
}
.sidebar-overlay.visible {
    display: block;
}

/* ===== TABLE SCROLL WRAPPER (added by JS isn't needed — use CSS overflow) ===== */
.table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== RESPONSIVE: TABLET (max 900px) ===== */
@media (max-width: 900px) {
    .form-row { flex-direction: column; }
    .stats-row { flex-wrap: wrap; }
    .reports-controls { flex-direction: column; }
    .reports-controls .form-group { max-width: none; }
    .main-content { padding: 24px 20px; }
    .inv-header { flex-direction: column; gap: 12px; padding: 24px 24px 20px; }
    .inv-header-right { text-align: left; }
    .inv-body { padding: 20px 24px; }
    .inv-footer { padding: 18px 24px; }
}

/* ===== RESPONSIVE: MOBILE (max 768px) ===== */
@media (max-width: 768px) {
    /* Show mobile header, hide desktop sidebar */
    .mobile-header { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        width: 260px;
        z-index: 150;
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 70px 14px 24px;
        min-height: 100vh;
    }

    .view h2 {
        font-size: 1.25rem;
        margin-bottom: 16px;
    }

    /* Stats cards: 2 per row */
    .stats-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 16px;
    }
    .stat-card {
        padding: 14px 10px;
    }
    .stat-num {
        font-size: 1.5rem;
    }
    .sales-row .stat-num {
        font-size: 1.05rem;
    }
    .stat-label {
        font-size: 0.75rem;
    }

    /* Filter row stacks */
    .filter-row {
        flex-direction: column;
        gap: 8px;
    }

    /* Tables: horizontal scroll */
    .invoice-table, .line-items-table, .payment-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    .invoice-table th, .invoice-table td {
        padding: 10px 10px;
        font-size: 0.82rem;
    }
    .line-items-table th, .line-items-table td {
        padding: 8px;
        font-size: 0.82rem;
    }

    /* Action buttons stack narrower */
    .action-btns {
        gap: 4px;
    }
    .action-btns .btn {
        font-size: 0.72rem;
        padding: 5px 8px;
    }

    /* Pagination */
    .pagination-row {
        justify-content: center;
        font-size: 0.82rem;
    }

    /* Forms */
    .form-row { flex-direction: column; gap: 10px; }
    .form-actions { flex-wrap: wrap; }
    .form-group.flex-2 { flex: 1; }

    /* Totals */
    .totals-section { align-items: stretch; }
    .total-line { justify-content: space-between; gap: 12px; }
    .total-final { text-align: center; justify-content: center; }

    /* Client search row */
    .client-search-row {
        flex-direction: column;
        gap: 8px;
    }
    #sort-clients {
        min-width: 0;
        width: 100%;
    }

    /* Client summary card */
    .clients-summary-card {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }

    /* Invoice preview */
    .invoice-preview {
        max-width: 100%;
        border-radius: 0;
    }
    .inv-header {
        flex-direction: column;
        gap: 10px;
        padding: 20px 16px;
    }
    .inv-header-left h1 { font-size: 1.3rem; }
    .inv-header-right { text-align: left; }
    .inv-header-right .inv-title { font-size: 1.3rem; }
    .inv-body { padding: 16px; }
    .inv-bill-to .client-name { font-size: 1.1rem; }
    .inv-items-table td { white-space: normal; }
    .inv-pending-box { font-size: 0.85rem; padding: 6px 12px; }
    .inv-total-box { font-size: 0.95rem; padding: 10px 18px; gap: 12px; }
    .inv-footer { padding: 14px 16px; }
    .inv-warranty-page { padding: 16px; }

    /* Preview actions */
    .preview-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Client history */
    .client-history-stats {
        grid-template-columns: 1fr 1fr;
    }
    .client-invoice-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px 14px;
    }
    .client-invoice-body {
        padding: 12px 14px;
    }

    /* Reports chart */
    .reports-chart-wrap { padding: 10px; }

    /* Import panels */
    .import-panel { padding: 12px; }
    #sql-import-text { rows: 4; }

    /* Login card */
    .login-card { padding: 22px 18px; }

    /* Cloud sync badge in sidebar */
    .cloud-sync-badge {
        margin: 8px 12px;
        font-size: 0.7rem;
    }

    /* Buttons slightly larger touch targets */
    .btn { padding: 11px 18px; }
    .btn-sm { padding: 8px 12px; font-size: 0.78rem; }
}

/* ===== RESPONSIVE: SMALL PHONES (max 420px) ===== */
@media (max-width: 420px) {
    .main-content { padding: 62px 10px 20px; }

    .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .stat-card { padding: 10px 6px; }
    .stat-num { font-size: 1.2rem; }
    .sales-row .stat-num { font-size: 0.9rem; }
    .stat-label { font-size: 0.68rem; }

    .view h2 { font-size: 1.1rem; }

    .inv-header-left h1 { font-size: 1.1rem; }
    .inv-header-right .inv-title { font-size: 1.1rem; }

    .client-history-stats {
        grid-template-columns: 1fr;
    }

    .reports-stats {
        grid-template-columns: 1fr 1fr;
    }
}

/* Action buttons in tables */
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }
