/* ===== Design tokens (см. dataviz skill: references/palette.md) ===== */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --card: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --baseline: #c3c2b7;

  --accent: #2a78d6;
  --accent-track: #cde2fb;
  --income: #008300;
  --expense: #e34948;
  --success-text: #006300;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius-card: 16px;
  --radius-bar: 4px;
  --shadow-card: 0 1px 2px rgba(11,11,11,0.04), 0 4px 16px rgba(11,11,11,0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --card: #221f1f;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255,255,255,0.10);
    --baseline: #383835;

    --accent: #3987e5;
    --accent-track: #184f95;
    --income: #008300;
    --expense: #e66767;
    --success-text: #0ca30c;
    --shadow-card: 0 1px 2px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --card: #221f1f;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255,255,255,0.10);
  --baseline: #383835;

  --accent: #3987e5;
  --accent-track: #184f95;
  --income: #008300;
  --expense: #e66767;
  --success-text: #0ca30c;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 84px;
  min-height: 100vh;
}

a { color: inherit; }

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px 8px;
}

/* ---------- Header ---------- */
.app-header {
  padding: 18px 16px 8px;
  max-width: 560px;
  margin: 0 auto;
}
.app-header__title {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}
.hero-figure {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero-figure__currency {
  font-size: 20px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-left: 4px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 10px;
}

/* ---------- Stat tiles ---------- */
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-tile {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}
.stat-tile__label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.stat-tile__value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
}
.stat-tile__value.income { color: var(--success-text); }
.stat-tile__value.expense { color: var(--expense); }

/* ---------- Nav (bottom tab bar) ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 4px calc(env(safe-area-inset-bottom, 0px) + 6px);
  z-index: 20;
}
.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 10.5px;
  color: var(--text-muted);
  background: none;
  border: none;
  font-family: inherit;
}
.tabbar__item .icon { font-size: 20px; }
.tabbar__item.active { color: var(--accent); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: 78px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 56px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(42,120,214,0.4);
  z-index: 21;
}

/* ---------- Lists ---------- */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
}
.list-row:last-child { border-bottom: none; }
.list-row__main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.list-row__icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--page);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.list-row__title { font-size: 14.5px; font-weight: 500; }
.list-row__sub { font-size: 12px; color: var(--text-muted); }
.list-row__amount { font-size: 14.5px; font-weight: 600; white-space: nowrap; }
.list-row__amount.income { color: var(--success-text); }
.list-row__amount.expense { color: var(--text-primary); }
.list-row__del {
  background: none; border: none; color: var(--text-muted);
  font-size: 15px; padding: 4px 6px; flex-shrink: 0;
}

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

/* ---------- Meter (budgets / credits) ---------- */
.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--accent-track);
  overflow: hidden;
  margin: 6px 0 4px;
}
.meter__fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .3s ease;
}
.meter__fill.warning { background: var(--status-warning); }
.meter__fill.critical { background: var(--status-critical); }
.meter-row__top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13.5px;
}
.meter-row__legend {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-muted);
}

/* ---------- Bar chart (horizontal, category breakdown) ---------- */
.barlist__row { margin-bottom: 10px; }
.barlist__label {
  display: flex; justify-content: space-between;
  font-size: 13px; margin-bottom: 4px;
}
.barlist__track {
  height: 20px;
  background: var(--page);
  border-radius: var(--radius-bar);
  overflow: hidden;
}
.barlist__fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-bar);
  min-width: 4px;
}

/* ---------- Grouped bar chart (monthly trend) ---------- */
.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 160px;
  padding-top: 8px;
  border-bottom: 1px solid var(--baseline);
}
.trend-chart__group {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 100%;
  position: relative;
}
.trend-chart__plot { position: relative; }
.trend-chart__max {
  position: absolute; left: 0; right: 0; top: 8px;
  border-top: 1px dashed var(--baseline); pointer-events: none;
}
.trend-chart__max span {
  position: absolute; top: -8px; left: 0; padding-right: 6px;
  font-size: 10.5px; color: var(--text-muted); background: var(--card);
}
.trend-chart__col {
  position: relative; display: flex; align-items: flex-end;
  height: 100%;
}
.trend-chart__value {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  margin-bottom: 2px; font-size: 10px; white-space: nowrap;
  color: var(--text-secondary, var(--text-muted)); font-variant-numeric: tabular-nums;
}
.trend-chart__col { height: 100%; }
.trend-chart__labels span.is-current { color: var(--text-primary); font-weight: 600; }
.trend-chart__bar {
  width: 10px;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}
.trend-chart__bar.income { background: var(--income); }
.trend-chart__bar.expense { background: var(--expense); }
.trend-chart__labels {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.trend-chart__labels span {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}
.legend {
  display: flex;
  gap: 16px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 10px;
}
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend__swatch.income { background: var(--income); }
.legend__swatch.expense { background: var(--expense); }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex;
  background: var(--page);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 12px;
}
.segmented__item {
  flex: 1;
  border: none;
  background: none;
  padding: 7px 4px;
  font-size: 13px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: inherit;
}
.segmented__item.active {
  background: var(--card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(11,11,11,0.08);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  width: 100%;
  background: var(--accent);
  color: #fff;
}
.btn.secondary {
  background: var(--page);
  color: var(--text-primary);
}
.btn.danger {
  background: var(--status-critical);
  color: #fff;
}
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
}
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.type-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
}
.type-toggle button.active.income { background: var(--income); color: #fff; border-color: transparent; }
.type-toggle button.active.expense { background: var(--expense); color: #fff; border-color: transparent; }

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chip {
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--page);
  font-size: 13.5px;
  color: var(--text-primary);
  font-family: inherit;
}
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- Modal / bottom sheet ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 30;
  display: flex;
  align-items: flex-end;
}
.modal-overlay[hidden] { display: none; }
.modal-sheet {
  background: var(--card);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
}
.modal-sheet__handle {
  width: 36px; height: 4px;
  background: var(--gridline);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.modal-sheet__title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 16px;
}

/* ---------- Alert banner ---------- */
.banner {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.banner.warning { background: color-mix(in srgb, var(--status-warning) 18%, var(--card)); color: var(--text-primary); }
.banner.critical { background: color-mix(in srgb, var(--status-critical) 16%, var(--card)); color: var(--text-primary); }

.section-title {
  font-size: 14px;
  font-weight: 700;
  margin: 18px 4px 8px;
}

.small-muted { font-size: 12px; color: var(--text-muted); }

.credit-card { margin-bottom: 12px; }
.credit-card__name { font-size: 15.5px; font-weight: 700; margin-bottom: 2px; }
.credit-card__row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.credit-card.closed { opacity: 0.6; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--status-good) 18%, var(--card));
  color: var(--success-text);
}

.loading, .toast {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px;
}

.toast-fixed {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--page);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.legend__note{margin-left:auto;color:var(--text-muted)}
