/* ======================
   Immersive Chatbot Styles
   ====================== */

/* Theme colors */
:root {
  /* Requested palette */
  --adw-chatbot-secondary: #a1573c;
  --adw-chatbot-primary: #0530ad;

  /* RGB helpers for rgba() usage */
  --adw-chatbot-secondary-rgb: 161, 87, 60;
  --adw-chatbot-primary-rgb: 5, 48, 173;
}

/* Global animations */
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

/* Toggle Button */
#chatbot-toggle {
  position: fixed;
  bottom: 25px;
  right: 25px;
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: #fff;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483646;
  box-shadow: 
    0 10px 30px rgba(var(--adw-chatbot-primary-rgb), 0.4),
    0 4px 12px rgba(0, 0, 0, 0.15),
    inset 0 -3px 10px rgba(0, 0, 0, 0.1),
    inset 0 3px 10px rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: bounce 2s ease-in-out infinite;
  border: 3px solid rgba(255, 255, 255, 0.3);
  overflow: visible;
}

#chatbot-toggle.widget-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

#chatbot-toggle:hover {
  transform: scale(1.08) translateY(-3px);
  box-shadow: 
    0 15px 40px rgba(var(--adw-chatbot-primary-rgb), 0.5),
    0 8px 16px rgba(0, 0, 0, 0.2),
    inset 0 -3px 10px rgba(0, 0, 0, 0.1),
    inset 0 3px 10px rgba(255, 255, 255, 0.3);
  animation: none;
  border-color: rgba(255, 255, 255, 0.5);
}

#chatbot-toggle:active {
  transform: scale(1.0) translateY(-1px);
  box-shadow: 
    0 8px 20px rgba(var(--adw-chatbot-primary-rgb), 0.4),
    0 4px 10px rgba(0, 0, 0, 0.15);
}

.chatbot-toggle-image {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -62%);
  border: none;
  box-shadow: 
    0 18px 45px rgba(0, 0, 0, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.22);
  filter: drop-shadow(0 14px 20px rgba(var(--adw-chatbot-primary-rgb), 0.25));
  z-index: 1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#chatbot-toggle:hover .chatbot-toggle-image {
  transform: translate(-50%, -66%) scale(1.09);
  box-shadow: 
    0 22px 55px rgba(0, 0, 0, 0.4),
    0 10px 22px rgba(0, 0, 0, 0.25);
}

#chatbot-invitation-bubble {
  position: absolute;
  /* Position bubble above the launcher so the arrow tip hits the avatar (not the button edge) */
  bottom: 90px;
  right: 0;
  background: white;
  color: #333;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  /* Avoid shrink-to-fit being constrained by the 70px toggle button (causes vertical/stacked text) */
  width: max-content;
  max-width: 220px;
  display: inline-flex;
  align-items: center;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.25;
  animation: fadeIn 0.35s ease-out;
  pointer-events: none;
}

@supports not (width: max-content) {
  #chatbot-invitation-bubble {
    width: 220px;
  }
}

#chatbot-invitation-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  /* Align arrow tip with the launcher avatar center (70px toggle => 35px from right) */
  right: 35px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid white;
}

#chatbot-toggle.widget-open #chatbot-invitation-bubble {
  display: none;
}

#chatbot-notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  border: 2px solid white;
  animation: pulse 2s ease-in-out infinite;
}

/* Main Widget */
#chatbot-widget {
  position: fixed;
  bottom: 20px;
  right: 25px;
  width: 450px;
  max-height: calc(100vh - 40px);
  height: 650px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  z-index: 2147483646;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#chatbot-widget.chatbot-hidden {
  display: none;
}

#chatbot-widget.minimized {
  height: 70px !important;
  overflow: hidden;
}

/* Header */
#chatbot-header {
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: #fff;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.chatbot-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chatbot-avatar-container {
  position: relative;
}

.chatbot-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.chatbot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chatbot-status-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid white;
  animation: pulse 2s ease-in-out infinite;
}

.chatbot-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chatbot-title {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
}

.chatbot-status {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 400;
}

.chatbot-header-actions {
  display: flex;
  gap: 8px;
}

.chatbot-icon-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}

.chatbot-icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.chatbot-icon-btn:active {
  transform: scale(0.95);
}

/* Minimize/expand chevron */
#chatbot-minimize .chatbot-minimize-icon {
  transition: transform 0.2s ease;
}

