/* Палитра — единственное место с цветами. Всё остальное ссылается на эти токены. */
:root {
  color-scheme: dark;
  --bg: #0B0C0F;
  --card: #141618;
  --plate: #1C1E21;
  --plate-2: #242628;
  --line: #27282B;
  --text: #F2F3F5;
  --text-2: #8E9196;
  --on-accent: #0B0C0F;
  --check: #F7F8FA;
  --scrim: rgb(0 0 0 / 55%);

  --purple: #A39FF3;  /* ккал */
  --pink: #E185B6;    /* белки */
  --amber: #E0A254;   /* жиры */
  --blue: #76B3F4;    /* углеводы */
  --green: #86CD8C;
  --teal: #63BEA4;    /* клетчатка */
  --cyan: #60C0E6;    /* вода */
  --orange: #F57F00;
  --red: #B26660;     /* пропуск */

  --nav: 68px;        /* высота нижней навигации без safe-area */
  --radius: 24px;
  --radius-s: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;

  /* нижний отступ: safe-area + нижние кнопки Telegram (--bar выставляет JS, пока они видны) */
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --bar: 0px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F2F3F7;
  --card: #FFFFFF;
  --plate: #F0F1F5;
  --plate-2: #E4E6EC;
  --line: #E3E5EA;
  --text: #0F1115;
  --text-2: #6B7078;
  --scrim: rgb(0 0 0 / 35%);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, p, ol, ul { margin: 0; padding: 0; }
button { font: inherit; color: inherit; }
b { font-weight: 700; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--tg-content-safe-area-inset-top, 0px)) 16px calc(32px + var(--nav) + var(--safe-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* без этого nowrap-название еды раздувает всю колонку шире экрана */
  gap: 20px;
}
main[aria-busy="true"] .card { opacity: .55; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hint { color: var(--text-2); font-size: 14px; }
.eyebrow { color: var(--text-2); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 0 6px 10px; }

/* Цвет сущности: .c-<имя> задаёт --c, дальше всё берёт var(--c) */
.c-purple { --c: var(--purple); } .c-pink { --c: var(--pink); } .c-amber { --c: var(--amber); }
.c-blue { --c: var(--blue); } .c-green { --c: var(--green); } .c-teal { --c: var(--teal); }
.c-cyan { --c: var(--cyan); } .c-orange { --c: var(--orange); } .c-red { --c: var(--red); }

/* Шапка: дата и полоса недели */
.top-row { display: flex; justify-content: space-between; align-items: flex-end; padding: 6px 6px 0; }
h1 { font-size: 32px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.now { color: var(--text-2); font-size: 15px; font-weight: 600; background: var(--card); border-radius: 999px; padding: 6px 12px; }
.week { list-style: none; display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-top: 14px; }
.wk { display: grid; justify-items: center; gap: 6px; padding: 8px 0 8px; border-radius: 22px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.wk.today { background: var(--plate-2); color: var(--text); }
.wk-ring { position: relative; width: 38px; height: 38px; display: grid; place-items: center; font-size: 16px; font-weight: 700; color: var(--text); }
.wk-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.wk-ring circle { fill: none; stroke-width: 3.5; }
.wk-ring .track { stroke: var(--line); }
.wk.today .track { stroke: color-mix(in srgb, var(--text-2) 35%, transparent); }
.wk-ring .val { stroke: var(--green); stroke-linecap: round; }
.wk.future .wk-ring { color: var(--text-2); }
.wk.future .track { stroke: color-mix(in srgb, var(--text-2) 45%, transparent); stroke-dasharray: 1.5 5; stroke-linecap: round; }
.wk.zero .val { opacity: 0; }

/* Карточки */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  transition: opacity .3s var(--ease);
}
.card + .card { margin-top: 12px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.stack > .card, .stack .day .card { margin-top: 0; }
.sec-title { padding: 6px 6px 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 17px; font-weight: 700; flex: 1; }
.goal { color: var(--text-2); font-size: 14px; }
.goal b { color: var(--text); font-weight: 600; }

.plate.sm { width: 28px; height: 28px; border-radius: 9px; }
.plate.sm .ic { width: 16px; height: 16px; }
.plate.lg { width: 48px; height: 48px; border-radius: 15px; }
.plate.lg .ic { width: 26px; height: 26px; }
.plate {
  width: 34px; height: 34px; flex: none; border-radius: 11px;
  display: grid; place-items: center;
  color: var(--c, var(--text-2));
  background: color-mix(in srgb, var(--c, var(--text-2)) 16%, var(--card));
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 8px; vertical-align: 1px; }

/* Полосы прогресса */
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--plate-2); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 4px; background: var(--cyan); transition: width .9s var(--ease); }
.bar.teal i { background: var(--teal); }
.bar u { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .7; text-decoration: none; }

/* Вода */
.water-main { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; }
.water-num { display: grid; justify-items: start; line-height: 1; }
.water-num b { font-size: 46px; font-weight: 800; letter-spacing: -.03em; color: var(--cyan); }
.water-num span { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.water-viz { min-width: 0; }
.glasses { display: flex; justify-content: space-between; gap: 5px; margin-bottom: 10px; }
.cup { flex: 1 1 0; min-width: 0; max-width: 28px; height: auto; aspect-ratio: 24 / 28; overflow: visible; }
.cup .line { fill: none; stroke: var(--cyan); stroke-width: 1.8; stroke-linejoin: round; }
.cup .liquid { fill: var(--cyan); transform-box: fill-box; transform-origin: 50% 100%; transition: transform .8s var(--ease); }
.bar-labels { display: flex; justify-content: space-between; gap: 8px; color: var(--text-2); font-size: 13px; margin-top: 6px; }
.bar-labels .behind { color: var(--orange); }
.split { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 14px; color: var(--text-2); font-size: 14px; }
.split b { color: var(--text); font-weight: 600; }
.chips { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  border: 0; border-radius: 999px; padding: 10px 16px;
  font: 600 15px/1 var(--font);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 14%, var(--card));
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .15s var(--ease), background .2s;
}
.chip.primary { color: var(--on-accent); background: var(--purple); }
.chip.danger { color: var(--red); background: color-mix(in srgb, var(--red) 16%, var(--card)); }
.chip.pop { animation: pop .35s var(--ease); }
.chip:active { transform: scale(.94); }
.entries { margin-top: 10px; }
.more { display: block; margin: 4px auto 0; }

/* Списки и строки */
.list { list-style: none; }
.list li { display: flex; align-items: center; gap: 12px; min-height: 48px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li.group { min-height: 0; border: 0; padding: 14px 0 4px; color: var(--text-2); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.list li.group:first-child { padding-top: 6px; }
.list button.row { all: unset; display: flex; align-items: center; gap: 12px; width: 100%; cursor: pointer; box-sizing: border-box; }
.row:focus-visible, .swipe-content:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; border-radius: 12px; }
.name { flex: 1; min-width: 0; }
.name small { display: block; color: var(--text-2); font-size: 13px; }
.empty { color: var(--text-2); font-size: 14px; padding: 8px 0; }
.plain li { min-height: 36px; font-size: 15px; }

.entry-time { color: var(--text-2); font-size: 14px; width: 44px; flex: none; }
.entry-ml { flex: none; font-weight: 600; }
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.icon-btn { border: 0; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; cursor: pointer; color: var(--text-2); background: var(--plate); }
.icon-btn:active { transform: scale(.9); }

/* Питание */
.rings-row { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 16px; align-items: center; }
.rings { width: 116px; height: 116px; transform: rotate(-90deg); }
.rings circle { fill: none; stroke-width: 8; }
.rings .track { stroke: color-mix(in srgb, var(--c) 18%, var(--card)); }
.rings .val { stroke: var(--c); stroke-linecap: round; transition: stroke-dashoffset 1s var(--ease), opacity .3s; }
.kcal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-weight: 700; white-space: nowrap; }
.kcal-head small { color: var(--text-2); font-size: 12px; font-weight: 500; text-align: right; }
.kcal-num { margin-top: 8px; color: var(--text-2); font-size: 15px; }
.kcal-num b { color: var(--text); font-size: 30px; letter-spacing: -.02em; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.macro { font-size: 13px; color: var(--text-2); }
.macro b { display: block; margin-top: 4px; font-size: 17px; color: var(--text); }
.macro b span { color: var(--text-2); font-weight: 500; font-size: 14px; }
.fiber { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 15px; }
.fiber .ic.teal { color: var(--teal); }
.fiber > span:first-of-type { color: var(--text-2); }
.fiber-val { color: var(--text-2); font-size: 15px; }
.fiber-val b { color: var(--text); }

.food li { padding: 8px 0; }
.food button.row { gap: 12px; }
.thumb {
  width: 46px; height: 46px; flex: none; border-radius: 14px; overflow: hidden;
  display: grid; place-items: center; color: var(--text-2); background: var(--plate);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; animation: fade .3s var(--ease); }
.food .name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food .name small { font-weight: 400; }
.food-kcal { text-align: right; flex: none; font-weight: 700; font-size: 16px; }
.food-kcal small { display: block; font-weight: 500; font-size: 12px; color: var(--cyan); }

/* Привычки */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--plate); border-radius: var(--radius-s); padding: 14px; }
.stat { color: var(--c); }
.stat > div { display: flex; align-items: center; gap: 6px; font-size: 19px; font-weight: 700; white-space: nowrap; }
.stat small { display: block; margin-top: 4px; color: var(--text-2); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.habit-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 6px; color: var(--text-2); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.dots { display: flex; gap: var(--dot-gap); }
.card.habits { --dot: clamp(20px, 5.4vw, 26px); --dot-gap: clamp(3px, 1.1vw, 6px); padding-inline: 14px; }
.dots > span { width: var(--dot); text-align: center; letter-spacing: 0; }
.dots > .today { color: var(--text); }
.habit-list li { padding: 0; }
.habit-list button.row { padding: 8px 0; gap: 8px; }
.habit-list .plate { width: 34px; height: 34px; }
.habit-list .name { font-size: 14px; font-weight: 500; line-height: 1.2; }
.habit-list .name small { margin-top: 2px; font-size: 12px; }
.dot-mark {
  width: var(--dot); height: var(--dot); flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--check);
  border: 2px solid var(--plate-2); background: transparent;
}
.dot-mark .ic { width: 62%; height: 62%; stroke-width: 3; }
.dot-mark.done { background: var(--c); border-color: var(--c); }
.dot-mark.skip { border-color: var(--red); color: var(--red); }
.dot-mark.pending { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), 0 0 12px color-mix(in srgb, var(--c) 45%, transparent); }
.dot-mark.off { background: var(--plate); border-color: transparent; }
.dot-mark.pop { animation: pop .4s var(--ease); }

