/* Self-hosted fonts (Google Fonts moved on-site to avoid external CLS/LCP cost) */
@font-face {
    font-family: 'DM Sans';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/dm-sans-latin-var-400-700.woff2') format('woff2');
}

@font-face {
    font-family: 'Playfair Display';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/playfair-display-latin-var-400-700.woff2') format('woff2');
}

@font-face {
    font-family: 'Playfair Display';
    font-style: italic;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/playfair-display-latin-italic-var-400-700.woff2') format('woff2');
}
/* Reverted to original styles as per user request */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0f4c3a;
    --primary-light: #1a6b52;
    --primary-dark: #092e23;
    --accent: #d4af37;
    --accent-text: #937000;
    --accent-light: #e8c547;
    --secondary: #1a2a3a;
    --background: #f5f7fa;
    --card-bg: #ffffff;
    --text-dark: #0f1419;
    --text-light: #595959;
    --border: #e5e7eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --pulse-glow: rgba(16, 185, 129, 0.4);
    --chart-principal: #0f4c3a;
    --chart-interest: #d97706;
    --chart-balance-line: #991b1b;
    --chart-prepayment: #0d4221;
    --chart-total-prepayment: #6d28d9;
    --bg-body: #f8f9fb;
    --pct: 0;
    --bg-card: var(--card-bg);
}

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

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    width: 100%;
    min-height: 100vh;
    font-family: 'DM Sans', sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, #eef2f5 100%);
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
}

/* Prevent horizontal scroll on all containers */
.container,
.main-grid,
.calculator-section,
.card,
.results-grid,
.comparison-grid,
.charts-grid,
#resultsContainer {
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 45px;
    height: 45px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 595; /* below tabbar (600) so it never covers More tab */
    border: none;
}
@media (max-width: 860px) {
    .back-to-top {
        bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 12px); /* above tabbar */
        right: 16px;
        width: 40px;
        height: 40px;
        z-index: 595;
    }
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--primary-light);
    transform: translateY(-5px);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 var(--pulse-glow);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.savings-card.pulse {
    animation: pulse 2s infinite;
}

/* Header & Navigation */
header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.logo span {
    color: #856300;
}

/* Main Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 24px;
}

/* Hero Section */
.hero {
    text-align: center;
    margin-bottom: 50px;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hero h1 {
    font-family: 'Playfair Display', serif;
    font-size: 48px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 12px;
    line-height: 1.2;
}

.hero p {
    font-size: 18px;
    color: var(--text-light);
    max-width: 650px;
    margin: 0 auto;
    line-height: 1.6;
    font-weight: 400;
}

/* Loan Type Selector */
.loan-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.loan-selector .form-group {
    margin-bottom: 0;
}

.loan-selector .form-group label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.loan-selector select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%230f4c3a' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C2.185 5.355 2.402 5 2.808 5h9.384c.406 0 .623.355.358.658l-4.796 5.482a.5.5 0 0 1-.727 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding: 0 48px 0 14px;
    font-size: 14px;
    font-weight: 600;
    background-color: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    height: 54px;
    width: 100%;
    color: var(--text-dark);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.loan-selector select:hover {
    border-color: var(--primary-light);
}

.loan-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(15, 76, 58, 0.1);
}

.loan-type-btn {
    padding: 12px 32px;
    border: 2px solid var(--border);
    background: var(--card-bg);
    color: var(--text-dark);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'DM Sans', sans-serif;
    position: relative;
    overflow: hidden;
}

.loan-type-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(15, 76, 58, 0.12);
}

.loan-type-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 12px 32px rgba(15, 76, 58, 0.2);
}

/* Main Grid Layout */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    animation: fadeIn 0.8s ease-out 0.3s backwards;
}

@media (max-width: 1200px) {
    .main-grid {
        grid-template-columns: 1fr;
        max-width: 100%;
    }
}

/* Calculator Section */
.calculator-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .calculator-section {
        grid-template-columns: 1fr;
    }
}

/* Card Styles */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
    border-color: rgba(15, 76, 58, 0.2);
}

.card h2 {
    font-family: 'Playfair Display', serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card h2::before {
    content: '';
    width: 5px;
    height: 24px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 4px;
}

.beautiful-title {
    margin: 30px 0 20px;
    font-size: 22px;
    color: var(--primary-dark);
    font-family: 'Playfair Display', serif;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    padding-bottom: 8px;
}

.beautiful-title::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px;
}

.disclaimer-box {
    background: rgba(15, 76, 58, 0.03);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

/* 3D tilt effect for pie charts only */
.chart-container:has(#pieChartNoPrepayment),
.chart-container:has(#pieChartWithPrepayment),
.chart-container:has(#monthlyBreakdownChart) {
    perspective: none;
}

.chart-container:has(#pieChartNoPrepayment) canvas,
.chart-container:has(#pieChartWithPrepayment) canvas,
.chart-container:has(#monthlyBreakdownChart) canvas {
    transform: none;
    filter: none;
    transition: transform 0.3s ease;
}

.chart-container:has(#pieChartNoPrepayment) canvas:hover,
.chart-container:has(#pieChartWithPrepayment) canvas:hover,
.chart-container:has(#monthlyBreakdownChart) canvas:hover {
    transform: scale(1.02);
}

.chart-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

/* Form Elements */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
    font-size: 14px;
    position: relative;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: var(--primary-light);
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    cursor: help;
    position: relative;
    vertical-align: middle;
}

.info-icon:hover::after {
    content: attr(data-tooltip);
    /* Fixed position instead of absolute to break out of overflow: hidden containers */
    position: fixed;
    background: var(--primary-dark);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 400;
    white-space: normal;
    width: max-content;
    max-width: 250px;
    text-align: left;
    z-index: 999999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    line-height: 1.4;
    /* Controlled by JS */
    top: var(--tooltip-top, auto);
    left: var(--tooltip-left, -9999px);
    transform: translate(var(--tooltip-shift, -50%), -100%);
}

.info-icon:hover::before {
    content: '';
    position: fixed;
    border: 6px solid transparent;
    border-top-color: var(--primary-dark);
    z-index: 999999;
    /* Controlled by JS */
    top: var(--arrow-top, auto);
    left: var(--arrow-left, -9999px);
    transform: translate(var(--arrow-shift, -50%), -100%);
}

.input-wrapper {
    position: relative;
}

.input-prefix,
.input-suffix {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-weight: 700;
    pointer-events: none;
    z-index: 1;
}

.input-prefix {
    left: 16px;
}

.input-suffix {
    right: 16px;
}

input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    font-family: 'DM Sans', sans-serif;
    transition: all 0.3s;
    background: var(--card-bg);
    color: var(--text-dark);
    font-weight: 700;
}

input[type="number"].has-prefix {
    padding-left: 40px;
}

input[type="number"].has-suffix {
    padding-right: 40px;
}

/* Dropdown Styling */
.header-select {
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    width: auto;
}

.header-select:hover {
    border-color: var(--primary-light);
    background: #fff;
}

.loan-category-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%230f4c3a' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C2.185 5.355 2.402 5 2.808 5h9.384c.406 0 .623.355.358.658l-4.796 5.482a.5.5 0 0 1-.727 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding-right: 48px !important;
    font-weight: 600;
    background-color: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    height: 54px;
}

.loan-category-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(15, 76, 58, 0.1);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(15, 76, 58, 0.1);
}

.read-only-input {
    background-color: #f3f4f6 !important;
    color: #4b5563 !important;
    cursor: not-allowed !important;
    border-color: #d1d5db !important;
}

/* Slider Styles */
.slider-group {
    margin-top: 12px;
}

.slider-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.slider-value-display {
    font-weight: 700;
    color: var(--primary);
    font-size: 16px;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, var(--primary) 0%, var(--primary) 50%, var(--border) 50%, var(--border) 100%);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 76, 58, 0.3);
    transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(15, 76, 58, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(15, 76, 58, 0.3);
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.radio-option {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    cursor: pointer;
    accent-color: var(--primary);
}

.radio-option label {
    cursor: pointer;
    margin: 0;
    font-weight: 500;
    color: var(--text-dark);
}

/* Button */
.btn-calculate {
    width: 100%;
    padding: 16px 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'DM Sans', sans-serif;
    box-shadow: 0 8px 20px rgba(15, 76, 58, 0.25);
    margin-top: 24px;
}

.btn-calculate:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(15, 76, 58, 0.35);
}

.btn-calculate:active {
    transform: translateY(0);
}

/* Results Section */
#resultsContainer {
    margin-top: 40px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
}

#resultsContainer.hidden {
    opacity: 0.5;
    pointer-events: none;
    min-height: 800px;
    /* Reserve space to prevent CLS */
    transition: opacity 0.3s ease;
}

