:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e3e5ea;
  --text: #16181d;
  --text-dim: #6b7280;
  --text-faint: #9aa0ab;
  --accent: #6366f1;
  --accent-2: #ec4899;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16,20,30,0.04), 0 4px 16px rgba(16,20,30,0.06);
  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* glass-mode background glow colors - overridden per [data-accent] below */
  --glow-1: rgba(99,102,241,0.35);
  --glow-2: rgba(236,72,153,0.28);
  --glow-3: rgba(34,197,94,0.18);
  --glow-1-dark: rgba(99,102,241,0.22);
  --glow-2-dark: rgba(236,72,153,0.16);
  --glow-3-dark: rgba(34,197,94,0.10);
}

/* ---------- Color theme (accent) options ---------- */
:root[data-accent="professional"] {
  --accent: #1d4ed8;
  --accent-2: #1e293b;
  --glow-1: rgba(29,78,216,0.28);
  --glow-2: rgba(30,41,59,0.20);
  --glow-3: rgba(100,116,139,0.14);
  --glow-1-dark: rgba(29,78,216,0.20);
  --glow-2-dark: rgba(148,163,184,0.12);
  --glow-3-dark: rgba(100,116,139,0.10);
}
:root[data-accent="slate"] {
  --accent: #475569;
  --accent-2: #64748b;
  --glow-1: rgba(71,85,105,0.28);
  --glow-2: rgba(100,116,139,0.22);
  --glow-3: rgba(148,163,184,0.16);
  --glow-1-dark: rgba(100,116,139,0.20);
  --glow-2-dark: rgba(148,163,184,0.14);
  --glow-3-dark: rgba(71,85,105,0.14);
}
:root[data-accent="teal"] {
  --accent: #0d9488;
  --accent-2: #06b6d4;
  --glow-1: rgba(13,148,136,0.30);
  --glow-2: rgba(6,182,212,0.26);
  --glow-3: rgba(45,212,191,0.16);
  --glow-1-dark: rgba(13,148,136,0.20);
  --glow-2-dark: rgba(6,182,212,0.16);
  --glow-3-dark: rgba(45,212,191,0.10);
}
:root[data-accent="orange"] {
  --accent: #ea580c;
  --accent-2: #f59e0b;
  --glow-1: rgba(234,88,12,0.30);
  --glow-2: rgba(245,158,11,0.26);
  --glow-3: rgba(251,191,36,0.16);
  --glow-1-dark: rgba(234,88,12,0.20);
  --glow-2-dark: rgba(245,158,11,0.16);
  --glow-3-dark: rgba(251,191,36,0.10);
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #eef0f4;
  --text-dim: #9aa2b1;
  --text-faint: #6b7280;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 20px rgba(0,0,0,0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #eef0f4;
    --text-dim: #9aa2b1;
    --text-faint: #6b7280;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 20px rgba(0,0,0,0.35);
  }
}

/* ---------- Glassmorphism style variant ---------- */
:root[data-style="glass"] {
  --glass-bg: rgba(255,255,255,0.55);
  --glass-bg-strong: rgba(255,255,255,0.7);
  --glass-border: rgba(255,255,255,0.5);
  --glass-blur: blur(20px) saturate(160%);
}
:root[data-style="glass"][data-theme="dark"] {
  --glass-bg: rgba(30,34,45,0.5);
  --glass-bg-strong: rgba(30,34,45,0.68);
  --glass-border: rgba(255,255,255,0.09);
}
@media (prefers-color-scheme: dark) {
  :root[data-style="glass"]:not([data-theme="light"]) {
    --glass-bg: rgba(30,34,45,0.5);
    --glass-bg-strong: rgba(30,34,45,0.68);
    --glass-border: rgba(255,255,255,0.09);
  }
}

[data-style="glass"] body {
  background:
    radial-gradient(circle at 12% 8%, var(--glow-1), transparent 45%),
    radial-gradient(circle at 88% 15%, var(--glow-2), transparent 45%),
    radial-gradient(circle at 25% 90%, var(--glow-3), transparent 40%),
    var(--bg);
  background-attachment: fixed;
}
[data-style="glass"][data-theme="dark"] body {
  background:
    radial-gradient(circle at 12% 8%, var(--glow-1-dark), transparent 45%),
    radial-gradient(circle at 88% 15%, var(--glow-2-dark), transparent 45%),
    radial-gradient(circle at 25% 90%, var(--glow-3-dark), transparent 40%),
    var(--bg);
  background-attachment: fixed;
}
@media (prefers-color-scheme: dark) {
  [data-style="glass"]:not([data-theme="light"]) body {
    background:
      radial-gradient(circle at 12% 8%, var(--glow-1-dark), transparent 45%),
      radial-gradient(circle at 88% 15%, var(--glow-2-dark), transparent 45%),
      radial-gradient(circle at 25% 90%, var(--glow-3-dark), transparent 40%),
      var(--bg);
    background-attachment: fixed;
  }
}

