:root {
  --bg: #0d0f0e;
  --bg-elev: #151917;
  --card: #171b19;
  --card-2: #1e2320;
  --border: #262d28;
  --border-soft: #20261f;
  --text: #f3f5f2;
  --text-2: #aab3aa;
  --text-3: #727b72;
  --accent: #8be24d;
  --accent-ink: #0c1806;
  --accent-soft: rgba(139, 226, 77, 0.14);
  --blue: #6cb6ff;
  --warn: #e9be55;
  --danger: #f0785c;
  --radius: 16px;
  --radius-sm: 12px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

/* ── HEADER ─────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--border-soft);
}
.appbar .title { font-size: 17px; font-weight: 700; letter-spacing: -0.2px; margin: 0; }
.appbar .sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.appbar .goalbar { margin-top: 10px; height: 6px; border-radius: 6px; background: var(--card-2); overflow: hidden; }
.appbar .goalbar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s ease; }

/* ── CONTENT ────────────────────────────────────────────── */
.content {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 20px);
}
.tab { display: none; }
.tab.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 22px 2px 10px; font-weight: 700; }
h2.section:first-child { margin-top: 4px; }

/* ── CARDS ──────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card.tight { padding: 12px 14px; }
.card-title { font-size: 15px; font-weight: 650; margin: 0 0 2px; }
.card-sub { font-size: 12.5px; color: var(--text-2); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ── HERO (сегодня) ─────────────────────────────────────── */
.hero {
  background: linear-gradient(160deg, #1b2419, var(--card));
  border: 1px solid var(--border); border-radius: 20px;
  padding: 20px; margin-bottom: 16px;
}
.hero .cap { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .5px; }
.hero .kcal { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 2px; }
.hero .kcal b { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.hero .kcal span { font-size: 15px; color: var(--text-2); }
.hero .leftnote { font-size: 13px; color: var(--text-2); margin-top: 6px; }
.hero .leftnote.over { color: var(--warn); }

/* ── MACRO BARS ─────────────────────────────────────────── */
.macros { display: grid; gap: 12px; margin-top: 16px; }
.macro .top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.macro .top .lbl { color: var(--text-2); }
.macro .top .val { font-variant-numeric: tabular-nums; }
.macro .bar { height: 7px; border-radius: 7px; background: var(--card-2); overflow: hidden; }
.macro .bar > i { display: block; height: 100%; border-radius: 7px; transition: width .4s ease; }
.macro.p .bar > i { background: var(--accent); }
.macro.f .bar > i { background: var(--warn); }
.macro.c .bar > i { background: var(--blue); }

/* ── STAT GRID ──────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 460px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 12px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 750; letter-spacing: -0.3px; }
.stat .l { font-size: 11.5px; color: var(--text-2); margin-top: 3px; }
.stat.accent .v { color: var(--accent); }
.stat.ok .v { color: var(--accent); }
.stat.warn .v { color: var(--warn); }

/* ── MEAL LIST ──────────────────────────────────────────── */
.meal { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.meal:last-child { border-bottom: none; }
.meal .slot { flex: 0 0 74px; font-size: 12px; color: var(--text-3); padding-top: 2px; }
.meal .body { flex: 1; }
.meal .name { font-size: 14px; }
.meal .mk { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ── PILLS / SEGMENTED ──────────────────────────────────── */
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  border: none; background: transparent; color: var(--text-2);
  padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg button.active { background: var(--accent); color: var(--accent-ink); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--card);
  color: var(--text-2); padding: 7px 13px; border-radius: 999px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── BADGES ─────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 11.5px; color: var(--text-2); }
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge.warn { background: rgba(233,190,85,.12); border-color: transparent; color: var(--warn); }

/* ── INPUTS / BUTTONS ───────────────────────────────────── */
.field {
  width: 100%; background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; outline: none;
}
.field:focus { border-color: var(--accent); }
.btn {
  border: none; background: var(--accent); color: var(--accent-ink);
  border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn.block { width: 100%; }
.inline-add { display: flex; gap: 8px; margin-top: 10px; }
.inline-add .field { flex: 1; }

/* ── CALLOUT ────────────────────────────────────────────── */
.callout { border-radius: var(--radius-sm); padding: 13px 15px; margin-bottom: 14px; font-size: 13px; line-height: 1.5; border: 1px solid var(--border); background: var(--card); }
.callout b { display: block; margin-bottom: 3px; font-size: 13px; }
.callout.info { background: rgba(108,182,255,.08); border-color: rgba(108,182,255,.25); }
.callout.warn { background: rgba(233,190,85,.08); border-color: rgba(233,190,85,.28); }

/* ── EXERCISE ROWS ──────────────────────────────────────── */
.ex { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); font-size: 14px; }
.ex:last-child { border-bottom: none; }
.ex .body { flex: 1; min-width: 0; }
.ex .muscle { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.ex .sets { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ── THUMBNAILS + LIGHTBOX ──────────────────────────────── */
.thumb {
  flex: 0 0 auto; width: 54px; height: 54px; border-radius: 12px; object-fit: cover;
  background: var(--card-2); border: 1px solid var(--border); cursor: pointer;
  transition: transform .15s ease;
}
.thumb:active { transform: scale(.94); }
.thumb.sm { width: 44px; height: 44px; border-radius: 10px; }
.hero-img { width: 100%; height: 150px; object-fit: cover; border-radius: 16px; margin-bottom: 14px; border: 1px solid var(--border); cursor: pointer; }
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.9);
  display: none; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(6px);
}
.lightbox.open { display: flex; animation: fade .2s ease; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 18px; }
.lightbox .cap { position: absolute; bottom: calc(28px + var(--safe-bottom)); left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; padding: 0 24px; }

/* ── LOG ROWS ───────────────────────────────────────────── */
.logrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); font-size: 14px; }
.logrow:last-child { border-bottom: none; }
.logrow .del { color: var(--danger); font-size: 12px; cursor: pointer; flex: 0 0 auto; }
.muted { color: var(--text-2); font-size: 13px; }
.empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 18px 0; }