#resultsContainer.hidden .result-value {
    color: transparent !important;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    animation: pulse 1.5s infinite;
}

:root[data-theme="dark"] #resultsContainer.hidden .result-value {
    background: rgba(255, 255, 255, 0.1);
}

#resultsContainer * {
    max-width: 100%;
    box-sizing: border-box;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
    max-width: 100%;
}

@media (max-width: 600px) {
    .results-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
}

.result-card {
    /* original result background: linear-gradient(135deg, #0f4c3a 0%, #1a6b52 100%); */
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #d4af37;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(15, 76, 58, 0.2);
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.result-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.result-card:hover {
    border-color: #d4af37;
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(15, 76, 58, 0.3);
}

.result-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.96);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    z-index: 1;
}

.result-value {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    font-family: 'DM Sans', sans-serif;
    position: relative;
    z-index: 1;
}

.result-value.highlight {
    color: #ffffff;
}

.result-value.highlight.negative {
    color: #f59e0b !important;
}

.result-value.negative {
    color: #f59e0b !important;
}

#resultsContainer .result-value {
    color: #ffffff !important;
}

#resultsContainer .result-value.negative {
    color: #f59e0b !important;
}

/* Balance After N Years value sizing (moved from inline styles) */
#balanceDate {
    font-size: 18px;
}

#balanceInterestPaid,
#balancePrincipalPaid,
#balanceOutstanding {
    font-size: 20px;
}

/* Comparison Section */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
    max-width: 100%;
}

@media (max-width: 900px) {
    .comparison-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
}

.comparison-card {
    /* original result background: linear-gradient(135deg, #0f4c3a 0%, #1a6b52 100%); */
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 24px;
    border-radius: 12px;
    border: none;
    box-shadow: 0 4px 15px rgba(15, 76, 58, 0.2);
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.comparison-card::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 50%;
    transform: translate(-30%, 30%);
}

.comparison-card h3 {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.comparison-card .comparison-description {
    font-size: 13px;
    color: #ffffff;
    margin-bottom: 15px;
    font-family: 'DM Sans', sans-serif;
    line-height: 1.4;
}

.comparison-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    position: relative;
    z-index: 1;
}

.comparison-item:last-child {
    border-bottom: none;
}

.comparison-label {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    font-weight: 500;
}

.comparison-value {
    font-weight: 700;
    color: #ffffff;
    font-size: 15px;
}

.comparison-value.negative {
    color: #f59e0b;
}

/* Table Styles */
.table-container {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 100%;
    margin-top: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.table-wrapper {
    overflow-x: auto;
    max-height: 550px;
    overflow-y: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbar */
.table-wrapper::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

table {
    width: 100%;
    min-width: 900px;
    border-collapse: separate;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: 16px 12px;
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--primary-dark);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

td {
    padding: 12px;
    border-bottom: 1px solid #edf2f7;
    font-size: 14px;
    color: var(--text-dark);
    transition: background 0.2s;
}

tr:last-child td {
    border-bottom: none;
}

tr:nth-child(even) {
    background-color: #f8fafc;
}

tr:hover {
    background-color: #f1f5f9 !important;
}

/* Prepayment Row Highlight (Excel Style) */
.prepayment-row {
    background-color: #dcfce7 !important;
    /* Soft Green */
}

.prepayment-row:hover {
    background-color: #bbf7d0 !important;
}

.prepayment-row td {
    font-weight: 500;
    color: #166534;
    border-bottom-color: #bbf7d0;
}

.text-right {
    text-align: right;
}

.font-bold {
    font-weight: 700;
}

.payment-no {
    color: var(--primary-dark);
    font-weight: 700;
}

.year-end-marker {
    background: linear-gradient(90deg, rgba(15, 76, 58, 0.05), var(--primary-dark), rgba(15, 76, 58, 0.05)) !important;
    color: #ffffff !important;
    font-weight: 700;
    text-align: center !important;
    padding: 10px !important;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 12px;
    border: none !important;
}

:root[data-theme="dark"] .year-end-marker {
    background: linear-gradient(90deg, rgba(52, 211, 153, 0.05), var(--primary-dark), rgba(52, 211, 153, 0.05)) !important;
}

/* Chart Styles */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(450px, 100%), 1fr));
    gap: 24px;
    margin: 30px 0;
}

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

.loan-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    background: rgba(15, 76, 58, 0.03);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

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

.chart-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.chart-card h3 {
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 20px;
    text-align: center;
}

