/* ==================== VARIABLES & RESET ==================== */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --success-color: #10b981;
    --success-light: #d1fae5;
    --warning-color: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.12);
    --danger-color: #ef4444;
    --danger-light: #fee2e2;

    --page-bg: #f3f4f6;
    --card-bg: #ffffff;
    --neutral-bg: #f9fafb;
    --neutral-border: #e5e7eb;
    --text-dark: #1f2937;
    --text-light: #6b7280;
    --ring-track: #e5e7eb;

    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.15);

    --transition: all 0.25s ease;
}

body.dark {
    --primary-color: #818cf8;
    --primary-dark: #6366f1;
    --page-bg: #0f172a;
    --card-bg: #1e293b;
    --neutral-bg: #172033;
    --neutral-border: #334155;
    --text-dark: #f1f5f9;
    --text-light: #94a3b8;
    --ring-track: #334155;
    --success-light: rgba(16, 185, 129, 0.18);
    --danger-light: rgba(239, 68, 68, 0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--page-bg);
    color: var(--text-dark);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==================== HEADER ==================== */
.header {
    background: var(--gradient-primary);
    color: white;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.header-content { max-width: 1400px; margin: 0 auto; }

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.logo { font-size: 2.3rem; font-weight: 800; text-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.tagline { font-size: 1.05rem; opacity: 0.95; font-weight: 300; }

.header-actions { display: flex; align-items: center; gap: 1rem; }

.period-toggle {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 4px;
}

.period-btn {
    border: none;
    background: transparent;
    color: white;
    padding: 0.5rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}
.period-btn.active { background: white; color: var(--primary-dark); box-shadow: var(--shadow-sm); }

.theme-toggle {
    border: none;
    background: rgba(255, 255, 255, 0.18);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.32); transform: scale(1.05); }

/* ==================== CONTAINER & LAYOUT ==================== */
.container { max-width: 1400px; margin: 0 auto; padding: 0 1rem; }
.main-content { padding: 0 0 2rem; }

section { margin-bottom: 2.5rem; }

.section-head { margin-bottom: 1.25rem; }
.section-head h2 { font-size: 1.4rem; color: var(--text-dark); }
.section-sub { color: var(--text-light); font-size: 0.9rem; }

/* ==================== SUMMARY CARDS ==================== */
.summary-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.5rem;
}

.summary-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--primary-color);
    transition: var(--transition);
}
.summary-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.summary-card.income-card { border-left-color: var(--success-color); }
.summary-card.expense-card { border-left-color: var(--danger-color); }
.summary-card.savings-card { border-left-color: var(--primary-color); }
.summary-card.ratio-card { border-left-color: var(--warning-color); }

.card-icon { font-size: 2.3rem; min-width: 54px; text-align: center; }
.card-content h3 {
    font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-light); margin-bottom: 0.4rem; font-weight: 600;
}
.amount { font-size: 1.7rem; font-weight: 800; color: var(--primary-color); }
.amount.expense { color: var(--danger-color); }
.amount.savings { color: var(--success-color); }
.amount.negative { color: var(--danger-color); }
.period { font-size: 0.8rem; color: var(--text-light); font-weight: 500; }

/* ==================== HEALTH SCORE ==================== */
.health-section { }
.health-score {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 2.5rem;
    flex-wrap: wrap;
}

.score-ring {
    width: 150px; height: 150px; border-radius: 50%;
    background: conic-gradient(var(--primary-color) 0deg, var(--ring-track) 0deg);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.6s ease;
}
.score-inner {
    width: 116px; height: 116px; border-radius: 50%;
    background: var(--card-bg);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-value { font-size: 2.8rem; font-weight: 800; line-height: 1; color: var(--primary-color); }
.score-max { font-size: 0.85rem; color: var(--text-light); }

.health-details { flex: 1; min-width: 240px; }
.health-details h2 { font-size: 1.4rem; margin-bottom: 0.4rem; }
.health-rating { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.5rem; }
.health-summary { color: var(--text-light); font-size: 0.95rem; }

/* ==================== 50/30/20 RULE ==================== */
.rule-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}
.rule-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}
.rule-top { display: flex; align-items: center; gap: 0.85rem; margin-bottom: 1rem; }
.rule-icon { font-size: 1.6rem; }
.rule-top h4 { font-size: 1.05rem; }
.rule-desc { font-size: 0.75rem; color: var(--text-light); }
.rule-target { margin-left: auto; font-size: 0.78rem; color: var(--text-light); white-space: nowrap; }

