/* Палитра приходит из tg.themeParams (см. app.js applyTheme).
   Значения ниже — дефолты для обычного браузера вне Telegram. */
:root {
  --bg: #ffffff;
  --text: #000000;
  --hint: #707579;
  --link: #3390ec;
  --button: #3390ec;
  --button-text: #ffffff;
  --secondary-bg: #f4f4f5;

  /* Расход и доход — приглушённые, не светофор */
  --expense: #c2705a;
  --income: #5a8a6e;
  --border: color-mix(in srgb, var(--hint) 22%, transparent);

  /* Шкала отступов кратна 4 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--s4) var(--s4) calc(var(--nav-h) + var(--s6));
  min-height: 100vh;
}

/* --- типографика --- */
.num { font-variant-numeric: tabular-nums; }

h1 { font-size: 20px; font-weight: 600; margin: 0 0 var(--s4); }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 var(--s3); }

.hint { color: var(--hint); font-size: 13px; }

/* --- переключатель месяца --- */
.month-switch {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s5);
}
.month-switch button {
  width: 44px; height: 44px;
  border: none; background: none; color: var(--link);
  font-size: 20px; cursor: pointer; border-radius: var(--radius-sm);
  transition: background 160ms;
}
.month-switch button:active { background: var(--secondary-bg); }
.month-switch button:disabled { opacity: .3; cursor: default; }
.month-switch .title { font-size: 17px; font-weight: 600; }

/* --- карточки --- */
.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: var(--s4);
  margin-bottom: var(--s4);
}

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.totals .cell { }
.totals .label { font-size: 12px; color: var(--hint); text-transform: lowercase; }
.totals .value { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.totals .wide { grid-column: 1 / -1; padding-top: var(--s3); border-top: 1px solid var(--border); }
.value.expense { color: var(--expense); }
.value.income { color: var(--income); }

/* --- список операций --- */
.op-list { display: flex; flex-direction: column; }
.op {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.op:last-child { border-bottom: none; }
.op .body { flex: 1; min-width: 0; }
.op .cat { font-size: 15px; }
.op .meta {
  font-size: 12px; color: var(--hint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.op .amount { font-weight: 600; white-space: nowrap; }

/* --- бары категорий --- */
.bar-row { padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.bar-row:last-child { border-bottom: none; }
.bar-head { display: flex; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.bar-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 200ms ease; }
.delta { font-size: 12px; }
.delta.up { color: var(--expense); }
.delta.down { color: var(--income); }

/* --- нижняя навигация --- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 10;
}
.nav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 48px;
  border: none; background: none; cursor: pointer;
  color: var(--hint); font-size: 10px;
  transition: color 160ms;
}
.nav button.active { color: var(--link); }
.nav button svg { width: 22px; height: 22px; }

/* --- фильтры --- */
.filters { display: flex; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s4); }
.chip {
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border); border-radius: 999px;
  background: none; color: var(--text);
  font-size: 13px; cursor: pointer; min-height: 32px;
  transition: all 160ms;
}
.chip.active { background: var(--link); color: var(--button-text); border-color: var(--link); }

/* --- состояния --- */
.skeleton {
  background: linear-gradient(90deg,
    var(--secondary-bg) 25%,
    color-mix(in srgb, var(--secondary-bg) 60%, var(--hint) 12%) 50%,
    var(--secondary-bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
  height: 16px; margin-bottom: var(--s2);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  * { transition: none !important; }
}

.empty, .error {
  text-align: center; padding: var(--s8) var(--s4); color: var(--hint);
}
.error { color: var(--expense); }
.error button {
  display: block; margin: var(--s4) auto 0;
  padding: var(--s2) var(--s5); min-height: 44px;
  background: var(--button); color: var(--button-text);
  border: none; border-radius: var(--radius-sm); cursor: pointer;
}

.screen { animation: fade 180ms ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.legend { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s4); }
.legend-item { display: flex; align-items: center; gap: var(--s2); font-size: 13px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chart-wrap { overflow-x: auto; }
