:root {
  --bg: #f0f3f8;
  --surface: #ffffff;
  --surface-alt: #f7f9fc;
  --border: #e2e8f0;
  --text: #1a2b4a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --income: #059669;
  --income-light: #d1fae5;
  --expense: #dc2626;
  --expense-light: #fee2e2;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --font-body: 'Manrope', sans-serif;
  --font-display: 'Space Grotesk', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Sidebar ---- */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
  padding: 0 6px;
}
.logo svg { color: var(--primary); }
.logo span {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .18s;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }

.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: var(--text-light);
  padding: 0 6px;
}

/* ---- Main ---- */
.main {
  flex: 1;
  padding: 36px 40px;
  max-width: 900px;
}

.page-head { margin-bottom: 28px; }
.page-head h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.page-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* ---- Views ---- */
.view { display: none; }
.view.active { display: block; }

/* ---- Stats ---- */
.stat-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.stat-balance {
  background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
  color: #fff;
  border: none;
}
.stat-balance .stat-label { color: rgba(255,255,255,.7); }
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat-balance .stat-value { font-size: 34px; }
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }
.stat-trend { font-size: 12px; margin-top: 6px; opacity: .8; }

/* ---- Panel ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 18px;
}

.cat-list { display: flex; flex-direction: column; gap: 12px; }
.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cat-bar-wrap { flex: 1; height: 8px; background: var(--surface-alt); border-radius: 4px; overflow: hidden; }
.cat-bar { height: 100%; border-radius: 4px; transition: width .6s ease; }
.cat-bar.income { background: var(--income); }
.cat-bar.expense { background: var(--expense); }
.cat-name { font-size: 13px; font-weight: 600; width: 100px; }
.cat-amount { font-family: var(--font-display); font-size: 13px; font-weight: 700; width: 90px; text-align: right; }
.cat-amount.income { color: var(--income); }
.cat-amount.expense { color: var(--expense); }

/* ---- Filter Chips ---- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 7px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ---- Table ---- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th {
  text-align: left;
  padding: 14px 18px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.tx-table td {
  padding: 14px 18px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.tx-table tbody tr:last-child td { border-bottom: none; }
.tx-table tbody tr:hover { background: var(--surface-alt); }
.ta-right { text-align: right; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.badge.income { background: var(--income-light); color: var(--income); }
.badge.expense { background: var(--expense-light); color: var(--expense); }
.tx-amount { font-family: var(--font-display); font-weight: 700; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }
.btn-del {
  border: none;
  background: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
}
.btn-del:hover { background: var(--expense-light); color: var(--expense); }
.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }

/* ---- Add Form ---- */
.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  max-width: 480px;
}

.type-toggle {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}
.type-toggle input { display: none; }
.type-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .18s;
  color: var(--text-muted);
}
#t-income:checked + .type-label.income {
  border-color: var(--income);
  background: var(--income-light);
  color: var(--income);
}
#t-expense:checked + .type-label.expense {
  border-color: var(--expense);
  background: var(--expense-light);
  color: var(--expense);
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--surface-alt);
  transition: all .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-submit {
  width: 100%;
  padding: 14px;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all .18s;
}
.btn-submit:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-submit:active { transform: translateY(0); }

.form-msg { margin-top: 14px; font-size: 14px; font-weight: 600; text-align: center; }
.form-msg.ok { color: var(--income); }
.form-msg.err { color: var(--expense); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    align-items: center;
    padding: 14px 16px;
    gap: 12px;
    overflow-x: auto;
  }
  .logo { margin-bottom: 0; flex-shrink: 0; }
  nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main { padding: 20px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-balance { grid-column: 1 / -1; }
}
