/* ==========================================================================
   Дневник тренировок — Mobile-First PWA
   Фиолетовая тёмная тема
   ========================================================================== */

:root {
  /* Поверхности */
  --bg:            #0f0a1f;
  --bg-elevated:   #1a1230;
  --surface:       #221842;
  --surface-2:     #2d2050;
  --border:        #382a5c;

  /* Бренд (фиолетовый) */
  --primary:        #8b5cf6;
  --primary-hover:  #7c3aed;
  --primary-soft:   rgba(139, 92, 246, 0.15);
  --accent:         #a855f7;
  --gradient:       linear-gradient(135deg, #8b5cf6 0%, #a855f7 100%);

  /* Текст */
  --text:          #f5f3ff;
  --text-muted:    #a99fc7;
  --text-dim:      #6f6592;

  /* Состояния */
  --success:       #34d399;
  --warning:       #fbbf24;
  --danger:        #f87171;
  --info:          #60a5fa;

  /* Типы подходов */
  --set-warmup:    #fbbf24;
  --set-working:   #8b5cf6;
  --set-drop:      #60a5fa;
  --set-failure:   #f87171;

  --radius:     16px;
  --radius-sm:  10px;
  --radius-lg:  24px;
  --shadow:     0 8px 30px rgba(0, 0, 0, 0.4);
  --shadow-glow:0 0 0 1px var(--primary-soft), 0 8px 30px rgba(139,92,246,0.25);

  --bottom-nav-h: 68px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Roboto', sans-serif;
}

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

html, body {
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
}

input, select, textarea { user-select: text; font-family: inherit; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ====== App layout ====== */
#app {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

.screen {
  padding: calc(16px + var(--safe-top)) 16px calc(var(--bottom-nav-h) + 24px + var(--safe-bottom));
  min-height: 100dvh;
  animation: fadeIn .22s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ====== Splash (до загрузки) ====== */
.splash {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.splash__logo { font-size: 64px; animation: pulse 1.6s ease-in-out infinite; }
.splash__text { color: var(--text-muted); font-weight: 600; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.1); opacity: 1; } }

/* ====== Header ====== */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.header__back {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}
.header__title { font-size: 24px; font-weight: 700; flex: 1; }
.header__title small { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); }

/* ====== Кнопки ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  transition: transform .12s ease, background .15s ease;
  min-height: 48px;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--gradient); color: #fff; box-shadow: 0 6px 18px rgba(139,92,246,.35); }
.btn--primary:active { background: var(--primary-hover); }
.btn--ghost { background: var(--surface); color: var(--text); }
.btn--ghost:active { background: var(--surface-2); }
.btn--danger { background: rgba(248,113,113,.15); color: var(--danger); }
.btn--block { width: 100%; }
.btn--lg { padding: 18px; font-size: 18px; }
.btn--icon { padding: 0; width: 44px; height: 44px; min-height: 44px; border-radius: 12px; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ====== Инпуты ====== */
.field { margin-bottom: 14px; }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  transition: border-color .15s ease;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); }
.input::placeholder { color: var(--text-dim); }
.textarea { resize: vertical; min-height: 80px; }

/* ====== Карточки ====== */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

/* ====== Списки (exercises / programs / history) ====== */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.list-item:active { transform: scale(.98); background: var(--surface); }
.list-item__icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
  display: grid; place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}
.list-item__body { flex: 1; min-width: 0; }
.list-item__title { font-weight: 600; font-size: 16px; }
.list-item__sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.list-item__action { color: var(--text-dim); font-size: 20px; }

/* ====== Badges / chips ====== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}
.chip--primary { background: var(--primary-soft); color: var(--accent); }
.chip--success { background: rgba(52,211,153,.15); color: var(--success); }
.chip--warning { background: rgba(251,191,36,.15); color: var(--warning); }

.muscle-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.muscle-chest    { background: rgba(248,113,113,.18); color: #fca5a5; }
.muscle-back     { background: rgba(96,165,250,.18); color: #93c5fd; }
.muscle-legs     { background: rgba(52,211,153,.18); color: #6ee7b7; }
.muscle-shoulders{ background: rgba(251,191,36,.18); color: #fcd34d; }
.muscle-arms     { background: rgba(168,85,247,.18); color: #c4b5fd; }
.muscle-core     { background: rgba(244,114,182,.18); color: #f9a8d4; }

/* ====== Поиск / фильтры ====== */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input { padding-left: 44px; }
.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: .6;
}
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-pill {
  padding: 8px 16px;
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  border: 1.5px solid transparent;
  transition: all .12s;
}
.filter-pill--active {
  background: var(--primary-soft);
  color: var(--text);
  border-color: var(--primary);
}

