:root {
    --primary-color: #333;
    --border-color: #ddd;
    --bg-color: #f5f5f5;
    --spacing-sm: 8px;
    --spacing-md: 15px;
    --spacing-lg: 20px;
}

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

body {
    font-family: sans-serif;
    background-color: var(--bg-color);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}

.a4-container {
    /* Screen mode: Fit height */
    height: calc(100vh - 40px);
    aspect-ratio: 210/297;
    width: auto;
    max-width: 100%;
    background: white;
    padding: 2vh 3vh;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent scrolling */
}

.header {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-bottom: 2vh;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 1.5vh;
    flex-shrink: 0;
}

.header-top {
    width: 100%;
    text-align: center;
    margin-bottom: 1.5vh;
}

.header-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-logo {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

.header-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: right;
    padding-left: 3vh;
}

.logo-placeholder {
    width: 12vh;
    height: 8vh;
    background-color: #f8f9fa;
    border: 1px dashed #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
    font-weight: 600;
    font-size: 1.2vh;
    border-radius: 4px;
}

.document-title {
    font-size: 3.5vh;
    font-weight: 400;
    color: #2c3e50;
    text-transform: uppercase;
    letter-spacing: 2px;
    white-space: nowrap;
    background-color: #f0f4f8;
    padding: 1vh 0;
    width: 100%;
    display: block;
}

.company-name {
    font-size: 2.2vh;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.5vh;
    line-height: 1.2;
    white-space: nowrap;
}

.company-details {
    font-size: 1.1vh;
    color: #555;
    line-height: 1.4;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5vh;
    margin-bottom: 1vh;
    font-size: 1.2vh;
    flex-shrink: 0;
}

.info-section {
    border: 1px solid var(--border-color);
    padding: 0.5vh;
    border-radius: 4px;
    height: 100%;
}

.info-row {
    display: grid;
    grid-template-columns: 40% 60%;
    margin-bottom: 0.5vh;
    align-items: baseline;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-label {
    font-weight: 600;
    color: #444;
}

.info-value {
    color: #000;
}

.section-title {
    background-color: #f8f9fa;
    padding: 0.8vh 1.5vh;
    font-weight: 700;
    font-size: 1.3vh;
    border-left: 4px solid var(--primary-color);
    margin-bottom: 1vh;
    text-transform: uppercase;
    flex-shrink: 0;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2vh;
    font-size: 1.2vh;
    flex-shrink: 0;
}

.items-table th,
.items-table td {
    border: 1px solid var(--border-color);
    padding: 0.8vh;
    text-align: left;
}

.items-table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 1.1vh;
}

/* Column widths */
.items-table th:nth-child(1) { width: 10%; text-align: center; } /* Sl. No */
.items-table th:nth-child(2) { width: 45%; } /* Description */
.items-table th:nth-child(3) { width: 15%; } /* UOM */
.items-table th:nth-child(4) { width: 10%; text-align: center; } /* QTY */
.items-table th:nth-child(5) { width: 20%; text-align: right; } /* Total */

.items-table td:nth-child(1) { text-align: center; }
.items-table td:nth-child(4) { text-align: center; }
.items-table td:nth-child(5) { text-align: right; }

.signature-section {
    display: flex;
    justify-content: space-between;
    margin-top: auto;
    margin-bottom: 1vh;
    padding: 0 2vh;
    flex-shrink: 0;
}

.signature-box {
    text-align: center;
    width: 30%;
}

.signature-line {
    border-top: 1px solid #000;
    padding-top: 1vh;
    font-size: 1.2vh;
    font-weight: 600;
}

.terms-section {
    margin-top: 1vh;
    border: 1px solid var(--border-color);
    padding: 1.5vh;
    font-size: 1.1vh;
    line-height: 1.4;
    background-color: #fcfcfc;
    flex-grow: 0;
}

.terms-title {
    font-weight: 700;
    font-size: 1.2vh;
    margin-bottom: 1vh;
    text-transform: uppercase;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5vh;
}

.term-item {
    margin-bottom: 0.5vh;
    display: flex;
}

.term-item strong {
    margin-right: 8px;
    min-width: 25px;
}

.comments-box {
    border: 1px solid var(--border-color);
    padding: 1vh;
    border-radius: 4px;
    margin-bottom: 2vh;
    min-height: 4vh;
    font-size: 1.2vh;
    display: flex;
    align-items: center;
}

@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: white;
        padding: 0;
        height: auto;
        width: auto;
        overflow: visible;
        display: block;
        margin: 0;
    }
    
    .a4-container {
        box-shadow: none;
        margin: 0;
        width: 210mm;
        height: 297mm;
        /* Ensure it doesn't overflow or shrink */
        min-height: 297mm;
        max-height: 297mm;
        padding: 15mm;
        overflow: hidden; /* Ensure content stays within page */
        aspect-ratio: auto;
        page-break-after: always;
        position: relative;
    }

    /* Restore fixed sizes for print */
    .document-title { font-size: 20px; margin-bottom: 15px; }
    .company-name { font-size: 18px; margin-bottom: 8px; }
    .company-details { font-size: 11px; }
    .info-grid { gap: 20px; margin-bottom: 20px; font-size: 11px; }
    .info-section { padding: 10px; }
    .info-row { margin-bottom: 5px; }
    .section-title { padding: 8px; font-size: 12px; margin-bottom: 10px; }
    .items-table { margin-bottom: 20px; font-size: 11px; }
    .items-table th, .items-table td { padding: 8px; }
    .items-table th { font-size: 11px; }
    .signature-section { margin-top: 30px; margin-bottom: 30px; }
    .signature-line { font-size: 11px; padding-top: 5px; }
    .terms-section { padding: 15px; font-size: 10px; }
    .terms-title { font-size: 12px; margin-bottom: 10px; }
    
    .section-title {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .items-table th {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}