.ai-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1060;
  font-family: inherit;
}

html[dir="rtl"] .ai-chat-root {
  right: auto;
  left: 24px;
}

.ai-chat-toggle {
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #163a5c);
  color: #fff;
  box-shadow: 0 16px 40px rgba(15, 39, 64, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  transition: var(--transition);
  cursor: pointer;
}

.ai-chat-toggle:hover,
.ai-chat-toggle.is-open {
  transform: translateY(-2px) scale(1.04);
  background: linear-gradient(135deg, var(--accent), #e67410);
}

.ai-chat-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: min(380px, calc(100vw - 2rem));
  height: min(520px, calc(100vh - 8rem));
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(15, 39, 64, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(30, 73, 118, 0.08);
  transform-origin: bottom right;
}

html[dir="rtl"] .ai-chat-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.ai-chat-header {
  background: linear-gradient(135deg, var(--primary), #163a5c);
  color: #fff;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.ai-chat-header h6 {
  margin: 0;
  font-weight: 700;
}

.ai-chat-header small {
  opacity: 0.85;
}

.ai-chat-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--light);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-chat-bubble {
  max-width: 88%;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-bubble.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--text);
  border: 1px solid rgba(30, 73, 118, 0.08);
  border-bottom-left-radius: 4px;
}

html[dir="rtl"] .ai-chat-bubble.bot {
  align-self: flex-start;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

.ai-chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

html[dir="rtl"] .ai-chat-bubble.user {
  align-self: flex-end;
  border-bottom-right-radius: 14px;
  border-bottom-left-radius: 4px;
}

.ai-chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 0.65rem 0.85rem;
  background: #fff;
  border-radius: 14px;
  border: 1px solid rgba(30, 73, 118, 0.08);
}

.ai-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: aiChatDot 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiChatDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-chat-input-wrap {
  padding: 0.85rem;
  border-top: 1px solid rgba(30, 73, 118, 0.08);
  background: #fff;
  display: flex;
  gap: 0.5rem;
}

.ai-chat-input-wrap input {
  flex: 1;
  border: 1px solid rgba(30, 73, 118, 0.15);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-size: 0.92rem;
}

.ai-chat-input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 73, 118, 0.12);
}

.ai-chat-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.ai-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
  background: var(--light);
}

.ai-chat-quick button {
  border: 1px solid rgba(30, 73, 118, 0.12);
  background: #fff;
  color: var(--primary);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.ai-chat-quick button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

body:has(.ai-chat-root) .floating-actions {
  bottom: 94px;
}

@media (max-width: 575.98px) {
  .ai-chat-root {
    bottom: 16px;
    right: 16px;
  }

  html[dir="rtl"] .ai-chat-root {
    left: 16px;
  }

  body:has(.ai-chat-root) .floating-actions {
    bottom: 86px;
  }
}
