/*
 * CloudCandy AI Chat Widget Styles
 *
 * These styles are specific to the AI chat widget component.
 * They complement the Tailwind CSS utility classes used in the widget.
 */

/* ===== Chat Widget Container ===== */
[data-controller="chat"] {
  /* Ensure the chat widget is above other floating elements */
  z-index: 50;
}

/* ===== Chat Window ===== */
[data-chat-target="widget"] {
  /* Ensure smooth transitions for all properties */
  transition: opacity 300ms ease-in-out, transform 300ms ease-in-out;
  transform-origin: bottom right;
}

/* ===== Floating Action Button (FAB) ===== */
[data-chat-target="toggle"] {
  /* Pulse animation to draw attention */
  animation: chat-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes chat-pulse {
  0%, 100% {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
                0 4px 6px -2px rgba(0, 0, 0, 0.05);
  }
  50% {
    box-shadow: 0 20px 25px -5px rgba(168, 85, 247, 0.3),
                0 10px 10px -5px rgba(168, 85, 247, 0.2);
  }
}

/* Hide pulse animation after first interaction */
[data-controller="chat"].chat-interacted [data-chat-target="toggle"] {
  animation: none;
}

/* ===== Messages Container ===== */
[data-chat-target="messages"] {
  /* Smooth scrolling */
  scroll-behavior: smooth;
}

/* Custom scrollbar for messages */
[data-chat-target="messages"]::-webkit-scrollbar {
  width: 6px;
}

[data-chat-target="messages"]::-webkit-scrollbar-track {
  background: transparent;
}

[data-chat-target="messages"]::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

[data-chat-target="messages"]::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ===== Message Animations ===== */
@keyframes message-slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Typing Indicator ===== */
[data-chat-target="typingIndicator"] span {
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

[data-chat-target="typingIndicator"] span:nth-child(1) {
  animation-delay: -0.32s;
}

[data-chat-target="typingIndicator"] span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* ===== Input Field ===== */
[data-chat-target="input"] {
  /* Auto-resize for multiline input */
  field-sizing: content;
  min-height: 48px;
  max-height: 120px;
}

[data-chat-target="input"]:focus {
  outline: none;
}

/* ===== Quick Action Buttons ===== */
[data-chat-target="quickActions"] button {
  transition: all 150ms ease-in-out;
}

[data-chat-target="quickActions"] button:hover {
  transform: translateY(-1px);
}

[data-chat-target="quickActions"] button:active {
  transform: translateY(0);
}

/* ===== Status Indicator ===== */
[data-chat-target="statusIndicator"].text-emerald-500 {
  animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ===== Message Bubbles ===== */
.message-content {
  /* Ensure links in messages are styled correctly */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-content a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content a:hover {
  text-decoration-thickness: 2px;
}

.message-content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.875em;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
}

.message-content ul,
.message-content ol {
  padding-left: 1.25rem;
}

.message-content li {
  margin: 0.25rem 0;
}

/* ===== Error Messages ===== */
[data-role="alert"] {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 640px) {
  [data-chat-target="widget"] {
    width: calc(100vw - 2rem) !important;
    max-height: 80vh;
    bottom: 5rem;
  }

  [data-chat-target="toggle"] {
    width: 3.5rem;
    height: 3.5rem;
  }
}

/* ===== Reduced Motion Preference ===== */
@media (prefers-reduced-motion: reduce) {
  [data-chat-target="widget"],
  [data-chat-target="toggle"],
  [data-chat-target="messages"],
  [data-chat-target="quickActions"] button,
  .animate-slide-up {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  [data-chat-target="toggle"] {
    animation: none;
  }

  [data-chat-target="typingIndicator"] span {
    animation: none;
  }
}

/* ===== Dark Mode Support (future enhancement) ===== */
@media (prefers-color-scheme: dark) {
  /* Placeholder for dark mode styles */
  /* These will be activated when dark mode is implemented */
}

/* ===== High Contrast Mode ===== */
@media (prefers-contrast: high) {
  [data-chat-target="widget"] {
    border: 2px solid currentColor;
  }

  .message-content {
    font-weight: 500;
  }
}

/* ===== Print Styles ===== */
@media print {
  [data-controller="chat"] {
    display: none !important;
  }
}
