/* Improved Chat Widget Styles */
.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
}

.chat-toggle {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  border: none;
}

.chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.chat-container {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: min(700px, 95vw); /* Increased from 600px */
  height: min(900px, 90vh); /* Increased from 800px */
  min-width: 500px; /* Increased from 450px */
  min-height: 700px; /* Increased from 600px */
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  transform-origin: bottom right;
}

.chat-container.hidden {
  display: none;
}

/* Compact header with single line layout */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  height: 48px; /* Fixed height for single line */
}

.header-content {
  display: flex;
  flex-direction: row; /* Changed to row for single line */
  align-items: center;
  gap: 16px; /* Space between title and dropdown */
  flex: 1;
}

.header-content h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.audience-selector {
  display: flex;
  align-items: center;
  gap: 6px; /* Reduced space for compact layout */
}

.audience-selector label {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
  white-space: nowrap;
}

.audience-selector select {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.audience-selector select:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.4);
}

.audience-selector select option {
  background: #333;
  color: white;
}

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

.close-button:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.user-message {
  align-self: flex-end;
}

.bot-message {
  align-self: flex-start;
}

.message-content {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 15px; /* Increased from 14px */
  line-height: 1.6; /* Increased for better readability */
}

.user-message .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.bot-message .message-content {
  background: #f8fafc;
  color: #1e293b; /* Darker for better contrast */
  border: 1px solid #e2e8f0;
  line-height: 1.7; /* Increased for better readability */
  letter-spacing: 0.01em; /* Slight letter spacing */
}

.bot-message strong {
  color: #1e293b;
  font-weight: 600;
}

.bot-message code {
  background: #e2e8f0;
  color: #475569;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 12px;
}

/* Improved message list formatting */
.bot-message ul,
.bot-message ol {
  margin: 12px 0;
  padding-left: 24px;
}

.bot-message li {
  margin: 6px 0;
  line-height: 1.6;
}

/* Better markdown support */
.bot-message h1,
.bot-message h2,
.bot-message h3 {
  margin: 16px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
}

.bot-message h1 {
  font-size: 20px;
}

.bot-message h2 {
  font-size: 18px;
  color: #334155;
}

.bot-message h3 {
  font-size: 16px;
  color: #475569;
}

.bot-message p {
  margin: 8px 0;
  line-height: 1.6;
}

.bot-message p + p {
  margin-top: 12px;
}

.bot-message br {
  display: block;
  margin: 4px 0;
  content: "";
}

.bot-message a {
  color: #667eea;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.bot-message a:hover {
  border-bottom-color: #667eea;
}

.bot-message blockquote {
  margin: 12px 0;
  padding-left: 16px;
  border-left: 3px solid #667eea;
  color: #64748b;
  font-style: italic;
}

.message-sources {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
}

.sources-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sources-header svg {
  color: #64748b;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px; /* Slightly increased gap */
  margin-top: 6px;
}

.source-item {
  display: block;
  line-height: 1.4;
}

.source-link {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 12px; /* Slightly increased padding */
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #334155;
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 13px;
  gap: 8px;
}

.source-link:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.source-link-text {
  flex: 1;
  min-width: 0;
}

.source-link-text strong {
  color: #1e293b;
  font-weight: 600;
  display: block;
  margin-bottom: 2px;
}

.source-link-description {
  color: #64748b;
  font-size: 12px;
  line-height: 1.3;
  display: block;
}

.source-link-icon {
  display: flex;
  align-items: center;
  color: #64748b;
  margin-top: 2px;
  flex-shrink: 0;
}

.source-link:hover .source-link-icon {
  color: #3b82f6;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Simplified input container without footer */
.chat-input-container {
  padding: 12px 16px; /* Reduced padding */
  border-top: 1px solid #e5e7eb;
  background: white;
}

.input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

#chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  outline: none;
  font-size: 14px;
  transition: all 0.2s ease;
  background: #f9fafb;
}

#chat-input:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chat-input::placeholder {
  color: #9ca3af;
}

#send-button {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

#send-button:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

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

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

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.loading-overlay.hidden {
  display: none;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.error-message {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 8px 0;
  font-size: 14px;
}

.retry-button {
  background: #dc2626;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  margin-top: 8px;
  transition: all 0.2s ease;
}

.retry-button:hover {
  background: #b91c1c;
}

/* Mobile responsiveness */
@media (max-width: 480px) {
  .chat-widget {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }

  .chat-container {
    width: calc(100vw - 20px);
    height: min(80vh, 600px); /* Increased mobile height */
    min-height: 400px;
    right: 0;
    bottom: 70px;
  }

  .chat-toggle {
    position: fixed;
    bottom: 10px;
    right: 10px;
  }

  .chat-header {
    padding: 8px 12px;
  }

  .header-content {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .audience-selector label {
    display: none; /* Hide label on mobile to save space */
  }
}

/* Tablet responsiveness */
@media (min-width: 481px) and (max-width: 768px) {
  .chat-container {
    width: min(480px, 90vw);
    height: min(650px, 80vh);
  }
}

/* Animation for widget appearance */
.chat-container {
  animation: slideInUp 0.3s ease-out;
}

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

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

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Smooth transitions for all interactive elements */
button,
input,
select,
a {
  transition: all 0.2s ease;
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Improved link styling in messages */
.message-content a {
  color: #667eea;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content a:hover {
  color: #764ba2;
}
