:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #7b8794);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --red: #d64545;
  --green: #2e9d5b;
  --orange: #e08a1e;
  --line: rgba(127, 127, 127, 0.22);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); font: 16px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { min-height: 100vh; padding-bottom: 76px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.hide { display: none !important; }

/* шапка и вкладки */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.top .grow { flex: 1; min-width: 0; }
.top .biz { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { font-size: 13px; color: var(--hint); }
.back { border: 0; background: none; color: var(--link); font-size: 16px; padding: 4px 6px 4px 0; cursor: pointer; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg); border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabs button { flex: 1; border: 0; background: none; padding: 12px 4px 10px; color: var(--hint); font-size: 13px; cursor: pointer; }
.tabs button b { display: block; font-size: 20px; line-height: 1.1; font-weight: 400; }
.tabs button.on { color: var(--btn); font-weight: 600; }

/* блоки */
.wrap { padding: 12px 14px; }
.card { background: var(--bg); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h3 { font-size: 16px; margin-bottom: 8px; }
.muted { color: var(--hint); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.big { font-size: 30px; font-weight: 700; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.red { color: var(--red); } .green { color: var(--green); } .orange { color: var(--orange); }
.empty { text-align: center; color: var(--hint); padding: 28px 12px; }

/* список */
.list { background: var(--bg); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--bg2); color: var(--hint); margin-right: 4px; }
.badge.red { background: rgba(214, 69, 69, .14); color: var(--red); }
.badge.orange { background: rgba(224, 138, 30, .16); color: var(--orange); }
.badge.green { background: rgba(46, 157, 91, .14); color: var(--green); }
.badge.blue { background: rgba(36, 129, 204, .14); color: var(--link); }

/* формы */
input, select, textarea { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--btn); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--hint); margin: 10px 0 4px; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--btn); color: var(--btn-text); font-weight: 600; cursor: pointer; width: 100%; }
.btn.sec { background: var(--bg2); color: var(--text); }
.btn.red { background: var(--red); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.sm { width: auto; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.btns { display: flex; gap: 10px; } .btns .btn { flex: 1; }
.link { border: 0; background: none; color: var(--link); padding: 4px 0; cursor: pointer; font-size: 14px; }
.amount { font-size: 32px; font-weight: 700; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 20px; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.warn { background: rgba(224, 138, 30, .13); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--text); }
.err { background: rgba(214, 69, 69, .12); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

/* журнал записей */
.entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry.void .num { text-decoration: line-through; color: var(--hint); }
.bar { height: 8px; border-radius: 4px; background: var(--btn); }

/* нижнее окно */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; }
.sheet { background: var(--bg); width: 100%; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 18px; margin-bottom: 8px; }

.toast { position: fixed; left: 14px; right: 14px; bottom: 90px; background: #222; color: #fff; padding: 12px 14px; border-radius: 12px; z-index: 40; text-align: center; font-size: 14px; }
.center { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 14px; text-align: center; }
.center h1 { font-size: 22px; }
.banner { background: var(--orange); color: #fff; padding: 8px 14px; font-size: 14px; text-align: center; cursor: pointer; }
.fab { position: fixed; right: 16px; bottom: 84px; z-index: 7; border: 0; width: 56px; height: 56px; border-radius: 28px; background: var(--btn); color: var(--btn-text); font-size: 28px; box-shadow: 0 3px 10px rgba(0, 0, 0, .25); cursor: pointer; }
