:root {
  --bg: #0F1112;
  --bg-deep: #0A0B0C;
  --surface: #181B1D;
  --surface-hi: #1B1F21;
  --field: #0F1112;
  --line: #23272A;
  --line-hi: #2A2F33;
  --chip: #262A2D;
  --seg: #15181A;
  --seg-on: #2A2F33;
  --text: #F2F0EA;
  --text-2: #C9CDCF;
  --muted: #9AA0A3;
  --faint: #7C8387;
  --accent: #C8F25A;
  --accent-ink: #0F1112;
  --protein: #6FC3FF;
  --fat: #FFB547;
  --carbs: #C59BFF;
  --over: #FF7A6B;
  --danger: #FF7A6B;
  --radius-card: 22px;
  --tabbar-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Unbounded", "Onest", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select { -webkit-appearance: none; appearance: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { display: block; }

/* ---------- Каркас ---------- */
.view {
  padding: 20px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 8px 8px calc(8px + var(--safe-b));
  background: #121416; border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 0; text-decoration: none; color: var(--faint); font-size: 12px; min-height: 44px;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }

.title { font-size: 24px; font-weight: 700; margin: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-family: var(--font-num); font-weight: 700; letter-spacing: -0.5px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 16px;
}
.card.accent { background: var(--surface-hi); border: 1.5px solid var(--accent); }

/* ---------- Кнопки ---------- */
.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 22px; border: 1px solid var(--chip);
  background: #15181A; display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:disabled { color: #4A5054; cursor: default; }
.icon-btn svg, .btn svg, .add-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.add-btn {
  width: 36px; height: 36px; border-radius: 18px; border: none; background: var(--chip);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0;
}
.add-btn svg { width: 18px; height: 18px; }
.btn {
  height: 48px; padding: 0 18px; border-radius: 24px; border: 1px solid var(--line-hi);
  background: var(--field); font-weight: 500; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 600; font-size: 16px; height: 54px; border-radius: 27px; }
.btn.primary:disabled { opacity: 0.45; }
.btn.ghost { background: transparent; border: none; color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #3A2A28; background: transparent; }
.btn.small { height: 36px; font-size: 14px; padding: 0 14px; border-radius: 18px; }
.btn.block { width: 100%; }
.btn.dashed { border-style: dashed; border-color: #3A3F43; background: transparent; color: var(--accent); }

/* ---------- Сегменты и чипы ---------- */
.seg {
  display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 4px;
  padding: 4px; background: var(--seg); border-radius: 22px;
}
.seg button {
  height: 36px; border: none; border-radius: 18px; background: transparent; color: var(--muted); font-size: 14px;
}
.seg button[aria-pressed="true"] { background: var(--seg-on); color: var(--text); font-weight: 600; }
.seg.compact { border-radius: 14px; padding: 3px; background: var(--field); }
.seg.compact button { height: 38px; border-radius: 11px; }

.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.chip {
  height: 36px; border-radius: 18px; border: 1px solid var(--line-hi); background: transparent; color: var(--text-2); font-size: 14px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--text); font-weight: 600; }

/* ---------- Поля ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.input, .select {
  height: 46px; width: 100%; padding: 0 14px; border-radius: 14px; background: var(--field);
  border: 1px solid var(--line-hi); outline: none; font-size: 16px;
}
.input:focus, .select:focus { border-color: var(--accent); }
.select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.search {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; border-radius: 26px;
  background: var(--surface); border: 1px solid var(--line-hi);
}
.search:focus-within { border-color: var(--accent); }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.search input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

/* ---------- Сегодня ---------- */
.day-head { display: flex; align-items: center; justify-content: space-between; }
.day-head .center { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.day-head .center b { font-size: 17px; font-weight: 600; }
.ring-row { display: flex; align-items: center; gap: 20px; }
.ring { position: relative; width: 168px; height: 168px; flex-shrink: 0; }
.ring svg { transform: rotate(-90deg); }
.ring .inside { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; }
.ring .inside .num { font-size: 32px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 22px; font-weight: 600; }
.macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.macro { display: flex; flex-direction: column; gap: 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }

.meal { padding: 14px 14px 10px 16px; display: flex; flex-direction: column; gap: 8px; }
.meal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.meal-head h2 { font-size: 16px; font-weight: 600; margin: 0; display: flex; align-items: baseline; gap: 8px; }
.meal-head h2 span { font-size: 13px; color: var(--muted); font-weight: 400; }
.meal-macros { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: -4px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.meal-macros b { font-weight: 600; }
.p { color: var(--protein); } .f { color: var(--fat); } .c { color: var(--carbs); }
.entry {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px;
  background: none; border: none; padding: 6px 0; text-align: left; width: 100%; min-height: 32px;
}
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .qty { color: var(--muted); white-space: nowrap; }
.meal.empty { flex-direction: row; align-items: center; justify-content: space-between; padding: 14px 14px 14px 16px; }
.meal.empty .btn { height: 36px; }

/* ---------- Списки ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); min-height: 60px;
}
.item[aria-pressed="true"] { background: var(--surface-hi); border: 1.5px solid var(--accent); }
.item .t { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item .t b { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.item .t small { font-size: 12px; color: var(--muted); }
.item .k { font-size: 15px; font-weight: 600; white-space: nowrap; }
.item .k small { font-size: 12px; color: var(--muted); font-weight: 400; }
.empty-note { text-align: center; color: var(--muted); font-size: 14px; padding: 24px 8px; }

/* ---------- Нижние листы ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); animation: fade 0.18s ease; }
.sheet {
  position: relative; max-height: 92vh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-top: 1px solid var(--line-hi); border-radius: 28px 28px 0 0;
  padding: 10px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px;
  max-width: 560px; width: 100%; margin: 0 auto; animation: up 0.22s cubic-bezier(.2,.8,.2,1);
}
.sheet > * { flex-shrink: 0; }
.sheet.full { height: 100vh; max-height: 100vh; border-radius: 0; border-top: none; padding-top: 20px; }
.sheet .grab { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: #3A3F43; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.sheet-head .sub { font-size: 13px; color: var(--muted); }
.pick-panel { background: var(--surface); border: 1px solid var(--line-hi); border-radius: 24px; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.stepper { display: flex; align-items: center; justify-content: space-between; }
.stepper .icon-btn { width: 52px; height: 52px; border-radius: 26px; background: var(--field); border-color: var(--line-hi); }
.stepper .val { display: flex; align-items: baseline; gap: 6px; }
.stepper input {
  width: 140px; text-align: center; background: transparent; border: none; outline: none;
  font-family: var(--font-num); font-weight: 700; font-size: 38px; letter-spacing: -1px; padding: 0;
}
.preview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 12px; border-radius: 18px; background: var(--field); text-align: center; }
.preview div { display: flex; flex-direction: column; gap: 2px; }
.preview b { font-size: 17px; font-weight: 600; }
.preview span { font-size: 12px; color: var(--muted); }

@keyframes up { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- История ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart text { font-family: var(--font); }

/* ---------- Тост и загрузка ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: #2A2F33; color: var(--text); padding: 12px 16px; border-radius: 16px; font-size: 14px; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: #3A2422; color: #FFD3CD; }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, #1F2325 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-card); }
@keyframes shimmer { to { background-position: -200% 0; } }
.center-screen { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; }
.center-screen h1 { font-size: 20px; margin: 0; }

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