/* ═══════════════════════════════════════════════════════════════
   Print Styles — A4 PDF Output + Preview Scaling
   ═══════════════════════════════════════════════════════════════ */

/* ── Screen Preview ──────────────────────────────────────────── */
.preview-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg) 0;
}

.preview-workspace {
    width: 100%;
    overflow: hidden;
    background: var(--card-bg);
    padding: var(--space-lg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
}

.page-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: visible;
    transition: height 0.2s ease;
}

.page-wrapper.fixed-height {
    height: 297mm;
}

.page-wrapper.flex-height {
    height: auto;
}

/* ── A4 Page ─────────────────────────────────────────────────── */
.print-page {
    width: 210mm;
    min-width: 210mm;
    flex-shrink: 0;
    min-height: 297mm;
    max-height: 297mm;
    padding: 11mm;
    box-sizing: border-box;
    background: white;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow-lg);
    font-family: var(--font-body);
    color: #000;
}

.print-page.flex-page {
    max-height: none;
}

/* ── A4 Typography ───────────────────────────────────────────── */
.print-page .doc-title {
    font-size: 28px;
    font-weight: 700;
    text-align: right;
    color: #000;
    line-height: 1.2;
}

.print-page .doc-subtitle {
    font-size: 10px;
    font-weight: 500;
    text-align: right;
    color: #64748b;
    margin-top: -2px;
}

.print-page .doc-brand-name {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -0.02em;
    color: #000;
}

.print-page .doc-brand-tagline {
    font-size: 9px;
    color: #64748b;
    font-weight: 500;
    font-style: italic;
    margin-top: -2px;
}

/* ── A4 Info Block ───────────────────────────────────────────── */
.print-page .info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    font-size: 11px;
    line-height: 1.5;
    color: #000;
}

.print-page .info-label {
    display: inline-block;
    width: 56px;
    color: #64748b;
    font-weight: 500;
    flex-shrink: 0;
}

.print-page .info-label-wide {
    display: inline-block;
    width: 64px;
    color: #64748b;
    font-weight: 500;
    flex-shrink: 0;
}

.print-page .info-value {
    font-weight: 700;
    color: #000;
}

