/* BH - Brokers Hipotecarios - Estilos */
:root {
    --primary: #1a56db;
    --primary-light: #3b82f6;
    --primary-dark: #1e40af;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
}

/* === Layout === */
.app-container { min-height: 100vh; display: flex; flex-direction: column; }
.navbar {
    background: var(--primary-dark);
    color: white;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
}
.navbar h1 { font-size: 18px; font-weight: 600; }
.navbar .user-info { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.navbar .badge {
    background: rgba(255,255,255,0.2);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
}
.main-content { flex: 1; padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* === Login === */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}
.login-card {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card h2 { text-align: center; margin-bottom: 8px; color: var(--primary-dark); }
.login-card .subtitle { text-align: center; color: var(--gray-500); margin-bottom: 32px; font-size: 14px; }
.login-card .error { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; display: none; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 4px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.form-group input.invalid { border-color: var(--danger); }
.form-group .hint { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.form-group .error-msg { font-size: 12px; color: var(--danger); margin-top: 2px; display: none; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    gap: 8px;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--gray-50); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* === Cards === */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}
.card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

/* === Section Collapsible === */
.section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.section-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    user-select: none;
}
.section-header h3 { margin: 0; border: none; padding: 0; font-size: 15px; }
.section-header .step {
    background: var(--primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    margin-right: 12px;
}
.section-header .left { display: flex; align-items: center; }
.section-header .chevron { transition: transform 0.2s; color: var(--gray-500); }
.section.collapsed .section-body { display: none; }
.section.collapsed .chevron { transform: rotate(-90deg); }
.section-body { padding: 20px; }
.section.complete .section-header { background: #ecfdf5; }
.section.complete .step { background: var(--success); }

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* === Table === */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 13px;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--gray-50); }

/* === Results === */
.results-container { display: none; }
.results-container.visible { display: block; }
.result-card {
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}
.result-card.top-1 { border-color: #fbbf24; background: #fffbeb; }
.result-card.top-2 { border-color: #9ca3af; background: #f9fafb; }
.result-card.top-3 { border-color: #d97706; background: #fffbeb; }
.result-card .rank {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 8px;
}
.result-card.top-1 .rank { color: #b45309; }
.result-card .banco { font-size: 18px; font-weight: 700; }
.result-card .producto { color: var(--gray-500); font-size: 14px; }
.result-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.metric { text-align: center; }
.metric .value { font-size: 20px; font-weight: 700; color: var(--primary); }
.metric .label { font-size: 12px; color: var(--gray-500); }

/* === Loading === */
.spinner {
    border: 3px solid var(--gray-200);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.loading-overlay.active { display: flex; }
.loading-box {
    background: white;
    padding: 32px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.loading-box p { margin-top: 16px; color: var(--gray-700); }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    z-index: 200;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
}
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* === Tooltips === */
.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
    line-height: 1;
}
#bh-tooltip-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 9998;
}
#bh-tooltip-overlay.active { display: block; }
#bh-tooltip-box {
    display: none;
    position: fixed;
    background: #1e293b;
    color: #f1f5f9;
    padding: 16px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 400;
    line-height: 1.7;
    width: 370px;
    max-width: calc(100vw - 24px);
    max-height: 50vh;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    text-align: left;
    white-space: normal;
    border: 1px solid rgba(255,255,255,0.1);
}
#bh-tooltip-box.active { display: block; }
#bh-tooltip-box b { color: #93c5fd; }
#bh-tooltip-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
}
#bh-tooltip-close:hover { color: white; }
