:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2b7de9);
  --accent: var(--tg-theme-button-color, #2b7de9);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --good: #2e9e5b;
  --warn: #e08a1e;
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --radius: 14px;
}
/* Вне Telegram (в обычном браузере) — тёмная тема по настройке системы */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #1c1d21);
    --bg2: var(--tg-theme-secondary-bg-color, #111214);
    --text: var(--tg-theme-text-color, #f2f3f5);
    --hint: var(--tg-theme-hint-color, #8f949c);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
main { padding: 12px 12px 84px; max-width: 720px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 4px 12px; }
h2 { font-size: 17px; margin: 18px 4px 8px; }
.hint { color: var(--hint); font-size: 13px; }
.loading, .empty { color: var(--hint); text-align: center; padding: 40px 16px; }
.card { background: var(--bg); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.btn { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.btn.ghost { background: var(--bg2); color: var(--text); }
.btn.small { padding: 6px 10px; font-size: 13px; }
input[type=number], input[type=text], input[type=search], input[type=date] {
  font: inherit; color: var(--text); background: var(--bg2); border: 0; border-radius: 10px; padding: 10px 12px; width: 100%; }

/* нижние вкладки */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabs button { flex: 1; padding: 8px 0 10px; font-size: 11px; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 2px; }
#tabs button span { font-size: 20px; }
#tabs button.active { color: var(--accent); }

/* фильтры */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 7px 12px; border-radius: 999px; background: var(--bg); font-size: 14px; }
.chip.active { background: var(--accent); color: var(--accent-text); }

/* карточки рецептов */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.rcard { background: var(--bg); border-radius: var(--radius); overflow: hidden; text-align: left; display: flex; flex-direction: column; }
.thumb { aspect-ratio: 4 / 3; width: 100%; object-fit: cover; display: flex; align-items: center; justify-content: center;
  font-size: 46px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--bg)), color-mix(in srgb, var(--good) 18%, var(--bg))); }
.rcard .body { padding: 9px 10px 11px; }
.rcard .title { font-weight: 600; font-size: 14px; line-height: 1.25; }
.rcard .meta { color: var(--hint); font-size: 12px; margin-top: 4px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg2); color: var(--hint); margin-top: 6px; }
.badge.cis { background: color-mix(in srgb, var(--accent) 15%, var(--bg)); color: var(--accent); }

/* рецепт */
.hero { margin: -12px -12px 12px; position: relative; }
.hero .thumb { aspect-ratio: 16 / 10; font-size: 80px; border-radius: 0; }
.hero img.thumb { display: block; }
.hero .photo-btn { position: absolute; right: 12px; bottom: 12px; background: rgba(0,0,0,.55); color: #fff; border-radius: 999px; padding: 7px 12px; font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tile { background: var(--bg2); border-radius: 10px; padding: 8px 4px; text-align: center; }
.tile b { display: block; font-size: 17px; }
.tile small { color: var(--hint); font-size: 11px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 34px; height: 34px; border-radius: 50%; background: var(--bg2); font-size: 18px; }
.ing { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.ing:last-child { border-bottom: 0; }
.ing span:last-child { color: var(--hint); white-space: nowrap; padding-left: 10px; }
.step { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); text-align: left; width: 100%; }
.step:last-child { border-bottom: 0; }
.step .num { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.step.done { opacity: .45; }
.step.done .num { background: var(--good); }
.toggle { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }

/* план */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
.day { background: var(--bg); border-radius: 10px; padding: 6px 0; text-align: center; font-size: 12px; color: var(--hint); }
.day b { display: block; font-size: 16px; color: var(--text); }
.day.active { background: var(--accent); color: var(--accent-text); }
.day.active b { color: var(--accent-text); }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.meal { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--line); }
.meal:last-child { border-bottom: 0; }
.meal .em { font-size: 30px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--bg2); border-radius: 12px; flex: 0 0 44px; overflow: hidden; }
.meal .em img { width: 100%; height: 100%; object-fit: cover; }
.meal small { color: var(--hint); display: block; }
.weeknav { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 10px; }

/* тело */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form label { font-size: 12px; color: var(--hint); display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photos .ph { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--bg2); }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.photos .ph small { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.55); color: #fff; padding: 1px 6px; border-radius: 6px; font-size: 11px; }
.photos .ph .del { position: absolute; right: 4px; top: 4px; background: rgba(0,0,0,.55); color: #fff; width: 24px; height: 24px; border-radius: 50%; font-size: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--hint); font-weight: 500; }
.down { color: var(--good); }
.up { color: var(--warn); }

/* статистика */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kpi { background: var(--bg); border-radius: var(--radius); padding: 12px; }
.kpi small { color: var(--hint); font-size: 12px; display: block; }
.kpi b { font-size: 22px; display: block; margin-top: 2px; }
.kpi span { font-size: 12px; color: var(--hint); }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--hint); font-size: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--hint); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff;
  padding: 9px 14px; border-radius: 10px; font-size: 14px; z-index: 10; }
