/* Фирменная палитра «свежая зелёная» (согласована с пользователем).
   Светлая/тёмная схемы задаются явно, а не наследуются от темы Telegram —
   у приложения своё лицо. От темы Telegram берём только сигнал светлая/тёмная
   (класс на <body> ставит app.js по tg.colorScheme). */

:root {
  --brand: #2FBF71;
  --brand-dark: #249E5C;
  --brand-soft: rgba(47, 191, 113, 0.12);

  --bg: #ffffff;
  --card: #F2F7F4;
  --text: #121417;
  --hint: #7A8691;
  --border: #E3EBE6;
  --button: var(--brand);
  --button-text: #ffffff;
  --shadow: rgba(18, 20, 23, 0.12);

  --radius: 18px;
}

body.dark {
  --bg: #14161A;
  --card: #1E2126;
  --text: #F5F7F5;
  --hint: #8D97A1;
  --border: #2A2E35;
  --brand-soft: rgba(47, 191, 113, 0.18);
  --shadow: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

#app {
  position: relative;
  min-height: 100vh;
}

.screen {
  padding: 20px 16px 96px;
  min-height: 100vh;
  animation: screen-in 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

.screen.hidden { display: none; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

h1 { font-size: 24px; font-weight: 700; margin: 4px 0 4px; letter-spacing: -0.02em; }
h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 0 8px;
  color: var(--hint);
}
.subtitle { color: var(--hint); font-size: 14px; margin: 0 0 20px; line-height: 1.4; }

form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 16px;
}

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  transition: border-color 180ms ease, background 180ms ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--bg);
}

.segmented {
  display: flex;
  margin-top: 6px;
  padding: 4px;
  border-radius: 14px;
  gap: 4px;
  background: var(--card);
}
.segmented button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: background 220ms ease, color 220ms ease, transform 150ms ease;
}
.segmented button.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(47, 191, 113, 0.35);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  margin-top: 12px;
  box-shadow: 0 4px 14px rgba(47, 191, 113, 0.3);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(47, 191, 113, 0.25);
}

/* Внутри настоящего Telegram-клиента главное действие отдано нативной
   MainButton (см. app.js), а своя кнопка становится избыточной. Вне Telegram
   (обычный браузер при разработке) tg-native не ставится, и кнопка остаётся
   единственным способом нажать «дальше». */
body.tg-native .btn-primary.sticky,
body.tg-native #btn-estimate,
body.tg-native #btn-save-estimate,
body.tg-native #btn-add-product-confirm,
body.tg-native #btn-save-weight {
  display: none;
}

.btn-primary.sticky {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 20px;
  z-index: 10;
}

.btn-back {
  border: none;
  background: none;
  color: var(--brand);
  font-size: 15px;
  font-weight: 600;
  padding: 4px 0 12px;
}

.kbzhu-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin: 14px 0;
}
.kbzhu-card .stat { text-align: center; }
.kbzhu-card .stat .value {
  font-size: 20px;
  font-weight: 800;
  display: block;
  letter-spacing: -0.02em;
}
.kbzhu-card .stat:first-child .value { color: var(--brand); }
.kbzhu-card .stat .label {
  font-size: 11px;
  color: var(--hint);
  font-weight: 600;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}
.btn-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  transition: transform 150ms ease, border-color 180ms ease;
}
.btn-card:active { transform: scale(0.98); border-color: var(--brand); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.chip {
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  transition: background 180ms ease, color 180ms ease, transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1), border-color 180ms ease;
}
.chip.selected {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  transform: scale(1.05);
  box-shadow: 0 2px 10px rgba(47, 191, 113, 0.3);
}

.recipe-list { display: flex; flex-direction: column; gap: 10px; }
.recipe-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  text-align: left;
  transition: transform 150ms ease, border-color 180ms ease;
}
.recipe-item-main { display: flex; align-items: center; min-width: 0; }
.recipe-item-thumb {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  margin-right: 12px;
  flex-shrink: 0;
}
.recipe-photo {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 14px;
  display: block;
}
.recipe-item:active { transform: scale(0.98); border-color: var(--brand); }
.recipe-item .title { font-weight: 700; font-size: 15px; }
.recipe-item .meta { font-size: 12px; color: var(--hint); margin-top: 3px; }
.recipe-item .coverage {
  font-size: 12px;
  font-weight: 800;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
  margin-left: 10px;
}