.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 3D tilt effect for pie charts only */
.chart-container:has(#pieChartNoPrepayment),
.chart-container:has(#pieChartWithPrepayment),
.chart-container:has(#monthlyBreakdownChart) {
    perspective: none;
}

.chart-container:has(#pieChartNoPrepayment) canvas,
.chart-container:has(#pieChartWithPrepayment) canvas,
.chart-container:has(#monthlyBreakdownChart) canvas {
    transform: none;
    filter: none;
    transition: transform 0.3s ease;
}

.chart-container:has(#pieChartNoPrepayment) canvas:hover,
.chart-container:has(#pieChartWithPrepayment) canvas:hover,
.chart-container:has(#monthlyBreakdownChart) canvas:hover {
    transform: scale(1.02);
}

.chart-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.chart-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.chart-detail-label {
    color: var(--text-light);
    font-weight: 500;
}

.chart-detail-value {
    color: var(--text-dark);
    font-weight: 700;
    font-family: 'DM Sans', sans-serif;
}

.chart-detail-value.highlight {
    color: var(--primary);
}

/* Ad Space */
.ad-space {
    background: linear-gradient(135deg, var(--card-bg) 0%, #f9fafb 100%);
    border-radius: 16px;
    padding: 32px;
    border: 2px dashed var(--border);
    min-height: 600px;
    display: none;
    /* Hidden for now */
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 18px;
    font-weight: 600;
    position: sticky;
    top: 100px;
}

/* Footer */
footer {
    background: var(--primary-dark);
    color: white;
    padding: 40px 24px;
    margin-top: 80px;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

.footer-content p {
    font-size: 14px;
    opacity: 0.8;
}

/* Utilities */
.hidden {
    display: none;
}

/* MOBILE OVERFLOW FIX - HIGHEST PRIORITY - CONSOLIDATED */
@media (max-width: 768px) {

    html,
    body {
        overflow-x: hidden !important;
        max-width: 100% !important;
        width: 100% !important;
        position: relative;
    }

    .container {
        padding: 15px 10px !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }

    .main-grid,
    .calculator-section,
    .card,
    .results-grid,
    .comparison-grid,
    .charts-grid,
    #resultsContainer {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
        min-width: 0 !important;
    }

    .loan-selector {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .result-value,
    .comparison-value,
    .chart-detail-value {
        max-width: 100% !important;
        word-wrap: break-word !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        white-space: normal !important;
        font-size: 18px !important;
    }

    .export-group {
        justify-content: center;
        gap: 8px !important;
    }

    .btn-export {
        width: 100% !important;
        justify-content: center;
    }

    /* Table containment */
    .table-container {
        width: 100% !important;
        max-width: calc(100vw - 20px) !important;
    }

    .table-wrapper {
        width: 100% !important;
        max-width: calc(100vw - 40px) !important;
    }

    table {
        min-width: 600px !important;
        /* Allow scroll but don't force page width */
    }
}

@media (max-width: 480px) {
    .hero h1 {
        font-size: 1.5rem !important;
    }

    .result-value {
        font-size: 1.05rem !important;
    }

}

/* ==================== SEO INTERNAL LINKS STYLES ==================== */
.internal-links-section {
    margin-bottom: 40px;
    padding: 30px;
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

/* Modifier for when nested inside another card to prevent cumulative padding/borders */
.internal-links-section.nested {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    margin-bottom: 30px;
}

.internal-links-section h3 {
    color: var(--primary);
    font-size: 20px;
    margin-bottom: 25px;
    font-family: 'Playfair Display', serif;
    text-align: center;
}

.internal-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}

.seo-link-card {
    text-decoration: none;
    padding: 16px;
    background: rgba(15, 76, 58, 0.05);
    border-radius: 12px;
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 14px;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}

.seo-link-card:hover {
    border-color: var(--primary);
    background: white;
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(15, 76, 58, 0.1);
    color: var(--primary);
}

:root[data-theme="dark"] .seo-link-card {
    background: rgba(52, 211, 153, 0.1);
    color: var(--primary-light);
}

:root[data-theme="dark"] .seo-link-card:hover {
    background: var(--card-bg);
    border-color: var(--primary);
}

@media (max-width: 768px) {
    .internal-links-section:not(.nested) {
        padding: 20px;
        border-radius: 16px;
    }

    .internal-links-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    .internal-links-section.nested {
        margin-bottom: 25px;
    }
}

@media (max-width: 480px) {
    .internal-links-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .seo-link-card {
        min-height: 50px;
        padding: 12px;
        font-size: 13px;
    }

    .internal-links-section h3 {
        font-size: 18px;
        margin-bottom: 15px;
    }
}

@media (max-width: 480px) {

    .card {
        padding: 12px !important;
    }

    /* Mobile table optimization - sticky first 4 columns */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    table {
        font-size: 10px !important;
        min-width: auto !important;
    }

    th,
    td {
        padding: 6px 4px !important;
        font-size: 10px !important;
        white-space: nowrap;
    }
}

.comparison-item,
.chart-detail-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 2px !important;
    padding: 12px 0 !important;
    width: 100% !important;
}

.comparison-label,
.chart-detail-label {
    width: 100% !important;
    display: block !important;
    text-align: left !important;
    font-size: 13px !important;
    margin-bottom: 2px !important;
}

/* Export Group stacking */
.export-group {
    gap: 10px !important;
    flex-direction: column !important;
    width: 100% !important;
}

.btn-export {
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    justify-content: center !important;
}

.loan-selector .form-group {
    min-width: 0 !important;
    flex: 1 1 100% !important;
}

.chart-container {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    height: 300px !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

canvas {
    max-width: 100% !important;
}

table {
    width: 100% !important;
    min-width: 0 !important;
}

.beautiful-title {
    font-size: 18px !important;
    word-wrap: break-word !important;
}

/* ==================== DARK MODE ==================== */
:root[data-theme="dark"] {
    --primary: #34d399;
    --primary-light: #6ee7b7;
    --primary-dark: #059669;
    --accent: #fbbf24;
    --accent-light: #fcd34d;
    --secondary: #1e293b;
    --background: #0f172a;
    --card-bg: #1e293b;
    --text-dark: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --chart-principal: #34d399;
    --chart-interest: #f59e0b;
    --chart-balance-line: #f87171;
    --chart-prepayment: #10b981;
    --chart-total-prepayment: #a78bfa;
}

:root[data-theme="dark"] body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

:root[data-theme="dark"] header {
    background: #1e293b;
    border-bottom-color: #334155;
}

:root[data-theme="dark"] .result-card {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.15) 0%, rgba(16, 185, 129, 0.08) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

:root[data-theme="dark"] .comparison-card {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.12) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid rgba(52, 211, 153, 0.15);
}

:root[data-theme="dark"] .comparison-item {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] tr:nth-child(even) {
    background-color: #1a2744;
}

:root[data-theme="dark"] tr:hover {
    background-color: #1e3a5f !important;
}

:root[data-theme="dark"] td {
    border-bottom-color: #2d3748;
}

:root[data-theme="dark"] th {
    background: #0f2b1d;
}

:root[data-theme="dark"] .prepayment-row {
    background-color: rgba(16, 185, 129, 0.15) !important;
}

:root[data-theme="dark"] .prepayment-row:hover {
    background-color: rgba(16, 185, 129, 0.25) !important;
}

:root[data-theme="dark"] .prepayment-row td {
    color: #6ee7b7;
    border-bottom-color: rgba(16, 185, 129, 0.15);
}

:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] input[type="date"],
:root[data-theme="dark"] select {
    background: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

/* One-time payments (DCA-style add-row UI) */
.one-time-lump-section {
    background: rgba(15, 76, 58, 0.03);
    border-radius: 12px;
    padding: 20px;
    border: 1px dashed var(--border);
}

.one-time-payment-row {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.one-time-payment-row:last-child {
    margin-bottom: 0;
}

.one-time-lump-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: flex-end;
}

.one-time-lump-grid.action-row {
    grid-template-columns: 2fr 1fr;
}

.one-time-lump-section .btn-secondary {
    width: 100%;
    padding: 12px 14px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.one-time-lump-section .btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(15, 76, 58, 0.06);
}

.btn-secondary.btn-cancel-soft {
    height: 50px;
    width: 100%;
    padding: 0 10px;
    border: 1px solid #feb2b2;
    border-radius: 10px;
    background: #fff5f5;
    color: #c53030;
}

.btn-secondary.btn-cancel-soft:hover {
    background: #ffe3e3;
    border-color: #fda4af;
    color: #c53030;
}

@media (max-width: 480px) {

    .one-time-lump-grid,
    .one-time-lump-grid.action-row {
        grid-template-columns: 1fr;
    }

    .one-time-lump-grid.action-row button {
        width: 100%;
        margin-top: 5px;
    }
}

:root[data-theme="dark"] input[type="range"] {
    background: #334155;
}

:root[data-theme="dark"] .table-container {
    border-color: #334155;
}

:root[data-theme="dark"] .seo-loan-grid>div,
:root[data-theme="dark"] [style*="background: #f9fafb"] {
    background: #1a2744 !important;
}

/* Dark Mode Toggle Button */
.theme-toggle {
    background: none;
    border: 2px solid var(--border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    color: var(--text-dark);
}

.theme-toggle:hover {
    border-color: var(--accent);
    transform: rotate(30deg) scale(1.1);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

/* ==================== GLASSMORPHISM RESULT CARDS ==================== */
.result-card {
    /* original result background: linear-gradient(135deg, #0f4c3a 0%, #1a6b52 100%); */
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
    border: 1px solid #d4af37 !important;
}

.comparison-card {
    /* original result background: linear-gradient(135deg, #0f4c3a 0%, #1a6b52 100%); */
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
}

/* ==================== AUTHOR BIO ==================== */
.author-bio {
    display: flex;
    align-items: center;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-top: 40px;
    gap: 20px;
}

.author-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 32px;
    font-weight: bold;
    flex-shrink: 0;
}

.author-info h3 {
    margin: 0 0 8px 0;
    color: var(--text-dark);
    font-size: 18px;
}

.author-info p {
    margin: 0 0 12px 0;
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.5;
}

.author-links a {
    display: inline-flex;
    align-items: center;
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.author-links a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

@media (max-width: 600px) {
    .author-bio {
        flex-direction: column;
        text-align: center;
    }
}

/* ==================== HERO BACKGROUND PATTERN ==================== */
/* Hero background is now handled by the .hero class above */

.ad-space {
    min-height: 90px;
    /* Standard ad height to prevent CLS */
    display: none;
    /* Hidden for now as requested */
    align-items: center;
    justify-content: center;
    background: rgba(15, 76, 58, 0.02);
    margin: 20px 0;
    border-radius: 8px;
    border: 1px dashed var(--border);
}

.seo-content-area {
    min-height: 500px;
    /* Reserve space for large content block to reduce CLS (0.156 score) */
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, rgba(15, 76, 58, 0.05) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}

.hero * {
    position: relative;
    z-index: 1;
}

@keyframes heroPulse {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(12px, 12px);
    }
}

/* ==================== SCROLL REVEAL ANIMATIONS ==================== */
.scroll-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.scroll-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

.scroll-reveal:nth-child(2) {
    transition-delay: 0.1s;
}

.scroll-reveal:nth-child(3) {
    transition-delay: 0.2s;
}

.scroll-reveal:nth-child(4) {
    transition-delay: 0.3s;
}

/* ==================== INPUT FOCUS MICRO-ANIMATIONS ==================== */
.form-group {
    position: relative;
}

input[type="number"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(15, 76, 58, 0.15), 0 4px 12px rgba(15, 76, 58, 0.1);
    transform: translateY(-1px);
}

.form-group label {
    transition: color 0.3s ease;
}

.form-group:focus-within label {
    color: var(--primary);
}

/* ==================== LOADING SKELETON ==================== */
.skeleton-loading {
    position: relative;
    background: rgba(15, 76, 58, 0.03);
}

/* ==================== BUTTON RIPPLE EFFECT ==================== */
.btn-calculate {
    position: relative;
    overflow: hidden;
}

.btn-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0);
    animation: rippleEffect 0.6s linear;
    pointer-events: none;
}

@keyframes rippleEffect {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ==================== SAVINGS HIGHLIGHT CARD ==================== */
.savings-card {
    background: rgba(212, 175, 55, 0.08);
    border: 2px solid rgba(212, 175, 55, 0.3);
    border-radius: 16px;
    padding: 24px;
    margin-top: 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.savings-card .savings-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 8px;
}

.savings-card .savings-amount {
    font-family: 'Playfair Display', serif;
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 2px 10px rgba(212, 175, 55, 0.3);
}

.savings-card .savings-subtitle {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 6px;
}

/* Sparkle animation for savings card */
.savings-card .sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
    animation: sparkleFloat 3s ease-in-out infinite;
}

@keyframes sparkleFloat {

    0%,
    100% {
        opacity: 0;
        transform: translateY(0) scale(0);
    }

    50% {
        opacity: 1;
        transform: translateY(-20px) scale(1);
    }
}

/* Print Styles */
@media print {

    /* Page setup */
    @page {
        size: A4 portrait;
        margin: 15mm 12mm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Hide ONLY these elements */
    header,
    .ad-space,
    .btn-calculate,
    .export-group,
    .loan-selector,
    .calculator-section,
    .hero,
    .seo-content-area,
    .back-to-top,
    #chartFallback,
    .theme-toggle,
    footer,
    .disclaimer-box,
    .savings-card {
        display: none !important;
    }

    /* SHOW CHARTS IN PDF - Keep them visible */
    .chart-card {
        display: block !important;
        page-break-inside: avoid !important;
        margin-bottom: 20px !important;
        padding: 10px !important;
        border: 1px solid #ddd !important;
    }

    .chart-container {
        display: block !important;
        height: 300px !important;
        page-break-inside: avoid !important;
    }

    canvas {
        display: block !important;
        max-width: 100% !important;
        height: 300px !important;
    }

    .charts-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 15px !important;
        margin: 20px 0 !important;
        page-break-inside: avoid !important;
    }

    /* Show chart details */
    .chart-details {
        display: block !important;
        visibility: visible !important;
        height: auto !important;
    }

    .container {
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    #resultsContainer {
        display: block !important;
        opacity: 1 !important;
        transform: none !important;
        width: 100% !important;
    }

    .card {
        box-shadow: none !important;
        border: none !important;
        margin-bottom: 15px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        padding: 0 !important;
        width: 100% !important;
        display: block !important;
        visibility: visible !important;
    }

    .card h2 {
        font-size: 18pt !important;
        color: #0f4c3a !important;
        margin-bottom: 15px !important;
        border-bottom: 2px solid #0f4c3a !important;
        padding-bottom: 8px !important;
        page-break-after: avoid !important;
    }

    .card h3 {
        font-size: 14pt !important;
        color: #0f4c3a !important;
        margin: 15px 0 10px 0 !important;
        page-break-after: avoid !important;
    }

    /* Results Grid */
    .results-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
        page-break-inside: avoid !important;
        width: 100% !important;
    }

    .result-card {
        background: white !important;
        border: 2px solid #0f4c3a !important;
        padding: 12px !important;
        border-radius: 8px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .result-label {
        color: #666 !important;
        font-size: 10pt !important;
        font-weight: 600 !important;
        margin-bottom: 5px !important;
    }

    .result-value {
        color: #0f4c3a !important;
        font-size: 16pt !important;
        font-weight: 700 !important;
    }

    /* Special styling for Total Monthly Payment card */
    .result-card:has(#totalMonthlyPayment) {
        background: #0f4c3a !important;
        border: 2px solid #0f4c3a !important;
        grid-column: 1 / -1 !important;
    }

    .result-card:has(#totalMonthlyPayment) .result-label {
        color: white !important;
        font-size: 12pt !important;
    }

    .result-card:has(#totalMonthlyPayment) .result-value {
        color: #ffffff !important;
        font-size: 20pt !important;
    }

    .result-card:has(#monthlyPI) .result-label,
    .result-card:has(#monthlyPI) .result-value {
        color: #d4af37 !important;
    }

    /* Comparison cards */
    .comparison-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 15px !important;
        margin: 15px 0 !important;
        page-break-inside: avoid !important;
    }

    .comparison-card {
        background: white !important;
        border: 2px solid #0f4c3a !important;
        padding: 12px !important;
        border-radius: 8px !important;
    }

    .comparison-card h3 {
        color: #0f4c3a !important;
        font-size: 12pt !important;
        margin-bottom: 10px !important;
        border-bottom: 1px solid #0f4c3a !important;
        padding-bottom: 5px !important;
    }

    .comparison-item {
        padding: 5px 0 !important;
        border-bottom: 1px dotted #ddd !important;
        display: flex !important;
        justify-content: space-between !important;
    }

    .comparison-label {
        color: #666 !important;
        font-size: 9pt !important;
    }

    .comparison-value {
        color: #0f4c3a !important;
        font-size: 10pt !important;
        font-weight: 700 !important;
    }

    /* Beautiful title - SHOW them */
    .beautiful-title {
        display: block !important;
        font-size: 14pt !important;
        color: #0f4c3a !important;
        margin: 20px 0 10px 0 !important;
        padding-bottom: 5px !important;
        border-bottom: 2px solid #0f4c3a !important;
        page-break-after: avoid !important;
    }

    /* Chart details */
    .chart-detail-item {
        display: flex !important;
        justify-content: space-between !important;
        padding: 8px 0 !important;
        border-bottom: 1px dotted #ddd !important;
    }

    .chart-detail-label {
        color: #666 !important;
        font-size: 10pt !important;
    }

    .chart-detail-value {
        color: #0f4c3a !important;
        font-size: 10pt !important;
        font-weight: 700 !important;
    }

    /* SIMPLIFIED TABLE - Minimal styles for fast loading */
    .table-container {
        margin-top: 15px !important;
        page-break-before: auto !important;
    }

    .table-wrapper {
        overflow: visible !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 6pt !important;
    }

    th {
        background: #0f4c3a !important;
        color: white !important;
        padding: 4px 2px !important;
        font-size: 6pt !important;
        border: 1px solid #000 !important;
    }

    td {
        border: 1px solid #ccc !important;
        padding: 3px 2px !important;
        font-size: 6pt !important;
    }

    /* Remove all transitions and animations for faster rendering */
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
        box-shadow: none !important;
    }

    /* Prevent widows and orphans */
    p,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        orphans: 3;
        widows: 3;
        page-break-after: avoid !important;
    }
}

:root[data-theme="dark"] .savings-card {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.12) 0%, rgba(212, 175, 55, 0.05) 100%);
    border-color: rgba(251, 191, 36, 0.25);
}

/* ==================== ANIMATED COUNTER ==================== */
.counter-animate {
    display: inline-block;
}

/* ==================== CHART CARD ICONS ==================== */
.chart-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-right: 6px;
}

/* ==================== DISCLAIMER BOX ==================== */
.disclaimer-box {
    color: var(--text-dark);
    line-height: 1.8;
    margin-top: 30px;
    font-size: clamp(12px, 2vw, 14px);
    text-align: center;
    padding: 15px;
    background: #f0f9ff;
    border-radius: 8px;
    border: 1px solid #bae6fd;
    transition: all 0.3s ease;
}

:root[data-theme="dark"] .disclaimer-box {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-dark);
}

