/**
 * SISTEMA DE CRÉDITOS Y COBRANZAS - ESTILOS UI/UX SENIOR
 * Paleta moderna Fintech / SaaS con soporte responsivo total
 */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --font-primary: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    --color-primary: #4F46E5;
    --color-primary-hover: #4338CA;
    --color-primary-light: #EEF2FF;
    --color-primary-border: #C7D2FE;
    
    --color-success: #10B981;
    --color-success-light: #ECFDF5;
    --color-success-border: #A7F3D0;
    
    --color-warning: #F59E0B;
    --color-warning-light: #FFFBEB;
    --color-warning-border: #FDE68A;
    
    --color-danger: #EF4444;
    --color-danger-light: #FEF2F2;
    --color-danger-border: #FECACA;
    
    --color-info: #06B6D4;
    --color-info-light: #ECFEFF;
    
    --bg-body: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-sidebar: #0F172A;
    --bg-sidebar-hover: #1E293B;
    --bg-sidebar-active: #4F46E5;
    
    --text-main: #1E293B;
    --text-muted: #64748B;
    --text-light: #94A3B8;
    --text-white: #FFFFFF;
    
    --border-color: #E2E8F0;
    --border-focus: #818CF8;
    
    --shadow-subtle: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 6px 16px -4px rgba(0, 0, 0, 0.04);
    --shadow-elevated: 0 10px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    --sidebar-width: 260px;
    --topbar-height: 70px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #F1F5F9;
}
::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* ==========================================================
   LAYOUT PRINCIPAL: SIDEBAR + TOPBAR + CONTENT
   ========================================================== */
.app-wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #94A3B8;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.sidebar-brand-text {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    color: #FFFFFF;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 0.7rem;
    color: #818CF8;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.sidebar-menu {
    padding: 1.25rem 0.875rem;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-heading {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 0.75rem 0.75rem 0.35rem 0.75rem;
}

.nav-item-link {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: #94A3B8;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.nav-item-link i {
    font-size: 1.15rem;
    color: #64748B;
    transition: color 0.2s ease;
}

.nav-item-link:hover {
    color: #FFFFFF;
    background: var(--bg-sidebar-hover);
}

.nav-item-link:hover i {
    color: #818CF8;
}

.nav-item-link.active {
    background: var(--bg-sidebar-active);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.nav-item-link.active i {
    color: #FFFFFF;
}

.nav-item-badge {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-full);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #3B82F6 0%, #1D4ED8 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.72rem;
    color: #818CF8;
    text-transform: capitalize;
}

/* Main Content Area */
.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Topbar */
.app-topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 900;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle-btn {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.25rem;
}

