/* Денежка — мини-приложение. Цвета берутся из темы Telegram (--tg-theme-*), поверх — свой слой. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111214);
  --hint: var(--tg-theme-hint-color, #6b7078);
  --sep: rgba(127, 127, 127, .16);
  --accent: #14a84b;
  --accent-soft: rgba(29, 185, 84, .13);
  --accent-text: #fff;
  --red: #e5484d;
  --red-soft: rgba(229, 72, 77, .12);
  --yellow-soft: rgba(245, 166, 35, .16);
  --radius: 16px;
  --tabbar: 64px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}
html.dark { --accent: #2ed16b; --accent-soft: rgba(46, 209, 107, .16); --accent-text: #0b1a10;
  --bg: var(--tg-theme-secondary-bg-color, #0f1012); --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1c1f));
  --text: var(--tg-theme-text-color, #f2f3f5); --hint: var(--tg-theme-hint-color, #8d939b); --sep: rgba(255, 255, 255, .09); }
@media (prefers-color-scheme: dark) {
  html:not(.light) { --accent: #2ed16b; --accent-soft: rgba(46, 209, 107, .16); --accent-text: #0b1a10;
    --bg: var(--tg-theme-secondary-bg-color, #0f1012); --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1c1f));
    --text: var(--tg-theme-text-color, #f2f3f5); --hint: var(--tg-theme-hint-color, #8d939b); --sep: rgba(255, 255, 255, .09); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num, .amt { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.hint { color: var(--hint); }
.small { font-size: 13px; }
.red { color: var(--red); }
.green { color: var(--accent); }

#view { padding: calc(12px + var(--safe-top)) 12px calc(var(--tabbar) + var(--safe-bottom) + 24px); max-width: 640px; margin: 0 auto; }
h1 { font-size: 26px; margin: 6px 4px 12px; letter-spacing: -.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); font-weight: 600; margin: 20px 6px 8px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card.tight { padding: 4px 0; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Главная ---------- */
.hero { background: linear-gradient(140deg, #16b351, #0d8a3c); color: #fff; border-radius: 20px; padding: 18px 18px 16px; margin-bottom: 10px;
  box-shadow: 0 6px 20px rgba(20, 168, 75, .22); }
.hero.over { background: linear-gradient(140deg, #e5484d, #b8282d); box-shadow: 0 6px 20px rgba(229, 72, 77, .22); }
.hero .label { opacity: .88; font-size: 15px; }
.hero .big { font-size: 40px; font-weight: 700; margin: 2px 0 12px; letter-spacing: -.03em; }
.hero .sub { opacity: .9; font-size: 14px; margin-top: 8px; }
.hero .btn-ghost { background: rgba(255, 255, 255, .2); color: #fff; }
.bar { height: 8px; border-radius: 6px; background: var(--sep); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--accent); transition: width .2s; }
.bar.over > i { background: var(--red); }
.hero .bar { background: rgba(255, 255, 255, .28); }
.hero .bar > i { background: #fff; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.tile .v { font-size: 22px; font-weight: 650; margin-top: 2px; }
.ring { width: 52px; height: 52px; flex: none; }
.ring .bg { stroke: var(--sep); }
.ring .fg { stroke: var(--accent); transition: stroke-dashoffset .2s; }
.ring text { fill: var(--text); font-size: 15px; font-weight: 700; }
.tip { background: var(--accent-soft); }
.link { color: var(--accent); font-weight: 600; }
.pay-day { width: 46px; text-align: center; flex: none; font-size: 12px; color: var(--hint); line-height: 1.1; }
.pay-day b { display: block; font-size: 18px; color: var(--text); }

/* ---------- Списки ---------- */
.li { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px; position: relative; }
.li + .li::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--sep); }
.li.plain + .li.plain::before { left: 16px; }
.ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--accent-soft); flex: none; }
.ico.inc { background: rgba(29, 185, 84, .2); }
.li .t { font-weight: 550; }
.li .s { font-size: 13px; color: var(--hint); }
.li .a { font-weight: 650; white-space: nowrap; }
.a.plus { color: var(--accent); }
.chev::after { content: "›"; color: var(--hint); font-size: 22px; margin-left: 4px; }

/* ---------- История ---------- */
.search { display: flex; gap: 8px; margin-bottom: 8px; position: sticky; top: 0; z-index: 3; padding-top: 4px; background: var(--bg); }
.search input { flex: 1; min-width: 0; height: 42px; border-radius: 12px; border: 0; padding: 0 14px; background: var(--card); outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.hintbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.hintbar button { background: var(--yellow-soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.hintbar button.on { outline: 2px solid #f5a623; }
.day-h { display: flex; justify-content: space-between; padding: 14px 6px 6px; font-size: 13px; color: var(--hint); font-weight: 600; }
.swipe { position: relative; overflow: hidden; }
.swipe .under { position: absolute; inset: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; font-weight: 600; color: #fff; }
.swipe .under .l { background: var(--accent); }
.swipe .under.del { background: var(--red); justify-content: flex-end; }
.swipe .under.cat { background: var(--accent); justify-content: flex-start; }
.swipe .front { background: var(--card); position: relative; transition: transform .18s ease-out; touch-action: pan-y; }
.swipe .front.drag { transition: none; }
.sel .li { padding-left: 52px; }
.check { position: absolute; left: 16px; top: 50%; margin-top: -11px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--hint); }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: "✓"; color: #fff; font-size: 14px; display: block; text-align: center; line-height: 18px; }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 14px); width: 56px; height: 56px; border-radius: 28px; z-index: 20;
  background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 56px; text-align: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .22); }
.selbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 10px); z-index: 21; background: var(--card); border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); display: flex; gap: 8px; padding: 8px; align-items: center; max-width: 616px; margin: 0 auto; }
.selbar .grow { padding-left: 8px; font-weight: 600; }
.more { width: 100%; padding: 14px; color: var(--accent); font-weight: 600; }