[data-style="glass"] .card,
[data-style="glass"] .sheet,
[data-style="glass"] .topbar,
[data-style="glass"] .bottom-nav,
[data-style="glass"] .sidebar,
[data-style="glass"] .auth-card,
[data-style="glass"] .fab,
[data-style="glass"] .icon-btn {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
}
[data-style="glass"] .card { box-shadow: 0 8px 32px rgba(16,20,30,0.10); }
[data-style="glass"] .fab { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
[data-style="glass"] input, [data-style="glass"] select, [data-style="glass"] textarea {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-color: var(--glass-border);
}
[data-style="glass"] .btn-secondary { background: var(--glass-bg-strong); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); }
[data-style="glass"] .pill, [data-style="glass"] .progress-track, [data-style="glass"] .cat-icon { background: var(--glass-bg-strong); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
a { color: inherit; }
button, input, select, textarea { font-family: inherit; color: inherit; }
h1,h2,h3,h4 { margin: 0; }
p { margin: 0; }

#app { min-height: 100%; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 24px + var(--safe-bottom));
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar h1 .icon { color: var(--accent); }
.topbar .month-nav { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: var(--surface-2); border: none; border-radius: 10px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 16px;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- Bottom nav (mobile-first) ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-faint); font-size: 10.5px; font-weight: 600;
}
.bottom-nav a .nav-icon { font-size: 20px; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.scan-btn .nav-icon {
  width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; display: flex; align-items: center; justify-content: center; font-size: 20px;
  margin-top: -22px; box-shadow: var(--shadow);
}

/* ---------- Desktop sidebar ---------- */
.app-shell { display: flex; min-height: 100%; }
.sidebar { display: none; }

@media (min-width: 880px) {
  .bottom-nav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; width: 230px; flex-shrink: 0;
    background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; gap: 2px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .sidebar .brand { font-size: 19px; font-weight: 800; padding: 8px 10px 18px; display: flex; align-items: center; gap: 8px; }
  .sidebar a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    text-decoration: none; color: var(--text-dim); font-size: 14px; font-weight: 600;
  }
  .sidebar a:hover { background: var(--surface-2); }
  .sidebar a.active { background: var(--accent); color: white; }
  .main-col { flex: 1; min-width: 0; }
  .container { padding: 24px 32px 48px; max-width: 1100px; }
}

/* ---------- Cards / layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 340px) { .more-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 880px) { .more-grid { grid-template-columns: repeat(6, 1fr); gap: 12px; } }
.more-tile {
  text-decoration: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 7px; padding: 16px 6px; text-align: center; aspect-ratio: 1 / 1;
}
.more-tile-icon { color: var(--accent); }
.more-tile-label { font-weight: 700; font-size: 11px; color: var(--text); line-height: 1.25; }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); margin: 20px 2px 8px;
}
.section-title:first-child { margin-top: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* ---------- Stat tiles ---------- */
.stat-tile { display: flex; flex-direction: column; gap: 4px; }
.stat-tile .label { font-size: 11.5px; color: var(--text-dim); font-weight: 600; }
.stat-tile .value { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.stat-tile .sub { font-size: 11.5px; color: var(--text-faint); }
.stat-tile .value.good { color: var(--good); }
.stat-tile .value.bad { color: var(--bad); }

/* ---------- Progress bars ---------- */
.progress-track { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; transition: width 0.3s ease; }
.progress-fill.ok { background: var(--good); }
.progress-fill.warn { background: var(--warn); }
.progress-fill.bad { background: var(--bad); }

/* ---------- Budget rows ---------- */
.budget-cat { padding: 12px 4px; border-bottom: 1px solid var(--border); }
.budget-cat:last-child { border-bottom: none; }
.budget-cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.cat-icon {
  width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.budget-person-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.person-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 10px; padding: 11px 16px; font-weight: 700; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: rgba(220,38,38,0.1); color: var(--bad); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.btn:active { transform: scale(0.98); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + var(--safe-bottom));
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: white;
  border: none; font-size: 24px; box-shadow: var(--shadow); z-index: 25; cursor: pointer;
}
@media (min-width: 880px) { .fab { bottom: 24px; } }

/* ---------- Forms ---------- */
label { font-size: 12.5px; font-weight: 700; color: var(--text-dim); display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 15px; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 12px; }
.field-row { display: flex; gap: 10px; }
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; margin-top: 4px; }
.icon-pick {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-pick.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.field-row .field { flex: 1; }
textarea { resize: vertical; min-height: 60px; }

/* ---------- Modal / sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,12,16,0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 880px) { .overlay { align-items: center; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-bottom));
  animation: sheet-in 0.18s ease;
}
@media (min-width: 880px) { .sheet { border-radius: 16px; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 17px; }

/* ---------- Lists ---------- */
.tx-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--border); }
.tx-row:last-child { border-bottom: none; }
.tx-main { flex: 1; min-width: 0; }
.tx-main .desc { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-main .meta { font-size: 12px; color: var(--text-faint); }
.tx-amount { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.tx-amount.income { color: var(--good); }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--text-dim);
}

