/* Google Font Import */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

/* CSS Variables for Theming */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --bg-color: #f8f9fa;
    --card-bg-color: #ffffff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font-family: 'Poppins', sans-serif;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --card-bg-color: #1e1e1e;
    --text-color: #e0e0e0;
    --border-color: #333;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* --- MOBILE FIRST BASE STYLES --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 100%;
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

/* ⬇️ HEADER & FOOTER UPDATED HERE ⬇️ */
header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--card-bg-color);
}

.home-link {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s;
}

.home-link:hover {
    color: var(--text-color);
}

.header-title-group {
    flex-basis: 100%;
    order: -1;
    /* Move to the top on mobile */
    text-align: center;
}

header h1 {
    color: var(--primary-color);
    font-size: 1.4rem;
    margin: 0;
}

.powered-by {
    font-size: 0.8rem;
    color: var(--secondary-color);
    margin: 0;
}

footer {
    text-align: center;
    padding: 1.5rem 1rem;
    background-color: var(--card-bg-color);
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}

.disclaimer {
    font-size: 0.8rem;
    color: var(--secondary-color);
    margin-top: 0.5rem;
}

/* Theme Switcher */
.theme-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ... other styles remain the same ... */

/* Generic Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

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

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

.slider.round {
    border-radius: 28px;
}

.slider.round:before {
    border-radius: 50%;
}

.switch.small {
    width: 40px;
    height: 22px;
}

.switch.small .slider:before {
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
}

input:checked+.switch.small .slider:before {
    transform: translateX(18px);
}

/* Card Styles */
.calculator-card,
.results-card {
    background-color: var(--card-bg-color);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

h2 {
    margin-bottom: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.25rem;
}

/* Form */
.mode-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.input-group,
.inflation-section {
    margin-bottom: 1.5rem;
}

.input-group label,
.inflation-section>label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.input-group input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.input-group input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.input-with-slider input[type="range"] {
    width: 100%;
    margin-top: 0.75rem;
    cursor: pointer;
}

.inflation-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

#inflationRateContainer {
    flex-basis: 100%;
    margin-top: 1rem;
}

/* Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    width: 100%;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #fff;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: #fff;
}

/* Results */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

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

.result-item p {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-bottom: 0.25rem;
}

.result-item h3 {
    font-weight: 600;
    font-size: 1.2rem;
}

#maturityValue {
    color: var(--success-color);
}

#goalStatus.surplus {
    color: var(--success-color);
}

#goalStatus.shortfall {
    color: var(--danger-color);
}

/* Charts & Table */
.charts-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-wrapper {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 8px;
}

.chart-wrapper h3,
.table-container h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-weight: 500;
    font-size: 1.1rem;
}

.table-container {
    overflow-x: auto;
}

#amortizationTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

#amortizationTable th,
#amortizationTable td {
    padding: 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

#amortizationTable thead {
    background-color: var(--bg-color);
}

/* Export Buttons */
.export-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 2rem;
}

.btn-outline {
    background-color: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background-color: var(--primary-color);
    color: #fff;
}


/* --- TABLET & SMALLER DESKTOP STYLES (min-width: 768px) --- */
@media (min-width: 768px) {
    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 2rem 1.5rem;
    }

    /* ⬇️ HEADER UPDATED HERE ⬇️ */
    header {
        flex-wrap: nowrap;
        justify-content: space-between;
    }

    .header-title-group {
        flex-basis: auto;
        order: 0;
        /* Reset order */
    }

    header h1 {
        font-size: 1.75rem;
    }

    .action-buttons {
        flex-direction: row;
    }

    .export-buttons {
        flex-direction: row;
        justify-content: center;
    }

    .btn {
        width: auto;
    }

    .charts-container {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- LARGE DESKTOP STYLES (min-width: 992px) --- */
@media (min-width: 992px) {
    .container {
        grid-template-columns: 380px 1fr;
        gap: 2rem;
    }

    .results-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }

    .result-item h3 {
        font-size: 1.4rem;
    }
}

/* --- PRINT STYLES --- */
@media print {
    body {
        background-color: #fff;
        color: #000;
    }

    header,
    footer,
    .calculator-card,
    .export-buttons,
    .theme-switcher,
    .mode-selector {
        display: none;
    }

    main,
    .container,
    .results-card {
        all: unset;
    }

    .results-card {
        box-shadow: none;
    }

    .charts-container {
        grid-template-columns: 1fr !important;
    }

    #printableArea {
        margin: 0.5in;
    }

    .result-item {
        border: 1px solid #ccc;
    }

    a[href]:after {
        content: none !important;
    }

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