:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #e2e8f0;
  --text: #0f172a;
  --text2: #475569;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior: none;
}

/* Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--bg3);
  z-index: 100;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
  color: var(--text2); font-size: 11px; background: none; border: none;
}
.nav-item.active, .nav-item:hover { color: var(--accent); }
.nav-item svg { width: 22px; height: 22px; }

/* Screens */
.screen { display: none; padding: 16px 16px 80px; max-width: 480px; margin: 0 auto; }
.screen.active { display: block; }

/* Cards */
.card {
  background: var(--bg2); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card-sm { padding: 12px; border-radius: var(--radius-sm); }

/* Balance card */
.balance-card {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: white; text-align: center; padding: 24px 16px;
}
.balance-label { font-size: 13px; opacity: 0.8; }
.balance-amount { font-size: 36px; font-weight: 700; letter-spacing: -1px; margin: 4px 0; }
.balance-sub { font-size: 12px; opacity: 0.7; }

/* Progress bar */
.progress-wrap { margin: 6px 0; }
.progress-bar {
  height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  background: var(--green);
  transition: width 0.4s ease;
}
.progress-fill.warn { background: var(--yellow); }
.progress-fill.over { background: var(--red); }

/* Envelope */
.envelope {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--bg3);
}
.envelope:last-child { border-bottom: none; }
.envelope-emoji { font-size: 22px; width: 30px; text-align: center; }
.envelope-info { flex: 1; min-width: 0; }
.envelope-name { font-size: 14px; font-weight: 500; }
.envelope-amounts { font-size: 12px; color: var(--text2); }
.envelope-status { font-size: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--radius);
  font-size: 15px; font-weight: 600; cursor: pointer;
  border: none; transition: var(--transition);
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text); }
.btn-block { width: 100%; justify-content: center; }
.btn-fab {
  position: fixed; bottom: 76px; right: 16px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; box-shadow: 0 4px 20px rgba(99,102,241,0.4);
  cursor: pointer; border: none; z-index: 99;
  transition: transform 0.2s;
}
.btn-fab:hover { transform: scale(1.1); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2); border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px; width: 100%; max-width: 480px; margin: 0 auto;
  transform: translateY(100%); transition: transform 0.3s ease;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal h3 { margin-bottom: 16px; font-size: 18px; }

/* Form */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg3); border: 1px solid transparent;
  color: var(--text); font-size: 15px;
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
select.form-input { appearance: none; cursor: pointer; }

/* Charts */
.chart-wrap { position: relative; width: 100%; }
canvas { max-width: 100%; }

/* Transaction list */
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--bg3);
}
.tx-item:last-child { border-bottom: none; }
.tx-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--bg3); display: flex; align-items: center;
  justify-content: center; font-size: 18px; flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-merchant { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 12px; color: var(--text2); }
.tx-amount { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }

/* Subscription */
.sub-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--bg3);
}
.sub-name { font-size: 14px; font-weight: 500; }
.sub-meta { font-size: 12px; color: var(--text2); }
.sub-amount { font-size: 15px; font-weight: 600; color: var(--red); }

/* Focus / Forest */
.focus-timer {
  text-align: center; padding: 32px 16px;
}
.timer-display {
  font-size: 72px; font-weight: 700; letter-spacing: -3px;
  font-variant-numeric: tabular-nums; color: var(--text);
  margin: 16px 0;
}
.tree-stage {
  font-size: 64px; transition: all 0.5s; display: block; margin: 8px auto;
}
.focus-controls { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.forest-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 8px 0;
}
.forest-tree { font-size: 28px; text-align: center; }

/* Donut */
.donut-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Header */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.page-title { font-size: 22px; font-weight: 700; }

/* Section title */
.section-title { font-size: 13px; color: var(--text2); margin-bottom: 8px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }

/* To be budgeted banner */
.tbb-banner {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; color: white;
}
.tbb-banner.warn { background: linear-gradient(135deg, #eab308, #ca8a04); }
.tbb-banner.over { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* Import */
.import-zone {
  border: 2px dashed var(--bg3); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer;
  transition: border-color 0.2s;
}
.import-zone:hover, .import-zone.drag { border-color: var(--accent); }
.import-zone input { display: none; }
.import-icon { font-size: 40px; margin-bottom: 8px; }

/* Chip / tag */
.chip {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 20px;
  background: var(--bg3); font-size: 12px; color: var(--text2);
}

/* Loading */
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--bg3);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toaster */
#toaster {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--bg2); color: var(--text);
  padding: 10px 18px; border-radius: 24px;
  box-shadow: var(--shadow); font-size: 14px;
  animation: toast-in 0.3s ease;
}
@keyframes toast-in { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform: none; } }

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f8fafc; --bg2: #ffffff; --bg3: #e2e8f0;
    --text: #0f172a; --text2: #475569;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
  }
}
