/* Оверлей ИИ-помощника: анимация появления/закрытия диалога (панель "вырастает" из кнопки
   #supportLauncher через clip-path: circle(...at var(--morph-x) var(--morph-y))), панель
   настроек внутри диалога, «живая» плавающая кнопка (разворот при открытии/закрытии,
   см. .drawer-open/.drawer-closing) и проактивные облачка-подсказки (подсказки урока и
   напоминания делят одну и ту же карточку .assistant-nudge, см. assistant-ui.js).
   Анимируются opacity, transform, clip-path и backdrop-filter, без width/height, чтобы не
   было рывков и переполнение/скролл внутри панели работали как обычно (после раскрытия
   clip-path сбрасывается в none, см. mount() в assistant-ui.js).
   Цвета берутся из переменных styles.css (--surface, --line, --text, --text-soft, --primary),
   поэтому тёмная тема поддерживается автоматически, без отдельных [data-theme="dark"] правил.
   Сайт уже глобально уважает prefers-reduced-motion (figma-system.css сворачивает все
   animation/transition-duration до .01ms), это распространяется и на анимации ниже; печатную
   машинку и точки набора (JS-таймеры, не CSS-анимация) assistant-ui.js дополнительно пропускает
   сам, проверяя matchMedia. */

/* Блокируем прокрутку страницы только на телефоне (полноэкранный лист): на десктопе исчезающая полоса прокрутки дёргала экран. */
@media (max-width: 600px) {
  html.assistant-scroll-lock { overflow: hidden; }
}

/* ---------- Подложка ---------- */
.drawer-scrim {
  background: rgba(16, 11, 24, .46);
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
  transition: none;
}
.drawer-scrim.mounted { pointer-events: auto; }
.drawer-scrim.mounted.entering { animation: l2g-scrim-in .32s cubic-bezier(.2,.8,.2,1) both; }
.drawer-scrim.mounted.leaving { animation: l2g-scrim-out .2s cubic-bezier(.2,.8,.2,1) both; }

