* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Montserrat', 'Segoe UI', Arial, sans-serif;

}

body {
    background-color: #f0f0f0;
    padding: 10px 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* --- BOTÓN DE IMPRESIÓN --- */
.print-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #2b2b2b;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: background 0.2s;
    z-index: 9999;
}

.print-btn:hover {
    background-color: #444444;
}

.invoice-container {
    width: 210mm;
    /* Tamaño A4 estándar */
    height: 297mm;
    /* Fijado el tamaño exacto de una hoja para evitar desbordes */
    padding: 12mm 20mm;
    margin: 0 auto;
    position: relative;
    background: #ffffff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

/* --- ENCABEZADO --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.company-info h1 {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.company-details {
    font-size: 11.5px;
    line-height: 1.4;
}

.company-details strong {
    font-weight: 700;
}

/* Bloque contenedor derecho para el logo y sus metadatos pegados */
.logo-section-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.logo-box {
    width: 140px;
    height: 140px;
    background-color: #2b2b2b;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
    /* Espacio mínimo directo abajo */
}

/* Símbolo del logo simulado */
.logo-icon {
    width: 50px;
    height: 50px;
    position: relative;
    margin-bottom: 5px;
}

.logo-icon::before,
.logo-icon::after {
    content: '';
    position: absolute;
    border-top: 6px solid #ffffff;
    border-right: 6px solid #ffffff;
    border-radius: 3px;
}

.logo-icon::before {
    width: 30px;
    height: 30px;
    top: 5px;
    left: 5px;
    transform: rotate(-135deg);
}

.logo-icon::after {
    width: 15px;
    height: 15px;
    top: 22px;
    left: 22px;
    transform: rotate(-135deg);
}

.logo-box span {
    font-size: 24px;
    font-weight: bold;
    color: #ffffff;
    letter-spacing: 1px;
}

/* Metadata pegada justo abajo del logo */
.invoice-meta-inline {
    font-size: 13.5px;
    line-height: 1.5;
}

.invoice-meta-inline div {
    margin-bottom: 4px;
}

.invoice-meta-inline strong {
    font-weight: 800;
}

/* --- SECCIÓN CLIENTE --- */
.meta-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 25px;
}

.client-box {
    border: 2px solid #000000;
    border-radius: 35px;
    padding: 12px 30px;
    width: 60%;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.client-box div {
    font-size: 14px;
    line-height: 1.4;
}

.client-box .label {
    font-weight: 800;
    font-size: 14px;
}

/* --- TABLA DE ARTÍCULOS CORREGIDA --- */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
}

.items-table th {
    border-top: 2px solid #000000;
    border-bottom: 2px solid #000000;
    padding: 10px 5px;
    font-size: 14px;
    font-weight: 800;
}

/* Control de anchos precisos de columnas por CSS */
.items-table th:nth-child(1) {
    width: 8%;
    text-align: center;
}

/* Cantidad corta */
.items-table th:nth-child(2) {
    width: 44%;
    text-align: left;
}

/* Descripción amplia */
.items-table th:nth-child(3) {
    width: 16%;
    text-align: right;
}

/* Valor Unitario */
.items-table th:nth-child(4) {
    width: 16%;
    text-align: right;
}

/* Rebajas y Descuentos */
.items-table th:nth-child(5) {
    width: 16%;
    text-align: right;
}

/* Total pegado a la derecha */

.items-table td {
    padding: 10px 5px;
    font-size: 13.5px;
    vertical-align: middle;
}

.items-table td:nth-child(1) {
    text-align: center;
}

.items-table td:nth-child(2) {
    text-align: left;
}

.items-table td:nth-child(3) {
    text-align: right;
}

.items-table td:nth-child(4) {
    text-align: right;
}

.items-table td:nth-child(5) {
    text-align: right;
}

/* Total alineado al borde derecho */

/* --- SECCIÓN DE TOTALES --- */
.totals-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-bottom: 35px;
}

.total-letras {
    margin-top: 14px;
    width: 45%;
    align-self: flex-end;
    font-size: 12.5px;
    line-height: 1.5;
    font-weight: 600;
    text-align: left;
    color: #111;
    border-top: 1px dashed #999;
    padding-top: 10px;
    word-break: break-word;
}

.totals-table {
    width: 45%;
    border-collapse: collapse;
}

.totals-table td {
    padding: 2px 0;
    font-size: 13px;
}

.totals-table td:first-child {
    text-align: left;
    font-weight: 600;
}

.totals-table td:last-child {
    text-align: right;
    width: 35%;
}

.totals-table .subtotal-row td {
    border-top: 1px solid #a0a0a0;
    padding-top: 6px;
    font-size: 14px;
}

.totals-table .total-row td {
    border-top: 3px solid #000000;
    border-bottom: 3px solid #000000;
    padding: 6px 0;
    font-size: 16px;
    font-weight: 800;
}

/* --- PIE DE PÁGINA --- */
.footer {
    margin-top: auto;
    /* Empuja el pie de página al fondo de la hoja */
    padding-bottom: 5px;
}

.thanks-msg {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 12px;
}

.footer-details {
    display: flex;
    justify-content: flex-end;
    text-align: right;
    font-size: 9.5px;
    line-height: 1.4;
    color: #333333;
    margin-bottom: 15px;
}

.footer-details h2 {
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.legal-disclaimer {
    border-top: 1px solid #000000;
    padding-top: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* --- CONTROL DE IMPRESIÓN --- */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: none;
        padding: 0;
    }

    .print-btn {
        display: none;
    }

    .invoice-container {
        margin: 0;
        box-shadow: none;
        width: 210mm;
        height: 297mm;
    }
}