:root {
    --primary: #1a56db;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --secondary: #0f172a;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0891b2;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
}

/* Flash Messages */
.flash {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 24px;
    border-radius: var(--radius);
    color: white;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}
.flash-success { background: var(--success); }
.flash-danger { background: var(--danger); }
.flash-warning { background: var(--warning); }
.flash button { background: none; border: none; color: white; cursor: pointer; margin-left: 20px; font-size: 16px; }

.flash-message {
    display: inline;
}

.flash-message a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
    margin-left: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
}

.flash-message a:hover {
    background: rgba(255,255,255,0.2);
    text-decoration: none;
}

.flash-message a.btn {
    margin-left: 10px;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.flash-message .btn-whatsapp { background: #25D366; color: white; }
.flash-message .btn-pdf { background: #dc2626; color: white; }
.flash-message .btn-whatsapp:hover { background: #128C7E; }
.flash-message .btn-pdf:hover { background: #b91c1c; }


/* Botones de WhatsApp y PDF en tablas */
.btn-whatsapp {
    background: #25D366 !important;
    color: white !important;
    border: none;
}
.btn-whatsapp:hover {
    background: #128C7E !important;
}

.btn-pdf {
    background: #dc2626 !important;
    color: white !important;
    border: none;
}
.btn-pdf:hover {
    background: #b91c1c !important;
}


/* Select2 personalizado */
.select2-container--default .select2-selection--single {
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    padding: 10px;
    height: 45px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 24px;
    color: var(--gray-700);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 43px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--primary);
}

/* DataTables personalizado */
.dataTables_wrapper {
    padding: 16px;
}

.dataTables_wrapper .dataTables_length select {
    border-radius: 6px;
    padding: 4px 8px;
}

.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 6px 12px;
    margin-left: 8px;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0,0,0,.02);
}
/* Select2 - Búsqueda inteligente */
.select2-container {
    width: 100% !important;
    z-index: 9999;
}

.select2-container--default .select2-selection--single {
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    height: 45px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 28px;
    color: var(--gray-700);
    padding-left: 0;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 43px;
    right: 12px;
}

.select2-dropdown {
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 10000;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--primary);
    color: white;
}

.select2-search__field {
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 8px;
    font-size: 14px;
}

/* Selector de préstamos mejorado */
#selectPrestamo {
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    padding: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

#selectPrestamo:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

#buscadorPrestamo {
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    transition: all 0.3s;
}

#buscadorPrestamo:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

/* Opciones del select */
#selectPrestamo option {
    padding: 8px;
    cursor: pointer;
}

#selectPrestamo option:hover {
    background-color: var(--primary);
    color: white;
}

#selectPrestamo option[selected] {
    background-color: var(--primary);
    color: white;
}


/* Selector de documentos mejorado */
#selectCliente {
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    padding: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
    min-height: 200px;
}

#selectCliente:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

#buscadorCliente {
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    transition: all 0.3s;
}

#buscadorCliente:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

#selectCliente option {
    padding: 8px;
    cursor: pointer;
}

#selectCliente option[selected] {
    background-color: var(--primary);
    color: white;
}


/* Combobox de clientes */
#dropdownClientes {
    animation: slideDown 0.2s ease-out;
}

/* Combobox de clientes - Documentos */
#dropdownClientes {
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cliente-item:hover {
    background-color: var(--primary) !important;
}

.cliente-item:hover div:first-child {
    color: white;
}

.cliente-item:hover div:last-child {
    color: rgba(255,255,255,0.9);
}

/* Scroll personalizado */
#dropdownClientes::-webkit-scrollbar {
    width: 8px;
}

#dropdownClientes::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#dropdownClientes::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

#dropdownClientes::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Logo en login */
.login-card img {
    transition: transform 0.3s ease;
}

.login-card img:hover {
    transform: scale(1.02);
}

/* Logo en sidebar */
.sidebar-logo {
    background: var(--gray-50);
    border-radius: 0 0 12px 12px;
}

.sidebar-logo img {
    transition: opacity 0.3s ease;
}

.sidebar-logo img:hover {
    opacity: 0.9;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .sidebar-logo img {
        max-width: 120px;
    }
    
    .login-card img {
        max-width: 140px;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cliente-item:hover {
    background-color: var(--primary);
    color: white;
}

.cliente-item:hover div:first-child {
    color: white;
}

.cliente-item:hover div:last-child {
    color: rgba(255,255,255,0.9);
}

.cliente-item.selected {
    background-color: var(--primary);
}

/* Scroll personalizado */
#dropdownClientes::-webkit-scrollbar {
    width: 8px;
}

#dropdownClientes::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#dropdownClientes::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

#dropdownClientes::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Layout */
.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--secondary) 0%, var(--gray-800) 100%);
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 100;
}
.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand h1 {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-brand i { color: var(--primary-light); }
.sidebar-nav { padding: 16px 12px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: var(--primary); color: white; }
.nav-item i { width: 20px; text-align: center; }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}
.top-bar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.top-bar h2 { font-size: 18px; color: var(--gray-700); margin-left: 12px; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-600); }
.user-info { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; }
.badge-role {
    background: var(--primary-light);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.btn-logout { color: var(--danger); text-decoration: none; font-size: 18px; }

.content-area { padding: 24px; }

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}
.card-header h3 { font-size: 18px; font-weight: 600; color: var(--gray-800); }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}
.stat-icon.blue { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.stat-icon.green { background: linear-gradient(135deg, #10b981, #059669); }
.stat-icon.orange { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.red { background: linear-gradient(135deg, #ef4444, #dc2626); }
.stat-info h4 { font-size: 13px; color: var(--gray-500); font-weight: 500; }
.stat-info .value { font-size: 28px; font-weight: 700; color: var(--gray-900); }

/* Tables */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    font-size: 14px;
}
th { font-weight: 600; color: var(--gray-600); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
tr:hover { background: var(--gray-50); }

/* Badges */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-200); color: var(--gray-700); }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    text-decoration: none;
}
.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: #047857; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-whatsapp { background: #25D366; color: white; }
.btn-whatsapp:hover { background: #128C7E; }
.btn-pdf { background: #dc2626; color: white; }
.btn-pdf:hover { background: #b91c1c; }

/* Alerts */
.alert-card {
    background: white;
    border-left: 4px solid var(--warning);
    padding: 16px 20px;
    border-radius: 8px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.alert-card.urgent { border-left-color: var(--danger); }
.alert-card .alert-info h4 { font-size: 15px; margin-bottom: 4px; }
.alert-card .alert-info p { font-size: 13px; color: var(--gray-500); }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.global-footer {
    text-align: center;
    padding: 20px;
    background: var(--gray-800);
    color: var(--gray-300);
    font-size: 13px;
    margin-left: var(--sidebar-width);
}
@media (max-width: 768px) {
    .global-footer { margin-left: 0; }
}

.modal-close {
    background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-500);
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary-dark) 100%);
}
.login-card {
    background: white;
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--gray-900);
    font-size: 24px;
}
.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 32px;
    font-size: 14px;
}
.login-card .form-group { margin-bottom: 20px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
}