/* Палитра «эвкалипт и слива» — общая с Энциклопедией здоровья */
:root {
  --bg: #F5F7F3;
  --surface: #E9EEE8;
  --card: #FFFFFF;
  --ink: #1E2925;
  --muted: #5D6A64;
  --line: #D3DCD5;
  --accent: #4C7A6B;
  --accent-soft: #DCE8E2;
  --plum: #8E5672;
  --plum-soft: #F2E6EC;
  --focus: #2F6F5C;
  /* доли тарелки */
  --c-veg: #6FA35A;
  --c-protein: #B8644F;
  --c-carbs: #D8A43D;
  --c-fats: #8E7BB0;
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Manrope", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #131A17;
  --surface: #1C2521;
  --card: #18201D;
  --ink: #E5ECE8;
  --muted: #9AA9A2;
  --line: #2B3732;
  --accent: #8CC0AE;
  --accent-soft: #22322C;
  --plum: #D49AB6;
  --plum-soft: #2E2229;
  --focus: #A6D4C4;
  --c-veg: #8CC27A;
  --c-protein: #D98A74;
  --c-carbs: #E5BC62;
  --c-fats: #AE9DD0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.with-dock { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

/* ---------- шапка ---------- */
.head { padding: 24px 0 6px; }
.head .kicker { font-size: 13px; font-weight: 700; color: var(--plum); letter-spacing: .02em; }
.head h1 {
  font-family: var(--serif); font-weight: 600;
  font-size: 28px; line-height: 1.15; letter-spacing: -0.01em;
  margin: 4px 0 6px;
}
.head p { margin: 0; color: var(--muted); font-size: 15px; }

/* ---------- загрузка фото ---------- */
.drop {
  margin-top: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 168px; padding: 22px;
  border: 1.5px dashed var(--accent); border-radius: 18px;
  background: var(--accent-soft); color: var(--accent);
  text-align: center;
}
.drop:active { filter: brightness(.97); }
.drop .big { font-size: 18px; font-weight: 700; }
.drop small { color: var(--muted); font-size: 13px; font-weight: 600; }
.drop.over { border-style: solid; }

.thumbs { margin-top: 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--surface); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n, .strip .n {
  position: absolute; left: 6px; top: 6px;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: rgba(20, 28, 25, .72); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.thumb .x {
  position: absolute; right: 5px; top: 5px; width: 28px; height: 28px; border-radius: 14px; border: 0;
  background: rgba(20, 28, 25, .72); color: #fff; font-size: 16px; line-height: 1;
}
.thumb.add {
  border: 1.5px dashed var(--line); background: none; color: var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 700; font-size: 13px;
}
.thumb.add span { font-size: 26px; line-height: 1; font-weight: 500; }
.thumb.busy::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: shimmer 1s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- поля ---------- */
.field { margin-top: 20px; }
.field label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field label small { color: var(--muted); font-weight: 600; }
.input, .textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: none; min-height: 86px; line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink);
}
.chip:active, .chip[aria-pressed="true"] { background: var(--plum-soft); border-color: var(--plum); color: var(--plum); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--bg); font-weight: 700; font-size: 16px;
  width: 100%;
}
.btn:active { filter: brightness(.94); }
.btn[disabled] { opacity: .45; cursor: default; filter: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: none; color: var(--accent); height: 44px; }
.btn.done { background: var(--plum); }
.cta { margin: 22px 0 28px; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
  display: grid; gap: 8px;
}
.dock .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.dock .row .btn { height: 54px; font-size: 12.5px; padding: 0 4px; gap: 1px; flex-direction: column; line-height: 1.2; }
.dock .row .btn .i { font-size: 17px; }
@media (min-width: 680px) { .dock { padding-inline: calc(50% - 320px + 16px); } }

