:root {
    --primary: #2c3e50;
    --primary-dark: #1a252f;
    --secondary: #3498db;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --gold: #f39c12;
    --equatorial: #e67e22;
    --light-bg: #ecf0f1;
    --text-dark: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #bdc3c7;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text-dark);
}

.main-container {
    max-width: 1000px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Upload Section */
.upload-bundle {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.upload-area {
    border: 3px dashed var(--border);
    border-radius: 8px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-area:hover {
    border-color: var(--secondary);
    background: rgba(52, 152, 219, 0.05);
}

.upload-area.dragover {
    border-color: var(--success);
    background: rgba(39, 174, 96, 0.1);
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.upload-subtext {
    font-size: 0.9rem;
    color: var(--text-muted);
}

#fileInput {
    display: none;
}

.file-info {
    margin-top: 1rem;
    padding: 0.8rem;
    background: var(--light-bg);
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.file-info.show {
    display: flex;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 0.95rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    width: 100%;
}

/* Results Section */
.results-section {
    display: none;
}

.results-section.show {
    display: block;
}

.raw-data-container {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.section-title {
    font-size: 1.3rem;
    color: var(--text-dark);
}

/* NOVA FATURA - TAMANHO A4 E ESCALA MENOR - OPTIMIZED FOR PRINT */
.invoice-new {
    display: none;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 80 80'%3E%3Ctext x='50%25' y='50%25' font-family='sans-serif' font-weight='bold' font-size='9' fill='rgba(255,255,255,0.4)' text-anchor='middle' transform='rotate(-45 40 40)'%3EGOLDTECH%3C/text%3E%3C/svg%3E"),
        linear-gradient(to bottom, #B4C4C9 0%, #D0BDAF 100%);
    background-size: 60px 60px, 100% 100%;
    border-radius: 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    margin: 0 auto 2rem;
    width: 210mm;
    /* Ensure strict A4 height */
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
    overflow: hidden;
    /* Prevent spillover */
}

.invoice-new.show {
    display: block;
}

.top-line {
    width: 90%;
    height: 3px;
    background-color: #1e3c72;
    margin: 15px auto 5px;
    /* Restored some margin */
}

.invoice-header-high-fid {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 5px 40px;
    position: relative;
    color: #1e3c72;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.header-center-content {
    text-align: center;
    flex: 1;
}

.company-name {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 1px;
}

.company-cnpj {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 3px;
}

.invoice-title-main {
    font-size: 1.6rem;
    font-weight: 400;
    letter-spacing: 4px;
    margin: 2px 0;
    /* Restored some margin */
    color: #2c3e50;
}

.invoice-month-line {
    font-size: 1.4rem;
    font-weight: 600;
}

.invoice-month-line span {
    font-weight: 400;
}

.contact-info {
    margin-top: 5px;
    font-size: 0.7rem;
    line-height: 1.2;
    font-weight: 600;
}

.logo-container-circle {
    position: absolute;
    right: 40px;
    top: 5px;
    width: 90px;
    height: 90px;
}

.logo-container-circle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 1.5px solid #2c3e50;
    border-radius: 50%;
}

.logo-container-circle img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    background: white;
    border-radius: 50%;
}

.invoice-body-middle {
    padding: 0 40px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 10px;
    /* Restored some margin */
}

.energy-summary {
    width: 50%;
    font-family: 'Segoe UI', sans-serif;
    color: #2c3e50;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.summary-row.stripe {
    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px;
}

.summary-value {
    font-weight: 800;
}

.economy-badge {
    background-color: #347696;
    color: white;
    padding: 8px 12px;
    border-radius: 12px;
    margin-top: 10px;
    margin-bottom: 12px;
    /* Increased slightly */
    margin-left: auto;
    width: fit-content;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 5;
}

.economy-title {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.economy-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 2px;
}

.economy-row .currency {
    font-size: 0.8rem;
}

.economy-row .value {
    font-size: 1.2rem;
    font-weight: 400;
}

/* NOVA TABELA ESQUERDA */
.invoice-demonstration-small {
    margin-top: 20px;
    /* Restored some margin */
    width: 100%;
    position: relative;
}

.demo-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Segoe UI', sans-serif;
}

.demo-table thead th {
    background-color: #d37d3d;
    color: white;
    text-align: left;
    padding: 2px 8px;
    font-size: 0.6rem;
    font-weight: 700;
}

.demo-table tbody td {
    padding: 2px 8px;
    font-size: 0.6rem;
    color: #2c3e50;
    border-bottom: 1px dotted #999;
}

.demo-table tbody tr.highlight td {
    font-weight: 800;
    color: #1e3c72;
    font-size: 0.65rem;
    padding: 2px 8px;
}

/* NOVO BANNER TOTAL ESQUERDO */
.total-banner-small {
    margin-top: 12px;
    /* Restored some margin */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #2c3e50;
    border-bottom: 1px solid #2c3e50;
    padding: 6px 0;
    /* Restored some padding */
}

.total-label {
    font-size: 0.9rem;
    font-weight: 900;
    color: #000;
}

.total-badge {
    background-color: #347696;
    color: white;
    padding: 3px 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
}

/* COLUNA DIREITA */
.comparison-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    gap: 15px;
    width: 45%;
}

.comparison-item {
    font-family: 'Segoe UI', sans-serif;
}

.comp-text {
    font-size: 1.0rem;
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 2px;
}

.comp-value {
    font-size: 1.4rem;
    font-weight: 800;
}

.comparison-item.red .comp-value {
    color: #e74c3c;
}

.comparison-item.green .comp-value {
    color: #27ae60;
}

.comp-subtext {
    font-size: 0.9rem;
    font-weight: 500;
    color: #2c3e50;
    margin-top: -3px;
}

/* PAGAMENTO GOLDTECH */
.goldtech-pay-summary {
    margin-top: 80px;
    /* Increased from 60px */
    width: 85%;
    margin-left: auto;
    font-family: 'Segoe UI', sans-serif;
    color: #000;
}

.goldtech-details {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    font-size: 0.65rem;
    font-weight: 500;
    color: #666;
    margin-bottom: 2px;
    padding-right: 5px;
}

.goldtech-main-line {
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.goldtech-label {
    font-size: 1.0rem;
    font-weight: 900;
    letter-spacing: -0.5px;
}

.goldtech-value {
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: -0.5px;
}

/* PAGAMENTO EQUATORIAL */
.equatorial-pay-summary {
    margin-top: 40px;
    /* Increased from 30px */
    width: 85%;
    margin-left: auto;
    font-family: 'Segoe UI', sans-serif;
    color: #000;
}

.equatorial-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 5px;
    padding-right: 5px;
}

.eq-row {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    font-size: 0.65rem;
    font-weight: 500;
    color: #666;
}

.equatorial-main-line {
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.equatorial-label {
    font-size: 1.0rem;
    font-weight: 900;
    letter-spacing: -0.5px;
}

.equatorial-value {
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: -0.5px;
}

/* INFORMAÇÕES DO CONSUMIDOR - VERSÃO MINI (ESQUERDA) */
.consumer-info-box {
    margin-top: 15px;
    /* Restored some margin */
    width: 100%;
    text-align: left;
    font-family: 'Segoe UI', sans-serif;
    color: #444;
}

.info-line-main {
    font-size: 0.85rem;
    font-weight: 800;
    margin-bottom: 5px;
    /* Restored some margin */
    display: flex;
    justify-content: flex-start;
    gap: 5px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 5px;
    /* Restored some padding */
}

.info-group {
    margin-bottom: 2px;
    /* Restored some margin */
    font-size: 0.7rem;
    line-height: 1.2;
}

.info-group .label {
    font-weight: 700;
    color: #000;
}

.info-group .value {
    font-weight: 500;
}

.payer-info {
    margin-top: 8px;
    /* Restored some margin */
    margin-bottom: 8px;
    /* Restored some margin */
}

.payer-info .label {
    font-weight: 800;
    color: #000;
    font-size: 0.75rem;
}

.payer-info .value {
    font-size: 0.75rem;
    font-weight: 600;
    display: block;
}

.service-line {
    margin-top: 5px;
    /* Restored some margin */
    font-style: italic;
    opacity: 0.8;
}

/* Estilos para Impressão */
@media print {
    @page {
        margin: 0;
        size: auto;
        /* auto is the initial value */
    }

    body {
        margin: 0;
        padding: 0;
        background: white;
    }

    .main-container {
        max-width: none;
        margin: 0;
    }

    #loading,
    .upload-bundle,
    .raw-data-container,
    header,
    .btn,
    #newExtractionBtn {
        display: none !important;
    }

    .invoice-new {
        box-shadow: none;
        margin: 0;
        width: 210mm;
        height: 297mm;
        /* Ensure strict A4 height */
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
        overflow: hidden;
        /* Prevent spillover */
    }
}

/* PAGAMENTO VIA PIX - VERSÃO REFINADA */
.pix-qr-mini-box {
    margin-top: 5px;
    /* Restored some margin */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    /* Restored some gap */
    width: 100%;
}

.pix-mini-label {
    font-size: 0.7rem;
    font-weight: 800;
    color: #1a3a5a;
    letter-spacing: 1px;
    opacity: 0.8;
}

.pix-qr-img-wrapper {
    width: 170px;
    height: 170px;
    background: white;
    padding: 10px;
    /* Restored padding */
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    filter: blur(2.5px) grayscale(100%);
    opacity: 0.6;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.pix-qr-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* RODAPÉ DA FATURA */
.invoice-footer {
    width: 100%;
    margin-top: 35px;
    padding: 0 40px 15px;
    /* Increased padding */
    font-family: 'Segoe UI', sans-serif;
}

.footer-top-line {
    width: 100%;
    height: 3px;
    background-color: #347696;
    margin-bottom: 5px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 2px;
}

.footer-text {
    text-align: left;
    color: #333;
    flex: 1;
}

.footer-text .thanks {
    font-size: 0.85rem;
    /* Increased size */
    font-weight: 500;
    margin-bottom: 2px;
}

.footer-text .next-bill {
    font-size: 0.95rem;
    /* Increased size */
    font-weight: 400;
}

.footer-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 20px;
}

.footer-logo img {
    width: 32px;
    /* Increased */
    height: 32px;
    /* Increased */
    object-fit: contain;
}

.footer-logo-text {
    font-size: 0.7rem;
    /* Increased */
    font-weight: 900;
    line-height: 1;
    color: #347696;
    text-transform: uppercase;
}

.footer-logo-text small {
    font-size: 0.5rem;
    font-weight: 400;
    color: #666;
}

/* CÓDIGO DE BARRAS FULL WIDTH */
.barcode-container {
    margin: 15px auto 15px;
    width: 90%;
    border-top: 1px solid #000;
    padding-top: 10px;
    /* Restored padding */
    text-align: center;
    font-family: 'Segoe UI', sans-serif;
    color: #000;
}

.barcode-label {
    font-size: 0.8rem;
    /* Increased */
    font-weight: 800;
    margin-bottom: 5px;
    /* Restored margin */
    letter-spacing: 2px;
}

.barcode-img-wrapper {
    width: 100%;
    height: 80px;
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    filter: blur(3px) grayscale(100%);
    opacity: 0.6;
}

.barcode-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.barcode-numbers {
    font-family: monospace;
    font-size: 0.95rem;
    /* Increased */
    font-weight: 700;
    margin-top: 5px;
    /* Restored margin */
    letter-spacing: 2px;
}