/* ── A4 Document Meta Box ────────────────────────────────────── */
.print-page .doc-meta-box {
    background: #000;
    color: #fff;
    padding: 10px;
    font-size: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.print-page .doc-meta-row {
    display: flex;
    justify-content: space-between;
}

.print-page .doc-meta-value {
    font-weight: 700;
    margin-left: auto;
}

/* ── A4 Table ────────────────────────────────────────────────── */
.print-page .doc-table {
    width: 100%;
    text-align: left;
    font-size: 11px;
    border-collapse: collapse;
    border: 1px solid #000;
    table-layout: fixed;
}

.print-page .doc-table thead tr {
    background: #000;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}

.print-page .doc-table th,
.print-page .doc-table td {
    padding: 8px;
    border: 1px solid #000;
}

.print-page .doc-table th {
    font-weight: 600;
}

.print-page .doc-table tbody tr {
    vertical-align: top;
    color: #000;
}

.print-page .doc-table .col-no { width: 40px; text-align: center; }
.print-page .doc-table .col-desc { width: 45%; }
.print-page .doc-table .col-qty { width: 48px; text-align: center; }
.print-page .doc-table .col-unit { width: 48px; text-align: center; }
.print-page .doc-table .col-price { width: 80px; text-align: right; }
.print-page .doc-table .col-amount { width: 96px; text-align: right; }
.print-page .doc-table .col-wht { width: 48px; text-align: center; }

/* ── A4 Summary Block ────────────────────────────────────────── */
.print-page .summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    font-size: 11px;
    margin-top: 8px;
}

.print-page .summary-left {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px;
}

.print-page .summary-right {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.print-page .grand-total-box {
    background: #000;
    color: #fff;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #000;
}

.print-page .grand-total-label {
    font-size: 11px;
    font-weight: 700;
}

.print-page .grand-total-value {
    font-size: 16px;
    font-weight: 700;
}

.print-page .net-row {
    padding: 8px;
    background: #fff;
    border: 1px solid #000;
    border-top: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.print-page .net-row-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.print-page .net-row-item.final {
    border-top: 1px solid #d1d5db;
    padding-top: 8px;
    font-weight: 700;
}

/* ── A4 Bank Grid ────────────────────────────────────────────── */
.print-page .bank-section {
    margin-top: 16px;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    padding: 12px 0;
}

.print-page .bank-section-title {
    font-size: 10px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
}

.print-page .bank-grid {
    display: grid;
    gap: 4px;
    font-size: 9px;
    line-height: 1.3;
    color: #475569;
}

.print-page .bank-item {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    border-right: 1px solid rgba(0, 0, 0, 0.15);
    padding-right: 4px;
}

.print-page .bank-item:last-child {
    border-right: none;
}

.print-page .bank-icon {
    width: 14px;
    height: 14px;
    object-fit: contain;
    margin-top: 2px;
    flex-shrink: 0;
}

.print-page .bank-name {
    font-weight: 700;
    color: #000;
}

.print-page .bank-acc-name {
    font-size: 8px;
    color: #94a3b8;
}

/* ── A4 Signature Block ──────────────────────────────────────── */
.print-page .sign-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #000;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    font-size: 9px;
    text-align: center;
    color: #475569;
}

.print-page .sign-box {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: 80px;
    line-height: 1.1;
}

.print-page .sign-title {
    font-weight: 700;
    color: #000;
    font-size: 9px;
}

.print-page .sign-image {
    max-width: 100%;
    max-height: 28px;
    object-fit: contain;
}

.print-page .sign-name {
    font-size: 8px;
    color: #475569;
}

.print-page .sign-date {
    font-size: 7px;
    color: #94a3b8;
}

.print-page .stamp-box {
    border: 1px dashed rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 4px;
    background: rgba(248, 250, 252, 0.3);
    height: 80px;
}

.print-page .stamp-label {
    font-size: 8px;
    font-weight: 700;
    color: #94a3b8;
}

.print-page .stamp-image {
    max-width: 48px;
    max-height: 40px;
    object-fit: contain;
    margin-top: auto;
    margin-bottom: 4px;
}

.print-page .customer-sign-box {
    border: 1px solid #000;
    text-align: left;
    padding: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 80px;
    background: #fff;
}

.print-page .customer-sign-title {
    font-weight: 700;
    color: #000;
    text-align: center;
    font-size: 9px;
}

.print-page .customer-sign-line {
    font-size: 8px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
}

/* ── A4 Page Footer ──────────────────────────────────────────── */
.print-page .page-footer {
    text-align: center;
    font-size: 9px;
    font-family: var(--font-heading);
    font-weight: 700;
    color: #000;
    letter-spacing: 0.1em;
    opacity: 0.8;
    padding-top: 12px;
    user-select: none;
}

/* ── Page Divider (screen only) ──────────────────────────────── */
.page-divider {
    width: 210mm;
    border-top: 2px dashed var(--text-muted);
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    padding-top: 4px;
    user-select: none;
}

/* ═══════════════════════════════════════════════════════════════
   @media print — Override everything for PDF output
   ═══════════════════════════════════════════════════════════════ */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    html, body {
        width: 210mm !important;
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide everything except preview */
    .no-print,
    .sidebar,
    .sidebar-toggle,
    .sidebar-overlay,
    .mode-toggle-bar,
    .mobile-bottom-bar,
    .page-divider {
        display: none !important;
    }

    .app-content {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
    }

    .preview-workspace {
        padding: 0 !important;
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important;
        display: block !important;
        width: 210mm !important;
        height: auto !important;
    }

    .page-wrapper {
        width: 210mm !important;
        display: block !important;
        transform: none !important;
    }

    .page-wrapper.fixed-height {
        height: 297mm !important;
        max-height: 297mm !important;
        min-height: 297mm !important;
    }

    .page-wrapper.flex-height {
        height: auto !important;
        max-height: none !important;
        min-height: 297mm !important;
    }

    .print-page {
        width: 210mm !important;
        height: 297mm !important;
        max-width: 210mm !important;
        min-width: 210mm !important;
        max-height: 297mm !important;
        min-height: 297mm !important;
        padding: 11mm !important;
        box-sizing: border-box !important;
        background: white !important;
        page-break-after: always !important;
        break-after: page !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        border: none !important;
        box-shadow: none !important;
        transform: none !important;
    }

    .print-page.flex-page {
        height: auto !important;
        max-height: none !important;
        min-height: 297mm !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    /* Ensure form mode is hidden */
    #form-mode-container {
        display: none !important;
    }

    #preview-mode-container {
        display: block !important;
        width: 210mm !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }

    main.app-content {
        max-width: none !important;
        width: 210mm !important;
    }
}
