:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #6d5dfc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: color-mix(in srgb, var(--hint) 18%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  --protein: #6d5dfc; --fat: #f59e0b; --carbs: #10b981; --water: #06b6d4;
  --g-hero: linear-gradient(135deg, #7c3aed 0%, #6d5dfc 38%, #3b82f6 100%);
  --g-weight: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  --g-kcal: linear-gradient(90deg, #f97316, #ec4899);
  --g-protein: linear-gradient(90deg, #8b5cf6, #6366f1);
  --g-fat: linear-gradient(90deg, #fbbf24, #f97316);
  --g-carbs: linear-gradient(90deg, #34d399, #10b981);
  --g-water: linear-gradient(90deg, #22d3ee, #3b82f6);
  --shadow: 0 6px 24px -10px rgba(30, 20, 80, .28);
  --r: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
body { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
#view { padding: 14px 14px 8px; max-width: 640px; margin: 0 auto; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--hint); } .small { font-size: 12px; }
.empty { color: var(--hint); text-align: center; padding: 26px 8px; }

/* появление */
.in { animation: rise .45s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i, 0) * 55ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .in { animation: none; } }

/* заглушки загрузки */
.sk { border-radius: var(--r); background: linear-gradient(90deg, var(--soft) 0%, color-mix(in srgb, var(--hint) 22%, transparent) 50%, var(--soft) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear; margin-bottom: 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* навигация — плавающая «пилюля» */
#tabs { position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; padding: 6px; border-radius: 24px; max-width: 520px; margin: 0 auto;
  background: color-mix(in srgb, var(--card) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.6); backdrop-filter: blur(18px) saturate(1.6);
  box-shadow: 0 10px 30px -12px rgba(0,0,0,.35), inset 0 0 0 1px var(--sep); }
#tabs button { flex: 1; border: 0; background: none; color: var(--hint); padding: 7px 0 5px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 600;
  transition: background .25s, color .25s, transform .15s; }
#tabs button:active { transform: scale(.94); }
#tabs button b { font-size: 20px; font-weight: normal; filter: grayscale(1); opacity: .55; transition: .25s; }
#tabs button.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
#tabs button.on b { filter: none; opacity: 1; transform: translateY(-1px); }

/* карточки */
.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--hint); letter-spacing: .02em;
  display: flex; justify-content: space-between; align-items: baseline; }
.card h3 span { font-weight: 600; color: var(--text); font-size: 13px; }

/* главная карточка с градиентом */
.hero { position: relative; overflow: hidden; border-radius: 26px; padding: 18px; margin-bottom: 12px; color: #fff;
  background: var(--g-hero); box-shadow: 0 18px 40px -18px rgba(99, 70, 255, .65); }
.hero.weight { background: var(--g-weight); box-shadow: 0 18px 40px -18px rgba(59, 130, 246, .6); }
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255,255,255,.35), transparent 70%); }
.hero::before { width: 220px; height: 220px; right: -70px; top: -90px; }
.hero::after { width: 160px; height: 160px; left: -60px; bottom: -80px; opacity: .6; }
.hero .top { display: flex; justify-content: space-between; align-items: center; position: relative; z-index: 1; }
.hero .big { font-size: 46px; font-weight: 800; line-height: 1; margin: 6px 0 2px; }
.hero .lbl { font-size: 13px; opacity: .85; font-weight: 600; }
.hero .sub { font-size: 13px; opacity: .85; }
.hero .chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; position: relative; z-index: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px; border-radius: 999px; font-size: 12.5px;
  font-weight: 700; background: rgba(255,255,255,.2); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.pill.dark { background: var(--soft); box-shadow: none; color: var(--text); }
.pill.good { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); box-shadow: none; }
.pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); box-shadow: none; }

