:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-editor: #f8fafc;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-editor);
    color: var(--text-main);
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Editor Panel */
.editor-panel {
    width: 400px;
    background: white;
    border-right: 1px solid var(--border-color);
    padding: 2rem;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.editor-header {
    margin-bottom: 2rem;
}

.editor-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
}

.actions {
    display: flex;
    gap: 0.75rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.form-section h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin: 1.5rem 0 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: #475569;
}

.form-group input, 
.form-group textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-group input:focus, 
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    padding: 3rem;
    background: #e2e8f0;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.invoice-container {
    width: 210mm;
    min-height: 297mm;
    background: white;
    padding: 10mm;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    box-sizing: border-box;
    position: relative;
    border: 1px solid #ddd;
}

/* Report Container for Repeating Headers */
.report-container {
    width: 100%;
    border-collapse: collapse;
}

.report-header-cell {
    padding: 0;
    text-align: left;
    font-weight: normal;
}

.report-content-cell {
    padding: 0;
    vertical-align: top;
}

/* Invoice Branding Header */
.invoice-header {
    border: 1px solid #000;
    margin-bottom: 0;
    background: white;
}

.header-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    padding: 5px 10px;
    border-bottom: 1px solid #000;
    font-size: 11px;
}

.header-top .title {
    font-weight: bold;
    text-decoration: underline;
    font-size: 14px;
}

.header-top .contact {
    text-align: right;
}

.company-branding {
    text-align: center;
    padding: 10px;
}

.company-logo {
    height: 80px;
    margin-bottom: 10px;
}

.company-name {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: 2px;
}

.company-address, .company-email {
    font-size: 12px;
    margin-top: 2px;
}

/* Middle Section (Only Page 1) */
.invoice-middle {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    border: 1px solid #000;
    border-top: none;
}

.customer-info {
    display: flex;
    border-right: 1px solid #000;
}

.ms-label {
    padding: 5px;
    border-right: 1px solid #000;
    font-weight: bold;
    min-width: 40px;
}

.ms-details {
    padding: 5px 10px;
    font-size: 13px;
}

.ms-details strong {
    font-size: 16px;
    display: block;
    margin-bottom: 5px;
}

.ms-details p {
    margin: 2px 0;
}

.invoice-info {
    padding: 5px 10px;
    font-size: 13px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

/* Items Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0;
    border-top: none;
}

.items-table th, .items-table td {
    border: 1px solid #000;
    padding: 5px;
    font-size: 12px;
    text-align: center;
}

.items-table thead tr th {
    border-top: none; /* Connect to middle section */
}

.items-table th {
    background: #f8fafc;
    font-weight: bold;
}

.items-table td {
    height: 25px;
}

/* Calculations */
.calculation-section {
    display: flex;
    border: 1px solid #000;
    border-top: none;
    page-break-inside: avoid;
}

.amt-words {
    flex: 1;
    padding: 10px;
    font-size: 12px;
    border-right: 1px solid #000;
}

.totals {
    width: 250px;
}

.total-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid #000;
    font-size: 12px;
}

.total-row:last-child {
    border-bottom: none;
}

.total-row span {
    padding: 5px 10px;
}

.total-row span:first-child {
    border-right: 1px solid #000;
    font-weight: bold;
}

.total-row span:last-child {
    text-align: right;
}

.grand-total {
    background: #f1f5f9;
    font-weight: bold;
}

/* Footer Section */
.footer-wrapper {
    page-break-inside: avoid;
}

.footer-section {
    display: flex;
    border: 1px solid #000;
    border-top: none;
}

.footer-left {
    flex: 1;
    padding: 10px;
    border-right: 1px solid #000;
}

.bank-details {
    font-size: 11px;
    margin-bottom: 15px;
}

.bank-details h4 {
    text-decoration: underline;
    margin-bottom: 5px;
}

.remarks-box {
    font-size: 12px;
    margin-bottom: 15px;
}

.remarks-box p {
    white-space: pre-wrap;
}

.terms {
    font-size: 10px;
}

.terms ul {
    list-style: none;
}

.footer-right {
    width: 250px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
}

.signature-area {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 12px;
}

.sign-space {
    height: 60px;
}

/* Editor Specifics */
.row-editor {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.row-editor-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.remove-row-btn {
    color: #ef4444;
    cursor: pointer;
    font-size: 0.75rem;
}

/* PRINT MEDIA OVERRIDES */
@media print {
    @page {
        size: A4;
        margin: 10mm;
    }

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

    body {
        background: none;
        margin: 0;
        padding: 0;
    }

    .preview-panel {
        padding: 0;
        margin: 0;
        background: none;
        display: block;
    }

    .invoice-container {
        width: 100%;
        min-height: auto;
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .report-header {
        display: table-header-group; /* This enables repetition */
    }

    .report-content {
        display: table-row-group;
    }

    .items-table thead {
        display: table-header-group; /* Secondary repetition */
    }

    /* Keep calculations and footer from breaking split */
    .calculation-section, .footer-wrapper {
        page-break-inside: avoid;
    }
}