/* ==================== EXPORT BUTTONS ==================== */
.export-group {
    display: flex;
    gap: 12px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    text-decoration: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn-export:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.btn-pdf {
    background: linear-gradient(135deg, #d97706, #b45309);
}

.btn-csv {
    background: linear-gradient(135deg, #0f4c3a, #0a3d2e);
}

.btn-export svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ==================== HOME AFFORDABILITY MODULE CSS ==================== */
#afford-module {
    display: none !important;
    margin-top: 20px;
    animation: fadeIn 0.5s ease-out;
}

#afford-module.afford-visible {
    display: block !important;
}

.afford-calc-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 16px;
    font-weight: 700;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(15, 76, 58, 0.3);
    letter-spacing: 0.5px;
}

.afford-calc-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(15, 76, 58, 0.4);
}

.afford-calc-btn:active {
    transform: translateY(0);
}

/* Affordability Input Wrappers (independent from main calc) */
#afford-module .input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#afford-module .input-prefix {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-weight: 600;
    font-size: 15px;
    z-index: 2;
    pointer-events: none;
}

#afford-module .input-wrapper input[type="number"] {
    width: 100%;
}

#afford-module .input-prefix~input {
    padding-left: 36px !important;
}

#afford-module .input-suffix {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-weight: 600;
    font-size: 14px;
    pointer-events: none;
}