.ingredient-list, .steps-list, .shopping-list { padding-left: 0; list-style: none; margin: 0; }
.ingredient-list li, .shopping-list li {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.ingredient-list li span:last-child { color: var(--hint); font-weight: 600; }

.steps-list { counter-reset: step; }
.steps-list li {
  position: relative;
  padding: 9px 0 9px 38px;
  font-size: 15px;
  line-height: 1.45;
}
.steps-list li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0; top: 8px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}

/* Три магазина в строке уже не помещаются на узких экранах, поэтому позиция
   переносится: название с граммовкой сверху, ссылки — строкой под ним. */
.shopping-list li {
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.shopping-list li > div:first-child { flex: 1 1 100%; }
.shopping-list .amount { color: var(--hint); font-size: 13px; margin-top: 2px; }
.shopping-list .links { display: flex; flex-wrap: wrap; gap: 6px; }
.shopping-list .links a {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--brand-soft);
  transition: background 160ms ease;
}
.shopping-list .links a:active { background: var(--brand); color: #fff; }

/* ---------- Юридические тексты ---------- */

.legal-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--hint);
  background: var(--card);
  border-radius: 12px;
  padding: 11px 13px;
  margin: 4px 0 14px;
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  margin-bottom: 16px;
}
.consent-row input {
  width: auto;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--brand);
}

.link-btn {
  border: none;
  background: none;
  padding: 0;
  color: var(--brand);
  font-size: inherit;
  font-weight: 700;
  text-decoration: underline;
  display: inline;
}

.text-link {
  display: block;
  width: 100%;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 0;
  text-align: center;
}
.text-link:active { color: var(--brand); }

.terms-text { font-size: 14px; line-height: 1.6; color: var(--text); }
.terms-text p { margin: 0 0 16px; }

.ai-note {
  font-size: 12.5px;
  color: var(--hint);
  background: var(--brand-soft);
  padding: 10px 12px;
  border-radius: 12px;
  margin: 0 0 4px;
  line-height: 1.4;
}
.ai-note.hidden { display: none; }

/* ---------- Карточка рецепта ---------- */

.recipe-desc {
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  margin: 6px 0 12px;
}

.recipe-facts { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.recipe-facts .fact {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 99px;
  background: var(--card);
  border: 1.5px solid var(--border);
  white-space: nowrap;
}

.tips-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.tips-list li {
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--brand-soft);
  padding: 11px 13px;
  border-radius: 12px;
}

/* ---------- Дневник питания ---------- */

.btn-card.compact { padding: 14px 16px; font-size: 15px; }
.btn-card .sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--hint);
  margin-top: 3px;
  line-height: 1.35;
}

/* Кольцо съеденного за день. Заполнение задаётся через --pct из JS.
   Больше 100% не рисуем — кольцо просто становится полным и краснеет,
   иначе при перееданиии дуга пошла бы на второй круг и запутала. */
