/* Палитра построена от предмета: тренажёр когнитивных функций.
   Чернильно-сливовая база, приглушённое золото как единственный яркий акцент,
   три темы занятий получают собственные цвета и держат навигацию по контенту. */
:root {
  --ink: #17131F;
  --ink-soft: #4A4356;
  --ink-faint: #8A8394;
  --bg: #F3F1F6;
  --paper: #FFFFFF;
  --line: #E2DEE9;
  --line-strong: #CFC8DC;
  --plum: #4B2E73;
  --plum-hover: #5C3A8A;
  --plum-wash: #EFEAF6;
  --gold: #A07829;
  --gold-wash: #F7F0DF;
  --green: #2C6E5A;
  --green-wash: #E5F1EC;
  --rust: #9B4A26;
  --rust-wash: #F7EAE3;
  --red: #93262C;
  --red-wash: #F8E7E7;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-1: 0 1px 2px rgba(23, 19, 31, .05);
  --shadow-2: 0 12px 32px -12px rgba(23, 19, 31, .22);
  --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, ui-sans-serif, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1140px; margin: 0 auto; padding: 36px 24px 96px; }

h1 { font-size: clamp(26px, 3vw, 34px); font-weight: 800; letter-spacing: -.025em; line-height: 1.15; margin: 0 0 4px; }
h2 { font-size: 19px; font-weight: 750; letter-spacing: -.015em; margin: 40px 0 14px; }
p { margin: 0 0 14px; }
a { color: var(--plum); text-underline-offset: 3px; }

.lead { color: var(--ink-soft); max-width: 64ch; }
.dim { color: var(--ink-faint); }
.clip { max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  height: 62px; padding: 0 24px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 800; font-size: 17px; letter-spacing: -.03em;
  text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 9px;
}
.brand::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, var(--gold), var(--plum) 70%);
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  text-decoration: none; color: var(--ink-soft); font-weight: 600; font-size: 14.5px;
  padding: 7px 13px; border-radius: 999px;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.topbar nav a:hover { background: var(--plum-wash); color: var(--ink); }
.topbar nav a.on { background: var(--plum); color: #fff; }
.out { display: flex; align-items: center; gap: 12px; margin: 0; }
.out span { color: var(--ink-faint); font-size: 13.5px; }
.out button { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.out button:hover { background: var(--paper); color: var(--ink); }

.head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 6px; }

/* Кнопки */
button, .button {
  font: inherit; font-weight: 650; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: var(--plum); color: #fff;
  padding: 9px 16px; text-decoration: none; display: inline-block;
  transition: background .16s var(--ease), transform .16s var(--ease), box-shadow .16s var(--ease);
}
button:hover, .button:hover { background: var(--plum-hover); box-shadow: var(--shadow-2); }
button:active, .button:active { transform: translateY(1px); }
.button.ghost, button.ghost { background: var(--paper); color: var(--plum); border-color: var(--line-strong); }
.button.ghost:hover, button.ghost:hover { background: var(--plum-wash); box-shadow: var(--shadow-1); }
.button.big { padding: 13px 22px; font-size: 16px; border-radius: var(--r-md); }
button.danger { background: var(--paper); color: var(--red); border-color: var(--line-strong); }
button.danger:hover { background: var(--red-wash); }
:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; border-radius: 4px; }

/* Поля */
input, select, textarea {
  font: inherit; width: 100%; padding: 9px 12px; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--paper);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--plum); box-shadow: 0 0 0 3px var(--plum-wash);
}
textarea { resize: vertical; line-height: 1.55; }
input.narrow { width: 84px; }
label, .field { display: block; margin-bottom: 18px; font-weight: 650; font-size: 14px; }
label input, label select, label textarea { margin-top: 6px; font-weight: 400; font-size: 15px; }
label small, .field small { display: block; margin-top: 6px; color: var(--ink-faint); font-weight: 400; font-size: 13px; line-height: 1.45; }
label.check { font-weight: 500; display: flex; align-items: center; gap: 10px; }
label.check input { width: auto; margin: 0; accent-color: var(--plum); }
.field-label { display: block; margin-bottom: 6px; }

fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 20px 4px; margin: 0 0 20px; background: var(--paper); }
legend { font-weight: 750; padding: 0 8px; font-size: 14px; }