@keyframes l2g-scrim-in {
  from { opacity: 0; -webkit-backdrop-filter: blur(0px); backdrop-filter: blur(0px); }
  to   { opacity: 1; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
}
@keyframes l2g-scrim-out {
  from { opacity: 1; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
  to   { opacity: 0; -webkit-backdrop-filter: blur(0px); backdrop-filter: blur(0px); }
}

/* ---------- Панель диалога: "вырастает" из кнопки-лаунчера ----------
   --morph-x/--morph-y - центр кнопки #supportLauncher в системе координат самой панели;
   их считает JS (assistant-ui.js, mount()) через getBoundingClientRect при каждом
   открытии. Раскрытие и закрытие - это clip-path: circle(...at var(--morph-x)
   var(--morph-y)), поэтому панель всегда "растёт"/"схлопывается" в текущее место кнопки,
   где бы она ни была пришпилена (обычный лаунчер, режим урока, embed и т.п.). Значения
   по умолчанию (100%/100%) - это просто безопасный фолбэк на случай, если clip-path
   отрисуется раньше, чем JS выставит переменные (правый нижний угол панели). */
.assistant-drawer {
  --morph-x: 100%;
  --morph-y: 100%;
  display: none;
  top: 16px; right: 16px; bottom: 16px; left: auto;
  width: min(420px, calc(100vw - 32px));
  height: auto;
  max-height: calc(100vh - 32px);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: 0 26px 60px rgba(20,10,30,.22), 0 6px 20px rgba(20,10,30,.12);
  transform: none;
  transition: none;
  opacity: 1;
  overflow: hidden;
  clip-path: none;
}
.assistant-drawer.mounted {
  display: flex;
  flex-direction: column;
}
.assistant-drawer.mounted.entering { animation: l2g-assistant-morph-in .48s cubic-bezier(.2,.8,.2,1) both; }
.assistant-drawer.mounted.leaving { animation: l2g-assistant-morph-out .32s cubic-bezier(.2,.8,.2,1) .12s both; }

@keyframes l2g-assistant-morph-in {
  from { clip-path: circle(0px at var(--morph-x) var(--morph-y)); opacity: .6; transform: scale(.94); }
  to   { clip-path: circle(160% at var(--morph-x) var(--morph-y)); opacity: 1; transform: scale(1); }
}
@keyframes l2g-assistant-morph-out {
  from { clip-path: circle(160% at var(--morph-x) var(--morph-y)); opacity: 1; transform: scale(1); }
  to   { clip-path: circle(0px at var(--morph-x) var(--morph-y)); opacity: .6; transform: scale(.94); }
}

/* Внутреннее содержимое (шапка, подсказки, сообщения, композер) появляется чуть позже
   начала раскрытия и уходит первым при закрытии, до того как схлопнется круг.
   .assistant-settings нарочно пропущена - у неё своя пара l2g-settings-in/out ниже,
   которая отрабатывает отдельным переключателем уже внутри открытой панели. */
.assistant-drawer.mounted.entering > *:not(.assistant-settings) {
  animation: l2g-drawer-content-in .28s cubic-bezier(.2,.8,.2,1) .12s both;
}
.assistant-drawer.mounted.leaving > *:not(.assistant-settings) {
  animation: l2g-drawer-content-out .12s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes l2g-drawer-content-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes l2g-drawer-content-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(8px); }
}

.assistant-drawer .chat-messages { flex: 1; min-height: 0; }
.assistant-head-actions { display: flex; align-items: center; gap: 2px; }
#assistantSettingsToggle[aria-expanded="true"] { color: var(--primary); }

/* ---------- Сообщения чата (только в панели диалога): лёгкое появление с шагом ~40 мс
   на первых строках. Селектор нарочно уточнён до .assistant-drawer: .chat-messages/
   .chat-bubble переиспользуются ещё и подсказчиком урока (#tutorMessages), который эта
   задача не трогает. ---------- */
.assistant-drawer .chat-messages .chat-bubble,
.assistant-drawer .chat-messages .chat-welcome {
  animation: l2g-row-in .22s cubic-bezier(.2,.8,.2,1) both;
}
.assistant-drawer .chat-messages .chat-bubble:nth-child(1) { animation-delay: 0ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(2) { animation-delay: 40ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(3) { animation-delay: 80ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(4) { animation-delay: 120ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(5) { animation-delay: 160ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(6) { animation-delay: 200ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(7) { animation-delay: 240ms; }
.assistant-drawer .chat-messages .chat-bubble:nth-child(8) { animation-delay: 280ms; }
@keyframes l2g-row-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Панель настроек внутри диалога ---------- */
.assistant-settings {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  opacity: 1;
  transform: none;
}
.assistant-settings.mounted { display: flex; }
.assistant-settings.mounted.entering { animation: l2g-settings-in .2s cubic-bezier(.22,.61,.36,1) both; }
.assistant-settings.mounted.leaving { animation: l2g-settings-out .16s cubic-bezier(.22,.61,.36,1) both; }
.assistant-settings .notify-channel { border-color: var(--line); padding: 10px 12px; background: var(--surface); }
.assistant-settings .notify-channel-head small { line-height: 1.35; }

@keyframes l2g-settings-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes l2g-settings-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ---------- Десктоп: компактное окошко над кнопкой, а не во весь экран ---------- */
@media (min-width: 601px) {
  .assistant-drawer {
    top: auto;
    bottom: 96px;
    height: min(640px, calc(100vh - 120px));
    max-height: none;
    border-radius: 16px;
  }
}

/* ---------- Мобильная раскладка: панель во всю ширину снизу ---------- */
@media (max-width: 600px) {
  .assistant-drawer {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 88vh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
}

/* ---------- Плавающая кнопка: дыхание в покое, вращение при подсказке,
   разворот+увеличение при открытии/закрытии панели (drawer-open/-closing переключает
   assistant-ui.js в mount()/unmount()), превращение иконки в крестик, пока открыт
   диалог ---------- */
.support-launcher-icon { will-change: transform; position: relative; }
.support-launcher:not(.nudge-active) .support-launcher-icon {
  animation: l2g-breathe 4.8s ease-in-out infinite;
}
.support-launcher.nudge-active .support-launcher-icon {
  animation: l2g-icon-spin .7s cubic-bezier(.34,1.56,.64,1);
}
.support-launcher.drawer-open .support-launcher-icon {
  animation: l2g-launcher-morph-in .36s cubic-bezier(.2,.8,.2,1) both; /* один разворот и застываем: не дышим, пока диалог открыт */
}
.support-launcher.drawer-closing .support-launcher-icon {
  /* без задержки: 0-360мс перекрывает большую часть схлопывания круга (120-440мс) и укладывается
     в окно до unmount()-очистки классов кнопки (см. assistant-ui.js, finish() на 440/560мс) */
  animation: l2g-launcher-morph-out .36s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes l2g-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes l2g-icon-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes l2g-launcher-morph-in {
  0%   { transform: rotate(0deg) scale(1); }
  55%  { transform: rotate(300deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}
@keyframes l2g-launcher-morph-out {
  0%   { transform: rotate(0deg) scale(1); }
  45%  { transform: rotate(-300deg) scale(1.1); }
  100% { transform: rotate(-360deg) scale(1); }
}

.support-launcher-icon svg {
  transition: opacity .2s ease, transform .2s cubic-bezier(.2,.8,.2,1);
}
.support-launcher-icon::before,
.support-launcher-icon::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 16px; height: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0;
  transition: opacity .2s ease, transform .2s cubic-bezier(.2,.8,.2,1);
  transform: translate(-50%, -50%) rotate(45deg) scale(.4);
}
.support-launcher-icon::after { transform: translate(-50%, -50%) rotate(-45deg) scale(.4); }

.support-launcher.drawer-open .support-launcher-icon svg {
  transition-duration: .32s;
  opacity: 0;
  transform: rotate(90deg) scale(.4);
}
.support-launcher.drawer-open .support-launcher-icon::before,
.support-launcher.drawer-open .support-launcher-icon::after {
  transition-duration: .32s;
  opacity: 1;
  transform: translate(-50%, -50%) rotate(45deg) scale(1);
}
.support-launcher.drawer-open .support-launcher-icon::after {
  transform: translate(-50%, -50%) rotate(-45deg) scale(1);
}

/* Гало вокруг кнопки, когда появляется новое напоминание (2 цикла ~1с, затем само гаснет) */
.support-launcher.reminder-pulse {
  animation: l2g-halo-pulse 1s ease-out 2;
}
@keyframes l2g-halo-pulse {
  0%   { box-shadow: 0 0 0 0 var(--primary); }
  70%  { box-shadow: 0 0 0 14px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Облачко-подсказка/напоминание рядом с кнопкой ---------- */
.assistant-nudge {
  display: none;
  position: fixed;
  z-index: 46;
  width: max-content;
  max-width: min(300px, calc(100vw - 32px));
  opacity: 0;
  transform: translateY(16px) scale(.96);
  pointer-events: none;
}
.assistant-nudge.mounted { display: block; }
.assistant-nudge.mounted.entering { animation: l2g-nudge-in .42s cubic-bezier(.2,.8,.2,1) both; pointer-events: auto; }
.assistant-nudge.mounted.leaving { animation: l2g-nudge-out .22s cubic-bezier(.2,.8,.2,1) both; pointer-events: none; }

@keyframes l2g-nudge-in {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes l2g-nudge-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(16px) scale(.96); }
}

.assistant-nudge-bubble {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 16px;
  background: linear-gradient(var(--surface), var(--surface)) padding-box,
              linear-gradient(135deg, var(--primary), var(--primary-soft)) border-box;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.42;
  box-shadow: 0 16px 36px rgba(20,10,30,.2);
  cursor: pointer;
  position: relative;
}
.assistant-nudge-bubble:hover,
.assistant-nudge-bubble:focus-visible { box-shadow: 0 16px 36px rgba(20,10,30,.28); }
.assistant-nudge-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 28px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}

.assistant-nudge-avatar {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
}
.assistant-nudge-avatar svg { width: 14px; height: 14px; }
.assistant-nudge-content { min-width: 0; flex: 1; }

.assistant-nudge-typing { display: flex; gap: 3px; align-items: center; height: 16px; }
.assistant-nudge-typing[hidden] { display: none; }
.assistant-nudge-typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-soft);
  opacity: .3;
  animation: l2g-typing-dot 1s ease-in-out infinite;
}
.assistant-nudge-typing i:nth-child(2) { animation-delay: .15s; }
.assistant-nudge-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes l2g-typing-dot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.assistant-nudge-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(20,10,30,.18);
}
.assistant-nudge-close:hover,
.assistant-nudge-close:focus-visible { color: var(--text); border-color: var(--primary); }

.assistant-nudge-cta {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.assistant-nudge-cta:hover { background: var(--primary-strong); }
.assistant-nudge-cta.hidden { display: none; }

/* Мобильная раскладка: карточка на всю ширину минус отступы 16px с обеих сторон */
@media (max-width: 600px) {
  .assistant-nudge {
    max-width: none;
    width: calc(100vw - 32px);
    left: 16px !important;
    right: 16px !important;
  }
}

.assistant-support-offer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  min-width: 0;
  overflow-wrap: anywhere;
}
.assistant-support-offer p { margin: 0 0 8px; font-size: 13px; }
.assistant-support-offer .assistant-support-consent {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-soft);
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}
.assistant-support-offer .btn.assistant-support-send {
  min-height: 44px;
  max-width: 100%;
  white-space: normal;
  text-align: left;
  gap: 8px;
}
.assistant-support-send svg { flex: none; width: 16px; height: 16px; }
.assistant-support-send span { min-width: 0; overflow-wrap: anywhere; }
.assistant-support-send:disabled { opacity: .6; cursor: default; }
.assistant-support-offer .assistant-support-status { display: block; margin-top: 6px; font-size: 12px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.assistant-support-status:empty { display: none; }

/* ---------- prefers-reduced-motion: без разворота кнопки и без задержек ----------
   Общее "длительность .01ms" на анимации/переходы уже стоит глобально (figma-system.css,
   styles.css), сюда попадает и морфинг панели с кругом. Здесь только гасим то, что тот
   общий сброс не трогает: animation-delay у новых анимаций (иначе появление/скрытие
   "зависает" на 120мс перед мгновенным кадром) и сам разворот кнопки (чтобы не мелькал
   даже за .01ms). */
@media (prefers-reduced-motion: reduce) {
  .support-launcher.drawer-open .support-launcher-icon,
  .support-launcher.drawer-closing .support-launcher-icon {
    animation: none;
  }
  .assistant-drawer.mounted.leaving,
  .assistant-drawer.mounted.entering > *:not(.assistant-settings),
  .assistant-drawer.mounted.leaving > *:not(.assistant-settings) {
    animation-delay: 0s;
  }
}
