:root {
  --bg: #f8f7ff;
  --surface: #ffffff;
  --surface2: #f2f0fb;
  --border: #e4e1f0;
  --text: #18172e;
  --text-muted: #64748b;

  --accent: #6c63ff;
  --accent-dark: #5a52d5;
  --accent-light: #eeeeff;

  --green: #16a34a;
  --green-light: #dcfce7;
  --green-border: #86efac;
  --red: #dc2626;
  --red-light: #fee2e2;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --yellow: #b45309;
  --yellow-light: #fef3c7;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 4px rgba(24,23,46,0.06), 0 4px 16px rgba(24,23,46,0.05);
  --shadow-lg: 0 8px 32px rgba(108,99,255,0.14), 0 2px 8px rgba(24,23,46,0.08);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── NAV ─────────────────────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,0.04);
}

.nav-brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 20px;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.83rem;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  transition: color 0.13s, background 0.13s;
  white-space: nowrap;
  position: relative;
}

nav a:hover { color: var(--text); background: var(--surface2); }

nav a.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
}

/* ── PAGES ───────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── HERO ────────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #5b52e8 0%, #8378f5 60%, #a78df7 100%);
  color: white;
  padding: 26px 32px 24px;
}

.hero-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.avatar {
  width: 62px; height: 62px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  flex-shrink: 0;
  border: 2.5px solid rgba(255,255,255,0.45);
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.hero-info h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; }
.hero-info p  { font-size: 0.85rem; opacity: 0.82; margin-top: 2px; }

.hero-stats { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }

.hero-stat {
  text-align: center;
  background: rgba(255,255,255,0.13);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,0.2);
  backdrop-filter: blur(6px);
}

.hero-stat .val { font-size: 1.15rem; font-weight: 700; display: block; letter-spacing: -0.01em; }
.hero-stat .lbl { font-size: 0.68rem; opacity: 0.78; display: block; margin-top: 1px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── LAYOUT ──────────────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 32px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── CARDS ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title {
  font-size: 0.97rem;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── PROGRESS ────────────────────────────────────────────────────────────── */
.progress-wrap { margin-bottom: 16px; }
.progress-wrap:last-child { margin-bottom: 0; }

.progress-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}

.progress-label  { font-size: 0.875rem; font-weight: 600; }
.progress-values { font-size: 0.78rem; color: var(--text-muted); }

.progress-bar-bg {
  height: 8px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 1s cubic-bezier(.4,0,.2,1);
}

.progress-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

/* ── STAT CARDS ──────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-card .icon   { font-size: 1.35rem; margin-bottom: 8px; display: block; }
.stat-card .amount { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-card .label  { font-size: 0.77rem; color: var(--text-muted); margin-top: 2px; }

.stat-card.danger .amount { color: var(--red);    }
.stat-card.success .amount{ color: var(--green);  }
.stat-card.warn .amount   { color: var(--orange); }
.stat-card.primary .amount{ color: var(--accent); }

/* ── DEBT CARDS ──────────────────────────────────────────────────────────── */
.debt-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.debt-card:last-child { margin-bottom: 0; }

.debt-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
}