#chatbot-widget.minimized #chatbot-minimize .chatbot-minimize-icon {
  transform: rotate(180deg);
}

/* Messages Container */
#chatbot-messages-container {
  flex: 1;
  overflow-y: auto;
  background: linear-gradient(to bottom, #f9fafb 0%, #ffffff 100%);
  position: relative;
}

#chatbot-messages {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Custom scrollbar */
#chatbot-messages-container::-webkit-scrollbar {
  width: 6px;
}

#chatbot-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

#chatbot-messages-container::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

#chatbot-messages-container::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Message Bubbles */
.chatbot-message {
  display: flex;
  gap: 10px;
  animation: fadeIn 0.3s ease-out;
  max-width: 85%;
}

.chatbot-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  margin-top: 4px;
  overflow: hidden;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-avatar.bot {
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: white;
}

.message-avatar.user {
  background: linear-gradient(135deg, var(--adw-chatbot-secondary) 0%, var(--adw-chatbot-primary) 100%);
  color: white;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 14px;
  word-wrap: break-word;
  position: relative;
  animation: slideUp 0.3s ease-out;
}

.chatbot-message.bot .message-bubble {
  background: white;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Markdown styling in bot messages */
.chatbot-message.bot .message-bubble p {
  margin: 0 0 8px 0;
}

.chatbot-message.bot .message-bubble p:last-child {
  margin-bottom: 0;
}

.chatbot-message.bot .message-bubble h1,
.chatbot-message.bot .message-bubble h2,
.chatbot-message.bot .message-bubble h3 {
  margin: 12px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
}

.chatbot-message.bot .message-bubble h1 {
  font-size: 18px;
  color: var(--adw-chatbot-primary);
}

.chatbot-message.bot .message-bubble h2 {
  font-size: 16px;
  color: var(--adw-chatbot-primary);
}

.chatbot-message.bot .message-bubble h3 {
  font-size: 14px;
  color: var(--adw-chatbot-secondary);
}

.chatbot-message.bot .message-bubble ul,
.chatbot-message.bot .message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.chatbot-message.bot .message-bubble li {
  margin: 4px 0;
}

.chatbot-message.bot .message-bubble code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: #ef4444;
}

.chatbot-message.bot .message-bubble pre {
  background: #1f2937;
  color: #f9fafb;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.chatbot-message.bot .message-bubble pre code {
  background: transparent;
  padding: 0;
  color: #f9fafb;
  font-size: 13px;
}

.chatbot-message.bot .message-bubble blockquote {
  border-left: 3px solid var(--adw-chatbot-primary);
  padding-left: 12px;
  margin: 8px 0;
  color: #6b7280;
  font-style: italic;
}

.chatbot-message.bot .message-bubble a {
  color: var(--adw-chatbot-primary);
  text-decoration: none;
  font-weight: 500;
}

.chatbot-message.bot .message-bubble a:hover {
  text-decoration: underline;
}

.chatbot-message.bot .message-bubble strong {
  font-weight: 600;
  color: #111827;
}

.chatbot-message.bot .message-bubble em {
  font-style: italic;
}

.chatbot-message.bot .message-bubble hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 12px 0;
}

.chatbot-message.bot .message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.chatbot-message.bot .message-bubble th,
.chatbot-message.bot .message-bubble td {
  border: 1px solid #e5e7eb;
  padding: 6px 8px;
  text-align: left;
}

.chatbot-message.bot .message-bubble th {
  background: #f9fafb;
  font-weight: 600;
}

.chatbot-message.user .message-bubble {
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: white;
  box-shadow: 0 2px 12px rgba(var(--adw-chatbot-primary-rgb), 0.3);
}

.message-time {
  font-size: 11px;
  color: #9ca3af;
  padding: 0 4px;
}

.chatbot-message.user .message-time {
  text-align: right;
}

/* Typing Indicator */
#chatbot-typing-indicator {
  padding: 0 20px 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.typing-bubble {
  background: white;
  border: 1px solid #e5e7eb;
  padding: 12px 16px;
  border-radius: 18px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-bubble span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: typing 1.4s ease-in-out infinite;
}

.typing-bubble span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-bubble span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Quick Actions */
#chatbot-quick-actions {
  padding: 12px 20px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid #f3f4f6;
  background: #fafafa;
}