.rule-bar { width: 100%; height: 10px; background: var(--ring-track); border-radius: 6px; overflow: hidden; }
.rule-fill { height: 100%; border-radius: 6px; transition: width 0.5s ease; }
.rule-fill.good { background: var(--success-color); }
.rule-fill.warning { background: var(--warning-color); }
.rule-fill.danger { background: var(--danger-color); }

.rule-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: 0.65rem; }
.rule-pct { font-size: 1.5rem; font-weight: 800; }
.rule-pct.good { color: var(--success-color); }
.rule-pct.warning { color: var(--warning-color); }
.rule-pct.danger { color: var(--danger-color); }
.rule-amt { font-size: 0.85rem; color: var(--text-light); }

/* ==================== CHARTS ==================== */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 2rem;
}
.chart-container {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}
.chart-container h2 { font-size: 1.2rem; margin-bottom: 1.25rem; }
.chart-container.full-width { grid-column: 1 / -1; }
canvas { max-height: 320px; }

/* ==================== INPUT SECTION ==================== */
.input-section {
    background: var(--card-bg);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.tab-content { display: none; padding: 2rem; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.category { margin-bottom: 2.5rem; }
.category:last-child { margin-bottom: 0; }
.category h3 {
    font-size: 1.15rem; margin-bottom: 0.5rem; color: var(--text-dark);
    padding-bottom: 0.75rem; border-bottom: 2px solid var(--neutral-border);
}
.category-hint { font-size: 0.85rem; color: var(--text-light); margin-bottom: 1.25rem; }

/* Goals */
.goals-container { margin-bottom: 1.25rem; }
.goal-item { background-color: var(--neutral-bg); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.goal-input-group {
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr 1fr auto;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}
.goal-input-group input {
    padding: 0.6rem 0.75rem;
    border: 2px solid var(--neutral-border);
    border-radius: 6px;
    font-size: 0.88rem;
    background: var(--card-bg);
    color: var(--text-dark);
}
.goal-input-group input:focus { outline: none; border-color: var(--primary-color); }
.btn-remove-goal {
    background: var(--danger-color); color: white; border: none; border-radius: 6px;
    width: 36px; height: 36px; cursor: pointer; font-size: 1.2rem; transition: var(--transition);
}
.btn-remove-goal:hover { transform: scale(1.08); }
.progress-bar { width: 100%; height: 8px; background-color: var(--ring-track); border-radius: 4px; overflow: hidden; margin-bottom: 0.5rem; }
.progress-fill { height: 100%; background: var(--gradient-success); border-radius: 4px; width: 0; transition: width 0.5s ease; }
.progress-text { font-size: 0.82rem; color: var(--text-light); }

/* ==================== BUTTONS ==================== */
.button-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    padding: 1.5rem 2rem 0.5rem;
}
.btn-primary, .btn-secondary, .btn-add-goal {
    padding: 0.8rem 1.4rem;
    border: none; border-radius: 8px;
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.btn-primary { background: var(--gradient-primary); color: white; box-shadow: var(--shadow-md); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-secondary { background-color: var(--card-bg); color: var(--primary-color); border: 2px solid var(--primary-color); }
.btn-secondary:hover { background-color: var(--primary-color); color: white; }
.btn-add-goal { background-color: var(--success-light); color: var(--success-color); border: 2px solid var(--success-color); }
.btn-add-goal:hover { background-color: var(--success-color); color: white; }

.autosave-note { text-align: center; font-size: 0.78rem; color: var(--text-light); padding: 0.75rem 0 1.25rem; }

/* ==================== RECOMMENDATIONS & BENCHMARKS ==================== */
.recommendations-section, .comparison-section {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}
.recommendations-section h2, .comparison-section h2 { font-size: 1.4rem; margin-bottom: 1.5rem; }
.recommendations-list { display: grid; gap: 1rem; }
.recommendation-item {
    background-color: var(--neutral-bg);
    border-left: 4px solid var(--warning-color);
    padding: 1.25rem;
    border-radius: 10px;
    display: flex; align-items: start; gap: 1rem;
}
.recommendation-icon { font-size: 1.5rem; flex-shrink: 0; }
.recommendation-content h4 { font-size: 1rem; margin-bottom: 0.25rem; }
.recommendation-content p { font-size: 0.9rem; color: var(--text-light); }
.recommendation-item.positive { border-left-color: var(--success-color); background-color: var(--success-light); }
.recommendation-item.positive h4 { color: var(--success-color); }
.recommendation-item.warning h4 { color: var(--warning-color); }

.benchmark-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.25rem; }
.benchmark-item {
    background-color: var(--neutral-bg);
    border-radius: 10px;
    padding: 1.5rem;
    border: 2px solid var(--neutral-border);
    transition: var(--transition);
}
.benchmark-item:hover { border-color: var(--primary-color); box-shadow: var(--shadow-md); }
.benchmark-item h4 { font-size: 0.82rem; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.benchmark-item .value { font-size: 1.7rem; font-weight: 800; color: var(--primary-color); margin-bottom: 0.4rem; }
.benchmark-item .benchmark { font-size: 0.82rem; color: var(--text-light); }
.benchmark-item .status { display: inline-block; margin-top: 0.7rem; padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.75rem; font-weight: 700; }
.benchmark-item .status.good { background-color: var(--success-light); color: var(--success-color); }
.benchmark-item .status.warning { background-color: var(--warning-light); color: var(--warning-color); }
.benchmark-item .status.danger { background-color: var(--danger-light); color: var(--danger-color); }

/* ==================== FOOTER ==================== */
.footer {
    background-color: var(--text-dark);
    color: white;
    text-align: center;
    padding: 2rem;
    border-top: 4px solid var(--primary-color);
}
body.dark .footer { background-color: #020617; }
.footer p { margin: 0; font-size: 0.92rem; }
.footer-fine { opacity: 0.6; font-size: 0.78rem !important; margin-top: 0.4rem !important; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .header { padding: 1.75rem 1rem; }
    .header-top { flex-direction: column; align-items: flex-start; }
    .logo { font-size: 1.9rem; }
    .summary-section, .charts-section, .rule-grid { grid-template-columns: 1fr; }
    .health-score { flex-direction: column; text-align: center; }
    .tab-content { padding: 1.5rem 1rem; }
    .button-group { grid-template-columns: 1fr; padding: 1.25rem 1rem 0.25rem; }
    .goal-input-group { grid-template-columns: 1fr 1fr; }
    .goal-input-group .btn-remove-goal { grid-column: 1 / -1; width: 100%; }
    canvas { max-height: 280px; }
}

@media (max-width: 480px) {
    .logo { font-size: 1.6rem; }
    .container { padding: 0 0.5rem; }
    .amount { font-size: 1.4rem; }
    .goal-input-group { grid-template-columns: 1fr; }
}

/* ==================== ANIMATIONS ==================== */
@keyframes slideIn { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: translateX(0); } }
.summary-card { animation: slideIn 0.5s ease forwards; }
.summary-card:nth-child(2) { animation-delay: 0.08s; }
.summary-card:nth-child(3) { animation-delay: 0.16s; }
.summary-card:nth-child(4) { animation-delay: 0.24s; }

/* ==================== NAV LINK ==================== */
.nav-link {
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.18);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    transition: var(--transition);
    white-space: nowrap;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.32); transform: translateY(-1px); }

.footer-link { color: var(--primary-light, #818cf8); text-decoration: underline; }

/* ============================================================
   FRONT PAGE — COLORFUL & ANIMATED ENHANCEMENTS
   ============================================================ */

@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.header-content { position: relative; z-index: 2; }

/* Pulsing pill buttons */
.nav-link { animation: glowPulse 3s ease-in-out infinite; }
@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.0); }
    50%      { box-shadow: 0 0 16px 2px rgba(255,255,255,0.35); }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- COLORFUL SUMMARY CARDS ---- */
.summary-card { position: relative; overflow: hidden; border-top: 4px solid transparent; }
.summary-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0.08;
    pointer-events: none;
}
.summary-card.income-card::before  { background: linear-gradient(135deg, #10b981, #34d399); }
.summary-card.expense-card::before { background: linear-gradient(135deg, #ef4444, #f97316); }
.summary-card.savings-card::before { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.summary-card.ratio-card::before   { background: linear-gradient(135deg, #f59e0b, #fbbf24); }

.summary-card .card-icon {
    animation: iconPop 0.6s ease both;
    transition: transform 0.3s ease;
}
.summary-card:hover .card-icon { transform: scale(1.2) rotate(-6deg); }
@keyframes iconPop {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* Gradient numbers */
.income-card .amount  { background: linear-gradient(135deg, #10b981, #059669); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.savings-card .amount { background: linear-gradient(135deg, #6366f1, #8b5cf6); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
/* Negative surplus must stay solid red even over the gradient */
.savings-card .amount.negative {
    background: none;
    -webkit-text-fill-color: var(--danger-color);
    color: var(--danger-color);
}

/* ---- SECTION ENTRANCE ANIMATIONS ---- */
.health-section, .rule-section, .charts-section, .input-section,
.recommendations-section, .comparison-section {
    animation: fadeUp 0.6s ease both;
}

/* Animated conic ring sweep on the health score */
.score-ring::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, rgba(99,102,241,0.25), transparent);
    animation: spin 6s linear infinite;
    z-index: -1;
}
.score-ring { position: relative; }
@keyframes spin { to { transform: rotate(360deg); } }
.score-value { animation: countPop 0.5s ease; }
@keyframes countPop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- CHART & RULE CARD HOVER LIFT ---- */
.chart-container, .rule-card, .benchmark-item {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.chart-container:hover, .rule-card:hover {
    transform: translateY(-6px) scale(1.01);
    box-shadow: var(--shadow-lg);
}
.rule-card { border-top: 4px solid transparent; }
.rule-card:nth-child(1) { border-top-color: #6366f1; }
.rule-card:nth-child(2) { border-top-color: #ec4899; }
.rule-card:nth-child(3) { border-top-color: #10b981; }

/* Animated shimmer fill on the 50/30/20 + rate bars */
.rule-fill, .progress-fill {
    background-image: linear-gradient(90deg, rgba(255,255,255,0.0), rgba(255,255,255,0.45), rgba(255,255,255,0.0));
    background-size: 200% 100%;
    animation: barShine 2.5s linear infinite;
}
@keyframes barShine { to { background-position: -200% 0; } }

/* ---- ANIMATED PRIMARY BUTTON ---- */
.btn-primary {
    background: linear-gradient(120deg, #6366f1, #8b5cf6, #ec4899, #6366f1);
    background-size: 300% 100%;
    animation: gradientShift 6s ease infinite;
}
.btn-primary:hover { animation-duration: 2s; }

/* Recommendation cards slide in nicely */
.recommendation-item { transition: transform 0.25s ease; }
.recommendation-item:hover { transform: translateX(6px); }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .nav-link, .summary-card .card-icon, .score-ring::after,
    .score-value, .rule-fill, .progress-fill, .btn-primary {
        animation: none !important;
    }
}

/* ============================================================
   CLEAN WHITE THEME OVERRIDE
   White headers + white pages. Only the Leftover box (page 2)
   keeps its color.
   ============================================================ */

/* White page background */
:root { --page-bg: #ffffff; }

/* ---- WHITE HEADER (both pages) ---- */
.header {
    background: #ffffff;
    animation: none !important;
    color: var(--text-dark);
    border-bottom: 1px solid var(--neutral-border);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem 2rem;
    margin-bottom: 2rem;
}
body:not(.dark) .header { background: #ffffff; }
body.dark .header { background: var(--card-bg); }
.logo { color: var(--text-dark); text-shadow: none; }
.tagline { color: var(--text-light); }

/* Header controls restyled for a light background */
.nav-link {
    background: var(--neutral-bg);
    color: var(--primary-color);
    border: 1px solid var(--neutral-border);
    animation: none !important;
    box-shadow: none;
}
.nav-link:hover { background: var(--primary-color); color: #fff; }

.period-toggle { background: var(--neutral-bg); border: 1px solid var(--neutral-border); }
.period-btn { color: var(--text-light); }
.period-btn.active { background: var(--primary-color); color: #fff; }

.theme-toggle {
    background: var(--neutral-bg);
    border: 1px solid var(--neutral-border);
    color: var(--text-dark);
}
.theme-toggle:hover { background: var(--neutral-border); }

/* ---- REMOVE LOUD DECORATIONS ON PAGE 1 ---- */
.summary-card { border-top: none; }
.summary-card::before { display: none; }
.income-card .amount,
.savings-card .amount {
    background: none;
    -webkit-text-fill-color: initial;
}
.income-card .amount { color: var(--success-color); }
.savings-card .amount { color: var(--primary-color); }

/* ---- PAGE 2: white everything except the Leftover box ---- */
.calc-page .main-content { background: none; padding-top: 0; }

/* The Leftover box stays colorful (this is the intended exception) */

/* ============================================================
   COLORFUL + ANIMATED HEADER BUTTONS
   (Quick Calculator link, Monthly/Yearly toggle, theme button)
   ============================================================ */

/* Quick Calculator / Full Planner link — animated gradient pill */
.nav-link {
    background: linear-gradient(120deg, #6366f1, #8b5cf6, #ec4899, #6366f1) !important;
    background-size: 300% 100% !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35) !important;
    animation: gradientShift 5s ease infinite !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.nav-link:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 6px 18px rgba(236, 72, 153, 0.45) !important;
    animation-duration: 2s !important;
}

/* Monthly / Yearly toggle — gradient track + animated active pill */
.period-toggle {
    background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(236,72,153,0.12)) !important;
    border: 1px solid rgba(99, 102, 241, 0.25) !important;
    padding: 4px !important;
}
.period-btn {
    color: var(--primary-dark) !important;
    transition: transform 0.2s ease, color 0.2s ease;
}
.period-btn:hover { transform: translateY(-1px); }
.period-btn.active {
    background: linear-gradient(120deg, #6366f1, #8b5cf6, #ec4899, #6366f1) !important;
    background-size: 300% 100% !important;
    color: #fff !important;
    box-shadow: 0 3px 10px rgba(139, 92, 246, 0.4) !important;
    animation: gradientShift 5s ease infinite !important;
}

/* Theme toggle — colorful gradient circle that spins on hover */
.theme-toggle {
    background: linear-gradient(135deg, #f59e0b, #ec4899, #8b5cf6) !important;
    background-size: 200% 200% !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.35) !important;
    animation: gradientShift 6s ease infinite !important;
    transition: transform 0.4s ease, box-shadow 0.2s ease;
}
.theme-toggle:hover {
    transform: rotate(20deg) scale(1.12);
    box-shadow: 0 6px 18px rgba(245, 158, 11, 0.5) !important;
}

@media (prefers-reduced-motion: reduce) {
    .nav-link, .period-btn.active, .theme-toggle { animation: none !important; }
}

/* ============================================================
   QUICK CALCULATOR CTA (between summary cards & health score)
   ============================================================ */
.quick-cta {
    display: flex;
    justify-content: center;
    margin: 0 0 2.5rem;
}
.quick-cta-btn {
    display: inline-block;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    padding: 0.95rem 2.4rem;
    border-radius: 50px;
    background: linear-gradient(120deg, #6366f1, #8b5cf6, #ec4899, #f59e0b, #6366f1);
    background-size: 300% 100%;
    box-shadow: 0 8px 22px rgba(99, 102, 241, 0.4);
    animation: gradientShift 5s ease infinite, ctaBob 3s ease-in-out infinite;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.quick-cta-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 28px rgba(236, 72, 153, 0.5);
    animation-duration: 2s, 3s;
}
.quick-cta-btn:active { transform: translateY(0) scale(1.0); }

@keyframes ctaBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
    .quick-cta-btn { animation: none !important; }
}

/* ============================================================
   CALCULATOR PAGE — LIVE RESULT BAR (sticky)
   ============================================================ */
.live-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--neutral-border);
    border-radius: 16px;
    padding: 1.1rem 1.5rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 0.75rem;
}
.live-item { display: flex; flex-direction: column; }
.live-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); }
.live-val { font-size: 1.35rem; font-weight: 800; line-height: 1.2; }
.live-val.income { color: var(--success-color); }
.live-val.expense { color: var(--danger-color); }
.live-val.saving { color: var(--primary-color); }
.live-op { font-size: 1.3rem; font-weight: 700; color: var(--text-light); }

.leftover-item {
    background: var(--gradient-primary);
    color: #fff;
    padding: 0.5rem 1.1rem;
    border-radius: 12px;
}
.leftover-item .live-label { color: rgba(255,255,255,0.85); }
.live-val.leftover { color: #fff; }
.live-val.leftover.negative { color: #fecaca; }

.live-rate { margin-left: auto; min-width: 160px; }
.live-rate-bar { width: 100%; height: 8px; background: var(--ring-track); border-radius: 5px; overflow: hidden; margin-bottom: 0.35rem; }
.live-rate-fill { height: 100%; width: 0; border-radius: 5px; background: var(--primary-color); transition: width 0.4s ease; }
.live-rate-fill.good { background: var(--success-color); }
.live-rate-fill.warning { background: var(--warning-color); }
.live-rate-fill.danger { background: var(--danger-color); }
.live-rate span { font-size: 0.85rem; font-weight: 700; color: var(--text-dark); }

/* Clear All button inside the live result bar */
.live-clear {
    border: 1px solid var(--neutral-border);
    background: var(--card-bg);
    color: var(--text-light);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}
.live-clear:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: #fff;
    transform: translateY(-1px);
}

/* Collapse / expand toggle inside the live result bar */
.live-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: none;
    border: 1px solid var(--neutral-border);
    background: var(--card-bg);
    color: var(--text-light);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}
.live-toggle:hover {
    background: var(--gradient-primary);
    border-color: transparent;
    color: #fff;
    transform: translateY(-1px);
}
.lt-arrow { font-size: 0.8rem; line-height: 1; transition: transform 0.3s ease; }

/* Label shown only when the bar is collapsed */
.live-collapsed-label {
    display: none;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-light);
}

/* Collapsed state: hide the metrics, keep a slim tappable strip */
.live-bar.collapsed {
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    gap: 0.5rem;
}
.live-bar.collapsed > .live-item,
.live-bar.collapsed > .live-op,
.live-bar.collapsed > .live-rate,
.live-bar.collapsed > .live-clear {
    display: none;
}
.live-bar.collapsed .live-collapsed-label {
    display: inline-block;
    margin-right: auto;
}
.live-bar.collapsed .lt-arrow { transform: rotate(180deg); }

.live-msg {
    text-align: center;
    font-size: 0.92rem;
    color: var(--text-light);
    margin-bottom: 1.75rem;
    padding: 0.6rem 1rem;
    border-radius: 10px;
}
.live-msg.good { color: var(--success-color); background: var(--success-light); }
.live-msg.danger { color: var(--danger-color); background: var(--danger-light); }

/* Link styled as primary button */
.btn-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ============================================================
   DASHBOARD — EMPTY STATE, CTA SECONDARY, GOALS OVERVIEW
   ============================================================ */
.empty-state {
    text-align: center;
    background: var(--card-bg);
    border: 2px dashed var(--neutral-border);
    border-radius: 16px;
    padding: 3rem 1.5rem;
    margin-bottom: 2.5rem;
}
.empty-state h2 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-light); max-width: 460px; margin: 0 auto 1.5rem; }

.cta-secondary {
    background: var(--card-bg);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    border-radius: 50px;
    padding: 0.85rem 1.8rem;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}
.cta-secondary:hover { background: var(--primary-color); color: #fff; transform: translateY(-2px); }

.quick-cta { gap: 1rem; flex-wrap: wrap; }

.goals-overview { }
.goals-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
}
.goal-overview-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--success-color);
}
.goal-overview-card h4 { font-size: 1.05rem; margin-bottom: 0.85rem; }
.goal-overview-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: 0.6rem; font-size: 0.9rem; color: var(--text-light); }
.goal-overview-foot strong { font-size: 1.2rem; color: var(--primary-color); }
.goal-overview-eta { display: block; margin-top: 0.4rem; font-size: 0.8rem; color: var(--text-light); }

@media (max-width: 768px) {
    .live-bar { gap: 0.4rem 0.8rem; padding: 0.9rem 1rem; }
    .live-val { font-size: 1.1rem; }
    .live-op { font-size: 1rem; }
    .live-rate { margin-left: 0; width: 100%; }
}

/* ============================================================
   CALCULATOR — SYSTEMATIC CATEGORY HEADERS & FIELD HINTS
   ============================================================ */
.cat-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.4rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--neutral-border);
}
.cat-head h3 {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 1.15rem;
}
.cat-icon {
    font-size: 1.4rem;
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, rgba(99,102,241,0.14), rgba(236,72,153,0.14));
    border-radius: 12px;
    flex-shrink: 0;
}
.cat-subtotal {
    margin-left: auto;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--primary-color);
    background: var(--neutral-bg);
    border: 1px solid var(--neutral-border);
    padding: 0.3rem 0.85rem;
    border-radius: 50px;
    white-space: nowrap;
}
.cat-subtotal:empty { display: none; }

/* Per-category clear button in the header */
.cat-clear {
    margin-left: 0.6rem;
    border: 1px solid var(--neutral-border);
    background: var(--card-bg);
    color: var(--text-light);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.32rem 0.7rem;
    border-radius: 50px;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}
/* When the subtotal pill is hidden, push the clear button to the right edge */
.cat-subtotal:empty + .cat-clear { margin-left: auto; }
.cat-clear:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: #fff;
    transform: translateY(-1px);
}

/* Field hint text under each label */
.field-hint {
    display: block;
    width: 100%;
    font-size: 0.74rem;
    font-weight: 400;
    color: var(--text-light);
    margin-top: 2px;
    line-height: 1.35;
}

/* ============================================================
   CALCULATOR — ALIGNED FIELD TABLE (label | amount | freq | hint)
   Mirrors calculator.net but cleaner. Columns line up perfectly.
   ============================================================ */
.field-table { display: flex; flex-direction: column; }

.field-row {
    display: grid;
    grid-template-columns: 230px 150px 130px 1fr;
    align-items: center;
    gap: 0.85rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    transition: background 0.15s ease;
}
.field-row:nth-child(odd) { background: var(--neutral-bg); }
.field-row:hover { background: rgba(99,102,241,0.07); }

.field-label {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-dark);
    text-align: right;
    padding-right: 0.25rem;
}

/* Amount box with leading/trailing symbol */
.amount-box {
    display: flex;
    align-items: center;
    border: 2px solid var(--neutral-border);
    border-radius: 8px;
    background: var(--card-bg);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.amount-box .amount-sym {
    padding: 0 0.6rem;
    color: var(--text-light);
    font-weight: 700;
    font-size: 0.95rem;
}
.amount-box input {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-dark);
    padding: 0.55rem 0.6rem 0.55rem 0;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    text-align: right;
}
.amount-box.pct input { padding: 0.55rem 0 0.55rem 0.7rem; text-align: left; }
.amount-box input:focus { outline: none; }
.amount-box:focus-within { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }

/* Frequency dropdown */
.field-freq { display: flex; align-items: center; gap: 0.4rem; }
.freq-slash { color: var(--text-light); font-weight: 700; }
.freq-select {
    flex: 1;
    padding: 0.5rem 0.5rem;
    border: 2px solid var(--neutral-border);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-dark);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease;
}
.freq-select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.freq-fixed {
    font-size: 0.78rem;
    color: var(--text-light);
    font-weight: 600;
    text-transform: lowercase;
    padding-left: 0.2rem;
}

