:root { --primary: #003366; --accent: #e74c3c; --yellow-pm: #ffcc00; --black-pm: #000000; --bg-dark: #333; }
body { font-family: 'Segoe UI', sans-serif; background-color: var(--bg-dark); margin: 0; padding-top: 60px; }

/* --- INTERFAZ PANTALLA (WEB) --- */
.cotizador-layout { display: flex; gap: 30px; padding: 20px; justify-content: center; max-width: 1400px; margin: 0 auto; }
.admin-panel-sidebar { width: 340px; background: white; padding: 20px; border-radius: 8px; position: sticky; top: 80px; max-height: 90vh; overflow-y: auto; z-index: 50; }
.top-bar { position: fixed; top: 0; left: 0; width: 100%; height: 50px; background: #222; color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; z-index: 1000; }
.top-bar a { color: #ddd; text-decoration: none; font-weight: bold; }

/* --- HOJA VISTA PREVIA (WEB) --- */
.page { 
    background: white; 
    width: 210mm; 
    min-height: 297mm; 
    margin-bottom: 50px; 
    box-shadow: 0 0 25px rgba(0,0,0,0.3); 
    position: relative; 
    display: block; 
    padding-bottom: 50px; 
    box-sizing: border-box;
    overflow: hidden; 
}

/* HEADER Y FOOTER EN PANTALLA */
.print-header-fixed { position: absolute; top: 0; left: 0; width: 100%; height: 100px; background: white; z-index: 10; }
.print-footer-fixed { 
    position: absolute; bottom: 0; left: 0; 
    width: 100%; height: 40px; background: black; 
    display: flex; align-items: center; z-index: 10; 
}

/* Estilos Gráficos */
.strip-black { height: 15px; background: var(--black-pm); width: 100%; }
.strip-yellow { height: 4px; background: var(--yellow-pm); width: 100%; }
.logo-container { padding: 10px 15mm 0 15mm; } .logo-img { max-height: 80px; }

/* FOOTER */
.footer-black-bar { 
    width: 100%; height: 100%; display: flex; justify-content: space-between; align-items: center; 
    padding: 0 10mm; box-sizing: border-box; color: white; font-size: 8pt; font-weight: bold; 
    border-bottom: 4px solid var(--yellow-pm); white-space: nowrap; overflow: hidden;
}
.contact-icon { background: var(--yellow-pm); color: black; border-radius: 50%; width: 16px; height: 16px; display: flex; justify-content: center; align-items: center; font-size: 9px; margin-right: 5px; flex-shrink: 0; }

/* TABLAS E INPUTS */
table.flow-table { width: 100%; border-collapse: collapse; }
/* Padding solo para pantalla */
.content-cell { padding-top: 110px; padding-left: 15mm; padding-right: 15mm; }

table.report-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
table.report-table th { background: var(--primary); color: white; padding: 6px; font-size: 9pt; border: 1px solid var(--primary); }
table.report-table td { border: 1px solid #ccc; padding: 6px; vertical-align: top; font-size: 9pt; }

.table-input { width: 100%; border: none; background: transparent; outline: none; font-size: 9pt; }
.desc-textarea { width: 100%; border: none; resize: none; overflow: hidden; font-family: inherit; font-size: 9pt; background: transparent; display: block; white-space: pre-wrap; }
.print-desc-div { display: none; font-size: 9pt; white-space: pre-wrap; }

/* UTILS */
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
.editable { background-color: #fffde7 !important; border: 1px dashed #f39c12 !important; border-radius: 3px; padding: 2px; }
.hidden { display: none !important; }
.full-input, .styled-input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-bottom: 5px; }
.btn { width: 100%; padding: 10px; border: none; cursor: pointer; border-radius: 4px; color: white; font-weight: bold; margin-bottom: 5px; }
.btn-green { background: #27ae60; } .btn-red { background: #c0392b; } .btn-blue { background: #2980b9; } .btn-dark { background: #34495e; }
.modal { display: none; position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); align-items: center; justify-content: center; }
.modal-content { background: white; padding: 20px; border-radius: 8px; width: 600px; }
.preview-img { max-height: 120px; width: auto; max-width: 100%; object-fit: contain; display: block; margin: 0 auto 10px auto; border: 1px solid #ddd; }
.col-item { width: 5%; text-align: center; font-weight: bold; } .col-img { width: 12%; text-align: center; } .prod-thumb { width: 60px; height: 60px; object-fit: contain; } .col-desc { width: 43%; } .col-cant, .col-unit, .col-total { text-align: right; width: 10%; } .col-action { width: 5%; }
.totals-area { text-align: right; margin-bottom: 5px; font-size: 10pt; } .total-line { display: flex; justify-content: flex-end; gap: 20px; margin-bottom: 4px; } .total-final { font-weight: bold; color: var(--primary); font-size: 11pt; border-top: 2px solid #ccc; padding-top: 5px; } .text-red { color: red; font-weight: bold; }

/* --- BLOQUE DE IMPRESIÓN (SOLUCIÓN HOJA BLANCA + LÍNEAS) --- */


/* --- BLOQUE DE IMPRESIÓN (CORREGIDO) --- */
/* --- BLOQUE DE IMPRESIÓN (SOLUCIÓN DEFINITIVA) --- */
@media print {
    @page {
        margin: 0;
        size: A4;
    }

    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        height: auto !important; /* Importante: auto, no 100% */
        width: 100%;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Ocultar elementos de interfaz */
    .top-bar, .admin-panel-sidebar, .col-action, .modal, .btn, .admin-layout {
        display: none !important;
    }
    
    /* Resetear el layout principal para que no sea Flex */
    .cotizador-layout {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* --- CONFIGURACIÓN DE LA HOJA (PAGE) --- */
    .page {
        width: 100%;
        margin: 0 !important;
        border: none;
        box-shadow: none;
        padding: 0 !important;
        position: relative !important;
        display: block !important;
        overflow: visible !important;
    }

    /* --- HEADER Y FOOTER FIJOS (ELEMENTOS VISUALES) --- */
    .print-header-fixed {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100px; /* Altura del encabezado */
        background: white;
        z-index: 1000;
    }

    .print-footer-fixed {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 40px; /* Altura del pie */
        background: black !important;
        z-index: 1000;
        display: flex !important;
        align-items: center;
    }
    
    .footer-black-bar {
        width: 100%;
        background: black !important;
        color: white !important;
        border-bottom: 4px solid #ffcc00 !important;
    }
    
    .footer-black-bar span, .footer-black-bar i {
        color: white !important;
    }

    /* --- TABLA MAESTRA (FLOW TABLE) --- */
    /* Esta tabla controla que el header/footer se repitan si hay muchas hojas */
    table.flow-table {
        width: 100%;
        border-collapse: collapse;
        table-layout: fixed; /* Ayuda a la estabilidad */
    }

    /* ESPACIADORES: Empujan el contenido para que no quede debajo del header/footer fijo */
    .header-spacer-box { height: 110px; display: block; } /* Un poco más que el fixed header */
    .footer-spacer-box { height: 50px; display: block; }  /* Un poco más que el fixed footer */

    table.flow-table thead { display: table-header-group; }
    table.flow-table tfoot { display: table-footer-group; }
    
    /* REGLA CRÍTICA 1: Permitir que la tabla maestra se rompa entre páginas */
    table.flow-table tr {
        page-break-inside: auto !important;
        break-inside: auto !important;
    }
    
    /* La celda principal donde va todo el contenido */
    .content-cell {
        padding: 0 15mm !important; /* Solo padding lateral */
        display: table-cell !important;
        vertical-align: top;
    }

    /* --- TABLA DE PRODUCTOS (INTERNA) --- */
    table.report-table {
        width: 100%;
        border-collapse: collapse;
    }
    
    table.report-table td {
        border-bottom: 1px solid #ccc;
    }

    /* REGLA CRÍTICA 2: Evitar que UN PRODUCTO se parta a la mitad */
    /* Solo aplicamos esto a las filas de productos, no a la tabla maestra */
    table.report-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Línea negra al final de grupo */
    tr.last-in-group td {
        border-bottom: 2px solid #000 !important;
    }

    /* --- ELEMENTOS FINALES --- */
    /* Evitar que los totales se corten o se separen de las firmas */
    .final-block-wrapper, .client-table, .conditions-box {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Textareas se ocultan, se muestran los divs de impresión */
    .desc-textarea { display: none !important; }
    .print-desc-div { display: block !important; white-space: pre-wrap; }
    .hidden { display: none !important; }
}