:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --card: var(--tg-theme-secondary-bg-color, #1a1d24);
  --text: var(--tg-theme-text-color, #eceff4);
  --hint: var(--tg-theme-hint-color, #8b93a7);
  --accent: var(--tg-theme-button-color, #6ab04c);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { max-width: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding: 0 14px env(safe-area-inset-bottom) 14px;
  -webkit-font-smoothing: antialiased;
  max-width: 100%; overflow-x: hidden;
}
img, svg, video, canvas { max-width: 100%; }
/* нічого не може бути ширшим за екран → жодного бокового скролу */
.seg, .time-row, .macros, .tabs, .shop-item, .day-picker { max-width: 100%; }
input, select, textarea, button { max-width: 100%; }
/* десктоп / широкий екран: центрувати в колонку, як у Telegram-панелі */
@media (min-width: 640px) {
  body { max-width: 600px; margin: 0 auto; }
  .chat-input {
    left: 50%; right: auto; transform: translateX(-50%);
    width: 100%; max-width: 600px;
  }
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 2px 10px;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.brand span { font-size: 18px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.user { font-size: 13px; color: var(--hint); }
.edit-profile { border: 0; background: var(--card); border-radius: 8px; padding: 5px 9px; font-size: 15px; cursor: pointer; line-height: 1; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; padding: 10px; border: 0; border-radius: 12px;
  background: var(--card); color: var(--hint); font-size: 15px; font-weight: 600;
}
.tab.active { background: var(--accent); color: var(--accent-text); }

.loading, .error { text-align: center; color: var(--hint); padding: 40px 0; }
.error { color: #e06c75; }

/* day header */
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 12px; }
.day-name { font-size: 19px; font-weight: 700; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: rgba(106,176,76,.18); color: var(--accent);
}
.badge.training { background: rgba(235,160,60,.18); color: #eba03c; }

/* macros strip */
.macros { display: flex; gap: 8px; margin: 0 2px 16px; }
.macro {
  flex: 1; background: var(--card); border-radius: 12px; padding: 10px 8px; text-align: center;
}
.macro b { display: block; font-size: 17px; }
.macro small { color: var(--hint); font-size: 11px; }

/* meal cards */
.meal {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 10px;
}
.meal-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.meal-slot { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .4px; }
.meal-time { font-size: 12px; color: var(--hint); }
.meal-title { font-size: 16px; font-weight: 600; line-height: 1.3; }
.meal-kbju { font-size: 12px; color: var(--hint); margin-top: 6px; }
.meal-note {
  font-size: 12px; color: var(--hint); margin-top: 8px; padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.06); line-height: 1.4;
}
.photo-ph {
  height: 4px; border-radius: 4px; margin-top: 10px;
  background: linear-gradient(90deg, rgba(106,176,76,.4), transparent);
}

/* week list */
.week-day { margin-bottom: 22px; }

/* shopping list */
.shop-top {
  display: flex; align-items: center; justify-content: space-between;
  margin: 2px 2px 14px;
}
.shop-top small { color: var(--hint); font-size: 12px; }
.refresh-btn {
  border: 0; border-radius: 12px; padding: 9px 14px; font-size: 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.refresh-btn.wide { width: 100%; margin-top: 14px; padding: 13px; }
.shop-cat { margin-bottom: 16px; }
.shop-cat-h {
  font-size: 12px; font-weight: 700; color: var(--hint);
  text-transform: uppercase; letter-spacing: .5px; margin: 0 2px 6px;
}
.shop-item {
  display: grid; grid-template-columns: 22px 40px 1fr auto auto; align-items: center;
  column-gap: 8px; background: var(--card); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 6px;
}
.shop-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.shop-thumb { grid-column: 2; grid-row: 1 / span 2; width: 40px; height: 40px;
  border-radius: 8px; object-fit: cover; background: rgba(255,255,255,.05); }
.shop-thumb.ph { background: rgba(255,255,255,.04); }
.shop-name { font-size: 14px; line-height: 1.25; grid-column: 3; }
.shop-meta { grid-column: 3; font-size: 11px; color: var(--hint); }
.shop-price { grid-column: 4; grid-row: 1 / span 2; font-size: 13px; font-weight: 600; }
.shop-item.checked .shop-name { text-decoration: line-through; color: var(--hint); }

/* акції від Gemma */
.deal { display: flex; gap: 10px; align-items: center; background: rgba(235,160,60,.1);
  border: 1px solid rgba(235,160,60,.3);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; text-decoration: none; color: var(--text); }
.deal-thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.deal-info { flex: 1; min-width: 0; }
.deal-top { font-size: 14px; }
.deal-top s { color: var(--hint); font-size: 12px; }
.deal-pct { color: #eba03c; font-weight: 700; font-size: 12px; margin-left: 4px; }
.deal-name { font-size: 13px; margin-top: 2px; }
.deal-why { font-size: 12px; color: var(--hint); margin-top: 4px; line-height: 1.35; }

/* список «треба купити» */
.wl-add { display: flex; gap: 8px; margin-bottom: 8px; }
.wl-add input { flex: 1; border: 0; border-radius: 10px; padding: 10px; background: var(--card); color: var(--text); font-size: 14px; }
.wl-add .refresh-btn { width: 44px; padding: 0; }
.wl-item { display: flex; justify-content: space-between; align-items: center; background: var(--card);
  border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; font-size: 14px; }
.wl-item .ghost { border: 0; background: transparent; color: var(--hint); font-size: 14px; }

/* meal photo + stock badge */
.meal-photo { width: 100%; height: 150px; object-fit: cover; border-radius: 12px; margin-top: 10px; }
.stock-badge {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: rgba(106,176,76,.2); color: var(--accent); vertical-align: middle;
}
.regen-btn {
  margin-top: 8px; border: 0; border-radius: 9px; padding: 7px 12px;
  font-size: 12px; font-weight: 600; background: rgba(255,255,255,.08); color: var(--hint);
}
.regen-btn:disabled { opacity: .7; }

/* фото-студія (модалка) */
.studio.hidden { display: none; }
.studio {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.studio-box {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.studio-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.studio-head span { font-size: 18px; font-weight: 700; }
.studio-head button { border: 0; background: var(--card); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.studio-status { color: var(--hint); font-size: 13px; margin-bottom: 10px; }
.studio-hint { color: var(--hint); font-size: 13px; padding: 20px 0; text-align: center; }
.variations { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.variation { background: var(--card); border-radius: 12px; overflow: hidden; }
.variation img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.pick-btn {
  width: 100%; border: 0; padding: 9px; font-size: 13px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.pick-btn:disabled { opacity: .4; }
.studio-prompt { font-size: 12px; color: var(--hint); background: var(--card); border-radius: 10px; padding: 10px; margin-bottom: 12px; line-height: 1.4; }
#studio-comments {
  width: 100%; min-height: 64px; border: 0; border-radius: 10px; padding: 10px;
  background: var(--card); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical;
}
.studio-actions { display: flex; gap: 8px; margin-top: 10px; }
.studio-actions select { border: 0; border-radius: 10px; padding: 0 10px; background: var(--card); color: var(--text); font-size: 14px; }
.studio-actions .refresh-btn { flex: 1; }

/* онбординг */
#onboarding-body label { display: block; font-size: 13px; color: var(--hint); margin: 12px 2px 5px; }
#onboarding-body select, #onboarding-body input, #onboarding-body textarea {
  width: 100%; border: 0; border-radius: 10px; padding: 11px;
  background: var(--card); color: var(--text); font-size: 15px; font-family: inherit;
}
#onboarding-body textarea { min-height: 60px; resize: vertical; }
.onb-hint { color: var(--hint); font-size: 13px; line-height: 1.4; }
.onb-row { display: flex; gap: 8px; }
.onb-row > div { flex: 1; }
#onb-err, #o-err { margin-top: 8px; }
.onb-nav { display: flex; gap: 8px; margin-top: 16px; }
.onb-nav .refresh-btn { flex: 1; }
.onb-nav .regen-btn { flex: 0 0 auto; }
#onboarding-body input[type="time"] { width: 100%; }
.onb-row2 { display: flex; gap: 8px; margin-bottom: 6px; }
.onb-row2 input { flex: 1; border: 0; border-radius: 10px; padding: 10px; background: var(--card); color: var(--text); font-size: 14px; }
.onb-row2 .regen-btn { flex: 0 0 auto; }

/* ── Крок 1 редизайну: селектор тижня, профіль, порожні стани, фото ── */
.wk-selector { display: flex; gap: 6px; margin: 2px 0 12px; }
.wk-pill { flex: 1; padding: 9px 6px; border: 0; border-radius: 10px; background: var(--card);
  color: var(--hint); font-size: 13px; font-weight: 600; cursor: pointer; }
.wk-pill.active { background: var(--accent); color: var(--accent-text); }

.empty { text-align: center; color: var(--hint); padding: 32px 16px; }
.empty p { margin-bottom: 14px; line-height: 1.5; }

.prof-card { background: var(--card); border-radius: var(--radius); padding: 2px 14px; margin-bottom: 14px; }
.prof-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 14px; }
.prof-row:last-child { border-bottom: 0; }
.prof-row span { color: var(--hint); }
.prof-row b { text-align: right; }
.prof-sec { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--hint);
  margin: 22px 2px 8px; }
.regen-btn.wide { width: 100%; margin-top: 10px; padding: 12px; }

/* історія без іконки */
.hist-row { grid-template-columns: 1fr auto; }
.hist-note { grid-column: 1 / -1; }

/* фото страви — більше, по центру, не обрізає важливе (п.3) */
.meal-photo { height: auto; aspect-ratio: 16 / 9; object-position: center; }
.recipe-photo { max-height: none; height: auto; aspect-ratio: 16 / 9; object-position: center; }

/* ── Онбординг 2.0 (сегменти, пікер часу, прогрес, адаптив) ── */
.onb-progress { height: 5px; border-radius: 999px; background: rgba(255,255,255,.08); overflow: hidden; margin: 2px 2px 10px; }
.onb-progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.onb-step-lbl { color: var(--hint); font-size: 13px; margin: 0 2px 4px; }
.lbl-opt { color: var(--hint); font-weight: 400; font-size: 11px; }

/* сегмент-контрол — кнопки замість select */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt {
  flex: 1 1 auto; border: 1px solid rgba(255,255,255,.08);
  background: var(--card); color: var(--text); border-radius: 12px;
  padding: 12px 12px; font-size: 14px; font-weight: 600; cursor: pointer; line-height: 1.2;
  transition: background .15s, border-color .15s; -webkit-tap-highlight-color: transparent;
}
.seg-opt.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* кастомний пікер часу (нативний type=time ламається в Telegram на macOS) */
.time-list { display: flex; flex-direction: column; gap: 8px; }
.time-row { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 8px 12px; }
.time-lbl { flex: 1; font-size: 14px; color: var(--hint); }
#onboarding-body .time-row select {
  width: auto; flex: 0 0 auto; padding: 8px 10px; font-size: 17px; font-weight: 600;
  border: 0; border-radius: 10px; background: var(--bg); color: var(--text);
  -webkit-appearance: none; appearance: none; text-align: center; min-width: 60px;
}
.time-colon { font-weight: 700; color: var(--hint); }

/* модалка онбордингу: картка по центру (десктоп) / майже повний екран (телефон) */
@media (min-width: 640px) {
  #onboarding { align-items: center; }
  #onboarding .studio-box { border-radius: 18px; max-width: 480px; max-height: 88vh; }
}
@media (max-width: 639px) {
  #onboarding .studio-box { max-height: 94vh; min-height: 72vh; }
}

/* банери масштабу / комори */
.hh-banner { background: var(--card); border-radius: 10px; padding: 9px 12px; margin-bottom: 10px; font-size: 14px; }
.pantry-note { color: var(--hint); font-size: 13px; margin-bottom: 10px; }

/* комора (Кухня) */
.pantry-add { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.pantry-add select { flex: 1; border: 0; border-radius: 10px; padding: 10px; background: var(--card); color: var(--text); font-size: 14px; }
.pantry-add input { width: 80px; border: 0; border-radius: 10px; padding: 10px; background: var(--card); color: var(--text); font-size: 14px; }
.pantry-add .refresh-btn { width: 44px; padding: 0; }
.pantry-unit { color: var(--hint); font-size: 13px; min-width: 24px; }

/* чат-консультант */
.chat-log { display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 90px; min-height: 60vh; }
.bubble { max-width: 85%; padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.4; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--hint); font-style: italic; }
.bubble.error { background: rgba(224,108,117,.15); color: #e06c75; }
.chat-input {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg); border-top: 1px solid rgba(255,255,255,.07);
}
.chat-input textarea {
  flex: 1; border: 0; border-radius: 18px; padding: 10px 14px; resize: none;
  background: var(--card); color: var(--text); font-size: 15px; font-family: inherit; max-height: 120px;
}
.chat-input .refresh-btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 16px; flex-shrink: 0; }

/* kitchen / inventory */
.cook-box { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.cook-box select {
  width: 100%; padding: 10px; border-radius: 10px; border: 0; margin-bottom: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.cook-row { display: flex; gap: 8px; }
.cook-row input {
  width: 80px; padding: 10px; border-radius: 10px; border: 0;
  background: var(--bg); color: var(--text); font-size: 15px; text-align: center;
}
.cook-row .refresh-btn { flex: 1; }
.inv {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  border-left: 3px solid var(--hint);
}
.inv.st-fresh { border-left-color: var(--accent); }
.inv.st-low { border-left-color: #eba03c; }
.inv.st-done, .inv.st-exp { border-left-color: #e06c75; opacity: .7; }
.inv-name { font-size: 15px; font-weight: 600; }
.inv-meta { font-size: 12px; color: var(--hint); margin-top: 3px; }
.inv-actions { display: flex; gap: 6px; flex-shrink: 0; }
.inv-actions button {
  border: 0; border-radius: 9px; padding: 8px 10px; font-size: 13px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.inv-actions button:disabled { opacity: .4; }
.inv-actions .ghost { background: transparent; color: var(--hint); }

/* клікабельні страви → картка рецепта */
.meal-title.tappable { cursor: pointer; }
.tap-hint { color: var(--hint); font-weight: 400; }

/* картка рецепта (модалка) */
.recipe-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin-bottom: 10px; }
.recipe-kbju { font-size: 14px; font-weight: 600; }
.recipe-meta { font-size: 12px; color: var(--hint); margin-bottom: 10px; }
.recipe-sec { margin-top: 12px; }
.recipe-sec h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); margin: 0 0 6px; }
.recipe-steps { margin: 0; padding-left: 20px; }
.recipe-steps li { font-size: 14px; line-height: 1.5; margin-bottom: 6px; }

/* сторінка очікування схвалення */
.gate { text-align: center; padding: 40px 20px; }
.gate h3 { font-size: 20px; margin-bottom: 8px; }
.gate p { color: var(--hint); line-height: 1.5; }

/* вибір дня (Сьогодні) */
.day-picker { display: flex; gap: 6px; margin: 2px 0 14px; }
.day-pill { flex: 1; padding: 8px 0; border: 0; border-radius: 10px; background: var(--card);
  color: var(--hint); font-size: 13px; font-weight: 600; position: relative; }
.day-pill.active { background: var(--accent); color: var(--accent-text); }
.day-pill.today:not(.active)::after { content: "•"; position: absolute; top: 1px; right: 6px; color: var(--accent); }

/* історія їжі */
.hist-row { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px;
  background: var(--card); border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; font-size: 14px; }
.hist-ic { font-size: 15px; }
.hist-time { font-size: 12px; color: var(--hint); }
.hist-note { grid-column: 2 / span 2; font-size: 12px; color: var(--hint); margin-top: 2px; }

/* чернетка меню */
.draft-head { background: rgba(106,176,76,.12); border: 1px solid rgba(106,176,76,.3);
  border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.draft-head b { display: block; margin-bottom: 8px; }
.draft-actions { display: flex; gap: 8px; }
.draft-actions .refresh-btn { flex: 1; }
.draft-warn { font-size: 12px; color: #eba03c; margin-bottom: 12px; line-height: 1.4; }

/* кнопка прибрати позицію списку */
.shop-del { grid-column: 5; grid-row: 1 / span 2; border: 0; background: transparent;
  color: var(--hint); font-size: 13px; padding: 4px 2px; cursor: pointer; }

/* вподобання (Консультант) */
.prefs-bar:not(:empty) { margin-bottom: 10px; }
.prefs-title { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); margin-bottom: 6px; }
.prefs-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pref-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--card);
  border-radius: 999px; padding: 5px 6px 5px 10px; font-size: 13px; }
.pref-chip button { border: 0; background: transparent; color: var(--hint); font-size: 12px; cursor: pointer; padding: 0 2px; }

/* кнопка заміни страви */
.meal-top-right { display: inline-flex; align-items: center; gap: 8px; }
.swap-btn { border: 0; background: rgba(255,255,255,.08); color: var(--hint);
  border-radius: 8px; padding: 3px 7px; font-size: 12px; cursor: pointer; }
.swap-btn:disabled { opacity: .6; }

/* зірки-оцінка */
.stars { display: flex; gap: 4px; }
.star { border: 0; background: transparent; font-size: 24px; line-height: 1;
  color: rgba(255,255,255,.18); cursor: pointer; padding: 0; }
.star.on { color: #f5c518; }

/* відгук + доопрацювання страви */
#recipe-fb textarea { width: 100%; min-height: 64px; border: 0; border-radius: 10px;
  padding: 10px; background: var(--card); color: var(--text); font-size: 14px; resize: vertical; }
.fb-actions { display: flex; gap: 8px; margin-top: 8px; }
.fb-actions .refresh-btn { flex: 1; }
.fb-actions .regen-btn { margin-top: 0; }
.fb-hist { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.fb-item { background: var(--card); border-radius: 10px; padding: 9px 12px; font-size: 13px; line-height: 1.4; }
.fb-stars { color: #f5c518; }
.fb-at { color: var(--hint); font-size: 11px; margin-top: 3px; }
.pers-badge { color: var(--accent); font-weight: 600; }