.field-row .field-hint {
    font-size: 0.78rem;
    color: var(--text-light);
    line-height: 1.3;
}

/* Responsive: stack into label-over-controls on small screens */
@media (max-width: 720px) {
    .field-row {
        grid-template-columns: 1fr 120px;
        grid-template-areas:
            "label label"
            "amount freq"
            "hint hint";
        gap: 0.4rem 0.6rem;
        padding: 0.75rem 0.6rem;
    }
    .field-label { grid-area: label; text-align: left; }
    .amount-box { grid-area: amount; }
    .field-freq { grid-area: freq; }
    .field-row .field-hint { grid-area: hint; }
    .field-row .field-hint:empty { display: none; }
}

/* ============================================================
   CALCULATOR — ALL SECTIONS VISIBLE AT ONCE (no tabs to click)
   ============================================================ */
.calc-page .tab-content { display: block; }   /* every section always shown */
.calc-page .tab-content + .tab-content { border-top: 1px solid var(--neutral-border); }

/* Big section divider banner (Income / Expenses / Savings & Goals) */
.section-band {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff;
    background: var(--gradient-primary);
    padding: 0.9rem 1.5rem;
    margin: -2rem -2rem 1.75rem;   /* bleed to the edges of the padded tab-content */
    border-radius: 0;
}
.calc-page .tab-content { padding-top: 2rem; }

