/* DOGYM.AI — экран ассистента. Палитра и радиусы берутся из web.css,
 * своё здесь только то, чего на сайте ещё не было: лента диалога, композер
 * и типографика Markdown-ответа. Макеты: design/Приветствие.png, design/Ответ ИИ.png. */

.ai {
  --ai-user-bubble: #1668a8;

  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  /* Экран фиксирован по высоте, прокручивается лента внутри панели, а не
   * страница: композер и предупреждение всегда на месте, как в макете. */
  height: calc(100dvh - 130px);
  min-height: 420px;
}

.web-main--ai { align-items: center; padding-bottom: 24px; }

/* ---------- Приветствие ---------- */
.ai__welcome { margin: auto auto 24px; text-align: center; }
.ai__title {
  font-family: var(--web-font-title);
  font-size: 34px; line-height: 1.2; font-weight: 800;
  color: var(--web-text); margin: 0 0 12px;
}
.ai__subtitle { color: var(--web-text-2); font-size: 16px; margin: 0; }

/* ---------- Лента диалога ---------- */
.ai__panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--web-surface);
  border: 1px solid var(--web-border);
  border-radius: var(--web-radius);
  margin-bottom: 16px;
  overflow: hidden;
}
/* display:flex перебивает браузерное [hidden] { display: none } */
.ai__panel[hidden] { display: none; }
.ai__panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--web-border); }
.ai__brand { font-family: var(--web-font-title); font-weight: 800; font-size: 20px; color: var(--web-text); }
.ai__log { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }

.ai__msg { max-width: 100%; font-size: 15px; line-height: 1.6; }
.ai__msg--user {
  align-self: flex-end;
  max-width: 70%;
  background: var(--ai-user-bubble);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--web-radius-md);
  white-space: pre-wrap;
}
.ai__msg--assistant { color: var(--web-text-2); }
.ai__msg--pending { color: var(--web-muted); }
.ai__msg--error { color: var(--web-danger); }

/* Ответ печатается: каретка после последнего дорисованного абзаца текста. */
.ai__msg--streaming .ai__block--generated > :last-child::after {
  content: "▍";
  margin-left: 2px;
  color: var(--web-green);
  animation: ai-caret 1s steps(2, start) infinite;
}
@keyframes ai-caret { to { visibility: hidden; } }

/* Обрыв генерации (docs/ai-chat.md §9): многоточие на месте среза, подпись и
   «Продолжить» под тем, что пришло. */
.ai__msg--interrupted .ai__block--generated > :last-child::after { content: " …"; color: var(--web-muted); }
.ai__interrupted {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px;
  margin-top: 12px; color: var(--web-muted); font-size: 13px;
}
.ai__continue {
  border: 1px solid var(--web-border-strong); border-radius: 999px;
  background: var(--web-surface-2); color: var(--web-text);
  padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer;
}
.ai__continue:hover { border-color: var(--web-green); color: var(--web-green); }

/* Программы каталога под текстом ответа (маркер инструмента, docs/ai-chat.md §5).
 * Селекторы через блок: иначе их перебивают правила Markdown-списков ниже. */
