/**
 * Public CSS for Hello World FastAPI Chatbot - Floating Widget
 */

/* Floating Chatbot Widget */
.floating-chatbot-widget {
  position: fixed;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* Inline Chatbot Widget (for shortcode) */
.inline-chatbot-widget {
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  margin: 20px auto;
  max-width: 800px;
}

/* Position variants for floating widget */
.floating-chatbot-widget[data-position="bottom-right"] {
  bottom: 20px;
  right: 40px;
}

.floating-chatbot-widget[data-position="bottom-left"] {
  bottom: 20px;
  left: 20px;
}

.floating-chatbot-widget[data-position="top-right"] {
  top: 20px;
  right: 40px;
}

.floating-chatbot-widget[data-position="top-left"] {
  top: 20px;
  left: 20px;
}

/* Toggle Button (only for floating mode) */
.floating-chatbot-widget .chatbot-toggle-button {
  position: relative;
  width: 50px;
  height: 50px;
  /* background: linear-gradient(to right, #8a2be2, #4b0082); */
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  border: none;
  z-index: 10000;
}

.floating-chatbot-widget .chatbot-toggle-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.18);
  /* background: unset; */
}

.floating-chatbot-widget .chatbot-toggle-button.active {
  /* background: linear-gradient(to right, #4b0082, #8a2be2); */
}

.button-icon {
  color: white;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.button-icon svg {
  transition: all 0.3s ease;
  width: 24px;
  height: 24px;
  display: block;
}

/* Notification Badge */
.notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #dc3545;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Chatbot Popup */
.chatbot-popup {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid #e1e5e9;
  width: 360px;
  height: 560px;
  z-index: 10001;
}

/* Floating popup positioning */
.floating-chatbot-widget .chatbot-popup {
  position: absolute;

  /* Responsive bounding so the popup never exceeds viewport on tablets/laptops */
  max-width: calc(100vw - 40px); /* keep small side margins */
  max-height: calc(100vh - 120px); /* leave room for toggle & breathing space */
}

/* Inline popup (for shortcode) */
.inline-chatbot-widget .chatbot-popup {
  position: relative;
  display: flex !important;
}

/* Position the floating popup based on widget position */
.floating-chatbot-widget[data-position="bottom-right"] .chatbot-popup,
.floating-chatbot-widget[data-position="top-right"] .chatbot-popup {
  right: 0;
}

.floating-chatbot-widget[data-position="bottom-left"] .chatbot-popup,
.floating-chatbot-widget[data-position="top-left"] .chatbot-popup {
  left: 0;
}

.floating-chatbot-widget[data-position="bottom-right"] .chatbot-popup,
.floating-chatbot-widget[data-position="bottom-left"] .chatbot-popup {
  bottom: 64px;
}

.floating-chatbot-widget[data-position="top-right"] .chatbot-popup,
.floating-chatbot-widget[data-position="top-left"] .chatbot-popup {
  top: 80px;
}

.floating-chatbot-widget .chatbot-popup.show {
  display: flex !important;
  animation: popupSlideIn 0.3s ease-out;
}

/* Debug: Ensure show class overrides display none */
.chatbot-popup.show {
  display: flex !important;
}

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

/* Header */
.chatbot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: linear-gradient(to right, #8a2be2, #4b0082);
  color: white;
}

.chatbot-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.chatbot-header-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 10px;
  object-fit: cover;
  background-color: #f0f0f0; /* Placeholder background */
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #6c757d;
  transition: background-color 0.3s ease;
}

.status-indicator.connected {
  background-color: #28a745;
  box-shadow: 0 0 8px rgba(40, 167, 69, 0.6);
}

.status-indicator.disconnected {
  background-color: #dc3545;
  box-shadow: 0 0 8px rgba(220, 53, 69, 0.6);
}

.status-indicator.busy,
.status-indicator.processing {
  background-color: #ffc107;
  box-shadow: 0 0 8px rgba(255, 193, 7, 0.6);
  animation: pulse 2s infinite;
}

.minimize-button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.minimize-button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Messages Container */
.chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
}

.chatbot-message {
  margin-bottom: 16px;
  display: flex;
  animation: fadeIn 0.3s ease-in;
  align-items: flex-start;
  gap: 4px;
}

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

