/* Mini App «Бюджет». Цвета берутся из темы Telegram, статусы и цвета групп заданы здесь. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --field: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #14171a);
  --hint: var(--tg-theme-hint-color, #6c747d);
  --accent: var(--tg-theme-button-color, #2b7a78);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(120, 128, 138, .22);
  --track: rgba(120, 128, 138, .18);
  --ok: #1f8a5b;
  --warn: #b97712;
  --bad: #c23b32;
  --radius: 14px;
  color-scheme: light;
}
html[data-scheme="dark"] {
  --ok: #4cc38a;
  --warn: #e8a838;
  --bad: #f06a5f;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
small, .hint { color: var(--hint); }
small { font-size: 12.5px; }

/* ---------- каркас */
#top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  display: flex; align-items: center; justify-content: space-between;
}
.mnav { width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; color: var(--hint); }
.mnav:active { background: var(--track); }
.mlabel { flex: 1; text-align: center; padding: 6px 4px; border-radius: 12px; line-height: 1.15; }
.mlabel b { font-size: 18px; font-weight: 650; display: block; }
.mlabel small { display: block; }
.mlabel:active { background: var(--track); }
#view { padding: 4px 12px calc(88px + env(safe-area-inset-bottom, 0px)); max-width: 640px; margin: 0 auto; }
.loading, .fatal { text-align: center; color: var(--hint); padding: 48px 16px; }
.fatal b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#tabs button { padding: 8px 4px 7px; display: grid; justify-items: center; gap: 2px; font-size: 11.5px; color: var(--hint); }
#tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }
#tabs svg, .ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- карточки и строки */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; font-weight: 650; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 7px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row.total { font-weight: 650; }
.pos { color: var(--ok); } .neg { color: var(--bad); } .warn { color: var(--warn); }
.chip { display: inline-block; font-size: 12px; line-height: 1; padding: 4px 8px; border-radius: 99px; white-space: nowrap;
  background: var(--track); color: var(--hint); font-weight: 550; }
.chip.ok { background: rgba(31, 138, 91, .14); color: var(--ok); }
.chip.warn { background: rgba(185, 119, 18, .16); color: var(--warn); }
.chip.bad { background: rgba(194, 59, 50, .14); color: var(--bad); }
@supports (background: color-mix(in srgb, red 10%, transparent)) {
  .chip.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); }
  .chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); }
  .chip.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); }
}
.empty { text-align: center; padding: 22px 8px; color: var(--hint); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; font-size: 16px; }

/* ---------- полоса месяца: факт и цель друг под другом */
.bars { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 6px 8px; margin: 2px 0 12px; }
.bars small { text-align: left; }
.bar { height: 16px; border-radius: 8px; background: var(--track); display: flex; overflow: hidden; gap: 2px; }
.bar.thin { height: 7px; border-radius: 4px; }
.bar i { display: block; height: 100%; min-width: 0; }
.bar.thin i { opacity: .5; }
.grow { display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 4px 10px; padding: 8px 0; }
.grow + .grow { border-top: 1px solid var(--line); }
.dot { width: 12px; height: 12px; border-radius: 4px; }
.gname small { display: block; }
.gdev { min-width: 64px; text-align: right; font-size: 13.5px; }
.fix { grid-column: 2 / -1; font-size: 13.5px; }
.note { font-size: 13.5px; color: var(--hint); margin: 8px 0 0; }

/* ---------- расход по группам */
.group { border-top: 1px solid var(--line); }
.group:first-of-type { border-top: 0; }
.ghead { width: 100%; text-align: left; padding: 10px 0; display: grid; gap: 6px; }
.ghead .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; }
.cats { padding: 0 0 8px 12px; display: grid; gap: 8px; }
.crow { display: grid; gap: 4px; font-size: 14.5px; }
.crow .top { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- формы */
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; color: var(--hint); }
input[type="text"], input[type="date"], input[type="number"], input:not([type]) {
  width: 100%; background: var(--field); border: 1px solid transparent; border-radius: 10px; padding: 11px 12px; min-height: 44px;
}
input:focus { outline: none; border-color: var(--accent); }
.amount { display: flex; align-items: baseline; gap: 8px; background: var(--field); border-radius: 12px; padding: 4px 14px; margin-bottom: 12px; }
.amount input { background: none; border: 0; font-size: 30px; font-weight: 650; padding: 8px 0; min-height: 0; flex: 1; min-width: 0; }
.amount span { font-size: 20px; color: var(--hint); }
.cgroup { margin-bottom: 10px; }
.cgroup > small { display: block; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cat { padding: 8px 12px; border-radius: 12px; background: var(--field); border: 1px solid transparent; text-align: left; line-height: 1.2; min-height: 44px; }
.cat small { display: block; }
.cat[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.cat[aria-pressed="true"] small { color: inherit; opacity: .85; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: block; width: 100%; padding: 13px 16px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; text-align: center; min-height: 46px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--field); color: var(--text); font-weight: 550; }
.btn.small { padding: 9px 12px; min-height: 40px; font-size: 14.5px; width: auto; }
.btn.danger { background: none; color: var(--bad); font-weight: 550; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.btns .btn { flex: 1 1 auto; }

/* ---------- списки */
.dayhead { font-size: 13px; color: var(--hint); padding: 10px 2px 4px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.item + .item { border-top: 1px solid var(--line); }
.item .main { flex: 1; min-width: 0; }
.item .main div { overflow: hidden; text-overflow: ellipsis; }
.item .amt { text-align: right; font-weight: 600; }
.iconbtn { width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; color: var(--hint); flex: none; }
.iconbtn:active { background: var(--track); }
.rcard { width: 100%; text-align: left; display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 14px; }
.rcard .chips { margin-top: 6px; }

/* ---------- нижний лист */
#sheet { position: fixed; inset: 0; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: fade .18s ease-out; }
.panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 94dvh; max-height: 94vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0; animation: rise .22s ease-out; max-width: 640px; margin: 0 auto; }
.phead { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 6px 18px; }
.phead b { font-size: 17px; }
.pbody { overflow-y: auto; padding: 6px 12px 12px; overscroll-behavior: contain; }
.pfoot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--line); display: grid; gap: 8px; }
.pfoot .sum { display: flex; justify-content: space-between; align-items: center; }
.arow { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; }
.arow + .arow { border-top: 1px solid var(--line); }
.step { display: flex; align-items: center; gap: 4px; }
.step button { width: 40px; height: 40px; border-radius: 12px; background: var(--field); font-size: 20px; line-height: 1; }
.step input { width: 66px; text-align: center; padding: 8px 4px; }
.mrow { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 14px 6px; text-align: left; }
.mrow + .mrow { border-top: 1px solid var(--line); }
.mrow[aria-current="true"] { color: var(--accent); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 8px); z-index: 30;
  background: #1d2125; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14.5px; max-width: 90vw; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #8f2a23; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
