.invoice-tool-header {
    text-align: center;
    margin-bottom: 30px;
    margin-top: 20px;
}

.invoice-tool-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 30px;
    margin-bottom: 80px;
}

/* ================= Editor Section ================= */
.invoice-editor {
    background: var(--nav-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.editor-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.editor-section label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--primary-color);
}

input,
select {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    border-color: var(--primary-color);
}

.input-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    color: var(--text-color);
}

.extras-row {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.ml-15 {
    margin-left: 15px;
}

/* Item Row inside Editor */
.item-row-edit {
    display: grid;
    grid-template-columns: 2fr 80px 100px 40px;
    gap: 10px;
    margin-bottom: 10px;
}

.full-width {
    width: 100%;
    margin-top: 10px;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    padding: 16px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1.05rem;
    transition: 0.3s;
}

.primary-btn:hover {
    opacity: 0.9;
}

.secondary-btn {
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-color);
}

/* ================= Live Preview Area ================= */
.invoice-preview-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Wrapper Fix for Mobile Horizontal Scroll / Zoom */
.invoice-paper-wrapper {
    width: 100%;
    max-width: 210mm;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    justify-content: center;
    padding: 10px;
    background: var(--nav-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

/* Strict A4 Paper Format */
.a4-preview {
    width: 210mm;
    height: 297mm;
    flex-shrink: 0;
    background: white;
    padding: 20mm;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    color: #000;
    font-family: Arial, sans-serif;
    /* Modern font for invoices */
    box-sizing: border-box;
    overflow: hidden;
    transform-origin: top center;
}

/* Inside Preview (A4 Paper elements) */
.a4-preview * {
    color: #000;
    /* Ensure text is strictly black for print */
}

.preview-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
}

.preview-logo-box img {
    max-width: 150px;
    max-height: 80px;
    object-fit: contain;
}

.preview-biz-info h1 {
    margin: 0;
    font-size: 24pt;
    text-transform: uppercase;
}

.preview-biz-info p {
    margin: 5px 0;
    font-size: 10pt;
    color: #444;
}

.preview-client-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
}

.p-bill-to label {
    font-size: 9pt;
    font-weight: bold;
    text-transform: uppercase;
    color: #555;
}

.p-bill-to h3 {
    margin: 5px 0;
    font-size: 14pt;
}

.p-inv-meta p {
    margin: 5px 0;
    font-size: 10pt;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.preview-table th {
    background: #f0f0f0;
    text-align: left;
    padding: 10px;
    border-bottom: 2px solid #ccc;
    font-size: 10pt;
    text-transform: uppercase;
}

.preview-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    font-size: 10.5pt;
}

.preview-totals {
    align-self: flex-end;
    width: 250px;
    margin-left: auto;
    /* Pushes total to the right */
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 11pt;
}

.grand-total {
    border-top: 2px solid #000;
    font-weight: bold;
    font-size: 14pt;
    margin-top: 10px;
}

/* ================= Mobile Responsiveness (Same logic as CV) ================= */
@media (max-width: 850px) {
    .invoice-paper-wrapper {
        justify-content: flex-start;
    }

    .a4-preview {
        zoom: 0.7;
    }
}

@media (max-width: 500px) {
    .a4-preview {
        zoom: 0.45;
    }
}

/* ================= Bulletproof 1-Page PDF Print (Exactly like CV) ================= */
@media print {
    @page {
        size: A4;
        margin: 0mm !important;
    }

    html,
    body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
    }

    body * {
        visibility: hidden !important;
    }

    .a4-preview,
    .a4-preview * {
        visibility: visible !important;
    }

    .a4-preview {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 20mm !important;
        box-shadow: none !important;
        border: none !important;
        transform: scale(1) !important;
        zoom: 1 !important;
        overflow: hidden !important;
    }
}

/* ================= Mobile Fix for Invoice Item Rows ================= */
@media (max-width: 768px) {
    .item-row-edit {
        grid-template-columns: 1fr 1fr 40px;
        background: rgba(13, 110, 253, 0.05);
        padding: 15px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        margin-bottom: 15px;

        width: 100%;
        box-sizing: border-box;
    }

    .item-row-edit input,
    .item-row-edit button {
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .item-row-edit input:nth-child(1) {
        grid-column: 1 / -1;
        margin-bottom: 5px;
    }
}