@media (max-width: 768px) {
    .section-band { margin: -1.5rem -1rem 1.25rem; font-size: 1.1rem; }
}

/* ============================================================
   MOBILE-FRIENDLY IMPROVEMENTS (phones & small tablets)
   ============================================================ */

/* Prevent iOS auto-zoom: any focused input must be >= 16px */
@media (max-width: 768px) {
    .amount-box input,
    .freq-select,
    .goal-input-group input,
    input[type="number"],
    input[type="text"] {
        font-size: 16px;
    }
}

/* ---- Header controls wrap neatly on phones ---- */
@media (max-width: 768px) {
    .header-top { gap: 1rem; }
    .header-actions { flex-wrap: wrap; width: 100%; gap: 0.6rem; }
    .period-toggle { flex: 1; justify-content: center; }
    .period-btn { flex: 1; text-align: center; }
    .nav-link { flex: 1; text-align: center; }
}

/* ---- Live result bar becomes a clean stacked layout on phones ---- */
@media (max-width: 768px) {
    .live-bar {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 0.5rem;
        padding: 1rem;
    }
    .live-op { display: none; }                 /* hide the - and = symbols */
    .live-item {
        background: var(--neutral-bg);
        border-radius: 10px;
        padding: 0.55rem 0.6rem;
        text-align: center;
    }
    .live-item .live-label { display: block; }
    .leftover-item { grid-column: 1 / -1; }      /* leftover spans full width */
    .live-rate { grid-column: 1 / -1; margin-left: 0; width: 100%; }
    .live-clear { grid-column: 1 / -1; justify-self: center; width: auto; max-width: calc(100% - 3rem); padding: 0.55rem 1.1rem; font-size: 0.85rem; }
    .live-val { font-size: 1.15rem; }
    .live-toggle { position: absolute; bottom: 1.3rem; right: 1.05rem; width: 32px; height: 32px; z-index: 2; box-shadow: var(--shadow-sm); }
    .live-bar.collapsed { display: flex; align-items: center; }
    .live-bar.collapsed .live-toggle { position: static; box-shadow: none; }
}