.day-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
}
.day-ring {
  --pct: 0;
  flex: none;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--ring-color, var(--brand)) calc(var(--pct) * 1%), var(--border) 0);
  transition: background 600ms ease;
}
.day-ring::after {
  content: "";
  grid-area: 1 / 1;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--card);
}
.day-ring .inner { grid-area: 1 / 1; z-index: 2; text-align: center; }
.day-ring .n { display: block; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.day-ring .c { display: block; font-size: 10px; color: var(--hint); font-weight: 700; }

.day-macros { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.day-macro { display: grid; grid-template-columns: 18px 1fr auto; gap: 9px; align-items: center; font-size: 12px; }
.day-macro .k { font-weight: 800; color: var(--hint); }
.day-macro .bar { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.day-macro .bar i { display: block; height: 100%; border-radius: 99px; background: var(--brand); transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1); }
.day-macro .v { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

.day-left {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 600;
}
.day-left.over { background: rgba(232, 90, 79, 0.15); }

/* Секции приёмов пищи. Пустые слоты остаются видимыми — они и есть
   приглашение записать то, что забыл. */
.meal-slot {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  margin-bottom: 12px;
}
.slot-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.slot-name { font-size: 15px; font-weight: 700; }
.slot-total {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.slot-actions { display: flex; gap: 8px; margin-top: 8px; }

.slot-add {
  flex: 1;
  padding: 10px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: none;
  color: var(--hint);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  transition: border-color 180ms ease, color 180ms ease;
}
.slot-add:active { border-color: var(--brand); color: var(--brand); }

/* «Не ел» — намеренно тихая кнопка: это не действие, которого от человека
   ждут, а способ снять с себя ощущение незаполненности. */
.slot-skip {
  flex: none;
  padding: 10px 14px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  opacity: 0.75;
  transition: opacity 180ms ease, color 180ms ease;
}
.slot-skip:active { opacity: 1; color: var(--text); }
.slot-skip.active { flex: 1; opacity: 1; }

/* Пропущенный слот приглушается целиком, чтобы не тянуть на себя внимание. */
.meal-slot.is-skipped { opacity: 0.62; }
.meal-slot.is-skipped .slot-add { border-style: dotted; }
.meal-list .empty.skipped { font-style: italic; }

.meal-list { list-style: none; padding: 0; margin: 0; }
.meal-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.meal-list .m-main { flex: 1; min-width: 0; }
.meal-list .m-title { font-size: 14.5px; font-weight: 600; }
.meal-list .m-meta { font-size: 11.5px; color: var(--hint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.meal-list .m-kcal { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meal-list .m-del {
  border: none;
  background: none;
  color: var(--hint);
  font-size: 19px;
  padding: 2px 4px;
  line-height: 1;
}
.meal-list .empty { color: var(--hint); font-size: 14px; justify-content: center; border: none; }

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--border);
  color: var(--hint);
  margin-left: 6px;
  vertical-align: 1px;
}
.tag.ai { background: var(--brand-soft); color: var(--brand); }

.add-ways { display: flex; flex-direction: column; gap: 9px; margin-top: 22px; }

/* ---------- Свободный ввод ---------- */

textarea {
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--brand); background: var(--bg); }

.estimate {
  margin-top: 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--card);
  animation: screen-in 300ms ease;
}
.estimate.hidden { display: none; }
.estimate h3 { margin: 0 0 4px; font-size: 17px; }
.estimate .conf { font-size: 12px; font-weight: 700; margin-bottom: 10px; }
.estimate .conf.high { color: var(--brand); }
.estimate .conf.medium { color: #E0A02A; }
.estimate .conf.low { color: #E85A4F; }
.estimate .assumption {
  font-size: 12.5px;
  color: var(--hint);
  line-height: 1.45;
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.estimate .edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--hint);
}
.estimate .edit-row input {
  width: 90px;
  margin: 0;
  padding: 8px 10px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Прогресс ---------- */

.weight-block {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.weight-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.weight-now { font-size: 27px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.weight-delta { font-size: 14px; font-weight: 700; }
.weight-delta.down { color: var(--brand); }
.weight-delta.up { color: #E85A4F; }
.weight-sub { font-size: 12px; color: var(--hint); margin-top: 3px; }

.spark { width: 100%; height: 78px; margin-top: 12px; display: block; overflow: visible; }
.spark path.line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.spark path.area { fill: var(--brand-soft); stroke: none; }
.spark circle { fill: var(--brand); }

.weight-add { display: flex; gap: 8px; align-items: stretch; margin-bottom: 6px; }
.weight-add input { margin-top: 0; }
.btn-primary.inline { width: auto; margin-top: 0; padding: 13px 18px; white-space: nowrap; }

/* Столбики калорий по дням. Целевая линия — пунктир поверх колонок. */
.kcal-chart {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 150px;
  padding: 14px 12px 0;
  background: var(--card);
  border-radius: var(--radius);
}
.kcal-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 5px; }
.kcal-bar {
  width: 100%;
  border-radius: 7px 7px 3px 3px;
  background: var(--brand);
  min-height: 3px;
  transition: height 500ms cubic-bezier(0.22, 1, 0.36, 1);
}
.kcal-bar.over { background: #E85A4F; }
.kcal-bar.none { background: var(--border); }
.kcal-col .d { font-size: 9.5px; color: var(--hint); font-weight: 700; }
.kcal-col .v { font-size: 9.5px; color: var(--hint); font-variant-numeric: tabular-nums; }

.target-line {
  position: absolute;
  left: 12px; right: 12px;
  border-top: 1.5px dashed var(--hint);
  opacity: 0.65;
}
.target-line span {
  position: absolute;
  right: 0; top: -16px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--hint);
  background: var(--card);
  padding: 0 4px;
}

.chart-note { font-size: 12.5px; color: var(--hint); margin-top: 10px; line-height: 1.45; }

.portion-note {
  font-size: 13px;
  color: var(--hint);
  background: var(--brand-soft);
  padding: 10px 12px;
  border-radius: 12px;
  margin: 0 0 4px;
}