.debt-name { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.debt-apr  { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.debt-badge {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.badge-red    { background: var(--red-light);    color: var(--red);    }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-green  { background: var(--green-light);  color: var(--green);  }
.badge-sky    { background: #e0f2fe; color: #0369a1; }

.debt-amounts { display: flex; gap: 20px; margin-bottom: 12px; flex-wrap: wrap; }
.debt-amount-item .amt { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.debt-amount-item .lbl { font-size: 0.7rem; color: var(--text-muted); margin-top: 1px; }

/* ── PAYOFF CALCULATOR ───────────────────────────────────────────────────── */
.payoff-calc {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.payoff-calc-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.payoff-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.payoff-input-lbl  { font-size: 0.875rem; font-weight: 500; }
.payoff-total-lbl  { font-size: 0.8rem; color: var(--text-muted); }

.payoff-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 0.82rem;
}

.pcg-header {
  background: var(--surface2);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.pcg-header.pcg-highlight { background: var(--accent-light); color: var(--accent); }

.pcg-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.pcg-val {
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-left: 1px solid var(--border);
}

.pcg-val.pcg-highlight { background: var(--accent-light); color: var(--accent); }
.pcg-val.pcg-red       { color: var(--red); }

.payoff-compare-grid > *:nth-last-child(-n+3) { border-bottom: none; }

.payoff-savings-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.savings-chip {
  font-size: 0.73rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
}

.savings-green { background: var(--green-light); color: #15803d; }

/* ── MILESTONES ──────────────────────────────────────────────────────────── */
.milestone-track {
  position: relative;
  padding-left: 28px;
}

.milestone-track::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}

.milestone-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}

.milestone-item::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 18px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--surface);
  z-index: 1;
}

.milestone-item.done::before  { background: var(--green);  }
.milestone-item.active::before{ background: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

.milestone-item.done   { background: var(--green-light);  }
.milestone-item.active { background: var(--accent-light); box-shadow: 0 2px 12px rgba(108,99,255,0.15); }

.milestone-icon  { font-size: 1.2rem; flex-shrink: 0; }
.milestone-title { font-weight: 600; font-size: 0.875rem; }
.milestone-desc  { font-size: 0.77rem; color: var(--text-muted); margin-top: 2px; }
.milestone-date  { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

.milestone-item.done   .milestone-title { color: #15803d; }
.milestone-item.active .milestone-title { color: var(--accent); }

/* ── CHARTS ──────────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; }

/* ── BUDGET TABLE ────────────────────────────────────────────────────────── */
.budget-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  table-layout: fixed;
}

.budget-table th {
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 11px 16px;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}

.budget-table th.num-col  { text-align: right; }
.budget-table th.adj-head { color: var(--accent); }

.budget-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.budget-cat { font-size: 0.875rem; }
.num-col    { text-align: right; white-space: nowrap; }
.curr-val   { color: var(--text-muted); font-size: 0.85rem; }

/* Alternating expense rows */
.budget-row:nth-child(even) td { background: #fdfcff; }
.budget-row:hover td { background: var(--surface2) !important; }

/* Section headers */
.section-header-row { cursor: pointer; user-select: none; }
.section-header-row:hover td { background: #e8e5f8; }

.section-header-row td {
  background: var(--surface2);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 8px 16px;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.income-section-header td     { background: #f0fdf4 !important; color: #15803d !important; border-top: none !important; }
.income-section-header:hover td { background: #dcfce7 !important; }
.income-section-header .sec-arrow { color: #16a34a; }

.sec-arrow { font-size: 0.6rem; margin-right: 5px; color: var(--accent); display: inline-block; }

/* Section subtotals */
.section-total-row td {
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 7px 16px;
  border-bottom: 2px solid var(--border);
}

/* Grand total + surplus */
.grand-total-row td {
  padding: 12px 16px;
  border-top: 2px solid var(--border);
  background: var(--surface2);
  font-size: 0.875rem;
}

.surplus-row td {
  padding: 12px 16px;
  border-bottom: none;
  font-size: 0.875rem;
}

.surplus-pos { color: var(--green); }
.surplus-neg { color: var(--red);   }

/* Diff colors */
.diff-over  { color: var(--red);   font-weight: 600; }
.diff-under { color: var(--green); font-weight: 600; }

/* Adjusted input */
.adj-cell { padding: 5px 16px !important; text-align: right; }

.adj-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface2);
  border-radius: 7px;
  padding: 5px 9px;
  border: 1.5px solid transparent;
  transition: border-color 0.13s, background 0.13s;
}

.adj-wrap:focus-within {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dollar-sign {
  color: var(--text-muted);
  font-size: 0.78rem;
  user-select: none;
}

.adj-input {
  border: none;
  background: transparent;
  outline: none;
  width: 70px;
  text-align: right;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
}

.adj-input::-webkit-inner-spin-button,
.adj-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.adj-input[type=number] { -moz-appearance: textfield; }
.adj-input.changed { color: var(--accent); }

/* ── BUDGET SUMMARY BAR ──────────────────────────────────────────────────── */
.budget-summary-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 22px;
  margin-bottom: 18px;
  gap: 0;
  flex-wrap: wrap;
  row-gap: 10px;
}

.bsb-item {
  display: flex;
  flex-direction: column;
  min-width: 110px;
}

.bsb-item.bsb-surplus {
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  border: 1px solid #d4d0ff;
}

.bsb-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.bsb-val {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.bsb-val.surplus-pos { color: var(--green); }
.bsb-val.surplus-neg { color: var(--red);   }

.bsb-arrow {
  font-size: 1.2rem;
  color: var(--text-muted);
  padding: 0 14px;
  align-self: center;
  opacity: 0.4;
  font-weight: 300;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.save-btn {
  margin-left: auto;
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.13s, transform 0.1s;
  letter-spacing: 0.01em;
}

.save-btn:hover  { background: var(--accent-dark); }
.save-btn:active { transform: scale(0.97); }

.save-btn.save-btn-confirm { background: var(--green); cursor: default; }

.reset-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  transition: all 0.13s;
}

.reset-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ── ACTION ITEMS ────────────────────────────────────────────────────────── */
.action-list { display: flex; flex-direction: column; gap: 9px; }

.action-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  font-size: 0.875rem;
}

.action-num {
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.action-text { line-height: 1.4; }
.action-text strong { display: block; font-weight: 600; font-size: 0.875rem; }
.action-text span   { color: var(--text-muted); font-size: 0.78rem; }

/* ── CELEBRATION BANNER ──────────────────────────────────────────────────── */
.celebration-banner {
  background: linear-gradient(135deg, #5b52e8, #d946ef);
  color: white;
  border-radius: var(--radius);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-lg);
}

.celebration-banner .icon { font-size: 1.7rem; flex-shrink: 0; }
.celebration-banner h3    { font-size: 0.92rem; font-weight: 700; }
.celebration-banner p     { font-size: 0.81rem; opacity: 0.88; margin-top: 2px; }

/* ── ALERTS ──────────────────────────────────────────────────────────────── */
.alert-banner {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.84rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.alert-banner.warn { background: var(--orange-light); border: 1px solid #fed7aa; }
.alert-banner.info { background: var(--accent-light); border: 1px solid #c4b5fd; }

/* ── INLINE STATS ────────────────────────────────────────────────────────── */
.inline-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.inline-stat {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  flex: 1; min-width: 90px;
}

.inline-stat .val { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.inline-stat .lbl { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* ── BADGE MISC ──────────────────────────────────────────────────────────── */
.tip-label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero-stats { display: none; }
  nav { padding: 0 12px; gap: 2px; }
  nav a { font-size: 0.75rem; padding: 5px 8px; }
  .container { padding: 16px; }
  .hero { padding: 20px 16px; }
}

/* ── LOCK SCREEN ─────────────────────────────────────────────────────────── */
#lock-screen {
  position: fixed;
  inset: 0;
  background: #0e0d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.lock-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.lock-emoji { font-size: 36px; }

.lock-title {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.lock-sub {
  color: #7065a0;
  font-size: 13px;
  margin-top: -12px;
}

.lock-dots {
  display: flex;
  gap: 12px;
  margin: 4px 0;
}

.lock-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #4a4070;
  transition: all 0.15s;
}

.lock-dot.filled {
  background: #6c63ff;
  border-color: #6c63ff;
  box-shadow: 0 0 10px rgba(108,99,255,0.5);
}

.lock-dot.error {
  background: #ef4444;
  border-color: #ef4444;
  box-shadow: 0 0 10px rgba(239,68,68,0.5);
}

.lock-error {
  color: #f87171;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.2s;
  height: 16px;
  margin-top: -12px;
}

.lock-keypad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 10px;
}

.lock-key {
  height: 64px;
  border-radius: 16px;
  border: none;
  background: #1c1a2e;
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, transform 0.08s;
  font-family: inherit;
}

.lock-key:hover  { background: #2a2640; }
.lock-key:active { transform: scale(0.94); background: #6c63ff; }

.lock-key-del { font-size: 18px; color: #a090c0; }
.lock-key-empty { /* grid spacer */ }