/* Покупки */
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 14px; background: var(--plate); }
.seg button { border: 0; background: transparent; color: var(--text-2); font-weight: 600; font-size: 14px; padding: 8px 10px; border-radius: 11px; cursor: pointer; transition: background .2s var(--ease), color .2s; }
.seg button[aria-selected="true"] { background: var(--plate-2); color: var(--text); }
.add { display: flex; gap: 8px; margin: 14px 0 6px; }
.add input, .sheet-card input {
  flex: 1; min-width: 0; border: 0; border-radius: 14px; padding: 12px 14px;
  font: inherit; color: var(--text); background: var(--plate); outline: none;
}
.add input:focus, .sheet-card input:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--purple) 55%, transparent); }
.add .chip { width: 46px; padding: 0; flex: none; }
.mark {
  width: 26px; height: 26px; flex: none; border-radius: 8px; display: grid; place-items: center;
  border: 2px solid var(--plate-2); color: var(--check);
  transition: background .25s var(--ease), border-color .25s;
}
.mark .ic { width: 16px; height: 16px; stroke-width: 3; }
.mark.done { background: var(--green); border-color: var(--green); animation: pop .35s var(--ease); }
.mark.skip { background: var(--orange); border-color: var(--orange); animation: pop .35s var(--ease); }
.item.bought .name { text-decoration: line-through; color: var(--text-2); }
.item.skipped .name { color: var(--text-2); }
.item.skipped .name small { text-decoration: none; }
.item input.rename { flex: 1; min-width: 0; border: 0; border-radius: 12px; padding: 10px 12px; font: inherit; color: var(--text); background: var(--plate); outline: none; }
.item .remove { color: var(--red); background: color-mix(in srgb, var(--red) 16%, var(--card)); }
.actions { display: flex; gap: 18px; justify-content: flex-end; margin-top: 8px; }
.link { border: 0; background: none; color: var(--purple); font: 600 15px/1 var(--font); padding: 8px 0; cursor: pointer; }
.history-day { display: block !important; padding: 8px 0; }
.history-day b { display: block; font-size: 12px; color: var(--text-2); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }

/* Свайпы: контент едет поверх подложек с действиями */
.swipe { position: relative; overflow: hidden; padding: 0 !important; touch-action: pan-y; }
.swipe-content {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 48px; padding: 6px 0; background: var(--card); cursor: pointer; user-select: none; -webkit-user-select: none;
}
.swipe-left { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 16px; background: var(--green); color: var(--on-accent); font-weight: 700; }
.swipe-actions { position: absolute; top: 0; right: 0; bottom: 0; display: flex; }
.swipe .swipe-left, .swipe .swipe-actions { visibility: hidden; }
.swipe.peek .swipe-left, .swipe.revealed .swipe-actions { visibility: visible; }
.act { border: 0; width: 72px; color: #fff; font: 600 13px/1.1 var(--font); cursor: pointer; }
.act.skip { background: var(--orange); }
.act.edit { background: var(--blue); color: var(--on-accent); }
.act.del { background: var(--red); }

/* Лист: правка, причина, действия привычки. Скрытый (hidden) не занимает место и не ловит нажатия. */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: var(--scrim); animation: fade .2s var(--ease); }
.sheet-card {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; margin: 0 auto;
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 18px calc(18px + var(--safe-bottom) + var(--bar));
  display: grid; gap: 12px; animation: up .28s var(--ease);
}
.sheet-card h2 { font-size: 19px; font-weight: 700; }
.sheet-buttons { display: flex; justify-content: space-between; align-items: center; }
.sheet-buttons.has-main { display: none; } /* в Telegram вместо них — нижние кнопки */
.field { display: grid; gap: 6px; color: var(--text-2); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.field input { font-size: 16px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-tools .chip { padding: 13px 0; }
.sheet-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-chips .chip { color: var(--text); background: var(--plate); }
.choice {
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 16px; padding: 14px 16px;
  font: 600 16px/1.2 var(--font); text-align: left; cursor: pointer;
  color: var(--c, var(--text)); background: color-mix(in srgb, var(--c, var(--text-2)) 14%, var(--card));
  transition: transform .15s var(--ease);
}
.choice:active { transform: scale(.98); }
.choice.neutral { --c: var(--text); background: var(--plate); }
.choice small { margin-left: auto; color: var(--text-2); font-weight: 500; font-size: 13px; }
body.sheet-open { overflow: hidden; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + var(--nav) + var(--safe-bottom)); z-index: 19;
  margin: 0 auto; max-width: 528px; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-radius: 16px; background: var(--text); color: var(--card); animation: rise .25s var(--ease);
}
.toast .link { color: var(--card); font-weight: 700; }
.error {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + var(--nav) + var(--safe-bottom)); z-index: 30;
  margin: 0 auto; max-width: 528px; padding: 12px 16px; border-radius: 16px;
  background: var(--red); color: #fff; font-weight: 600; animation: rise .3s var(--ease);
}

