/* ══════════════════════════════════════════════════
   NEXWAVE CORE - Shared ERP Styles
   ══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --sidebar-width: 260px;
    --primary-green: #2e7d32;
    --dark-green: #0b2b0f;
    --light-green: #e8f5e9;
    --accent-green: #69f0ae;
    --bg-gray: #f8faf9;
    --text-main: #333;
    --text-muted: #666;
    --border-color: #e0e0e0;
    --red: #c62828;
    --light-red: #ffebee;
    --blue: #1565c0;
    --light-blue: #e3f2fd;
    --amber: #e65100;
    --light-amber: #fff3e0;
}

* { box-sizing: border-box; }
body { font-family: 'Inter', 'Segoe UI', sans-serif; display: flex; margin: 0; background: var(--bg-gray); color: var(--text-main); min-height: 100vh; overflow-y: scroll; }

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-width); background: var(--dark-green); color: white; padding: 0; display: flex; flex-direction: column; flex-shrink: 0; position: fixed; height: 100vh; z-index: 1000; transition: transform 0.3s ease; }
.sidebar-logo { padding: 30px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,0.05); text-decoration: none; }
.sidebar-logo-img { width: 36px; height: 36px; object-fit: contain; border-radius: 6px; flex-shrink: 0; }
.sidebar-logo h2 { font-size: 1.2em; color: #fff; margin: 0; font-weight: 700; letter-spacing: 0.5px; }
.sidebar-logo span { color: var(--accent-green); font-size: 0.8em; font-weight: 400; }
.user-info { padding: 20px; background: rgba(255,255,255,0.03); margin: 10px 15px; border-radius: 12px; font-size: 0.85em; color: var(--accent-green); border: 1px solid rgba(255,255,255,0.05); }
.nav-group { padding: 20px 15px; flex: 1; }
.nav-link { padding: 12px 16px; cursor: pointer; display: flex; align-items: center; gap: 12px; color: #c8e6c9; text-decoration: none; border-radius: 8px; margin-bottom: 5px; transition: 0.2s; font-size: 0.95em; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-link.active { background: var(--primary-green); color: white; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }

/* ── Main Layout ── */
.main-wrapper { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; transition: margin-left 0.3s ease; }
.main-content { padding: 40px; max-width: 1200px; width: 100%; margin: 0 auto; }
h1 { font-size: 1.8em; font-weight: 700; margin-bottom: 30px; color: var(--dark-green); display: flex; align-items: center; gap: 10px; }

/* ── Cards ── */
.card { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 24px; border-radius: 16px; border: 1px solid rgba(255, 255, 255, 0.5); box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05); margin-bottom: 30px; transition: 0.3s; }
.card h3 { font-size: 0.9em; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-top: 0; margin-bottom: 15px; }
.card:hover { transform: translateY(-2px); }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 15px; text-align: left; border-bottom: 2px solid var(--border-color); color: var(--text-muted); font-weight: 600; background: #fafafa; }
td { padding: 15px; text-align: left; border-bottom: 1px solid var(--border-color); color: var(--text-main); }
tr:hover td { background: var(--bg-gray); }

