/* ============================================
   PÁGINA: VENTAS (sales.js / POS)
   Recibo térmico, items de venta, lotes,
   calculadora de cambio y resumen.
   ============================================ */

/* ============================================
   RECIBO TÉRMICO
   ============================================ */

/* Modal de recibo */
.receipt-modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Vista previa del ticket en pantalla */
.thermal-preview {
    background: #fff;
    border: 1px dashed #ccc;
    padding: 20px;
    max-width: 320px;  /* Ancho típico de impresora 80mm */
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* El ticket en sí */
.thermal-receipt {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.4;
    color: #000;
    width: 100%;
    text-align: center;
}

.receipt-header {
    margin-bottom: 8px;
}

.store-name {
    font-size: 16px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.store-info {
    font-size: 11px;
}

.receipt-divider {
    font-size: 10px;
    letter-spacing: -1px;
    margin: 4px 0;
    color: #333;
}

.receipt-divider-light {
    font-size: 10px;
    letter-spacing: -1px;
    margin: 4px 0;
    color: #666;
}

.receipt-title {
    font-size: 14px;
    font-weight: bold;
    margin: 4px 0;
}

.receipt-section {
    text-align: left;
    margin: 6px 0;
}

.receipt-row {
    display: flex;
    justify-content: space-between;
    margin: 2px 0;
}

.receipt-label {
    text-align: left;
}

.receipt-value {
    text-align: right;
    font-weight: 500;
}

.receipt-products {
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
    line-height: 1.6;
    text-align: left;
    margin: 0;
    white-space: pre;
    overflow-x: auto;
}

.receipt-totals {
    text-align: left;
}

.receipt-totals .total {
    font-size: 14px;
    font-weight: bold;
    margin-top: 4px;
}

.receipt-payment {
    text-align: left;
}

.receipt-footer {
    margin-top: 8px;
}

.thank-you {
    font-size: 13px;
    font-weight: bold;
    margin: 8px 0;
}

.receipt-barcode {
    font-family: 'Libre Barcode 39', 'Courier New', monospace;
    font-size: 24px;
    margin-top: 8px;
    letter-spacing: 2px;
}

/* Lista de productos en el recibo */
.receipt-products-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.receipt-products-header {
    display: grid;
    grid-template-columns: 35px 1fr 60px 60px;
    gap: 4px;
    font-weight: bold;
    font-size: 10px;
    text-align: left;
    border-bottom: 1px dashed #999;
    padding-bottom: 2px;
    margin-bottom: 4px;
}

.receipt-product-row {
    display: grid;
    grid-template-columns: 35px 1fr 60px 60px;
    gap: 4px;
    font-size: 11px;
    text-align: left;
    align-items: center;
}

.rp-qty {
    text-align: center;
}

.rp-name {
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rp-price, .rp-total {
    text-align: right;
    font-family: 'Courier New', monospace;
}

.rph-qty { text-align: center; }
.rph-name { text-align: left; }
.rph-price, .rph-total { text-align: right; }

/* ============================================
   ESTILOS DE IMPRESIÓN (recibo)
   ============================================ */

@media print {
    /* Ocultar TODO excepto el recibo */
    body * {
        visibility: hidden !important;
    }

    .thermal-receipt,
    .thermal-receipt * {
        visibility: visible !important;
    }

    .thermal-receipt {
        position: absolute;
        left: 0;
        top: 0;
        width: 80mm;  /* Ancho estándar de impresora térmica */
        padding: 0;
        margin: 0;
    }

    /* Ocultar botones y UI del modal */
    .receipt-actions,
    .modal-header,
    .modal-close,
    .modal-overlay {
        display: none !important;
    }

    /* Asegurar fondo blanco */
    .thermal-preview {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        max-width: 80mm !important;
    }

    /* Ajuste de columnas del listado en impresión */
    .receipt-product-row,
    .receipt-products-header {
        grid-template-columns: 30px 1fr 50px 50px !important;
        font-size: 10px !important;
    }

    /* Forzar tamaño de papel */
    @page {
        size: 80mm auto;  /* Ancho fijo, alto automático */
        margin: 0;
    }
}

/* ============================================
   SALE ITEMS (POS)
   ============================================ */

.sale-items-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sale-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.sale-item-info {
    flex: 1;
}

.sale-item-name {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
}

.sale-item-price {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.sale-item-qty {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sale-item-qty button {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--gray-300);
    background: white;
    color: var(--gray-600);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sale-item-qty button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.sale-item-qty input {
    width: 3rem;
    text-align: center;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.25rem;
    font-size: 0.875rem;
}

.sale-item-total {
    font-weight: 700;
    color: var(--primary);
    min-width: 80px;
    text-align: right;
}

.sale-item-remove {
    color: var(--danger);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    transition: transform var(--transition-fast);
}

.sale-item-remove:hover {
    transform: scale(1.1);
}

.sale-summary {
    background: var(--gray-800);
    color: white;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-top: 1.5rem;
}

.sale-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.sale-summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

/* ============================================
   SELECCIÓN DE LOTE EN VENTAS
   ============================================ */

.sale-item-batch {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.35rem;
}

.sale-item-batch-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
}

.sale-item-batch-clear,
.sale-item-batch-link {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--gray-500);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0;
    transition: color var(--transition-fast);
}

.sale-item-batch-clear:hover { color: var(--danger); }
.sale-item-batch-link:hover { color: var(--primary); }

.batch-picker-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.batch-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.batch-picker-number {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
}

.batch-picker-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-500);
}

/* ============================================
   CALCULADORA DE CAMBIO
   ============================================ */

.btn-icon-toggle {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    transition: color var(--transition-fast);
}

.btn-icon-toggle:hover { color: var(--primary); }

.change-calculator {
    padding-top: 1rem;
    border-top: 1px dashed var(--gray-200);
}

.change-calculator-result {
    margin-top: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    text-align: right;
    min-height: 1.4rem;
}

.change-calculator-result.ok { color: var(--secondary); }
.change-calculator-result.insufficient { color: var(--danger); }

/* ============================================
   RESUMEN DE VENTA (card clara)
   Nota: se usa .sale-summary-card como ancla porque
   ".sale-summary-row" a secas ya se usa en el resumen
   oscuro de venta más arriba; sin este ancla, esta
   definición (por venir después) le pisaba el
   font-size y el margin-bottom a ese otro componente.
   ============================================ */

.sale-summary-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.sale-summary-card .sale-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.summary-label {
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 500;
}

.summary-value {
    color: #1e293b;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'Courier New', Courier, monospace;
}

.sale-summary-divider {
    height: 1px;
    background-color: #cbd5e1;
    margin: 0.85rem 0;
    border-style: dashed;
}

/* Fila destacada del TOTAL */
.sale-summary-card .sale-summary-row.total-row {
    margin-bottom: 0;
    align-items: flex-end;
}

.total-label-group {
    display: flex;
    flex-direction: column;
}

.total-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #475569;
    letter-spacing: 0.5px;
}