/* ---------- v3: навигация, вода-напитки, подробности еды, прогресс, журнал, бюджет ---------- */

/* Нижняя навигация: над safe-area и нижними кнопками Telegram (--bar), под листами (z-index 20) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: var(--bar); z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  min-height: var(--nav);
  padding: 6px max(12px, calc((100% - 536px) / 2)) calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: none; color: var(--text-2); cursor: pointer;
  display: grid; justify-items: center; align-content: center; gap: 4px;
  padding: 7px 0 6px; border-radius: 18px; font: 600 11px/1.1 var(--font);
  transition: background .2s var(--ease), color .2s;
}
.tab .ic { width: 23px; height: 23px; }
.tab.on { color: var(--text); background: var(--plate-2); }
.tab.on .ic { color: var(--purple); }
.tab:active { transform: scale(.95); }
.tab:focus-visible { outline: 2px solid var(--purple); outline-offset: 1px; }

/* Заголовки экранов (кроме «Сегодня») */
main[data-screen]:not([data-screen="today"]) > .top { padding: 6px 6px 0; }

/* Вода: главная кнопка и «Другое» */
.water-actions { display: flex; gap: 8px; margin-top: 14px; }
.water-main-btn { flex: 1; min-width: 0; padding: 14px 16px; color: var(--on-accent); background: var(--cyan); font-size: 16px; }
.water-main-btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.water-pick { flex: none; padding: 14px 16px; }

