:root {
  --blue: #2563EB;
  --green: #22C55E;
  --red: #EF4444;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #0F172A;
  --text-2: #64748B;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --shadow-lg: 0 8px 30px rgba(15,23,42,.12);
  --hover: rgba(15,23,42,.04);
}
[data-theme="dark"] {
  --bg: #020617;
  --card: #0F172A;
  --text: #E2E8F0;
  --text-2: #94A3B8;
  --border: #1E293B;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
  --hover: rgba(255,255,255,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

#root { min-height: 100vh; }

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
}
.brand-logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: block;
  box-shadow: 0 4px 12px rgba(37,99,235,.35);
}
.brand-name { font-weight: 700; font-size: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14.5px;
  font-weight: 600;
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: rgba(37,99,235,.12); color: var(--blue); }
.sidebar-spacer { flex: 1; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 40px) 40px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 4px; }
.page-sub { color: var(--text-2); margin: 0 0 22px; }

/* Bottom mobile nav + FAB */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
}
.bottom-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none;
  color: var(--text-2);
  font-size: 10.5px; font-weight: 600;
  padding: 6px 12px;
  border-radius: 12px;
}
.bottom-item svg { width: 22px; height: 22px; }
.bottom-item.active { color: var(--blue); }
.fab {
  position: fixed;
  right: 18px; bottom: 84px;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2563EB, #3B82F6);
  color: #fff;
  box-shadow: 0 8px 24px rgba(37,99,235,.45);
  display: grid; place-items: center;
  z-index: 40;
  transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 26px; height: 26px; }

/* ---------- Home ---------- */
.home-hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  min-height: 252px;
  margin-bottom: 18px;
  padding: 32px clamp(24px, 4vw, 42px);
  border-radius: 24px;
  color: #F5F8F4;
  background: linear-gradient(118deg, #173D35 0%, #205A4A 58%, #2C7057 100%);
  box-shadow: 0 18px 38px rgba(23,61,53,.18);
}
.home-hero-copy, .home-balance { position: relative; z-index: 1; }
.home-eyebrow { display: flex; align-items: center; gap: 9px; color: #BDD9C8; font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.home-eyebrow span { width: 7px; height: 7px; border-radius: 50%; background: #B7E2A7; box-shadow: 0 0 0 4px rgba(183,226,167,.13); }
.home-hero h1 { margin: 20px 0 5px; font-size: clamp(30px, 4vw, 42px); line-height: 1.1; letter-spacing: -.04em; }
.home-hero h1 span { font-size: .72em; }
.home-hero-copy p { margin: 0 0 22px; color: #D1E1D7; font-size: 15px; }
.home-cta { color: #173D35; background: #F5F8F4; box-shadow: 0 7px 18px rgba(8,35,28,.18); }
.home-cta:hover { background: #fff; }
.home-balance { width: min(100%, 310px); flex-shrink: 0; padding: 21px 23px; border: 1px solid rgba(255,255,255,.18); border-radius: 18px; background: rgba(255,255,255,.105); backdrop-filter: blur(12px); }
.home-balance-label, .home-balance-note { display: block; color: #D1E1D7; font-size: 12px; font-weight: 600; }
.home-balance > strong { display: block; margin: 5px 0 1px; font-size: clamp(27px, 3vw, 34px); line-height: 1.2; letter-spacing: -.04em; }
.home-balance-note { color: #B5D0C2; font-size: 11.5px; font-weight: 500; }
.home-balance-divider { height: 1px; margin: 17px 0 13px; background: rgba(255,255,255,.17); }
.home-balance-month { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #D1E1D7; font-size: 12px; }
.home-balance-month strong { font-size: 14px; }
.home-balance-month .positive { color: #C7F0B7; }
.home-balance-month .negative { color: #FFC7B8; }
.home-orbit { position: absolute; z-index: -1; border: 1px solid rgba(222,245,225,.1); border-radius: 50%; pointer-events: none; }
.home-orbit-one { width: 410px; height: 410px; right: 14%; top: -270px; }
.home-orbit-two { width: 560px; height: 560px; right: 4%; top: -333px; }
.home-stats { grid-template-columns: repeat(3, 1fr); }
.home-stats .stat-card { padding: 16px 18px; }
.home-stats .stat-icon { width: 36px; height: 36px; margin-bottom: 10px; }

/* ---------- Grids ---------- */
.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(4, 1fr); }
.dash-grid { grid-template-columns: 1fr 1fr; }
.side-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: fadeUp .35s ease both;
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h3 { margin: 0; }

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

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  animation: fadeUp .35s ease both;
}
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.stat-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  margin-bottom: 12px;
}
.stat-icon svg { width: 20px; height: 20px; }
.icon-blue { background: rgba(37,99,235,.12); color: var(--blue); }
.icon-green { background: rgba(34,197,94,.12); color: var(--green); }
.icon-red { background: rgba(239,68,68,.12); color: var(--red); }
.icon-slate { background: var(--hover); color: var(--text-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14.5px; font-weight: 700;
  transition: transform .1s, box-shadow .15s, background .15s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--blue); color: #fff;
  box-shadow: 0 4px 14px rgba(37,99,235,.3);
}
.btn-primary:hover { background: #1D4ED8; }
.btn-secondary {
  background: var(--hover); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: rgba(239,68,68,.1); color: var(--red); }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form .btn { padding: 14px; font-size: 15px; }

/* ---------- Form ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 7px; }
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  transition: border .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
  background: var(--card);
}
.textarea { resize: vertical; min-height: 80px; }
.field-error { color: var(--red); font-size: 12.5px; font-weight: 600; margin-top: 6px; }

/* type toggle */
.type-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
.type-opt {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .15s;
}
.type-opt.expense.active { background: rgba(239,68,68,.1); color: var(--red); border-color: var(--red); }
.type-opt.income.active { background: rgba(34,197,94,.1); color: var(--green); border-color: var(--green); }
.type-opt svg { width: 18px; height: 18px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 700;
  white-space: nowrap;
}
.badge-income { background: rgba(34,197,94,.14); color: var(--green); }
.badge-expense { background: rgba(239,68,68,.12); color: var(--red); }
.cat-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  color: #fff;
  flex-shrink: 0;
  font-size: 15px;
}

/* ---------- Transactions list ---------- */
.tx-list { display: flex; flex-direction: column; }
.tx-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-info { flex: 1; min-width: 0; }
.tx-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { color: var(--text-2); font-size: 12.5px; margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.tx-amount { font-weight: 800; font-size: 15px; white-space: nowrap; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--text); }
.tx-actions { display: flex; gap: 4px; }
.icon-btn {
  background: none; border: none;
  color: var(--text-2);
  border-radius: 8px;
  padding: 6px;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn svg { width: 18px; height: 18px; }

/* transaction with default type (light keeps expense dark, dark keeps light) */
[data-theme="dark"] .tx-amount.expense { color: var(--text); }

/* ---------- Filters ---------- */
.filters {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 18px;
}
.filters .input { padding: 10px 12px; }

/* ---------- Progress ---------- */
.progress-track { height: 10px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.budget-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.budget-name { font-weight: 700; }
.budget-amounts { color: var(--text-2); font-size: 13px; }
.budget-warn { color: #F59E0B; font-weight: 700; }
.budget-over { color: var(--red); font-weight: 700; }
.budget-edit { margin-left: 8px; color: var(--text-2); }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-2);
}
.empty-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--hover);
  display: grid; place-items: center;
  margin: 0 auto 16px;
}
.empty-icon svg { width: 34px; height: 34px; color: var(--text-2); }
.empty h4 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0; font-size: 13.5px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(2,6,23,.5);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: modalPop .2s ease;
  border: 1px solid var(--border);
}
@keyframes modalPop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
.modal h3 { margin: 0 0 8px; font-size: 19px; }
.modal p { color: var(--text-2); margin: 0 0 20px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 120;
  animation: toastIn .25s ease;
  display: flex; align-items: center; gap: 8px;
}
.toast svg { width: 18px; height: 18px; color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Charts ---------- */
.chart-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut { position: relative; }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
}
.donut-center .val { font-weight: 800; font-size: 20px; }
.donut-center .lbl { color: var(--text-2); font-size: 11.5px; }
.legend { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 150px; }
.legend-item { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text-2); font-weight: 600; }
.legend-val { font-weight: 700; }
.bars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 44px;
  border-radius: 8px 8px 4px 4px;
  min-height: 3px;
  transition: height .4s ease;
  position: relative;
}
.bar:hover { opacity: .85; }
.bar-val { font-size: 11px; color: var(--text-2); font-weight: 600; }
.bar-lbl { font-size: 11.5px; color: var(--text-2); font-weight: 700; }
.bar-total {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-2);
}
.bar-total .big { font-size: 22px; font-weight: 800; color: var(--text); }

/* ---------- Settings / misc ---------- */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-weight: 700; }
.setting-desc { color: var(--text-2); font-size: 12.5px; margin-top: 3px; }