/* On very narrow phones, give each metric its own full-width row pair */
@media (max-width: 380px) {
    .live-bar { grid-template-columns: 1fr 1fr; }
    .live-item:nth-child(5) { grid-column: 1 / -1; } /* savings spans full */
}

/* ---- Calculator field rows: roomier touch targets on phones ---- */
@media (max-width: 720px) {
    .amount-box input { padding: 0.7rem 0.6rem 0.7rem 0; }
    .freq-select { padding: 0.6rem 0.5rem; }
    .field-row { padding: 0.85rem 0.7rem; }
    .field-label { font-size: 0.95rem; }
}

/* ---- Category headers wrap so the Clear button never overflows ---- */
@media (max-width: 560px) {
    .cat-head { flex-wrap: wrap; }
    .cat-head h3 { font-size: 1.05rem; }
    .cat-subtotal { font-size: 0.82rem; }
    .cat-clear { margin-left: auto; }
}

/* ---- Goals stack fully and stay tappable on small phones ---- */
@media (max-width: 560px) {
    .goal-input-group { grid-template-columns: 1fr; gap: 0.6rem; }
    .goal-input-group input { padding: 0.7rem 0.8rem; }
    .goal-input-group .btn-remove-goal { width: 100%; height: 40px; }
}

/* ---- Bigger, comfy buttons on phones ---- */
@media (max-width: 768px) {
    .quick-cta { flex-direction: column; }
    .quick-cta-btn, .cta-secondary { width: 100%; text-align: center; }
    .btn-primary, .btn-secondary, .btn-add-goal, .btn-link {
        padding: 0.9rem 1.2rem;
        font-size: 0.95rem;
    }
}