.total-subtitle {
    font-size: 0.72rem;
    color: #94a3b8;
}

.total-amount {
    font-size: 1.6rem;
    font-weight: 800;
    color: #0f172a;
    font-family: 'Courier New', Courier, monospace;
    line-height: 1;
}

/* ============================================
   ESTILOS EXTRAÍDOS DE sales.js (antes inline)
   ============================================ */

.sales-page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.customer-display-btn {
    margin-right: 0.5rem;
}

.btn-icon-spacing {
    margin-right: 0.4rem;
}

.pos-layout {
    gap: 1.5rem;
}

.customer-selected-icon {
    font-size: 1.5rem;
}

.sale-summary-sticky {
    top: 80px;
}

/* Recibo: detalles que antes iban con style="" en el HTML del ticket */
.receipt-cai-value {
    font-size: 10px;
    word-break: break-all;
}

.store-info-left {
    text-align: left;
}

.receipt-legal-note {
    font-size: 10px;
}

/* ============================================
   PREVIEW DEL MODAL DE RECIBO
   Antes era un <style> inyectado por JS dentro de
   showReceipt(). Se mueve aquí porque ese modal es
   parte de la página y ya carga este archivo.

   NOTA: el <style> del popup de impresión (ventana
   nueva vía window.open/document.write) se queda
   en sales.js a propósito — es un documento HTML
   aparte que no tiene acceso a este stylesheet.
   ============================================ */

.thermal-preview-container {
    background-color: #f4f4f4;
    padding: 20px;
    display: flex;
    justify-content: center;
    border-radius: 8px;
}

.thermal-preview-container .thermal-receipt {
    width: 300px;
    background: #fff;
    padding: 15px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.3;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    color: #000;
    border-radius: 4px;
}

.thermal-preview-container .receipt-header,
.thermal-preview-container .receipt-footer,
.thermal-preview-container .text-center {
    text-align: center;
}

.thermal-preview-container .store-name {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 5px;
}

.thermal-preview-container .receipt-row {
    display: flex;
    justify-content: space-between;
    margin: 3px 0;
}

.thermal-preview-container .receipt-products-header {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
}

.thermal-preview-container .receipt-product-row {
    display: grid;
    grid-template-columns: 35px 1fr 85px;
    gap: 4px;
    margin: 4px 0;
    width: 100%;
}

.thermal-preview-container .rp-total {
    text-align: right;
}

.thermal-preview-container .receipt-divider,
.thermal-preview-container .receipt-divider-light {
    margin: 5px 0;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
}

.thermal-preview-container .total {
    font-size: 14px;
    border-top: 1px dashed #000;
    padding-top: 5px;
}