/* Чат-виджет */
.ai-chat-widget {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 9999;
  font-family: "Inter", sans-serif;
}

.ai-chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  border: none;
  box-shadow: 0 8px 20px rgba(79, 172, 254, 0.4);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
}

.ai-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 30px rgba(79, 172, 254, 0.5);
}

.ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  height: 500px;
  max-width: 90vw;
  max-height: 80vh;
  background: #1a1f2e;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.ai-chat-window.active {
  display: flex;
}

.ai-chat-window.maximized {
  position: fixed;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 70vw !important;
  height: 70vh !important;
  max-width: 90vw !important;
  max-height: 90vh !important;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  bottom: auto !important;
  right: auto !important;
}

.ai-chat-header {
  padding: 16px 20px;
  background: #232838;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.ai-chat-header-title {
  font-weight: 600;
  color: #ffffff;
  font-size: 16px;
}

.ai-chat-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== КОРЗИНА ===== */
.ai-chat-clear {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
  margin-right: 12px;
}

.ai-chat-clear:hover {
  color: #ff6b6b;
}

/* ===== КНОПКА МЕНЮ В ШАПКЕ ===== */
.ai-chat-menu-btn-header {
  background: rgba(131, 253, 130, 0.12);
  border: 1px solid rgba(131, 253, 130, 0.25);
  color: #83fd82;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1.4;
  touch-action: manipulation;
}

.ai-chat-menu-btn-header:hover {
  background: rgba(131, 253, 130, 0.2);
  border-color: rgba(131, 253, 130, 0.4);
}

.ai-chat-maximize,
.ai-chat-close {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  line-height: 1;
  transition: color 0.2s;
}

.ai-chat-maximize:hover,
.ai-chat-close:hover {
  color: #ffffff;
}

.ai-chat-window:not(.maximized)::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  cursor: nw-resize;
  background: transparent;
  z-index: 10;
}

.ai-chat-messages {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #1a1f2e;
  -webkit-overflow-scrolling: touch;
}

/* ===== СТИЛИЗОВАННЫЙ СКРОЛЛБАР ===== */
.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: #1a1f2e;
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #2d3446;
  border-radius: 3px;
  transition: background 0.3s;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #3d4456;
}

.ai-chat-messages {
  scrollbar-width: thin;
  scrollbar-color: #2d3446 #1a1f2e;
}

/* ===== ОСНОВНЫЕ СТИЛИ СООБЩЕНИЙ ===== */
.ai-chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-chat-message.user {
  align-self: flex-end;
  background: #7ce6fe;
  color: #0b0f1c;
  max-width: 85%;
  word-break: break-word;
  overflow-wrap: break-word;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  border-radius: 12px 12px 4px 12px;
}

.ai-chat-message.assistant {
  align-self: flex-start;
  background: #232838;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  max-width: 85%;
  word-break: break-word;
  overflow-wrap: break-word;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  border-radius: 12px 12px 12px 4px;
}

/* ===== HTML-ТЕГИ В СООБЩЕНИЯХ ===== */
.ai-chat-message.assistant strong {
  color: #83fd82;
  font-weight: 600;
}

.ai-chat-message.assistant ul,
.ai-chat-message.assistant ol {
  padding-left: 20px;
  margin: 4px 0;
  list-style: disc;
}

.ai-chat-message.assistant li {
  margin-bottom: 2px;
  display: list-item;
  list-style: disc;
}

.ai-chat-message.assistant br {
  display: block;
  content: "";
  margin: 2px 0;
}

.ai-chat-message.assistant table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.ai-chat-message.assistant th {
  background: #2d3446;
  color: #ffffff;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: left;
}

.ai-chat-message.assistant td {
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.ai-chat-message.assistant a {
  color: #4facfe;
  text-decoration: underline;
  word-break: break-all;
  transition: color 0.2s;
}

.ai-chat-message.assistant a:hover {
  color: #00f2fe;
  text-decoration: none;
}

.ai-chat-message.assistant img {
  max-width: 180px;
  max-height: 180px;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  display: block;
  border: 1px solid #e9edf2;
  padding: 8px;
  background: #ffffff;
}

/* ===== ИНДИКАТОР НАБОРА ===== */
.ai-chat-message .typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.ai-chat-message .typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #83fd82;
  display: inline-block;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.ai-chat-message .typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-chat-message .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-message .typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* ===== ВВОД ===== */
.ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  background: #232838;
}

.ai-chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1a1f2e;
  color: #ffffff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s;
}

.ai-chat-input:focus {
  border-color: #4facfe;
}

.ai-chat-input::placeholder {
  color: #6c7a8a;
}

.ai-chat-send {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: #0b0f1c;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.ai-chat-send:hover {
  transform: scale(1.02);
}

.ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== КНОПКА МЕНЮ ПОД ОТВЕТОМ ===== */
/* ===== КНОПКА МЕНЮ ПОД ОТВЕТОМ (ВСЕГДА СЛЕВА) ===== */
.ai-chat-menu-btn-reply {
    display: block !important;
    text-align: left !important;
    margin-top: 6px !important;
    margin-right: auto !important;
    margin-left: 0 !important;
    width: fit-content !important;
    background: rgba(131, 253, 130, 0.1);
    border: 1px solid rgba(131, 253, 130, 0.2);
    color: #83fd82;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 3px 12px;
    border-radius: 12px;
    transition: all 0.2s;
    line-height: 1.6;
    touch-action: manipulation;
}

.ai-chat-menu-btn-reply:hover {
    background: rgba(131, 253, 130, 0.2);
    border-color: rgba(131, 253, 130, 0.4);
    transform: scale(1.02);
}

.ai-chat-menu-btn-reply:active {
    transform: scale(0.97);
}

/* ===== МОДАЛЬНОЕ ОКНО ===== */
.ai-chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999999;
  animation: modalFadeIn 0.25s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.ai-chat-modal-content {
  background: #1a1f2e;
  border-radius: 16px;
  padding: 20px 24px 24px 24px;
  max-width: 460px;
  width: 92%;
  max-height: 65vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  border: 1px solid #2a3040;
  -webkit-overflow-scrolling: touch;
}

.ai-chat-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
}

.ai-chat-modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
  touch-action: manipulation;
}

.ai-chat-modal-close:hover {
  color: #fff;
}

.ai-question-card {
  background: #232838;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 8px;
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  font-size: 14px;
  border: 1px solid transparent;
  touch-action: manipulation;
}

.ai-question-card:hover {
  background: #2d3348;
  border-color: #3a4058;
}

.ai-question-card:active {
  transform: scale(0.98);
}

/* ============================================================
   МОБИЛЬНАЯ АДАПТАЦИЯ (640px и меньше)
   ============================================================ */
@media (max-width: 640px) {
  .ai-chat-widget {
    bottom: 0;
    right: 0;
  }

  .ai-chat-toggle {
    width: 56px;
    height: 56px;
    font-size: 24px;
    position: fixed;
    bottom: 20px;
    right: 20px;
  }

  .ai-chat-window {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  .ai-chat-w