:root {
  --bg: #0b1020;
  --bg-2: #0f172a;
  --surface: #111a33;
  --surface-2: #172244;
  --border: #1f2b4d;
  --text: #e6ecff;
  --text-dim: #9aa7c7;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #1b2550 0%, transparent 60%),
              radial-gradient(1000px 500px at 110% 10%, #2a1b50 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 14px calc(90px + var(--safe-bottom));
}

/* HEADER */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center; font-size: 22px;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.subtitle { margin: 0; font-size: 12px; color: var(--text-dim); }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 16px;
  transition: transform .15s, background .15s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-1px); }

/* SUMMARY */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.summary-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.summary-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--primary);
}
.summary-card.income::before { background: linear-gradient(90deg, #10b981, #34d399); }
.summary-card.expense::before { background: linear-gradient(90deg, #ef4444, #f87171); }
.summary-card.balance::before { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.summary-card .label { font-size: 12px; color: var(--text-dim); }
.summary-card .value { font-size: 20px; font-weight: 700; }
.summary-card .delta { font-size: 11px; color: var(--text-dim); }

/* MONTH SELECTOR */
.month-selector {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 8px 0 16px;
}
.month-label {
  font-weight: 600; font-size: 16px; min-width: 180px; text-align: center;
  text-transform: capitalize;
}
.nav-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 18px;
}
.nav-btn:hover { background: var(--surface-2); }

/* TABS */
.tab-panel { display: none; animation: fade .25s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel-card h2 { margin: 0 0 12px; font-size: 16px; }
.panel-card h3 { margin: 0 0 10px; font-size: 14px; color: var(--text-dim); }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-header h2 { margin: 0; }

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

/* LIST */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; transition: transform .15s;
}
.list-item:hover { transform: translateX(2px); }
.list-item .li-left { display: flex; align-items: center; gap: 10px; }
.list-item .li-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px;
  background: rgba(99,102,241,.15); color: var(--primary-2);
}
.list-item.income .li-icon { background: rgba(16,185,129,.15); color: #34d399; }
.list-item.expense .li-icon { background: rgba(239,68,68,.15); color: #f87171; }
.list-item .li-title { font-weight: 600; font-size: 14px; }
.list-item .li-sub { font-size: 11px; color: var(--text-dim); }
.list-item .li-amount { font-weight: 700; font-size: 15px; }
.list-item.income .li-amount { color: #34d399; }
.list-item.expense .li-amount { color: #f87171; }
.empty { text-align: center; color: var(--text-dim); padding: 24px; font-size: 13px; }

/* BUTTONS */
.btn {
  border: none; border-radius: 10px; padding: 10px 16px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), #8b5cf6); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99,102,241,.35); }

/* TAB BAR */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: rgba(15, 23, 42, .92); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + var(--safe-bottom));
  z-index: 50;
}
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px; cursor: pointer; font-size: 11px;
  transition: color .15s;
}
.tab-btn .icon { font-size: 20px; }
.tab-btn.active { color: var(--primary-2); }

/* MODAL */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 100; padding: 16px;
  animation: fade .2s;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; width: 100%; max-width: 440px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-content label { display: block; margin-bottom: 12px; font-size: 12px; color: var(--text-dim); }
.modal-content input, .modal-content select, .modal-content textarea {
  width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px; font-family: inherit;
}
.modal-content input:focus, .modal-content select:focus, .modal-content textarea:focus {
  outline: none; border-color: var(--primary);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.hidden { display: none !important; }

/* CHARTS */
.chart-wrap { position: relative; height: 260px; }

/* GOALS */
.goal-item {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 8px;
}
.goal-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.goal-name { font-weight: 600; font-size: 14px; }
.goal-nums { font-size: 12px; color: var(--text-dim); }
.progress { height: 8px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); transition: width .4s; }

/* CATEGORIES */
.cat-group { margin-bottom: 14px; }
.cat-group h4 { margin: 0 0 6px; font-size: 13px; color: var(--text-dim); }
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 999px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.cat-chip button {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px;
}
.cat-add { display: flex; gap: 6px; margin-top: 8px; }
.cat-add input { flex: 1; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; }

/* TOAST */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 200;
}
.toast.hidden { display: none; }

.hint { font-size: 12px; color: var(--text-dim); margin: 4px 0 10px; }

/* RESPONSIVE */
@media (max-width: 600px) {
  .summary { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .summary-card .value { font-size: 18px; }
}