/* ============================================
   AI Chat Widget — Shared Component
   Mobile-first, accessible, works with all 3 frameworks
   ============================================ */

/* Chat Toggle Button */
.ai-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1), box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.ai-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.12);
}
.ai-chat-toggle:active {
  transform: scale(0.95);
}
.ai-chat-toggle svg {
  width: 26px;
  height: 26px;
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
}
.ai-chat-toggle[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

/* Notification dot */
.ai-chat-toggle .chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  display: none;
  animation: pulse-dot 2s infinite;
}
.ai-chat-toggle .chat-badge.visible { display: block; }

@keyframes pulse-dot {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* Chat Window */
.ai-chat-window {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9999;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100dvh - 140px));
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.95);
  transition: opacity 0.3s cubic-bezier(0.16,1,0.3,1),
              transform 0.3s cubic-bezier(0.16,1,0.3,1),
              visibility 0.3s;
  box-shadow: 0 12px 48px rgba(0,0,0,0.15), 0 4px 16px rgba(0,0,0,0.1);
}
.ai-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Mobile full-screen */
@media (max-width: 480px) {
  .ai-chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }
  .ai-chat-toggle {
    bottom: 16px;
    right: 16px;
  }
}

/* Chat Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  flex-shrink: 0;
}
.ai-chat-header .chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-chat-header .chat-avatar svg {
  width: 18px;
  height: 18px;
}
.ai-chat-header .chat-info {
  flex: 1;
  min-width: 0;
}
.ai-chat-header .chat-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}
.ai-chat-header .chat-status {
  font-size: 11px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-chat-header .chat-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}
.ai-chat-header .chat-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  color: inherit;
  transition: background 0.2s;
}
.ai-chat-header .chat-close:hover {
  background: rgba(255,255,255,0.25);
}

/* Messages Area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Message Bubbles */
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msg-in 0.3s cubic-bezier(0.16,1,0.3,1);
}
.chat-msg.bot { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.chat-msg .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
}
.chat-msg.user .msg-avatar { display: none; }

.chat-msg .msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.bot .msg-bubble {
  border-top-left-radius: 4px;
}
.chat-msg.user .msg-bubble {
  border-top-right-radius: 4px;
}

.chat-msg .msg-time {
  font-size: 10px;
  opacity: 0.5;
  margin-top: 4px;
}

/* Quick Replies */
.ai-chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}
.ai-chat-quick-replies button {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.ai-chat-quick-replies button:active {
  transform: scale(0.96);
}

/* Input Area */
.ai-chat-input-area {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.ai-chat-input-area textarea {
  flex: 1;
  border: 1px solid;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  background: transparent;
}
.ai-chat-input-area textarea::placeholder {
  opacity: 0.5;
}
.ai-chat-input-area .chat-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.ai-chat-input-area .chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ai-chat-input-area .chat-send svg {
  width: 18px;
  height: 18px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  align-items: center;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator 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; }
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Powered-by footer */
.ai-chat-powered {
  text-align: center;
  font-size: 10px;
  opacity: 0.4;
  padding: 4px 0 8px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ai-chat-window,
  .ai-chat-toggle,
  .ai-chat-toggle svg,
  .chat-msg,
  .typing-indicator span {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
