/* 6 Weeks — мини-приложение. Цвета берём из темы Telegram (переменные --tg-theme-*),
   поэтому светлая и тёмная тема получаются сами. Запасные значения — для браузера. */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --surface: 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, #6d6d72));
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --accent-ink: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: var(--tg-theme-section-separator-color, rgba(60, 60, 67, 0.2));
  --head: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #6d6d72));
  --soft: rgba(36, 129, 204, 0.12);
  --tabs-h: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --soft: color-mix(in srgb, var(--accent) 14%, transparent);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabs-h) + var(--safe-bottom) + 28px);
}
.screen.no-tabs { padding-bottom: calc(var(--safe-bottom) + 28px); }

.loading { margin: 40vh 0 0; text-align: center; color: var(--hint); }

/* Заголовок экрана */
.head { margin: 4px 4px 16px; }
.head h1 { margin: 0; font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.01em; }
.head .sub { margin: 6px 0 0; color: var(--sub); font-size: 15px; }

.progress { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--sub); font-size: 14px; }
.progress-track { flex: 0 0 96px; height: 4px; border-radius: 2px; background: var(--sep); overflow: hidden; }
.progress-track span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }

/* Счётчик дня */
.hero { background: var(--surface); border-radius: 18px; padding: 16px 16px 12px; margin-bottom: 12px; }
.count { display: flex; align-items: baseline; gap: 10px; }
.count-num { font-size: 56px; line-height: 1; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.count-label { font-size: 17px; font-weight: 600; }
.count-avg { margin: 6px 0 0; color: var(--sub); font-size: 15px; }

/* Лента дня: сутки с 04:00 до 04:00, каждая сигарета — штрих */
.strip { margin-top: 14px; }
.strip-track { position: relative; height: 26px; }
.strip-track::before { content: ""; position: absolute; left: 0; right: 0; top: 12px; height: 2px; border-radius: 1px; background: var(--sep); }
.strip-tick { position: absolute; top: 8px; width: 1px; height: 10px; background: var(--sep); }
.strip-mark { position: absolute; top: 4px; width: 4px; height: 18px; margin-left: -2px; border-radius: 2px; background: var(--accent); }
.strip-mark.untagged { background: var(--hint); }
.strip-now { position: absolute; top: 0; width: 2px; height: 26px; margin-left: -1px; border-radius: 1px; background: var(--text); opacity: 0.5; }
.strip-labels { position: relative; height: 16px; margin-top: 2px; font-size: 11px; color: var(--hint); font-variant-numeric: tabular-nums; }
.strip-labels span { position: absolute; transform: translateX(-50%); }

/* Кнопки */
.actions { display: grid; gap: 8px; margin-bottom: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 50px; padding: 0 16px;
  border: 0; border-radius: 14px;
  font-size: 17px; font-weight: 600;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-big { min-height: 60px; font-size: 19px; }
.btn-quiet { background: var(--soft); color: var(--accent-ink); }
.btn-plain { background: none; color: var(--accent-ink); font-weight: 500; }
.btn-danger { background: none; color: var(--danger); font-weight: 500; }
.btn-small { width: auto; flex: 0 0 auto; min-height: 48px; font-size: 16px; }

/* Разделы и списки в духе Telegram */
.section-title { margin: 24px 4px 8px; font-size: 15px; font-weight: 600; color: var(--head); }
.list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border-radius: 14px; overflow: hidden; }
.list > li + li { border-top: 0.5px solid var(--sep); }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 10px 16px;
  border: 0; background: none; text-align: left;
}
button.row:active { background: var(--soft); }
.row-time { flex: 0 0 auto; min-width: 46px; color: var(--sub); font-variant-numeric: tabular-nums; }
.row-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.row-missing { color: var(--accent-ink); }
.row-note { display: block; margin-top: 1px; font-size: 13px; color: var(--hint); }
.row-count { flex: 0 0 auto; font-size: 14px; color: var(--hint); }
.row-btn { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--soft); color: var(--accent-ink); font-size: 14px; font-weight: 600; }
.row-danger { color: var(--danger); }
.row select { flex: 0 1 auto; max-width: 60%; min-height: 36px; border: 0; background: none; color: var(--accent-ink); text-align: right; }

.empty { margin: 0 4px; color: var(--hint); }
.foot { margin: 16px 4px 0; font-size: 13px; color: var(--hint); }

/* Сила тяги: пять точек */
.pips { display: inline-flex; gap: 3px; flex: 0 0 auto; min-width: 42px; justify-content: flex-end; }
.pips i { width: 6px; height: 6px; border-radius: 50%; background: var(--sep); }
.pips i.on { background: var(--accent); }

/* Нижняя панель разделов */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 0.5px solid var(--sep);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabs-h); border: 0; background: none;
  color: var(--hint); font-size: 11px; font-weight: 500;
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent-ink); }

