/* «Трекер тела» — стили экранов. Токены — в tokens.css. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* Верхний отступ контента: ниже статус-бара и зоны размытия iOS 26.
   Закреплённые шапки «Тренировок» тянутся к верху на эту же величину. */
:root { --app-pt: calc(max(env(safe-area-inset-top), 12px) + 16px); }

/* iOS 26 размывает верх установленного веб-приложения (Liquid Glass «scroll edge
   effect» под статус-баром) — плашка даты и шапки «мылились». WebKit не накладывает
   его, если у верхней кромки стоит закреплённая непрозрачная полоса на всю ширину
   (выше ~10 px). Она точно закрывает зону статус-бара — контент начинается под ней. */
.edgebar { position: fixed; top: 0; left: 0; right: 0; z-index: 40; pointer-events: none;
           height: max(env(safe-area-inset-top), 12px); background: var(--bg); }
html, body { margin: 0; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--ink);
  background: transparent;
  font-size: 15px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; }

#app {
  max-width: 520px; margin: 0 auto;
  padding: var(--app-pt) var(--pad)
           calc(env(safe-area-inset-bottom) + 64px);
  display: flex; flex-direction: column; gap: 10px;
}

/* ── Верх: дата ─────────────────────────────────────── */
.top { display: flex; align-items: center; gap: 8px; padding-top: 2px; -webkit-font-smoothing: antialiased; }
.top h1 { font: 700 30px/1.1 var(--font-display); letter-spacing: -.02em; margin: 0; flex: 1; }
.iconbtn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; border: 1px solid rgba(20, 24, 15, .12);
  box-shadow: 0 1px 2px rgba(20, 24, 15, .06);
}
.iconbtn:disabled { opacity: .35; }
.iconbtn svg { width: 20px; height: 20px; }
.datepill {
  height: 36px; padding: 0 14px; border-radius: var(--r-pill); flex: 1;
  background: #fff; border: 1px solid rgba(20, 24, 15, .12);
  box-shadow: 0 1px 2px rgba(20, 24, 15, .06); font-weight: 600; font-size: 15px;
}
.datepill.past { background: var(--accent-soft); }

