/* Common Styles */
#scai-chatbot-container {
  /* Default fallback values - will be overridden by dynamic CSS from admin settings */
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --secondary-color: #e5e7eb;
  --text-color: #111827;
  --bg-color: #ffffff;
  --message-bot-bg: #f3f4f6;
  --message-user-bg: #4f46e5;
  --message-user-color: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --border-radius: 16px;
  --border-radius-lg: 24px;
  --input-bg: #f9fafb;
  --backdrop-blur: blur(16px);
  --gradient-primary: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  --gradient-primary-hover: linear-gradient(135deg, var(--primary-hover), #3730a3);
  --gradient-light: linear-gradient(135deg, var(--primary-light), #f0f9ff);
  --online-color: #10b981;
  --online-pulse: #6ee7b7;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue",
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-color);
}

.scai-dark-mode {
  --primary-color: #6366f1;
  --primary-hover: #5b21b6;
  --primary-light: #312e81;
  --secondary-color: #374151;
  --text-color: #f9fafb;
  --bg-color: #1f2937;
  --message-bot-bg: #374151;
  --message-user-bg: #6366f1;
  --message-user-color: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
  --input-bg: #111827;
  --gradient-primary: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  --gradient-primary-hover: linear-gradient(135deg, var(--primary-hover), #4c1d95);
  --gradient-light: linear-gradient(135deg, var(--primary-light), #1e1b4b);
  --online-color: #10b981;
  --online-pulse: #6ee7b7;
}

/* Chat Button */
#scai-chat-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 99999999999999 !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 0;
  outline: none;
}

#scai-chat-button:hover {
  transform: scale(1.05);
  background: var(--gradient-primary-hover);
  box-shadow: var(--shadow-xl);
}

#scai-chat-button:active {
  transform: scale(0.95);
}

/* Ping animation for new messages */
#scai-chat-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background: var(--gradient-primary);
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
  opacity: 0;
  z-index: -1;
}

@keyframes ping {
  75%, 100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

/* Popup Chat */
.scai-popup-mode #scai-chat-popup {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 384px;
  height: 500px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: var(--backdrop-blur);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  display: none;
  animation: slideInFromBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.scai-dark-mode .scai-popup-mode #scai-chat-popup {
  background: rgba(31, 41, 55, 0.95);
  border: 1px solid rgba(55, 65, 81, 0.3);
}

@keyframes slideInFromBottom {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Ensure the popup has proper layout when visible */
.scai-popup-mode #scai-chat-popup.active {
  display: flex;
  animation: slideInFromBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#scai-chat-header {
  padding: 16px 20px;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
  position: relative;
  overflow: hidden;
  min-height: 64px;
}

/* Dot pattern overlay for header */
#scai-chat-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: radial-gradient(circle at 2px 2px, rgba(255, 255, 255, 0.15) 1px, transparent 0);
  background-size: 20px 20px;
  pointer-events: none;
}

#scai-chat-header .scai-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
  flex: 1;
}

#scai-chat-header .scai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
#scai-chat-header .scai-avatar svg {
  fill: white;
}
#scai-chat-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.025em;
  color: #fff;
}

#scai-close-chat,
#scai-close-full-chat {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  margin: 0;
  border-radius: 50%;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 1;
  border-radius: 99px !important;
}

#scai-close-chat:hover,
#scai-close-full-chat:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

#scai-close-chat:active,
#scai-close-full-chat:active {
  transform: scale(0.95);
}

/* Update the chat messages container to fix scrolling */
#scai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  max-height: calc(100% - 140px); /* Account for header and input area */
  overscroll-behavior: contain; /* Prevent scroll chaining */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scroll-behavior: smooth;
  background: var(--bg-color);
}

/* Custom scrollbar */
#scai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

#scai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

#scai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

.scai-dark-mode #scai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

