/* ═══════════════════════════════════════════════════════════════
   Дизайн-система. Принципи: мінімум оздоблення, волосяні розділювачі
   замість важких карток, один акцентний колір, чітка типографічна
   іерархія. Кольори — з теми Telegram, із запасними значеннями.
   ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  --page:   var(--tg-theme-secondary-bg-color, #f2f2f5);
  --card:   var(--tg-theme-bg-color, #ffffff);
  --ink:    var(--tg-theme-text-color, #14161a);
  --ink-2:  var(--tg-theme-hint-color, #7d8189);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);

  --line:   color-mix(in oklab, var(--ink) 9%, transparent);
  --line-2: color-mix(in oklab, var(--ink) 5%, transparent);
  --fill:   color-mix(in oklab, var(--ink) 4%, transparent);

  --ok:   #1c9e6d;
  --warn: #d98a00;
  --bad:  #d94141;

  --bar: var(--accent);

  --r:    14px;
  --r-sm: 10px;
  --tap:  46px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --nav: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:  var(--tg-theme-secondary-bg-color, #15191e);
    --card:  var(--tg-theme-bg-color, #1e242b);
    --ink:   var(--tg-theme-text-color, #f2f4f7);
    --ink-2: var(--tg-theme-hint-color, #939aa4);
    --ok:   #2bb37e;
    --warn: #e0a021;
    --bad:  #e86a6a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:  var(--tg-theme-secondary-bg-color, #15191e);
  --card:  var(--tg-theme-bg-color, #1e242b);
  --ink:   var(--tg-theme-text-color, #f2f4f7);
  --ink-2: var(--tg-theme-hint-color, #939aa4);
  --ok:   #2bb37e;
  --warn: #e0a021;
  --bad:  #e86a6a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }

/* ─── каркас ───────────────────────────────────────────────── */

.app { min-height: 100%; padding: calc(var(--sat) + 4px) 0 calc(var(--nav) + var(--sab) + 92px); }
.wrap { max-width: 600px; margin: 0 auto; padding: 0 16px; }

.top {
  position: sticky; top: 0; z-index: 30;
  padding: 8px 16px 12px;
  background: color-mix(in oklab, var(--page) 86%, transparent);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
}
.top-row { display: flex; align-items: center; gap: 12px; min-height: 32px; }
.top h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.4px; }

/* перемикач місяця — текст, а не кнопки-стрілки */
.month { display: flex; align-items: center; gap: 4px; }
.month button {
  width: 30px; height: 30px; border-radius: 8px; color: var(--ink-2);
  display: grid; place-items: center; font-size: 17px;
}
.month button:active { background: var(--fill); }
.month .lbl { font-size: 14px; font-weight: 600; min-width: 74px; text-align: center; }

/* ─── групи та рядки ───────────────────────────────────────── */

.group { background: var(--card); border-radius: var(--r); overflow: hidden; margin-bottom: 14px; }
.pad { padding: 16px; }

h2.sec {
  margin: 22px 4px 8px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); letter-spacing: 0;
}
.sec-row { display: flex; align-items: baseline; margin: 22px 4px 8px; }
.sec-row h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.sec-row button { margin-left: auto; font-size: 13px; font-weight: 500; color: var(--accent); }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 16px; min-height: var(--tap); text-align: left;
  border-bottom: 1px solid var(--line-2);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--fill); }
.row.static:active { background: none; }

.rt { flex: 1; min-width: 0; }
.rt b { display: block; font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt small { display: block; margin-top: 2px; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val { font-weight: 550; font-variant-numeric: tabular-nums; white-space: nowrap; }
.val.neg { color: var(--bad); }
.val.pos { color: var(--ok); }
.chev { color: var(--ink-2); font-size: 18px; opacity: .5; }

/* кольорова крапка замість емодзі-іконки — тихіше й рівніше */
.dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: var(--accent); }
.emo { width: 26px; flex: 0 0 26px; text-align: center; font-size: 19px; line-height: 1; }

.muted { color: var(--ink-2); }
.sm { font-size: 13px; }
.xs { font-size: 12px; }
.nums { font-variant-numeric: tabular-nums; }
.flex { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.center { text-align: center; }
.right { text-align: right; }

/* ─── головне число ───────────────────────────────────────── */

.hero { padding: 20px 16px 18px; text-align: center; }
.hero .cap { font-size: 13px; color: var(--ink-2); }
.hero .big {
  margin: 6px 0 4px; font-size: 38px; font-weight: 680; letter-spacing: -1.4px;
  font-variant-numeric: tabular-nums; line-height: 1.05;
}
.hero .sub { font-size: 13px; color: var(--ink-2); }
.hero .big.neg { color: var(--bad); }

.trio { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line-2); }
.trio > div { padding: 12px 6px; text-align: center; border-left: 1px solid var(--line-2); }
.trio > div:first-child { border-left: 0; }
.trio .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trio .k { margin-top: 2px; font-size: 12px; color: var(--ink-2); }

/* ─── смуга прогресу ──────────────────────────────────────── */

.bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--bar); transition: width .4s ease; }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--bad); }
.bar.tall { height: 8px; border-radius: 4px; }