.page-main-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-quick-credit {
    background: linear-gradient(135deg, var(--color-primary) 0%, #6366F1 100%);
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.55rem 1.15rem;
    font-weight: 700;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-quick-credit:hover {
    color: #FFFFFF;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

/* Page Content Body */
.app-content {
    padding: 2rem;
    flex: 1;
}

/* ==========================================================
   COMPONENTES UI & TARJETAS MODERNAS
   ========================================================== */
.card-modern {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    transition: all 0.25s ease;
    overflow: hidden;
}

.card-modern:hover {
    box-shadow: var(--shadow-elevated);
}

.card-header-modern {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #FFFFFF;
}

.card-title-modern {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body-modern {
    padding: 1.5rem;
}

/* KPI Card Moderno */
.kpi-card {
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-elevated);
    border-color: #CBD5E1;
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.kpi-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 0.35rem;
}

.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Variaciones de Color para KPIs */
.kpi-primary .kpi-icon { background: var(--color-primary-light); color: var(--color-primary); }
.kpi-success .kpi-icon { background: var(--color-success-light); color: var(--color-success); }
.kpi-warning .kpi-icon { background: var(--color-warning-light); color: var(--color-warning); }
.kpi-danger .kpi-icon  { background: var(--color-danger-light); color: var(--color-danger); }
.kpi-info .kpi-icon    { background: var(--color-info-light); color: var(--color-info); }

/* Banner de Alertas en Dashboard */
.alert-banner-mora {
    background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%);
    border: 1px solid #FECACA;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.08);
}

.alert-banner-title {
    font-weight: 800;
    color: #991B1B;
    font-size: 1rem;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-banner-desc {
    color: #B91C1C;
    font-size: 0.875rem;
    margin: 0;
}

/* Tablas Modernas */
.table-modern-wrapper {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #FFFFFF;
}

.table-modern {
    width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
}

.table-modern th {
    background: #F8FAFC;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table-modern td {
    padding: 0.9rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #F1F5F9;
    font-size: 0.875rem;
    color: var(--text-main);
}

.table-modern tbody tr:last-child td {
    border-bottom: none;
}

.table-modern tbody tr {
    transition: background 0.15s ease;
}

.table-modern tbody tr:hover {
    background: #F8FAFC;
}

/* Badges Modernos */
.badge-pill-modern {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-pagado {
    background: #DEF7EC;
    color: #03543F;
    border: 1px solid #BCF0DA;
}

.badge-pendiente {
    background: #FEF08A;
    color: #713F12;
    border: 1px solid #FDE047;
}

.badge-vence-hoy {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FCD34D;
    animation: pulseGlow 2s infinite;
}

.badge-vencido {
    background: #FDE8E8;
    color: #9B1C1C;
    border: 1px solid #F8B4B4;
}

.badge-parcial {
    background: #FFEDD5;
    color: #9A3412;
    border: 1px solid #FED7AA;
}

.badge-activo {
    background: #E0E7FF;
    color: #3730A3;
    border: 1px solid #C7D2FE;
}

.badge-completado {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}

@keyframes pulseGlow {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

/* Botones de Acción */
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: #FFFFFF;
    color: var(--text-muted);
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-action:hover {
    color: var(--color-primary);
    border-color: var(--color-primary-border);
    background: var(--color-primary-light);
}

.btn-action-wa {
    background: #25D366;
    color: #FFFFFF !important;
    border: none;
}
.btn-action-wa:hover {
    background: #1EBE5D !important;
    color: #FFFFFF !important;
    transform: scale(1.05);
}

.btn-action-pay {
    background: var(--color-primary);
    color: #FFFFFF !important;
    border: none;
}
.btn-action-pay:hover {
    background: var(--color-primary-hover) !important;
    color: #FFFFFF !important;
}

/* Formularios Elegantes */
.form-label-modern {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.4rem;
}

.form-control-modern, .form-select-modern {
    display: block;
    width: 100%;
    padding: 0.65rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-main);
    background-color: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.form-control-modern:focus, .form-select-modern:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
    outline: 0;
}

/* Modales Modernos */
.modal-content-modern {
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-hover);
    overflow: hidden;
}

.modal-header-modern {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border-color);
    background: #FFFFFF;
}

.modal-body-modern {
    padding: 1.75rem;
    background: #FFFFFF;
}

.modal-footer-modern {
    padding: 1rem 1.75rem;
    border-top: 1px solid var(--border-color);
    background: #F8FAFC;
}

/* Pantalla de Login */
.login-page-bg {
    min-height: 100vh;
    background: radial-gradient(circle at top left, #1E1B4B 0%, #0F172A 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    background: #FFFFFF;
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 440px;
    padding: 2.5rem;
}

/* Impresión y Documentos PDF */
@media print {
    .app-sidebar, .app-topbar, .btn, .no-print {
        display: none !important;
    }
    .app-main {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .app-content {
        padding: 0 !important;
    }
    body {
        background: #FFFFFF !important;
        color: #000000 !important;
    }
}

/* Responsive Breakpoints */
@media (max-width: 992px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
    .sidebar-toggle-btn {
        display: block;
    }
    .app-content {
        padding: 1.25rem;
    }
    .app-topbar {
        padding: 0 1.25rem;
    }
}
