:root {
  --bg: var(--tg-theme-secondary-bg-color, #f0f1f5);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --line: rgba(128,134,144,0.16);
  --accent: #1fb573;
  --accent-soft: rgba(31,181,115,0.12);
  --warn: #f5a623;
  --danger: #ff4d4f;
  --p: #3b8fe6;
  --f: #f0a232;
  --c: #8b7cf0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

#app { padding: 10px 14px 92px; max-width: 540px; margin: 0 auto; }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.xsmall { font-size: 12px; }
b { font-weight: 600; }
#loading { padding: 60px 16px; line-height: 1.6; }

#topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; }
#topbar .hello { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: none; border: none; padding: 4px; color: var(--hint); cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 600;
}

.card { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.section-label { font-size: 13px; color: var(--hint); margin: 4px 2px 8px; font-weight: 500; }

/* --- Компактная сводка: кольцо + макросы --- */
.summary { display: flex; align-items: center; gap: 16px; }
.ring-sm { width: 104px; height: 104px; flex-shrink: 0; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 9; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round;
  transition: stroke-dashoffset .6s cubic-bezier(.4,0,.2,1), stroke .3s; }
.ring-num-sm { fill: var(--text); font-size: 26px; font-weight: 700; text-anchor: middle; letter-spacing: -0.5px; }
.ring-cap-sm { fill: var(--hint); font-size: 10px; text-anchor: middle; }
.macros-col { flex: 1; display: flex; flex-direction: column; }
.mrow { display: flex; justify-content: space-between; margin-bottom: 3px; }
.mrow:not(:first-child) { margin-top: 9px; }
.mbar { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.mfill { height: 100%; width: 0; border-radius: 6px; transition: width .5s ease; }
.mfill.p { background: var(--p); }
.mfill.f { background: var(--f); }
.mfill.c { background: var(--c); }

/* --- Приёмы пищи (по группам) --- */
#meals { display: flex; flex-direction: column; gap: 8px; }
.meal { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.meal-head { display: flex; align-items: center; justify-content: space-between; }
.meal-title { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.meal-ic { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.meal-kcal { font-size: 14px; font-weight: 600; }
.meal.empty .meal-title, .meal.empty .meal-kcal { color: var(--hint); font-weight: 400; }
.meal-items { margin-top: 8px; }
.meal-item { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--text); }
.meal-item .mi-k { color: var(--hint); white-space: nowrap; padding-left: 10px; }
.mi-del { background: none; border: none; color: var(--hint); font-size: 17px; line-height: 1; padding: 0 0 0 10px; cursor: pointer; }

/* --- Навигация по датам --- */
.date-nav { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 10px; }
#day-label { font-size: 14px; font-weight: 500; }
.nav-btn { background: none; border: none; color: var(--accent); font-size: 26px; width: 40px; height: 32px; line-height: 1; cursor: pointer; }
.nav-btn:disabled { color: var(--hint); opacity: .35; }

/* --- Чипы: стрик и вода --- */
.stats-row { display: flex; gap: 10px; margin-bottom: 12px; }
.chip { flex: 1; background: var(--card); border-radius: 14px; padding: 11px 13px; display: flex; align-items: center; gap: 7px; font-size: 14px; }
.chip b { font-weight: 600; }
.chip.water { justify-content: flex-start; }
.chip-btn { width: 28px; height: 28px; border: none; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 16px; line-height: 1; cursor: pointer; }
.chip.water .chip-btn:first-of-type { margin-left: auto; }

.ghost-btn {
  width: 100%; margin-top: 12px; padding: 13px; border: none; border-radius: 14px;
  background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 600; font-family: inherit;
}
.ghost-btn:active { transform: scale(.99); }

/* --- Вес: ввод --- */
.weight-row { display: flex; gap: 10px; }
.weight-row input { flex: 1; }
.weight-row button {
  padding: 0 20px; border: none; border-radius: 12px; background: var(--accent);
  color: #fff; font-size: 15px; font-weight: 600; font-family: inherit; white-space: nowrap;
}
#w-status { margin-top: 8px; }

/* --- Прогресс --- */
.prow { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 0.5px solid var(--line); }
.prow:last-of-type { border-bottom: none; }
.prow b { font-variant-numeric: tabular-nums; }
.verdict { margin-top: 12px; padding: 11px; border-radius: 12px; font-size: 13px; text-align: center; }
.verdict.good { background: var(--accent-soft); color: var(--accent); }
.verdict.warn { background: rgba(245,166,35,.14); color: #c47f0a; }

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photos img { width: 100%; border-radius: 12px; display: block; }
.photos .ph-cap { font-size: 12px; color: var(--hint); text-align: center; margin-top: 3px; }
.photos .empty { grid-column: 1/3; padding: 10px; text-align: center; }

/* --- Коуч --- */
.coach-out { margin-top: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.coach-out.loading { color: var(--hint); }

/* --- Достижения --- */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.ach { background: var(--bg); border-radius: 14px; padding: 14px 10px; text-align: center; }
.ach-ic { font-size: 28px; line-height: 1; }
.ach-t { font-size: 13px; font-weight: 600; margin-top: 6px; }
.ach-d { margin-top: 2px; }
.ach.locked { opacity: .45; filter: grayscale(1); }

/* --- Настройки --- */
label { display: block; margin: 14px 0 5px; font-size: 13px; color: var(--hint); }
input, select {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: none;
  background: var(--bg); color: var(--text); font-size: 15px; font-family: inherit;
}
.primary {
  width: 100%; margin-top: 12px; padding: 14px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; font-family: inherit;
}
.primary:active { transform: scale(.985); }
#settings-status { margin-top: 10px; }

/* --- Нижнее меню --- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--card); border-top: 0.5px solid var(--line);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  max-width: 540px; margin: 0 auto;
}
#tabbar button {
  flex: 1; background: none; border: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-family: inherit; cursor: pointer;
}
#tabbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabbar button.active { color: var(--accent); }
