:root {
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --card: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15171a);
  --muted: var(--tg-theme-hint-color, #7a7f87);
  --accent: var(--tg-theme-button-color, #2f9e62);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, .18);
  --ok: #2f9e62;
  --warn: #e08a1e;
  --bad: #d6453d;
  --p: #3b82c4;
  --f: #d9a21b;
  --c: #8b5cc7;
  --snack: #e08a1e;
  --sweet: #d6458f;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #0f1115);
    --card: var(--tg-theme-section-bg-color, #1a1d23);
    --text: var(--tg-theme-text-color, #eceef1);
    --muted: var(--tg-theme-hint-color, #8d939c);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 0 calc(76px + env(safe-area-inset-bottom));
}
#app { max-width: 560px; margin: 0 auto; padding: 12px 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h2 { margin: 8px 0 12px; font-size: 22px; }
h3 { margin: 20px 0 8px; font-size: 17px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.primary { background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.secondary { background: var(--line); border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.primary:disabled, .secondary:disabled { opacity: .5; }
.icon { font-size: 28px; width: 44px; height: 44px; border-radius: 50%; }
.icon:disabled { opacity: .25; }
.hint { font-size: 13px; margin: -4px 4px 14px; }

/* вход */
.login-box { text-align: center; padding: 18vh 12px 0; }
.login-box .logo { font-size: 56px; }
.login-box h1 { margin: 8px 0; }
.login-box .primary { width: 100%; margin-top: 12px; }

/* день */
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.day-title { text-align: center; display: flex; flex-direction: column; }
.day-title b { font-size: 18px; }
.ring-card { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 12px; position: relative; }
#ring { width: 150px; height: 150px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--ok); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .5s, stroke .3s; }
.ring-center { position: absolute; left: 14px; width: 150px; text-align: center; }
.ring-center .big { font-size: 30px; font-weight: 700; line-height: 1.1; }
.ring-center .muted { font-size: 12px; }
.ring-side { display: flex; flex-direction: column; gap: 10px; }
.ring-side div { display: flex; flex-direction: column; }
.ring-side b { font-size: 20px; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.macro .name { font-size: 13px; color: var(--muted); }
.macro .val { font-weight: 600; margin: 2px 0 6px; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; transition: width .5s; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { background: var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chip.snack { background: color-mix(in srgb, var(--snack) 20%, transparent); }
.chip.sweet { background: color-mix(in srgb, var(--sweet) 20%, transparent); }
.timeline { position: relative; height: 26px; }
.tl-axis { position: absolute; left: 0; right: 0; top: 12px; height: 2px; background: var(--line); }
.tl-dot { position: absolute; top: 5px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--ok); border: 2px solid var(--card); }
.tl-dot.snack { background: var(--snack); }
.tl-dot.sweet { background: var(--sweet); }
.tl-dot.nc { background: var(--muted); opacity: .5; }
.tl-now { position: absolute; top: 0; width: 2px; height: 26px; background: var(--muted); opacity: .6; }
.tl-labels { display: flex; justify-content: space-between; font-size: 11px; margin-top: 2px; }

.add { display: flex; gap: 8px; padding: 8px; }
.add input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: inherit; padding: 8px; outline: none; }
.add .primary { padding: 8px 16px; font-size: 20px; }

.entry { background: var(--card); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.entry-main { display: flex; gap: 12px; padding: 12px; align-items: center; width: 100%; text-align: left; }
.thumb { width: 56px; height: 56px; border-radius: 12px; background: var(--line) center/cover no-repeat; flex: none; display: grid; place-items: center; font-size: 26px; }
.entry-body { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 13px; color: var(--muted); }
.entry-kcal { text-align: right; font-weight: 700; white-space: nowrap; }
.entry-kcal small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 1px; }
.tag.snack { background: color-mix(in srgb, var(--snack) 22%, transparent); }
.tag.sweet { background: color-mix(in srgb, var(--sweet) 22%, transparent); }
.tag.pending { background: var(--line); }
.tag.nc { background: var(--line); }
.entry-more { padding: 0 12px 12px; border-top: 1px solid var(--line); }
.entry-more .note { font-style: italic; margin: 10px 0; }
.items { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.items td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.items td:not(:first-child) { text-align: right; padding-left: 8px; white-space: nowrap; }
.photo-big { width: 100%; border-radius: 12px; margin-top: 10px; display: block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions button { flex: 1; min-width: 90px; }
.fix { display: flex; gap: 8px; margin-top: 10px; }
.fix input { flex: 1; min-width: 0; }
.edit-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.edit-grid label, .form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; width: 100%;
}
.checks { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; }
.checks label { display: flex; align-items: center; gap: 6px; }
.checks input { width: auto; }
.empty { text-align: center; padding: 30px 10px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc-out { background: var(--bg); border-radius: 10px; padding: 10px; font-size: 14px; }

/* история */
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
#hist-chart svg { width: 100%; height: 180px; display: block; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 18px; }
.hrow { display: flex; justify-content: space-between; align-items: center; background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; width: 100%; text-align: left; }
.hrow .d { font-weight: 600; }
.hrow .s { font-size: 12px; color: var(--muted); }

nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
nav#tabs button { flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); padding: 4px; }
nav#tabs button span { font-size: 20px; }
nav#tabs button.on { color: var(--accent); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto; background: #222; color: #fff; padding: 12px 14px;
  border-radius: 12px; font-size: 14px; z-index: 10;
}

/* ---- v2: ИИ-ввод, приёмы, шторка ---- */
.quick { display: flex; flex-direction: column; gap: 8px; }
.photo-btn { display: flex; align-items: center; justify-content: center; font-size: 17px; padding: 14px; cursor: pointer; }
.photo-btn.disabled { opacity: .5; pointer-events: none; }
.wide { width: 100%; display: flex; justify-content: center; margin: 4px 0 12px; }
.quick .add { padding: 0; }
.quick .add input { background: var(--bg); border-radius: 10px; }
.busy { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.block-title { font-weight: 600; margin: 4px 4px 8px; }
.entry.draft { border: 1px dashed var(--muted); }
.entry.draft .entry-main { padding-bottom: 4px; }
.entry-main { display: flex; gap: 12px; padding: 12px; align-items: center; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 12px 12px; align-items: center; }
.sheet .row-btns { padding: 12px 0 0; }
.row-btns > button { flex: 1; min-width: 0; padding: 10px 8px; }
.row-btns > .icon-btn { flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: var(--line); font-size: 17px; flex: none; }
.danger { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.meal { padding: 10px 12px; }
.meal-head { display: flex; align-items: center; gap: 8px; }
.meal-head b { flex: 1; font-size: 16px; }
.add-small { width: 36px; height: 36px; border-radius: 50%; background: var(--line); font-size: 20px; color: var(--accent); }
.meal .row { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.row-main { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; text-align: left; padding: 0; }
.meal .thumb { width: 44px; height: 44px; font-size: 20px; border-radius: 10px; }
.meal .icon-btn { width: 34px; height: 34px; font-size: 15px; background: transparent; opacity: .6; }
.entry-ask { font-size: 12px; color: var(--warn); margin-top: 2px; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; box-shadow: 0 -6px 30px rgba(0,0,0,.25);
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.label { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { background: var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; }
.chip-btn.on { background: var(--accent); color: var(--accent-text); }
.chip-btn.big { border-radius: 12px; display: flex; flex-direction: column; align-items: center; min-width: 76px; font-weight: 600; }
.chip-btn small { font-weight: 400; font-size: 11px; color: var(--muted); }
.pick { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 10px 2px; border-bottom: 1px solid var(--line); text-align: left; gap: 8px; }
.pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick small { color: var(--muted); white-space: nowrap; }
.more { margin-top: 14px; }
.more summary { color: var(--muted); font-size: 14px; cursor: pointer; padding: 6px 0; }
.span2 { grid-column: 1 / -1; }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
label.check input { width: auto; }
.r-row { display: flex; gap: 6px; align-items: center; }
.r-row select { flex: 1; min-width: 0; }
.r-row input { width: 80px; flex: none; }
body.noscroll { overflow: hidden; }
#prod-new { margin-top: 4px; }
.ask { margin: 6px 0 2px 54px; font-size: 13px; }
.ask .chip-row { margin-top: 4px; }
.ask .chip-btn { padding: 5px 12px; font-size: 13px; }
.health { font-size: 13px; margin-top: 8px; }
.tip { background: color-mix(in srgb, var(--ok) 12%, transparent); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.sheet-close { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border-radius: 50%; background: var(--line); font-size: 15px; }
.sheet { position: fixed; }
.lipid { margin-top: -4px; }
.small { font-size: 11px; line-height: 1.2; }
