/**
 * ИИ-консультант на главной: блок, лог сообщений, поле ввода, микрофон.
 * Использует переменные бренда из style.css (--brand-main-color: #FF7D01).
 */

.ai-chat-section {
  padding: 24px 0 56px;
}

.ai-chat {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 30px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
  padding: 28px 28px 22px;
}

/* ── Шапка ─────────────────────────────────────────────────────────── */
.ai-chat__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.ai-chat__title {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.26;
  color: var(--main-text-color, #1c1c1c);
}

.ai-chat__subtitle {
  margin: 0;
  max-width: 640px;
  font-size: 15px;
  line-height: 1.5;
  color: #666;
}

.ai-chat__voice {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 1px solid #eee;
  border-radius: 1000px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.ai-chat__voice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ai-chat__voice-box {
  width: 18px;
  height: 18px;
  border: 1.5px solid #d7d7d7;
  border-radius: 4px;
  background: #fff;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.ai-chat__voice-box::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background 0.15s;
}

.ai-chat__voice input:checked + .ai-chat__voice-box {
  border-color: var(--brand-main-color, #ff7d01);
}

.ai-chat__voice input:checked + .ai-chat__voice-box::after {
  background: var(--brand-main-color, #ff7d01);
}

.ai-chat__voice input:focus-visible + .ai-chat__voice-box {
  outline: 2px solid var(--brand-main-color, #ff7d01);
  outline-offset: 2px;
}

.ai-chat__voice-text {
  font-size: 14px;
  color: #333;
}

/* ── Лог сообщений ─────────────────────────────────────────────────── */
.ai-chat__log {
  max-height: 420px;
  min-height: 110px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 4px 4px 0;
  scrollbar-width: thin;
}

.ai-chat__msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 86%;
}

.ai-chat__msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-chat__msg--ai {
  align-self: flex-start;
}

.ai-chat__avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 125, 1, 0.12);
  color: var(--brand-main-color, #ff7d01);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat__bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f7f7;
  color: var(--main-text-color, #1c1c1c);
}

.ai-chat__msg--user .ai-chat__bubble {
  background: var(--brand-main-color, #ff7d01);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.ai-chat__msg--ai .ai-chat__bubble {
  border-bottom-left-radius: 6px;
}

.ai-chat__bubble--typing {
  color: #999;
  letter-spacing: 2px;
}

.ai-chat__bubble--error {
  background: #fdecef;
  color: #b31241;
}

/* ── Форма ─────────────────────────────────────────────────────────── */
.ai-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding: 8px 8px 8px 10px;
  border: 1px solid #e6e6e6;
  border-radius: 24px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-chat__form:focus-within {
  border-color: var(--brand-main-color, #ff7d01);
  box-shadow: 0 0 0 3px rgba(255, 125, 1, 0.1);
}

.ai-chat__input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 140px;
  padding: 9px 4px;
  border: 0;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--main-text-color, #1c1c1c);
  background: transparent;
}

.ai-chat__input::placeholder {
  color: #9b9b9b;
}

/* Одна кнопка на два режима: микрофон (поле пустое) и отправка (есть текст).
   Сброс каскада портала: в style.css есть глобальное
   `[type="submit"] { width: 100%; padding-right: 50px; border-radius: 1000px }`.
   При box-sizing: border-box оно сжимало круглые кнопки 42×42 до нуля
   (SVG получал width: 0). Селектор с .ai-chat__form специфичнее атрибутного. */
.ai-chat__form .ai-chat__action {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: var(--brand-main-color, #ff7d01);
  transition: background 0.15s, transform 0.15s;
}

.ai-chat__form .ai-chat__action:hover:not(:disabled) {
  background: #e67000;
}

.ai-chat__form .ai-chat__action svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

/* В режиме микрофона показываем только микрофон, в режиме отправки — только
   стрелку. Именно display: none, а не прозрачность: у скрытой иконки не
   должно быть ни места в раскладке, ни возможности получить клик. */
.ai-chat__action .ai-chat__icon-send { display: none; }
.ai-chat__action.is-send .ai-chat__icon-mic { display: none; }
.ai-chat__action.is-send .ai-chat__icon-send { display: block; }

/* Запись идёт прямо сейчас — пульсирующее кольцо, цвет бренда сохраняем. */
.ai-chat__action.is-recording {
  animation: ai-chat-pulse 1.1s ease-in-out infinite;
}

@keyframes ai-chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 125, 1, 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(255, 125, 1, 0); }
}

.ai-chat__action:disabled,
.ai-chat__input:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ── Статус ────────────────────────────────────────────────────────── */
.ai-chat__status {
  min-height: 20px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.4;
  color: #666;
}

.ai-chat__status--active { color: var(--brand-main-color, #ff7d01); }
.ai-chat__status--error { color: #e11d48; }

/* ── Адаптив ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .ai-chat__head {
    flex-direction: column;
    gap: 14px;
  }

  .ai-chat__msg {
    max-width: 100%;
  }
}

@media (max-width: 720px) {
  .ai-chat-section {
    padding: 16px 0 40px;
  }

  .ai-chat {
    padding: 20px 16px 16px;
    border-radius: 22px;
  }

  .ai-chat__title {
    font-size: 21px;
  }

  .ai-chat__log {
    max-height: 340px;
  }

  .ai-chat__bubble {
    font-size: 14px;
    padding: 10px 13px;
  }

  .ai-chat__form {
    padding: 6px;
    border-radius: 20px;
  }

  .ai-chat__form .ai-chat__action {
    width: 38px;
    height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat__action.is-recording { animation: none; }
  .ai-chat__action,
  .ai-chat__form { transition: none; }
}
