:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #17212b);
  --hint: var(--tg-theme-hint-color, #708499);
  --card: var(--tg-theme-secondary-bg-color, #f1f4f7);
  --accent: var(--tg-theme-button-color, #2f81f7);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5534b;
  --ok: #2ea043;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0 12px 32px;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 6px;
  padding: 10px 0;
  background: var(--bg);
}
.tabs button {
  flex: 1;
  padding: 8px 0;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  color: var(--hint);
  font: inherit;
  font-size: 14px;
}
.tabs button.active { background: var(--accent); color: var(--accent-fg); }

.loading, .error { color: var(--hint); text-align: center; padding: 32px 0; }
.error { color: var(--danger); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.total { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.total-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.delta { font-size: 14px; font-weight: 600; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--ok); }
.sub { color: var(--hint); font-size: 13px; margin-top: 4px; }

.donut-wrap { display: flex; align-items: center; gap: 14px; }
.donut { flex: 0 0 132px; }

/* На узком экране кольцо и легенда рядом не помещаются — суммы обрезаются. */
@media (max-width: 430px) {
  .donut-wrap { flex-direction: column; align-items: stretch; gap: 10px; }
  .donut { align-self: center; }
}
.legend { flex: 1; min-width: 0; display: grid; gap: 7px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .val { font-variant-numeric: tabular-nums; }
.legend-row .pct { color: var(--hint); font-size: 12px; width: 34px; text-align: right; }

.bars { width: 100%; height: auto; display: block; }

.rows { display: grid; gap: 9px; }
.row { display: flex; align-items: center; gap: 10px; }
.row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value { font-variant-numeric: tabular-nums; font-weight: 600; }
.row .meta { color: var(--hint); font-size: 12px; }
.row.total-line { border-top: 1px solid rgba(127, 127, 127, .18); padding-top: 8px; }
.note { color: var(--hint); font-size: 12px; }

.bar-track { height: 6px; border-radius: 3px; background: rgba(127, 127, 127, .25); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--ok); }
.bar-fill.warn { background: #d9a406; }
.bar-fill.over { background: var(--danger); }

.tx { display: flex; gap: 10px; align-items: center; padding: 8px 0; border: 0;
      background: none; color: inherit; font: inherit; text-align: left; width: 100%; }
.tx + .tx { border-top: 1px solid rgba(127, 127, 127, .18); }
.tx .emoji { flex: none; width: 26px; font-size: 18px; }
.tx .body { flex: 1; min-width: 0; }
.tx .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .when { color: var(--hint); font-size: 12px; }
.tx .amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.tx .amount.income { color: var(--ok); }

.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; z-index: 20; }
.sheet.hidden { display: none; }
.sheet-body { width: 100%; max-height: 80vh; overflow-y: auto; background: var(--bg);
              border-radius: 16px 16px 0 0; padding: 14px 14px 24px; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.icon { border: 0; background: none; color: var(--hint); font-size: 18px; }

.chips.books { margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 14px; }
.chip { border: 0; border-radius: 9px; padding: 7px 11px; background: var(--card);
        color: inherit; font: inherit; font-size: 14px; }
.chip.active { background: var(--accent); color: var(--accent-fg); }
.btn { width: 100%; padding: 12px; border: 0; border-radius: 11px; font: inherit;
       font-weight: 600; background: var(--card); color: inherit; }
.btn.danger { color: var(--danger); }
