/* Prila — система оформления
   Ориентир: приборная панель, а не фитнес-приложение.
   Крупные табличные цифры, один акцент, без градиентов и колец прогресса. */

:root {
  color-scheme: light dark;

  /* Нейтральная шкала — светлая тема */
  --bg: #f1f3f4;
  --surface: #ffffff;
  --surface-sunken: #e7eaec;
  --border: #d8dee1;
  --border-strong: #b9c2c7;
  --ink: #111619;
  --ink-muted: #5b666c;
  --ink-faint: #8b969b;

  /* Акцент — янтарь приборного табло */
  --accent: #ffb000;
  --accent-ink: #1a1200;
  --accent-text: #9a6000;
  --accent-soft: rgba(255, 176, 0, 0.16);

  --good: #1f8a4c;
  --warn: #b57400;
  --critical: #c23b32;

  /* Ритм */
  --u: 8px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Системный SF Pro: резкие табличные цифры, доступен офлайн */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;

  --tap: 48px;
  --tabbar: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1113;
    --surface: #171b1e;
    --surface-sunken: #101416;
    --border: #262c30;
    --border-strong: #3a4348;
    --ink: #e9eef1;
    --ink-muted: #939fa5;
    --ink-faint: #6b767c;
    --accent-text: #ffb000;
    --accent-soft: rgba(255, 176, 0, 0.14);
    --good: #3fb373;
    --warn: #e0a02a;
    --critical: #e06258;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1113;
  --surface: #171b1e;
  --surface-sunken: #101416;
  --border: #262c30;
  --border-strong: #3a4348;
  --ink: #e9eef1;
  --ink-muted: #939fa5;
  --ink-faint: #6b767c;
  --accent-text: #ffb000;
  --accent-soft: rgba(255, 176, 0, 0.14);
  --good: #3fb373;
  --warn: #e0a02a;
  --critical: #e06258;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

/* Цифры табличные — колонки не пляшут при смене значений */
.num,
.counter-value,
.stepper-value,
.timer-face,
.stat-value,
input[type="number"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Каркас ---------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.screen {
  flex: 1;
  padding: calc(var(--u) * 2);
  padding-top: calc(env(safe-area-inset-top) + var(--u) * 2);
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + var(--u) * 3);
  display: none;
}

.screen.is-active {
  display: block;
}

.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--u);
  margin-bottom: calc(var(--u) * 2);
}

.screen-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.screen-date {
  color: var(--ink-muted);
  font-size: 14px;
}

/* ---------- Нижняя панель вкладок ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 40;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--ink-faint);
  min-height: var(--tap);
}

.tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  color: var(--ink);
}

.tab.is-active svg {
  stroke: var(--accent-text);
}

/* ---------- Карточки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: calc(var(--u) * 2);
  margin-bottom: calc(var(--u) * 1.5);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--u);
  margin-bottom: var(--u);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.card-meta {
  font-size: 13px;
  color: var(--ink-muted);
}

/* ---------- Сводка дня ---------- */

.daybar {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 1.5);
  margin-bottom: calc(var(--u) * 2);
}

.daybar-dial {
  width: 54px;
  height: 54px;
  flex: none;
}

.daybar-text {
  min-width: 0;
}

.daybar-text strong {
  display: block;
  font-size: 17px;
  font-weight: 600;
}

.daybar-text span {
  display: block;
  font-size: 14px;
  color: var(--ink-muted);
  /* Одна строка: перенос сдвигал карточки вниз и ломал ритм экрана */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Привычка: отметка ---------- */

.habit {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 1.5);
  min-height: var(--tap);
  width: 100%;
  text-align: left;
}

.habit + .habit {
  border-top: 1px solid var(--border);
  padding-top: var(--u);
  margin-top: var(--u);
}

.habit-mark {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  display: grid;
  place-items: center;
  transition: background 120ms ease, border-color 120ms ease;
}

.habit-mark svg {
  width: 22px;
  height: 22px;
  stroke: var(--ink-faint);
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.habit.is-done .habit-mark {
  background: var(--accent);
  border-color: var(--accent);
}

.habit.is-done .habit-mark svg {
  stroke: var(--accent-ink);
}

.habit-body {
  flex: 1;
  min-width: 0;
}

.habit-name {
  display: block;
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit.is-done .habit-name {
  color: var(--ink-muted);
}

.habit-sub {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Привычка: счётчик ---------- */

.counter-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.counter-value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.counter-goal {
  font-size: 15px;
  color: var(--ink-muted);
  font-weight: 500;
}

.pips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: calc(var(--u) * 1.5) 0;
}

.pip {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
}

.pip.is-filled {
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- Питание: строка КБЖУ ---------- */

.macro-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--u);
  margin-top: calc(var(--u) * 1.5);
  padding-top: calc(var(--u) * 1.5);
  border-top: 1px solid var(--border);
}

.macro-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}