/* Шторка снизу */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); opacity: 0; transition: opacity 0.2s ease; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 560px; max-height: 90vh; margin: 0 auto; overflow-y: auto;
  padding: 6px 16px calc(var(--safe-bottom) + 16px);
  background: var(--surface); border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform 0.22s ease;
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 36px; height: 5px; margin: 4px auto 12px; border-radius: 3px; background: var(--sep); }
.sheet h2 { margin: 2px 0 2px; font-size: 21px; line-height: 26px; }
.sheet .sub { margin: 0 0 14px; color: var(--sub); font-size: 15px; }
.sheet h3 { margin: 18px 0 10px; font-size: 17px; }
.sheet-foot { display: grid; gap: 4px; margin-top: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 42px; padding: 8px 14px;
  border: 0; border-radius: 21px;
  background: var(--bg); color: var(--text); font-size: 16px; text-align: left;
}
.chip svg { width: 14px; height: 14px; fill: currentColor; flex: 0 0 auto; }
.chip.suggested { background: var(--soft); color: var(--accent-ink); font-weight: 600; }
.chip.selected { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip-add { background: none; box-shadow: inset 0 0 0 1.5px var(--sep); color: var(--accent-ink); }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1 1 auto; min-width: 0; }

.scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.scale-btn { min-height: 54px; border: 0; border-radius: 14px; background: var(--bg); font-size: 20px; font-weight: 600; }
.scale-btn.selected { background: var(--accent); color: var(--on-accent); }
.scale-hint { display: flex; justify-content: space-between; margin: 6px 2px 0; font-size: 13px; color: var(--hint); }

.quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

input[type="text"], input[type="time"], textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--sep); border-radius: 12px;
  background: var(--bg); color: var(--text);
}
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--hint); }

/* Карточки отчёта */
.card { background: var(--surface); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.card p { margin: 0; }
.card p + p { margin-top: 8px; }
.lead { font-size: 17px; }
.hint { color: var(--sub); font-size: 15px; }

.coverage { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.coverage b { font-size: 44px; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.coverage span { font-size: 16px; line-height: 1.3; }
.split { display: flex; gap: 2px; height: 12px; border-radius: 6px; overflow: hidden; }
.split-cycles { background: var(--accent); }
.split-rest { background: var(--hint); opacity: 0.45; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; color: var(--sub); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; }
.legend .sw-accent { background: var(--accent); }
.legend .sw-rest { background: var(--hint); opacity: 0.45; }
.legend .sw-weekend { background: var(--accent); opacity: 0.5; }
.card .facts { margin-top: 14px; }

/* Твой день: циклы по времени */
.routine { list-style: none; margin: 0 0 12px; padding: 6px 16px; background: var(--surface); border-radius: 18px; }
.routine-item { position: relative; display: grid; grid-template-columns: 46px 12px minmax(0, 1fr) auto; column-gap: 12px; align-items: start; padding: 10px 0; }
.routine-item::before { content: ""; position: absolute; left: calc(46px + 12px + 5px); top: 0; bottom: 0; width: 2px; background: var(--sep); }
.routine-item:first-child::before { top: 18px; }
.routine-item:last-child::before { bottom: calc(100% - 18px); }
.routine-item:only-child::before { display: none; }
.routine-time { color: var(--sub); font-variant-numeric: tabular-nums; }
.routine-dot { position: relative; z-index: 1; width: 12px; height: 12px; margin-top: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--surface); }
.routine.near .routine-dot { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 3px var(--surface); }
.routine-name { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.routine-meta { margin: 2px 0 0; font-size: 14px; color: var(--sub); }
.routine .pips { margin-top: 8px; }

.share { display: grid; grid-template-columns: minmax(0, 1fr) 30% 40px; align-items: center; column-gap: 10px; padding: 12px 16px; }
.share-bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.share-bar i { display: block; height: 100%; border-radius: 3px; background: var(--hint); }
.share-pct { text-align: right; color: var(--sub); font-variant-numeric: tabular-nums; }

/* Сигарет по дням */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 128px; }
.bar { position: relative; flex: 1 1 0; height: 100%; padding: 0; border: 0; background: none; display: flex; align-items: flex-end; }
.bar span { display: block; width: 100%; height: max(var(--h), 3px); border-radius: 4px 4px 0 0; background: var(--accent); }
.bar.weekend span { opacity: 0.5; }
.bar.today span { background: none; box-shadow: inset 0 0 0 1.5px var(--accent); }
.bar.active span { opacity: 1; filter: brightness(1.15); }
.bars-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--hint); }
.chart-caption { min-height: 21px; margin-top: 8px !important; font-size: 15px; color: var(--sub); }

/* Подсказка внизу */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30;
  bottom: calc(var(--tabs-h) + var(--safe-bottom) + 12px);
  max-width: 420px; margin: 0 auto; padding: 12px 16px;
  border-radius: 12px; background: rgba(28, 28, 30, 0.92); color: #ffffff;
  font-size: 15px; text-align: center;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.top {
  top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 12px);
  bottom: auto; transform: translateY(-8px);
}
.toast.top.show { transform: none; }

.notice { margin: 30vh 8px 0; text-align: center; }
.notice h1 { font-size: 22px; margin: 0 0 8px; }
.notice p { margin: 0 0 16px; color: var(--sub); }

@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop, .sheet-panel, .toast, .btn { transition: none; }
}
