:root {
  --bg: #0c1226;
  --sidebar: #0a0f1e;
  --card: #111a38;
  --card-hover: #162044;
  --accent: #0e5ee0;
  --accent-2: #7a5cff;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #e2e8f0;
  --text-muted: #8892a8;
  --border: #1e293b;
  --topbar-bg: rgba(12, 18, 38, 0.85);
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --sidebar: #eef1f8;
  --card: #ffffff;
  --card-hover: #f7f9fd;
  --accent: #0e5ee0;
  --accent-2: #7a5cff;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --topbar-bg: rgba(244, 246, 251, 0.85);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100dvh; }

.sidebar {
  width: 240px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  padding: 20px 14px;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; color: #fff;
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-item .nav-ico { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; margin-left: 240px; display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.topbar-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.month-nav { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.month-label { font-weight: 700; font-size: 14px; min-width: 96px; text-align: center; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent; border: none; color: var(--text-muted);
  border-radius: 8px; font-size: 20px; line-height: 1;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }

.content { padding: 24px 28px 40px; flex: 1; }

/* ===== Bottom nav (mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--sidebar);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 20;
}
.bottom-nav .nav-item {
  flex-direction: column; gap: 3px;
  font-size: 10px; font-weight: 700;
  padding: 6px 4px; text-align: center;
  border-radius: 10px;
  min-width: 60px; flex-shrink: 0;
}
.bottom-nav .nav-item .nav-ico { width: 22px; height: 22px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 700; font-size: 14px;
  transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover { background: var(--card-hover); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: #1a6cf0; }
.btn-danger { background: transparent; border-color: rgba(239,68,68,.4); color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,.12); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon-only { padding: 8px; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.card:hover { background: var(--card-hover); box-shadow: var(--shadow); }
.card-title { font-size: 15px; font-weight: 700; color: var(--text-muted); margin-bottom: 14px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ===== Stat cards ===== */
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.stat-value.pos { color: var(--success); }
.stat-value.neg { color: var(--danger); }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.balance-hero { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.balance-hero.pos { color: var(--success); }
.balance-hero.neg { color: var(--danger); }

/* ===== Lists / tables ===== */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-ico {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 19px;
  background: rgba(128, 140, 170, 0.12);
  border: 1px solid var(--border);
}
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: var(--text-muted); }
.list-amount { font-weight: 800; font-size: 15px; white-space: nowrap; }
.list-amount.pos { color: var(--success); }
.list-amount.neg { color: var(--danger); }
.list-amount.pending { color: var(--warning); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}

/* ===== Forms ===== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { min-height: 70px; resize: vertical; }
.seg {
  display: flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.seg button {
  flex: 1; padding: 10px; background: transparent; border: none;
  color: var(--text-muted); font-weight: 700;
}
.seg button.active { background: var(--accent); color: #fff; }
.seg button.seg-income.active { background: var(--success); color: #04120a; }
.seg button.seg-expense.active { background: var(--danger); color: #fff; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 8, 20, 0.7);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 18px; letter-spacing: -0.02em; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 11px 20px; border-radius: 10px;
  font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

/* ===== Charts ===== */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.bar-group { flex: 1; display: flex; align-items: flex-end; gap: 4px; height: 100%; }
.bar { flex: 1; border-radius: 6px 6px 0 0; min-height: 2px; transition: height .3s; }
.bar.income { background: var(--success); }
.bar.expense { background: var(--danger); }
.bar-labels { display: flex; gap: 10px; margin-top: 8px; }
.bar-label { flex: 1; text-align: center; font-size: 11px; color: var(--text-muted); font-weight: 600; }

.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 180px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text); font-weight: 600; }
.legend-val { color: var(--text-muted); font-weight: 700; }

.progress { height: 9px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; transition: width .3s; }
.progress.ok > div { background: var(--success); }
.progress.warn > div { background: var(--warning); }
.progress.danger > div { background: var(--danger); }

/* ===== Empty state ===== */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty .empty-ico { font-size: 42px; margin-bottom: 10px; }

/* ===== Filters ===== */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters .input, .filters .select { width: auto; min-width: 140px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .bottom-nav { display: flex; }
  .content { padding: 16px 16px 100px; }
  .topbar { padding: 12px 16px; }
  .topbar-title { font-size: 18px; }
  .topbar-right { gap: 10px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .balance-hero { font-size: 36px; }
  .month-nav { order: -1; }
  #btn-add { padding: 10px 14px; }
}

@media (max-width: 380px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-right { width: 100%; justify-content: space-between; }
}
