/* Copyright 2025 Renofy Ltd. All rights reserved. */
@page {
    size: A4;
    margin: 0; /* we manage printable margins via the .print-container padding */
}

@media print {
    .no-print {
        display: none !important;
    }

    /* reset page and body so browser margins don't stack on our layout */
    html, body {
        margin: 0;
        padding: 0;
        height: auto;
        background-color: white;
    }

    /* Use an exact A4 content width and internal padding to control printable margins.
       This is more reliable across browsers than relying on browser print margins. */
    .print-container {
        box-shadow: none;
        padding: 15mm; /* 1.5cm safe printable margin */
        margin: 0 auto;
        width: 210mm;     /* A4 width */
        max-width: 210mm;
        min-width: 210mm;
        box-sizing: border-box;
        transform: none !important; /* ensure no page scaling (overrides mobile scaling rules) */
        transform-origin: initial !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica', 'Arial', sans-serif;
    font-size: 10pt;
    line-height: 1.5;
    color: #333;
    background-color: #f5f5f5;
    padding: 2rem;
    overflow-x: auto;
}

.print-container {
    max-width: 21cm;
    min-width: 21cm;
    margin: 0 auto;
    background: white;
    padding: 1.5cm;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

/* Mobile: scale down to fit viewport while maintaining layout */
@media (max-width: 820px) {
    body {
        padding: 0;
        overflow-x: scroll;
    }

    .print-container {
        transform-origin: top left;
        /* Scale down proportionally to fit mobile screens */
        transform: scale(0.45);
        margin: 0;
    }

    /* Adjust body height to account for scaled content */
    html {
        /* Calculate approximate height: original height * scale factor */
        min-height: calc(100vh / 0.45);
    }
}

/* Print Actions */
.print-actions {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: var(--z-index-header);
}

/* Mobile: adjust button positioning for scaled content */
@media (max-width: 820px) {
    .print-actions {
        position: fixed;
        top: 0.5rem;
        right: 0.5rem;
        flex-direction: column;
        gap: 0.25rem;
    }

    .print-btn {
        font-size: 12px;
        padding: 0.5rem 1rem;
    }
}

.print-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.print-btn:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.close-btn {
    background: #7f8c8d;
}

.close-btn:hover {
    background: #6c7a7b;
}

/* Invoice Header */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid #3498db;
}

.company-info h1 {
    font-size: 28pt;
    color: #2c3e50;
    margin-bottom: 0.25rem;
    font-weight: 700;
}

.company-tagline {
    color: #7f8c8d;
    font-size: 11pt;
}

.quote-meta {
    text-align: right;
}

.quote-number {
    font-size: 20pt;
    font-weight: 700;
    color: #3498db;
    margin-bottom: 0.25rem;
}

.quote-date {
    color: #7f8c8d;
    font-size: 9pt;
}

/* Two Column Info */
.info-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.info-box {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.info-box h3 {
    font-size: 11pt;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-row {
    display: flex;
    margin-bottom: 0.3rem;
    font-size: 9pt;
}

.info-label {
    font-weight: 600;
    color: #7f8c8d;
    min-width: 100px;
}

.info-value {
    color: #2c3e50;
}

/* Job Details Section */
.job-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: #fff9e6;
    border-left: 3px solid #ffc107;
    border-radius: 4px;
}

.job-section h3 {
    font-size: 11pt;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.job-title {
    font-size: 13pt;
    font-weight: 600;
    color: #1F2937;
    margin-bottom: 0.5rem;
}

.job-description {
    color: #1F2937;
    line-height: 1.6;
    font-size: 9pt;
}

/* Section Header */
.section-header {
    font-size: 13pt;
    font-weight: 700;
    color: #2c3e50;
    margin: 1.5rem 0 0.75rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.4rem;
}

/* Professional Table */
.milestones-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.75rem;
}

.milestones-table thead {
    background-color: #2c3e50;
    color: white;
}

.milestones-table th {
    padding: 0.6rem 0.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 9pt;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.milestones-table th.text-right {
    text-align: right;
}

.milestones-table tbody tr {
    border-bottom: 1px solid #dee2e6;
}

.milestones-table td {
    padding: 0.6rem 0.5rem;
    vertical-align: top;
    font-size: 9pt;
}

.milestone-number {
    font-weight: 600;
    color: #6c757d;
    width: 90px;
}

.milestone-description {
    color: #2c3e50;
    line-height: 1.5;
}

.milestone-cost {
    text-align: right;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
    width: 120px;
}

/* Totals Section */
.totals-section {
    margin-left: auto;
    width: 350px;
    margin-top: 0.5rem;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    font-size: 10pt;
}

.totals-row.total {
    background-color: #2c3e50;
    color: white;
    font-size: 14pt;
    font-weight: 700;
    border: none;
    margin-top: 0.25rem;
}

.totals-label {
    font-weight: 600;
}

.totals-value {
    font-weight: 700;
}

/* Notes Section */
.notes-section {
    margin-top: 1.5rem;
    padding: 1rem;
    background-color: #f8f9fa;
    border-left: 3px solid #3498db;
    border-radius: 4px;
}

.notes-section h3 {
    font-size: 11pt;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.notes-text {
    color: #2c3e50;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 9pt;
}

/* Footer */
.footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 2px solid #dee2e6;
    font-size: 8pt;
    color: #6c757d;
    text-align: center;
    line-height: 1.6;
}

.footer p {
    margin-bottom: 0.2rem;
}

.footer strong {
    color: #2c3e50;
}
