/* Цвета берём из темы Telegram; запасные значения — для открытия в обычном браузере */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --muted: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --ok: #30a46c;
  --warn: #f0883e;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
main { padding: 12px 16px 150px; max-width: 560px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 0 12px; text-align: center; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }

.tab { display: none; }
.tab.active { display: block; }

/* шапка дня */
.day-nav { display: flex; align-items: center; justify-content: space-between; }
.day-nav h1 { margin: 0; flex: 1; }
.day-title { flex: 1; font-size: 20px; font-weight: 700; padding: 8px 0; }
.day-title::after { content: " ▾"; font-size: 14px; color: var(--muted); }

/* календарь */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head b { font-size: 17px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .wd { font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day { aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; font-size: 15px; }
.cal-day i { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.cal-day i.ok { background: var(--ok); }
.cal-day i.over { background: var(--warn); }
.cal-day i.any { background: var(--accent); }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.selected { background: var(--accent); color: var(--accent-text); }
.cal-day.selected i { background: var(--accent-text); }
.cal-day:disabled { opacity: .3; }
.cal-legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 10px; }
.cal-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; }
.icon-btn { font-size: 26px; width: 44px; height: 44px; border-radius: 50%; color: var(--accent); }
.icon-btn:disabled { opacity: .25; }

/* кольцо калорий */
.summary { display: grid; grid-template-columns: 120px 1fr; gap: 6px 16px; align-items: center; margin-top: 8px; }
#ring { width: 120px; height: 120px; grid-column: 1; grid-row: 1 / span 2; transform: rotate(-90deg); }
#ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: color-mix(in srgb, var(--muted) 22%, transparent); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s, stroke .3s; }
.ring-fg.over { stroke: var(--warn); }
.ring-text { grid-column: 1; grid-row: 1 / span 2; text-align: center; align-self: center; pointer-events: none; }
.big { font-size: 24px; font-weight: 700; }
.left-line { grid-column: 2; font-weight: 600; }
.left-line.over { color: var(--warn); }
.macros { grid-column: 2; display: grid; gap: 6px; }
.macro { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; align-items: center; font-size: 13px; }
.macro b { font-weight: 500; color: var(--muted); grid-column: 2; grid-row: 1; }
.macro .bar { grid-column: 1 / -1; grid-row: 2; }
.bar { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--muted) 22%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s; }
.macro[data-key="fat"] .bar i { background: #f5a524; }
.macro[data-key="carbs"] .bar i { background: #8e4ec6; }
.hint { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.hint a { color: var(--accent); }

/* приёмы пищи */
.meal-group h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 16px 4px 6px;
  display: flex; justify-content: space-between; }
.meal { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.meal + .meal { border-top: 1px solid color-mix(in srgb, var(--muted) 18%, transparent); margin-top: 10px; padding-top: 10px; }
.meal .title { flex: 1; min-width: 0; }
.meal .thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; flex: none;
  background: color-mix(in srgb, var(--muted) 15%, transparent); }
.sheet .meal-photo { width: 100%; max-height: 300px; object-fit: cover; border-radius: 12px; margin-bottom: 10px;
  background: color-mix(in srgb, var(--muted) 15%, transparent); min-height: 120px; }
.meal .title div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal .kcal { font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* неделя */
#week-chart { width: 100%; height: auto; }
#week-chart text { fill: var(--muted); font-size: 11px; }
#week-chart .val { fill: var(--text); font-size: 10px; }
.stat-row { display: flex; justify-content: space-between; padding: 6px 0; }
.stat-row + .stat-row { border-top: 1px solid color-mix(in srgb, var(--muted) 18%, transparent); }

/* профиль */
form label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 0;
  border-radius: 10px; padding: 10px 12px; margin-top: 4px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 8px 14px; border-radius: 20px; background: var(--bg); }
.chips button.on { background: var(--accent); color: var(--accent-text); }
.primary { background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.wide { width: 100%; margin-top: 16px; }
.danger { color: var(--danger); }
.norm-card .big { color: var(--accent); }
.toggle-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.toggle-row input { width: 22px; height: 22px; flex: none; }

/* кнопка добавления и нижнее меню */
.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(72px + env(safe-area-inset-bottom));
  background: var(--accent); color: var(--accent-text); padding: 13px 22px; border-radius: 26px;
  font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.18); z-index: 5; white-space: nowrap; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid color-mix(in srgb, var(--muted) 18%, transparent); z-index: 6; }
.tabbar button { flex: 1; padding: 8px 0; font-size: 20px; display: flex; flex-direction: column; align-items: center; color: var(--muted); }
.tabbar span { font-size: 11px; }
.tabbar button.active { color: var(--accent); }

/* нижняя панель */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto; z-index: 11;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; animation: up .2s ease-out; }
.sheet.no-anim { animation: none; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .section { margin-top: 14px; }
.sheet .section > div:first-child { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.sheet img { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; }
.sheet pre { white-space: pre-wrap; font: inherit; background: var(--bg); border-radius: 12px; padding: 12px; margin: 12px 0 0; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .actions button { flex: 1; padding: 12px; border-radius: 12px; background: var(--bg); font-weight: 600; }
.sheet .actions .primary { background: var(--accent); color: var(--accent-text); }
.edit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.edit-row label { font-size: 13px; color: var(--muted); }
.edit-row input { font-size: 17px; font-weight: 600; }
.items { display: grid; gap: 6px; }
.item-row { display: grid; grid-template-columns: 1fr 74px 74px 30px; gap: 6px; align-items: center; }
.item-row .name { font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
.item-row .name small { display: block; color: var(--muted); font-size: 11px; }
.item-row input { padding: 8px; margin: 0; font-size: 15px; font-weight: 600; text-align: right; }
.item-row .unit-head { font-size: 11px; color: var(--muted); text-align: right; padding-right: 8px; }
.item-row .del { color: var(--danger); font-size: 18px; }
.item-row.edited .name::after { content: " ✏️"; font-size: 12px; }
.link-btn { color: var(--accent); font-size: 14px; padding: 8px 0 0; }
.spinner { width: 34px; height: 34px; margin: 18px auto; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(130px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; font-size: 14px; }
