#ai-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#ai-widget.left {
  right: auto;
  left: 20px;
}

#ai-widget * {
  box-sizing: border-box;
}

/* Состояния */
#ai-widget.ai-open #ai-window {
  display: flex;
}
#ai-widget.ai-open #ai-btn {
  display: none;
}
#ai-widget:not(.ai-open) #ai-window {
  display: none;
}

/* Развёрнутый режим: центр экрана (desktop), fullscreen на мобиле */
#ai-widget.ai-expanded {
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
}

#ai-widget.ai-expanded #ai-window {
  width: min(720px, 96vw);
  height: min(720px, 90vh);
}

/* На маленьких экранах — во всю ширину/высоту снизу */
@media (max-width: 640px) {
  #ai-widget.ai-expanded {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
  }

  #ai-widget.ai-expanded #ai-window {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
}


/* Плавающая кнопка */
#ai-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #ff3b62;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(15,23,42,0.35);
  transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
}
#ai-btn:hover {
  background: #e62e4d;
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(15,23,42,0.45);
}

/* Окно */
#ai-window {
  width: 360px;
  height: 480px;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(15,23,42,0.45);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: ai-slide-in 0.18s ease-out;
}

@keyframes ai-slide-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Шапка */
#ai-header {
  padding: 10px 12px;
  background: linear-gradient(135deg, #ff3b62, #ff5c7d);
  color: white;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#ai-header-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#ai-header-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(15,23,42,0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
#ai-header-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ai-header-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.9;
}
#ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Шапка кнопки */
#ai-widget .ai-header-btn {
  border: none;
  background: rgba(15,23,42,0.18);
  color: #e5e7eb;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ai-widget .ai-header-btn:hover {
  background: rgba(15,23,42,0.30);
  color: #ffffff;
}

/* Чат */
#ai-chat {
  flex: 1;
  padding: 12px 10px 8px 10px;
  background: #f9fafb;
  overflow-y: auto;
  font-size: 14px;
}
#ai-chat-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#ai-widget .ai-msg {
  max-width: 270px;
  padding: 8px 10px;
  border-radius: 14px;
  line-height: 1.4;
}
#ai-widget .ai-msg-user {
  margin-left: auto;
  background: #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 4px 14px;
}
#ai-widget .ai-msg-assistant {
  margin-right: auto;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 14px 4px;
}
#ai-widget .ai-msg-assistant a {
  color: #ff3b62;
  text-decoration: underline;
}

/* Стили для форматированного текста в сообщениях бота */
#ai-widget .bubble.bot ul {
  margin: 6px 0;
  padding-left: 20px;
  list-style: none;
}
#ai-widget .bubble.bot ul li {
  margin: 4px 0;
  padding-left: 8px;
  position: relative;
}
#ai-widget .bubble.bot ul li:before {
  content: "—";
  position: absolute;
  left: -8px;
  color: #6b7280;
}
#ai-widget .bubble.bot br {
  line-height: 1.6;
}

/* typing indicator */
#ai-typing {
  display: none;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0 0;
  font-size: 12px;
  color: #6b7280;
}
#ai-typing-dots {
  display: inline-flex;
  gap: 2px;
}
.ai-dot {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: #9ca3af;
  animation: ai-dot-bounce 0.9s infinite;
}
.ai-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* input */
#ai-input-box {
  padding: 8px 10px 10px 10px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: white;
}
#ai-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
#ai-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 14px;
  resize: none;
  min-height: 34px;
  max-height: 84px;
  color: #111827;
  background: #ffffff;
}
#ai-input::placeholder {
  color: #9ca3af;
}

/* Адаптация для ID из скрипта (q, messages, send, typing) */
#q {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 14px;
  resize: none;
  min-height: 34px;
  max-height: 84px;
  font-family: inherit;
  color: #111827 !important;
  background: #ffffff !important;
}
#q::placeholder {
  color: #9ca3af;
}
#send {
  background: #ff3b62;
  border-radius: 10px;
  padding: 7px 12px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  border: none;
  min-width: 40px;
  font-family: inherit;
}
#send[disabled] {
  opacity: 0.55;
  cursor: default;
}
#send:hover:not([disabled]) {
  background: #e62e4d;
}
#messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#typing {
  display: none;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0 0;
  font-size: 12px;
  color: #6b7280;
}
#typing.show {
  display: flex;
}
#ai-widget .msgRow {
  max-width: 270px;
}
#ai-widget .msgRow.me {
  margin-left: auto;
}
#ai-widget .msgRow.bot {
  margin-right: auto;
}
#ai-widget .bubble {
  padding: 8px 10px;
  border-radius: 14px;
  line-height: 1.4;
}
#ai-widget .bubble.me {
  background: #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 4px 14px;
}
#ai-widget .bubble.bot {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 14px 4px;
}
#statusText {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.9;
}
#ai-send {
  background: #ff3b62;
  border-radius: 10px;
  padding: 7px 12px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  border: none;
  min-width: 40px;
}
#ai-send[disabled] {
  opacity: 0.55;
  cursor: default;
}
#ai-send:hover:not([disabled]) {
  background: #e62e4d;
}
#ai-helper {
  font-size: 10px;
  color: #9ca3af;
  padding: 0 2px;
}