.ai__block--programs:empty { display: none; }
.ai__block--programs .ai__programs {
  list-style: none; margin: 12px 0; padding: 0;
  display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.ai__block--programs .ai__program {
  margin: 0; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--web-surface-2);
  border: 1px solid var(--web-border-strong);
  border-radius: var(--web-radius-sm);
}
.ai__program-title { color: var(--web-text); font-weight: 700; font-size: 16px; line-height: 1.3; }
.ai__program-meta { color: var(--web-green); font-size: 13px; }
.ai__program-description { font-size: 14px; line-height: 1.5; }
.ai__block--programs .ai__program-features { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.ai__block--programs .ai__program-features li {
  margin: 0; padding: 2px 10px; border-radius: 999px;
  background: var(--web-surface-3); color: var(--web-text-2); font-size: 12px;
}
.ai__msg--assistant .ai__programs-survey { display: inline-block; margin-bottom: 10px; text-decoration: none; }

/* Кнопки под ответом по состоянию посетителя (docs/ai-chat.md §14). */
.ai__block--cta:empty { display: none; }
.ai__block--cta { margin-top: 12px; }
.ai__block--cta .ai__offer-text { margin: 0 0 10px; }
.ai__offer-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.ai__msg--assistant .ai__offer-buttons .ai__chip { display: inline-block; text-decoration: none; }

/* Markdown-ответ: заголовки и списки — обязательная часть формата (§14). */
.ai__msg--assistant h1,
.ai__msg--assistant h2,
.ai__msg--assistant h3 {
  font-family: var(--web-font-title);
  color: var(--web-text);
  font-size: 20px; line-height: 1.3; font-weight: 700;
  margin: 24px 0 8px; padding-top: 16px;
  border-top: 1px solid var(--web-border);
}
.ai__msg--assistant > :first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.ai__msg--assistant p { margin: 0 0 10px; }
.ai__msg--assistant ul, .ai__msg--assistant ol { margin: 0 0 10px; padding-left: 22px; }
.ai__msg--assistant li { margin-bottom: 6px; }
.ai__msg--assistant strong { color: var(--web-text); }
.ai__msg--assistant a { color: var(--web-green); }
.ai__msg--assistant code {
  background: var(--web-surface-2); border-radius: 6px; padding: 1px 5px; font-size: 13px;
}
.ai__msg--assistant pre { background: var(--web-surface-2); border-radius: var(--web-radius-sm); padding: 12px; overflow-x: auto; }
.ai__msg--assistant table { border-collapse: collapse; width: 100%; }
.ai__msg--assistant th, .ai__msg--assistant td { border: 1px solid var(--web-border); padding: 6px 10px; text-align: left; }

/* ---------- Композер ---------- */
.ai__composer {
  position: relative;
  display: block;
  background: var(--web-surface-2);
  border: 1px solid var(--web-border-strong);
  border-radius: var(--web-radius);
  /* Снизу — ряд кнопок по макету: «+» слева, отправка справа. */
  padding: 18px 22px 68px;
  /* На приветственном экране auto-поля делят пустоту поровну и держат
   * «приветствие + композер» по центру, а предупреждение — у нижнего края;
   * с открытой лентой её flex:1 съедает свободное место и поля обнуляются. */
  margin-bottom: auto;
}
.ai__label {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.ai__input {
  width: 100%; resize: none; border: 0; background: transparent; outline: none;
  color: var(--web-text); font-family: var(--web-font); font-size: 16px; line-height: 1.5;
}
.ai__input::placeholder { color: var(--web-muted); }
.ai__send {
  position: absolute; right: 16px; bottom: 16px;
  width: 40px; height: 40px; border-radius: 999px; border: 0;
  background: var(--web-surface-3); color: var(--web-text-2);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.ai__send:hover:not(:disabled) { background: var(--web-green); color: #fff; }
.ai__send:disabled { opacity: 0.5; cursor: default; }

/* ---------- Предупреждение об ограничениях (макет «Приветствие») ---------- */
.ai__notice { margin: 16px 0 0; text-align: center; color: var(--web-muted); font-size: 13px; }

/* Чат выключен: строка на месте поля ввода. */
.ai__unavailable {
  margin: 0;
  padding: 18px 22px;
  text-align: center;
  background: var(--web-surface-2);
  border: 1px solid var(--web-border-strong);
  border-radius: var(--web-radius);
}

@media (max-width: 720px) {
  .ai { height: calc(100dvh - 110px); }
  .ai__title { font-size: 24px; }
  .ai__subtitle { font-size: 15px; }
  .ai__log { padding: 16px; }
  .ai__msg--user { max-width: 85%; }
  .ai__composer { padding: 14px 16px 60px; }
  .ai__send { right: 12px; bottom: 12px; width: 36px; height: 36px; }
  .ai__attach { left: 12px; bottom: 12px; width: 36px; height: 36px; }
}

/* ---------- Популярные запросы (макеты «Приветствие», «Популярные запросы») ---------- */
.ai__chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.ai__chip, .ai__popular-open {
  border: 1px solid; border-radius: 999px; background: transparent;
  font-family: var(--web-font); font-size: 14px; cursor: pointer;
}
.ai__chip { border-color: var(--web-green); color: var(--web-green); line-height: 1.3; padding: 7px 14px; text-align: left; }
.ai__chip:hover { background: var(--web-selected); }
/* На приветствии чипы стоят под композером и забирают его auto-поле себе:
 * группа «приветствие + композер + чипы» остаётся по центру, как в макете. */
.ai__composer:has(+ .ai__chips--welcome) { margin-bottom: 0; }
.ai__chips--welcome { margin: 16px 0 auto; }
.ai__welcome[hidden] ~ .ai__chips--welcome { display: none; }

.ai__popular-open { border-color: var(--web-border-strong); color: var(--web-text); padding: 8px 16px; white-space: nowrap; }
.ai__popular-open:hover { background: var(--web-surface-2); }

.ai__panel-actions { display: flex; align-items: center; gap: 8px; }
.ai__clear {
  border: 0; border-radius: 999px; background: var(--web-surface-3); color: var(--web-text);
  font-family: var(--web-font); font-size: 14px; padding: 8px 16px; white-space: nowrap; cursor: pointer;
}
.ai__clear:hover:not(:disabled) { background: var(--web-surface-2); }
.ai__clear:disabled { opacity: 0.5; cursor: default; }
.ai__popular {
  margin: 0 16px 16px; padding: 16px 20px;
  border: 1px solid var(--web-border-strong); border-radius: var(--web-radius);
}
.ai__popular-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; color: var(--web-text); font-size: 16px; }
.ai__popular-close {
  margin-left: auto; width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent;
  color: var(--web-text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.ai__popular-close:hover { background: var(--web-surface-2); }

@media (max-width: 720px) {
  .ai__chip, .ai__popular-open { font-size: 13px; padding: 6px 12px; }
  .ai__popular { margin: 0 12px 12px; padding: 14px 16px; }
}

/* ---------- Файлы к вопросу (макет «Написание в чат - текст+картинка+файлы») ---------- */
.ai__attach {
  position: absolute; left: 16px; bottom: 16px;
  width: 40px; height: 40px; border-radius: 999px; border: 0;
  background: transparent; color: var(--web-text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.ai__attach:hover:not(:disabled) { background: var(--web-surface-3); }
.ai__attach:disabled { opacity: 0.5; cursor: default; }
.ai__attach-locked { margin: 8px 0 0; color: var(--web-text-2); font-size: 13px; }
.ai__attach-locked a { color: var(--web-green); }
.ai__attach-error { margin: 0 0 10px; color: var(--web-danger); font-size: 13px; white-space: pre-line; }

.ai__files { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
/* display:flex перебивает браузерное [hidden] { display: none } */
.ai__files[hidden] { display: none; }
.ai__file {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  height: 64px; max-width: 260px; padding: 0 34px 0 14px;
  background: var(--web-surface);
  border: 1px solid var(--web-border-strong);
  border-radius: var(--web-radius-sm);
}
.ai__file-icon { flex: none; display: block; }
.ai__file-icon--document {
  width: 22px; height: 28px; border-radius: 3px; background: #2f8fef;
  clip-path: polygon(0 0, 68% 0, 100% 26%, 100% 100%, 0 100%);
}
/* Миниатюра фото, а без самого файла (после перезагрузки) — зелёная плашка. */
.ai__file-icon--image { width: 40px; height: 40px; border-radius: 6px; background: var(--web-green); object-fit: cover; }
.ai__file-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ai__file-name { color: var(--web-text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai__file-meta { color: var(--web-muted); font-size: 12px; }
.ai__file-remove {
  position: absolute; top: 5px; right: 5px;
  width: 20px; height: 20px; border: 0; border-radius: 50%;
  background: var(--web-text); color: var(--web-surface);
  font-size: 14px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
/* В ленте файлы стоят над вопросом, у правого края, как и он. */
.ai__msg-files { align-self: flex-end; max-width: 70%; }
.ai__msg-files .ai__files { margin: 0; justify-content: flex-end; }