/* switch */
.switch { position: relative; width: 48px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .2s;
  cursor: pointer;
}
.slider:before {
  content: "";
  position: absolute; left: 3px; top: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.budget-input { width: 90px; }
.form-note { color: var(--text-2); font-size: 13px; margin-top: 12px; text-align: center; }
.dual-note { font-size: 12px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }

.category-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 12px; font-weight: 600;
  transition: all .15s;
}
.cat-opt .cat-badge { width: 32px; height: 32px; font-size: 14px; }
.cat-opt.active { border-color: var(--blue); background: rgba(37,99,235,.08); color: var(--text); }

.insight-list { display: flex; flex-direction: column; gap: 12px; }
.insight {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--hover);
}
.insight svg { width: 20px; height: 20px; color: var(--blue); flex-shrink: 0; }
.insight small { display: block; color: var(--text-2); font-size: 12px; }
.insight strong { font-size: 14px; }

/* ---------- Responsive ---------- */
@media (min-width: 901px) {
  .bottom-nav { display: none; }
  .fab { display: none; }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  body { padding-bottom: 74px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .fab { display: grid; }
}
@media (max-width: 720px) {
  .dash-grid { grid-template-columns: 1fr; }
  .side-grid { grid-template-columns: 1fr; }
  .home-hero { align-items: stretch; flex-direction: column; gap: 24px; padding: 26px 22px; }
  .home-hero h1 { margin-top: 15px; }
  .home-balance { width: 100%; }
  .home-stats { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 30px; }
  .page-title { font-size: 22px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
  .category-picker { grid-template-columns: repeat(3, 1fr); }
  .modal-actions { flex-direction: column-reverse; }
}
@media (min-width: 901px) and (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .home-stats { grid-template-columns: repeat(3, 1fr); }
  .home-hero { gap: 22px; }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
