@font-face { font-family: "Unbounded"; font-weight: 500; font-display: swap;
  src: url(fonts/unbounded-cyrillic-500-normal.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Unbounded"; font-weight: 500; font-display: swap;
  src: url(fonts/unbounded-latin-500-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20BD, U+20B8, U+2122, U+2212, U+2215; }
@font-face { font-family: "Unbounded"; font-weight: 700; font-display: swap;
  src: url(fonts/unbounded-cyrillic-700-normal.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Unbounded"; font-weight: 700; font-display: swap;
  src: url(fonts/unbounded-latin-700-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20BD, U+20B8, U+2122, U+2212, U+2215; }

:root {
  /* цвета темы Telegram (SDK выставляет --tg-theme-*), запасные — для браузера */
  --page: var(--tg-theme-secondary-bg-color, #efeff3);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15151a);
  --hint: var(--tg-theme-hint-color, #8a8a94);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 140, .22));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);

  --iris: #5b5bd6;
  --iris-soft: rgba(91, 91, 214, .12);
  --plus: #12a150;
  --minus: #e5484d;

  --num: "Unbounded", ui-rounded, system-ui, sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Roboto", "Segoe UI", system-ui, sans-serif;
  --r-group: 14px;
  --pad: 16px;
  --bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}
:root[data-scheme="dark"] {
  --iris: #8d8df7;
  --iris-soft: rgba(141, 141, 247, .16);
  --plus: #3dd68c;
  --minus: #ff6369;
  --page: var(--tg-theme-secondary-bg-color, #0f0f12);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c21));
  --text: var(--tg-theme-text-color, #f2f2f5);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body {
  font: 15px/1.4 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--iris); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }

#app { padding-bottom: calc(var(--bottom) + 24px); max-width: 560px; margin: 0 auto; }

/* ---------- главный экран: баланс и график ---------- */
.hero {
  background: var(--surface);
  padding: calc(var(--pad) + var(--tg-content-safe-area-inset-top, 0px)) 0 14px;
  border-radius: 0 0 24px 24px;
}
.hero-top { display: flex; justify-content: space-between; align-items: center; padding: 0 var(--pad); }
.hero-label { color: var(--hint); font-size: 14px; }
.chip-btn {
  font-size: 13px; color: var(--hint); padding: 4px 10px; border-radius: 99px; background: var(--page);
}
.hero-amount {
  display: block; padding: 6px var(--pad) 0; font-family: var(--num); font-weight: 700;
  font-size: 44px; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums;
  white-space: nowrap; transition: color .2s;
}
.hero-amount.scrubbing { color: var(--iris); }
.hero-delta { margin: 6px var(--pad) 0; font-size: 14px; color: var(--hint); min-height: 20px; }
.hero-delta b { font-weight: 600; }

.chart { position: relative; height: 168px; margin-top: 10px; touch-action: pan-y; user-select: none; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .line { fill: none; stroke: var(--iris); stroke-width: 2.25; stroke-linejoin: round; }
.chart .zero { stroke: var(--sep); stroke-dasharray: 3 4; }
.chart .cursor { stroke: var(--iris); stroke-width: 1; opacity: .5; }
.chart .dot { fill: var(--surface); stroke: var(--iris); stroke-width: 2.5; }
.chart .axis { fill: var(--hint); font-size: 11px; }
.chart.draw .line { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.1s cubic-bezier(.3, .7, .2, 1) forwards; }
.chart.draw .area { opacity: 0; animation: fade .6s .7s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 1; } }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--hint); font-size: 14px; padding: 0 32px; text-align: center; }

.segmented {
  display: flex; gap: 2px; margin: 12px var(--pad) 0; padding: 3px; border-radius: 11px; background: var(--page);
}
.segmented button {
  flex: 1; padding: 7px 4px; border-radius: 8px; font-size: 13px; color: var(--hint); white-space: nowrap;
}
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented.small { margin-top: 0; }

.split { display: flex; gap: 18px; margin: 6px var(--pad) 0; font-size: 13px; color: var(--hint); }
.split b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- группы, как в настройках Telegram ---------- */
.group { background: var(--surface); border-radius: var(--r-group); margin: 0 12px; overflow: hidden; }
.group-title { font-size: 13px; font-weight: 400; color: var(--hint); margin: 22px 28px 7px; }
.group-note { font-size: 13px; color: var(--hint); margin: 8px 28px 0; line-height: 1.45; }
.page-title { font: 700 24px/1.2 var(--num); letter-spacing: -.02em; margin: 0; padding: calc(20px + var(--tg-content-safe-area-inset-top, 0px)) 24px 14px; }

.totals { display: grid; grid-template-columns: 1fr 1fr; margin-top: 14px; }
.totals > div { padding: 14px var(--pad); }
.totals > div + div { border-left: 1px solid var(--sep); }
.totals span { display: block; color: var(--hint); font-size: 13px; }
.totals .num { font-size: 19px; font-weight: 500; display: block; margin-top: 2px; }
.totals .avg { grid-column: 1 / -1; border-top: 1px solid var(--sep); border-left: 0 !important; padding: 11px var(--pad); color: var(--hint); font-size: 13px; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 9px var(--pad);
  text-align: left; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--pad); border-top: 1px solid var(--sep); }
.row:has(.icon) + .row::before { left: 64px; }
.row-main { flex: 1; min-width: 0; }
.row-value { color: var(--hint); font-size: 14px; white-space: nowrap; }
.row-value.tab { font-variant-numeric: tabular-nums; color: var(--text); }
.row-btn:active { background: var(--page); }
.row.danger .row-main { color: var(--danger); }

.icon {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: none;
  font-size: 18px; background: var(--page);
}
.row-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { text-align: right; flex: none; }
.row-amount .num { font-size: 15px; font-weight: 500; display: block; }
.row-amount small { display: block; color: var(--hint); font-size: 12px; }

.badge {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: none;
  font: 700 10px/1 var(--num); letter-spacing: -.02em; color: var(--c, var(--iris));
  background: color-mix(in srgb, var(--c, var(--iris)) 14%, transparent);
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.addr-box { background: var(--page); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.addr-box .mono { flex: 1; }
.mini-btn { color: var(--iris); font-size: 14px; padding: 4px 2px; flex: none; }
.detect { font-size: 13px; color: var(--hint); min-height: 19px; margin: 8px 2px 0; }
.detect.ok { color: var(--plus); }
.detect.bad { color: var(--minus); }
.warn { color: var(--minus); }
.tag-btn { font-size: 12px; color: var(--iris); background: var(--iris-soft); padding: 3px 8px; border-radius: 7px; margin-top: 3px; display: inline-block; }
.switch {
  appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; flex: none;
  background: var(--sep); position: relative; cursor: pointer; transition: background .2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch:checked { background: var(--plus); }
.switch:checked::after { transform: translateX(18px); }
.sheet .group { background: var(--page); }
.field.mono { font: 14px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.chips-note { font-size: 13px; color: var(--hint); margin-top: 6px; }

.cat-bar { height: 4px; border-radius: 2px; background: var(--page); margin-top: 6px; overflow: hidden; }
.cat-bar i { display: block; height: 100%; background: var(--iris); border-radius: 2px; }

.day-head { display: flex; justify-content: space-between; margin: 20px 28px 7px; font-size: 13px; color: var(--hint); }
.day-head .num { font-size: 12px; }
.empty { padding: 28px 24px; text-align: center; color: var(--hint); font-size: 14px; line-height: 1.5; }
.link-btn { display: block; margin: 10px auto 0; padding: 10px 16px; color: var(--iris); font-size: 15px; }

/* ---------- нижняя панель и кнопка «+» ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--sep);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--hint); padding: 4px 10px; min-width: 64px; }
.tabbar button.on { color: var(--iris); }
.tabbar svg, .fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--bottom) + 14px); z-index: 11; width: 58px; height: 58px; border-radius: 20px;
  background: var(--iris); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px -6px color-mix(in srgb, var(--iris) 70%, transparent);
  transition: transform .15s;
}
.fab:active { transform: scale(.93); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

/* ---------- нижний лист ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .38); animation: fade .2s; opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; max-width: 560px; margin: 0 auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  animation: rise .28s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 8px auto 4px; }
.sheet-body { padding: 4px var(--pad) 0; }
.sheet h3 { font: 600 17px/1.3 var(--ui); margin: 6px 0 14px; text-align: center; }

.kind { margin: 0 0 16px; }
.kind button.on[data-kind="expense"] { color: var(--minus); }
.kind button.on[data-kind="income"] { color: var(--plus); }

.amount-field { display: flex; align-items: baseline; gap: 10px; padding: 4px 2px 0; }
.amount-field input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--text); outline: none;
  font: 700 40px/1.15 var(--num); letter-spacing: -.03em; padding: 0;
}
.amount-field input::placeholder { color: var(--sep); }
.cur-btn { font: 600 16px var(--ui); color: var(--iris); background: var(--iris-soft); padding: 7px 12px; border-radius: 10px; }
.cur-static { background: none; color: var(--hint); }
.conv { font-size: 13px; color: var(--hint); min-height: 19px; margin: 4px 2px 12px; }

.field {
  width: 100%; border: 0; outline: none; border-radius: 12px; background: var(--page); color: var(--text);
  font: 16px var(--ui); padding: 13px 14px;
}
.field:focus { box-shadow: inset 0 0 0 1.5px var(--iris); }
.label { display: block; font-size: 13px; color: var(--hint); margin: 16px 2px 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips button {
  padding: 7px 11px; border-radius: 10px; background: var(--page); font-size: 14px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.chips button.on { background: var(--iris); color: #fff; }
.chips input[type="date"] { border: 0; background: var(--page); color: var(--text); border-radius: 10px; padding: 6px 10px; font: 14px var(--ui); }

.primary {
  display: block; width: 100%; margin-top: 22px; padding: 15px; border-radius: 14px;
  background: var(--iris); color: #fff; font-weight: 600; font-size: 16px;
}
.primary:disabled { opacity: .45; }
.secondary { display: block; width: 100%; margin-top: 8px; padding: 13px; border-radius: 14px; color: var(--danger); font-size: 15px; }

.pick-list .row { min-height: 46px; }
.pick-list .row.on .row-value { color: var(--iris); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 18px); z-index: 30; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); animation: fade .2s;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .chart.draw .line { stroke-dasharray: none; stroke-dashoffset: 0; }
  .chart.draw .area { opacity: 1; }
}
