/* ===== AI CHAT WIDGET ===== */

/* Кнопка открытия */
.chat-toggle {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e63946, #c1121f);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(230,57,70,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(230,57,70,0.5);
}
.chat-toggle svg { flex-shrink: 0; }

/* Бейдж непрочитанных */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #1d3557;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.chat-badge.show { opacity: 1; }

/* Окно чата */
.chat-window {
  position: fixed;
  bottom: 96px;
  right: 30px;
  width: 360px;
  max-height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}
.chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  visibility: visible;
}

/* Шапка */
.chat-header {
  background: linear-gradient(135deg, #1d3557, #2a4a7f);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-info strong { display: block; font-size: 15px; font-weight: 700; }
.chat-header-info span { font-size: 12px; opacity: 0.75; }
.chat-status-dot {
  width: 8px; height: 8px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.chat-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.2s;
}
.chat-close:hover { color: #fff; }

/* Сообщения */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #dee2e6; border-radius: 2px; }

/* Сообщение */
.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: msg-in 0.2s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.chat-msg.user {
  flex-direction: row-reverse;
}
/* Обёртка пузыря */
.chat-msg > div:last-child {
  min-width: 0;
  max-width: 82%;
}
/* Аватар только у бота */
.chat-msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #1d3557;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.chat-msg.user .chat-msg-avatar {
  display: none;
}
.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  color: #2d2d2d;
  background: #f1f3f5;
  border-bottom-left-radius: 4px;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.user .chat-msg-bubble {
  background: #e63946;
  color: #fff;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}
.chat-msg-time {
  font-size: 10px;
  color: #adb5bd;
  margin-top: 4px;
}
.chat-msg.user .chat-msg-time {
  text-align: right;
}

/* Индикатор печатания */
.chat-typing .chat-msg-bubble {
  display: flex; gap: 4px; align-items: center;
  padding: 12px 16px;
}
.chat-typing .dot {
  width: 7px; height: 7px;
  background: #adb5bd;
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Быстрые вопросы */
.chat-quick {
  padding: 0 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.chat-quick-btn {
  background: #f1f3f5;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: #1d3557;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.chat-quick-btn:hover {
  background: #e63946;
  border-color: #e63946;
  color: #fff;
}

/* Поле ввода */
.chat-input-wrap {
  padding: 12px 16px;
  border-top: 1px solid #f1f3f5;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  border: 1.5px solid #dee2e6;
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s;
  overflow-y: auto;
}
.chat-input:focus { border-color: #e63946; }
.chat-send {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #e63946;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.2s;
}
.chat-send:hover { background: #c1121f; transform: scale(1.05); }
.chat-send:disabled { background: #dee2e6; cursor: not-allowed; transform: none; }

/* Мобильная адаптация */
@media (max-width: 480px) {
  .chat-window {
    width: calc(100vw - 20px);
    right: 10px;
    bottom: 80px;
    max-height: 70vh;
  }
  .chat-toggle { right: 20px; bottom: 20px; width: 48px; height: 48px; }
}
