:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f7;
  --border: #e3e5ee;
  --text: #1c1e2b;
  --text-dim: #6b7080;
  --brand: #6366f1;
  --brand-dim: #eef0fe;
  --income: #16a34a;
  --income-dim: #eafaf0;
  --expense: #dc2626;
  --expense-dim: #fdeeee;
  --warn: #d97706;
  --warn-dim: #fef3e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 8px 24px rgba(20, 20, 40, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131c;
    --surface: #1a1c29;
    --surface-2: #21232f;
    --border: #2c2e3d;
    --text: #edeef5;
    --text-dim: #9b9fb3;
    --brand: #818cf8;
    --brand-dim: #262a44;
    --income: #4ade80;
    --income-dim: #17301f;
    --expense: #f87171;
    --expense-dim: #351d1f;
    --warn: #fbbf24;
    --warn-dim: #3a2c10;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { 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;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0 0 4px; }
p { margin: 0; }

.page-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 20px 64px;
}

/* ── Navbar ── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.navbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex; align-items: center; gap: 20px;
  flex-wrap: wrap;
}
.navbar-brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav-link {
  text-decoration: none; color: var(--text-dim); font-size: 14px;
  padding: 7px 12px; border-radius: 8px; font-weight: 600;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-dim); color: var(--brand); }
.navbar-user { display: flex; align-items: center; gap: 10px; }
.navbar-who { font-size: 13px; color: var(--text-dim); }

/* ── Cards / layout ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 800px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-bottom: 12px; }

.stat-label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }

/* ── Buttons / forms ── */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 9px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--expense); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

input, select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); border-radius: 9px; padding: 9px 11px; font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }
label { font-size: 13px; font-weight: 600; color: var(--text-dim); display: block; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

.error-text { color: var(--expense); font-size: 13px; margin-top: 8px; }
.hint-text { color: var(--text-dim); font-size: 13px; margin-top: 6px; }

/* ── Chips / badges ── */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-overdue { background: var(--expense-dim); color: var(--expense); }
.badge-soon { background: var(--warn-dim); color: var(--warn); }
.badge-ok { background: var(--income-dim); color: var(--income); }

/* ── Table / list rows ── */
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; font-size: 14px; }
.list-row-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.amount { font-weight: 700; font-size: 14px; white-space: nowrap; }
.amount.income { color: var(--income); }
.amount.expense { color: var(--expense); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-dim); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 10, 20, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 440px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 16px; }
.hidden { display: none !important; }

/* ── Auth page ── */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; font-size: 28px; margin-bottom: 4px; }
.auth-title { text-align: center; font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }
.auth-tabs { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; text-align: center; padding: 8px; border-radius: 8px; font-size: 13px; font-weight: 700;
  cursor: pointer; color: var(--text-dim);
  appearance: none; border: none; background: transparent; font-family: inherit;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

canvas { max-width: 100%; }
