:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --pos: #2e9e5b;
  --neg: #e0453a;
  --loan: #8e6bd8;
  --warn: #e8a317;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17181c; --bg2: #232429; --text: #f2f2f2; --hint: #8b8d94;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid transparent;
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; }
input:focus { outline: none; border-color: var(--accent); }
h1 { font-size: 17px; margin: 0; text-transform: capitalize; }
h2 { font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase;
  letter-spacing: .04em; margin: 22px 0 8px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
  justify-content: space-between; padding: 10px 12px; background: var(--bg); }
.icon { font-size: 26px; width: 40px; height: 36px; border-radius: 10px; }
.icon:active { background: var(--bg2); }
main { padding: 0 16px; }
.tab { display: none; }
.tab.active { display: block; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { background: var(--bg2); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.card span { color: var(--hint); font-size: 13px; }
.card b { font-size: 19px; font-variant-numeric: tabular-nums; }
.card small { color: var(--hint); font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.hint { color: var(--hint); font-size: 13px; margin: 10px 2px 0; }
.hint.big { font-size: 15px; color: var(--text); }
.empty { color: var(--hint); text-align: center; padding: 28px 0; }

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row .head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.bar-row .head b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row .head small { color: var(--hint); font-weight: 400; }
.track { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.fill { height: 100%; border-radius: 4px; background: var(--accent); }
.fill.warn { background: var(--warn); } .fill.over { background: var(--neg); }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.trend .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; cursor: pointer; }
.trend .cols { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.trend .cols i { width: 30%; max-width: 12px; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend .m.cur span { color: var(--text); font-weight: 600; }
.trend span { font-size: 11px; color: var(--hint); }
.c-inc, .lg-inc { background: var(--pos); } .c-exp, .lg-exp { background: var(--neg); } .c-loan, .lg-loan { background: var(--loan); }
.legend { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--hint); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: -8px; }

.day { font-size: 13px; color: var(--hint); margin: 16px 0 4px; display: flex; justify-content: space-between; }
.tx { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--bg2); cursor: pointer; }
.tx .e { width: 36px; height: 36px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; flex: none; }
.tx .t { flex: 1; min-width: 0; }
.tx .t div:last-child { color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx b { font-variant-numeric: tabular-nums; white-space: nowrap; }

.form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--hint); }
.limit-row { display: flex; align-items: center; gap: 10px; }
.limit-row span { flex: 1; }
.limit-row input { width: 120px; text-align: right; }
.btn { background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 13px; font-weight: 600; width: 100%; }
.btn.danger { background: var(--bg2); color: var(--neg); }
input[type=range] { padding: 0; background: none; accent-color: var(--accent); }

.fab { position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); z-index: 6; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid var(--bg2); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabs button { flex: 1; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; font-size: 20px; opacity: .5; }
.tabs button span { font-size: 11px; }
.tabs button.active { opacity: 1; color: var(--accent); }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  max-height: 90vh; overflow-y: auto; }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 14px; }
.seg button.active { background: var(--bg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.amount { font-size: 30px; font-weight: 600; text-align: center; background: none; border: 0; padding: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { background: var(--bg2); border-radius: 16px; padding: 6px 10px; font-size: 14px; }
.chips button.active { background: var(--accent); color: var(--accent-text); }
.row { display: flex; gap: 8px; }
.row input[type=date] { flex: 0 0 150px; }

.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 20; background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); }
