/* ===== CSS Reset & Variables ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-card-hover: rgba(255, 255, 255, 1);
    --border-glass: rgba(0, 0, 0, 0.08);
    --border-glass-hover: rgba(0, 0, 0, 0.15);

    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;

    --accent-indigo: #4f46e5;
    --accent-violet: #7c3aed;
    --accent-purple: #9333ea;
    --accent-teal: #0d9488;
    --accent-green: #16a34a;
    --accent-red: #dc2626;
    --accent-amber: #d97706;

    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-green: linear-gradient(135deg, #22c55e, #2dd4bf);
    --gradient-amber: linear-gradient(135deg, #f59e0b, #ef4444);
    --gradient-purple: linear-gradient(135deg, #a855f7, #6366f1);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow-indigo: 0 0 30px rgba(99, 102, 241, 0.15);
    --shadow-glow-green: 0 0 30px rgba(34, 197, 94, 0.15);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ===== Background Orbs ===== */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
}
.orb-1 {
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.3), transparent 70%);
    top: -100px; left: -100px;
    animation: float-orb 15s ease-in-out infinite;
}
.orb-2 {
    width: 350px; height: 350px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.25), transparent 70%);
    bottom: -50px; right: -50px;
    animation: float-orb 20s ease-in-out infinite reverse;
}
.orb-3 {
    width: 250px; height: 250px;
    background: radial-gradient(circle, rgba(45, 212, 191, 0.2), transparent 70%);
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    animation: float-orb 18s ease-in-out infinite 3s;
}

@keyframes float-orb {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -40px) scale(1.05); }
    66% { transform: translate(-20px, 30px) scale(0.95); }
}

/* ===== App Container ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.app-header {
    padding: 24px 0 16px;
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.logo .subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ===== Glass Card ===== */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xl);
    padding: 28px;
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.glass-card:hover {
    border-color: var(--border-glass-hover);
    box-shadow: var(--shadow-glow-indigo);
}

/* ===== Section Header ===== */
.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.section-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.section-icon.purple { background: var(--gradient-purple); }
.section-icon.teal { background: linear-gradient(135deg, #2dd4bf, #06b6d4); }

.section-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Input Section ===== */
.input-section {
    animation: fadeInUp 0.5s ease-out 0.1s both;
}

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

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

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.input-prefix {
    position: absolute;
    left: 16px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent-indigo);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: 16px 16px 16px 40px;
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-family);
    background: #ffffff;
    border: 2px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper input:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.input-hint {
    display: block;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Term Grid ===== */
.term-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.term-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 8px;
    background: rgba(15, 15, 40, 0.8);
    border: 2px solid var(--border-glass);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.term-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.term-btn:hover {
    border-color: var(--accent-indigo);
    transform: translateY(-2px);
}

.term-btn.active {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.term-btn.active::before {
    opacity: 0.15;
}

.term-months {
    position: relative;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.term-label {
    position: relative;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 2px;
}

.term-rate {
    position: relative;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-indigo);
    margin-top: 6px;
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 20px;
}

.term-btn.active .term-rate {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
}

/* ===== Calculate Button ===== */
.calculate-btn {
    width: 100%;
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-family);
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.calculate-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.35);
}

.calculate-btn:hover::after {
    transform: translateX(100%);
}

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

/* ===== Results Section ===== */
.results-section {
    margin-top: 24px;
    display: none;
}

.results-section.visible {
    display: block;
    animation: fadeInUp 0.5s ease-out;
}

/* ===== Summary Cards ===== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.summary-card {
    position: relative;
    text-align: center;
    padding: 24px 16px;
    overflow: hidden;
}

.card-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 4px;
}

.card-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.card-portal .card-value { color: var(--accent-indigo); }
.card-interest .card-value { color: var(--accent-amber); }
.card-monthly .card-value { color: var(--accent-green); }

.card-glow {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.15;
    bottom: -40px;
    right: -30px;
    pointer-events: none;
}

.card-portal .card-glow { background: var(--accent-indigo); }
.card-interest .card-glow { background: var(--accent-amber); }
.card-monthly .card-glow { background: var(--accent-green); }

/* ===== Breakdown Table ===== */
.breakdown-card {
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease-out 0.15s both;
}

.breakdown-table {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.breakdown-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.breakdown-row.highlight {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
}

.breakdown-row.highlight.green {
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.15);
}

.row-label {
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.row-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

.breakdown-divider {
    height: 1px;
    background: var(--border-glass);
    margin: 8px 0;
}

/* ===== Comparison Table ===== */
.comparison-card {
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease-out 0.25s both;
}

.comparison-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
}

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

.comparison-table thead th {
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--border-glass);
    white-space: nowrap;
}

.comparison-table tbody tr {
    transition: background var(--transition-fast);
}

.comparison-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.comparison-table tbody tr.active-row {
    background: rgba(99, 102, 241, 0.1);
}

.comparison-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
    white-space: nowrap;
}

.comparison-table tbody td:first-child {
    font-weight: 600;
    color: var(--text-primary);
}

.comparison-table tbody td:last-child {
    font-weight: 700;
    color: var(--accent-green);
}

/* ===== Action Buttons ===== */
.action-buttons {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.5s ease-out 0.35s both;
}

.action-btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-family);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-fast);
}

.pdf-btn {
    background: var(--gradient-green);
    color: white;
}

.pdf-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(34, 197, 94, 0.3);
}

.reset-btn {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-glass);
}

.reset-btn:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
    transform: translateY(-2px);
}

/* ===== Footer ===== */
.app-footer {
    margin-top: auto;
    padding: 24px 0;
    text-align: center;
}

.app-footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    .logo h1 {
        font-size: 1.2rem;
    }

    .term-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary-cards {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .summary-card {
        padding: 18px 16px;
    }

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

    .glass-card {
        padding: 20px;
    }

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

    .comparison-table {
        font-size: 0.78rem;
    }
}

@media (max-width: 480px) {
    .term-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .term-btn {
        padding: 10px 6px;
    }

    .term-months {
        font-size: 1.1rem;
    }

    .input-wrapper input {
        font-size: 1.1rem;
        padding: 14px 14px 14px 36px;
    }
}

/* ===== Animations for staggered cards ===== */
.summary-card:nth-child(1) { animation: fadeInUp 0.4s ease-out 0.05s both; }
.summary-card:nth-child(2) { animation: fadeInUp 0.4s ease-out 0.12s both; }
.summary-card:nth-child(3) { animation: fadeInUp 0.4s ease-out 0.19s both; }

/* ===== Number animation pulse ===== */
@keyframes numberPop {
    0% { transform: scale(0.8); opacity: 0; }
    60% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.card-value.animate {
    animation: numberPop 0.4s ease-out;
}