.chatbot-message.user-message {
  justify-content: flex-end;
}

.chatbot-message.bot-message {
  justify-content: flex-start;
}

/* Message Content */
.message-content {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
  /* Ensure consistent base font size */
  font-size: 14px !important;
  /* Prevent theme font inheritance */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif !important;
}

/* Override any inherited font sizes from WordPress themes */
.message-content * {
  font-family: inherit !important;
}

/* Gradient background for user messages */
.user-message .message-content {
  background: var(
    --chatbot-gradient,
    linear-gradient(to right, #8a2be2, #4b0082)
  ) !important;
  color: #ffffff !important;
  border-radius: 18px !important;
  border-bottom-right-radius: 4px !important;
}

.bot-message .message-content {
  background-color: #fff;
  color: #333;
  border: 1px solid #e1e5e9;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.error-message .message-content {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

/* Message Content Formatting */
.message-content h4 {
  margin: 0 0 12px 0;
  font-size: 14px !important;
  font-weight: 600;
  color: #007cba;
}

.message-content p {
  margin: 0 0 12px 0;
  font-size: 14px !important;
  line-height: 1.5;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul {
  margin: 12px 0;
  padding-left: 18px;
  font-size: 14px !important;
  line-height: 1.5;
}

.message-content ol {
  margin: 12px 0;
  padding-left: 18px;
  font-size: 14px !important;
  line-height: 1.5;
}

.message-content li {
  margin-bottom: 6px;
  line-height: 1.4;
  font-size: 14px !important;
}

.message-content li:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 600;
  color: #333;
  font-size: inherit !important;
}

.message-content em {
  font-style: italic;
  color: #666;
  font-size: 13px !important;
}

.message-content code {
  background-color: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: "Courier New", Courier, monospace;
  font-size: 13px !important;
}

.message-content pre {
  background-color: rgba(0, 0, 0, 0.1);
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0;
  font-size: 13px !important;
}

/* Better spacing for bot messages */
.bot-message .message-content h4:first-child {
  margin-top: 0;
}

.bot-message .message-content p + ul,
.bot-message .message-content h4 + ul {
  margin-top: 8px;
}

/* Message Sources */
.message-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.source-item {
  display: inline-block;
  background-color: rgba(0, 123, 186, 0.1);
  color: #007cba;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  margin: 0 4px 4px 0;
  font-weight: 500;
}

/* Input Container */
.chatbot-input-container {
  padding: 6px 20px 28px; /* extra bottom space for footer labels */
  background-color: #f8f9fa;
  border-top: 1px solid #e1e5e9;
  position: relative;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 6px;
  border: 1px solid #ced4da;
  border-radius: 25px;
  background-color: #ffffff;
}

/* Microphone + Send buttons share the same look */
.mic-button,
.send-button {
  background: var(
    --chatbot-gradient,
    linear-gradient(to right, #8a2be2, #4b0082)
  );
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
}

.mic-button:hover,
.send-button:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.send-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.mic-button.recording {
  background: #ef4444;
  color: #ffffff;
  animation: pulse 1.2s infinite;
}

.loading-spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.chatbot-info {
  position: absolute;
  bottom: 6px;
  left: 20px;
  font-size: 10px;
  color: #6c757d;
}

.stt-status {
  position: absolute;
  bottom: 6px;
  right: 20px;
  font-size: 10px !important; /* match branding */
  line-height: 1;
}

/* Scrollbar */
.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #ced4da;
  border-radius: 2px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  /* When popup is open, hide the toggle button to avoid overlap */
  .floating-chatbot-widget .chatbot-toggle-button.active {
    display: none;
  }

  /* Ensure full-screen flex layout only when visible */
  .floating-chatbot-widget .chatbot-popup.show {
    display: flex !important;
    flex-direction: column;
  }

  /* Respect device safe-area (e.g. iPhone notch / home bar) */
  .chatbot-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  .chatbot-input-container {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .floating-chatbot-widget[data-position*="right"] {
    right: 20px;
  }

  .floating-chatbot-widget[data-position*="left"] {
    left: 10px;
  }

  .floating-chatbot-widget[data-position*="bottom"] {
    bottom: 10px;
  }

  .floating-chatbot-widget .chatbot-popup {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }

  .floating-chatbot-widget .chatbot-toggle-button {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .message-content {
    max-width: 90%;
  }

  .chatbot-header {
    padding: 12px 16px;
  }

  .chatbot-input-container {
    padding: 12px 16px 20px; /* extra bottom space for branding/STT */
  }
}

@media (max-width: 480px) {
  .floating-chatbot-widget .chatbot-popup {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }

  .chatbot-messages {
    padding: 16px;
  }

  .message-content {
    /* Slightly tighter padding for very small screens */
    padding: 8px 10px;
  }

  /* Reduce header/input padding further on extra-small screens */
  .chatbot-header {
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .chatbot-input-container {
    padding: 10px 12px 40px 12px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}

/* Legacy support for old container class */
.hello-world-chatbot-container {
  display: none;
}

/* Inline chatbot container for specific theme compatibility */
.hello-world-chatbot-container {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* Thinking Message Animation */
.thinking-message {
  opacity: 0.7;
}

.thinking-animation {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  justify-content: flex-start;
}

.thinking-animation .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(
    --chatbot-gradient,
    linear-gradient(to right, #8a2be2, #4b0082)
  );
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.thinking-animation .dot.active {
  opacity: 1;
  animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
  0%,
  20%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
  60% {
    transform: translateY(-4px);
  }
}

/* Progressive response styling */
.thinking-message .message-content {
  background-color: #ffffff !important;
  border-left: none !important;
}

/* Enhanced fade transition for thinking message removal */
.thinking-message.fadeOut {
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 20px 20px;
  background-color: #f8f9fa;
  border-top: 1px solid #e9ecef;
}

.quick-action-button {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: #f0f2f5;
  border: 1px solid #e1e5e9;
  border-radius: 8px;
  padding: 12px 15px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.quick-action-button:hover {
  background-color: #e0e4e8;
  border-color: #d1d5d9;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.button-emoji {
  font-size: 18px;
}

/* Avatar Styles */
.chatbot-message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

/* Positioning adjustments */
.user-message .avatar {
  margin-left: 4px;
}

.bot-message .avatar {
  margin-right: 4px;
}

.chatbot-input-container input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 10px;
  font-size: 14px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif !important;
  outline: none;
}

.chatbot-input-container input[type="text"]:focus {
  box-shadow: none;
}

.chatbot-input-container textarea {
  flex: 1;
  background: transparent;
  padding: 0 10px; /* vertical padding removed, horizontal kept */
  font-size: 14px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif !important;
  outline: none !important;
  border: none !important;
  resize: none !important;
  overflow: hidden; /* hide scroll until max-height reached by JS */
  height: 20px; /* single-line */
  line-height: 20px;
  min-height: 20px;
  max-height: 160px;
}

.chatbot-input-container textarea:focus {
  box-shadow: none !important;
  outline: none !important;
}

.stt-status {
  display: none; /* toggled via JS */
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.85rem;
  color: #6b7280; /* neutral gray */
}

.stt-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top: 2px solid var(--primary-color, #8a2be2);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.stt-status.recording {
  color: #ef4444; /* red matches mic when recording */
}

.stt-dot {
  opacity: 0;
  animation: blink 1.2s infinite;
}

.dot1 {
  animation-delay: 0s;
}
.dot2 {
  animation-delay: 0.2s;
}
.dot3 {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.tts-button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding-left: 6px;
  color: #9ca3af;
  transition: color 0.2s;
}

.tts-button:hover {
  color: var(--primary-color, #8a2be2);
}

/* Extra-small: flex layout only when popup is visible */
.floating-chatbot-widget .chatbot-popup.show {
  display: flex !important;
  flex-direction: column;
}

/* Ensure the chatbot is always on top of all other page elements */
.floating-chatbot-widget,
.floating-chatbot-widget .chatbot-toggle-button,
.floating-chatbot-widget .chatbot-popup,
.inline-chatbot-widget,
.inline-chatbot-widget .chatbot-popup,
.chatbot-popup {
  z-index: 2147483647 !important;
}
