:root {
    --color-primario: #4A90E2;
    --color-primario-oscuro: #357ABD;
    --color-fondo: #F8F9FA;
    --color-superficie: #FFFFFF;
    --color-borde: #DEE2E6;
    --color-texto-principal: #212529;
    --color-texto-secundario: #6C757D;
    --color-exito: #28a745;
    --color-peligro: #dc3545;
    --color-alerta: #ffc107;
    --sombra-suave: 0 4px 6px rgba(0, 0, 0, 0.05);
    --radio-borde: 8px;
    --fuente-principal: 'Inter', 'Segoe UI', system-ui, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--fuente-principal); background-color: var(--color-fondo); color: var(--color-texto-principal); line-height: 1.6; }
.container { max-width: 1400px; margin: 0 auto; padding: 25px; }
header { margin-bottom: 2rem; }
header h1 { font-size: 2.2rem; color: var(--color-texto-principal); margin-bottom: 0.25rem; }
.subtitle { color: var(--color-texto-secundario); font-size: 1.1rem; margin-bottom: 1.5rem; }
nav { display: flex; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--color-borde); padding-bottom: 10px; }
.nav-btn { background: transparent; border: none; color: var(--color-texto-secundario); padding: 10px 20px; border-radius: var(--radio-borde); cursor: pointer; transition: background-color 0.2s ease, color 0.2s ease; font-weight: 600; border-bottom: 3px solid transparent; }
.nav-btn:hover { background-color: #e9ecef; color: var(--color-texto-principal); }
.nav-btn.active { color: var(--color-primario); border-bottom-color: var(--color-primario); }
.tab-content { display: none; padding-top: 2rem; }
.tab-content.active { display: block; animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 25px; margin-bottom: 2rem; }
.stat-card { background: var(--color-superficie); padding: 1.5rem; border-radius: var(--radio-borde); border: 1px solid var(--color-borde); box-shadow: var(--sombra-suave); display: flex; align-items: center; gap: 1rem; }
.stat-card .icon-container { font-size: 1.8rem; padding: 15px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.stat-card.info .icon-container { color: var(--color-primario); background-color: #e9f2fe; }
.stat-card.warning .icon-container { color: var(--color-peligro); background-color: #fbe9e9; }
.stat-card.success .icon-container { color: var(--color-exito); background-color: #eaf6ec; }
.stat-card .stat-info { min-width: 0; }
.stat-card .stat-info h3 { color: var(--color-texto-secundario); font-size: 0.9rem; margin-bottom: 0.25rem; text-transform: uppercase; }
.stat-card .stat-info p { font-size: 1.9rem; font-weight: 700; overflow-wrap: break-word; }
.dashboard-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 25px; }
.chart-container, .card { background: var(--color-superficie); padding: 2rem; border-radius: var(--radio-borde); border: 1px solid var(--color-borde); box-shadow: var(--sombra-suave); }
.chart-container h3, .card h3 { margin-bottom: 1.5rem; color: var(--color-texto-principal); font-size: 1.3rem; }
.btn { padding: 10px 20px; border: 1px solid transparent; border-radius: var(--radio-borde); cursor: pointer; font-size: 0.95rem; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.btn-primary { background-color: var(--color-primario); color: white; }
.btn-primary:hover { background-color: var(--color-primario-oscuro); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.btn-secondary { background-color: var(--color-texto-secundario); color: white; }
.btn-secondary:hover { background-color: #5a6268; }
.btn-danger { background-color: var(--color-peligro); color: white; }
.btn-danger:hover { background-color: #c82333; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 15px; }
.filters { display: flex; gap: 15px; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
.search-box { position: relative; flex: 1; min-width: 250px; }
.search-box i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #adb5bd; }
.search-box input { padding-left: 45px; }
input, select, textarea { width: 100%; padding: 10px 15px; border: 1px solid var(--color-borde); border-radius: var(--radio-borde); font-size: 0.95rem; background: var(--color-superficie); transition: border-color 0.2s ease, box-shadow 0.2s ease; font-family: var(--fuente-principal); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primario); box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.25); }
.table-container { background: var(--color-superficie); border-radius: var(--radio-borde); box-shadow: var(--sombra-suave); border: 1px solid var(--color-borde); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px; text-align: left; border-bottom: 1px solid var(--color-borde); vertical-align: middle; }
th { background-color: #F8F9FA; font-weight: 600; color: var(--color-texto-secundario); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.5px; }
tbody tr:hover { background-color: #f1f3f5; }
.actions { display: flex; gap: 10px; }
.estado-bajo, .stock-bajo { color: var(--color-peligro); font-weight: bold; }
.estado-normal, .stock-normal { color: var(--color-exito); }
.categoria-badge { background: #e9f2fe; color: #357ABD; padding: 4px 8px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.badge { background: #e9ecef; color: #495057; padding: 4px 8px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.alert-list { max-height: 400px; overflow-y: auto; }
.stock-alert { background: #fff3cd; padding: 15px; margin-bottom: 10px; border-radius: var(--radio-borde); border-left: 4px solid var(--color-alerta); }
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.5); animation: fadeIn 0.3s; }
.modal-content { background-color: var(--color-superficie); margin: 10% auto; padding: 2rem; border: 1px solid var(--color-borde); width: 90%; max-width: 600px; border-radius: var(--radio-borde); box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); position: relative; }
.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--color-borde); padding-bottom: 1rem; margin-bottom: 1.5rem; }
.modal-header h3 { margin: 0; font-size: 1.5rem; color: var(--color-texto-principal); }
.close-btn { color: #aaa; font-size: 28px; font-weight: bold; cursor: pointer; border: none; background: transparent; }
.close-btn:hover, .close-btn:focus { color: var(--color-texto-principal); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { margin-bottom: 0.5rem; font-weight: 600; color: var(--color-texto-secundario); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding-top: 1.5rem; margin-top: 1.5rem; border-top: 1px solid var(--color-borde); }
.notification { position: fixed; top: 20px; right: 20px; background: white; padding: 1rem 1.5rem; border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,0.15); transform: translateX(120%); transition: transform 0.3s ease; z-index: 10000; border-left: 5px solid var(--color-exito); max-width: 400px; }
.notification.error { border-left-color: var(--color-peligro); }
.notification.show { transform: translateX(0); }
.notification-content { display: flex; align-items: center; gap: 10px; }
.notification-content i { font-size: 1.2rem; }
.notification.success i { color: var(--color-exito); }
.notification.error i { color: var(--color-peligro); }

/* ============================================
   ESTILOS PARA FACTURAS PRE-PAGO
   ============================================ */

/* Contenedor de productos agregados */
.productos-agregados-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid #e9ecef;
}

.productos-agregados-container h4 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.1rem;
    border-bottom: 2px solid #4A90E2;
    padding-bottom: 8px;
}

/* Lista de productos */
.productos-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: white;
}

.producto-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: white;
    border-bottom: 1px solid #f1f3f4;
    transition: background-color 0.2s;
}

.producto-item:hover {
    background-color: #f8f9fa;
}

.producto-item:last-child {
    border-bottom: none;
}

.producto-info {
    flex: 1;
    min-width: 0;
}

.producto-info strong {
    display: block;
    color: #2c3e50;
    font-size: 0.95rem;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.producto-info small {
    display: block;
    color: #6c757d;
    font-size: 0.85em;
}

.producto-totals {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

.producto-totals span {
    font-weight: 600;
    color: #2c3e50;
    min-width: 80px;
    text-align: right;
}

.producto-totals .btn-sm {
    padding: 4px 8px;
    font-size: 0.8rem;
}

/* Contenedor de totales */
.totals-container {
    background: linear-gradient(135deg, #6C757D 0%, #6C757D 100%);
    color: #FFFFFF;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.totals-container h4 {
    color: #FFFFFF;
    margin-bottom: 15px;
    font-size: 1.2rem;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 10px;
}

.totals-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.total-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.total-item:last-child {
    border-bottom: none;
}

.total-item.total-final {
    font-size: 1.3rem;
    font-weight: bold;
    grid-column: span 2;
    background: rgba(255,255,255,0.1);
    padding: 12px 15px;
    border-radius: 6px;
    margin-top: 5px;
}

/* Estados de facturas */
.estado-success {
    background-color: #d4edda;
    color: #155724;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.estado-warning {
    background-color: #fff3cd;
    color: #856404;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.estado-error {
    background-color: #f8d7da;
    color: #721c24;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

/* Mejoras para el formulario */
.sales-form-customer .form-group.full-width.totals-container {
    margin-top: 30px;
}

/* Responsive */
@media (max-width: 768px) {
    .producto-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .producto-totals {
        width: 100%;
        justify-content: space-between;
    }
    
    .totals-grid {
        grid-template-columns: 1fr;
    }
    
    .total-item.total-final {
        grid-column: span 1;
    }
    
    .productos-agregados-container .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar personalizada para la lista de productos */
.productos-list::-webkit-scrollbar {
    width: 6px;
}

.productos-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.productos-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.productos-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Animación para productos agregados */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.producto-item {
    animation: fadeIn 0.3s ease-out;
}

/* Estilos para inputs específicos de factura pre-pago */
#prepago-costo-envio {
    background-color: #f8f9fa;
    border: 2px solid #dee2e6;
}

#prepago-costo-envio:focus {
    border-color: #4A90E2;
    background-color: white;
}

/* Botón de agregar producto */
#prepago-producto + .btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    border: none;
    transition: all 0.3s ease;
}

#prepago-producto + .btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

/* ============================================
   ESTILOS PARA ESTADO CUOTAS
   ============================================ */

.estado-row {
    transition: background-color 0.2s ease;
}

.estado-row.moroso {
    background-color: #fff3cd;
}

.estado-row.moroso:hover {
    background-color: #ffe8a3;
}

.progress-indicator {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.progress-indicator span {
    font-size: 0.85rem;
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background-color: #e9ecef;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--color-exito);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.estado-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.estado-normal {
    background-color: #d1ecf1;
    color: #0c5460;
}

.estado-exito {
    background-color: #d4edda;
    color: #155724;
}

.estado-peligro {
    background-color: #f8d7da;
    color: #721c24;
}

.text-danger {
    color: var(--color-peligro) !important;
    font-weight: bold;
}

.text-right {
    text-align: right !important;
}

.text-center {
    text-align: center !important;
}

/* Tabla de detalle de cuotas */
.detalle-cuotas-table {
    width: 100%;
    border-collapse: collapse;
}

.detalle-cuotas-table th,
.detalle-cuotas-table td {
    padding: 10px;
    border-bottom: 1px solid var(--color-borde);
}

.detalle-cuotas-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.85rem;
}

.cliente-info {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-left: 4px solid var(--color-primario);
}

/* Responsive para estado cuotas */
@media (max-width: 1024px) {
    .estado-cuotas-filters {
        flex-direction: column;
    }
    
    .estado-cuotas-filters > * {
        width: 100%;
    }
}

/* Animaciones */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.estado-row {
    animation: fadeInUp 0.3s ease-out;
}

/* ============================================
   ESTILOS PARA TABLA DE PRODUCTOS - BOTONES FIJOS
   ============================================ */

/* Asegurar que todas las celdas tengan alineación vertical media */
#productos-body td,
#productos-body th {
    vertical-align: middle !important;
}

/* Estilo para la celda de nombre/archivos que contiene descripción larga */
#productos-body td:first-child {
    vertical-align: middle !important;
    max-width: 300px;
}

/* Contenedor del nombre del producto con descripción */
.producto-nombre-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.producto-nombre-container strong {
    font-size: 1rem;
    margin-bottom: 2px;
}

.producto-descripcion {
    font-size: 0.8rem;
    color: #6c757d;
    line-height: 1.3;
    word-break: break-word;
    white-space: normal;
    margin-top: 4px;
}

/* Enlaces de archivos (imagen y PDF) */
.file-links {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.file-links a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    text-decoration: none;
    color: #6c757d;
    transition: color 0.2s;
}

.file-links a:hover {
    color: var(--color-primario);
}

.file-links i {
    font-size: 14px;
}

/* Celda de acciones - fija y centrada */
#productos-body td:last-child {
    vertical-align: middle !important;
    white-space: nowrap;
    min-width: 100px;
}

/* Botones de acción dentro de la celda */
#productos-body td:last-child .actions {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
}

/* Asegurar que los botones no se deformen */
#productos-body .btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    min-width: 32px;
    height: 32px;
}

/* Para la fila de stock bajo */
#productos-body tr.stock-bajo-row {
    background-color: #fff3cd;
}

#productos-body tr.stock-bajo-row:hover {
    background-color: #ffe8a3;
}

/* Estilo para texto de stock bajo */
.stock-bajo {
    color: var(--color-peligro);
    font-weight: bold;
}

.stock-normal {
    color: var(--color-exito);
}

/* Mejorar visualización de la tabla en móviles */
@media (max-width: 768px) {
    #productos-body td:first-child {
        max-width: 200px;
    }
    
    #productos-body td:last-child .actions {
        flex-direction: column;
        gap: 5px;
    }
    
    #productos-body .btn-sm {
        width: 100%;
    }
}