/* ==========================================
   AMB NOVEDADES - POS PRO v4.9.2 (ACTUALIZADO)
   DISEÑO LIMPIO + LÓGICA FRACCIONADA + IMPRESIÓN
   ========================================== */

:root {
    /* NUEVA PALETA DE COLORES (MODERNA Y PROFESIONAL) */
    --primary: #4f46e5;       /* Indigo */
    --primary-dark: #4338ca;  /* Indigo Oscuro */
    --primary-light: #e0e7ff; /* Indigo Muy Claro */
    --secondary: #64748b;     /* Slate Gris */
    --success: #10b981;       /* Esmeralda */
    --warning: #f59e0b;       /* Ambar/Naranja (Para fraccionadas) */
    --danger: #ef4444;
    
    /* FONDOS Y TEXTOS */
    --bg-app: #f8fafc;        /* Gris Muy Claro (Slate 50) */
    --text-main: #1e293b;
    
    /* VARIABLES DE INTERFAZ */
    --border: #e2e8f0;           
    --glass-bg: rgba(255,255,255,0.98); 
    --glass-border: rgba(255,255,255,0.5);
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- LOGIN --- */
.center-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* Fondo azul sólido como en la imagen */
    background: #2563eb; 
}

.login-box {
    background: white;
    padding: 30px;
    border-radius: 12px; /* Bordes ligeramente redondeados */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px; /* Controla el ancho horizontal */
    height: auto;     /* Permite que la altura se ajuste al contenido, no a la pantalla */
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;        /* Espaciado uniforme entre elementos */
}

.login-box h2 { color: var(--primary); margin-bottom: 20px; }
.login-box input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 16px;
}
.login-box button {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}
.login-box button:hover { background: var(--primary-dark); }

/* --- HEADER (LIMPIO Y SOMBRA) --- */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: white; /* Fondo Blanco Limpio */
    padding: 0 24px;
    display: grid; 
    grid-template-columns: 300px 1fr 250px; 
    align-items: center;
    border-bottom: 1px solid var(--border);
    height: 70px;
    z-index: 50;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05); /* Sombra sutil */
}

.brand-text { 
    font-size: 1.3rem; 
    font-weight: 800; 
    color: var(--primary); 
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Navegación */
.nav-group { 
    display: flex; 
    justify-content: center; 
    gap: 10px;
}

.nav-btn {
    background: transparent;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    color: var(--secondary);
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 14px;
}

.nav-btn:hover { background: var(--bg-app); color: var(--primary); }
.nav-btn.active { 
    background: var(--primary); 
    color: white; 
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}

/* Usuario y Salida */
.user-section {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
}

#sede-actual-badge {
    font-family: monospace;
    font-size: 12px;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--bg-app);
    border: 1px solid var(--border);
    color: var(--secondary);
}

.btn-exit {
    background: #fee2e2;
    color: #ef4444;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    padding: 6px 12px;
    font-weight: bold;
    transition: 0.2s;
}
.btn-exit:hover { background: #fecaca; }

/* --- CONTENEDOR PRINCIPAL --- */
.container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--bg-app);
}

/* Grids */
.grid-2 { 
    display: grid; 
    grid-template-columns: 350px 1fr; /* Búsqueda fija, carrito flexible */
    gap: 20px; 
    height: 100%; 
}

.grid-4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 15px; }

/* Componentes Generales */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-title {
    margin: 0 0 15px 0;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.input {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 10px;
    transition: 0.2s;
}

.input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: white; color: var(--text-main); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- NUEVO: BOTÓN DE ABONO (CALL TO ACTION) --- */
.btn-abonar {
    background: linear-gradient(135deg, #fbbf24 0%, var(--warning) 100%);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.3);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.btn-abonar:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px -1px rgba(245, 158, 11, 0.4);
    filter: brightness(1.1);
}

.btn-abonar:active {
    transform: translateY(0);
}

/* --- MODAL (MEJORADO) --- */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); /* Fondo más oscuro para contraste */
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 450px;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease;
}

/* --- TABLAS Y LISTAS --- */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 15px;
}

