/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --background-color: #f8fafc;
    --card-background: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --principal-color: #2563eb;
    --interest-color: #f59e0b;
}

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

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
}

header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

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

/* Main Content */
main {
    flex: 1;
}

/* Calculator Section */
.calculator-section {
    background: var(--card-background);
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-background);
    color: var(--text-primary);
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group input::placeholder {
    color: var(--secondary-color);
}

.calculate-btn {
    width: 100%;
    padding: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    margin-top: 10px;
}

.calculate-btn:hover {
    background: var(--primary-hover);
}

.calculate-btn:active {
    transform: scale(0.98);
}

/* Results Section */
.results-section {
    background: var(--card-background);
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
    display: none;
}

.results-section.visible {
    display: block;
    animation: fadeIn 0.3s ease;
}

.results-section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 30px;
}

.result-card {
    background: var(--background-color);
    padding: 20px;
    border-radius: var(--radius-md);
    text-align: center;
}

.result-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Chart Container */
.chart-container {
    text-align: center;
    padding: 20px 0;
}

.chart-container h3 {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.donut-chart {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin: 0 auto 20px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-center {
    position: absolute;
    background: var(--card-background);
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chart-total {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.legend-color.principal {
    background: var(--principal-color);
}

.legend-color.interest {
    background: var(--interest-color);
}

/* Amortization Section */
.amortization-section {
    background: var(--card-background);
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
    display: none;
}

.amortization-section.visible {
    display: block;
    animation: fadeIn 0.3s ease;
}

.amortization-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.amortization-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.toggle-btn {
    padding: 10px 20px;
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.toggle-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.amortization-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 600px;
}

.amortization-table th {
    background: var(--background-color);
    padding: 14px 12px;
    text-align: right;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.amortization-table th:first-child,
.amortization-table td:first-child {
    text-align: center;
}

.amortization-table th:nth-child(2),
.amortization-table td:nth-child(2) {
    text-align: left;
}

.amortization-table td {
    padding: 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.amortization-table tbody tr:hover {
    background: var(--background-color);
}

.amortization-table tbody tr:last-child td {
    border-bottom: none;
}

.amortization-table tbody tr.year-marker {
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--primary-color) 100%);
    background-size: 4px 100%;
    background-repeat: no-repeat;
}

.amortization-table tbody tr.year-marker td:first-child {
    font-weight: 600;
    color: var(--primary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .calculator-section,
    .results-section,
    .amortization-section {
        padding: 20px;
    }

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

    .result-card {
        padding: 16px;
    }

    .result-value {
        font-size: 1.3rem;
    }

    .amortization-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toggle-btn {
        width: 100%;
    }

    .chart-legend {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    .calculator-section,
    .results-section,
    .amortization-section {
        padding: 16px;
    }

    .input-group input,
    .input-group select {
        padding: 12px 14px;
    }

    .calculate-btn {
        padding: 14px;
        font-size: 1rem;
    }

    .donut-chart {
        width: 160px;
        height: 160px;
    }

    .chart-center {
        width: 96px;
        height: 96px;
    }

    .chart-total {
        font-size: 0.95rem;
    }
}

/* Print Styles */
@media print {
    .calculate-btn,
    .toggle-btn {
        display: none;
    }

    .container {
        max-width: 100%;
    }

    .calculator-section,
    .results-section,
    .amortization-section {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }

    .amortization-table {
        font-size: 0.8rem;
    }
}