/* DTI Color Indicator */
.afford-dti-meaning {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    margin-left: 8px;
    letter-spacing: 0.5px;
}

.afford-dti-low {
    background: rgba(52, 211, 153, 0.15);
    color: #059669;
}

.afford-dti-mid {
    background: rgba(251, 191, 36, 0.15);
    color: #d97706;
}

.afford-dti-high {
    background: rgba(248, 113, 113, 0.15);
    color: #dc2626;
}

.afford-dti-desc {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
    font-weight: 400;
}

#afford_dti_slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    margin-top: 8px;
    background: linear-gradient(to right, #d97706 49%, #e2e8f0 49%);
}

#afford_dti_slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

#afford_dti_slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

#afford_dti_slider::-moz-range-track {
    height: 8px;
    border-radius: 4px;
    background: transparent;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.afford-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 24px;
    align-items: start;
}

#afford-module>.loan-selector {
    grid-template-columns: 1fr 1.2fr;
    gap: 24px;
}


@media (max-width: 1100px) {

    .afford-grid,
    #afford-module>.loan-selector {
        grid-template-columns: 1fr;
    }
}

.afford-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.afford-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    color: var(--primary-dark);
}

.afford-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.afford-input-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 600px) {
    .afford-input-group {
        grid-template-columns: 1fr;
    }
}

.afford-result-display {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 20px;
    padding: 40px 30px;
    color: white;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(15, 76, 58, 0.15);
}

.afford-result-label {
    font-size: 16px;
    opacity: 0.9;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.afford-result-value {
    font-size: 3.5rem;
    font-weight: 800;
    font-family: 'DM Sans', sans-serif;
    margin-bottom: 10px;
}

.afford-breakdown-mini {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-top: 30px;
    padding-top: 25px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.afford-breakdown-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.afford-breakdown-label {
    font-size: 12px;
    opacity: 0.8;
}

.afford-breakdown-val {
    font-weight: 700;
    font-size: 15px;
}

.afford-wow-box {
    background: rgba(251, 191, 36, 0.08);
    border: 1px dashed var(--accent);
    border-radius: 16px;
    padding: 20px;
    margin-top: 24px;
    display: none;
    align-items: center;
    gap: 15px;
    animation: pulseAfford 2s infinite;
}

@keyframes pulseAfford {
    0% {
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.2);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(251, 191, 36, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0);
    }
}

.afford-mode-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px auto 40px;
    background: var(--card-bg);
    padding: 8px;
    border-radius: 50px;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 600px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    position: relative;
    z-index: 10;
}

.afford-mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 48px;
    padding: 0 16px;
    border-radius: 35px;
    border: none;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
    gap: 8px;
    white-space: nowrap;
    transform: translateZ(0);
}

.afford-mode-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 20px rgba(15, 76, 58, 0.25);
}

:root[data-theme="dark"] .afford-card {
    background: #1e293b;
    border-color: #334155;
}

:root[data-theme="dark"] .afford-mode-selector {
    background: #1e293b;
    border-color: #334155;
}

:root[data-theme="dark"] .afford-mode-btn.active {
    box-shadow: 0 2px 20px rgba(52, 211, 153, 0.3);
}

@media (max-width: 768px) {
    .afford-mode-selector {
        grid-template-columns: repeat(3, 1fr);
        border-radius: 20px;
        padding: 8px;
        gap: 5px;
    }

    .afford-mode-btn {
        height: 44px;
        border-radius: 12px;
        font-size: 11px;
        padding: 0 4px;
        gap: 4px;
    }

    .hide-mobile {
        display: none;
    }
}

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

