/* Reset and Core Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(22, 28, 45, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --success-color: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --danger-color: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    position: relative;
    overflow-x: hidden;
}

/* Background Glow Effect */
.glow-bg {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0) 70%);
    top: -100px;
    left: -100px;
    z-index: -1;
    pointer-events: none;
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header Styles */
.app-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-wrap: wrap;
    gap: 1rem;
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.nav-link i {
    font-size: 1rem;
    color: var(--primary-color);
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}


.app-header .logo h1 {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    color: var(--text-primary);
}

.app-header .logo h1 span {
    color: var(--primary-color);
}

.app-header .subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* Card General Design */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    padding: 2rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 1rem;
}

.card-header i {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.card-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Form Styles */
.loan-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.form-group label .opt {
    font-size: 0.75rem;
    opacity: 0.7;
    font-weight: 300;
}

.fico-info {
    cursor: pointer;
    color: var(--primary-color);
    margin-left: 0.25rem;
    transition: color var(--transition-fast);
}

.fico-info:hover {
    color: #a5b4fc;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    pointer-events: none;
    transition: color var(--transition-fast);
}

.input-wrapper input,
.input-wrapper select {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.5rem;
    background-color: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper input:focus,
.input-wrapper select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.input-wrapper input:focus + i,
.input-wrapper select:focus + i {
    color: var(--primary-color);
}

.input-wrapper select {
    appearance: none;
    cursor: pointer;
}

/* Button Customization */
.btn {
    padding: 0.9rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(1px);
}

/* Results Section States */
.state-container {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 1.5rem;
    min-height: 400px;
    height: 100%;
}

.state-container.active {
    display: flex;
}

.empty-icon {
    font-size: 4rem;
    color: rgba(99, 102, 241, 0.3);
    margin-bottom: 1.5rem;
}

.state-container h3 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.state-container p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 320px;
}

/* Spinner for loading state */
.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.05);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-icon {
    font-size: 4rem;
    color: var(--danger-color);
    margin-bottom: 1.5rem;
}

/* Results Content */
.results-content {
    display: none;
    flex-direction: column;
    gap: 1.75rem;
    padding: 0;
    text-align: left;
    min-height: auto;
}

.results-content.active {
    display: flex;
}

.result-header-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    gap: 1.5rem;
}

.decision-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    flex: 1;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.decision-badge.approved {
    background-color: var(--success-bg);
    color: var(--success-color);
    border: 1.5px solid rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.1);
}

.decision-badge.rejected {
    background-color: var(--danger-bg);
    color: var(--danger-color);
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.1);
}

/* Circular Gauge */
.gauge-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.gauge-ring {
    position: relative;
    width: 120px;
    height: 120px;
}

.gauge-ring svg {
    transform: rotate(-90deg);
}

.gauge-base {
    fill: none;
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 8;
}

.gauge-progress {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 314.16; /* 2 * PI * r (r=50) */
    stroke-dashoffset: 314.16;
    transition: stroke-dashoffset 1s ease-in-out, stroke 1s;
}

.gauge-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#healthScore {
    font-size: 1.4rem;
    font-weight: 700;
}

.gauge-text .label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    margin-top: 0.1rem;
    letter-spacing: 0.05em;
}

/* Narrative Section styling */
.narrative-section {
    background: rgba(99, 102, 241, 0.04);
    border: 1px solid rgba(99, 102, 241, 0.1);
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.narrative-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-sparkle {
    color: #a5b4fc;
    font-size: 1rem;
}

.narrative-title h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #c7d2fe;
    flex: 1;
}

.ai-badge {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ai-badge.fallback {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.narrative-body p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #e2e8f0;
    font-weight: 300;
    font-style: italic;
}

/* SHAP Factors Section */
.shap-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.shap-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.factors-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.factor-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 0.75rem;
    padding: 0.85rem 1.25rem;
    gap: 1rem;
    transition: transform var(--transition-fast);
}

.factor-item:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.02);
}

.factor-icon-wrapper {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.factor-icon-wrapper.positive {
    background-color: var(--success-bg);
    color: var(--success-color);
}

.factor-icon-wrapper.negative {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}

.factor-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.factor-name {
    font-size: 0.95rem;
    font-weight: 500;
}

.factor-val {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.factor-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
}

.factor-badge.positive {
    background-color: var(--success-bg);
    color: var(--success-color);
}

.factor-badge.negative {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}

/* Footer Section */
.metadata-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.25);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

