/* ===== CSS Variables ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --max-width: 900px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 16px;
}

/* ===== Header ===== */
.header {
    background: var(--card-bg);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 1.5rem;
}

.lang-switch {
    display: flex;
    align-items: center;
    gap: 4px;
}

.lang-btn {
    background: none;
    border: none;
    padding: 6px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    font-weight: 500;
}

.lang-btn.active {
    background: var(--primary);
    color: white;
}

.lang-btn:hover:not(.active) {
    background: var(--primary-light);
}

.lang-divider {
    color: var(--border);
}

/* ===== Ad Containers ===== */
.ad-container {
    margin: 20px auto;
    max-width: var(--max-width);
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.adsbygoogle {
    width: 100%;
    min-height: 90px;
    display: block;
}

.ad-container:empty {
    display: none;
}

/* ===== Calculator Section ===== */
.calculator-section {
    padding: 24px 0;
}

.calculator-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 24px;
}

.calculator-card h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    color: var(--text);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* ===== Form ===== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

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

.currency-symbol {
    position: absolute;
    left: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    z-index: 1;
}

.percent-symbol {
    position: absolute;
    right: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.input-wrapper input {
    padding-left: 28px;
}

input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s;
    background: white;
    color: var(--text);
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ===== Method Toggle ===== */
.method-toggle {
    display: flex;
    gap: 0;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.method-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.method-btn.active {
    background: var(--primary);
    color: white;
}

/* ===== Calculate Button ===== */
.calculate-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

/* ===== Results ===== */
.results-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.results-card h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.result-item {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.result-item.highlight {
    background: var(--primary);
    color: white;
    grid-column: span 2;
}

.result-item.highlight .result-label,
.result-item.highlight .result-value {
    color: white;
}

.result-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.result-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

/* ===== Chart ===== */
.chart-section {
    margin-bottom: 24px;
}

.chart-section h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.chart-bar {
    display: flex;
    height: 40px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 12px;
}

.chart-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: white;
    font-weight: 600;
    transition: width 0.5s ease;
}

.principal-segment {
    background: var(--primary);
}

.interest-segment {
    background: var(--accent);
}

.chart-legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

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

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

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

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

/* ===== Amortization Table ===== */
.amortization-section h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.table-wrapper.expanded {
    max-height: none;
}

.amortization-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.amortization-table thead {
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

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

.amortization-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

.toggle-schedule-btn {
    margin-top: 12px;
    padding: 8px 16px;
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.toggle-schedule-btn:hover {
    background: var(--primary);
    color: white;
}

/* ===== Info Section ===== */
.info-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.info-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.info-card h2 {
    font-size: 1.25rem;
    margin-bottom: 12px;
}

.info-content p {
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.tips-list {
    list-style: none;
    padding: 0;
}

.tips-list li {
    padding: 8px 0 8px 28px;
    position: relative;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.tips-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: bold;
}

.formula-content h4 {
    margin-bottom: 8px;
    color: var(--text);
}

.formula {
    background: var(--bg);
    padding: 16px;
    border-radius: var(--radius-sm);
    font-family: "Courier New", monospace;
    font-size: 1rem;
    text-align: center;
    margin-bottom: 8px;
}

.formula-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ===== FAQ ===== */
.faq-section {
    margin-bottom: 32px;
}

.faq-section h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.faq-item {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.faq-question {
    width: 100%;
    padding: 14px 16px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.faq-question::after {
    content: "+";
    font-size: 1.2rem;
    color: var(--primary);
    transition: transform 0.2s;
}

.faq-item.active .faq-question::after {
    transform: rotate(45deg);
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    padding: 0 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.faq-item.active .faq-answer {
    max-height: 200px;
    padding: 0 16px 14px 16px;
}

/* ===== Footer ===== */
.footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 24px 0;
    text-align: center;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.footer-links a {
    color: var(--primary);
    text-decoration: none;
}

.footer-links a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .result-item.highlight {
        grid-column: span 1;
    }
    
    .calculator-card,
    .results-card,
    .info-card {
        padding: 20px;
    }
    
    .calculator-card h2,
    .results-card h2 {
        font-size: 1.25rem;
    }
    
    .result-value {
        font-size: 1.1rem;
    }
    
    .header-content {
        padding: 10px 12px;
    }
    
    .logo {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }
    
    .calculator-card,
    .results-card,
    .info-card {
        padding: 16px;
    }
    
    .method-btn {
        font-size: 0.75rem;
        padding: 8px;
    }
}
