/* =========================================================
 * Матрица жизни v2 — Дизайн-система и компоненты
 * Тёмная и светлая темы, CSS-токены, адаптивная навигация,
 * уважение prefers-reduced-motion, контраст ≥ AA.
 * ========================================================= */

:root {
  color-scheme: dark;
  /* Поверхности и линии (Тёмная тема по умолчанию) */
  --bg: #0b0f14;
  --bg2: #121923;
  --bg3: #1a2432;
  --bg-elev: #1e2a3a;
  --line: #243040;
  --line-strong: #334155;

  /* Текст (контраст ≥ AA) */
  --fg: #f1f5f9;
  --fg2: #cbd5e1;
  --fg3: #94a3b8;

  /* Акценты и статусы */
  --acc: #38bdf8;
  --acc-fg: #04202e;
  --acc-soft: rgba(56, 189, 248, 0.14);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --bad: #fb7185;
  --bad-soft: rgba(251, 113, 133, 0.14);

  /* 6 осей матрицы */
  --love: #f43f5e;
  --friendship: #6366f1;
  --work: #3b82f6;
  --hobby: #a855f7;
  --wealth: #10b981;
  --health: #14b8a6;

  /* Градиенты */
  --grad-acc: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  --grad-card: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0) 100%);
  --nav-bg: rgba(11, 15, 20, 0.92);

  /* Радиусы, тени, отступы */
  --r-sm: 8px;
  --r: 14px;
  --r-lg: 20px;
  --r-full: 999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);

  /* Типографика */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Светлая тема по системе, если пользователь не переопределил */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f8fafc;
    --bg2: #ffffff;
    --bg3: #f1f5f9;
    --bg-elev: #e2e8f0;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --fg: #0f172a;
    --fg2: #334155;
    --fg3: #475569;
    --acc: #0284c7;
    --acc-fg: #ffffff;
    --acc-soft: rgba(2, 132, 199, 0.12);
    --ok: #059669;
    --ok-soft: rgba(5, 150, 105, 0.12);
    --warn: #d97706;
    --warn-soft: rgba(217, 119, 6, 0.12);
    --bad: #e11d48;
    --bad-soft: rgba(225, 29, 72, 0.12);
    --grad-card: linear-gradient(180deg, rgba(15,23,42,0.015) 0%, rgba(15,23,42,0) 100%);
    --nav-bg: rgba(255, 255, 255, 0.92);
    --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);
  }
}

/* Принудительная светлая тема */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --bg-elev: #e2e8f0;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --fg: #0f172a;
  --fg2: #334155;
  --fg3: #475569;
  --acc: #0284c7;
  --acc-fg: #ffffff;
  --acc-soft: rgba(2, 132, 199, 0.12);
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, 0.12);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --bad: #e11d48;
  --bad-soft: rgba(225, 29, 72, 0.12);
  --grad-card: linear-gradient(180deg, rgba(15,23,42,0.015) 0%, rgba(15,23,42,0) 100%);
  --nav-bg: rgba(255, 255, 255, 0.92);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);
}

/* Уважение prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  padding-bottom: 92px;
  overscroll-behavior-y: none;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 14px;
  animation: fadeIn 0.22s var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.muted { color: var(--fg2); }
.dim { color: var(--fg3); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }

/* Карточки */
.card {
  background: var(--bg2);
  background-image: var(--grad-card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.card.tight { padding: 12px 14px; }
.card.accent-border { border-left: 4px solid var(--acc); }
.card.evening-prompt {
  border-color: var(--acc);
  background: linear-gradient(135deg, var(--acc-soft) 0%, var(--bg2) 100%);
}

/* Сетки и флексы */
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap2 { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 520px) {
  .g3-sm-1 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
}

/* Кнопки и переключатели */
button, .btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg3);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 10px;
  transition: transform 0.12s var(--ease), background-color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover, .btn:hover { border-color: var(--line-strong); }
button:active, .btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--acc);
  color: var(--acc-fg);
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--fg2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg3); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; display: flex; text-align: center; }

/* Сегментированный переключатель */
.seg {
  display: inline-flex;
  background: var(--bg3);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--line);
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--fg2);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}
.seg button.on {
  background: var(--bg2);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

/* Поля ввода */
input, select, textarea {
  font: inherit;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--acc);
}
input[type="range"] {
  padding: 0;
  accent-color: var(--acc);
  cursor: pointer;
}
textarea { min-height: 76px; resize: vertical; }
label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg2);
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field { margin-bottom: 10px; }

/* Бейджи и чипы осей */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: var(--bg3);
  color: var(--fg2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--bg3);
  color: var(--fg2);
  cursor: pointer;
  transition: all 0.15s;
}
.chip.on, .chip:hover {
  border-color: var(--acc);
  color: var(--fg);
  background: var(--acc-soft);
}
.axis-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--r-full);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.big { font-size: 40px; font-weight: 800; line-height: 1; }
.kpi { font-size: 26px; font-weight: 800; line-height: 1.1; }

