/* Цвета берутся из темы Telegram, свои — только акценты: малахит, латунь Профа, красный для вредного */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #F2F5F2);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #FFFFFF));
  --ink: var(--tg-theme-text-color, #13201B);
  --muted: var(--tg-theme-hint-color, #5A6A63);
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --track: color-mix(in srgb, var(--muted) 14%, transparent);
  --accent: #0E7A55;
  --harm: #C0402C;
  --brass: #C38B2C;
  --accent-soft: color-mix(in srgb, var(--accent) 13%, var(--card));
  --harm-soft: color-mix(in srgb, var(--harm) 12%, var(--card));
  --brass-soft: color-mix(in srgb, var(--brass) 16%, var(--card));
  --f-body: "Golos Text", -apple-system, "SF Pro Text", Roboto, system-ui, sans-serif;
  --f-display: "Unbounded", "Golos Text", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-scheme="dark"] {
  --accent: #3DBF8B;
  --harm: #F06E58;
  --brass: #D9A54A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 var(--f-body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.weeknav { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; }
.nav { width: 40px; height: 40px; border-radius: 50%; font-size: 26px; line-height: 1; color: var(--accent); }
.nav:disabled { color: var(--line); cursor: default; }
.weektitle { text-align: center; display: flex; flex-direction: column; line-height: 1.2; }
.weektitle b { font-size: 16px; }
.weektitle span { font-size: 12px; color: var(--muted); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--track); border-radius: 10px; padding: 2px; }
.tabs button { padding: 7px 2px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

main { padding: 4px 14px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.harm { background: var(--harm-soft); }
.card.good { background: var(--accent-soft); }
.card.brass { background: var(--brass-soft); }
.lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.harm .lbl, .harm .big { color: var(--harm); }
.good .lbl, .good .big { color: var(--accent); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.big { font-size: 28px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { font-size: 14px; font-weight: 500; color: var(--muted); }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.pill { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill.bad { background: var(--harm-soft); color: var(--harm); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.meter { height: 9px; border-radius: 99px; background: var(--track); position: relative; }
.meter i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; }
.meter .lim { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }

.legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.days { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; height: 130px; align-items: end; }
.days .d { height: 100%; display: flex; flex-direction: column-reverse; }
.days .d i { display: block; background: var(--accent); }
.days .d i.h { background: var(--harm); }
.days .d i:last-child { border-radius: 4px 4px 0 0; }
.days .lim { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--ink); opacity: .5; }
.days-x { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; text-align: center; font-size: 11px; color: var(--muted); }

.cats { display: flex; flex-direction: column; gap: 8px; }
.cat { display: grid; grid-template-columns: 104px minmax(0, 1fr) 62px; gap: 8px; align-items: center; font-size: 13px; }
.cat span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.cat .bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.cat.h .bar i { background: var(--harm); }
.cat .v { text-align: right; font-variant-numeric: tabular-nums; }

.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 2px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th { font-size: 11px; font-weight: 500; color: var(--muted); }
.tbl th:first-child, .tbl td:first-child { text-align: left; white-space: normal; }
.tbl tr.category td { color: var(--muted); font-size: 12px; }
.tbl tr.category td:first-child { padding-left: 12px; }
.tbl tr.group td, .tbl tr.budget td { font-weight: 600; }
.tbl tr.harmful td { color: var(--harm); font-weight: 600; }
.tbl tr.total td { font-weight: 700; border-top: 1.5px solid var(--ink); }
.tbl tr.variance td { font-weight: 700; border-bottom: 0; }
.tbl tr.variance td.neg { color: var(--harm); }
.tbl tr.variance td.pos { color: var(--accent); }
.tbl td.g { color: var(--accent); font-weight: 600; }
.tbl tr:last-child td { border-bottom: 0; }

.alt-row { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 10px; align-items: center; font-size: 12.5px; }
.alt-bar { height: 18px; background: var(--track); border-radius: 5px; position: relative; overflow: hidden; }
.alt-bar i { position: absolute; inset: 0 auto 0 0; }
.alt-bar i.g { background: var(--accent); }
.alt-bar i.c { background: var(--muted); opacity: .5; }
.alt-val { grid-column: 2; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: -6px; font-size: 12.5px; }

.rc-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rc-row:last-of-type { border-bottom: 0; }
.rc-row b { display: block; font-size: 15px; font-weight: 600; }
.rc-row span { font-size: 12.5px; color: var(--muted); }
.grade { font-family: var(--f-display); font-weight: 700; font-size: 26px; text-align: right; }
.grade.hi { color: var(--accent); }
.grade.lo { color: var(--harm); }
.overall { display: flex; align-items: center; justify-content: space-between; border-top: 2px solid var(--ink); padding-top: 12px; }
.overall b { font-family: var(--f-display); font-weight: 500; font-size: 22px; }
.overall .badge { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-family: var(--f-display); font-weight: 700; font-size: 28px; color: #fff; background: var(--ink); }
.overall .badge.hi { background: var(--accent); }
.overall .badge.lo { background: var(--harm); }
.quote { font-size: 14px; line-height: 1.45; }
.quote cite { display: block; font-style: normal; font-weight: 600; color: var(--brass); font-size: 12.5px; margin-top: 4px; }

@media (prefers-reduced-motion: no-preference) {
  .meter i, .cat .bar i, .days .d i, .alt-bar i { transition: width .35s ease, height .35s ease; }
}
