/* AI Chat Widget */
.ai-chat-widget {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.whatsapp-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25d366, #128c7e);
  border: none;
  color: white;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37, 211, 102, 0.4);
  transition:
    transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    box-shadow 0.3s ease;
  text-decoration: none;
}

.whatsapp-toggle:hover {
  transform: scale(1.1);
  color: white;
}

.scroll-to-top-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(79, 70, 229, 0.3);
  transition:
    transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    box-shadow 0.3s ease,
    opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    border-color 0.3s ease;
  text-decoration: none;
  opacity: 0;
  transform: translateY(20px) scale(0.5);
  pointer-events: none;
  position: relative;
  overflow: hidden;
}

.scroll-to-top-toggle::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #ec4899);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.scroll-to-top-toggle.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  animation: scroll-btn-glow 3s ease-in-out infinite alternate;
}

.scroll-to-top-toggle:hover {
  transform: scale(1.15) translateY(-2px);
  color: white;
  border-color: rgba(79, 70, 229, 0.6);
  box-shadow: 0 0 25px rgba(79, 70, 229, 0.5), 0 0 50px rgba(236, 72, 153, 0.2);
}

.scroll-to-top-toggle:hover::before {
  opacity: 1;
}

.scroll-to-top-toggle:hover .bi-arrow-up {
  animation: arrow-bounce 0.6s ease infinite;
}

@keyframes scroll-btn-glow {
  0% {
    box-shadow: 0 0 12px rgba(79, 70, 229, 0.25);
    border-color: var(--border-color);
  }
  100% {
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.35);
    border-color: rgba(236, 72, 153, 0.3);
  }
}

@keyframes arrow-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

.ai-chat-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #ec4899);
  border: none;
  color: white;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
  transition:
    transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    box-shadow 0.3s ease;
  animation: pulse-glow-chat 2s infinite alternate;
}

@keyframes pulse-glow-chat {
  0% {
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.5);
  }
  100% {
    box-shadow: 0 0 25px rgba(236, 72, 153, 0.8);
  }
}

.ai-chat-toggle:hover {
  transform: scale(1.1);
}

.ai-chat-box {
  width: 350px;
  height: 480px;
  background: rgba(10, 10, 10, 0.85); /* Dark matching Ribanier theme */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  transform-origin: bottom right;
  animation: chat-pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-chat-box.d-none {
  display: none !important;
}

@keyframes chat-pop-in {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.ai-chat-header {
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
}

.ai-chat-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar for chat body */
.ai-chat-body::-webkit-scrollbar {
  width: 6px;
}
.ai-chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.ai-chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.ai-message {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.user-message {
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.ai-chat-input-area {
  padding: 15px;
  display: flex;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.ai-input {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-main) !important;
  box-shadow: none !important;
  font-family: inherit;
  border-radius: 6px !important;
}
.ai-input::placeholder {
  color: var(--text-muted);
}
.ai-input:focus {
  border-color: #4f46e5 !important;
}

.ai-word-counter {
  transition: color 0.3s ease;
}
.ai-word-counter.limit-reached {
  color: #ef4444 !important;
}

.ai-chat-error {
  padding: 8px 15px;
  background-color: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  font-size: 0.8rem;
  text-align: center;
  border-top: 1px solid rgba(239, 68, 68, 0.2);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: transparent;
  align-self: flex-start;
  opacity: 0.7;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite both;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}
.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-5px);
  }
}

/* Mobile Adjustments */
@media (max-width: 576px) {
  .ai-chat-box {
    width: calc(100vw - 32px);
    height: 55vh;
    max-height: 420px;
    right: -8px;
    position: relative;
    border-radius: 10px;
  }

  .ai-chat-header {
    padding: 12px 16px;
  }

  .ai-chat-body {
    padding: 14px;
  }

  .chat-message {
    font-size: 0.85rem;
    padding: 10px 14px;
  }

  .ai-chat-input-area {
    padding: 10px 12px;
    gap: 8px;
  }

  /* Hide text bubble on very small screens to save space */
  .ai-chat-bubble {
    display: none !important;
  }
}

/* AI Chat Bubble */
.ai-chat-bubble {
  position: absolute;
  right: 55px; /* next to the button */
  bottom: 0px;
  height: 40px; /* match button height */
  display: flex;
  align-items: center;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0 14px;
  border-radius: 12px;
  border-bottom-right-radius: 2px;
  font-size: 0.85rem;
  white-space: nowrap;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateX(10px) scale(0.9);
  transition: opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

.ai-chat-bubble::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -6px;
  transform: translateY(-50%);
  border-width: 6px 0 6px 6px;
  border-style: solid;
  border-color: transparent transparent transparent var(--border-color);
}

.ai-chat-bubble.show {
  opacity: 1;
  transform: translateX(0) scale(1);
}