/* конверт: назва / суми / смуга */
.env { padding: 13px 16px; border-bottom: 1px solid var(--line-2); }
.env:last-child { border-bottom: 0; }
.env:active { background: var(--fill); }
.env-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.env-top .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env-top .amt { margin-left: auto; font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.env-top .amt b { color: var(--ink); font-weight: 600; }
.env-foot { margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.env-foot.over { color: var(--bad); }

/* ─── кнопки ──────────────────────────────────────────────── */

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); padding: 0 18px;
  border-radius: var(--r-sm); background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 600;
}
.btn:active { opacity: .82; }
.btn[disabled] { opacity: .4; }
.btn.soft { background: var(--fill); color: var(--ink); }
.btn.line { background: none; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: none; color: var(--bad); }
.btn.sm { min-height: 36px; width: auto; padding: 0 14px; font-size: 13.5px; }
.btns { display: flex; gap: 8px; }
.btns > * { flex: 1; }

/* плаваюча кнопка помічника */
.mic {
  position: fixed; right: 16px; z-index: 40;
  bottom: calc(var(--nav) + var(--sab) + 16px);
  height: 52px; padding: 0 20px; border-radius: 26px;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; gap: 9px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px color-mix(in oklab, var(--accent) 40%, transparent);
}
.mic:active { transform: scale(.96); }
.mic .g { font-size: 19px; }

/* ─── нижня навігація ─────────────────────────────────────── */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--sab);
  background: color-mix(in oklab, var(--card) 94%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-top: 1px solid var(--line-2);
}
.nav button {
  height: var(--nav); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); font-size: 11px; font-weight: 500; position: relative;
}
.nav button .g { font-size: 20px; line-height: 1.1; }
.nav button.on { color: var(--accent); font-weight: 600; }
.nav .badge {
  position: absolute; top: 7px; left: 50%; margin-left: 4px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--bad); color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 600;
}

/* ─── шторка ──────────────────────────────────────────────── */

.scrim { position: fixed; inset: 0; z-index: 60; background: rgb(0 0 0 / .4); opacity: 0; transition: opacity .2s; }
.scrim.on { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--page); border-radius: 18px 18px 0 0;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.32,.72,0,1);
  padding-bottom: var(--sab);
}
.sheet.on { transform: translateY(0); }
.sheet-hd { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; flex: 0 0 auto; }
.sheet-hd h3 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; }
.sheet-hd .x { width: 30px; height: 30px; border-radius: 15px; background: var(--fill); color: var(--ink-2); display: grid; place-items: center; font-size: 15px; }
.sheet-bd { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 16px; }
.sheet-ft { flex: 0 0 auto; padding: 12px 16px calc(12px + var(--sab)); background: var(--card); border-top: 1px solid var(--line-2); }

/* ─── форми ───────────────────────────────────────────────── */

.f { margin-bottom: 14px; }
.f > label { display: block; margin: 0 0 6px 2px; font-size: 13px; font-weight: 500; color: var(--ink-2); }

.in {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  outline: none; appearance: none; -webkit-appearance: none;
}
.in:focus { border-color: var(--accent); }
textarea.in { min-height: 84px; resize: vertical; line-height: 1.5; }

/* велике поле суми */
.amt-box { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 18px 16px; background: var(--card); border-radius: var(--r); margin-bottom: 14px; }
.amt-box input {
  width: 100%; min-width: 0; padding: 0; border: 0; background: none; outline: none;
  font-size: 42px; font-weight: 680; letter-spacing: -1.6px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.amt-box .cur { font-size: 17px; font-weight: 600; color: var(--ink-2); }

/* сегменти */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--fill); border-radius: var(--r-sm); }
.seg button { flex: 1; min-height: 38px; border-radius: 8px; font-size: 14px; font-weight: 550; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); }

/* чіпси */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 18px; background: var(--card);
  border: 1px solid var(--line-2); font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* вибір категорії списком, а не сіткою емодзі */
.picks { background: var(--card); border-radius: var(--r); overflow: hidden; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; border-bottom: 1px solid var(--line-2); text-align: left; }
.pick:last-child { border-bottom: 0; }
.pick.on { background: color-mix(in oklab, var(--accent) 10%, transparent); }
.pick .nm { flex: 1; font-weight: 500; }
.pick .tick { color: var(--accent); font-weight: 700; opacity: 0; }
.pick.on .tick { opacity: 1; }