/* ==================== NON-CRITICAL CSS (DARK MODE & PRINT) ==================== */
@media print {
    body {
        background: white !important;
        padding: 0 !important;
        color: black !important;
    }

    header,
    .ad-space,
    .btn-calculate,
    .export-group,
    .hero,
    .seo-content-area,
    .back-to-top,
    .theme-toggle,
    #chartFallback {
        display: none !important;
    }

    .container {
        padding: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #eee !important;
        break-inside: avoid;
        padding: 20px !important;
        margin-bottom: 20px !important;
    }

    /* Ensure tables are visible and not truncated */
    .table-container,
    .table-wrapper {
        overflow: visible !important;
        max-height: none !important;
        height: auto !important;
        display: block !important;
    }

    table {
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: collapse !important;
        table-layout: auto !important;
    }

    table th {
        background-color: #0f4c3a !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Simplify table for print by hiding less important columns */
    /* For table WITH prepayments: hide Paid%, Remain%, Yr, Rate */
    #scheduleBody tr td:nth-child(7),
    #scheduleBody tr td:nth-child(8),
    #scheduleBody tr td:nth-child(10),
    #scheduleBody tr td:nth-child(11),
    #scheduleBody tr~thead th:nth-child(7),
    #scheduleBody tr~thead th:nth-child(8),
    #scheduleBody tr~thead th:nth-child(10),
    #scheduleBody tr~thead th:nth-child(11),
    table:has(#scheduleBody) thead th:nth-child(7),
    table:has(#scheduleBody) thead th:nth-child(8),
    table:has(#scheduleBody) thead th:nth-child(10),
    table:has(#scheduleBody) thead th:nth-child(11) {
        display: none !important;
    }

    /* For table WITHOUT prepayments: hide Paid%, Remain%, Yr, Rate */
    #scheduleBodyNoPrepayment tr td:nth-child(7),
    #scheduleBodyNoPrepayment tr td:nth-child(8),
    #scheduleBodyNoPrepayment tr td:nth-child(9),
    #scheduleBodyNoPrepayment tr td:nth-child(10),
    table:has(#scheduleBodyNoPrepayment) thead th:nth-child(7),
    table:has(#scheduleBodyNoPrepayment) thead th:nth-child(8),
    table:has(#scheduleBodyNoPrepayment) thead th:nth-child(9),
    table:has(#scheduleBodyNoPrepayment) thead th:nth-child(10) {
        display: none !important;
    }

    /* Rename label in print report only */
    #interestSavedLabel::after {
        content: ' by Prepays' !important;
    }

    .charts-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 30px !important;
        width: 100% !important;
    }

    .chart-card {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        padding: 15px !important;
        border: 1px solid #eee !important;
        display: block !important;
    }

    /* Chart container sizing for print - do NOT override canvas dimensions */
    /* Chart.js handles canvas sizing internally via maintainAspectRatio */
    .chart-container {
        width: 100% !important;
        max-width: 400px !important;
        margin: 0 auto !important;
        display: block !important;
        overflow: visible !important;
        position: relative !important;
    }
}

:root[data-theme="dark"] {
    --primary: #34d399;
    --primary-light: #6ee7b7;
    --primary-dark: #059669;
    --accent: #fbbf24;
    --accent-light: #fcd34d;
    --secondary: #1e293b;
    --background: #0f172a;
    --card-bg: #1e293b;
    --text-dark: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --chart-principal: #34d399;
    --chart-interest: #f59e0b;
    --chart-balance-line: #f87171;
    --chart-prepayment: #10b981;
    --chart-total-prepayment: #a78bfa;
}

:root[data-theme="dark"] body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

:root[data-theme="dark"] header {
    background: #1e293b;
    border-bottom-color: #334155;
}

:root[data-theme="dark"] .result-card {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.15) 0%, rgba(16, 185, 129, 0.08) 100%);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] input[type="date"],
:root[data-theme="dark"] select {
    background: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

/* --- Performance Optimizations for Mobile --- */
@media (max-width: 768px) {
    .savings-card.pulse {
        animation: none !important;
    }

    .result-card:hover,
    .btn-calculate:hover,
    .loan-type-btn:hover {
        transform: none !important;
    }

    /* Reduce transition overhead on mobile */
    * {
        transition-duration: 0.15s !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* --- COMMON SEO & UTILITY STYLES --- */

/* Responsive SEO Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.table-responsive table {
    min-width: 500px;
    /* Force scroll on small screens */
    width: 100%;
    border-collapse: collapse;
}

/* Mobile specific spacing for SEO tables */
@media (max-width: 600px) {

    .expert-block table th,
    .expert-block table td {
        padding: 8px 10px;
        /* Reduced padding */
        font-size: 13px;
    }

    .expert-block h2,
    .expert-block h3 {
        font-size: 1.1rem;
    }
}

/* Decorative Heading Style */
.seo-heading-decorated {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    margin-bottom: 20px;
}

.seo-heading-decorated::before {
    content: '';
    width: 5px;
    height: 1.2em;
    background: linear-gradient(180deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 4px;
    display: inline-block;
    vertical-align: middle;
}

/* Adjust expert blocks for the new line decoration */
.expert-block h2,
.expert-block h3 {
    display: flex;
    align-items: center;
    gap: 12px;
}

.expert-block h2::before,
.expert-block h3::before {
    content: '';
    width: 5px;
    height: 1.2em;
    background: linear-gradient(180deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 4px;
    display: inline-block;
}

/* === SHARED NAVIGATION - MortgagePayoffPlanner ===
   Nav HTML is baked into each page statically - no CLS.
   ================================================== */

header.legacy-header, .header-content { display: none !important; }
.afford-mode-selector { display: none !important; }

:root {
  --nv-green:     #0f4c3a;
  --nv-gold:      #d4af37;
  --nv-top-muted: rgba(255,255,255,0.65);
  --nv-sub-bg:    #f8faf9;
  --nv-sub-bdr:   #e2e8e5;
  --nv-sub-muted: #6b7280;
  --nv-sub-hover: #f0fdf4;
  --nv-sub-act:   #0f4c3a;
}

header.nv { position: sticky; top: 0; z-index: 200; box-shadow: 0 2px 12px rgba(0,0,0,0.12); }

.nv-top { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); height: 58px; display: flex; align-items: center; }
.nv-top-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; width: 100%;
}
.nv-logo {
  font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 700;
  color: #fff; text-decoration: none; white-space: nowrap;
  flex-shrink: 0; margin-right: 8px; letter-spacing: -0.01em;
}
.nv-logo span { color: var(--nv-gold); }
.nv-logo-sep {
  width: 1px; height: 22px; background: rgba(255,255,255,0.15);
  flex-shrink: 0; margin: 0 12px 0 4px;
}
.nv-top-nav { display: flex; align-items: stretch; flex: 1; }
.nv-top-item { position: relative; }
.nv-top-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 0 13px; height: 58px;
  background: transparent; border: none;
  color: var(--nv-top-muted);
  font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: inset 0 -3px 0 transparent;
}
.nv-top-btn:hover { color: #fff; box-shadow: inset 0 -3px 0 rgba(255,255,255,0.25); }
.nv-top-btn.active { color: #fff; box-shadow: inset 0 -3px 0 var(--nv-gold); }

/* Hover preview - instant, pure CSS */
.nv-preview {
  position: absolute; top: 100%; left: 0;
  background: #fff; border: 1px solid #e0ebe5;
  border-top: 3px solid var(--nv-green);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.12);
  padding: 14px 16px 12px;
  display: none; z-index: 400;
  width: auto; white-space: nowrap;
}
.nv-top-item:hover .nv-preview { display: block; }
.nv-preview.wide { width: 300px; white-space: normal; }

.nv-preview-title {
  font-family: 'DM Sans', sans-serif; font-size: 10px; font-weight: 700;
  color: var(--nv-green); text-transform: uppercase; letter-spacing: 1.3px;
  margin-bottom: 8px; padding-bottom: 7px; border-bottom: 1px solid #e8f0ec;
}
.nv-preview-grid { display: grid; gap: 2px; grid-template-columns: 1fr; }
.nv-preview-grid.g2 { grid-template-columns: 1fr 1fr; }
.nv-preview-grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.nv-preview-grid a {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; color: #374151; text-decoration: none;
  font-family: 'DM Sans', sans-serif; font-size: 13px;
  border-radius: 5px; white-space: nowrap;
}
.nv-preview-grid a:hover { background: var(--nv-sub-hover); color: var(--nv-green); }

/* Hamburger */
.nv-ham {
  display: none; align-items: center; gap: 7px; margin-left: auto;
  padding: 6px 10px; border: none; background: rgba(255,255,255,0.1);
  border-radius: 6px; color: rgba(255,255,255,0.9);
  font-family: 'DM Sans', sans-serif; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.nv-ham-lines { display: flex; flex-direction: column; gap: 4px; }
.nv-ham-lines span { display: block; width: 16px; height: 1.5px; background: rgba(255,255,255,0.9); border-radius: 2px; }

/* Sub-bar */
/* ══════════════════════════════════════════════════
   SUBHEADER TOGGLE
   ══════════════════════════════════════════════════
   SHOW_SUBHEADER = true   → sub-bar visible (default)
   SHOW_SUBHEADER = false  → sub-bar hidden everywhere

   To change: edit the ONE line marked below.
   CSS is sync → zero CLS, no flash on any page.
   ══════════════════════════════════════════════════ */

/* SHOW_SUBHEADER = true ← change "flex" to "none" to set false */
.nv-sub-bar { display: flex; }
.nv-sub-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; overflow-x: auto;
  scrollbar-width: none; width: 100%;
}
.nv-sub-inner::-webkit-scrollbar { display: none; }
.nv-sub-panel { display: none; align-items: center; gap: 2px; flex-wrap: nowrap; }
.nv-sub-panel.nv-sub-active { display: flex; }
.nv-sub-link {
  display: inline-flex; align-items: center; padding: 7px 13px;
  color: var(--nv-sub-muted); text-decoration: none;
  font-family: 'DM Sans', sans-serif; font-size: 12.5px; font-weight: 500;
  white-space: nowrap; border-radius: 5px;
  box-shadow: inset 0 -2px 0 transparent;
}
.nv-sub-link:hover { color: var(--nv-sub-act); background: var(--nv-sub-hover); }
.nv-sub-link.active { color: var(--nv-sub-act); font-weight: 600; box-shadow: inset 0 -2px 0 var(--nv-gold); }

/* Mobile bottom tab bar */
.nv-mob-tabbar {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  height: 64px; background: var(--primary-dark, #092e23); border-top: none;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.15); z-index: 600;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nv-mob-tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: transparent; border: none; cursor: pointer;
  padding: 8px 4px 10px; color: rgba(255,255,255,1);
  font-family: 'DM Sans', sans-serif; font-size: 10px; font-weight: 600;
  position: relative;
}
.nv-mob-tab .tab-emoji { font-size: 22px; line-height: 1; display: block; margin-top: 2px; }
.nv-mob-tab.active::after {
  content: '';
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  border-radius: 2px;
  background: var(--nv-gold, #d4af37);
}


/* Sheet */
.nv-sheet {
  display: none; position: fixed; left: 0; right: 0; bottom: 64px;
  top: auto; max-height: 82vh;
  background: #fff; z-index: 550; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
  border-top: 3px solid var(--nv-green);
}
.nv-sheet.open { display: block; }
.nv-sheet-handle {
  width: 40px; height: 4px; background: #d1d5db;
  border-radius: 2px; margin: 10px auto 0;
}
.nv-sheet-header {
  position: sticky; top: 0; background: #fff;
  border-bottom: 1px solid #f0ebe0; padding: 12px 20px 14px;
  display: flex; align-items: center; justify-content: space-between; z-index: 10;
}
.nv-sheet-title { font-family: 'DM Sans', sans-serif; font-size: 16px; font-weight: 700; color: #111827; }
.nv-sheet-close {
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: #f3f4f6; color: #6b7280;
  font-size: 14px; cursor: pointer; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.nv-sheet-close:hover { background: #fee2e2; color: #dc2626; }
.nv-sheet-group-hdr {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px 6px;
  font-family: 'DM Sans', sans-serif; font-size: 11px; font-weight: 700;
  color: var(--nv-green); text-transform: uppercase; letter-spacing: 0.06em;
  background: #f8faf9; border-top: 1px solid #f0ebe0;
}
.nv-sheet-group-hdr .sh-e { font-size: 16px; }
.nv-sheet-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  color: #374151; text-decoration: none;
  font-family: 'DM Sans', sans-serif; font-size: 14px;
  border-bottom: 1px solid #f5f0e8;
}
.nv-sheet-link:hover { background: #f9fdf9; color: var(--nv-green); }
.nv-sheet-link .sh-e { font-size: 18px; flex-shrink: 0; width: 26px; text-align: center; }
.nv-sheet-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 540;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.nv-sheet-overlay.open { display: block; }

@media (max-width: 860px) {
  .nv-top-nav { display: none; }
  .nv-ham     { display: flex; }
  .nv-sub-bar { display: none; }
  .nv-mob-tabbar { display: flex; }
  body { padding-bottom: 64px; }
}

/* === ACCORDION SHEET (mobile More/hamburger) === */
/* Group header row */
.nv-acc-hdr {
  display: flex;
  align-items: center;
  border-top: 1px solid #f0ebe0;
  background: #f8faf9;
  cursor: pointer;
  user-select: none;
}
/* Nav label — fills space, navigates on tap */
.nv-acc-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 0 13px 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--nv-green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.nv-acc-nav-btn .sh-e { font-size: 17px; }
/* Chevron — right side, only toggles expand */
.nv-acc-toggle {
  padding: 13px 20px 13px 12px;
  font-size: 20px;
  font-weight: 400;
  color: var(--nv-gold);
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}
/* Direct link headers (no subs) — span full row */
.nv-acc-hdr.nv-acc-direct .nv-acc-nav-btn {
  padding-right: 20px;
}
/* Sub-links body — hidden by default */
.nv-acc-body {
  display: none;
  background: #fff;
}
.nv-acc-body.open { display: block; }
.nv-acc-body .nv-sheet-link {
  padding-left: 32px;
  font-size: 13.5px;
}
.nv-acc-body .nv-sheet-link .sh-e {
  font-size: 16px;
  width: 24px;
}

/* === FONT METRIC OVERRIDES — eliminate nav height shift on font load ===
   These @font-face rules make the fallback fonts (Arial, Georgia) match
   the metrics of DM Sans and Playfair Display exactly.
   Result: zero visual shift when web fonts swap in. */

@font-face {
  font-family: 'DM Sans Fallback';
  src: local('Arial');
  ascent-override:  94%;
  descent-override: 24%;
  line-gap-override: 0%;
  size-adjust: 100%;
}

@font-face {
  font-family: 'Playfair Display Fallback';
  src: local('Georgia');
  ascent-override:  82%;
  descent-override: 21%;
  line-gap-override: 0%;
  size-adjust: 103%;
}

/* Use overridden fallbacks in nav elements */
.nv-logo {
  font-family: 'Playfair Display', 'Playfair Display Fallback', serif;
  /* Fixed line-height prevents any font metric from stretching the bar */
  line-height: 1;
}
.nv-top-btn,
.nv-sub-link,
.nv-ham,
.nv-mob-tab,
.nv-preview-grid a,
.nv-sheet-link,
.nv-acc-nav-btn,
.nv-sheet-title,
.nv-sheet-group-hdr {
  font-family: 'DM Sans', 'DM Sans Fallback', sans-serif;
  line-height: 1;
}

/* Lock the top bar to EXACTLY 58px regardless of font metrics */
.nv-top {
  min-height: 58px;
  max-height: 58px;
}
/* Lock sub-bar to exactly 40px */
.nv-sub-bar {
  min-height: 40px;
  max-height: 40px;
}
/* Lock mob tab bar height */

/* === NAV TEXT COLOR FIXES ===
   Unselected: readable white (0.88 opacity, not 0.65)
   Active:     pure white + subtle bright tint on background
   Hover:      pure white */
:root {
  --nv-top-muted: rgba(255,255,255,0.88);
}
.nv-top-btn {
  color: rgba(255,255,255,0.88);
}
.nv-top-btn:hover {
  color: #ffffff;
  box-shadow: inset 0 -3px 0 rgba(255,255,255,0.3);
}
/* Active: pure white + very subtle brighter green tint on background */
.nv-top-btn.active {
  color: #ffffff;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 -3px 0 var(--nv-gold);
}

/* === BOTTOM TAB BAR: subtle green-tinted background === */
/* Active tab: green text (already set) — add stronger indicator */

/* === MORE BUTTON: SVG icon sizing === */
.nv-more-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  margin-top: 2px;
  color: currentColor;
}
.nv-more-icon svg {
  display: block;
}

/* === ACCORDION: wider + tap area for toggle (25% of row) === */
.nv-acc-hdr {
  /* row height fixed so tap zones are consistent */
  min-height: 52px;
}
.nv-acc-nav-btn {
  /* takes ~75% of the row */
  flex: 3;
  min-height: 52px;
}
.nv-acc-toggle {
  /* takes ~25% of the row, centred */
  flex: 0 0 25%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 22px;
  /* visible tap boundary */
  border-left: 1px solid #f0ebe0;
}

/* === MORE BUTTON SVG - explicit colors, no currentColor inheritance === */
.nv-more-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
}
.nv-more-svg {
  display: block;
  overflow: visible;
}
.nv-more-line {
  fill: #9ca3af;
}
/* Active tab: green lines */
/* Non-more tabs: hide the icon class */
.nv-mob-tab:not(#nvMoreTab) .nv-more-icon {
  display: none;
}

/* === BOTTOM TAB BAR: use --primary-dark background (matches brand) === */

/* Tabs: white text on dark background */
.nv-mob-tab.active {
  color: #ffffff;
}
.nv-mob-tab.active::after {
  background: var(--nv-gold, #d4af37);
}
/* More icon: white on dark */
.nv-more-line {
  fill: rgba(255,255,255,0.6) !important;
}
.nv-mob-tab.active .nv-more-line {
  fill: #ffffff !important;
}

/* ================================================================
   FINAL OVERRIDES — accordion layout + tab brightness
   These sit at end of file to win the cascade cleanly.
   ================================================================ */

/* --- Accordion header: proper flex row, no button artifacts --- */
.nv-acc-hdr {
  display: flex !important;
  align-items: stretch !important;
  overflow: hidden !important;
  min-height: 52px;
  background: #f8faf9;
  border-top: 1px solid #e8ede9;
}
.nv-acc-nav-btn {
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none !important;
  outline: none;
  border: none !important;
  border-radius: 0;
  flex: 1 1 75% !important;
  min-width: 0;
  display: flex !important;
  align-items: center !important;
  padding: 0 12px 0 20px;
  min-height: 52px;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--nv-green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: transparent !important;
  cursor: pointer;
  text-align: left;
}
.nv-acc-toggle {
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none !important;
  outline: none;
  border: none !important;
  border-left: 1px solid #e8ede9 !important;
  border-radius: 0;
  flex: 0 0 25% !important;
  width: 25%;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  min-height: 52px;
  font-size: 22px;
  font-weight: 300;
  color: var(--nv-gold);
  background: #f8faf9 !important;
  cursor: pointer;
}

/* --- Bottom tabs: FULL brightness on dark background --- */

.nv-more-line {
  fill: rgba(255,255,255,1) !important;
}

/* === SHARED FOOTER ===
   footer-content is already styled (max-width, text-align, color).
   These add the link cloud and remove Made with heart. */
.footer-tagline {
    margin-top: 8px;
    font-size: 12px;
    opacity: 0.7;
}
.footer-links {
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 20px;
    font-size: 12px;
}
.footer-links a {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    transition: color 0.15s;
}
.footer-links a:hover {
    color: var(--accent, #d4af37);
    text-decoration: underline;
}

/* === FOOTER LINKS: always white, all states, no purple visited === */
.footer-links a,
.footer-links a:link,
.footer-links a:visited,
.footer-links a:active,
.footer-links a:hover {
  color: rgba(255,255,255,0.85) !important;
  text-decoration: none;
}
.footer-links a:hover {
  text-decoration: underline;
  opacity: 0.7;
}


/* ==================== INVEST VS PREPAY / PAY DEBT OR INVEST ==================== */

/* Two-column layout: left=inputs, right=results */
.app-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    align-items: start;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.app-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .app-section {
        grid-template-columns: 1fr;
    }
}

.results-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Card header */
.card-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    margin-bottom: 0;
}

/* Input prefix/suffix */
.prefix {
    position: absolute;
    left: 14px;
    color: var(--text-light);
    font-weight: 700;
    pointer-events: none;
    z-index: 1;
    top: 50%;
    transform: translateY(-50%);
}

.suffix {
    position: absolute;
    right: 14px;
    color: var(--text-light);
    font-weight: 700;
    pointer-events: none;
    z-index: 1;
    top: 50%;
    transform: translateY(-50%);
}

.with-prefix {
    padding-left: 30px !important;
}

.with-suffix {
    padding-right: 35px !important;
}

/* Toggle switch */
.toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    background: rgba(15, 76, 58, 0.05);
    padding: 12px 15px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.toggle-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Validation error */
.validation-error {
    background: #fff5f5;
    color: #c53030;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 15px;
    border-left: 4px solid #f56565;
    display: none;
}

/* Chart loading spinner */
#chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(15, 76, 58, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

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

/* Recommendation banner */
.recommendation-banner {
    background: linear-gradient(135deg, #fef3c7 0%, #fff7ed 100%);
    border: 2px solid var(--accent);
    border-radius: 16px;
    padding: 25px;
    text-align: center;
}

.recommendation-banner h2 {
    color: var(--accent);
    font-family: 'Playfair Display', serif;
}

.recommendation-banner h2::before {
    display: none;
}

/* Prepay / Invest comparison cards */
.prepay-card {
    border: 2px solid var(--primary-light);
    background: linear-gradient(135deg, var(--card-bg) 0%, rgba(16, 185, 129, 0.02) 100%);
}

.invest-card {
    border: 2px solid #d4af37;
    background: linear-gradient(135deg, var(--card-bg) 0%, rgba(212, 175, 55, 0.02) 100%);
}

.comparison-card h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Playfair Display', serif;
    font-size: 20px;
    margin-bottom: 20px;
}

.comparison-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.comparison-item:last-child {
    border-bottom: none;
}

.comparison-label {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    font-weight: 500;
}

.comparison-value {
    font-weight: 700;
    color: #ffffff;
    font-size: 16px;
}

/* SEO content sections */
.seo-section {
    margin-top: 60px;
    padding: 40px;
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid var(--border);
    line-height: 1.7;
}

@media (max-width: 768px) {
    .seo-section {
        padding: 20px 15px;
    }
}

.seo-section h2 {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 25px;
    text-align: center;
    position: relative;
}

.seo-section h2::after {
    content: '';
    display: block;
    width: 50px;
    height: 2px;
    background: var(--accent);
    margin: 10px auto 0;
    border-radius: 1px;
}

.comparison-table-wrapper {
    overflow-x: auto;
    margin: 30px 0;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.seo-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

.seo-table th {
    background: var(--primary);
    color: white;
    padding: 12px 15px;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
}

.seo-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.faq-item {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.faq-question {
    font-weight: 700;
    font-size: 17px;
    color: var(--primary-dark);
    display: block;
    margin-bottom: 10px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile: hide hero descriptions sitewide */
@media (max-width: 768px) {
  .hero p {
    display: none !important;
  }
}

/* Mobile-friendly dropdown optimization (Opt-in) */
.mobile-select-custom-fitness {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%230f4c3a' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C2.185 5.355 2.402 5 2.808 5h9.384c.406 0 .623.355.358.658l-4.796 5.482a.5.5 0 0 1-.727 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding-right: 48px !important;
    font-size: 16px !important; /* Prevents iOS auto-zoom */
    cursor: pointer;
}