/* Трекер: нативный вид Telegram. Цвета приходят из темы клиента через --tg-theme-*. */
:root {
  --fb-bg: #efeff4; --fb-card: #ffffff; --fb-text: #000000; --fb-hint: #8e8e93; --fb-accent: #2481cc;
  --fb-accent-t: #ffffff; --fb-link: #2481cc; --fb-danger: #e5484d; --fb-sep: #c8c7cc; --fb-head: #6d6d72;
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-t: var(--tg-theme-button-text-color, var(--fb-accent-t));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --sep: var(--tg-theme-section-separator-color, var(--fb-sep));
  --head: var(--tg-theme-section-header-text-color, var(--fb-head));
  --fill: rgba(118, 118, 128, 0.12);
  --ok: #2fb350; --ok-bg: rgba(47, 179, 80, 0.13);
  --warn: #f0961c; --warn-bg: rgba(240, 150, 28, 0.15);
  --sab: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #000000; --fb-card: #1c1c1e; --fb-text: #ffffff; --fb-hint: #8d8e93; --fb-accent: #3e88f7;
    --fb-link: #3e88f7; --fb-sep: #3d3d3f; --fb-head: #8d8e93; --fill: rgba(118, 118, 128, 0.24);
  }
}
:root[data-scheme="dark"] { --fill: rgba(118, 118, 128, 0.24); }
:root[data-scheme="light"] { --fill: rgba(118, 118, 128, 0.12); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
  padding-bottom: calc(78px + var(--sab));
}
body.has-page { padding-bottom: calc(28px + var(--sab)); }
body.has-page .tabbar { display: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex: none; }
.hide { display: none !important; }
.boot { padding: 80px 0; text-align: center; color: var(--hint); }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: minmax(44px, auto) 1fr minmax(44px, auto);
  align-items: center; min-height: 54px; padding: 4px 6px; background: var(--bg);
}
.top-c { text-align: center; min-width: 0; }
.top-t { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-s { font-size: 12px; color: var(--hint); min-height: 15px; }
.top-s.err { color: var(--danger); }
.ic {
  width: 42px; height: 42px; border: 0; background: none; color: var(--link);
  display: grid; place-items: center; border-radius: 12px;
}
.ic:disabled { opacity: 0.25; cursor: default; }
.ic svg, .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.top-a { border: 0; background: none; color: var(--link); font-weight: 600; font-size: 16px; padding: 8px 8px; justify-self: end; white-space: nowrap; }
.top-a:disabled { opacity: 0.4; }

/* ---------- секции и строки ---------- */
.view { padding: 2px 0 6px; }
.sec { margin: 0 12px 20px; }
.sec-h {
  margin: 0 16px 7px; font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.01em;
  color: var(--head); display: flex; justify-content: space-between; gap: 8px;
}
.sec-h span { text-transform: none; }
.sec-f { margin: 7px 16px 0; font-size: 13px; color: var(--hint); line-height: 1.4; }
.card { background: var(--card); border-radius: var(--r); overflow: hidden; }
.card.pad { padding: 12px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 50px;
  padding: 8px 14px 8px 16px; width: 100%; border: 0; background: none; text-align: left; color: var(--text);
}
.row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.card > .row:first-child::before { display: none; }
.row-l { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-l small { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.row-v { color: var(--hint); white-space: nowrap; }
button.row:active { background: var(--fill); }
.row-link .row-v { color: var(--link); }
.row-act { color: var(--link); font-weight: 500; gap: 10px; }
.row-act .ico { width: 20px; height: 20px; }
.stack { flex-direction: column; align-items: stretch; gap: 9px; padding-top: 11px; padding-bottom: 13px; }
.stack .row-l { flex-direction: row; justify-content: space-between; align-items: baseline; gap: 8px; }
.stack .row-l small { margin: 0; }

/* ---------- числа ---------- */
.num { display: flex; align-items: center; gap: 6px; }
.num input {
  width: 86px; border: 0; background: none; text-align: right; font-size: 17px; padding: 6px 0;
  outline: none; color: var(--text); border-radius: 0;
}
.num input::placeholder { color: var(--hint); opacity: 0.75; }
input.bad, .full.bad { color: var(--danger) !important; }
.unit { color: var(--hint); font-size: 15px; min-width: 24px; }
.step {
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--fill); color: var(--link);
  font-size: 20px; line-height: 1; display: grid; place-items: center; flex: none; padding: 0;
}
.step:active { opacity: 0.55; }

/* ---------- выбор ---------- */
.seg { display: flex; gap: 6px; }
.seg-b {
  flex: 1; min-width: 0; height: 38px; border: 0; border-radius: 10px; background: var(--fill); color: var(--text);
  font-size: 15px; font-weight: 500; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}
.seg-b.on { background: var(--accent); color: var(--accent-t); }
.seg-10 { gap: 4px; }
.seg-10 .seg-b { height: 34px; font-size: 14px; border-radius: 8px; padding: 0; }
.cap { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin-top: -3px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; border-radius: 18px; padding: 8px 13px; background: var(--fill); color: var(--text); font-size: 15px;
  display: inline-flex; align-items: baseline; gap: 6px; max-width: 100%; text-align: left;
}
.chip.on { background: var(--accent); color: var(--accent-t); }
.chip small { color: var(--hint); font-size: 13px; white-space: nowrap; }
.sec > .chips .chip { background: var(--card); }
.sec > .chips .chip:active { opacity: 0.6; }

/* ---------- кнопки ---------- */
.btn {
  width: 100%; min-height: 50px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-t);
  font-size: 17px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px;
}
.btn .ico { width: 20px; height: 20px; stroke-width: 2.4; }
.btn.ghost { background: var(--card); color: var(--link); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.5; }
.link { border: 0; background: none; color: var(--link); padding: 12px 0 0; font-size: 15px; text-align: left; display: block; }

/* ---------- сводка дня ---------- */
.sum { padding: 14px 16px 15px; }
.sum-top { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 96px; height: 96px; flex: none; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring-bg { fill: none; stroke: var(--fill); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.ring.over .ring-fg { stroke: var(--warn); }
.ring-t { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-t b { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.ring-t span { font-size: 11px; line-height: 1.2; color: var(--hint); }
.sum-m { flex: 1; display: grid; gap: 9px; min-width: 0; }
.mac-h { display: flex; justify-content: space-between; gap: 6px; font-size: 13.5px; margin-bottom: 4px; }
.mac-h span { color: var(--hint); }
.mac-h b { font-weight: 600; white-space: nowrap; }
.mac-h i { font-style: normal; color: var(--hint); font-weight: 400; }
.bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s ease; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; padding: 5px 10px 5px 8px; border-radius: 14px; background: var(--fill); color: var(--hint); }
.chk i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid currentColor; }
.chk svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.chk.ok { color: var(--ok); background: var(--ok-bg); }

textarea {
  display: block; width: 100%; border: 0; background: none; padding: 12px 16px; resize: none; outline: none;
  font-size: 16px; min-height: 86px; color: var(--text);
}
textarea::placeholder, .full::placeholder { color: var(--hint); opacity: 0.75; }

/* ---------- еда ---------- */
.meal-l { flex: 1; min-width: 0; }
.meal-t { font-size: 16px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.meal-t span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-s { font-size: 13px; color: var(--hint); margin-top: 2px; }
.meal-k { text-align: right; font-weight: 600; font-size: 16px; white-space: nowrap; }
.meal-k small { display: block; font-weight: 400; font-size: 12px; color: var(--hint); }
.badge { flex: none; font-size: 10.5px; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: var(--fill); color: var(--hint); text-transform: uppercase; letter-spacing: 0.03em; }
.empty { padding: 26px 20px; text-align: center; color: var(--hint); font-size: 15px; line-height: 1.45; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; font-weight: 600; }

/* ---------- формы на отдельных страницах ---------- */
.full { width: 100%; border: 0; background: none; outline: none; font-size: 17px; padding: 6px 0; color: var(--text); }
input[type="time"], input[type="date"], select {
  border: 0; background: var(--fill); border-radius: 8px; padding: 6px 10px; font-size: 16px; color: var(--text);
  min-height: 34px; outline: none; max-width: 60%; -webkit-appearance: none; appearance: none;
}
select { padding-right: 12px; text-overflow: ellipsis; }
.sw {
  -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill);
  position: relative; transition: background 0.2s; flex: none; margin: 0; cursor: pointer;
}
.sw::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22); transition: transform 0.2s;
}
.sw:checked { background: var(--accent); }
.sw:checked::after { transform: translateX(20px); }

/* ---------- прогресс ---------- */
.kpi { padding: 14px 16px 2px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.kpi-v { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-v small { font-size: 16px; font-weight: 500; color: var(--hint); margin-left: 3px; }
.kpi-d { font-size: 13px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: var(--fill); color: var(--hint); }
.kpi-d.good { color: var(--ok); background: var(--ok-bg); }
.kpi-d.bad { color: var(--warn); background: var(--warn-bg); }
.kpi-s { width: 100%; font-size: 13px; color: var(--hint); }
.chart-wrap { padding: 6px 8px 10px; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--sep); stroke-width: 0.6; }
.chart .ax { fill: var(--hint); font-size: 10px; }
.chart .raw { fill: none; stroke: var(--hint); stroke-width: 1; opacity: 0.45; }
.chart .dot { fill: var(--hint); opacity: 0.75; }
.chart .avg { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.chart .goal { stroke: var(--ok); stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart .goal-t { fill: var(--ok); }
.chart .col { fill: var(--accent); }
.chart .col.hi { fill: var(--warn); }
.chart .col.lo { opacity: 0.4; }
.chart .tgt { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.4; }
.chart-empty { padding: 30px 0; text-align: center; color: var(--hint); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.stat-l { font-size: 13px; color: var(--hint); }
.stat-v { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -0.01em; white-space: nowrap; }
.stat-v small { font-size: 13px; color: var(--hint); font-weight: 500; margin-left: 3px; }
.stat-s { font-size: 12.5px; color: var(--hint); margin-top: 2px; }
.stat-s.good { color: var(--ok); }
.stat-s.bad { color: var(--warn); }
.heat { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; padding: 14px 16px 10px; }
.heat-h { font-size: 11px; color: var(--hint); text-align: center; }
.hc { aspect-ratio: 1; border-radius: 7px; background: var(--fill); }
.hc.s-partial { background: var(--accent); opacity: 0.35; }
.hc.s-full { background: var(--accent); }
.hc.s-out { background: transparent; }
.hc.today { box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 16px 14px; font-size: 12.5px; color: var(--hint); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--fill); }
.legend i.full { background: var(--accent); }
.legend i.partial { background: var(--accent); opacity: 0.35; }
.seg.period { margin: 0 12px 16px; background: var(--fill); padding: 2px; border-radius: 10px; gap: 2px; }
.seg.period .seg-b { height: 32px; background: transparent; border-radius: 8px; font-size: 14px; }
.seg.period .seg-b.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.meas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--sep); }
.meas div { background: var(--card); padding: 11px 12px; min-width: 0; }
.meas span { display: block; font-size: 12.5px; color: var(--hint); }
.meas b { font-size: 17px; font-weight: 600; }
.meas i { font-style: normal; font-size: 12px; margin-left: 4px; color: var(--hint); }
.meas i.good { color: var(--ok); }
.meas i.bad { color: var(--warn); }

/* ---------- анализы ---------- */
.flag { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.flag.hi { color: var(--danger); }
.flag.lo { color: var(--warn); }
.flag.ok { color: var(--ok); }
.spark { width: 62px; height: 26px; flex: none; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark circle { fill: var(--accent); }
.lab-v { text-align: right; white-space: nowrap; }
.lab-v b { font-size: 16px; font-weight: 600; }
.lab-v small { display: block; font-size: 12px; color: var(--hint); }
.del { border: 0; background: none; color: var(--danger); padding: 6px; display: grid; place-items: center; }
.del .ico { width: 20px; height: 20px; }

/* ---------- профиль ---------- */
.hero { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.ava { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-t); display: grid; place-items: center; font-size: 23px; font-weight: 600; flex: none; }
.hero-n { font-size: 18px; font-weight: 600; }
.hero-s { font-size: 14px; color: var(--hint); margin-top: 1px; }

/* ---------- таб-бар ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 0.5px solid var(--sep); padding: 3px 4px var(--sab);
}
.tab { border: 0; background: none; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0 6px; font-size: 10.5px; font-weight: 500; min-width: 0; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--accent); }

/* ---------- служебное ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translate(-50%, 16px); z-index: 60;
  background: rgba(28, 28, 30, 0.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; line-height: 1.35;
  max-width: calc(100% - 32px); width: max-content; text-align: center; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.has-page #toast { bottom: calc(28px + var(--sab)); }
.sk { margin: 0 12px 20px; height: 112px; border-radius: var(--r); background: var(--card); position: relative; overflow: hidden; }
.sk.tall { height: 230px; }
.sk::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--fill), transparent);
  transform: translateX(-100%); animation: sh 1.2s infinite;
}
@keyframes sh { to { transform: translateX(100%); } }
.state { text-align: center; padding: 56px 28px; color: var(--hint); line-height: 1.45; }
.state h3 { color: var(--text); margin: 0 0 6px; font-size: 19px; }
.state .btn { margin-top: 18px; }
.foot { text-align: center; color: var(--hint); font-size: 13px; margin: 4px 28px 22px; line-height: 1.45; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* дополнения */
.badge { font-style: normal; }
a.btn { text-decoration: none; }
.chart .band { fill: var(--ok); opacity: 0.1; }
.chart .raw.strong { stroke: var(--accent); stroke-width: 2.2; opacity: 1; }
.chart .dot.strong { fill: var(--accent); opacity: 1; }

/* устройства */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5px; background: var(--sep); }
.tile { background: var(--card); padding: 11px 12px 12px; min-width: 0; }
.tile span { display: block; font-size: 12.5px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b { display: block; font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; letter-spacing: -0.01em; }
.tile b i { font-style: normal; font-size: 12px; font-weight: 500; color: var(--hint); margin-left: 2px; }
.tile small { display: block; font-size: 11.5px; color: var(--hint); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.rec b { color: var(--rec); }
.rec-g { --rec: var(--ok); }
.rec-y { --rec: #d9a300; }
.rec-r { --rec: var(--danger); }
.dev-w { padding: 10px 16px 12px; font-size: 13.5px; color: var(--hint); border-top: 0.5px solid var(--sep); line-height: 1.6; }
.chart .col.z-g { fill: var(--ok); }
.chart .col.z-y { fill: #d9a300; }
.chart .col.z-r { fill: var(--danger); }
.mini {
  flex: none; border: 0; border-radius: 15px; padding: 6px 13px; font-size: 14px; font-weight: 600;
  background: var(--fill); color: var(--link);
}
.mini.acc { background: var(--accent); color: var(--accent-t); }
.mini:disabled { opacity: 0.4; }
.mini:active { opacity: 0.7; }
.bad-t { color: var(--danger) !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13.5px !important; color: var(--hint) !important; }
.howto { margin: 0; padding: 12px 16px 12px 36px; font-size: 15px; line-height: 1.5; }
.howto li { margin: 0 0 8px; }
.howto li:last-child { margin-bottom: 0; }
.rec-hero { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 0.5px solid var(--sep); }
.rec-hero b { font-size: 34px; font-weight: 700; color: var(--rec); letter-spacing: -0.02em; line-height: 1; }
.rec-hero b i { font-style: normal; font-size: 16px; font-weight: 600; margin-left: 1px; }
.rec-hero span { display: block; font-weight: 600; font-size: 16px; }
.rec-hero small { display: block; color: var(--hint); font-size: 13px; margin-top: 1px; }
