:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btnfg: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --line: rgba(128, 128, 128, .25);
  --danger: #e5484d;
  --p: #3b82f6; --f: #f59e0b; --c: #10b981;
  --nav-h: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.35 system-ui, -apple-system, sans-serif; }
button { font: inherit; cursor: pointer; }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.hint { color: var(--hint); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; white-space: nowrap; }

/* ---------- навігація: знизу на телефоні, sidebar на десктопі ---------- */
.nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line); }
.nav .brand { display: none; }
.nav button { flex: 1; background: none; border: 0; color: var(--hint); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; padding: 6px 0; }
.nav .ico { font-size: 22px; line-height: 1; }
.nav .lbl { font-size: 11px; }
.nav button.active { color: var(--btn); font-weight: 600; }
main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
@media (min-width: 768px) {
  .nav { top: 0; right: auto; bottom: 0; width: 220px; height: auto; flex-direction: column; justify-content: flex-start;
    padding: 16px 10px; border-top: 0; border-right: 1px solid var(--line); gap: 4px; }
  .nav .brand { display: block; font-weight: 700; font-size: 20px; padding: 8px 12px 18px; }
  .nav button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: 10px; }
  .nav .lbl { font-size: 15px; }
  .nav button.active { background: var(--card); }
  main { margin-left: 220px; max-width: none; padding: 24px 32px; }
  .view { max-width: 720px; }
}

/* ---------- базові компоненти ---------- */
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.btn { background: var(--btn); color: var(--btnfg); border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--btn); border: 1px solid var(--btn); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.link { background: none; border: 0; color: var(--hint); padding: 6px 8px; }
.link.danger { color: var(--danger); }
input, select { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--fg); font-size: 16px; margin-bottom: 8px; }
label { display: block; font-size: 13px; color: var(--hint); margin: 4px 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { background: var(--card); border: 1px solid var(--line); color: var(--fg); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.active { background: var(--btn); color: var(--btnfg); border-color: var(--btn); }
.seg { display: flex; background: var(--card); border-radius: 10px; padding: 3px; margin-bottom: 8px; }
.seg button { flex: 1; border: 0; background: none; color: var(--fg); padding: 8px; border-radius: 8px; }
.seg button.active { background: var(--btn); color: var(--btnfg); }
.empty { text-align: center; color: var(--hint); padding: 24px 8px; }

.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--btn); border-radius: 4px; transition: width .3s; }
.bar.over > i { background: var(--danger); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.macro .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.macro.p .bar > i { background: var(--p); } .macro.f .bar > i { background: var(--f); } .macro.c .bar > i { background: var(--c); }
.big { font-size: 28px; font-weight: 700; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daynav .label { font-weight: 600; text-align: center; flex: 1; position: relative; }
.daynav .label input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; }
.daynav button { width: 44px; height: 40px; border-radius: 10px; border: 0; background: var(--card); color: var(--fg); font-size: 20px; }

.item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .name { overflow-wrap: anywhere; }
.pick { cursor: pointer; }
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet-body { position: relative; background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 17px; }
@media (min-width: 768px) { .sheet { align-items: center; } .sheet-body { border-radius: 18px; } }
.toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 18px); background: #222;
  color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; }
.toast[hidden] { display: none; }
svg text { fill: var(--hint); font-size: 10px; }
.chart { width: 100%; height: auto; display: block; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; text-align: center; }
.kpis b { display: block; font-size: 17px; }
