:root {
  --bg: var(--tg-theme-bg-color, #1a1a2e);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #16213e);
  --text: var(--tg-theme-text-color, #eaeaea);
  --hint: var(--tg-theme-hint-color, #8a8a9a);
  --accent: var(--tg-theme-button-color, #4f8ef7);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e05a5a;
  --success: #4caf7d;
  --warning: #f0a500;
  --card-bg: rgba(255,255,255,0.06);
  --radius: 14px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
}

/* ── Навигация ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 22px; height: 22px; }

/* ── Страницы ── */
.page {
  display: none;
  padding: 16px 16px 90px;
  max-width: 480px;
  margin: 0 auto;
}
.page.active { display: block; }

/* ── Карточки ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-card .label { font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; }
.stat-card .value.green { color: var(--success); }
.stat-card .value.red { color: var(--danger); }

/* ── Секции ── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 20px 0 8px;
}

/* ── Прогресс-бар ── */
.progress-wrap { margin-bottom: 12px; }
.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}
.progress-header .cat-name { font-weight: 500; }
.progress-header .cat-pct { color: var(--hint); }
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.progress-fill.danger { background: var(--danger); }
.progress-fill.warning { background: var(--warning); }
.progress-sub {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--hint);
  margin-top: 3px;
}

/* ── Транзакции ── */
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.08);
}
.tx-info { flex: 1; min-width: 0; }
.tx-cat { font-size: 14px; font-weight: 500; }
.tx-meta { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-weight: 600; font-size: 15px; white-space: nowrap; }
.tx-amount.expense { color: var(--danger); }
.tx-amount.income { color: var(--success); }

/* ── Источники ── */
.source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.source-row:last-child { border-bottom: none; }
.source-name { font-weight: 500; }
.source-amounts { text-align: right; font-size: 13px; }
.source-balance { font-weight: 700; }
.source-balance.green { color: var(--success); }
.source-balance.red { color: var(--danger); }

/* ── Цели ── */
.goal-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.goal-header { display: flex; justify-content: space-between; margin-bottom: 8px; }
.goal-name { font-weight: 600; }
.goal-pct { color: var(--accent); font-weight: 700; }
.goal-amounts { font-size: 12px; color: var(--hint); margin-top: 4px; }

/* ── Чарт ── */
.chart-wrap {
  height: 160px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 0 4px;
}
.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  height: 100%;
  justify-content: flex-end;
}
.chart-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 130px;
  width: 100%;
  justify-content: center;
}
.bar {
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  width: 12px;
  transition: height 0.5s ease;
}
.bar.income-bar { background: var(--success); }
.bar.expense-bar { background: var(--accent); }
.chart-label { font-size: 10px; color: var(--hint); text-align: center; }

/* ── ИИ-чат ── */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--card-bg);
  border-bottom-left-radius: 4px;
}
.msg.loading { color: var(--hint); font-style: italic; }
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
}
.chat-input {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 22px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.chat-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Кнопки ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--card-bg); color: var(--text); }

/* ── Форма расхода ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.field { margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--hint); display: block; margin-bottom: 5px; }
.field input, .field select {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.field select option { background: var(--bg-secondary); }

/* ── Фильтры ── */
.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--hint);
  font-size: 13px;
  cursor: pointer;
}
.filter-chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

/* ── Лоадер ── */
.loader { text-align: center; color: var(--hint); padding: 32px; }

/* ── Utility ── */
.text-green { color: var(--success); }
.text-red { color: var(--danger); }
.text-hint { color: var(--hint); font-size: 13px; }
.mt-4 { margin-top: 4px; }
.bold { font-weight: 700; }
