
/* ================= CSS VARIABLES ================= */
:root {
  --widget-primary: #8741F0;
  --widget-primary-dark: #6B2AC6;
  --widget-bg: #ffffff;
  --widget-bg-secondary: #f8f9fa;
  --widget-border: #e1e5e9;
  --widget-text: #1f2937;
  --widget-text-muted: #6b7280;
  --widget-error: #ef4444;
  --widget-success: #10b981;
  --widget-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --widget-radius: 16px;
  --widget-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================= WIDGET CONTAINER ================= */
#ai-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.bot .content{text-align: left;}
.user .content{text-align: right;}
/* ================= TOGGLE BUTTON ================= */
.widget-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--widget-primary), var(--widget-primary-dark));
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(135, 65, 240, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: 0;
  right: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.widget-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(135, 65, 240, 0.5);
}

.widget-toggle:active {
  transform: scale(0.95);
}

.toggle-icon {
  font-size: 24px;
  color: white;
  transition: opacity 0.2s ease, transform 0.3s ease;
  position: absolute;
}

.close-icon {
  opacity: 0;
  transform: rotate(-90deg);
  font-size: 20px;
  font-weight: bold;
}

.widget-open .chat-icon {
  opacity: 0;
  transform: rotate(90deg);
}

.widget-open .close-icon {
  opacity: 1;
  transform: rotate(0);
}

/* Unread Badge */
.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--widget-error);
  color: white;
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  animation: badgePop 0.3s ease;
}

@keyframes badgePop {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ================= CHAT CONTAINER ================= */
.chat-container {
  width: 380px;
  height: 580px;
  background: var(--widget-bg);
  border-radius: var(--widget-radius);
  box-shadow: var(--widget-shadow);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--widget-border);
  position: absolute;
  bottom: 80px;
  right: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: all var(--widget-transition);
  overflow: hidden;
}

.widget-open .chat-container {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ================= HEADER ================= */
#chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--widget-primary), var(--widget-primary-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(135, 65, 240, 0.3);
}

#chat-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-btn {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  transition: background 0.2s ease;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ================= MESSAGES ================= */
#chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--widget-bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Message Bubbles */
.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: bubbleSlide 0.25s ease-out;
}

@keyframes bubbleSlide {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble.user {
  margin-left: auto;
  background: linear-gradient(135deg, var(--widget-primary), var(--widget-primary-dark));
  color: white;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(135, 65, 240, 0.25);
}

.bubble.bot {
  margin-right: auto;
  background: var(--widget-bg);
  color: var(--widget-text);
  border: 1px solid var(--widget-border);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.bubble .time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 6px;
  text-align: right;
  font-weight: 400;
}

.bubble .chat-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-top: 8px;
  cursor: pointer;
  transition: max-height 0.3s ease;
}

.bubble .chat-img.expanded {
  max-height: 400px;
}

.bubble .chat-audio {
  width: 100%;
  margin-top: 8px;
  border-radius: 8px;
  height: 40px;
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: 20px;
}

.welcome-message .avatar {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--widget-primary), var(--widget-primary-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 28px;
}

.welcome-message h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--widget-text);
}

.welcome-message p {
  margin: 0;
  font-size: 13px;
  color: var(--widget-text-muted);
  line-height: 1.5;
}

/* ================= TYPING INDICATOR ================= */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--widget-bg);
  border: 1px solid var(--widget-border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  max-width: fit-content;
  margin: 0 16px 12px;
  animation: bubbleSlide 0.25s ease-out;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--widget-primary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

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

.typing-text {
  font-size: 13px;
  color: var(--widget-text-muted);
  font-style: italic;
}

/* ================= PREVIEW ================= */
.preview-container {
  padding: 12px 16px;
  border-top: 1px solid var(--widget-border);
  background: #fafbfc;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.preview-grid img {
  width: 100%;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.preview-grid img:hover {
  transform: scale(1.05);
}

.preview-audio {
  width: 100%;
  height: 50px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.progress {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--widget-primary), var(--widget-primary-dark));
  transition: width 0.3s ease;
}

.preview-actions {
  display: flex;
  justify-content: flex-end;
}

.cancel-btn {
  background: var(--widget-error);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.cancel-btn:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

/* ================= INPUT AREA ================= */
#chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--widget-border);
  align-items: center;
  background: var(--widget-bg);
}

#chat-input input[type="text"] {
  flex: 1;
  padding: 12px 16px;
  border-radius: 24px;
  border: 1px solid #d1d5db;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  min-width: 0;
}

#chat-input input[type="text"]:focus {
  border-color: var(--widget-primary);
  box-shadow: 0 0 0 3px rgba(135, 65, 240, 0.12);
}

#chat-input input[type="text"]::placeholder {
  color: #9ca3af;
}

.input-btn {
  width: 42px;
  height: 42px;
  background: #f3f4f6;
  color: var(--widget-text-muted);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.input-btn:hover:not(:disabled) {
  background: #e5e7eb;
  color: var(--widget-text);
}

.input-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.input-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-btn svg {
  width: 18px;
  height: 18px;
}

.send-btn {
  background: linear-gradient(135deg, var(--widget-primary), var(--widget-primary-dark));
  color: white;
}

.send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  color: white;
  box-shadow: 0 2px 8px rgba(135, 65, 240, 0.4);
}

/* Recording State */
.input-btn.recording {
  background: var(--widget-error) !important;
  color: white !important;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ================= RESPONSIVE ================= */
@media (max-width: 480px) {
  #ai-chat-widget {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }

  .chat-container {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    max-height: 600px;
    right: 0;
    left: 0;
    bottom: 70px;
  }

  .widget-toggle {
    width: 54px;
    height: 54px;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
