/* Палитра «эвкалипт и слива» — общая с Энциклопедией здоровья */
: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); }
.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ================= «Тарелка из холодильника» ================= */
.seg-ctl { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-ctl button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600;
}
.seg-ctl button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.left-line { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0 0; min-height: 1em; }

.guide { margin-bottom: 28px; }
.guide-body { display: flex; gap: 14px; align-items: flex-start; padding-bottom: 12px; }
.guide-plate { width: 84px; height: 84px; flex: none; }
.guide-list, .q-items, .tips ul { list-style: none; margin: 0; padding: 0; }
.guide-list li { font-size: 14px; padding-left: 16px; position: relative; margin-bottom: 6px; color: var(--muted); }
.guide-list li b { color: var(--ink); }
.guide-list li::before, .q-label::before, .pgroup b::before {
  content: ""; position: absolute; left: 0; top: .45em; width: 9px; height: 9px; border-radius: 3px; background: var(--c);
}

.plate-card {
  margin-top: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 14px 16px;
}
.plate-card.incomplete { border-color: var(--plum); }
.plate-meal { font-size: 12px; font-weight: 700; color: var(--plum); letter-spacing: .03em; text-transform: uppercase; }
.plate-meal .warn { text-transform: none; letter-spacing: 0; }
.plate-card h3 { font-family: var(--serif); font-weight: 600; font-size: 19px; line-height: 1.25; margin: 2px 0 10px; }
.quarters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.q { background: var(--surface); border-radius: 12px; padding: 9px 11px; }
.q:first-child { grid-column: 1 / -1; }
.q-label { position: relative; padding-left: 15px; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.q-items { font-size: 14px; line-height: 1.4; }
.q-items li + li { margin-top: 3px; }
.q.empty { background: var(--plum-soft); }
.q.empty .q-items { color: var(--plum); font-weight: 600; }
.cook { margin-top: 10px; }
.cook summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--accent); list-style: none; }
.cook summary::-webkit-details-marker { display: none; }
.cook summary::before { content: "▸ "; }
.cook[open] summary::before { content: "▾ "; }
.cook ol { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }
.cook li { margin: 3px 0; }
.plate-note { margin: 10px 0 0; font-size: 14px; color: var(--muted); }

.missing, .tips, .all-good { margin-top: 22px; }
.missing h2, .tips h2 { font-family: var(--serif); font-weight: 600; font-size: 21px; margin: 0 0 8px; }
.miss { background: var(--plum-soft); border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; }
.miss-part { font-weight: 700; color: var(--plum); font-size: 15px; margin-bottom: 4px; }
.miss p { margin: 4px 0; font-size: 14px; }
.miss .lbl { font-weight: 700; }
.miss .read { display: inline-block; margin: 6px 0 2px; font-size: 14px; font-weight: 600; color: var(--plum); text-decoration: none; }
.buy { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.buy span { background: var(--card); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 600; }
.all-good { background: var(--accent-soft); border-radius: 16px; padding: 12px 14px; display: grid; gap: 2px; font-size: 14px; }
.all-good b { color: var(--accent); font-size: 15px; }
.tips li { font-size: 14px; padding-left: 18px; position: relative; margin: 5px 0; }
.tips li::before { content: "•"; position: absolute; left: 4px; color: var(--accent); font-weight: 800; }

.pgroup { display: grid; gap: 1px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.pgroup b { position: relative; padding-left: 15px; font-size: 13px; }
.pgroup span { color: var(--muted); }
.pgroup.unsure b::before { background: var(--plum); }
.fine { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.dock .row.two { grid-template-columns: 1fr 1fr; }
.with-dock { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
.gate a { color: var(--accent); font-weight: 700; }
.no-plates { margin-top: 14px; background: var(--plum-soft); border-radius: 16px; padding: 12px 14px; display: grid; gap: 4px; font-size: 14px; }
.no-plates b { color: var(--plum); font-size: 15px; }

/* две кнопки: камера и галерея */
.pick { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick .drop { margin: 0; min-height: 140px; padding: 16px 10px; }
.pick .drop .big { font-size: 17px; }
.pick .drop.alt { border-color: var(--plum); background: var(--plum-soft); color: var(--plum); }
.pick-hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); text-align: center; }
.thumb.add-pair { display: grid; grid-template-rows: 1fr 1fr; gap: 6px; background: none; overflow: visible; }
.add-pair button {
  border: 1.5px dashed var(--line); background: none; border-radius: 12px; color: var(--accent);
  font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.add-pair button + button { color: var(--plum); }
.add-pair span { font-size: 18px; }

/* камера внутри приложения */
.cam { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; display: flex; flex-direction: column; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .8; } to { opacity: 0; } }
.cam-top {
  position: relative; display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
}
.cam-close { width: 40px; height: 40px; border-radius: 20px; border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 18px; }
.cam-count { font-weight: 700; font-size: 15px; background: rgba(0,0,0,.45); padding: 6px 12px; border-radius: 999px; }
.cam-count:empty { display: none; }
.cam-hint {
  position: relative; margin: auto 24px 16px; text-align: center; font-weight: 600; font-size: 15px;
  background: rgba(0,0,0,.45); padding: 8px 12px; border-radius: 12px;
}
.cam-bar {
  position: relative; margin-top: auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 18px 20px calc(22px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.cam-hint:not([hidden]) + .cam-bar { margin-top: 0; }
.cam-last { width: 54px; height: 54px; border-radius: 12px; overflow: hidden; border: 2px solid rgba(255,255,255,.8); }
.cam-last:empty { visibility: hidden; }
.cam-last img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; }
.cam-shutter i { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; }
.cam-shutter:active i { transform: scale(.9); }
.cam-done { justify-self: end; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; padding: 12px 18px; }
.cam-error { background: var(--bg); color: var(--ink); justify-content: center; padding: 24px 16px; }
.cam-msg { max-width: 420px; margin: 0 auto; display: grid; gap: 10px; }
.cam-msg b { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.cam-msg p { margin: 0; color: var(--muted); }