/* ---------- Кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.block { width: 100%; }
.btn.sec { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Нижнее меню ---------- */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--card); border-top: 1px solid var(--sep);
  padding-bottom: var(--safe-bottom); height: calc(var(--tabbar) + var(--safe-bottom)); }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--hint); min-height: 48px; }
#tabs button i { font-style: normal; font-size: 22px; filter: grayscale(1); opacity: .7; transition: transform .15s; }
#tabs button.on { color: var(--accent); font-weight: 600; }
#tabs button.on i { filter: none; opacity: 1; transform: translateY(-1px) scale(1.06); }

/* ---------- Листы ---------- */
#sheets { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .18s; pointer-events: auto; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - 40px - var(--safe-top)); background: var(--bg); border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform .2s cubic-bezier(.2, .8, .2, 1); pointer-events: auto; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
.sheet.full { top: calc(var(--safe-top) + 8px); max-height: none; }
.sheet.in { transform: none; }
.backdrop.in { opacity: 1; }
.sheet-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.sheet-h b { flex: 1; font-size: 18px; }
.sheet-x { width: 36px; height: 36px; border-radius: 18px; background: var(--card); font-size: 18px; color: var(--hint); }
.sheet-b { overflow-y: auto; padding: 6px 12px 16px; -webkit-overflow-scrolling: touch; }
.sheet-f { padding: 8px 12px calc(10px + var(--safe-bottom)); }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 8px auto 0; }

/* ---------- Формы ---------- */
.field { display: block; background: var(--card); border-radius: 12px; padding: 8px 14px; margin-bottom: 8px; }
.field span { display: block; font-size: 12px; color: var(--hint); }
.field input, .field select, .field textarea { width: 100%; border: 0; background: transparent; outline: none; padding: 4px 0; min-height: 30px; }
.amount-in::placeholder { color: var(--hint); opacity: .5; }
.amount-in { font-size: 34px; font-weight: 700; text-align: center; border: 0; background: transparent; width: 100%; outline: none; padding: 6px 0; }
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 3px; margin-bottom: 10px; gap: 2px; }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.catgrid button { background: var(--card); border-radius: 12px; padding: 8px 2px; min-height: 70px; font-size: 11px; line-height: 1.15; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.catgrid button i { font-style: normal; font-size: 22px; }
.catgrid button.on { outline: 2px solid var(--accent); background: var(--accent-soft); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--sep); transition: background .15s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.split-row { display: grid; grid-template-columns: 1fr 1.3fr 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.split-row input, .split-row select { background: var(--card); border: 0; border-radius: 10px; height: 42px; padding: 0 10px; min-width: 0; }

/* ---------- Графики ---------- */
.donut-wrap { display: flex; justify-content: center; padding: 8px 0; }
.donut text { fill: var(--text); }
.bars text { fill: var(--hint); font-size: 10px; }
.legend-dot { width: 10px; height: 10px; border-radius: 5px; flex: none; }
.delta-up { color: var(--red); font-size: 13px; }
.delta-down { color: var(--accent); font-size: 13px; }

/* ---------- Прочее ---------- */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 12px); z-index: 60; display: flex; justify-content: center; pointer-events: none; }
#toast > div { background: #222; color: #fff; border-radius: 14px; padding: 12px 14px; display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  pointer-events: auto; animation: up .18s ease-out; max-width: 560px; width: 100%; }
#toast button { color: #4ee38a; font-weight: 700; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.skel { background: linear-gradient(90deg, var(--sep) 25%, rgba(127, 127, 127, .08) 50%, var(--sep) 75%); background-size: 200% 100%; animation: sk 1.2s infinite linear; border-radius: 12px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 34px 20px; color: var(--hint); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.empty .btn { margin-top: 14px; }
.flash { animation: flash .9s ease-out; }
@keyframes flash { 0% { background: rgba(255, 214, 10, .45); } 100% { background: transparent; } }
.banner { background: var(--yellow-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; font-size: 14px; }
.lock { text-align: center; padding: 26px 18px; }
.lock .e { font-size: 40px; }
.offline { position: fixed; top: calc(var(--safe-top) + 6px); left: 50%; transform: translateX(-50%); z-index: 70; background: #333; color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 10px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill.red { background: var(--red-soft); color: var(--red); }
input[type=range] { width: 100%; accent-color: var(--accent); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 700px) { .catgrid { grid-template-columns: repeat(6, 1fr); } }