/* ── CHAT ───────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--nav-h) - var(--safe-bottom) - 92px - var(--safe-top)); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px 14px; }
.chat-log::-webkit-scrollbar { display: none; }
.bubble { max-width: 84%; padding: 11px 14px; border-radius: 18px; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.bubble.pending { color: var(--text-2); }
.chat-input { display: flex; gap: 8px; padding-top: 8px; }
.chat-input .field { flex: 1; border-radius: 999px; }
.chat-input .btn { border-radius: 999px; width: 48px; padding: 0; display: grid; place-items: center; }
.dots span { display: inline-block; width: 6px; height: 6px; margin: 0 1px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite both; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.suggest { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.suggest button { border: 1px solid var(--border); background: var(--card); color: var(--text-2); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; cursor: pointer; }

/* ── BOTTOM NAV ─────────────────────────────────────────── */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(15, 18, 16, 0.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + var(--safe-bottom));
}
.nav button {
  flex: 1; border: none; background: none; color: var(--text-3);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px; cursor: pointer; padding: 2px 0;
}
.nav button svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.nav button.active { color: var(--accent); }

.loading { text-align: center; color: var(--text-2); padding: 40px 0; font-size: 14px; }

/* ── PREMIUM POLISH ─────────────────────────────────────── */
.card { box-shadow: 0 1px 0 rgba(255,255,255,.02) inset, 0 6px 18px -12px rgba(0,0,0,.6); }
.hero {
  box-shadow: 0 10px 30px -16px rgba(139,226,77,.28), 0 8px 24px -14px rgba(0,0,0,.7);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ''; position: absolute; top: -40%; right: -20%; width: 55%; height: 160%;
  background: radial-gradient(circle, rgba(139,226,77,.12), transparent 70%); pointer-events: none;
}
.btn { box-shadow: 0 6px 16px -8px rgba(139,226,77,.55); transition: transform .12s ease, filter .12s ease; }
.btn:active { transform: translateY(1px) scale(.99); filter: brightness(1.05); }
.chip:active, .seg button:active { transform: scale(.97); }
.nav button svg { transition: transform .15s ease; }
.nav button.active svg { transform: translateY(-1px) scale(1.08); }
.pro-badge { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .8px; color: var(--accent-ink); background: var(--accent); padding: 2px 7px; border-radius: 6px; vertical-align: middle; margin-left: 6px; }
