:root {
  --bg: #14161a;
  --bg-alt: #1b1e24;
  --card: #20232b;
  --border: #2c303a;
  --text: #e8e9ec;
  --text-dim: #9297a3;
  --accent: #f5a623;
  --accent-dim: #7a5716;
  --income: #3ecf8e;
  --expense: #ef5b5b;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, select, textarea { font-family: inherit; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.login-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.login-brand .mark { color: var(--accent); font-size: 26px; font-weight: 700; }
.login-brand .name { font-size: 20px; font-weight: 600; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s ease;
}
.btn:hover { opacity: .88; }
.btn:active { opacity: .75; }
.btn-primary { background: var(--accent); color: #1a1305; }
.btn-secondary { background: var(--bg-alt); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--expense); color: #fff; }
.btn-block { width: 100%; }
.error-text { color: var(--expense); font-size: 13px; margin: 8px 0; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}
.sidebar-brand { padding: 0 20px 20px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sidebar-brand .mark { color: var(--accent); font-weight: 700; font-size: 20px; }
.sidebar-brand .name { font-weight: 600; font-size: 16px; margin-left: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.nav-item.active { color: var(--text); border-left-color: var(--accent); background: rgba(245,166,35,0.08); }
.sidebar-footer { margin-top: auto; padding: 12px 20px 0; border-top: 1px solid var(--border); }
.user-chip { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.user-chip strong { color: var(--text); display: block; font-size: 14px; }

.main { flex: 1; padding: 28px 32px; overflow-x: hidden; min-width: 0; }
.page-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }

.topbar-mobile { display: none; }

/* ---------- Cards / grids ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-label { color: var(--text-dim); font-size: 12px; margin-bottom: 8px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }

.panel-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; margin-bottom: 24px; }
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h3 { margin: 0 0 14px; font-size: 14px; font-weight: 600; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-label { width: 120px; flex-shrink: 0; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--bg-alt); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.income { background: var(--income); }
.bar-fill.expense { background: var(--expense); }
.bar-value { width: 90px; text-align: right; flex-shrink: 0; }

.account-list { display: flex; flex-direction: column; gap: 10px; }
.account-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--bg-alt); border-radius: 8px; font-size: 13px;
}
.account-row .acct-name { font-weight: 500; }
.account-row .acct-balance { font-weight: 700; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: none; background: var(--bg-alt); }
tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.income { background: rgba(62,207,142,0.15); color: var(--income); }
.badge.expense { background: rgba(239,91,91,0.15); color: var(--expense); }
.amt.income { color: var(--income); font-weight: 600; }
.amt.expense { color: var(--expense); font-weight: 600; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.filter-select, .filter-input {
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 460px; padding: 24px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 18px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 18px; font-size: 13px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-left-color: var(--expense); }

/* ---------- Settings tabs ---------- */
.tab-row { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; color: var(--text-dim); padding: 10px 16px;
  cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 8px 6px 14px; font-size: 13px;
}
.chip button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px; }
.chip button:hover { color: var(--expense); }

.empty-state { color: var(--text-dim); font-size: 13px; padding: 24px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    padding: 10px 12px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { display: none; }
  .sidebar-footer { display: none; }
  .nav-item { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; padding: 8px 12px; }
  .nav-item.active { border-bottom-color: var(--accent); }
  .main { padding: 18px 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .row-2 { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; }
  .bar-label { width: 80px; }
}
