/* Обновляем цвета под фирменный стиль Mooncharm */
:root {
  --mooncharm-black: #222;
  --mooncharm-white: #fff;
  --mooncharm-gray: #f5f5f5;
  --mooncharm-border: #e0e0e0;
  --mooncharm-text: #333;
  --mooncharm-text-light: #666;
}

/* Основной контейнер кнопки чата */
.chat-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: #222;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.chat-button:hover {
  background: #444;
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.chat-button.active {
  background: #000;
  transform: scale(0.95);
}

/* Основное окно чата */
.chat-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 420px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
  transition: all 0.3s ease;
}

.chat-window.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  visibility: hidden;
}

/* Заголовок чата */
.chat-header {
  background: #222;
  color: white;
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid #333;
}

.chat-title {
  display: flex;
  align-items: center;
}

.chat-title svg {
  margin-right: 8px;
  color: white;
}

.chat-title h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: white;
}

.close-chat {
  background: transparent;
  color: white;
  border: none;
  width: 30px;
  height: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  transition: background 0.2s;
}

.close-chat:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Контейнер сообщений */
.chat-messages {
  height: 400px;
  overflow-y: auto;
  padding: 12px 7px;
  flex-grow: 1;
  background-color: white;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: #999 transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: #999;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-track {
  background-color: transparent;
}

/* Сообщения */
.message {
  padding: 6px;
  max-width: 85%;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
  opacity: 0; /* Начальное состояние */
  animation: messageAppear 0.3s ease-out forwards;
}

.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message.bot {
  margin-right: auto;
}

.message-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background-color: transparent;
  color: white;
  margin-left: 8px;
  display: none;
}

.message.bot .message-avatar {
  background-color: #222;
  color: white;
  margin-right: 8px;
}

.message-content {
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message.user .message-content {
  background-color: #222;
  color: white;
  border-bottom-right-radius: 4px;
}

.message.bot .message-content {
  background-color: #f1f1f1;
  color: #333;
  border-bottom-left-radius: 4px;
  border-left: none;
  box-shadow: none;
  padding-top: 12px;
}

/* Добавим метку для ясности */
.message-content::before {
  display: none;
}

.message-text {
  font-size: 14px;
  display: block;
  margin-top: 0;
}

@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Добавляем задержку анимации для разных сообщений */
.chat-messages .message:nth-child(1) { animation-delay: 0.05s; }
.chat-messages .message:nth-child(2) { animation-delay: 0.1s; }
.chat-messages .message:nth-child(3) { animation-delay: 0.15s; }
.chat-messages .message:nth-child(4) { animation-delay: 0.2s; }
.chat-messages .message:nth-child(5) { animation-delay: 0.25s; }
.chat-messages .message:nth-child(6) { animation-delay: 0.3s; }
.chat-messages .message:nth-child(7) { animation-delay: 0.35s; }
.chat-messages .message:nth-child(n+8) { animation-delay: 0.4s; }

/* Индикатор загрузки */
.loading-indicator {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  margin: 10px 0;
  font-size: 14px;
  font-style: italic;
  color: #666;
  background-color: #f5f5f5;
  border-radius: 15px;
  max-width: 80%;
  animation: messageAppear 0.5s ease;
}

/* Анимация загрузки */
.loading-dots {
  display: inline-flex;
}

.loading-signature {
  margin-left: 10px;
  font-size: 12px;
  opacity: 0.7;
}

.loading-dots span {
  animation: loadingDots 1.4s infinite;
  font-size: 20px;
  line-height: 10px;
  height: 10px;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes loadingDots {
  0%, 100% {
    opacity: 0.2;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-5px);
  }
}

/* Курсор при печатании текста */
.typing-cursor {
  display: inline-block;
  width: 3px;
  height: 15px;
  background-color: #666;
  margin-left: 2px;
  animation: blinkCursor 0.7s infinite;
}

@keyframes blinkCursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.typing::after {
  content: '|';
  animation: cursor 1s infinite;
  font-weight: normal;
  display: inline-block;
}

@keyframes cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Поле ввода */
.chat-input {
  display: flex;
  padding: 8px 12px;
  border-top: 1px solid #e0e0e0;
  background: white;
}

.chat-input input {
  flex-grow: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 14px;
  outline: none; /* Убираем дефолтный outline */
  transition: border-color 0.2s, box-shadow 0.2s;
  background-color: #f5f5f5;
  -webkit-appearance: none; /* Убираем стандартные стили браузера */
  -moz-appearance: none;
  appearance: none;
}

.chat-input input:focus {
  border-color: #222;
  background-color: white;
  box-shadow: 0 0 0 1px #222;
  outline: none !important; /* Принудительно убираем outline */
  outline-color: #222 !important; /* Устанавливаем цвет обводки на всякий случай */
}

.send-message {
  width: 36px;
  height: 36px;
  margin-left: 8px;
  background: #222;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.send-message:hover {
  background: #444;
  transform: scale(1.05);
}

/* Устанавливаем черную обводку для всех элементов ввода при фокусе в чате */
.chat-window *:focus,
.chat-window *:focus-visible,
.chat-window input:focus,
.chat-window input:focus-visible {
  outline-color: #222 !important;
  outline-width: 1px !important;
  box-shadow: 0 0 0 1px #222 !important;
  border-color: #222 !important;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 767px) {
  .chat-window {
    width: calc(100% - 40px);
    bottom: 80px;
  }
  
  .chat-messages {
    height: 300px;
  }
}