.macro-label {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.macro-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-sunken);
  margin-top: 5px;
  overflow: hidden;
}

.macro-bar > div {
  height: 100%;
  background: var(--accent);
}

.macro-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--u);
}

/* ---------- Кнопки ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 calc(var(--u) * 2);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--u);
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-quiet {
  background: var(--surface-sunken);
  color: var(--ink);
  border-color: var(--border);
}

.btn-ghost {
  color: var(--accent-text);
  min-height: 36px;
  padding: 0 var(--u);
  font-size: 15px;
}

.btn-danger {
  color: var(--critical);
  border-color: var(--border);
}

.btn-block {
  width: 100%;
}

.btn:active {
  transform: scale(0.985);
}

.btn-row {
  display: flex;
  gap: var(--u);
}

.btn-row .btn {
  flex: 1;
}

/* ---------- Шаговый ввод ---------- */

.stepper {
  display: flex;
  align-items: center;
  gap: var(--u);
}

.stepper-btn {
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: var(--radius);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  font-size: 26px;
  font-weight: 600;
  display: grid;
  place-items: center;
  line-height: 1;
}

.stepper-field {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.stepper-value {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.stepper-label {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Таймер ---------- */

.timer-face {
  font-size: 64px;
  font-weight: 700;
  letter-spacing: -0.04em;
  text-align: center;
  line-height: 1;
  margin: calc(var(--u) * 2) 0;
}

.timer-caption {
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
  margin-bottom: calc(var(--u) * 2);
}

/* ---------- Лист снизу ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--border);
  padding: calc(var(--u) * 2);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--u) * 2);
  max-height: 88dvh;
  overflow-y: auto;
  transform: translateY(101%);
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet.is-open {
  transform: translateY(0);
}

.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 0 auto calc(var(--u) * 2);
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-sunken);
  z-index: 2;
}

.sheet-close svg {
  width: 18px;
  height: 18px;
  stroke: var(--ink-muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.sheet-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 calc(var(--u) * 2);
}

.field {
  margin-bottom: calc(var(--u) * 2);
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.choice-row {
  display: flex;
  gap: var(--u);
}

.choice {
  flex: 1;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  font-size: 15px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

.choice.is-picked {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.choice-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.choice-days .choice {
  min-height: 42px;
  font-size: 13px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--u);
}

/* ---------- Пустые состояния ---------- */

.empty {
  text-align: center;
  color: var(--ink-muted);
  padding: calc(var(--u) * 4) calc(var(--u) * 2);
  font-size: 15px;
}

/* ---------- Списки ---------- */

.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: calc(var(--u) * 1.5);
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--u);
  width: 100%;
  min-height: var(--tap);
  padding: 10px calc(var(--u) * 2);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row-main {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  font-size: 16px;
}

.list-row-sub {
  font-size: 13px;
  color: var(--ink-muted);
}

.list-row-value {
  color: var(--ink-muted);
  font-size: 15px;
}

.section-label {
  font-size: 13px;
  color: var(--ink-muted);
  margin: calc(var(--u) * 3) 0 var(--u);
}

/* ---------- Аналитика ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--u);
  margin-bottom: calc(var(--u) * 1.5);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: calc(var(--u) * 1.5);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-label {
  font-size: 13px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.grid-month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.grid-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}

/* Число дня в ячейке календаря */
.grid-cell.has-num {
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--ink-muted);
}

.grid-cell.is-blank {
  border-color: transparent;
  background: none;
}

.grid-cell.is-done,
.grid-cell.is-done .num {
  color: var(--accent-ink);
  font-weight: 600;
}

.grid-cell.is-today {
  border-color: var(--ink);
  border-width: 2px;
}

.grid-cell.is-today .num {
  color: var(--ink);
  font-weight: 700;
}

.grid-cell.is-picked {
  outline: 2px solid var(--accent-text);
  outline-offset: 1px;
}

/* Год целиком: недели колонками, дни строками — как на GitHub */
.year-grid {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  margin-bottom: var(--u);
}

.year-cell {
  aspect-ratio: 1;
  border-radius: 1.5px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}

.year-cell.is-done {
  background: var(--accent);
  border-color: var(--accent);
}

.year-cell.is-partial {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.year-cell.is-off {
  background: none;
  border-color: transparent;
}

/* Тепловая сетка читается как единый блок, а не как крупная таблица */
.grid-heat {
  max-width: 260px;
  gap: 3px;
}

.grid-heat .grid-cell {
  border-radius: 3px;
}

.grid-cell.is-done {
  background: var(--accent);
  border-color: var(--accent);
}

.grid-cell.is-partial {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.grid-cell.is-future {
  opacity: 0.4;
}

/* Тост стоит под заголовком: снизу его перекрывал бы открытый лист,
   а у самого верха он закрывал бы название экрана */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 64px);
  max-width: calc(100% - 48px);
  text-align: center;
  transform: translate(-50%, -12px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 60;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
