/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --blue-900: #1a365d; --blue-800: #1e3a5f; --blue-700: #2c5282;
    --blue-600: #2b6cb0; --blue-100: #ebf8ff; --blue-50: #f0f7ff;
    --teal-600: #0d9488; --teal-500: #14b8a6; --teal-100: #ccfbf1;
    --green-600: #059669; --green-100: #d1fae5;
    --red-600: #dc2626; --red-100: #fee2e2;
    --amber-600: #d97706; --amber-100: #fef3c7;
    --yellow-600: #ca8a04; --yellow-100: #fef9c3;
    --gray-900: #111827; --gray-700: #374151; --gray-500: #6b7280;
    --gray-400: #9ca3af; --gray-300: #d1d5db; --gray-200: #e5e7eb;
    --gray-100: #f3f4f6; --gray-50: #f9fafb;
    --sidebar-w: 240px; --topbar-h: 56px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --radius: 8px; --radius-sm: 6px;
}
html { font-size: 14px; }
body { font-family: 'Inter', system-ui, sans-serif; color: var(--gray-900); background: var(--gray-50); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: none; border-radius: var(--radius-sm); font-weight: 500; font-size: .875rem; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--blue-900); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }
.btn-secondary { background: var(--teal-600); color: #fff; }
.btn-secondary:hover { background: var(--teal-500); }
.btn-outline { background: transparent; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; color: var(--gray-700); margin-bottom: 4px; font-size: .85rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
    font-size: .9rem; font-family: inherit; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--teal-600); box-shadow: 0 0 0 3px rgba(13,148,136,.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* === LOGIN === */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-700) 100%); }
.login-card { background: #fff; border-radius: 12px; padding: 40px; width: 400px; max-width: 90vw; box-shadow: var(--shadow-md); text-align: center; }
.login-logo { margin-bottom: 16px; }
.login-card h1 { font-size: 1.4rem; color: var(--blue-900); margin-bottom: 4px; }
.login-subtitle { color: var(--gray-500); font-size: .85rem; margin-bottom: 28px; }
.login-card .form-group { text-align: left; }
.login-card .btn { margin-top: 8px; padding: 10px; font-size: .95rem; }
.login-footer { margin-top: 24px; font-size: .7rem; color: var(--gray-400); }

/* === APP SHELL === */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--blue-900); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; transition: transform .2s; }
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-text { font-weight: 700; font-size: 1rem; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: rgba(255,255,255,.7); font-size: .85rem; transition: all .15s; border-left: 3px solid transparent; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.1); border-left-color: var(--teal-500); }
.nav-section { margin-top: 16px; }
.nav-section-label { display: block; padding: 4px 18px 6px; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: rgba(255,255,255,.4); }

.main-wrapper { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; transition: margin-left .2s; }
.sidebar.collapsed ~ .main-wrapper { margin-left: 0; }
.topbar { height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; }
.topbar h2 { font-size: 1.1rem; font-weight: 600; color: var(--blue-900); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-info { font-size: .85rem; color: var(--gray-500); }
.sidebar-toggle { background: none; border: none; cursor: pointer; color: var(--gray-500); padding: 4px; }
.main-content { padding: 24px; flex: 1; }

/* === CARDS === */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 1rem; font-weight: 600; color: var(--blue-900); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; border-left: 4px solid var(--teal-600); }
.stat-card .stat-label { font-size: .75rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--blue-900); margin-top: 4px; }
.stat-card.approved { border-left-color: var(--green-600); }
.stat-card.rejected { border-left-color: var(--red-600); }
.stat-card.pending { border-left-color: var(--amber-600); }
.stat-card.info { border-left-color: var(--blue-600); }

/* === TABLES === */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th { text-align: left; padding: 10px 12px; background: var(--gray-50); color: var(--gray-500); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; border-bottom: 2px solid var(--gray-200); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--blue-50); }
tbody tr { cursor: pointer; }

/* === BADGES === */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.badge-nuevo { background: var(--gray-200); color: var(--gray-700); }
.badge-en_analisis { background: var(--amber-100); color: var(--amber-600); }
.badge-aprobado { background: var(--green-100); color: var(--green-600); }
.badge-rechazado { background: var(--red-100); color: var(--red-600); }
.badge-aprobado_condicionado { background: var(--yellow-100); color: var(--yellow-600); }
.badge-cancelado { background: var(--gray-200); color: var(--gray-500); }