/* Лист «Выпил…» */
.drinks { display: flex; flex-wrap: wrap; gap: 8px; }
.drink {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  border: 2px solid transparent; border-radius: 999px; padding: 4px 14px 4px 4px;
  font: 600 14px/1.1 var(--font); color: var(--text); background: var(--plate); cursor: pointer; text-align: left;
  transition: transform .15s var(--ease), background .2s, border-color .2s;
}
.drink .plate { width: 30px; height: 30px; border-radius: 50%; background: color-mix(in srgb, var(--cyan) 16%, var(--plate)); }
.drink .ic { width: 17px; height: 17px; }
.drink.on { border-color: var(--cyan); background: color-mix(in srgb, var(--cyan) 14%, var(--card)); }
.drink:active { transform: scale(.96); }
.vol { text-align: center; font-size: 56px; font-weight: 800; letter-spacing: -.03em; line-height: 1; color: var(--cyan); margin-top: 6px; }
.vol span { font-size: 20px; font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.vol-note { text-align: center; }
.slider {
  --fill: 0%;
  -webkit-appearance: none; appearance: none; width: 100%; height: 32px; margin: 0; padding: 0 !important; border-radius: 0 !important; background: transparent !important; box-shadow: none !important;
  touch-action: pan-y; cursor: pointer;
}
.slider::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(to right, var(--cyan) var(--fill), var(--plate-2) var(--fill)); }
.slider::-moz-range-track { height: 8px; border-radius: 4px; background: var(--plate-2); }
.slider::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--cyan); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%; border: 0; background: var(--text); box-shadow: 0 2px 8px rgb(0 0 0 / 35%); }
.slider::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--text); box-shadow: 0 2px 8px rgb(0 0 0 / 35%); }
.slider:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.sheet-chips.quick { justify-content: center; }
.sheet-chips .chip[aria-pressed="true"] { color: var(--on-accent); background: var(--cyan); }
.sheet-chips .chip .ic { width: 16px; height: 16px; }