.table { width: 100%; border-collapse: collapse; min-width: 600px; }
.table th { background: #f8fafc; color: var(--secondary); font-weight: 600; text-align: left; padding: 12px; border-bottom: 2px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid #f1f5f9; }

/* --- NUEVO: ESTILOS VISUALES PARA ESTADOS DE VENTA --- */

/* Fila de venta fraccionada (con deuda) */
.tr-fraccionada {
    background-color: #fffbeb; /* Amarillo muy suave */
    border-left: 4px solid var(--warning); /* Borde izquierdo naranja */
}

/* Fila completamente pagada (Exito) */
.tr-completada {
    background-color: #f0fdf4; /* Verde muy suave */
    border-left: 4px solid var(--success);
}

/* Fila de cotización */
.tr-cotizacion {
    background-color: #eff6ff; /* Azul muy suave */
    border-left: 4px solid var(--primary);
    opacity: 0.9;
}

/* --- NUEVO: TEXTO DE SALDOS --- */
.text-saldo {
    font-size: 0.75rem; /* Texto pequeño */
    color: var(--secondary);
    margin-top: 4px;
    display: block;
}

.text-saldo span {
    font-weight: 600;
}

/* Cuando el saldo es positivo (deuda) */
.saldo-deudor {
    color: var(--danger);
}

/* Cuando el saldo es 0 */
.saldo-pagado {
    color: var(--success);
}

.cart-items-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    margin-bottom: 15px;
    background: #fff;
    min-height: 200px;
}

.cart-totals {
    background: #f8fafc;
    padding: 15px;
    border-radius: 12px;
}

.total-display {
    text-align: right;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
}

.tab-content { display: none; animation: fadeIn 0.2s; }
.tab-content:not(.hidden) { display: block; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }
.admin-only { display: none; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* --- BOTONES MINI (PARA EL JS) --- */
.btn-mini {
    padding: 4px 8px;
    font-size: 10px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    color: white;
    font-weight: bold;
    text-transform: uppercase;
}
.btn-edit-mini { background-color: var(--warning); }
.btn-stock-mini { background-color: var(--secondary); }

/* ==========================================
   IMPRESIÓN (NUEVO: HISTORIAL DE PAGOS)
   ========================================== */
@media print {
    /* Oculta elementos de interfaz */
    body * { visibility: hidden; }
    #print-area, #print-area * { visibility: visible; }
    #print-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white;
        color: black;
        padding: 20px;
    }

    /* Asegura que el historial no rompa el diseño */
    .print-history-section {
        border-top: 1px dashed #000;
        margin-top: 10px;
        padding-top: 5px;
        font-size: 10px;
    }
    
    .print-history-title {
        text-align: center;
        font-weight: bold;
        margin-bottom: 5px;
        text-transform: uppercase;
    }

    .print-payment-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 2px;
        font-size: 9px;
    }

    .print-balance-total {
        border-top: 1px dotted #000;
        padding-top: 3px;
        margin-top: 5px;
        font-weight: bold;
        display: flex;
        justify-content: space-between;
    }
}

/* ==========================================
   RESPONSIVIDAD (REVERTIDO A GRID + MEJORAS)
   ========================================== */
@media (max-width: 768px) {
    body { font-size: 13px; }
    
    /* HEADER COMPACTO */
    .topbar {
        grid-template-columns: 1fr;
        height: auto;
        padding: 10px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }

    .brand-text { justify-content: center; width: 100%; }

    .nav-group {
        width: 100%;
        overflow-x: auto;
        justify-content: space-between; /* Distribuye los botones */
        padding-bottom: 5px;
    }

    .nav-btn {
        flex: 1;
        padding: 10px;
        font-size: 12px;
        background: #f1f5f9;
        color: var(--secondary);
        justify-content: center;
    }

    .nav-btn.active {
        background: var(--primary);
        color: white;
    }

    /* LAYOUT REVERTIDO: Mantiene Grid pero permite scroll horizontal */
    .grid-2 {
        display: grid;
        grid-template-columns: 300px 1fr; /* Búsqueda fija ancho mínimo */
        gap: 10px;
        height: auto;
        min-height: 80vh;
        overflow-x: hidden; /* Evita scroll en el body, permite scroll en paneles */
    }

    /* Ajuste específico para móviles pequeños */
    .pos-search-panel {
        min-width: 280px;
        order: 1; /* Búsqueda arriba si se apila, pero en grid es izquierda */
    }

    .pos-cart-panel {
        min-width: 300px;
    }

    .cart-items-container {
        max-height: 200px;
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
    }
}