.scai-dark-mode #scai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.scai-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 20px;
  line-height: 1.5;
  font-size: 14px;
  position: relative;
  animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.scai-bot-message {
  align-self: flex-start;
  background: var(--message-bot-bg);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-bottom-left-radius: 6px;
  color: var(--text-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.scai-dark-mode .scai-bot-message {
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.scai-user-message {
  align-self: flex-end;
  background: var(--gradient-primary);
  color: var(--message-user-color);
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.scai-dark-mode .scai-user-message {
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Link styles in chat messages */
.scai-message-content a {
  color: #2563eb;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
}

.scai-message-content a:hover {
  color: #1d4ed8;
  text-decoration-thickness: 2px;
  text-shadow: 0 0 8px rgba(37, 99, 235, 0.3);
}

.scai-message-content a:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Dark mode link styles */
.scai-dark-mode .scai-message-content a {
  color: #60a5fa;
}

.scai-dark-mode .scai-message-content a:hover {
  color: #93c5fd;
  text-shadow: 0 0 8px rgba(96, 165, 250, 0.4);
}

.scai-dark-mode .scai-message-content a:focus {
  outline-color: #60a5fa;
}

#scai-chat-input-container {
  display: flex;
  padding: 16px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(249, 250, 251, 0.5);
  backdrop-filter: var(--backdrop-blur);
  align-items: flex-end;
  gap: 12px;
  border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

.scai-dark-mode #scai-chat-input-container {
  background: rgba(17, 24, 39, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#scai-chat-input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 20px;
  padding: 12px 16px;
  resize: none;
  outline: none;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: var(--backdrop-blur);
  color: var(--text-color);
  font-size: 14px;
  max-height: 120px;
  min-height: 44px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  line-height: 1.4;
}

.scai-dark-mode #scai-chat-input {
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-color);
}

#scai-chat-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: rgba(255, 255, 255, 1);
}

.scai-dark-mode #scai-chat-input:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background: rgba(17, 24, 39, 1);
}

#scai-chat-input::placeholder {
  color: rgba(0, 0, 0, 0.4);
}

.scai-dark-mode #scai-chat-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

#scai-send-message {
  background: var(--gradient-primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  flex-shrink: 0;
  margin-right: 0;
  padding: 0px;
}

#scai-send-message:hover:not(:disabled) {
  background: var(--gradient-primary-hover);
}

#scai-send-message:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#scai-send-message svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s;
}

#scai-send-message:hover:not(:disabled) svg {
  transform: translateX(1px);
}

.scai-dark-mode #scai-send-message {
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.scai-dark-mode #scai-send-message:hover:not(:disabled) {
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

/* Full Page Chat */
.scai-full-page-mode #scai-full-page-chat {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  z-index: 999999;
  display: none;
  flex-direction: column;
}

.scai-full-page-mode #scai-chat-header {
  padding: 20px;
}

.scai-full-page-mode #scai-chat-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #fff;
}

#scai-header-actions {
  display: flex;
  gap: 10px;
}

#scai-toggle-theme {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: background-color 0.2s;
}

#scai-toggle-theme:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.scai-full-page-mode #scai-chat-messages {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.scai-full-page-mode .scai-message {
  max-width: 70%;
}

.scai-full-page-mode #scai-chat-input-container {
  padding: 15px 20px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* Responsive Styles */
@media (max-width: 768px) {
  .scai-popup-mode #scai-chat-popup {
    width: calc(100vw - 32px);
    height: min(500px, calc(100vh - 120px));
    bottom: 88px;
    right: 16px;
    left: 16px;
    margin: 0 auto;
  }

  #scai-chat-button {
    bottom: 20px;
    right: 20px;
  }

  .scai-full-page-mode .scai-message {
    max-width: 85%;
  }

  #scai-chat-messages {
    padding: 16px;
    gap: 12px;
  }

  #scai-chat-input-container {
    padding: 12px 16px;
  }

  #scai-chat-header {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .scai-popup-mode #scai-chat-popup {
    width: calc(100vw - 16px);
    height: min(450px, calc(100vh - 100px));
    bottom: 84px;
    right: 8px;
    left: 8px;
  }

  #scai-chat-button {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }
}

/* Loading Indicator */
.scai-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--message-bot-bg);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  align-self: flex-start;
  margin-bottom: 8px;
  animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.scai-dark-mode .scai-loading {
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.scai-loading span {
  width: 8px;
  height: 8px;
  background-color: var(--primary-color);
  border-radius: 50%;
  animation: scai-loading 1s infinite alternate;
}

.scai-loading span:nth-child(2) {
  animation-delay: 0.2s;
}

.scai-loading span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes scai-loading {
  0% {
    opacity: 0.3;
  }
  100% {
    opacity: 1;
  }
}

/* Message animation */
.scai-message {
  animation: message-fade-in 0.3s ease-out;
}

@keyframes message-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Typing indicator */
.scai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 12px 16px;
  background: var(--message-bot-bg);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  align-self: flex-start;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-color);
  animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.scai-dark-mode .scai-typing-indicator {
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.scai-typing-indicator .scai-typing-text {
  font-weight: 500;
  opacity: 0.7;
}

.scai-typing-indicator span {
  width: 4px;
  height: 4px;
  background-color: var(--text-color);
  border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s infinite both;
}

.scai-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.scai-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0% {
    opacity: 0.4;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-4px);
  }
  100% {
    opacity: 0.4;
    transform: translateY(0);
  }
}
