:root {
  --ai-chat-primary: #8ec047;
  --ai-chat-primary-hover: #7ba837;
  --ai-chat-bg: #ffffff;
  --ai-chat-text: #2c3e50;
  --ai-chat-gray-bg: #f5f7f8;
  --ai-chat-border: #e2e8f0;
  --ai-chat-radius: 18px;
  --ai-chat-shadow: 0 12px 35px rgba(0, 0, 0, 0.15);
}

/* Плавающий контейнер */
.ai-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ai-chat-text);
}

/* Кнопка открытия виджета */
.ai-chat-trigger-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background-color: rgba(138, 180, 70);
  background: linear-gradient(135deg, var(--ai-chat-primary), #73a532);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s, all 0.05s;
  filter: drop-shadow(4px 6px 2px rgba(0, 0, 0, 0.25));
}

.ai-chat-trigger-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 22px rgba(115, 165, 50, 0.5);
}

.ai-chat-trigger-btn svg.ai-chat-icon-open {
  width: 75px;
  height: 75px;
}

.ai-chat-trigger-btn svg.ai-chat-icon-close {
  width: 30px;
  height: 30px;
}

.ai-chat-trigger-btn .ai-chat-icon-close {
  display: none;
}

.ai-chat-widget.ai-chat-is-open .ai-chat-trigger-btn .ai-chat-icon-open {
  display: none;
}

.ai-chat-widget.ai-chat-is-open .ai-chat-trigger-btn .ai-chat-icon-close {
  display: block;
}

/* Окно диалога */
.ai-chat-window {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 370px;
  height: 540px;
  min-height: 540px;
  max-height: calc(100vh - 110px);
  background: var(--ai-chat-bg);
  border-radius: var(--ai-chat-radius);
  box-shadow: var(--ai-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out, visibility 0.25s;
}

.ai-chat-widget.ai-chat-is-open .ai-chat-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.ai-chat-window.ai-chat-is-resizing {
  transition: none !important;
  user-select: none;
}

/* Зона захвата для изменения высоты */
.ai-chat-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 9px;
  cursor: ns-resize;
  z-index: 100;
  background: transparent;
}

.ai-chat-resize-handle:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Шапка */
.ai-chat-header {
  background: linear-gradient(135deg, var(--ai-chat-primary), #73a532);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-bot-avatar {
  font-size: 24px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-bot-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.ai-chat-bot-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #55ff7f;
}

.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-action-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: background-color 0.2s ease, transform 0.2s ease;
  padding: 0;
  line-height: 1;
}

.ai-chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.ai-chat-action-btn:active {
  transform: scale(0.92);
}

.ai-chat-close-btn {
  font-size: 24px;
}

.ai-chat-action-btn.ai-chat-rotating svg {
  animation: aiChatSpin 0.5s ease-in-out;
}

@keyframes aiChatSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}

/* Экран согласия */
.ai-chat-consent-screen {
  flex: 1;
  padding: 22px;
  display: flex;
  align-items: center;
  background-color: #fafbfc;
}

.ai-chat-consent-screen.ai-chat-hidden {
  display: none !important;
}

.ai-chat-consent-card {
  text-align: center;
}

.ai-chat-warning-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.ai-chat-consent-card h4 {
  margin: 0 0 10px 0;
  font-size: 17px;
  color: #1a202c;
}

.ai-chat-disclaimer-text {
  font-size: 13.5px;
  line-height: 1.45;
  color: #4a5568;
  margin: 0 0 10px 0;
}

.ai-chat-disclaimer-subtext {
  font-size: 12px;
  line-height: 1.4;
  color: #718096;
  margin: 0 0 16px 0;
}

.ai-chat-consent-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 18px;
  user-select: none;
}

.ai-chat-consent-checkbox-label input {
  margin-top: 2.5px;
  accent-color: var(--ai-chat-primary);
}

.ai-chat-btn-primary {
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: 22px;
  background: var(--ai-chat-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.ai-chat-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-btn-primary:not(:disabled):hover {
  background: var(--ai-chat-primary-hover);
}

/* Область диалога */
.ai-chat-body {
  flex: 1;
  display: none;
  flex-direction: column;
  background: #fdfdfd;
  min-height: 0;
  overflow: hidden;
}

.ai-chat-body.ai-chat-active {
  display: flex;
}

/* Плашка-дисклеймер с крестиком */
.ai-chat-disclaimer-badge {
  background: #fff8e6;
  border-bottom: 1px solid #faecc5;
  color: #8c6800;
  font-size: 11px;
  padding: 5px 8px 5px 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-chat-disclaimer-badge.ai-chat-hidden {
  display: none !important;
}

.ai-chat-disclaimer-badge .ai-chat-disclaimer-text {
  flex: 1;
  text-align: center;
  line-height: 1.3;
  margin: 0;
}

.ai-chat-disclaimer-close {
  background: transparent;
  border: none;
  color: #8c6800;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.ai-chat-disclaimer-close:hover {
  opacity: 1;
}

.ai-chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-chat-message {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
}

.ai-chat-message-bot {
  background: var(--ai-chat-gray-bg);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  color: #2d3748;
}

.ai-chat-message-user {
  background: var(--ai-chat-primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-chat-message-error {
  background: #fee2e2;
  color: #991b1b;
  font-size: 12.5px;
  align-self: center;
}

/* Форма отправки внизу */
.ai-chat-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--ai-chat-border);
  background: #fff;
  flex-shrink: 0;
}

.ai-chat-input-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#aiChatInput {
  flex: 1;
  border: 1px solid var(--ai-chat-border);
  border-radius: 20px;
  padding: 8px 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 13.5px;
  max-height: 90px;
}

#aiChatInput:focus {
  border-color: var(--ai-chat-primary);
}

.ai-chat-btn-send {
  background: var(--ai-chat-primary);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.2s;
  flex-shrink: 0;
}

.ai-chat-btn-send:hover {
  background: var(--ai-chat-primary-hover);
}

/* Анимация индикатора набора текста (три точки) */
.ai-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  width: fit-content;
}

.ai-chat-typing .ai-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a99a8;
  animation: aiChatTypingBounce 1.2s infinite ease-in-out;
}

.ai-chat-typing .ai-chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-chat-typing .ai-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing .ai-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiChatTypingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Блок быстрых подсказок-ссылок */
.ai-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 4px 0 6px 0;
  animation: aiChatFadeIn 0.25s ease-out;
}

.ai-chat-suggestion-chip {
  background: #ffffff;
  border: 1px solid #dbe5ea;
  border-radius: 12px;
  color: #2c3e50;
  font-size: 13px;
  line-height: 1.35;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ai-chat-suggestion-chip:hover {
  background: #f4f8eb;
  border-color: var(--ai-chat-primary);
  color: #4b7318;
  transform: translateX(2px);
}

.ai-chat-suggestion-chip:active {
  transform: scale(0.98);
}

@keyframes aiChatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Мобильная адаптация */
@media (max-width: 480px) {
  .ai-chat-widget {
    bottom: 16px;
    right: 16px;
  }
  .ai-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
}