/* ============================================
   CSS ПЕРЕМЕННЫЕ - ЛЕГКАЯ НАСТРОЙКА ТЕМЫ
   ============================================ */
:root {
  /* Основные цвета */
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --primary-gradient: linear-gradient(135deg, #007bff, #0056b3);
  
  /* Сообщения */
  --bubble-user-bg: #007bff;
  --bubble-user-text: #ffffff;
  --bubble-other-bg: #f1f3f5;
  --bubble-other-text: #1e293b;
  
  /* Размеры */
  --bubble-radius: 16px;
  --message-spacing: 8px;
  --avatar-size: 32px;
  
  /* Тени и фон */
  --shadow-color: rgba(0,0,0,0.08);
  --bg-messages: #f8f9fa;
  --bg-chat: #ffffff;
}

/* ============================================
   ОСНОВНЫЕ СТИЛИ ВИДЖЕТА
   ============================================ */

/* Кнопка открытия чата */
.chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: white;
  border: none;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 20px rgba(0,123,255,0.4);
}

.chat-toggle:active {
  transform: scale(0.95);
}

/* Окно чата */
.chat-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 550px;
  background: var(--bg-chat);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  z-index: 9998;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.05);
}

/* Хедер чата */
.chat-header {
  padding: 16px 20px;
  background: var(--primary-gradient);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  cursor: move;
  user-select: none;
}

.chat-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.3px;
}

.chat-close {
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 5px;
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.2s;
}

.chat-close:hover {
  opacity: 1;
  transform: rotate(90deg);
}

/* Контейнер сообщений */
.chat-messages {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--bg-messages);
  min-height: 0;
}

/* Стилизация скролла */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #c1c7cd;
  border-radius: 2px;
}

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

/* Приветственное сообщение */
.chat-welcome {
  text-align: center;
  color: #6c757d;
  padding: 30px 20px;
  font-size: 14px;
  opacity: 0.8;
}

/* ============================================
   СОВРЕМЕННЫЕ СООБЩЕНИЯ (ОСНОВНЫЕ СТИЛИ)
   ============================================ */

.chat-message {
  margin-bottom: var(--message-spacing);
  display: flex;
  animation: fadeIn 0.2s ease;
}

/* Свои сообщения — справа */
.chat-message.own {
  justify-content: flex-end;
}

/* Чужие — слева */
.chat-message.other {
  justify-content: flex-start;
}

/* Анимация появления */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   ПУЗЫРЬКИ СООБЩЕНИЙ
   ============================================ */

.chat-message-bubble {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: var(--bubble-radius);
  position: relative;
  word-wrap: break-word;
  transition: all 0.2s ease;
}

/* Стиль для своих сообщений */
.chat-message.own .chat-message-bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,123,255,0.15);
}

/* Стиль для чужих сообщений */
.chat-message.other .chat-message-bubble {
  background: var(--bubble-other-bg);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px var(--shadow-color);
}

/* ============================================
   КОНТЕНТ СООБЩЕНИЙ
   ============================================ */

/* Имя пользователя — только для чужих сообщений */
.chat-message-name {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 3px;
  display: block;
  letter-spacing: 0.2px;
}

.chat-message.other .chat-message-name {
  color: #6c757d;
}

.chat-message.own .chat-message-name {
  display: none;
}

/* Текст сообщения */
.chat-message-text {
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

/* Время */
.chat-message-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
  text-align: right;
  letter-spacing: 0.2px;
}

.chat-message.own .chat-message-time {
  color: rgba(255,255,255,0.75);
}

.chat-message.other .chat-message-time {
  color: #6c757d;
}

/* ============================================
   АВАТАРЫ (опционально)
   ============================================ */

.chat-message-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  user-select: none;
  margin-right: 10px;
}

.chat-message.own .chat-message-avatar {
  display: none;
}

.chat-message.other .chat-message-avatar {
  display: flex;
}

/* ============================================
   СИСТЕМНЫЕ СООБЩЕНИЯ
   ============================================ */

.chat-system-message {
  text-align: center;
  color: #6c757d;
  font-style: italic;
  padding: 6px 14px;
  font-size: 12px;
  background: #e9ecef;
  border-radius: 20px;
  margin: 8px auto;
  max-width: 80%;
  display: inline-block;
  width: auto;
  animation: fadeIn 0.3s ease;
}

/* ============================================
   ОБЛАСТЬ ВВОДА
   ============================================ */

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-chat);
  align-items: center;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e9ecef;
  border-radius: 24px;
  outline: none;
  font-size: 14px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  background: #f8f9fa;
}

.chat-input-area input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

.chat-input-area input::placeholder {
  color: #adb5bd;
}

.chat-input-area button {
  padding: 10px 24px;
  background: var(--primary-gradient);
  color: white;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.chat-input-area button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,123,255,0.3);
}

.chat-input-area button:active {
  transform: scale(0.95);
}

/* ============================================
   СТАТУС ОНЛАЙН (индикатор)
   ============================================ */

.chat-online-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: 20px;
}

.chat-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #28a745;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

/* ============================================
   АДАПТИВНОСТЬ ДЛЯ МОБИЛЬНЫХ
   ============================================ */

@media (max-width: 480px) {
  .chat-window {
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    max-height: 100vh;
    max-width: 100vw;
  }
  
  .chat-header {
    border-radius: 0;
    padding: 14px 16px;
  }
  
  .chat-input-area {
    border-radius: 0;
    padding: 10px 12px;
  }
  
  .chat-toggle {
    bottom: 15px;
    right: 15px;
    width: 50px;
    height: 50px;
    font-size: 24px;
  }
  
  .chat-messages {
    padding: 12px 14px;
  }
  
  .chat-message-bubble {
    max-width: 88%;
    padding: 8px 12px;
  }
}

/* ============================================
   ДОПОЛНИТЕЛЬНЫЕ УЛУЧШЕНИЯ
   ============================================ */

/* Ссылки в сообщениях */
.chat-message-text a {
  color: inherit;
  text-decoration: underline;
  opacity: 0.9;
}

.chat-message.own .chat-message-text a {
  color: #ffffff;
}

.chat-message.other .chat-message-text a {
  color: var(--primary-color);
}

/* Разделитель даты */
.chat-date-divider {
  text-align: center;
  color: #6c757d;
  font-size: 11px;
  margin: 16px 0 12px;
  position: relative;
}

.chat-date-divider::before {
  content: '';
  position: absolute;
  left: 20%;
  right: 20%;
  top: 50%;
  height: 1px;
  background: #dee2e6;
}

.chat-date-divider span {
  background: var(--bg-messages);
  padding: 0 12px;
  position: relative;
  z-index: 1;
}