:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #8e8e93));
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #6d6d72));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 28%, transparent);
  --ok: #34c759;
  --warn: #ff9500;
  --radius: 12px;
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
main { padding: 12px 16px 24px; max-width: 640px; margin: 0 auto; }

/* ── Заголовки и секции ── */
.title { font-size: 22px; font-weight: 700; margin: 4px 4px 2px; }
.subtitle { color: var(--sub); margin: 0 4px 14px; font-size: 14px; }
.section-h {
  color: var(--header); font-size: 13px; text-transform: uppercase; letter-spacing: .02em;
  margin: 18px 4px 6px; display: flex; justify-content: space-between; align-items: center;
}
.section-h .link { text-transform: none; letter-spacing: 0; font-size: 14px; }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card + .card { margin-top: 10px; }
.empty { color: var(--hint); padding: 14px 16px; font-size: 14px; }

/* ── Строки списков ── */
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 46px;
  position: relative; width: 100%; background: none; border: 0; text-align: left;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 52px; right: 0; height: 1px; background: var(--sep);
}
.row.plain + .row.plain::before { left: 16px; }
.row .lead { width: 24px; text-align: center; flex: none; font-size: 18px; }
.row .main { flex: 1; min-width: 0; }
.row .name { overflow-wrap: anywhere; }
.row .meta { color: var(--sub); font-size: 13px; margin-top: 1px; }
.row .trail { color: var(--hint); font-size: 14px; flex: none; display: flex; gap: 6px; align-items: center; }
.row.done .name { color: var(--hint); text-decoration: line-through; }
.row.tappable:active { background: color-mix(in srgb, var(--hint) 12%, transparent); }
.overdue { color: var(--danger) !important; }

.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--hint); flex: none;
  display: grid; place-items: center; background: none; padding: 0; transition: .15s;
}
.check.on { background: var(--btn); border-color: var(--btn); }
.check.on::after { content: "✓"; color: var(--btn-text); font-size: 14px; font-weight: 700; }
.check.miss { border-color: var(--warn); }

/* ── Кнопки и поля ── */
.btn {
  border: 0; border-radius: 10px; padding: 8px 14px; background: var(--btn); color: var(--btn-text);
  font-weight: 600; white-space: nowrap; cursor: pointer;
}
.btn.ghost { background: color-mix(in srgb, var(--btn) 14%, transparent); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .5; }
.link { color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.input {
  width: 100%; border: 0; border-radius: 10px; padding: 10px 12px; outline: none;
  background: color-mix(in srgb, var(--hint) 14%, transparent);
}
.input:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--btn) 50%, transparent); }
.inline-form { display: flex; gap: 8px; padding: 10px 12px; align-items: center; }
.inline-form .input { flex: 1; min-width: 0; }
textarea.input { min-height: 90px; resize: vertical; }

.seg {
  display: flex; background: color-mix(in srgb, var(--hint) 16%, transparent); border-radius: 10px;
  padding: 2px; margin: 4px 0 12px;
}
.seg button {
  flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.seg button.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; border-radius: 16px; padding: 6px 12px; font-size: 14px; white-space: nowrap; cursor: pointer;
  background: var(--card); color: var(--text);
}
.chip.active { background: var(--btn); color: var(--btn-text); }

/* ── Вес и статистика ── */
.hero { padding: 16px; display: flex; align-items: center; gap: 14px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; }
.hero .big small { font-size: 16px; font-weight: 500; color: var(--hint); margin-left: 3px; }
.hero .side { flex: 1; color: var(--sub); font-size: 14px; }
.delta-down { color: var(--ok); }
.delta-up { color: var(--warn); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .k { color: var(--sub); font-size: 13px; }

/* ── График ── */
.chart-wrap { position: relative; padding: 12px 8px 6px; }
.chart { width: 100%; height: 220px; display: block; touch-action: pan-y; }
.chart .grid-line { stroke: var(--sep); stroke-width: 1; }
.chart .axis { fill: var(--hint); font-size: 10px; }
.chart .line { fill: none; stroke: var(--btn); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .avg { fill: none; stroke: var(--warn); stroke-width: 1.6; opacity: .85; }
.chart .target { stroke: var(--ok); stroke-width: 1.4; stroke-dasharray: 5 4; }
.chart .dot { fill: var(--card); stroke: var(--btn); stroke-width: 2; }
.chart .cursor { stroke: var(--hint); stroke-width: 1; }
.chart .sel { fill: var(--btn); }
.tooltip {
  position: absolute; top: 6px; transform: translateX(-50%); background: var(--text); color: var(--card);
  border-radius: 8px; padding: 4px 8px; font-size: 12px; white-space: nowrap; pointer-events: none;
}
.legend { display: flex; gap: 14px; padding: 0 16px 12px; color: var(--sub); font-size: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* ── Календарь ── */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 10px; }
.cal-nav .label { font-weight: 600; }
.cal-nav .arrow { font-size: 20px; width: 36px; height: 32px; border: 0; border-radius: 8px; background: var(--card); cursor: pointer; }
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 10px; }
.month .wd { text-align: center; color: var(--hint); font-size: 12px; padding-bottom: 4px; }
.month .day {
  aspect-ratio: 1 / 1; border: 0; border-radius: 10px; background: none; position: relative; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 15px;
}
.month .day.other { color: var(--hint); opacity: .5; }
.month .day.today { color: var(--accent); font-weight: 700; }
.month .day.selected { background: var(--btn); color: var(--btn-text); }
.month .dots { display: flex; gap: 2px; height: 5px; margin-top: 3px; }
.month .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.month .day.selected .dots i { background: var(--btn-text) !important; }
.dot-event { background: var(--btn) !important; }
.dot-training { background: var(--ok) !important; }
.dot-task { background: var(--warn) !important; }
.day-h { display: flex; justify-content: space-between; color: var(--header); font-size: 13px; margin: 16px 4px 6px; }
.day-h.today { color: var(--accent); font-weight: 600; }
.time { color: var(--sub); font-variant-numeric: tabular-nums; width: 44px; flex: none; font-size: 14px; }

/* ── Заметки ── */
.note .name { font-weight: 600; }
.note .preview { color: var(--sub); font-size: 14px; margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .preview.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Нижние вкладки ── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--sep); padding-bottom: var(--safe-bottom); z-index: 10;
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 7px 0 6px; display: flex; flex-direction: column;
  align-items: center; gap: 1px; font-size: 11px; color: var(--hint); cursor: pointer;
}
.tabs button .ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active .ico { filter: none; opacity: 1; }

/* ── Нижний лист ── */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet.hidden, .toast.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom)); max-height: 88vh; overflow-y: auto;
  animation: up .2s ease-out; max-width: 640px; margin: 0 auto;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-body h3 { margin: 0 0 12px; font-size: 18px; }
.field { margin-bottom: 10px; }
.field label { display: block; color: var(--sub); font-size: 13px; margin: 0 4px 4px; }
.two { display: flex; gap: 8px; }
.two > * { flex: 1; min-width: 0; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  z-index: 30; max-width: 90vw; text-align: center;
}
.loading { color: var(--hint); text-align: center; padding: 40px 0; }
.error-box { background: var(--card); border-radius: var(--radius); padding: 20px; text-align: center; color: var(--sub); }

/* ── Привычки ── */
.streak { font-size: 13px; color: var(--warn); font-weight: 600; margin-left: 4px; }
.bar { height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--hint) 22%, transparent); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--btn); border-radius: 2px; transition: width .2s; }
.row.done-soft .name { color: var(--hint); }