/* Подробности еды */
.sheet-tools.three { grid-template-columns: repeat(3, 1fr); }
.sheet-tools.three .chip { padding: 13px 0; font-size: 14px; }
.detail { display: grid; gap: 16px; min-width: 0; }
.detail-photo { width: 100%; aspect-ratio: 16 / 9; border-radius: 20px; overflow: hidden; background: var(--plate); }
.detail-photo img { width: 100%; height: 100%; object-fit: cover; display: block; animation: fade .3s var(--ease); }
.detail-head { display: grid; gap: 6px; justify-items: start; }
.detail-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; overflow-wrap: anywhere; }
.badge {
  display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; max-width: 100%;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--teal); background: color-mix(in srgb, var(--teal) 14%, var(--card));
}
.badge .ic { width: 15px; height: 15px; }
.badge small { color: var(--text-2); font-weight: 500; font-size: 12px; }
.badge.src-dish { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, var(--card)); }
.badge.src-product { color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, var(--card)); }
.badge.src-estimate { color: var(--purple); background: color-mix(in srgb, var(--purple) 14%, var(--card)); }
.badge.src-unknown { color: var(--text-2); background: var(--plate); }
.detail-dynamic { display: grid; gap: 18px; min-width: 0; }
.energy { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 18px; align-items: center; }
.energy-viz { position: relative; width: 124px; height: 124px; }
.energy-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.energy-ring circle { fill: none; stroke-width: 12; }
.energy-ring .track { stroke: var(--plate-2); }
.energy-ring .part { stroke: var(--c); }
.energy-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.05; }
.energy-center b { font-size: 26px; letter-spacing: -.02em; }
.energy-center small { color: var(--text-2); font-size: 12px; }
.energy-legend { list-style: none; display: grid; gap: 10px; }
.energy-legend li { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.energy-legend li span { flex: 1; color: var(--text-2); }
.dial-group { display: grid; gap: 10px; min-width: 0; }
.dial-group h3 { margin: 0; }
.dials { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 14px 6px; }
.dial { display: grid; justify-items: center; align-content: start; gap: 4px; text-align: center; min-width: 0; }
.dial-ring { position: relative; width: 58px; height: 58px; display: grid; place-items: center; }
.dial-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dial-ring circle { fill: none; stroke-width: 5; }
.dial-ring .track { stroke: color-mix(in srgb, var(--c) 18%, var(--card)); }
.dial-ring .val { stroke: var(--c); stroke-linecap: round; }
.dial-ring .unknown { stroke: var(--text-2); stroke-width: 2; stroke-dasharray: 3 5; opacity: .7; }
.dial-ring b { position: relative; font-size: 14px; color: var(--text); }
.dial-ring b.long { font-size: 12px; letter-spacing: -.02em; }
.dial.nodata .dial-ring b { color: var(--text-2); font-weight: 600; }
.dial-name { font-size: 12px; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.dial small { color: var(--text-2); font-size: 12px; line-height: 1.1; }
.micro-empty { margin: 0; }
.ing-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ing-head .hint { font-size: 12px; }
.ing-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.ing-table th { padding: 8px 0 6px 8px; color: var(--text-2); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; text-align: right; white-space: nowrap; }
.ing-table td { padding: 9px 0 9px 8px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; vertical-align: baseline; }
.ing-table td.strong { font-weight: 700; }
.ing-table th:first-child, .ing-table td:first-child { padding-left: 0; text-align: left; white-space: normal; }
.ing-table tbody tr { cursor: pointer; }
.ing-name { all: unset; display: block; font-size: 15px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; cursor: pointer; }
.ing-name:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; border-radius: 6px; }
.state-chip { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--plate); }
.detail-titlebar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; width: 100%; }
.edit-top { flex: none; padding: 9px 14px; font-size: 14px; }
.edit-top .ic { width: 16px; height: 16px; }
.eaten { font-size: 18px; color: var(--text-2); }
.eaten b { color: var(--text); }
.mode-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mode-label { font-size: 15px; font-weight: 700; }
.mode-label.per100 { color: var(--orange); }
.seg.small { display: inline-grid; grid-template-columns: auto auto; flex: none; padding: 2px; border-radius: 11px; }
.seg.small button { padding: 5px 11px; font-size: 12px; border-radius: 9px; }
.link.back { display: inline-flex; align-items: center; gap: 2px; justify-self: start; max-width: 100%; padding: 2px 0; }
.link.back .ic { width: 20px; height: 20px; margin-left: -6px; }
.link.back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Прогресс */
.habit-card .card-head { margin-bottom: 12px; }
.stats.mini { grid-template-columns: repeat(3, 1fr); }
.last-done { margin: 12px 4px 10px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
  aspect-ratio: 1; border-radius: 11px; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--plate);
}
.cal-day.done { background: var(--c); color: var(--on-accent); }
.cal-day.skip { background: color-mix(in srgb, var(--red) 18%, var(--card)); color: var(--red); box-shadow: inset 0 0 0 1.5px var(--red); }
.cal-day.pending { background: transparent; color: var(--c); box-shadow: inset 0 0 0 2px var(--c); }
.cal-day.off { opacity: .55; }
.cal-day.now { outline: 2px solid var(--text); outline-offset: 2px; }
.cal-range { margin: 8px 4px 0; text-align: center; font-size: 12px; }
.reasons { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.reasons h3 { margin: 0 0 4px; }
.reason { align-items: baseline; }
.reason .entry-time { width: 64px; }
.reason .name { font-size: 14px; overflow-wrap: anywhere; }
.chart-caption { margin: 0 0 8px; font-size: 14px; font-weight: 600; min-height: 1.35em; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { fill: var(--text-2); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-svg .axis.now { fill: var(--text); font-weight: 700; }
.chart-svg .bar-mark { fill: var(--c); transition: opacity .2s; }
.chart.reach .bar-mark.low { opacity: .38; }
.chart.limit .bar-mark.low { fill: var(--orange); }
.chart-svg .bar-mark.sel { stroke: var(--text); stroke-width: 1.5; }
.chart-svg .goal-line { fill: none; stroke: var(--text); opacity: .65; stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart-svg .hit { fill: transparent; cursor: pointer; outline: none; }
.chart-svg .hit:focus-visible { stroke: var(--purple); stroke-width: 2; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 0; font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.chart.reach .key.low { opacity: .38; }
.chart.limit .key.low { background: var(--orange); }
.key.goal { width: 14px; height: 0; border-radius: 0; background: none; border-top: 2px dashed var(--text); opacity: .65; }

/* Журнал */
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; overscroll-behavior-x: contain; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: none; border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer;
  font: 600 15px/1 var(--font); color: var(--text-2); background: var(--card);
  transition: background .2s var(--ease), color .2s;
}
.filter[aria-selected="true"] { color: var(--text); background: var(--plate-2); }
.filter:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.day { display: grid; gap: 8px; min-width: 0; }
.day-title { padding: 0 6px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.day-title span { color: var(--text-2); font-size: 15px; font-weight: 500; letter-spacing: 0; }
.journal.card { padding: 4px 16px; }
.journal li { padding: 10px 0; min-height: 56px; }
.jrow .name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.25; }
.jrow .name small { font-weight: 400; margin-top: 1px; }
.jrow .entry-time { width: auto; text-align: right; }
.jrow .receipt-tag { color: var(--pink); font-weight: 600; }

/* Бюджет */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius-s);
  font-size: 15px; font-weight: 600; color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, var(--card));
}
.banner span { color: var(--text); }
.balance-num { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; line-height: 1; margin: 4px 0 8px; }
.balance-num b { font-size: 44px; font-weight: 800; letter-spacing: -.03em; color: var(--green); overflow-wrap: anywhere; }
.balance-num span { color: var(--text-2); font-size: 18px; font-weight: 600; }
.total-split { display: flex; flex-wrap: wrap; gap: 2px 8px; color: var(--text-2); font-size: 15px; }
.total-split b { color: var(--text); font-weight: 600; }
.chip.wide { width: 100%; padding: 15px 0; font-size: 16px; }
.stats.spent .stat > div { font-size: 16px; }
.add-spend { margin-top: 0; }
.account { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; width: 100%; padding: 14px 16px; border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; transition: transform .15s var(--ease); }
.account:active { transform: scale(.985); }
.account .name { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.account .default-mark { display: flex; align-items: center; gap: 4px; color: var(--amber); font-weight: 600; }
.default-mark .ic { width: 12px; height: 12px; fill: currentColor; }
.acc-bal { white-space: nowrap; text-align: right; }
.acc-bal b { font-size: 18px; }
.acc-bal small { color: var(--text-2); font-size: 14px; }
.acc-extra { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 2px 10px; color: var(--text-2); font-size: 14px; }
.acc-extra b { color: var(--green); font-weight: 600; }
.utilities { padding: 4px 16px; }
.default-note { display: flex; align-items: center; gap: 8px; }
.default-note .ic { width: 16px; height: 16px; color: var(--amber); fill: currentColor; }
.field.pick .sheet-chips, .field.exclude .sheet-chips { text-transform: none; letter-spacing: 0; font-weight: 400; }
.field.pick .chip[aria-pressed="true"] { color: var(--on-accent); background: var(--green); }
.spend-sum { flex: none; font-size: 16px; font-variant-numeric: tabular-nums; }
.receipt-items li { align-items: flex-start; padding: 8px 0; min-height: 0; }
.receipt-items .name { font-size: 15px; overflow-wrap: anywhere; }
.receipt-items .spend-sum { font-size: 15px; }
.receipt-items .receipt-total { align-items: baseline; font-weight: 700; }
.receipt-marked { display: flex; align-items: center; gap: 8px; }
.receipt-marked .ic { flex: none; width: 16px; height: 16px; color: var(--green); }
.amount-preview { min-height: 1.2em; color: var(--text-2); font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.jrow .receipt-tag { white-space: nowrap; }
.budget-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.budget-tools .chip { padding: 15px 0; font-size: 15px; }
.jrow button.row .go { width: 18px; color: var(--text-2); }

/* Лист чека: позиции по категориям, чипы связи с базой */
.receipt-group { display: grid; }
.receipt-cat { margin: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0 2px; color: var(--text-2); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.receipt-cat b { color: var(--text); font-size: 14px; letter-spacing: 0; text-transform: none; white-space: nowrap; }
.receipt-sum { border-top: 2px solid var(--line); margin-top: 8px; }
.receipt-sum .receipt-total { border-top: 0; padding-top: 12px; }
.link-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; margin-top: 4px; padding: 3px 9px 3px 7px;
  border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.3;
  color: color-mix(in srgb, var(--c) 60%, var(--text)); background: color-mix(in srgb, var(--c) 16%, var(--card));
}
.link-chip .ic { width: 12px; height: 12px; }
.link-chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-chip.off { color: var(--text-2); background: var(--plate); }
button.link-chip { position: relative; border: 0; font-family: inherit; text-align: left; cursor: pointer; transition: transform .15s var(--ease); }
button.link-chip::after { content: ""; position: absolute; inset: -8px -4px; } /* кнопка мелкая: нажимаемая область шире видимой */
button.link-chip:active { transform: scale(.96); }
button.link-chip:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.link-chip .go { flex: none; margin-left: 2px; opacity: .7; }
.link-item { font-weight: 600; overflow-wrap: anywhere; }

/* Категории за месяц */
.categories .card-head { margin-bottom: 16px; }
.cat-list { list-style: none; display: grid; gap: 14px; }
.cat-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.cat-name { min-width: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.cat-sum { flex: none; font-size: 15px; white-space: nowrap; }
.cat-sum small { color: var(--text-2); font-size: 14px; }
.cat-bar i { background: var(--c, var(--text-2)); transition: none; }
.cat-name .dot, .receipt-cat .dot { background: var(--c, var(--text-2)); } /* категория без цвета — нейтральная */

/* Цены и польза */
.list .price-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0; }
.price-row .name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.price-row .name small { font-weight: 400; }
.price-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.price-stat { display: grid; align-content: start; gap: 2px; padding: 8px 10px; border-radius: 12px; background: var(--plate); }
.price-stat b { font-size: 16px; }
.price-stat small { color: var(--text-2); font-size: 11px; line-height: 1.2; }
.price-stat.on { background: color-mix(in srgb, var(--green) 16%, var(--card)); }

/* Собрать блюдо */
.search-box { position: relative; display: block; }
.search-box .ic { position: absolute; left: 13px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search-box input { width: 100%; padding-left: 40px; -webkit-appearance: none; appearance: none; }
.dish-results { max-height: 240px; overflow-y: auto; padding: 2px 14px; border-radius: var(--radius-s); background: var(--plate); }
.dish-results li { min-height: 48px; padding: 6px 0; }
.dish-results .name { font-size: 15px; font-weight: 600; }
.dish-results .row .ic { color: var(--purple); }
.dish-row { padding: 8px 0; }
.dish-row .name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.grams-box { display: flex; align-items: center; gap: 6px; flex: none; color: var(--text-2); }
.sheet-card input.grams { flex: none; width: 84px; text-align: right; }
.chip.rm { flex: none; width: 36px; height: 36px; padding: 0; color: var(--text-2); background: var(--plate); }
.chip.rm .ic { width: 16px; height: 16px; }
.portions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.sheet-card .stepper input { flex: none; width: 64px; text-align: center; }
.stepper .chip { flex: none; width: 40px; height: 40px; padding: 0; color: var(--text); background: var(--plate); }
.dish-summary {
  position: sticky; bottom: calc(var(--safe-bottom) + var(--bar)); z-index: 1; display: grid; gap: 4px;
  padding: 14px 16px; border-radius: var(--radius-s); background: var(--plate-2); transition: opacity .2s;
}
.dish-summary.stale { opacity: .6; }
.dish-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.dish-line .dish-cost { font-size: 17px; }
.dish-kcal { font-size: 15px; color: var(--text-2); }
.dish-kcal b { color: var(--text); font-size: 28px; letter-spacing: -.02em; }
.dish-total { color: var(--text); }

/* Подобрать дешевле под норму */
.field.exclude .chip[aria-pressed="true"] { color: var(--red); background: color-mix(in srgb, var(--red) 16%, var(--card)); text-decoration: line-through; }
.plan-result { display: grid; gap: 12px; min-width: 0; transition: opacity .2s; }
.plan-result.stale { opacity: .6; }
.plan-total { display: grid; gap: 12px; padding: 14px 16px; border-radius: var(--radius-s); background: var(--plate-2); }
.plan-bars { list-style: none; display: grid; gap: 10px; }
.plan-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 5px; font-size: 14px; white-space: nowrap; }
.plan-name { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.plan-bar { background: var(--plate); }
.plan-bar i { background: var(--c, var(--text-2)); transition: width .4s var(--ease); }
.plan-bars .short .plan-name { color: var(--orange); }
.plan-warn { display: grid; gap: 6px; padding: 12px 14px; border-radius: var(--radius-s); background: color-mix(in srgb, var(--orange) 14%, var(--card)); }
.plan-warn ul { list-style: none; display: grid; gap: 2px; font-size: 14px; }
.plan-warn-head { display: flex; align-items: center; gap: 8px; color: var(--orange); font-size: 14px; font-weight: 700; }
.plan-warn-head .ic { flex: none; width: 18px; height: 18px; }
.plan-note { display: flex; align-items: flex-start; gap: 8px; }
.plan-note .ic { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.plan-items li { align-items: flex-start; padding: 8px 0; min-height: 0; }
.plan-items .name { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.plan-items .name small { font-weight: 400; }
.plan-items .spend-sum { font-size: 15px; }

/* Стоимость блюда в «Подробно» */
.dish-cost-line { display: flex; align-items: flex-start; gap: 8px; font-weight: 600; }
.dish-cost-line .ic { width: 18px; height: 18px; margin-top: 1px; color: var(--green); }
.dish-cost-line small { display: block; color: var(--text-2); font-size: 13px; font-weight: 400; }

/* Анимации: появление при первой отрисовке, pop у изменившихся отметок */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { 50% { transform: scale(1.18); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes draw { from { stroke-dasharray: 0 100; } }
.intro > * { animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.intro .wk-ring .val { animation: draw .9s var(--ease) .15s both; }

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