/* ── Итог дня + список съеденного ──────────────────── */
.hero { padding: 12px 14px 0; overflow: hidden; }
.hero-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hero .label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.hero .kcal { font-size: 40px; line-height: 1; margin-top: 2px; }
.hero .kcal small { font: 600 15px var(--font); color: var(--ink-2); margin-left: 5px; letter-spacing: 0; }
.week { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.week b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bju { display: flex; flex-direction: column; gap: 3px; padding-top: 2px; }
.bju .m { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.bju b { font: 700 17px var(--font-display); font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.bju span { font-size: 11.5px; color: var(--ink-2); font-weight: 600; width: 44px; }
.bju i { width: 7px; height: 7px; border-radius: 50%; }
.bju .p i { background: var(--protein); }
.bju .f i { background: var(--fat); }
.bju .c i { background: var(--carbs); }
.hero .list { margin: 10px -14px 0; border-top: 1px solid var(--line);
              max-height: 236px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── Чат с Claude ───────────────────────────────────── */
.chat { padding: 6px; }
.thread { display: flex; flex-direction: column; gap: 8px; padding: 6px 4px 10px; }
.thread:empty { display: none; }
.thread-head { display: flex; justify-content: space-between; align-items: center;
               font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 0 4px; }
.thread-head button { color: var(--ink-2); font-size: 13px; padding: 4px 6px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 18px; font-size: 15px; line-height: 1.35;
       white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: rgba(255,255,255,.85); border-bottom-left-radius: 6px; }
.msg.err { background: #FFECEC; color: #9B1C1C; }
.msg .pics { display: flex; gap: 4px; margin-bottom: 6px; }
.msg .pics img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.est { align-self: stretch; background: #fff; border-radius: 20px; padding: 6px 12px 12px;
       box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.est .row { border-bottom: 1px solid var(--line); }
.est-total { display: flex; justify-content: space-between; align-items: baseline;
             padding: 10px 2px 10px; font-weight: 700; }
.est-total .num { font-size: 22px; }
.est-total small { font-weight: 600; color: var(--ink-2); font-size: 13px; }
.est-actions { display: flex; gap: 8px; }
.est.saved .est-actions { display: none; }
.est .done { display: none; color: var(--accent-text); font-weight: 700; padding: 4px 2px; }
.est.saved .done { display: block; }

.composer { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 140px; resize: none; border: 0; outline: 0;
  background: rgba(255,255,255,.9); border-radius: 20px; padding: 9px 14px;
  font-size: 16px; line-height: 1.35;
}
.composer textarea::placeholder { color: var(--ink-3); }
.cbtn { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
        background: rgba(255,255,255,.9); color: var(--ink); }
.cbtn.send { background: var(--accent); color: var(--accent-ink); }
.cbtn.rec { background: var(--danger); color: #fff;
            /* кольцо громкости: видно, что микрофон слышит голос */
            box-shadow: 0 0 0 calc(2px + var(--lvl, 0) * 10px) rgba(229, 72, 77, .28);
            transition: box-shadow .08s linear; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.attach { display: flex; gap: 6px; padding: 6px 4px 0; }
.attach:empty { display: none; }
.attach div { position: relative; }
.attach img { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; display: block; }
.attach button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
                 background: var(--ink); color: #fff; font-size: 13px; line-height: 22px; }
.rec-hint { font-size: 13px; color: var(--danger); font-weight: 600; padding: 6px 8px 0; }

/* ── Кнопки ─────────────────────────────────────────── */
.btn { height: 46px; padding: 0 18px; border-radius: var(--r-pill); font-weight: 700; font-size: 16px;
       display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); flex: 1; }
.btn.primary:active { background: var(--accent-press); }
.btn.ghost { background: rgba(20,24,15,.06); }
.btn:disabled { opacity: .5; }

/* ── Секции ─────────────────────────────────────────── */
.sec-h { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 4px 0; }
.sec-h h2 { margin: 0; font: 700 20px var(--font-display); letter-spacing: -.01em; }
.sec-h span { font-size: 13px; color: var(--ink-3); font-weight: 600; }

/* Быстрые блюда — 3 колонки, компактно, названия целиком */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.tile {
  text-align: left; padding: 6px 7px; border-radius: 14px; height: 50px;
  display: flex; align-items: center; gap: 6px; overflow: hidden;
  background: rgba(255,255,255,.78); border: 1px solid rgba(255,255,255,.95);
  box-shadow: 0 1px 2px rgba(30,40,10,.05);
  transition: transform .12s ease;
  /* долгое нажатие — наше превью, а не системное меню/выделение iOS */
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.tile:active { transform: scale(.96); background: var(--accent-soft); }
.tile.pressing { transform: scale(1.06); transition: transform .45s ease; box-shadow: var(--shadow-lift); }
.tile .em { font-size: 15px; line-height: 1; flex: none; }
.tile .tx { display: flex; flex-direction: column; gap: 1px; min-width: 0; overflow: hidden; }
/* одна высота у всех плиток: название до 2 строк, дальше многоточие */
.tile .nm { font-size: 12.5px; font-weight: 600; line-height: 1.15; overflow-wrap: break-word;
            display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.tile .mt { font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap;
            overflow: hidden; text-overflow: ellipsis; }
.tile.flash { animation: flash .5s ease; }
@keyframes flash { 0% { background: var(--accent); } 100% {} }
.more-btn { display: block; margin: 6px auto 0; height: 30px; padding: 0 14px; border-radius: var(--r-pill);
            background: rgba(255,255,255,.78); border: 1px solid rgba(20,24,15,.08);
            font-weight: 600; font-size: 13px; color: var(--ink-2); }

/* Список за день */
.list { padding: 2px 0; overflow: hidden; }
.list .empty { padding: 12px; color: var(--ink-3); text-align: center; font-size: 14px; }
.row { position: relative; overflow: hidden; }
.list .row + .row { border-top: 1px solid var(--line); }
.row-in {
  display: flex; align-items: center; gap: 9px; padding: 7px 14px; background: transparent;
  position: relative; z-index: 1; transition: transform .2s ease; touch-action: pan-y;
}
.list .row-in { background: rgba(255,255,255,.001); }
.row.dragging .row-in { transition: none; }
.row .em { font-size: 18px; width: 22px; text-align: center; flex: none; }
.row .nm { flex: 1; min-width: 0; }
.row .nm .t { font-size: 14px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.row .nm .sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.g { display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: var(--r-pill);
     background: rgba(20,24,15,.06); flex: none; }
.g input { width: 3.2ch; border: 0; outline: 0; background: transparent; text-align: right; padding: 0;
           font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.g input::placeholder { color: var(--ink-3); }
.g span { font-size: 13px; color: var(--ink-2); margin-left: 2px; }
.g:focus-within { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.row .k { width: 48px; text-align: right; font-size: 15px; flex: none; }
.row .k small { display: block; font: 600 10px var(--font); color: var(--ink-3); letter-spacing: 0; }
.row .del {
  position: absolute; right: 0; top: 0; bottom: 0; width: 96px; background: var(--danger); color: #fff;
  font-weight: 700; font-size: 14px;
}
.row .del { visibility: hidden; }
.row.dragging .del, .row.open .del { visibility: visible; }
.row.dragging .row-in, .row.open .row-in { background: #FAFBF6; }
.row.saving .k { opacity: .4; }

/* ── Таб-бар ────────────────────────────────────────── */
.tabbar {
  /* Закреплённая полоса внизу: занимает своё место, ничего не перекрывает
     (контенту — отступ снизу на её высоту, см. #app). */
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 8px;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--bg); border: 0; border-top: 1px solid var(--line);  /* непрозрачный: ничего не просвечивает */
  border-radius: 0; box-shadow: none;
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.tab { flex: 1; max-width: 200px; display: inline-flex; align-items: center; justify-content: center;
       gap: 7px; height: 40px; border-radius: var(--r-pill); color: var(--ink-2);
       text-decoration: none; font-weight: 600; font-size: 15px; }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.tab svg { width: 20px; height: 20px; }

/* ── Тост ───────────────────────────────────────────── */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30; max-width: 488px; margin: 0 auto;
  bottom: calc(env(safe-area-inset-bottom) + 62px);
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px;
  background: rgba(20,24,15,.92); color: #fff; border: 0; border-radius: 18px;
  font-size: 14px; font-weight: 600;
  animation: up .2s ease;
}
.toast .tt { flex: 1; }
.toast button { color: var(--accent); font-weight: 700; padding: 8px 10px; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }

/* ── Нижний лист «Ещё» ──────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(20,24,15,.25); display: flex; align-items: flex-end; }
.sheet-in {
  width: 100%; max-width: 520px; margin: 0 auto; max-height: 86dvh; display: flex; flex-direction: column;
  background: #FBFCF8; border-radius: 28px 28px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px);
  animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(40px); opacity: .5; } }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: rgba(20,24,15,.15); margin: 2px auto 10px; }
.sheet-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sheet-h input { flex: 1; height: 42px; border-radius: var(--r-pill); border: 0; outline: 0;
                 background: rgba(20,24,15,.06); padding: 0 16px; font-size: 16px; }
.sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.sheet-list .item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 4px;
                    border-bottom: 1px solid var(--line); text-align: left; }
.sheet-list .item:active { background: var(--accent-soft); }
.sheet-list .item .nm { flex: 1; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.sheet-list .item .mt { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Заглушки ───────────────────────────────────────── */
.card { padding: 20px; }
.card h3 { margin: 0 0 6px; font: 700 20px var(--font-display); }
.card p { margin: 0; color: var(--ink-2); font-size: 15px; line-height: 1.4; }
.skeleton { height: 120px; border-radius: var(--r-card); background: rgba(255,255,255,.5); }

/* ── Превью блюда по долгому нажатию ────────────────── */
.peek { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
        background: rgba(20, 24, 15, .22);
        -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.peek-card { width: 100%; max-width: 340px; background: #fff; border-radius: 26px; padding: 20px 18px 16px;
             box-shadow: var(--shadow-lift); animation: pop .22s cubic-bezier(.2, 1.4, .4, 1);
             -webkit-user-select: none; user-select: none; }
@keyframes pop { from { transform: scale(.85); opacity: .4; } }
.peek-em { font-size: 34px; line-height: 1; }
.peek-name { font: 700 21px/1.2 var(--font-display); margin-top: 8px; overflow-wrap: break-word; }
.peek-kcal { margin-top: 10px; font-size: 15px; color: var(--ink-2); }
.peek-kcal b { font: 700 26px var(--font-display); color: var(--ink); font-variant-numeric: tabular-nums; }
.peek-bju { display: flex; gap: 6px; margin-top: 10px; }
.peek-bju div { flex: 1; padding: 7px 9px; border-radius: var(--r-sm); background: rgba(20,24,15,.05);
                font-size: 12px; color: var(--ink-2); font-weight: 600; }
.peek-bju b { display: block; font: 700 17px var(--font-display); color: var(--ink); font-variant-numeric: tabular-nums; }
.peek-actions { display: flex; gap: 8px; margin-top: 16px; }
.peek-actions .btn { flex: 1; }
.peek-input { width: 100%; height: 46px; margin-top: 14px; border-radius: 14px; border: 0; outline: 0;
              background: rgba(20,24,15,.06); padding: 0 14px; font-size: 16px; font-weight: 600;
              -webkit-user-select: text; user-select: text; }
.peek-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* ── «Еда»: экран ровно в высоту окна ───────────────────
   Сверху итог + список (растягивается и прокручивается внутри), снизу —
   сетка блюд и поле чата, прижатые к таб-бару. Типичный день (до 10 записей,
   p90 по истории) помещается без прокрутки на iPhone 15 Pro Max. */
[data-section="food"] #app { height: 100dvh; overflow: hidden; gap: 6px; }
[data-section="food"] .hero { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; }
[data-section="food"] .hero .list { flex: 1 1 auto; min-height: 0; max-height: none; margin-bottom: 0; }
[data-section="food"] .dishes, [data-section="food"] .chat, [data-section="food"] .top { flex: none; }
[data-section="food"] .hero .kcal { font-size: 34px; }
[data-section="food"] .hero { padding-top: 8px; }
[data-section="food"] .hero .label { display: none; }  /* «сегодня» уже в плашке даты */
[data-section="food"] .hero .list { margin-top: 8px; }
[data-section="food"] .tile { height: 44px; }
[data-section="food"] .more-btn { height: 28px; margin: 0 0 5px; }  /* над сеткой, слева */
/* Переписка — шторка над строкой ввода, поверх сетки блюд: раскладка
   экрана не меняется, итог дня и верх списка остаются видны */
.chat { position: relative; }
.chat-panel { display: none; position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 15;
              flex-direction: column; max-height: 46dvh; padding: 6px 6px 0;
              background: #FCFDF9; border: 1px solid var(--line); border-radius: 22px;
              box-shadow: 0 -6px 28px rgba(20, 24, 15, .14); }
.chat.open .chat-panel { display: flex; }
.chat-panel .thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-panel .thread-head { padding: 2px 2px 2px 8px; gap: 4px; }
.chat-panel .thread-head span { flex: 1; }
.chat-panel .fold { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%;
                    background: rgba(20, 24, 15, .06); color: var(--ink); padding: 0; }
.chat-panel .fold svg { width: 20px; height: 20px; }

/* однострочные строки списка съеденного (~33 px) */
.row.slim .row-in { padding: 3px 14px; gap: 8px; min-height: 32px; }
.row.slim .nm .t { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.slim .g { height: 26px; padding: 0 9px; }
.row.slim .k { width: 44px; font-size: 15px; }

/* Шапки ниже зоны «scroll edge effect» iOS 26 (+8 px к отступу #app) */

/* Итог дня: точки БЖУ в одну вертикаль — сетка «точка | число | подпись» */
.bju { display: grid; grid-template-columns: 7px auto 46px; column-gap: 6px; row-gap: 3px;
       align-items: center; align-content: start; }
.bju .m { display: contents; }
.bju b { text-align: right; min-width: 3ch; }
.bju span { width: auto; }

/* Строка списка: название (обрезается) + мелко БЖУ, в одну строку */
.row.slim .nm { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.row.slim .nm .t { flex: 0 1 auto; min-width: 0; }
.row.slim .mac { flex: none; font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums;
                 white-space: nowrap; letter-spacing: -.01em; }

/* Выбор вкуса группы (Буми) */
.flavors { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.flavor { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "n k" "b k"; align-items: center;
          text-align: left; padding: 10px 12px; border-radius: 14px; background: rgba(20,24,15,.05); }
.flavor:active { background: var(--accent-soft); }
.flavor:first-child { box-shadow: inset 0 0 0 2px var(--accent); }  /* последний выбранный */
.flavor .fn { grid-area: n; font-weight: 700; font-size: 15px; }
.flavor .fb { grid-area: b; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.flavor .fk { grid-area: k; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.flavor .fk b { font-size: 17px; color: var(--ink); }

/* Неделя и цель — отдельной строкой под итогом; цель правится тапом,
   но выглядит обычным текстом */
[data-section="food"] .week { margin-top: 6px; font-size: 12.5px; }
.week .tgt { width: 4.6ch; border: 0; outline: 0; padding: 0; margin: 0; background: transparent;
             font: inherit; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.week .tgt:focus { color: var(--ink); font-size: 16px; width: 5ch; }

/* Плитки блюд ещё компактнее + воздух между сеткой и полем чата */
[data-section="food"] .tile { height: 40px; padding: 4px 6px; gap: 5px; border-radius: 12px; }
[data-section="food"] .tile .em { font-size: 13px; }
[data-section="food"] .tile .nm { font-size: 11.5px; }
[data-section="food"] .tile .mt { font-size: 9.5px; }
[data-section="food"] .grid { gap: 5px; }
[data-section="food"] .dishes { margin-bottom: 8px; }
/* подгонка под 10 строк без прокрутки после выноса недели на свою строку */
[data-section="food"] .week { margin-top: 3px; }
[data-section="food"] .hero { padding-top: 6px; }
[data-section="food"] .hero .list { margin-top: 5px; }
[data-section="food"] .more-btn { margin-bottom: 4px; }