/* ── Buttons ── */
.btn, button:not(.btn-sm):not(.btn-close):not(.icon-close):not(.menu-btn):not(.nav-link) { cursor: pointer; padding: 10px 20px; background: var(--primary-green); color: white; border: none; border-radius: 10px; font-weight: 600; transition: 0.2s; font-size: 0.9em; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover, button:not(.btn-sm):not(.btn-close):not(.icon-close):not(.menu-btn):not(.nav-link):hover { background: var(--dark-green); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; cursor: pointer; border: none; color: white; font-weight: 500; }
.btn-sm.red { background: var(--red); } .btn-sm.red:hover { background: #7f0000; }
.btn-sm.blue { background: var(--blue); } .btn-sm.blue:hover { background: #0d47a1; }
.btn-green  { background: var(--primary-green); color: white; border: none; padding: 10px 22px; border-radius: 10px; font-size: 14px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; transition: 0.2s; }
.btn-green:hover { background: var(--dark-green); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.btn-close { background: none; border: 1px solid #ccc; padding: 9px 18px; border-radius: 6px; cursor: pointer; font-size: 13px; color: #555; }
.btn-close:hover { background: #f5f5f5; }
.btn-ghost { background: white; color: var(--text-main); border: 1px solid var(--border-color); }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-proforma { background: #cfe2ff; color: #084298; }
.badge-delivered { background: #d1ecf1; color: #0c5460; }
.badge-invoice { background: #d1e7dd; color: #0a3622; }
.badge-income { background: #d1e7dd; color: #0a3622; }
.badge-expense { background: var(--light-red); color: var(--red); }
.badge-no-inv { background: #fff3cd; color: #856404; }
.badge-dn { background: #fce4ec; color: #c62828; }
.badge-recurring { background: #cfe2ff; color: #084298; }

/* ── Modal / Overlay ── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 2000; backdrop-filter: blur(4px); }
.overlay.open { display: flex; }
.modal { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); border: 1px solid rgba(255, 255, 255, 0.6); border-radius: 12px; width: 520px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.2); }
.modal-header { padding: 18px 24px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 600; display: flex; align-items: center; margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; touch-action: auto; }
.modal-footer { padding: 14px 24px; border-top: 1px solid #eee; display: flex; gap: 10px; align-items: center; }
.icon-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #888; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.icon-close:hover { background: #f0f0f0; }

/* ── Forms ── */
label { font-size: 11px; font-weight: 600; color: #888; display: block; margin: 14px 0 5px; text-transform: uppercase; letter-spacing: 0.4px; }
input, select, textarea { width: 100%; padding: 10px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 13px; color: #333; background: white; outline: none; transition: border-color 0.2s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-green); box-shadow: 0 0 0 3px rgba(46,125,50,0.1); }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 40px; }
.stat-card { display: flex; align-items: center; gap: 20px; }
.stat-icon { width: 50px; height: 50px; border-radius: 12px; background: var(--light-green); color: var(--primary-green); display: flex; align-items: center; justify-content: center; font-size: 1.2em; }
.stat-val { font-size: 2em; font-weight: 800; margin: 0; color: var(--dark-green); }

/* ── Mobile Header ── */
.mobile-header { display: none; align-items: center; justify-content: space-between; padding: 15px 20px; background: var(--dark-green); color: white; position: sticky; top: 0; z-index: 900; }
.mobile-header h2 { font-size: 1.1em; margin: 0; }
.menu-btn { display: flex; flex-direction: column; gap: 5px; cursor: pointer; }
.menu-btn span { display: block; height: 3px; width: 25px; background: white; border-radius: 3px; transition: 0.3s; }
.menu-btn.active span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.menu-btn.active span:nth-child(2) { opacity: 0; }
.menu-btn.active span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* ── Copyright ── */
.copyright-area { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: auto; flex-wrap: wrap; text-align: center; font-size: 11px; color: rgba(255,255,255,0.4); padding: 20px; border-top: 1px solid rgba(255,255,255,0.05); }
.armor-icon { width: 12px; height: 14px; background-color: var(--accent-green); clip-path: polygon(50% 0%, 90% 18%, 90% 55%, 68% 88%, 50% 100%, 32% 88%, 10% 55%, 10% 18%); flex-shrink: 0; animation: shieldGlow 1.2s infinite alternate ease-in-out; }
@keyframes shieldGlow { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(1.1); opacity: 1; } }

/* ── Hidden utility ── */
.hidden { display: none; }

/* ── KPI Grid ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.kpi { background: rgba(255,255,255,0.7); backdrop-filter: blur(10px); padding: 20px 24px; border-radius: 14px; border: 1px solid rgba(255,255,255,0.5); box-shadow: 0 8px 20px -5px rgba(0,0,0,0.06); }
.kpi-label { font-size: 0.78em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 8px; }
.kpi-val { font-size: 1.7em; font-weight: 800; color: var(--dark-green); line-height: 1; }
.kpi-val.neg { color: var(--red); }
.kpi-sub { font-size: 0.75em; color: var(--text-muted); margin-top: 5px; }
.kpi-icon { float: right; width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1em; }
.kpi-icon.green { background: var(--light-green); color: var(--primary-green); }
.kpi-icon.red { background: var(--light-red); color: var(--red); }
.kpi-icon.blue { background: var(--light-blue); color: var(--blue); }
.kpi-icon.amber { background: var(--light-amber); color: var(--amber); }

/* ── Tab Bar ── */
.tab-bar { display: flex; gap: 8px; margin-bottom: 30px; flex-wrap: wrap; border-bottom: 2px solid var(--border-color); padding-bottom: 0; }
.tab-btn { padding: 10px 20px; border: none; background: none; cursor: pointer; font-size: 0.9em; font-weight: 600; color: var(--text-muted); border-bottom: 3px solid transparent; margin-bottom: -2px; transition: 0.2s; display: flex; align-items: center; gap: 8px; border-radius: 0; }
.tab-btn:hover { color: var(--primary-green); }
.tab-btn.active { color: var(--primary-green); border-bottom-color: var(--primary-green); }
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Cat Tags ── */
.cat-tag { display: inline-block; padding: 2px 8px; background: var(--light-green); color: var(--primary-green); border-radius: 6px; font-size: 11px; font-weight: 600; }

/* ── Progress Bar ── */
.progress-bar { height: 8px; background: #eee; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease; }

/* ══════════════════════════════════════════════════
   PRINT PREVIEW SYSTEM
   ══════════════════════════════════════════════════ */

/* ── Print Preview Overlay (screen mode) ── */
#printPreviewOverlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.print-preview-container {
    background: #fff;
    width: 95vw;
    max-width: 1100px;
    max-height: 95vh;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.print-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    flex-shrink: 0;
}
.print-preview-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}
.print-preview-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.paper-size-wrap {
    display: flex;
    align-items: center;
}
.paper-size-select {
    padding: 7px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    background: white;
    cursor: pointer;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    width: auto;
    min-width: 72px;
}
.paper-size-select:hover {
    border-color: #999;
}
.paper-size-select:focus {
    border-color: var(--primary-green);
    box-shadow: 0 0 0 2px rgba(46,125,50,0.15);
}
.print-preview-actions .btn-ghost {
    background: none;
    border: 1px solid #ccc;
    color: #555;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, border-color 0.2s;
    font-family: inherit;
}
.print-preview-actions .btn-ghost:hover {
    background: #f0f0f0;
    border-color: #999;
}
.print-preview-body {
    flex: 1;
    overflow: auto;
    padding: 0;
    display: flex;
    justify-content: center;
    background: #f0f0f0;
}

/* ── The actual document being previewed ── */
.print-preview-body .print-document {
    width: 210mm;
    min-height: 297mm;
    padding: 14mm 16mm 20mm;
    background: #fff;
    margin: 20px 0;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    font-family: 'Segoe UI', 'Inter', Arial, sans-serif;
    color: #1a1a1a;
    font-size: 9.5pt;
    line-height: 1.6;
    position: relative;
    box-sizing: border-box;
    border: none;
    border-radius: 0;
    flex-shrink: 0;
}

/* ── Document Sections (all use page-break-inside: avoid for print) ── */
.print-document .doc-header,
.print-document .doc-parties,
.print-document .doc-totals-wrap,
.print-document .doc-notes,
.print-document .doc-general-note,
.print-document .doc-company-info,
.print-document .doc-signatory {
    page-break-inside: avoid;
}

/* ── QR Code Signature Area (replaces Authorized Signature for invoice/proforma) ── */
.print-document .doc-qr-signature-wrap {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
}
.print-document .doc-qr-code {
    width: 2cm;
    height: 2cm;
    min-width: 2cm;
    background: #fff;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.print-document .doc-qr-code img {
    width: 100% !important;
    height: 100% !important;
    display: block;
}
.print-document .doc-qr-img {
    width: 2cm;
    height: 2cm;
    display: block;
    flex-shrink: 0;
    image-rendering: pixelated;
    border: 1px solid #ddd;
    border-radius: 2px;
}
.print-document .doc-qr-signature-text {
    font-size: 7.5pt;
    color: #666;
    line-height: 1.5;
    text-align: right;
    font-weight: 500;
}

/* ── Document Header ── */
.print-document .doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    padding-bottom: 14px;
    margin-bottom: 18px;
    border-bottom: 3px solid var(--primary-green);
}
.print-document .doc-brand { display: flex; flex-direction: column; flex: 1; }
.print-document .doc-brand-top { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.print-document .doc-brand-text {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 22pt;
    letter-spacing: 4px;
    line-height: 1;
    margin-bottom: 2px;
}
.print-document .doc-brand-text .brand-nex { color: #071a09; }
.print-document .doc-brand-text .brand-wave { color: #b5f542; }
.print-document .doc-company-name {
    font-size: 9pt;
    font-weight: 700;
    color: #222;
    margin-bottom: 3px;
}
.print-document .doc-company-addr {
    font-size: 8pt;
    color: #555;
    margin-bottom: 4px;
    line-height: 1.45;
}
.print-document .doc-contact-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 7.5pt;
    color: #666;
    line-height: 1.55;
    flex-wrap: wrap;
}
.print-document .doc-contact-sep {
    color: #bbb;
    font-size: 7.5pt;
    margin: 0 3px;
}

.print-document .doc-meta {
    text-align: right;
    flex-shrink: 0;
    min-width: 200px;
}
.print-document .doc-type-badge {
    display: inline-block;
    font-family: 'Bebas Neue', sans-serif;
    font-size: 16pt;
    color: var(--primary-green);
    letter-spacing: 2.5px;
    margin-bottom: 4px;
    line-height: 1.1;
}
.print-document .doc-number {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 10pt;
    font-weight: 400;
    color: #555;
    margin-bottom: 10px;
    letter-spacing: 0.6px;
}
.print-document .doc-meta-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 3px 14px;
    font-size: 8pt;
    justify-content: end;
}
.print-document .meta-label {
    color: #777;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 7pt;
}
.print-document .meta-value { color: #222; font-weight: 500; text-align: right; }
.print-document .meta-status { color: #1565c0; }

/* ── Parties ── */
.print-document .doc-parties {
    display: flex;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 20px;
}
.print-document .doc-party { flex: 1; }
.print-document .doc-party-ref { text-align: right; max-width: 200px; }
.print-document .doc-party-label {
    font-size: 7pt;
    font-weight: 700;
    color: var(--primary-green);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
}
.print-document .doc-party-body { font-size: 8.5pt; color: #444; line-height: 1.55; }
.print-document .doc-party-body strong { color: #111; }

/* ── Items Table ── */
.print-document .items-section {
    margin-bottom: 16px;
}
.print-document table.doc-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
}
.print-document table.doc-items thead {
    display: table-header-group;
}
.print-document table.doc-items th {
    background: var(--primary-green);
    color: #fff;
    font-size: 7pt;
    font-weight: 700;
    padding: 8px 10px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.print-document table.doc-items td {
    padding: 8px 10px;
    font-size: 8.5pt;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}
.print-document table.doc-items tbody tr:last-child td {
    border-bottom: none;
}
.print-document table.doc-items tbody tr:nth-child(even) td { background: #fafafa; }
.print-document table.doc-items td small { color: #888; font-size: 7.5pt; }
.print-document table.doc-items .col-qty { text-align: right; white-space: nowrap; }
.print-document table.doc-items .col-unit { text-align: right; white-space: nowrap; }
.print-document table.doc-items .col-price { text-align: right; white-space: nowrap; }
.print-document table.doc-items .col-total { text-align: right; font-weight: 600; white-space: nowrap; }
.print-document table.doc-items th.col-qty { text-align: right; }
.print-document table.doc-items th.col-unit { text-align: right; }
.print-document table.doc-items th.col-price { text-align: right; }
.print-document table.doc-items th.col-total { text-align: right; }
.print-document table.doc-items .doc-empty { text-align: center; color: #aaa; padding: 24px; }

/* ── Totals ── */
.print-document .doc-totals-wrap {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
    page-break-inside: avoid;
    margin-top: 4px;
}
.print-document .doc-totals { width: 260px; }
.print-document .doc-total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 9.5pt;
    color: #333;
}
.print-document .doc-grand-total {
    font-size: 11pt;
    font-weight: 800;
    color: var(--dark-green);
    border-top: 2px solid var(--primary-green);
    padding-top: 8px;
    margin-top: 4px;
}

/* ── Notes & Signature ── */
.print-document .doc-notes {
    margin-top: 16px;
    padding: 10px 12px;
    font-size: 8pt;
    color: #555;
    page-break-inside: avoid;
    background: #fafafa;
    border-left: 3px solid var(--primary-green);
}
.print-document .doc-notes strong {
    display: block;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #333;
    margin-bottom: 4px;
}
.print-document .doc-notes p { margin: 0; line-height: 1.55; }

.print-document .doc-general-note {
    margin-top: 12px;
    padding: 0;
    font-size: 8pt;
    color: #555;
    page-break-inside: avoid;
    border: none;
}
.print-document .doc-general-note strong {
    display: block;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #333;
    margin-bottom: 4px;
}
.print-document .doc-general-note p { margin: 0; line-height: 1.55; }

.print-document .doc-footer-divider {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 12px 0 6px 0;
}

.print-document .doc-signatory {
    margin-top: 28px;
    text-align: right;
    font-size: 8pt;
    color: #888;
    page-break-inside: avoid;
}
.print-document .doc-sign-line {
    width: 180px;
    border-top: 1px solid #b5f542;
    margin-left: auto;
    margin-bottom: 6px;
}

/* ── Company Info Block (bottom of document) ── */
.print-document .doc-company-info {
    margin-top: 10px;
    padding: 6px 0 0;
    font-size: 7pt;
    color: #999;
    line-height: 1.5;
    page-break-inside: avoid;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

/* ── Page footer: hidden on screen, shown via position:fixed in @media print ── */    .print-document .print-page-footer {
    display: none;
}

/* ── Paper size CSS classes (replaces JS-set inline dimensions) ── */
.print-preview-body .print-document.paper-a4 {
    width: 210mm;
    min-height: 297mm;
}
.print-preview-body .print-document.paper-letter {
    width: 216mm;
    min-height: 279mm;
}
.print-preview-body .print-document.paper-legal {
    width: 216mm;
    min-height: 356mm;
}

/* ── ████████████████████████████████████████████████████████████████ ── */
/* ── @MEDIA PRINT: PREVIEW MODE (Print Preview → Ctrl+P) ── */
/* ── ████████████████████████████████████████████████████████████████ ── */

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
        orphans: 3;
        widows: 3;
    }

    /* ── Strip all background, margins, and flex from body/overlay ── */
    body, #printPreviewOverlay {
        background: none !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }

    /* ── Hide everything outside the print overlay ── */
    body.print-preview-active > *:not(#printPreviewOverlay) {
        display: none !important;
    }

    /* ── Overlay becomes the page ── */
    body.print-preview-active #printPreviewOverlay {
        position: static !important;
        background: none !important;
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }

    body.print-preview-active .print-preview-container {
        box-shadow: none !important;
        max-width: none !important;
        width: auto !important;
        height: auto !important;
        border-radius: 0 !important;
        overflow: visible !important;
    }

    /* ── Hide toolbar (Print button, paper-size selector, close) ── */
    body.print-preview-active .print-preview-header,
    body.print-preview-active .print-preview-actions,
    body.print-preview-active .paper-size-wrap,
    body.print-preview-active .paper-size-select {
        display: none !important;
    }

    /* ── Print body becomes a simple block (not flex) ── */
    body.print-preview-active .print-preview-body {
        overflow: visible !important;
        background: white !important;
        padding: 0 !important;
        display: block !important;
        justify-content: normal !important;
        align-items: normal !important;
        height: auto !important;
    }

    /* ── Document fills the @page content area exactly ── */
    body.print-preview-active .print-document {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        margin: 0 !important;
        padding: 14mm 16mm 20mm !important;
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        box-sizing: border-box !important;
        font-size: 9.5pt !important;
        line-height: 1.6 !important;
    }

    /* ── Page break: avoid orphans on compact blocks ── */
    body.print-preview-active .doc-header .doc-brand,
    body.print-preview-active .doc-header .doc-meta,
    body.print-preview-active .doc-party,
    body.print-preview-active .doc-totals,
    body.print-preview-active .doc-notes,
    body.print-preview-active .doc-general-note,
    body.print-preview-active .doc-general-note p,
    body.print-preview-active .doc-signatory,
    body.print-preview-active .doc-company-info {
        page-break-inside: avoid;
        break-inside: avoid-page;
    }

    /* ── Items table: allow page breaks between rows ── */
    body.print-preview-active .items-section {
        display: block;
        page-break-inside: auto;
        break-inside: auto;
        page-break-after: auto;
    }

    body.print-preview-active table.doc-items {
        width: 100% !important;
        page-break-inside: auto;
        break-inside: auto;
    }

    /* ── Never split a single table row across two pages ── */
    body.print-preview-active table.doc-items tbody tr,
    body.print-preview-active table.doc-items tr {
        page-break-inside: avoid;
        break-inside: avoid;
        page-break-after: auto;
    }

    /* ── Repeat table header on each page fragment ── */
    body.print-preview-active table.doc-items thead,
    body.print-preview-active .doc-items thead {
        display: table-header-group;
    }

    body.print-preview-active table.doc-items tfoot {
        display: table-footer-group;
    }

    body.print-preview-active tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* ── Page footer (fixed to bottom of each printed page) ── */
    /* ── Page footer (fixed to bottom of each printed page) ── */
    body.print-preview-active .print-page-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        font-size: 7pt;
        color: #999;
        border-top: 1px solid #ddd;
        padding: 3px 14px 0;
        background: white;
        z-index: 10001;
        width: 100%;
        box-sizing: border-box;
    }

    body.print-preview-active .print-footer-content {
        display: flex;
        justify-content: space-between;
        padding: 0 4px;
        max-width: 178mm;
        margin: 0 auto;
    }

    body.print-preview-active .print-footer-ref,
    body.print-preview-active .print-footer-pages {
        color: #999;
        font-size: 7pt;
    }

    /* ── QR code: same size as screen preview (2cm) so positions match exactly ── */
    .doc-qr-img {
        width: 2cm !important;
        height: 2cm !important;
        display: block !important;
    }

    /* ── Preserve background colors in print (table headers, badges) ── */
    .print-document,
    .print-document * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* ── Unscoped fallbacks for broader browser support ── */
    .print-document {
        display: block;
        width: 100%;
    }
    .items-section {
        page-break-inside: auto;
        break-inside: auto;
    }
    tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }
}

/* ── ████████████████████████████████████████████████████████████████ ── */
/* ── @MEDIA PRINT: REGULAR PAGE PRINTING (non-preview pages) ── */
/* ── ████████████████████████████████████████████████████████████████ ── */

@media print {
    body:not(.print-preview-active) {
        background: white !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    body:not(.print-preview-active) .sidebar,
    body:not(.print-preview-active) button,
    body:not(.print-preview-active) .nav-link,
    body:not(.print-preview-active) .user-info,
    body:not(.print-preview-active) .mobile-header,
    body:not(.print-preview-active) .tab-bar,
    body:not(.print-preview-active) .period-bar,
    body:not(.print-preview-active) .btn,
    body:not(.print-preview-active) .copyright-area,
    body:not(.print-preview-active) .sidebar-backdrop,
    body:not(.print-preview-active) .btn-green,
    body:not(.print-preview-active) .btn-sm,
    body:not(.print-preview-active) .btn-close,
    body:not(.print-preview-active) .btn-ghost,
    body:not(.print-preview-active) .kpi-icon,
    body:not(.print-preview-active) .menu-btn { display: none !important; }
    body:not(.print-preview-active) .main-wrapper,
    body:not(.print-preview-active) .main-content { margin: 0 !important; padding: 0 !important; width: 100% !important; }
    body:not(.print-preview-active) .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
    body:not(.print-preview-active) table { width: 100% !important; }
    body:not(.print-preview-active) tr,
    body:not(.print-preview-active) img { page-break-inside: avoid; }
    body:not(.print-preview-active) thead { display: table-header-group; }
    /* ── QR code: same size as screen preview (2cm) for position consistency ── */
    .doc-qr-img {
        width: 2cm !important;
        height: 2cm !important;
        display: block !important;
    }
    /* ── Preserve background colors on non-preview print ── */
    .print-document,
    .print-document * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ── ████████████████████████████████████████████████████████████████ ── */
/* ── RESPONSIVE: Print Preview on small screens ── */
/* ── ████████████████████████████████████████████████████████████████ ── */

@media (max-width: 900px) {
    .print-preview-container {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }
    .print-preview-header {
        padding: 12px 16px;
    }
    .print-preview-header h3 {
        font-size: 14px;
    }
    .print-preview-actions .btn-green {
        padding: 8px 14px;
        font-size: 12px;
    }
    .print-preview-body .print-document {
        width: 100%;
        min-height: auto;
        padding: 8mm 6mm;
        margin: 10px;
        font-size: 8.5pt;
    }
    /* Allow horizontal scroll on mobile for wide documents */
    .print-preview-body {
        justify-content: flex-start;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    .print-document .doc-header {
        flex-direction: column;
        gap: 12px;
    }
    .print-document .doc-meta {
        text-align: left;
        min-width: auto;
        width: 100%;
    }
    .print-document .doc-meta-grid {
        justify-content: start;
        grid-template-columns: auto 1fr;
    }
    .print-document .doc-parties {
        flex-direction: column;
        gap: 16px;
    }
    .print-document .doc-totals {
        width: 100%;
    }
    .print-document table.doc-items {
        font-size: 7.5pt;
    }
    .print-document table.doc-items th,
    .print-document table.doc-items td {
        padding: 6px 6px;
    }
}

@media (max-width: 600px) {
    .print-preview-body .print-document {
        padding: 6mm 4mm;
        margin: 6px;
        font-size: 8pt;
    }
    .print-document .doc-brand-text {
        font-size: 18pt;
    }
    .print-document .doc-type-badge {
        font-size: 14pt;
    }
}

/* ── Sidebar Backdrop (mobile) ── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-backdrop.open {
    display: block;
    opacity: 1;
}

/* ── Mobile Layout Tweaks (shared) ── */
@media (max-width: 1200px) {
    .main-content { padding: 32px 24px; }
}

/* ── Sidebar: ensure desktop doesn't show translate by default ── */
.sidebar {
    transform: none;
}

/* ── Tablet Portrait (768px - 900px) ── */
@media (max-width: 900px) {
    /* 1. Sidebar — left drawer */
    .sidebar { transform: translateX(-100%); width: 280px; height: 100vh; top: 0; left: 0; z-index: 2000; box-shadow: 2px 0 20px rgba(0,0,0,0.2); }
    .sidebar.open { transform: translateX(0); }

    /* 2. Mobile header — fixed at top, hamburger on right */
    .mobile-header { display: flex !important; position: fixed; top: 0; right: 0; left: 0; z-index: 1500; background: var(--dark-green); justify-content: space-between; }
    .menu-btn { margin-left: auto; order: 2; }

    /* 3. Main content — full width, padded below header */
    .main-wrapper { margin-left: 0 !important; padding-top: 60px; }
    .main-content { padding: 20px 15px !important; }

    .stats-grid { grid-template-columns: 1fr; }
    table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    h1 { font-size: 1.3em; margin-bottom: 20px; gap: 8px; }
    h1 i { font-size: 1em; }
    .kpi-grid { grid-template-columns: 1fr; gap: 12px; }
    .modal { width: 95vw; max-height: 95vh; }
    .modal-body { max-height: 60vh !important; }

    /* Touch-friendly inputs & buttons — prevents iOS zoom on focus */
    input, select, textarea, .btn, button, .btn-sm { font-size: 16px !important; }
    input, select, textarea { min-height: 44px; padding: 10px 12px; }
    button:not(.btn-sm):not(.icon-close):not(.nav-link) { min-height: 44px; padding: 10px 18px; }
    .btn-sm { min-height: 36px; padding: 8px 12px; }

    /* Tab bar: horizontal scroll on mobile */
    .tab-bar { overflow-x: auto; flex-wrap: nowrap; gap: 4px; padding-bottom: 2px; scrollbar-width: none; -ms-overflow-style: none; }
    .tab-bar::-webkit-scrollbar { display: none; }
    .tab-btn { white-space: nowrap; padding: 10px 14px; font-size: 0.82em; flex-shrink: 0; }

    /* Action/search bar */
    .action-bar { flex-direction: column; gap: 8px; }
    .action-bar button { width: 100%; justify-content: center; }
    .search-bar { flex-direction: column; gap: 8px; }
    .search-bar input { min-width: 0; width: 100%; }
    .search-bar select { width: 100%; }

    /* Card improvements */
    .card { padding: 18px; border-radius: 12px; }

    /* Line items on mobile */
    .line-item { grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border: 1px solid #eee; border-radius: 8px; margin-bottom: 8px; background: #fafafa; }
    .li-header { display: none; }

    /* KPI cards */
    .kpi { padding: 16px 18px; }
    .kpi-val { font-size: 1.4em; }

    /* Totals bar */
    .totals-bar { flex-direction: column; gap: 8px; align-items: stretch; }
    .totals-bar .value { font-size: 18px; }

    /* Tile grid */
    .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .tile { padding: 14px 10px; }
    .tile i { font-size: 20px; }
    .tile h4 { font-size: 12px; }
    .tile p { display: none; }

    /* Stat card */
    .stat-card { gap: 14px; padding: 16px; }
    .stat-val { font-size: 1.5em; }
    .stat-icon { width: 40px; height: 40px; font-size: 1em; }

    /* Form rows */
    .form-row, .form-row-3, .form-row-4, .client-grid, .product-meta, .settings-grid { grid-template-columns: 1fr; }

    /* Search input on customer/products pages */
    #customerSearch, #productSearch { width: 100%; min-width: 0; }

    /* Document actions */
    .doc-actions { flex-wrap: wrap; gap: 4px; }
    .doc-actions .btn-sm { font-size: 10px; padding: 6px 8px; }

    /* Accounting P&L grid */
    #pnlContent > div { grid-template-columns: 1fr; }

    /* Stats-grid inside cards */
    #summaryGrid { grid-template-columns: 1fr; }

    /* Overlay backdrop */
    .overlay.open { padding: 8px; }

    /* Tighter h1 with less icon gap */
    .action-bar { flex-direction: column; gap: 8px; }
    .action-bar button { width: 100%; justify-content: center; }

    /* Convert dialog buttons on mobile */
    #convertEstOverlay .modal-body button { padding: 14px !important; font-size: 15px !important; }
    #convertEstOverlay .modal-body button span { font-size: 11px !important; }
}

/* ── Small tablets & large phones (600px - 768px) ── */
@media (max-width: 768px) {
    .main-content { padding: 16px 12px; }
    .mobile-header { padding: 12px 16px; }
    .mobile-header h2 { font-size: 1em; }
    h1 { font-size: 1.15em; margin-bottom: 16px; }
    .card { padding: 16px; border-radius: 10px; margin-bottom: 20px; }
    .kpi-grid { gap: 10px; }
    .kpi { padding: 14px 16px; }
    .kpi-val { font-size: 1.3em; }
    .kpi-icon { width: 30px; height: 30px; font-size: 0.85em; }

    /* Compact tables */
    th, td { padding: 10px 10px; font-size: 13px; }

    /* Tighter tile grid */
    .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .tile { padding: 12px 8px; }
    .tile i { font-size: 18px; margin-bottom: 4px; }
    .tile h4 { font-size: 11px; }
    .tile p { display: none; }

    /* Compact stats */
    .stat-card { gap: 12px; padding: 14px; }
    .stat-val { font-size: 1.4em; }
    .stat-icon { width: 36px; height: 36px; font-size: 0.9em; }

    /* Modals — full-screen on tablet/mobile */
    .modal { width: 100vw; border-radius: 0; max-height: 100vh; }
    .modal-header { padding: 14px 16px; }
    .modal-header h3 { font-size: 14px; }
    .modal-body { padding: 14px; max-height: calc(100vh - 120px) !important; }
    .modal-footer { padding: 12px 16px; flex-direction: column; gap: 8px; }
    .modal-footer .btn-close,
    .modal-footer .btn-green { width: 100%; justify-content: center; }

    /* Line items at 768px */
    .line-item { padding: 8px 10px; }

    .tab-bar { gap: 2px; }
    .tab-btn { padding: 8px 12px; font-size: 0.78em; }
    .tab-btn i { font-size: 0.9em; }

    .totals-bar .value { font-size: 16px; }

    #pnlContent > div { grid-template-columns: 1fr !important; }

}

/* ── Card-view tables for better mobile/tablet readability ── */
@media (max-width: 768px) {
    .main-content table.card-view thead {
        display: none;
    }
    .main-content table.card-view tbody tr {
        display: flex; flex-direction: column; border: 1px solid var(--border-color);
        border-radius: 10px; margin-bottom: 10px; padding: 12px; background: white;
        box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    }
    .main-content table.card-view tbody tr:hover td { background: transparent; }
    .main-content table.card-view td {
        display: flex; justify-content: space-between; align-items: center;
        padding: 6px 0; border: none; font-size: 13px;
    }
    .main-content table.card-view td::before {
        content: attr(data-label);
        font-weight: 600; color: #888; font-size: 11px; text-transform: uppercase;
        margin-right: 12px; flex-shrink: 0; min-width: 80px;
    }
    .main-content table.card-view td:last-child { border-bottom: none; }
    .main-content table.card-view td:first-child { font-weight: 600; color: var(--dark-green); }
}

/* ── Extra small phones (480px and below) ── */
@media (max-width: 480px) {
    .main-content { padding: 12px 10px; }
    .mobile-header { padding: 10px 12px; }
    .mobile-header h2 { font-size: 0.95em; }
    h1 { font-size: 1.05em; margin-bottom: 14px; gap: 6px; }
    h1 i { font-size: 0.9em; }
    .card { padding: 14px; border-radius: 10px; margin-bottom: 16px; }

    /* Tighter KPIs */
    .kpi { padding: 12px 14px; }
    .kpi-val { font-size: 1.2em; }
    .kpi-icon { width: 28px; height: 28px; font-size: 0.8em; }
    .kpi-label { font-size: 0.7em; }

    /* Tighter stats */
    .stat-card { gap: 10px; padding: 12px; }
    .stat-val { font-size: 1.3em; }
    .stat-icon { width: 34px; height: 34px; font-size: 0.85em; }

    /* Full-width modals */
    .modal { width: 100vw; border-radius: 0; max-height: 100vh; }
    .modal-header { padding: 12px 14px; }
    .modal-header h3 { font-size: 13px; }
    .modal-body { padding: 12px; max-height: calc(100vh - 110px) !important; }
    .modal-footer { padding: 10px 14px; flex-direction: column; gap: 6px; }
    .modal-footer .btn-close,
    .modal-footer .btn-green { width: 100%; justify-content: center; }

    /* Smaller tile grid */
    .tile-grid { gap: 6px; }
    .tile { padding: 10px 6px; }
    .tile i { font-size: 16px; }
    .tile h4 { font-size: 10px; }

    /* Compact tab bar */
    .tab-bar { gap: 2px; }
    .tab-btn { padding: 6px 10px; font-size: 0.72em; }
    .tab-btn i { font-size: 0.8em; margin-right: 2px; }

    /* Search bars */
    .search-bar, .action-bar { gap: 6px; }
    .search-bar input, .search-bar select { padding: 8px 10px; font-size: 14px !important; }

    /* Touch-friendly button sizing */
    button:not(.btn-sm):not(.icon-close):not(.nav-link) { min-height: 42px; padding: 8px 14px; }
    .btn-sm { min-height: 34px; padding: 6px 10px; font-size: 11px !important; }

    /* Compact tables */
    th, td { padding: 8px 8px; font-size: 12px; }

    /* Line items */
    .line-item { padding: 6px 8px; gap: 4px; }
    .line-item input { font-size: 13px; padding: 6px 8px; }

    /* Totals bar */
    .totals-bar .value { font-size: 15px; }

    /* Form rows */
    .form-row, .form-row-3, .form-row-4, .client-grid, .product-meta, .settings-grid { grid-template-columns: 1fr; gap: 8px; }

    /* P&L grid */
    #pnlContent > div { grid-template-columns: 1fr !important; gap: 12px; }

    /* Convert dialog buttons */
    #convertEstOverlay .modal-body button { padding: 12px !important; font-size: 14px !important; }
    #convertEstOverlay .modal-body button span { font-size: 10px !important; }

    /* Overlay */
    .overlay.open { padding: 0; }
}
