/* ========================================
   Babayagas Web Designs — AI Chat Widget
   ======================================== */

/* --- Chat Bubble (floating trigger) --- */
.chat-bubble {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 60px;
  height: 60px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4);
  transition: all 0.3s ease;
  border: none;
  outline: none;
}

.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(6, 182, 212, 0.5);
}

.chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: transform 0.3s ease;
}

.chat-bubble.open svg.chat-icon { display: none; }
.chat-bubble.open svg.close-icon { display: block; }
.chat-bubble:not(.open) svg.chat-icon { display: block; }
.chat-bubble:not(.open) svg.close-icon { display: none; }

/* Pulse animation */
.chat-bubble::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  opacity: 0;
  animation: chat-pulse 3s ease-in-out infinite;
}

.chat-bubble.open::after {
  animation: none;
  opacity: 0;
}

@keyframes chat-pulse {
  0%, 100% { opacity: 0; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.15); }
}

/* --- Chat Window --- */
.chat-window {
  position: fixed;
  bottom: 6rem;
  right: 1.5rem;
  width: 380px;
  max-height: 520px;
  background: var(--dark-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s ease;
  overflow: hidden;
}

.chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* --- Chat Header --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header-dot {
  width: 10px;
  height: 10px;
  background: var(--success, #34D399);
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}

.chat-header-text h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.3;
}

.chat-header-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1.2rem;
  line-height: 1;
  transition: color 0.2s;
}

.chat-close:hover {
  color: var(--text);
}

/* --- Chat Messages --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 280px;
  max-height: 340px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Message bubbles */
.chat-msg {
  max-width: 85%;
  padding: 0.65rem 1rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface, var(--dark-light));
  color: var(--text);
  border-bottom-left-radius: 4px;
}

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

/* Links in assistant messages */
.chat-msg.assistant a {
  color: var(--primary-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg.assistant a:hover {
  color: var(--primary);
}

/* Quick action buttons */
.chat-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.chat-action-btn {
  padding: 0.35rem 0.75rem;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: 20px;
  color: var(--primary-light);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

.chat-action-btn:hover {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--primary);
  color: var(--primary);
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  background: var(--surface, var(--dark-light));
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

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

/* --- Chat Input --- */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--dark);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--dark-mid);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  max-height: 80px;
  min-height: 38px;
  line-height: 1.4;
}

.chat-input:focus {
  border-color: var(--primary);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-send {
  width: 38px;
  height: 38px;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send:hover {
  background: var(--primary-dark);
}

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

.chat-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* --- Powered by --- */
.chat-powered {
  text-align: center;
  padding: 0.4rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.5;
  background: var(--dark);
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .chat-window.open {
    height: 100vh;
    height: 100dvh;
  }

  .chat-messages {
    max-height: none;
    flex: 1;
  }

  .chat-bubble {
    bottom: 1rem;
    right: 1rem;
    width: 54px;
    height: 54px;
  }

  .chat-bubble svg {
    width: 24px;
    height: 24px;
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  .chat-window {
    width: 340px;
    right: 1rem;
    bottom: 5rem;
  }
}

/* --- Homepage: hide default bubble while in hero, robot speech bubble handles it --- */
.page-home .chat-bubble {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
  transition: all 0.4s ease;
}

.page-home.past-hero .chat-bubble {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}