/* ---- Tighten section band and headings on very small screens ---- */
@media (max-width: 480px) {
    .logo { font-size: 1.5rem; }
    .tagline { font-size: 0.9rem; }
    .live-val { font-size: 1.15rem; }
    .live-label { font-size: 0.65rem; }
    .health-details h2 { font-size: 1.2rem; }
    .score-ring { width: 130px; height: 130px; }
    .score-inner { width: 100px; height: 100px; }
    .score-value { font-size: 2.3rem; }
    canvas { max-height: 260px; }
}

/* Fallback note shown when Chart.js can't load */
.chart-fallback {
    color: var(--text-light);
    font-size: 0.9rem;
    text-align: center;
    padding: 1.5rem 1rem;
    background: var(--neutral-bg);
    border-radius: 10px;
    margin-top: 0.5rem;
}

/* ============================================================
   BACK-TO-TOP FLOATING BUTTON (colorful + animated)
   ============================================================ */
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 54px;
    height: 54px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 60;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;

    /* animated rainbow gradient */
    background: linear-gradient(135deg, #6366f1, #8b5cf6, #ec4899, #f59e0b, #10b981);
    background-size: 300% 300%;
    box-shadow: 0 8px 22px rgba(99, 102, 241, 0.45);

    /* hidden until the user scrolls down */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.7);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    animation: bttGradient 6s ease infinite;
}
.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.back-to-top:hover {
    transform: translateY(-4px) scale(1.1);
    box-shadow: 0 12px 28px rgba(236, 72, 153, 0.55);
    animation-duration: 2.5s;
}
.back-to-top:active { transform: translateY(0) scale(0.95); }

