/* OPTIMIZER RESULTS */
#optimizerResults {
    max-height: 600px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 1rem;
}

#optimizerResults tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

#optimizerResults tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

#optimizerResults tr:active {
    background-color: rgba(255, 255, 255, 0.1);
}

/* SCROLLBAR STYLING */
#optimizerResults::-webkit-scrollbar {
    width: 8px;
}
#optimizerResults::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
#optimizerResults::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
#optimizerResults::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #0f3460;
    --accent-primary: #e94560;
    --accent-secondary: #0ea5e9;
    --accent-tertiary: #22c55e;
    --accent-gold: #f59e0b;
    --accent-purple: #a855f7;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-glow: 0 0 40px rgba(233, 69, 96, 0.15);
    --gradient-primary: linear-gradient(135deg, #e94560 0%, #0ea5e9 100%);
    --gradient-card: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem 0;
}

h1 {
    font-size: 2.25rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

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

.card {
    background: var(--gradient-card);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.inputs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.input-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.section-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
}

.input-group {
    margin-bottom: 0.6rem;
}

.input-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

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

.input-prefix,
.input-suffix {
    position: absolute;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    pointer-events: none;
}

.input-prefix {
    left: 0.6rem;
}

.input-suffix {
    right: 0.6rem;
}

input[type="number"] {
    width: 100%;
    padding: 0.5rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-secondary);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

input.has-prefix {
    padding-left: 1.5rem;
}

input.has-suffix {
    padding-right: 2rem;
}

.calculated-value {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    color: var(--accent-tertiary);
    font-weight: 600;
    text-align: right;
}

.calculated-value.neutral {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.3);
    color: var(--accent-secondary);
}

.mortgage-terms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

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

.term-card {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
}

.term-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
}

.term-title {
    font-size: 0.9rem;
    font-weight: 700;
}

.term-title.t10 {
    color: var(--accent-tertiary);
}

.term-title.t15 {
    color: var(--accent-secondary);
}

.term-title.t30 {
    color: var(--accent-purple);
}

.term-badge {
    font-size: 0.55rem;
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.term-badge.t10 {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-tertiary);
}

.term-badge.t15 {
    background: rgba(14, 165, 233, 0.2);
    color: var(--accent-secondary);
}

.term-badge.t30 {
    background: rgba(168, 85, 247, 0.2);
    color: var(--accent-purple);
}

.term-calculations {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--border-color);
}

.calc-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
}

.calc-row .label {
    color: var(--text-muted);
}

.calc-row .value {
    font-weight: 600;
    color: var(--text-primary);
}

.calc-row .value.positive {
    color: var(--accent-tertiary);
}

.calc-row .value.negative {
    color: var(--accent-primary);
}

.comparison-table-wrapper {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.5rem 0.6rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    background: var(--bg-input);
    position: sticky;
    top: 0;
    z-index: 10;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
    text-align: left;
    font-weight: 600;
    position: sticky;
    left: 0;
    background: var(--bg-secondary);
    z-index: 5;
}

.comparison-table thead th:first-child {
    z-index: 15;
    background: var(--bg-input);
}

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

.comparison-table tr:hover td:first-child {
    background: var(--bg-card);
}

.comparison-table .best-row {
    background: rgba(34, 197, 94, 0.08);
}

.comparison-table .best-row td {
    border-top: 2px solid var(--accent-tertiary);
    border-bottom: 2px solid var(--accent-tertiary);
}

.comparison-table .best-row td:first-child {
    border-left: 2px solid var(--accent-tertiary);
}

.comparison-table .best-row td:last-child {
    border-right: 2px solid var(--accent-tertiary);
}

.best-badge {
    display: inline-block;
    background: var(--accent-tertiary);
    color: #000;
    font-size: 0.5rem;
    font-weight: 700;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    margin-left: 0.3rem;
    text-transform: uppercase;
}

.positive {
    color: var(--accent-tertiary);
}

.negative {
    color: var(--accent-primary);
}

.highlight {
    color: var(--accent-gold);
    font-weight: 700;
}

.chart-container {
    height: 280px;
    margin-top: 0.75rem;
}

.extra-payment-section {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    padding: 0.75rem;
    margin-top: 0.75rem;
}

.extra-payment-section .section-label {
    color: var(--accent-gold);
    border-color: rgba(245, 158, 11, 0.3);
}

.info-text {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

footer {
    text-align: center;
    padding: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.calculate-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.75rem;
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.3);
}

.legend-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.7rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

.scenario-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.scenario-tab {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    transition: all 0.2s;
}

.scenario-tab:hover {
    border-color: var(--accent-secondary);
    color: var(--text-primary);
}

.scenario-tab.active {
    background: var(--accent-secondary);
    color: white;
    border-color: var(--accent-secondary);
}

.scenario-tab.active.t10 {
    background: var(--accent-tertiary);
    border-color: var(--accent-tertiary);
}

.scenario-tab.active.t15 {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.scenario-tab.active.t30 {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
}

.scenario-tab.active.t30x {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
}

.toggle-switch { position: relative; display: inline-block; width: 40px; height: 20px; vertical-align: middle; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--surface-light); transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: var(--text-secondary); transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-primary); }
input:checked + .slider:before { transform: translateX(20px); background-color: #fff; }
.input-group-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.input-group-header h2, .input-group-header h3 { margin-bottom: 0; }

/* INSIGHTS PANEL */
.insights-panel {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(168, 85, 247, 0.1));
    border: 1px solid rgba(14, 165, 233, 0.3);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.insights-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.insight-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.insight-card {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.insight-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.insight-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.insight-description {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.spread-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.spread-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.spread-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

/* OPPORTUNITY COST CARD */
.opp-cost-card {
    background: rgba(251, 191, 36, 0.05);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.opp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.opp-option {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.opp-option.winner {
    border-color: var(--accent-gold);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.15);
    position: relative;
}

.opp-option.winner::after {
    content: '🏆 Recommended';
    position: absolute;
    top: -10px;
    right: 10px;
    background: var(--accent-gold);
    color: #000;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 10px;
}

.opp-option-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.opp-metric {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.opp-value {
    font-weight: 600;
    color: var(--text-primary);
}

.opp-total {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.opp-summary {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
    line-height: 1.4;
    padding: 0.75rem;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
}

/* SENSITIVITY TABLE */
.sensitivity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.sensitivity-cell {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0.6rem;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.sensitivity-cell.winner-10 {
    border-color: var(--accent-tertiary);
    background: rgba(34, 197, 94, 0.1);
}

.sensitivity-cell.winner-15 {
    border-color: var(--accent-secondary);
    background: rgba(14, 165, 233, 0.1);
}

.sensitivity-cell.winner-30 {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.1);
}

.sensitivity-cell.winner-30x {
    border-color: var(--accent-gold);
    background: rgba(245, 158, 11, 0.1);
}

.sensitivity-cell.current {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.sensitivity-rate {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.sensitivity-winner {
    font-size: 0.65rem;
    font-weight: 600;
}

.sensitivity-diff {
    font-size: 0.6rem;
    color: var(--text-muted);
}

/* KEY METRICS BAR */
.metrics-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.metric-item {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.metric-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.why-box {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    padding: 1rem;
    margin-top: 1rem;
}

.why-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 0.5rem;
}

.why-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .inputs-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chart-container {
        height: 220px;
    }
}

/* Button Progress Bar */
.btn-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px; /* Horizontal bar */
    width: 0%;
    background-color: rgba(255, 255, 255, 0.7);
    transition: width 0.1s linear;
    z-index: 10;
}