/* ---------- Auth screens ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 100%);
}
.auth-card {
  background: var(--surface); border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.auth-logo { font-size: 30px; text-align: center; margin-bottom: 4px; }
.auth-title { text-align: center; font-size: 20px; font-weight: 800; margin-bottom: 2px; }
.auth-sub { text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.auth-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-toggle button { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 700; font-size: 13px; cursor: pointer; }
.auth-toggle button.active { background: var(--accent); color: white; border-color: var(--accent); }

.color-theme-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.color-theme-picker button {
  display: flex; flex-direction: column; align-items: center; gap: 5px; background: none; border: none; cursor: pointer; padding: 4px;
}
.color-theme-picker .swatch {
  width: 38px; height: 38px; border-radius: 50%; display: block; border: 2px solid transparent; box-shadow: var(--shadow);
}
.color-theme-picker button.active .swatch { border-color: var(--text); }
.color-theme-picker .swatch-label { font-size: 10.5px; font-weight: 600; color: var(--text-dim); }
.color-theme-picker button.active .swatch-label { color: var(--text); }
.auth-error { background: rgba(220,38,38,0.1); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.auth-note { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); padding: 10px 12px; border-radius: 10px; font-size: 12.5px; margin-bottom: 12px; }
.link-btn { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 13px; cursor: pointer; padding: 0; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--text-faint); }
.empty .emoji { display: flex; justify-content: center; margin-bottom: 10px; color: var(--text-faint); }
.empty .icon { display: inline-block; vertical-align: -4px; margin-right: 4px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 14px; left: 0; right: 0; z-index: 100; display: flex; justify-content: center; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); animation: toast-in 0.2s ease; margin-top: 4px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Venn ---------- */
.venn-wrap { display: flex; align-items: center; justify-content: center; padding: 12px 0; }
.venn { position: relative; width: 260px; height: 160px; }
.venn-circle {
  position: absolute; top: 10px; width: 150px; height: 140px; border-radius: 50%;
  mix-blend-mode: multiply; opacity: 0.55; display: flex; align-items: center; justify-content: center;
}
:root[data-theme="dark"] .venn-circle, @media (prefers-color-scheme: dark) { }
.venn-circle.a { left: 10px; background: var(--accent); }
.venn-circle.b { right: 10px; background: var(--accent-2); }
.venn-label { position: absolute; font-size: 11px; font-weight: 700; text-align: center; width: 90px; color: var(--text); }

/* ---------- Charts (SVG) ---------- */
.chart-bar-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.chart-bar-track { flex: 1; height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.chart-bar-fill { height: 100%; border-radius: 6px; }
svg.trend-svg, svg.donut-svg { width: 100%; height: auto; display: block; }

/* ---------- Camera / receipt review ---------- */
.receipt-preview { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: var(--surface-2); }
.receipt-item-row { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.confidence-low { border-color: var(--warn); background: rgba(217,119,6,0.06); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite; margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Misc ---------- */
.icon { display: block; flex-shrink: 0; }
.icon-btn .icon, .fab .icon, .nav-icon .icon { margin: auto; }
.btn .icon { margin-right: 2px; }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-good { color: var(--good); }
.text-bad { color: var(--bad); }
.text-warn { color: var(--warn); }
.mt-0 { margin-top: 0; }
.hidden { display: none !important; }
.scroll-x { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { font-size: 11px; text-transform: uppercase; color: var(--text-faint); font-weight: 700; }