.stack { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 26px; box-shadow: var(--shadow-1); }
.form-wide { max-width: 820px; }
.narrow-form { max-width: 460px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.actions.tight { margin-top: 10px; }

.filters { display: flex; gap: 10px; margin: 20px 0 22px; flex-wrap: wrap; }
.filters input { flex: 1; min-width: 220px; }
.filters select { width: auto; }

/* Таблицы */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-1);
}
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 700; color: var(--ink-faint); background: #FAF9FC; letter-spacing: .01em; }
tbody tr { transition: background .14s var(--ease); }
tbody tr:hover { background: #FBFAFD; }
tr:last-child td { border-bottom: none; }
td input { margin: 0; }
.row-actions { display: flex; gap: 8px; }
.inline { display: inline; margin: 0; }

/* Плитки сводки */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; margin: 24px 0 8px; }
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 18px 20px; box-shadow: var(--shadow-1);
}
.card b { display: block; font-size: 30px; font-weight: 800; letter-spacing: -.035em; line-height: 1.1; }
.card span { color: var(--ink-faint); font-size: 13px; }
.card:first-child b { color: var(--plum); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 22px 0 30px; }
.facts div { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); padding: 13px 16px; }
.facts span { display: block; color: var(--ink-faint); font-size: 12.5px; margin-bottom: 2px; }

/* Метки */
.tag {
  display: inline-block; margin-left: 8px; padding: 2px 9px; font-size: 12px; font-weight: 650;
  border-radius: 999px; background: var(--plum-wash); color: var(--plum);
}
.status {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 650; background: #EFEDF3; color: var(--ink-soft);
}
.status.active { background: var(--green-wash); color: var(--green); }
.status.draft { background: var(--gold-wash); color: var(--gold); }
.status.archived { background: #EFEDF3; color: var(--ink-faint); }
.status.expired, .status.payment_failed { background: var(--red-wash); color: var(--red); }

.note {
  background: var(--green-wash); border: 1px solid #C4E0D5; color: var(--green);
  padding: 11px 15px; border-radius: var(--r-sm); font-weight: 600;
  animation: drop .3s var(--ease);
}
.errors { background: var(--red-wash); border: 1px solid #E9C9C9; color: var(--red); padding: 8px 16px; border-radius: var(--r-sm); margin-bottom: 20px; }
.error { color: var(--red); }
.ok-line { color: var(--green); font-weight: 700; }
.empty { background: var(--paper); border: 1px dashed var(--line-strong); border-radius: var(--r-md); padding: 30px; color: var(--ink-faint); text-align: center; }
.hint { color: var(--ink-faint); font-size: 13px; }

@keyframes drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Картинка упражнения */
.image-slot {
  border: 1px dashed var(--line-strong); border-radius: var(--r-md);
  background: #FBFAFD; padding: 14px; min-height: 128px;
  display: grid; place-items: center;
}
.image-empty { color: var(--ink-faint); font-size: 13.5px; text-align: center; margin: 0; }
.thumb { max-width: 100%; max-height: 240px; border-radius: var(--r-sm); display: block; }

/* Диалог загрузки */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(23, 19, 31, .42);
  display: grid; place-items: center; padding: 20px;
  animation: fade .18s var(--ease);
}
.sheet-body {
  position: relative; width: min(460px, 100%);
  background: var(--paper); border-radius: var(--r-lg); padding: 30px;
  box-shadow: 0 30px 70px -20px rgba(23, 19, 31, .45);
  animation: rise .26s var(--ease);
}
.sheet-body h2 { margin: 0 0 12px; font-size: 21px; }
.sheet-close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; padding: 0;
  background: transparent; color: var(--ink-faint); border: none; font-size: 22px; line-height: 1;
}
.sheet-close:hover { background: var(--bg); color: var(--ink); box-shadow: none; }
.waiting { display: flex; align-items: center; gap: 10px; margin-top: 18px; color: var(--ink-faint); font-size: 14px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); animation: pulse 1.5s ease-in-out infinite; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: .3; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }

/* Предпросмотр */
.phone { max-width: 430px; background: #14171C; border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-2); }
.bubble { background: #232A33; color: #EDEFF2; padding: 12px 15px; border-radius: 14px 14px 14px 5px; margin-bottom: 9px; white-space: pre-wrap; line-height: 1.5; }
.tg-button { background: #232A33; color: #8FB4E4; text-align: center; padding: 11px; border-radius: 9px; margin-bottom: 7px; font-weight: 600; }

/* Вход */
.login-page { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1100px 560px at 50% -10%, #E9E2F4 0%, var(--bg) 62%); }
.login-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 22px;
  padding: 44px 40px; max-width: 420px; text-align: center; box-shadow: var(--shadow-2);
  animation: rise .4s var(--ease);
}
.login-card h1 { margin-bottom: 12px; }
.login-card p { color: var(--ink-soft); }

@media (max-width: 760px) {
  main { padding: 24px 16px 72px; }
  .grid-2, .two-col { grid-template-columns: 1fr; }
  .topbar { height: auto; flex-wrap: wrap; padding: 12px 16px; gap: 12px; position: static; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