/* gentle floating bob while idle */
.back-to-top.visible .btt-arrow {
    display: inline-block;
    font-weight: 800;
    animation: bttBob 1.8s ease-in-out infinite;
}

@keyframes bttGradient {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes bttBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

/* pulsing ring around the button */
.back-to-top.visible::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(139, 92, 246, 0.5);
    animation: bttPulse 2s ease-out infinite;
}
@keyframes bttPulse {
    0%   { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.4); opacity: 0; }
}

@media (max-width: 480px) {
    .back-to-top { right: 16px; bottom: 16px; width: 48px; height: 48px; font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top, .back-to-top .btt-arrow, .back-to-top.visible::after { animation: none !important; }
}

/* ============================================================
   AD SLOTS (Google AdSense) — reserved space, labeled, tidy
   ============================================================ */
.ad-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 728px;          /* leaderboard width on desktop */
    min-height: 100px;          /* reserve space to avoid layout shift */
    margin: 2.5rem auto;
    padding: 0.5rem;
    background: var(--neutral-bg);
    border: 1px dashed var(--neutral-border);
    border-radius: 12px;
    overflow: hidden;
}
.ad-slot .adsbygoogle { display: block; width: 100%; }
.ad-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-light);
    margin-bottom: 0.4rem;
}

/* Hide the placeholder border once a real ad has filled the slot */
.ad-slot[data-loaded="1"] { border-style: solid; }

@media (max-width: 768px) {
    .ad-slot { min-height: 90px; margin: 1.75rem auto; max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .ad-slot { transition: none; }
}