/* ====== Bottom navigation ====== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: rgba(26, 18, 48, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  border-radius: 12px;
  transition: color .12s;
}
.nav-item__icon { font-size: 22px; }
.nav-item--active { color: var(--accent); }
.nav-item--active .nav-item__icon { transform: translateY(-1px); }
.nav-item--cta .nav-item__icon {
  background: var(--gradient);
  color: #fff;
  width: 48px; height: 48px;
  border-radius: 16px;
  display: grid; place-items: center;
  margin-top: -18px;
  box-shadow: 0 6px 18px rgba(139,92,246,.4);
  font-size: 26px;
}

/* ====== Экран активной тренировки ====== */
.workout-exercise {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.workout-exercise__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
}
.workout-exercise__name { font-weight: 700; font-size: 16px; flex: 1; }
.workout-exercise__hint {
  margin: 0 16px 12px;
  padding: 10px 12px;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--accent);
  border-left: 3px solid var(--primary);
}
.workout-exercise__prev {
  margin: 0 16px 8px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Таблица подходов */
.set-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr 46px;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.set-row__num {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--surface);
  font-weight: 700;
  font-size: 14px;
}
.set-row--done .set-row__num { background: var(--success); color: #042f1c; }
.set-input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  width: 100%;
  min-width: 0;
}
.set-input:focus { outline: none; border-color: var(--primary); }
.set-input--unit { position: relative; }
.set-input-wrap { position: relative; }
.set-input-wrap__unit {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--text-dim); pointer-events: none;
}

.set-type-btn {
  width: 36px; height: 32px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface);
  color: var(--text-dim);
}
.set-type-btn--warmup { color: var(--set-warmup); }
.set-type-btn--working { color: var(--set-working); }
.set-type-btn--drop { color: var(--set-drop); }
.set-type-btn--failure { color: var(--set-failure); }
.set-type-btn--active { background: currentColor; color: var(--bg) !important; opacity: .9; }

.set-check {
  width: 46px; height: 38px;
  border-radius: 10px;
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 20px;
  color: var(--text-dim);
}
.set-check--done { background: var(--success); color: #042f1c; }

.set-steppers {
  display: flex;
  gap: 6px;
  padding: 0 16px 10px;
  flex-wrap: wrap;
}
.stepper {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.stepper:active { background: var(--surface-2); }

/* ====== Rest timer (sticky) ====== */
.rest-timer {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 496px;
  background: var(--gradient);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(139,92,246,.5);
  z-index: 200;
  color: #fff;
  animation: slideDown .3s ease;
}
@keyframes slideDown { from { transform: translate(-50%, -120%); } to { transform: translate(-50%, 0); } }
.rest-timer--hidden { display: none; }
.rest-timer__time {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 78px;
  text-align: center;
}
.rest-timer__label { font-size: 12px; opacity: .85; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.rest-timer__controls { display: flex; gap: 6px; margin-left: auto; }
.rest-timer__btn {
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
}
.rest-timer__btn:active { background: rgba(255,255,255,.32); }
.rest-timer--finished { animation: pulseRed 1s ease-in-out infinite; }
@keyframes pulseRed {
  0%,100% { box-shadow: 0 8px 30px rgba(52,211,153,.5); }
  50% { box-shadow: 0 8px 40px rgba(52,211,153,.9); }
}

/* ====== Пустые состояния ====== */
.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty__icon { font-size: 56px; margin-bottom: 14px; opacity: .5; }
.empty__title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty__sub { font-size: 14px; }

/* ====== Тосты ====== */
.toasts {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 488px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
}
.toast--success { border-color: var(--success); color: var(--success); }
.toast--error { border-color: var(--danger); color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ====== Модальное окно ====== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: sheetUp .3s cubic-bezier(.32,.72,0,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.modal__handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.modal__title { font-size: 20px; font-weight: 700; margin-bottom: 16px; }

/* ====== Progress / счётчики ====== */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.stat-card__value { font-size: 28px; font-weight: 800; }
.stat-card__label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.progress-ring { display: block; margin: 0 auto; }
.progress-ring__circle {
  transition: stroke-dashoffset .35s ease;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

/* ====== График (SVG) ====== */
.chart {
  width: 100%;
  height: 160px;
  margin: 12px 0;
}
.chart__line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart__area { fill: url(#chartGrad); opacity: .4; }
.chart__dot { fill: var(--accent); }
.chart__grid { stroke: var(--border); stroke-width: 1; }
.chart__label { fill: var(--text-dim); font-size: 10px; }

/* ====== Plates calc ====== */
.plate-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.plate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.plate__disc {
  width: 44px; height: 44px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
}
.plate__count { font-size: 11px; color: var(--text-muted); }

/* ====== AI Summary (разбор тренировки) ====== */
.summary {
  animation: fadeIn .4s ease;
}

.summary__hero {
  text-align: center;
  padding: 24px 16px 28px;
  background: var(--gradient);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.summary__hero::before {
  content: '';
  position: absolute;
  top: -40%; right: -20%;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.summary__score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  font-size: 36px;
  font-weight: 900;
  color: #fff;
  margin-bottom: 10px;
}
.summary__score-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  opacity: .8;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.summary__section {
  margin-bottom: 16px;
}
.summary__section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.summary__section-title .icon { font-size: 20px; }

.summary__list {
  list-style: none;
}
.summary__list li {
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.5;
  border-left: 3px solid var(--primary);
}
.summary__list--good li { border-left-color: var(--success); }
.summary__list--improve li { border-left-color: var(--warning); }

.summary__advice {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.55;
}
.summary__advice-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.summary__motivation {
  text-align: center;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-style: italic;
  color: var(--accent);
  margin-top: 16px;
}

.summary__loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 20px;
}
.summary__spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.summary__loader-text {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
}
.summary__loader-sub {
  color: var(--text-dim);
  font-size: 13px;
}

/* ====== Утилиты ====== */
.row { display: flex; gap: 10px; align-items: center; }
.row--between { justify-content: space-between; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.t-center { text-align: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

.fade-enter { animation: fadeIn .2s ease; }
