/* ==========================================================================
   Ассистент студии — интерфейс чата.
   Подключается после styles.css и использует его токены (цвета, радиусы, шрифты),
   поэтому отдельной палитры здесь нет: всё наследуется от основной темы.
   ========================================================================== */

.chat { position: relative; z-index: 135; }

/* --- Кнопка запуска ------------------------------------------------------ */
.chat__launcher {
  position: fixed;
  z-index: 135;
  right: var(--gutter);
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 52px;
  padding: 12px 18px;
  border: 1px solid rgba(200, 255, 77, 0.45);
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), #a8f03a);
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 16px 40px -18px rgba(200, 255, 77, 0.75);
  transition: transform 0.2s var(--ease), box-shadow 0.25s var(--ease);
}
.chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 20px 46px -18px rgba(200, 255, 77, 0.9); }
.chat__launcher:active { transform: translateY(0) scale(0.99); }
.chat__launcher-icon { display: grid; place-items: center; }
.chat__launcher-text { white-space: nowrap; }

/* Кнопка «наверх» уступает место ассистенту, когда тот подключился */
html.chat-ready .to-top { right: calc(var(--gutter) + 64px); }

/* Пока на экране мини-форма первого экрана, ассистент не мешает главному CTA.
   visibility переключаем с задержкой, чтобы кнопка не ловила фокус с клавиатуры. */
.chat--aside .chat__launcher,
.chat--aside .chat__teaser {
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0s linear 0.25s;
}

/* --- Подсказка ----------------------------------------------------------- */
.chat__teaser {
  position: fixed;
  z-index: 134;
  right: var(--gutter);
  bottom: calc(146px + env(safe-area-inset-bottom));
  width: min(260px, calc(100vw - 2 * var(--gutter)));
  padding: 14px 34px 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  animation: chatTeaser 0.5s var(--ease-out) both;
}
.chat__teaser-close {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.chat__teaser-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
@keyframes chatTeaser { from { opacity: 0; transform: translateY(10px); } }

/* --- Панель диалога ------------------------------------------------------ */
.chat__panel {
  position: fixed;
  z-index: 140;
  right: var(--gutter);
  bottom: calc(148px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100vw - 2 * var(--gutter)));
  height: min(560px, calc(100dvh - 220px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.95);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.99);
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}
.chat__panel.is-visible { opacity: 1; transform: none; }

.chat__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 14px 13px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(200, 255, 77, 0.07), transparent);
}
.chat__avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-weight: 700;
}
.chat__head-text { display: grid; gap: 2px; min-width: 0; }
.chat__title { font-family: var(--font-display); font-size: 0.95rem; font-weight: 600; line-height: 1.2; }
.chat__status { font-size: var(--fs-xs); color: var(--text-dim); }
.chat__close {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.chat__close:hover { color: var(--text); border-color: var(--line-strong); }

.chat__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.chat__msg { display: flex; flex-direction: column; gap: 8px; max-width: 92%; }
.chat__msg--bot { align-self: flex-start; }
.chat__msg--user { align-self: flex-end; align-items: flex-end; }
.chat__msg--typing { max-width: 60px; }

.chat__bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: var(--fs-sm);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat__msg--bot .chat__bubble {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--text);
}
.chat__msg--user .chat__bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 5px;
  font-weight: 600;
}

.chat__chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chat__chip {
  padding: 7px 13px;
  border: 1px solid rgba(200, 255, 77, 0.4);
  border-radius: 999px;
  background: rgba(200, 255, 77, 0.07);
  color: var(--accent);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease);
}
.chat__chip:hover { background: var(--accent); color: var(--accent-ink); }

.chat__dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: chatDot 1.1s var(--ease) infinite;
}
.chat__dot:nth-child(2) { animation-delay: 0.15s; }
.chat__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatDot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 12px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(8, 9, 13, 0.6);
}
.chat__input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(8, 9, 13, 0.75);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16 px — iOS не зумит страницу при фокусе */
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
}
.chat__input::placeholder { color: var(--text-dim); }
.chat__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200, 255, 77, 0.16); }
.chat__send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform 0.18s var(--ease), opacity 0.18s var(--ease);
}
.chat__send:hover { transform: translateY(-1px); }
.chat__send:active { transform: scale(0.98); }

.chat__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Планшеты и десктоп -------------------------------------------------- */
@media (min-width: 1024px) {
  .chat__launcher { bottom: 28px; }
  .chat__teaser { bottom: 92px; }
  .chat__panel { bottom: 94px; }
  html.chat-ready .to-top { right: calc(var(--gutter) + 66px); }
}

/* --- Телефоны: чат раскрывается на весь экран ---------------------------- */
@media (max-width: 640px) {
  .chat__panel {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform: translateY(16px);
  }
  .chat__launcher-text { display: none; }
  .chat__launcher { padding: 14px; min-width: 54px; justify-content: center; }
  .chat__teaser { bottom: calc(146px + env(safe-area-inset-bottom)); }
}

/* Ассистент не мешает, когда открыт чат на мобильном */
html.chat-open .mobile-bar { display: none; }

@media (prefers-reduced-motion: reduce) {
  .chat__panel { transform: none; }
  .chat__dot { animation: none; opacity: 0.7; }
}