/* большое кольцо в hero */
.bigring { position: relative; width: 118px; height: 118px; flex: none; }
.bigring svg { width: 118px; height: 118px; transform: rotate(-90deg); }
.bigring .c { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.bigring .c b { font-size: 24px; font-weight: 800; }
.bigring .c span { font-size: 11px; opacity: .85; font-weight: 600; }
.arc { transition: stroke-dashoffset 1.1s cubic-bezier(.2, .8, .2, 1); }

/* шапка дня */
.dayhead { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 12px; }
.dayhead .t { text-align: center; cursor: pointer; }
.dayhead h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.dayhead .sub { color: var(--hint); font-size: 12px; font-weight: 600; }
.arrow { border: 0; background: var(--card); color: var(--accent); width: 38px; height: 38px; border-radius: 14px;
  font-size: 20px; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s; }
.arrow:active { transform: scale(.9); }
.arrow:disabled { opacity: .25; box-shadow: none; }

/* полоски БЖУ и воды */
.meter { margin-bottom: 13px; } .meter:last-child { margin-bottom: 0; }
.meter .h { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 6px; }
.meter .h b { font-weight: 700; } .meter .h span { color: var(--hint); font-size: 12.5px; }
.track { height: 10px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 99px; transition: width 1s cubic-bezier(.2, .8, .2, 1); }
.fill.over { background: linear-gradient(90deg, #f87171, #ef4444) !important; }

/* быстрые кнопки — лента */
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; margin: 0 -2px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.qbtn { flex: none; border: 0; background: var(--card); color: var(--text); border-radius: 16px; padding: 10px 13px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); cursor: pointer; transition: transform .15s; white-space: nowrap; }
.qbtn:active { transform: scale(.93); }
.qbtn i { font-style: normal; margin-right: 5px; }

/* лента еды */
.tl { position: relative; }
.tl .it { display: flex; gap: 12px; padding: 10px 0; cursor: pointer; position: relative; }
.tl .it + .it { border-top: 1px solid var(--sep); }
.tl .tm { width: 40px; flex: none; font-size: 12px; color: var(--hint); font-weight: 600; padding-top: 2px; }
.tl .badge { width: 34px; height: 34px; flex: none; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; }
.tl .main { flex: 1; min-width: 0; }
.tl .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl .mbar { display: flex; height: 5px; border-radius: 5px; overflow: hidden; margin-top: 6px; background: var(--soft); width: 100%; }
.tl .mbar i { display: block; height: 100%; }
.tl .meta { color: var(--hint); font-size: 11.5px; margin-top: 4px; }
.tl .kc { font-weight: 800; font-size: 15px; white-space: nowrap; text-align: right; }
.tl .kc span { display: block; font-size: 10px; color: var(--hint); font-weight: 600; }

/* обычные строки */
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--sep); }
.row:first-of-type { border-top: 0; }
.row.tap { cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .sub { color: var(--hint); font-size: 12px; }
.row .val { font-weight: 700; white-space: nowrap; }
.row .ico { width: 34px; height: 34px; border-radius: 12px; background: var(--soft); display: flex; align-items: center;
  justify-content: center; font-size: 17px; flex: none; }

/* мини-статистика */
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.st { background: var(--soft); border-radius: 16px; padding: 10px 8px; text-align: center; }
.st .ic { font-size: 18px; } .st b { display: block; font-size: 17px; font-weight: 800; margin-top: 2px; }
.st span { font-size: 11px; color: var(--hint); font-weight: 600; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .ic { position: absolute; right: 10px; top: 8px; font-size: 22px; opacity: .9; }
.kpi span { font-size: 12px; color: var(--hint); font-weight: 600; display: block; }
.kpi b { display: block; font-size: 24px; font-weight: 800; margin: 4px 0 6px; letter-spacing: -.02em; }
.up-bad, .down-bad { color: var(--bad); } .up-good, .down-good { color: var(--ok); }
.delta { display: inline-block; white-space: nowrap; font-style: normal; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.delta.up-good, .delta.down-good { background: color-mix(in srgb, var(--ok) 15%, transparent); }
.delta.up-bad, .delta.down-bad { background: color-mix(in srgb, var(--bad) 13%, transparent); }
.delta.same { background: var(--soft); color: var(--hint); }

.seg { display: flex; background: var(--card); border-radius: 14px; padding: 4px; margin-bottom: 12px; box-shadow: var(--shadow); }
.seg button { flex: 1; border: 0; background: none; color: var(--hint); padding: 8px 0; border-radius: 11px; font-size: 13px; font-weight: 700; transition: .25s; }
.seg button.on { background: var(--g-hero); color: #fff; box-shadow: 0 6px 16px -8px rgba(99, 70, 255, .8); }
canvas { max-width: 100%; }

/* календарь — тепловая карта */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .wd { text-align: center; font-size: 11px; color: var(--hint); font-weight: 700; padding-bottom: 2px; }
.cal .d { aspect-ratio: 1; border-radius: 12px; background: var(--soft); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 14px; font-weight: 700; cursor: pointer; transition: transform .15s; }
.cal .d:active { transform: scale(.92); }
.cal .d small { font-size: 8.5px; font-weight: 600; opacity: .9; }
.cal .d.ok, .cal .d.warn, .cal .d.over { color: #fff; }
.cal .d.today { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); animation: pulse 2.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--card), 0 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent); } }
.cal .d.future { opacity: .3; cursor: default; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--hint); margin-top: 12px; font-weight: 600; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }

/* нижний лист */
#sheet-bg { position: fixed; inset: 0; background: rgba(10, 8, 30, .45); z-index: 10;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade .2s both; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--card);
  border-radius: 26px 26px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow: auto; max-width: 640px; margin: 0 auto; animation: up .32s cubic-bezier(.2, .8, .2, 1) both; }
#sheet::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }
#sheet h2 { margin: 0 0 12px; font-size: 19px; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; background: var(--soft); color: var(--text); border-radius: 14px; padding: 9px 13px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip:active { transform: scale(.94); }
label.f { display: block; margin-bottom: 10px; font-size: 12px; color: var(--hint); font-weight: 600; }
label.f input, label.f select { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font-size: 16px;
  border: 0; border-radius: 13px; background: var(--soft); color: var(--text); outline: none; }
label.f input:focus { box-shadow: 0 0 0 2px var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.btn { display: block; width: 100%; border: 0; border-radius: 15px; padding: 14px; font-size: 16px; font-weight: 700;
  background: var(--g-hero); color: #fff; margin-top: 8px; cursor: pointer; box-shadow: 0 10px 22px -12px rgba(99, 70, 255, .9); }
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--soft); color: var(--text); box-shadow: none; }
.btn.danger { background: none; color: var(--bad); box-shadow: none; }
#toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20, 18, 40, .88); color: #fff; padding: 10px 16px; border-radius: 14px; z-index: 20; font-size: 14px;
  font-weight: 600; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); animation: rise .25s both; }