/* Developer / Debug Panel Styles */
.debug-toggle-container {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

.btn-debug {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-debug:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.debug-panel {
    display: none;
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: rgba(10, 15, 30, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    animation: fadeIn 0.3s ease-out;
}

.debug-panel.active {
    display: block;
}

.debug-section {
    margin-bottom: 1.5rem;
}

.debug-section:last-child {
    margin-bottom: 0;
}

.debug-section h5 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Metrics Table */
.metrics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.metrics-table tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.metrics-table tr:last-child {
    border-bottom: none;
}

.metrics-table td {
    padding: 0.5rem 0;
    color: var(--text-secondary);
}

.metrics-table td:last-child {
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

/* SHAP Chart */
.shap-chart-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.shap-bar-row {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    gap: 0.5rem;
}

.shap-bar-label {
    width: 130px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shap-bar-wrapper {
    flex: 1;
    height: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.shap-bar-center-line {
    position: absolute;
    left: 50%;
    top: 0;
    width: 1px;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    z-index: 2;
}

.shap-bar {
    position: absolute;
    height: 100%;
    border-radius: 3px;
    z-index: 1;
}

.shap-bar.positive {
    background: var(--success-color);
}

.shap-bar.negative {
    background: var(--danger-color);
}

.shap-bar-value {
    width: 55px;
    text-align: right;
    font-family: monospace;
    font-weight: bold;
}

.shap-bar-value.positive {
    color: var(--success-color);
}

.shap-bar-value.negative {
    color: var(--danger-color);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Advanced Options Styles */
.advanced-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.05);
    border: 1px dashed rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-color);
    transition: all var(--transition-fast);
    margin-top: 0.5rem;
}

.advanced-toggle:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.4);
    color: var(--text-primary);
}

.advanced-toggle .toggle-icon {
    transition: transform var(--transition-fast);
}

.advanced-toggle.active .toggle-icon {
    transform: rotate(180deg);
}

.advanced-fields {
    display: none;
    flex-direction: column;
    gap: 1.25rem;
    margin-top: 1rem;
    animation: fadeIn 0.3s ease-out;
}

/* Load Borderline Demo Button Styles */
.btn-demo-load {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: #818cf8;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.btn-demo-load:hover {
    color: var(--text-primary);
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-demo-load:active {
    transform: translateY(1px);
}

/* New Application Header Button Styles */
.btn-new-app {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    transition: all var(--transition-fast);
}

.btn-new-app i {
    color: var(--primary-color);
    transition: transform var(--transition-fast);
}

.btn-new-app:hover {
    color: #818cf8;
}

.btn-new-app:hover i {
    transform: rotate(90deg);
}

/* History Card and Table Styles */
.history-card {
    grid-column: span 2;
    margin-top: 1rem;
}

.history-table-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 1rem;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.history-table th,
.history-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.history-table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.history-table td {
    color: var(--text-primary);
}

.history-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.history-decision {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
}

.history-decision.approved {
    background-color: var(--success-bg);
    color: var(--success-color);
}

.history-decision.rejected {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}

.btn-history-load {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.btn-history-load:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.3);
}

.btn-history-load:active {
    transform: translateY(1px);
}

/* Mobile-specific adjustments (iPhones and other mobile devices) */
@media (max-width: 768px) {
    /* Hide the application history card as it is not necessary on mobile devices */
    .history-card {
        display: none !important;
    }
}

@media (max-width: 480px) {
    /* Reduce page container padding to maximize screen real estate */
    .container {
        padding: 1.25rem 0.75rem;
        gap: 1.25rem;
    }

    /* Reduce card padding to leave more space for inputs and charts */
    .card {
        padding: 1.25rem 1rem;
    }

    /* Make the app header more compact */
    .app-header {
        padding-bottom: 1rem;
        gap: 0.25rem;
    }

    .app-header .logo h1 {
        font-size: 1.85rem;
    }

    .app-header .subtitle {
        font-size: 0.85rem;
    }

    /* Adjust header main flex layout */
    .header-main {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-nav {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .nav-link {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    /* Wrap/stack card header buttons to prevent horizontal overflow */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .btn-demo-load {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }

    .btn-new-app {
        width: 100%;
    }

    /* Make result header box stack vertically on narrow screens */
    .result-header-box {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 1.25rem 1rem;
        gap: 1.25rem;
    }

    .decision-badge {
        width: 100%;
        font-size: 1.15rem;
        padding: 0.65rem 1rem;
    }

    .gauge-container {
        order: -1; /* Place gauge above decision badge for cleaner hierarchy on mobile */
    }

    /* Make SHAP chart elements inside debug panel fit narrow screens */
    .shap-bar-label {
        width: 90px;
        font-size: 0.7rem;
    }

    .shap-bar-value {
        width: 45px;
        font-size: 0.7rem;
    }
}

