:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --surface-2: #f1ebe3;
  --text: #2b2420;
  --muted: #7d726a;
  --line: #e6ddd3;
  --accent: #c8644a;
  --accent-soft: #f6dfd6;
  --ok: #5f8f6b;
  --ok-soft: #dcebdf;
  --calm: #5b7fa6;
  --calm-soft: #dde7f2;
  --warn: #c9973a;
  --phase-menstrual: #e9c3c3;
  --phase-follicular: #d8e8d8;
  --phase-ovulation: #e6ddf0;
  --phase-luteal: #f3e2c8;
  --phase-pms: #f0cfb6;
  --shadow: 0 1px 2px rgba(60, 40, 30, .06), 0 4px 16px rgba(60, 40, 30, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f0e9e2;
    --muted: #a3978d;
    --line: #3a332e;
    --accent: #e0826a;
    --accent-soft: #4a2e26;
    --ok: #8cbf98;
    --ok-soft: #26362a;
    --calm: #8fb0d4;
    --calm-soft: #24303d;
    --phase-menstrual: #4a2f31;
    --phase-follicular: #2a3a2c;
    --phase-ovulation: #352e40;
    --phase-luteal: #3d3324;
    --phase-pms: #45301f;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

main { max-width: 560px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--surface-2); font-weight: 600;
  min-height: 46px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.calm { background: var(--calm-soft); color: var(--calm); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: var(--surface-2); width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; font-size: 18px; }

input[type=text], input[type=number], input[type=date], input[type=time], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  background: var(--surface); min-height: 46px;
}
textarea { resize: vertical; min-height: 84px; }
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2);
}
.chip.phase-menstrual { background: var(--phase-menstrual); }
.chip.phase-follicular { background: var(--phase-follicular); }
.chip.phase-ovulation { background: var(--phase-ovulation); }
.chip.phase-luteal { background: var(--phase-luteal); }
.chip.phase-pms { background: var(--phase-pms); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
a.chip { text-decoration: none; color: var(--accent); }

/* Шапка дня */
.daybar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daybar h1 { text-align: center; flex: 1; font-size: 18px; }

/* Кольцо калорий */
.ring-wrap { display: grid; grid-template-columns: 132px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 26px; font-weight: 700; }
.bars { display: grid; gap: 9px; }
.bar .lbl { display: flex; justify-content: space-between; font-size: 13px; }
.bar .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar .fill { height: 100%; border-radius: 99px; background: var(--calm); }
.bar.protein .fill { background: var(--accent); }
.bar.fiber .fill { background: var(--ok); }

/* Приёмы пищи */
.meal { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.meal:first-child { border-top: 0; }
.meal .t { font-weight: 600; }
.meal .kc { font-weight: 700; white-space: nowrap; }
.meal.planned { opacity: .85; }
.meal button.link { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; text-decoration: underline; }

/* Нижнее меню */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs a {
  display: grid; justify-items: center; gap: 2px; text-decoration: none; color: var(--muted);
  font-size: 11px; padding: 4px 0;
}
nav.tabs a .ic { font-size: 21px; line-height: 1; }
nav.tabs a.active { color: var(--accent); font-weight: 600; }
nav.tabs a.sos .ic {
  background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 800; margin-top: -18px;
  box-shadow: 0 4px 12px rgba(200,100,74,.35);
}

/* Модальное окно снизу */
.sheet-bg { position: fixed; inset: 0; background: rgba(20, 12, 8, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 12px;
}
.sheet .handle { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 4px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-size: 14px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }

.hunger { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.hunger button { border: 0; border-radius: 8px; padding: 9px 0; background: var(--surface-2); font-weight: 600; }
.hunger button.on { background: var(--accent); color: #fff; }

.item-row { display: grid; grid-template-columns: 1fr 64px 64px 30px; gap: 6px; align-items: center; }
.item-row input { min-height: 38px; padding: 6px 8px; font-size: 14px; }
.item-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 8px; }
.item-macros input { min-height: 34px; padding: 4px 6px; font-size: 13px; }

.quick { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.quick button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 10px; text-align: left; font-size: 13px; max-width: 180px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; z-index: 60;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); font-size: 15px;
  animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }

/* SOS */
.sos-grid { display: grid; gap: 10px; }
.sos-big { text-align: left; padding: 16px; border-radius: var(--radius); border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; gap: 2px; }
.sos-big b { font-size: 17px; }
.timer { display: grid; place-items: center; gap: 14px; padding: 8px 0; }
.timer .num { font-size: 52px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chat { display: grid; gap: 8px; max-height: 52vh; overflow: auto; padding: 4px 0; }
.msg { padding: 10px 12px; border-radius: 14px; max-width: 86%; white-space: pre-wrap; }
.msg.user { background: var(--accent-soft); justify-self: end; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }

/* Вес */
.chart { width: 100%; height: auto; display: block; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .k { font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }

.list-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }

.empty { text-align: center; color: var(--muted); padding: 10px 0; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.switch:first-of-type { border-top: 0; }
.switch input[type=time] { width: 110px; min-height: 38px; }
.switch input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

.install-fab {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(84px + env(safe-area-inset-bottom));
  box-shadow: 0 6px 18px rgba(200, 100, 74, .35);
}

/* Меню «Ещё» */
.menu { display: grid; gap: 8px; }
.menu-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.menu-item .mi { font-size: 22px; width: 32px; text-align: center; }

/* Столбики недели и шагов */
.week-chart, .steps-chart { display: flex; align-items: flex-end; gap: 6px; height: 90px; padding-top: 10px; }
.steps-chart { gap: 2px; height: 80px; }
.wc-col, .sc-col { flex: 1; display: grid; justify-items: center; align-content: end; gap: 3px; }
.wc-bar, .sc-bar { width: 100%; background: var(--line); border-radius: 4px 4px 0 0; }
.wc-bar.ok, .sc-bar.ok { background: var(--ok); }
.wc-bar.over { background: var(--warn); }
.sc-bar { background: var(--calm); max-width: 10px; }
.sc-gym { font-size: 8px; color: var(--accent); height: 10px; }

/* Давление и анализы */
.p-ok { color: var(--ok); }
.p-mid { color: var(--warn); }
.p-warn { color: var(--accent); }

/* Баннер фокуса */
.focus { background: var(--calm-soft); color: var(--calm); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.act-row { display: flex; gap: 8px; align-items: center; }
.act-row input { max-width: 120px; min-height: 40px; }