/* ---------- анализ: загрузка ---------- */
.thinking { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 18px; }
.plate-anim { width: 132px; height: 132px; }
.plate-anim .seg { transform-origin: 66px 66px; animation: spin 2.4s cubic-bezier(.6,.1,.3,.9) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking h2 { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 0; }
.thinking p { margin: 0; color: var(--muted); min-height: 1.5em; }
.thinking .wait-note { font-size: 13px; opacity: .8; }
.mini-thumbs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.mini-thumbs img { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; }

/* ---------- результат ---------- */
.strip { display: flex; gap: 8px; overflow-x: auto; margin: 16px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip button { flex: none; border: 0; padding: 0; background: none; border-radius: 14px; overflow: hidden; position: relative; }
.strip img { width: 92px; height: 92px; object-fit: cover; display: block; }
.strip .n { position: absolute; left: 6px; top: 6px; }

.msg-card {
  margin-top: 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 16px 16px 14px;
}
.msg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.msg-head strong { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .02em; }
.msg-head .meta { font-size: 12px; color: var(--muted); }
.msg {
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 16px; line-height: 1.55; margin: 0;
}
.msg-edit {
  width: 100%; border: 0; outline: none; background: none; resize: none;
  font-size: 16px; line-height: 1.55; padding: 0; min-height: 200px;
}
.msg-card.editing { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.learn-note { margin-top: 8px !important; font-size: 13px !important; color: var(--accent) !important; font-weight: 600; }
/* полноэкранный редактор ответа: высота = видимая область над клавиатурой */
.editor {
  position: fixed; left: 0; right: 0; top: 0; height: 100vh; z-index: 80;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.editor-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.editor-bar button {
  border: 0; background: none; font-weight: 700; font-size: 15px; padding: 8px 6px; color: var(--muted);
}
.editor-bar .editor-done { color: var(--bg); background: var(--accent); border-radius: 10px; padding: 8px 14px; }
.editor-count { font-size: 12px; color: var(--muted); }
.editor .msg-edit {
  flex: 1; min-height: 0; width: 100%; resize: none; border: 0; outline: none;
  padding: 14px 16px 30vh; /* запас снизу, чтобы последние строки можно было поднять повыше */
  font-size: 16px; line-height: 1.5; background: var(--card); color: var(--ink);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
@media (min-width: 680px) { .editor { left: calc(50% - 320px); right: calc(50% - 320px); } }
body.editing-open { overflow: hidden; }
body.editing-open .dock { display: none; }
.len-hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }
.len-hint::before { content: "ⓘ "; color: var(--plum); }
.counter { font-size: 12px; color: var(--muted); margin-top: 8px; text-align: right; }

/* сводка ИИ */
.insight { margin-top: 16px; border-top: 1px solid var(--line); }
.insight > summary {
  list-style: none; cursor: pointer; padding: 14px 0;
  display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 15px;
}
.insight > summary::-webkit-details-marker { display: none; }
.insight > summary::after { content: "+"; font-size: 20px; color: var(--accent); font-weight: 500; }
.insight[open] > summary::after { content: "–"; }
.insight .summary-row { display: flex; gap: 8px; margin-bottom: 12px; }
.pill { background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.pill b { display: block; font-family: var(--serif); font-size: 20px; color: var(--ink); font-weight: 600; }

.meal { padding: 12px 0 14px; border-top: 1px solid var(--line); }
.meal h3 { margin: 0 0 2px; font-size: 15px; display: flex; gap: 8px; align-items: baseline; }
.meal h3 small { color: var(--muted); font-weight: 600; font-size: 12px; }
.meal .items { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface); }
.bar i { display: block; height: 100%; }
.bar i + i { box-shadow: -2px 0 0 var(--card); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); }
.legend .target { margin-left: auto; }
.notes { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.notes li { padding-left: 20px; position: relative; margin: 2px 0; }
.notes li::before { position: absolute; left: 0; }
.notes .ok::before { content: "✓"; color: var(--accent); font-weight: 700; }
.notes .bad::before { content: "!"; color: var(--plum); font-weight: 800; left: 4px; }

/* ---------- экран доступа ---------- */
.gate { min-height: 90vh; display: flex; flex-direction: column; justify-content: center; padding-block: 30px; }
.gate .mark { width: 76px; height: 76px; margin-bottom: 18px; }
.gate h1 { font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 1.2; margin: 0 0 10px; }
.gate p { color: var(--muted); margin: 0 0 8px; max-width: 30em; }
.gate .sig { margin-top: 18px; font-family: var(--serif); font-style: italic; color: var(--plum); }

.error-box { margin-top: 16px; background: var(--plum-soft); color: var(--ink); border-radius: 14px; padding: 14px 16px; font-size: 15px; }
.error-box strong { color: var(--plum); }

/* ---------- нижняя панель ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 14, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 80vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  animation: up .22s ease-out;
}
@media (min-width: 680px) { .sheet { left: calc(50% - 320px); right: calc(50% - 320px); } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 20px; margin: 0 0 4px; }
.sheet p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.opts { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 14px;
}
.opt .e { font-size: 22px; width: 28px; text-align: center; }
.opt b { display: block; font-size: 15px; }
.opt small { color: var(--muted); font-size: 13px; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: calc(160px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  z-index: 70; white-space: nowrap; animation: up .18s ease-out;
}

/* ---------- вкладки ---------- */
.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 12px;
  background: var(--surface); border-radius: 14px; padding: 4px;
}
.tabs button {
  border: 0; background: none; border-radius: 10px; padding: 9px 6px;
  font-weight: 700; font-size: 14px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--plum); color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- отчёты группы ---------- */
.thinking.short { min-height: 50vh; }
.reps { display: grid; gap: 10px; margin-top: 16px; }
.rep {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
  border-left: 4px solid var(--line);
}
.rep.s-ready { border-left-color: var(--accent); }
.rep.s-copied { border-left-color: var(--plum); }
.rep.s-error { border-left-color: var(--c-protein); }
.rep.s-closed { opacity: .7; }
.rep-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.rep-top b { font-size: 16px; }
.rep-top span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rep-photos { display: flex; gap: 6px; margin-top: 8px; }
.rep-photos .ph { width: 52px; height: 52px; border-radius: 10px; overflow: hidden; background: var(--surface); flex: none; }
.rep-photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rep-photos .more { display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.rep-preview { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.4; }
.badge { display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.rep.s-ready .badge { color: var(--accent); }
.rep.s-copied .badge { color: var(--plum); }
.ph.missing { background: var(--surface); }
.strip .ph img:not([src]) { background: var(--surface); }
.closed-list { margin-top: 22px; }
.status-line { font-weight: 700; color: var(--plum) !important; font-size: 14px !important; }
.caption {
  margin-top: 14px; background: var(--surface); border-radius: 14px; padding: 10px 14px;
  font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.caption small { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0 10px; }
.empty small { font-size: 13px; }
.howto { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.howto h2 { font-family: var(--serif); font-weight: 600; font-size: 20px; margin: 0 0 8px; }
.howto ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.howto code { background: var(--surface); padding: 1px 6px; border-radius: 6px; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- кабинет Жанны: переключатель приложений ---------- */
:root { --hub-h: 54px; }
.hub-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 6px 8px; height: var(--hub-h);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.hub-bar button {
  border: 0; border-radius: 12px; background: none; color: var(--muted);
  font-size: 11.5px; font-weight: 700; line-height: 1.1; padding: 2px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0;
}
.hub-bar button .i { font-size: 18px; line-height: 1; }
.hub-bar button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
@media (min-width: 680px) { .hub-bar { padding-inline: calc(50% - 320px + 8px); } }
body.hub { padding-top: var(--hub-h); }
.hub-frames { position: fixed; top: var(--hub-h); left: 0; right: 0; bottom: 0; z-index: 80; background: var(--bg); }
.hub-frame { display: block; width: 100%; height: 100%; border: 0; }
.hub-frame[hidden] { display: none; }
body.hub-away { overflow: hidden; }