/* === SCORE GAUGE === */
.gauge-container { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.gauge-bar { flex: 1; height: 12px; background: var(--gray-200); border-radius: 6px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 6px; transition: width .5s ease; }
.gauge-fill.red { background: var(--red-600); }
.gauge-fill.orange { background: #ea580c; }
.gauge-fill.amber { background: var(--amber-600); }
.gauge-fill.green { background: var(--green-600); }
.gauge-fill.teal { background: var(--teal-600); }
.gauge-value { font-weight: 700; font-size: 1.1rem; min-width: 60px; }

/* === PROFILE SECTION === */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.profile-section { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.profile-section h4 { font-size: .9rem; font-weight: 600; color: var(--blue-900); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--teal-100); }
.profile-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .85rem; }
.profile-row .label { color: var(--gray-500); }
.profile-row .value { font-weight: 600; }

/* === ALERTS === */
.alert-list { list-style: none; }
.alert-list li { padding: 8px 12px; margin-bottom: 6px; background: var(--red-100); color: var(--red-600); border-radius: var(--radius-sm); font-size: .85rem; display: flex; align-items: center; gap: 8px; }
.alert-list li::before { content: '!'; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--red-600); color: #fff; font-size: .7rem; font-weight: 700; flex-shrink: 0; }

/* === DICTAMEN === */
.dictamen-text { font-family: 'Courier New', monospace; white-space: pre-wrap; font-size: .8rem; line-height: 1.6; padding: 24px; background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); }
@media print {
    .sidebar, .topbar, .btn, .no-print { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
    .main-content { padding: 0 !important; }
    .dictamen-text { border: none; font-size: 10pt; }
}

/* === FILE UPLOAD === */
.upload-zone { border: 2px dashed var(--gray-300); border-radius: var(--radius); padding: 40px; text-align: center; cursor: pointer; transition: all .2s; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--teal-600); background: var(--teal-100); }
.upload-zone svg { margin-bottom: 12px; color: var(--gray-400); }
.upload-zone p { color: var(--gray-500); font-size: .9rem; }
.upload-zone input[type="file"] { display: none; }

/* === TOAST === */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius-sm); font-size: .85rem; color: #fff; box-shadow: var(--shadow-md); animation: slideIn .3s ease; max-width: 360px; }
.toast.success { background: var(--green-600); }
.toast.error { background: var(--red-600); }
.toast.info { background: var(--blue-600); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === LOADING === */
.loading-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; z-index: 9998; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--gray-200); border-top-color: var(--teal-600); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === DETAIL PAGE === */
.detail-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.detail-header .back-btn { background: none; border: none; cursor: pointer; color: var(--gray-500); padding: 4px; }
.detail-header h3 { font-size: 1.2rem; font-weight: 600; color: var(--blue-900); }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.detail-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.info-item { }
.info-item .info-label { font-size: .72rem; color: var(--gray-500); text-transform: uppercase; }
.info-item .info-value { font-weight: 500; margin-top: 2px; }

/* === TABS === */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab { padding: 10px 20px; font-size: .85rem; font-weight: 500; color: var(--gray-500); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--teal-600); border-bottom-color: var(--teal-600); }

/* === EMPTY STATE === */
.empty-state { text-align: center; padding: 40px; color: var(--gray-400); }
.empty-state svg { margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }

/* === SEARCH/FILTER BAR === */
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { padding: 7px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); font-size: .85rem; }
.filter-bar input { min-width: 240px; }

/* === SECTION HEADING === */
.section-heading { font-size: .9rem; font-weight: 600; color: var(--blue-900); margin: 20px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--teal-100); }

/* === MODAL === */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal h3 { font-size: 1.1rem; color: var(--blue-900); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .profile-grid { grid-template-columns: 1fr; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Credit Parameters Page */
.category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.category-tab {
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}
.category-tab:hover { background: #f3f4f6; }
.category-tab.active {
    background: #1E3A5F;
    color: #fff;
    border-color: #1E3A5F;
}
.category-tab .badge {
    display: inline-block;
    background: rgba(0,0,0,0.15);
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 11px;
    margin-left: 4px;
}
.category-tab.active .badge { background: rgba(255,255,255,0.3); }
.btn-danger-outline {
    border-color: #dc2626;
    color: #dc2626;
    background: #fff;
}
.btn-danger-outline:hover { background: #fef2f2; }

.param-name { font-weight: 600; font-size: 14px; }
.param-desc { font-size: 12px; color: #6b7280; margin-top: 2px; }
.badge-type {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    background: #e5e7eb;
    color: #374151;
}
.row-modified { background: #fffbeb !important; }
.font-mono { font-family: 'Courier New', monospace; }
.text-red-500 { color: #ef4444; }
.text-green-600 { color: #059669; }
.text-blue-600 { color: #2563eb; }

/* Credit Parameters Modal Fix */
.modal.hidden { display: none; }
#edit-param-modal, #history-param-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 300; display: flex; align-items: center; justify-content: center;
}
#edit-param-modal > .modal-overlay, #history-param-modal > .modal-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
}
#edit-param-modal > .modal-content, #history-param-modal > .modal-content {
    position: relative; z-index: 301;
    background: #fff; border-radius: 8px; padding: 24px;
    width: 500px; max-width: 90vw; max-height: 85vh;
    overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: #6b7280; }
.modal-close:hover { color: #111; }
.modal-body .form-group { margin-bottom: 14px; }
.modal-body label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: #374151; }
.modal-body .form-input { width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.modal-body .form-input:focus { outline: none; border-color: #1E3A5F; box-shadow: 0 0 0 2px rgba(30,58,95,0.15); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid #e5e7eb; }
