:root {
  --bg: #0f1115;
  --card: #171a21;
  --line: #262b36;
  --text: #e8ebf0;
  --muted: #8b93a3;
  --accent: #4ade80;
  --accent-dim: #1e3a2b;
  --warn: #fbbf24;
  --bad: #f87171;
  --tab-h: 62px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { padding-bottom: calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); }

.hidden { display: none !important; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
}

.top-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }

.date { font-size: 17px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.day-progress { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }
.ai-global {
  width: 38px; height: 38px;
  display: grid;
  place-content: center;
  border: 1px solid #2b3350;
  border-radius: 10px;
  background: #1b2030;
  color: #a7b4ff;
  font-size: 17px;
  cursor: pointer;
}
.ai-global:active { transform: scale(.96); }

.bar {
  margin-top: 9px;
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .25s ease;
}

main { padding: 12px 12px 0; display: grid; gap: 12px; max-width: 720px; margin: 0 auto; }
.view { display: grid; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
}

h2 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
  padding: 6px 10px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: #10131a;
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:active { background: var(--accent-dim); }

/* ---------- ввод ---------- */

.add { display: flex; gap: 8px; margin-top: 4px; }
.add input {
  flex: 1;
  min-width: 0;
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 16px;
}
.add button {
  width: 46px;
  flex: 0 0 46px;
  border: 0;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 22px;
  cursor: pointer;
}
.add .ai-btn { width: 42px; flex-basis: 42px; font-size: 17px; background: #1b2030; color: #a7b4ff; }

.tasks, .habits, .milestones, .events { list-style: none; margin: 0; padding: 0; }

.tasks li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.tasks li:last-child { border-bottom: 0; }

.tasks input[type="checkbox"] {
  appearance: none;
  width: 24px; height: 24px;
  flex: 0 0 24px;
  border: 2px solid #3a4150;
  border-radius: 7px;
  margin: 1px 0 0;
  display: grid;
  place-content: center;
  cursor: pointer;
}
.tasks input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.tasks input[type="checkbox"]:checked::after {
  content: "✓";
  color: #0b1b12;
  font-size: 15px;
  font-weight: 800;
}

.task-text { flex: 1; min-width: 0; }
.task-note { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.task-done .task-text { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.task-meta .tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 1px 7px;
}

.habits li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.habits li:last-child { border-bottom: 0; }

.switch {
  width: 50px; height: 30px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: #10131a;
  position: relative;
  cursor: pointer;
  flex: 0 0 50px;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #4a5263;
  transition: all .18s ease;
}
.switch.on { background: var(--accent-dim); border-color: #2f6b47; }
.switch.on::after { left: 23px; background: var(--accent); }

.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.field span { font-size: 15px; }
.field input {
  width: 120px;
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  text-align: right;
}
.field.col { flex-direction: column; align-items: stretch; gap: 6px; }
.field.col input { width: 100%; text-align: left; font-size: 14px; }

.target { margin-bottom: 12px; }
.target:last-child { margin-bottom: 0; }
.target-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; gap: 8px; }
.target-row .label { color: var(--text); }
.target-row .num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.target-bar { height: 8px; background: #10131a; border-radius: 99px; overflow: hidden; }
.target-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; }
.target-fill.warn { background: var(--warn); }
.target-fill.bad { background: var(--bad); }
.target-note { font-size: 12px; color: var(--muted); margin-top: 4px; }

.milestones li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.milestones li:last-child { border-bottom: 0; }
.ms-title { flex: 1; }
.ms-days { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ms-days.soon { color: var(--warn); }
.ms-days.over { color: var(--bad); }

#weight-chart { margin: 6px 0 8px; }
#weight-chart svg { width: 100%; height: 90px; display: block; }

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

.timer-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--tab-h) + 10px + env(safe-area-inset-bottom));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 696px;
  margin: 0 auto;
  padding: 9px 10px;
  border-radius: 12px;
  background: #14201a;
  border: 1px solid #2f6b47;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.timer-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.timer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.timer-elapsed { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 14px; }
.timer-bar button {
  border: 0; border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- вкладки ---------- */

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(15, 17, 21, .97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1;
  padding: 9px 4px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  min-height: 44px;
}
.tabs button.on { color: var(--accent); background: var(--accent-dim); }

/* ---------- лог ---------- */

.day-nav { display: flex; align-items: center; gap: 4px; }
.day-nav-label { font-size: 14px; font-weight: 600; white-space: nowrap; }
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #10131a;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.filter-row button {
  border: 1px solid var(--line);
  background: #10131a;
  color: var(--muted);
  border-radius: 99px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
}
.filter-row button.on { color: var(--accent); border-color: #2f6b47; background: var(--accent-dim); }

.events li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.events li:last-child { border-bottom: 0; }
.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; width: 40px; flex: 0 0 40px; padding-top: 2px; }
.ev-icon { width: 20px; flex: 0 0 20px; text-align: center; }
.ev-body { flex: 1; min-width: 0; }
.ev-title { font-size: 14.5px; word-break: break-word; }
.ev-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.ev-del {
  border: 0; background: transparent; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 0 4px;
}
.ev-hour {
  font-size: 11px; color: var(--muted); letter-spacing: .08em;
  padding: 10px 0 2px; font-variant-numeric: tabular-nums;
}
.day-divider { height: 1px; background: var(--line); margin: 10px 0; }

/* ---------- статы ---------- */

.seg { display: flex; gap: 4px; background: #10131a; padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 9px; border-radius: 7px; font-size: 12px; cursor: pointer;
}
.seg button.on { background: var(--accent-dim); color: var(--accent); }

.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-card { background: #10131a; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.stat-card .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-card .k { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.cat-row { margin-bottom: 10px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; margin-bottom: 4px; }
.cat-top .n { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-bar { height: 7px; background: #10131a; border-radius: 99px; overflow: hidden; }
.cat-fill { height: 100%; background: var(--accent); border-radius: 99px; }

.top-row2 { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.top-row2:last-child { border-bottom: 0; }
.top-row2 .n { color: var(--muted); font-variant-numeric: tabular-nums; }

.streak-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.streak-row:last-child { border-bottom: 0; }
.streak-row .n { color: var(--accent); font-variant-numeric: tabular-nums; }
.streak-row .n.zero { color: var(--muted); }

.week-bars { display: flex; align-items: flex-end; gap: 6px; height: 96px; padding-top: 8px; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.week-col .fill { width: 100%; max-width: 34px; background: var(--accent-dim); border: 1px solid #2f6b47; border-radius: 5px 5px 0 0; min-height: 2px; }
.week-col.today .fill { background: var(--accent); border-color: var(--accent); }
.week-col .d { font-size: 10.5px; color: var(--muted); }

#ai-review { white-space: pre-wrap; line-height: 1.5; }
#ai-review h4 { margin: 10px 0 4px; font-size: 13px; color: var(--text); }
#ai-review ul { margin: 0 0 6px; padding-left: 18px; }

/* ---------- настройки ---------- */

.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding: 6px 0; }
.check-row input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.section-label { font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.exclude-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.exclude-grid label { display: flex; gap: 7px; align-items: center; font-size: 13px; padding: 3px 0; }
.exclude-grid input { accent-color: var(--accent); }
.row-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row-actions.wrap { flex-wrap: wrap; }
.row-actions button {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #10131a;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.row-actions button.ghost { color: var(--muted); }
code { background: #10131a; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* ---------- модалка / тост ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .6);
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.modal-card h3 { margin: 0 0 10px; font-size: 16px; }
.modal-body { overflow: auto; flex: 1; min-height: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal-actions button {
  padding: 10px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}
.modal-actions button.ghost { background: #10131a; color: var(--muted); }
.preview-item { display: flex; gap: 9px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.preview-item:last-child { border-bottom: 0; }
.preview-item input { margin-top: 3px; accent-color: var(--accent); }
.preview-item .pi-title { flex: 1; }
.preview-item .pi-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.preview-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.toast {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--tab-h) + 76px + env(safe-area-inset-bottom));
  z-index: 60;
  display: none;
  align-items: center;
  gap: 10px;
  max-width: 696px;
  margin: 0 auto;
  padding: 10px 12px;
  background: #1b2029;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  font-size: 13.5px;
}
.toast.show { display: flex; }
.toast span { flex: 1; }
.toast button { border: 0; background: transparent; color: var(--accent); font-size: 13.5px; cursor: pointer; }

/* ---------- запись ---------- */

.capture-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.capture-actions .tiny { flex: 1; min-width: 140px; }

.mic-btn.running {
  background: #3a1f1f;
  color: var(--bad);
  animation: pulse 1.2s infinite;
}

/* ---------- тренировки ---------- */

.train-list { margin-top: 10px; }
.train-session {
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}
.train-session:last-child { border-bottom: 0; }
.train-session summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}
.train-session summary::-webkit-details-marker { display: none; }
.train-session .ts-name { font-size: 14.5px; }
.train-session .ts-meta { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.train-sets { margin: 7px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.train-sets li { padding: 2px 0; }
.train-ex { font-size: 13px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.train-ex:last-child { border-bottom: 0; }
.train-ex-top { display: flex; justify-content: space-between; gap: 8px; }
.train-ex-top .val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.train-ex-note { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.train-next-name { font-size: 18px; font-weight: 650; margin-bottom: 3px; }
.train-next-sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.train-next-ex { font-size: 13.5px; padding: 4px 0; color: var(--text); }
.train-next-ex span { color: var(--muted); }
.start-link {
  display: block;
  margin-top: 12px;
  padding: 12px;
  text-align: center;
  border-radius: 10px;
  background: var(--accent);
  color: #0b1b12;
  font-weight: 650;
  text-decoration: none;
}
.start-link:active { opacity: .85; }

/* ---------- цели ---------- */

.goal-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.goal-item:last-child { border-bottom: 0; }
.goal-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; }
.goal-top .v { font-variant-numeric: tabular-nums; white-space: nowrap; }
.goal-bar { height: 6px; background: #10131a; border-radius: 99px; overflow: hidden; margin: 5px 0 3px; }
.goal-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.goal-fill.warn { background: var(--warn); }
.goal-fill.bad { background: var(--bad); }
.goal-note { font-size: 12px; color: var(--muted); }
.goal-status { font-size: 11px; border-radius: 99px; padding: 1px 7px; border: 1px solid var(--line); }
.goal-status.good { color: var(--accent); border-color: #2f6b47; }
.goal-status.warn { color: var(--warn); border-color: #6b5a2f; }
.goal-status.bad { color: var(--bad); border-color: #6b2f2f; }
.goal-status.neutral { color: var(--muted); }

/* ---------- модалка: список дел ---------- */

.modal-body textarea {
  width: 100%;
  min-height: 160px;
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 12px;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  resize: vertical;
}
.list-check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.list-check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent); }
.list-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

@media (min-width: 640px) {
  .stat-cards { grid-template-columns: repeat(4, 1fr); }
}