/* галочка списку покупок */
.box { width: 24px; height: 24px; flex: 0 0 24px; border: 1.5px solid var(--line); border-radius: 12px; display: grid; place-items: center; color: transparent; font-size: 13px; font-weight: 700; }
.box.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.done b { text-decoration: line-through; color: var(--ink-2); }

/* ─── помічник ────────────────────────────────────────────── */

.ass-hint { padding: 4px 2px 12px; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.ass-hint code { background: var(--fill); padding: 2px 6px; border-radius: 5px; font-size: 12.5px; }

.ass-in { display: flex; gap: 8px; align-items: flex-end; }
.ass-in textarea { flex: 1; min-height: 46px; max-height: 120px; }

.rec-btn {
  width: 56px; height: 56px; flex: 0 0 56px; border-radius: 28px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 22px;
}
.rec-btn.live { background: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.07) } }

.bubble { padding: 13px 15px; border-radius: var(--r); background: var(--card); margin-bottom: 10px; line-height: 1.5; }
.bubble.me { background: var(--fill); }
.did { display: flex; align-items: flex-start; gap: 8px; padding: 9px 12px; background: color-mix(in oklab, var(--ok) 12%, transparent); border-radius: var(--r-sm); margin-bottom: 7px; font-size: 13.5px; }

.think { display: flex; gap: 5px; padding: 14px 0; justify-content: center; }
.think i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); animation: blink 1.2s infinite; }
.think i:nth-child(2) { animation-delay: .2s }
.think i:nth-child(3) { animation-delay: .4s }
@keyframes blink { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

/* ─── рецепт ──────────────────────────────────────────────── */

.ing { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); font-size: 14.5px; }
.ing:last-child { border-bottom: 0; }
.ing .q { margin-left: auto; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 0 0 16px 34px; line-height: 1.55; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -1px;
  width: 24px; height: 24px; border-radius: 12px; background: var(--fill);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700; color: var(--accent);
}
.steps li:last-child { padding-bottom: 0; }
.tip { padding: 12px 14px; background: color-mix(in oklab, var(--warn) 12%, transparent); border-radius: var(--r-sm); font-size: 13.5px; line-height: 1.5; }

/* ─── діаграми ────────────────────────────────────────────── */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line-2); stroke-width: 1; }
.chart .ax { fill: var(--ink-2); font-size: 9.5px; }
.chart .mk { fill: color-mix(in oklab, var(--accent) 22%, transparent); }
.chart .mk.on { fill: var(--accent); }
.chart .hit { fill: transparent; }
.tip-box {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -100%); opacity: 0; transition: opacity .12s;
  padding: 5px 9px; border-radius: 7px; background: var(--ink); color: var(--card);
  font-size: 11.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tip-box.on { opacity: 1; }

.legend { display: flex; justify-content: center; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.legend i { display: block; width: 9px; height: 9px; border-radius: 3px; }

/* таблиця-підстраховка до діаграми */
.tbl-h { display: flex; padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line-2); }

/* ─── дрібне ──────────────────────────────────────────────── */

.tag { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 12px; background: var(--fill); font-size: 12px; font-weight: 500; color: var(--ink-2); }
.tag.ok { background: color-mix(in oklab, var(--ok) 14%, transparent); color: var(--ok); }
.tag.warn { background: color-mix(in oklab, var(--warn) 16%, transparent); color: color-mix(in oklab, var(--warn) 85%, var(--ink)); }
.tag.bad { background: color-mix(in oklab, var(--bad) 14%, transparent); color: var(--bad); }

.empty { padding: 40px 24px; text-align: center; color: var(--ink-2); }
.empty b { display: block; margin-bottom: 6px; font-size: 15px; color: var(--ink); font-weight: 600; }
.empty span { font-size: 13.5px; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + var(--sab) + 84px); z-index: 90;
  transform: translate(-50%, 10px); opacity: 0; transition: all .2s; pointer-events: none;
  max-width: 88vw; padding: 11px 18px; border-radius: 22px;
  background: var(--ink); color: var(--card); font-size: 14px; font-weight: 550; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }

.skel { background: var(--line-2); border-radius: 8px; animation: sk 1.3s ease-in-out infinite; }
@keyframes sk { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

.view { animation: in .2s ease; }
@keyframes in { from { opacity: 0; transform: translateY(3px) } to { opacity: 1; transform: none } }

.day { display: flex; align-items: baseline; padding: 20px 4px 7px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.day .s { margin-left: auto; font-weight: 550; font-variant-numeric: tabular-nums; }

.gate { display: grid; place-items: center; min-height: 78vh; padding: 32px 26px; text-align: center; }
.gate .e { font-size: 50px; margin-bottom: 16px; }
.gate h2 { margin: 0 0 10px; font-size: 19px; }
.gate p { margin: 0 0 8px; color: var(--ink-2); line-height: 1.5; }
.gate code { background: var(--fill); padding: 3px 8px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