/* Навигация: мобильная снизу, десктопная слева от 900px */
nav.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs button {
  flex: 1;
  background: none;
  border: none;
  color: var(--fg3);
  padding: 7px 2px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
}
nav.tabs button .ic { font-size: 18px; line-height: 1; }
nav.tabs button.on {
  color: var(--acc);
  background: var(--acc-soft);
}

@media (min-width: 900px) {
  body {
    padding-bottom: 24px;
    padding-left: 220px;
  }
  nav.tabs {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 220px;
    flex-direction: column;
    justify-content: flex-start;
    padding: 24px 12px;
    border-top: none;
    border-right: 1px solid var(--line);
    gap: 6px;
  }
  nav.tabs::before {
    content: "Матрица жизни";
    font-size: 16px;
    font-weight: 800;
    color: var(--fg);
    padding: 4px 12px 16px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
  }
  nav.tabs button {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    padding: 11px 14px;
    font-size: 14px;
    gap: 10px;
  }
  .wrap {
    max-width: 880px;
    padding: 28px 28px;
  }
}

/* Плавающая кнопка «+» (Быстрые действия) */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 26;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--grad-acc);
  color: #ffffff;
  border: none;
  font-size: 28px;
  font-weight: 400;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s var(--ease-spring);
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(0.94); }
@media (min-width: 900px) {
  .fab { bottom: 28px; right: 28px; }
}

/* Bottom Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s var(--ease);
}
.sheet {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.22s var(--ease);
}
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--r-lg); padding-bottom: 20px; }
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--line-strong);
  border-radius: 99px;
  margin: 0 auto 12px;
}

/* Привычки и анимация отметки */
.habit {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.habit:last-child { border-bottom: none; }
.habit .tick, .tick {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  border: 2px solid var(--line-strong);
  background: transparent;
  display: grid;
  place-items: center;
  font-size: 15px;
  color: transparent;
  padding: 0;
  transition: transform 0.25s var(--ease-spring), background-color 0.15s, border-color 0.15s;
}
.habit .tick.done, .tick.done {
  color: #04202e;
  border-color: transparent;
  animation: popSpring 0.35s var(--ease-spring);
}
@keyframes popSpring {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.habit .ttl { flex: 1; min-width: 0; font-weight: 600; }
.habit .ttl small {
  display: block;
  font-weight: 400;
  color: var(--fg3);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.streakbar { display: flex; gap: 2px; margin-top: 6px; }
.streakbar i { width: 7px; height: 14px; border-radius: 2px; background: var(--bg3); }
.streakbar i.on { background: var(--ok); }
.streakbar i.today { outline: 1px solid var(--acc); outline-offset: 1px; }

/* Таблицы */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--fg3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
td.n, th.n { text-align: right; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Полоски показателей и скелетоны */
.meter { height: 7px; background: var(--bg3); border-radius: var(--r-full); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; border-radius: var(--r-full); background: var(--acc); transition: width 0.35s var(--ease); }

.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg-elev) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
  height: 20px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.sep { height: 1px; background: var(--line); margin: 12px 0; }
.empty { text-align: center; color: var(--fg3); padding: 22px 10px; font-size: 14px; }
.hidden { display: none !important; }

/* Логин и Тост */
.login { max-width: 360px; margin: 14vh auto; padding: 0 18px; }
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 94px;
  z-index: 60;
  background: var(--bg3);
  border: 1px solid var(--line-strong);
  color: var(--fg);
  border-radius: var(--r-full);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* Тренировки и подходы */
.setrow { display: grid; grid-template-columns: 1fr 66px 54px 54px 32px; gap: 6px; margin-bottom: 6px; align-items: center; }
.setrow input { padding: 8px 9px; font-size: 13px; }
.hint { font-size: 11px; color: var(--acc); margin-top: 3px; }
details summary { cursor: pointer; font-weight: 600; color: var(--fg2); padding: 4px 0; }

/* Эмодзи настроения и энергии */
.mood-pick { display: flex; gap: 6px; }
.mood-pick button {
  flex: 1;
  font-size: 20px;
  padding: 8px 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.mood-pick button.on {
  border-color: var(--acc);
  background: var(--acc-soft);
  transform: scale(1.05);
}

/* Конфетти и анимация колеса */
.wheel-poly {
  transform-origin: center;
  animation: drawWheel 0.5s var(--ease);
}
@keyframes drawWheel {
  from { transform: scale(0.15); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}
.confetti-burst {
  position: fixed;
  pointer-events: none;
  z-index: 70;
  inset: 0;
  overflow: hidden;
}
.confetti-dot {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  animation: confettiFall 0.85s var(--ease) forwards;
}
@keyframes confettiFall {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

/* Таймер отдыха */
.rest-bar {
  position: sticky;
  bottom: 72px;
  z-index: 22;
  background: var(--bg3);
  border: 1px solid var(--acc);
  border-radius: var(--r);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