.quick-action-btn {
  background: white;
  border: 1px solid #e5e7eb;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: #4b5563;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.quick-action-btn:hover {
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(var(--adw-chatbot-primary-rgb), 0.3);
}

/* Input Container */
#chatbot-input-container {
  border-top: 1px solid #e5e7eb;
  background: white;
  position: relative;
}

#chatbot-input {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  gap: 8px;
}

#chatbot-upload {
  padding: 6px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--adw-chatbot-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 30px;
  height: 30px;
}

#chatbot-upload:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, rgba(var(--adw-chatbot-primary-rgb), 0.1) 0%, rgba(var(--adw-chatbot-secondary-rgb), 0.1) 100%);
  border-color: var(--adw-chatbot-primary);
  box-shadow: 0 4px 12px rgba(var(--adw-chatbot-primary-rgb), 0.2);
}

#chatbot-upload:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(var(--adw-chatbot-primary-rgb), 0.2);
}

#chatbot-upload:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  background: #f9fafb;
  border-color: #e5e7eb;
}

.chatbot-hidden-input {
  display: none !important;
}

#chatbot-text {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  padding: 6px 10px;
  background: #f9fafb;
  border-radius: 20px;
  transition: background 0.2s;
  font-family: inherit;
  resize: none;
  min-height: 28px;
  max-height: 72px;
  overflow-y: auto;
  line-height: 1.4;
}

#chatbot-text:focus {
  background: #f3f4f6;
}

#chatbot-send {
  border: none;
  background: linear-gradient(135deg, var(--adw-chatbot-primary) 0%, var(--adw-chatbot-secondary) 100%);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(var(--adw-chatbot-primary-rgb), 0.3);
}

#chatbot-send:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(var(--adw-chatbot-primary-rgb), 0.4);
}

#chatbot-send:active:not(:disabled) {
  transform: scale(0.95);
}

#chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

#chatbot-char-counter {
  position: absolute;
  /* Keep clear of the send button on the right */
  right: 54px;
  bottom: 6px;
  padding: 0;
  font-size: 10px;
  line-height: 1;
  color: #9ca3af;
  text-align: right;
  pointer-events: none;
}

/* Footer */
#chatbot-footer {
  padding: 10px;
  text-align: center;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  font-size: 12px;
  color: #6b7280;
}

#chatbot-footer a {
  color: var(--adw-chatbot-primary);
  text-decoration: none;
  font-weight: 500;
}

#chatbot-footer a:hover {
  text-decoration: underline;
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Welcome message styling */
.welcome-message {
  text-align: center;
  padding: 20px;
  color: #6b7280;
  font-size: 14px;
  animation: fadeIn 0.5s ease-out;
}

.welcome-message strong {
  color: var(--adw-chatbot-primary);
  display: block;
  font-size: 18px;
  margin-bottom: 8px;
}

/* Feedback buttons */
.message-feedback {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  animation: fadeIn 0.3s ease-out 0.5s forwards;
}

.feedback-btn {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  color: #6b7280;
}

.feedback-btn:hover {
  background: #e5e7eb;
  transform: scale(1.05);
}

.feedback-btn.active {
  border-color: var(--adw-chatbot-primary);
  background: linear-gradient(135deg, rgba(var(--adw-chatbot-primary-rgb), 0.1) 0%, rgba(var(--adw-chatbot-secondary-rgb), 0.1) 100%);
  color: var(--adw-chatbot-primary);
  font-weight: 500;
}

.feedback-btn.like-btn.active {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.feedback-btn.dislike-btn.active {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.feedback-btn:active {
  transform: scale(0.95);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  #chatbot-widget {
    width: calc(100vw - 20px);
    height: 100vh;
    right: 10px;
    bottom: 0;
  }
  
  #chatbot-toggle {
    right: 15px;
    bottom: 15px;
  }

  /* On smaller screens, show the invite above the button */
  #chatbot-invitation-bubble {
    right: 0;
    bottom: 90px;
    max-width: min(240px, calc(100vw - 90px));
    white-space: normal;
  }

  #chatbot-invitation-bubble::after {
    right: 35px;
    bottom: -8px;
    border-top: 8px solid white;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: none;
  }
}

@media (max-width: 480px) {
  #chatbot-widget {
    width: 100vw;
    height: 100vh;
    right: 0;
    bottom: 0;
  }
}
