/* Chat-specific styles */

/* Chat message containers */
.message {
  padding: 10px 15px;
  border-radius: 8px;
  max-width: 80%;
  margin-bottom: 16px;
  position: relative;
}

.user-message {
  background-color: #e9ecef;
  color: #212529;
  margin-left: auto;
  border-top-right-radius: 0;
}

.assistant-message {
  background-color: #f0f7ff;
  color: #1a365d;
  margin-right: auto;
  border-top-left-radius: 0;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.message-body {
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-body p {
  margin-bottom: 8px;
}

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

/* Citations */
.citation {
  font-size: 0.8em;
  color: #6c757d;
  border-left: 2px solid #dee2e6;
  padding-left: 8px;
  margin-top: 10px;
}

/* Citation Modal Styles - Improved */
#citation-modal {
  z-index: 10000; /* Ensure it's above everything else */
  overflow-y: auto;
}

#citation-modal-box {
  max-height: 80vh; /* Increased height to show more content */
  width: 60%; /* Set width to 60% of screen */
  max-width: 800px; /* Maximum width for very large screens */
  min-width: 320px; /* Minimum width for very small screens */
  overflow-y: auto;
  margin: 0 auto; /* Center horizontally */
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  padding: 1.5rem 2rem; /* More padding for better spacing */
}

/* Loading spinner improvements */
#citation-loading {
  padding: 3rem 0;
}

#citation-loading .animate-spin {
  height: 3rem;
  width: 3rem;
  border-width: 4px;
  border-color: #6366f1;
  border-top-color: transparent;
}

/* Text area improvements */
#citation-text {
  width: 100%;
  padding: 1rem;
  border-radius: 0.375rem;
  background-color: #f8f9fa;
  font-size: 0.95rem;
  line-height: 1.6;
  min-height: 150px; /* Minimum height */
  max-height: none; /* Remove height restriction */
  height: auto; /* Let it expand as needed */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  transition: all 0.3s ease;
  overflow-y: auto;
  resize: vertical; /* Allow user to resize vertically */
  border: 1px solid #e2e8f0;
}

/* Make text area much larger initially */
#citation-text.max-h-48 {
  max-height: 350px !important; /* Override the small height */
}

#citation-text.max-h-full {
  max-height: none !important; /* Remove any height restriction when expanded */
}

#citation-toggle-btn {
  display: inline-block;
  margin-top: 0.75rem;
  color: #4f46e5;
  font-weight: 500;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  transition: all 0.2s;
  background-color: #eef2ff;
}

#citation-toggle-btn:hover {
  background-color: #e0e7ff;
  color: #4338ca;
}

/* Responsive improvements */
@media (max-width: 768px) {
  #citation-modal-box {
    width: 85%; /* Wider on smaller screens */
    padding: 1.25rem;
  }
}

@media (max-width: 640px) {
  #citation-modal-box {
    width: 95%; /* Almost full width on mobile */
    padding: 1rem;
  }
}

/* Style modal content with better spacing */
#citation-content {
  padding: 0.75rem 0;
}

#citation-content strong {
  color: #4b5563;
  font-weight: 600;
}

#citation-content span {
  word-break: break-word;
}

/* Better file info section */
#citation-content .bg-gray-50 {
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  margin-bottom: 1.25rem;
}

/* Better close button */
#citation-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background-color: #f3f4f6;
  border-radius: 9999px;
  padding: 0.35rem;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

#citation-modal-close:hover {
  background-color: #e5e7eb;
}

/* Animation for modal content */
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

#citation-content.visible {
  animation: fadeInScale 0.3s ease forwards;
}

/* Modal title improvements */
#citation-modal-box h2 {
  margin-bottom: 1.25rem;
  color: #1f2937;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.75rem;
}

/* Message input area */
#message-input {
  resize: none;
  overflow: hidden;
  min-height: 38px;
  max-height: 150px;
  transition: height 0.2s ease;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background-color: #f0f7ff;
  border-radius: 8px;
  color: #1a365d;
  max-width: fit-content;
  margin-bottom: 16px;
}

.typing-dot {
  height: 8px;
  width: 8px;
  background-color: #4f46e5;
  border-radius: 50%;
  display: inline-block;
  margin: 0 1px;
  animation: typing 1.3s infinite;
}

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

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

.typing-label {
  margin-right: 6px;
  font-weight: 500;
}

@keyframes typing {
  0% {
    transform: translateY(0px);
    background-color: #4f46e5;
  }
  28% {
    transform: translateY(-5px);
    background-color: #818cf8;
  }
  44% {
    transform: translateY(0px);
    background-color: #4f46e5;
  }
}

/* Sidebar */
.conversation-item {
  transition: background-color 0.2s ease;
}

.conversation-item:hover .edit-conversation-btn,
.conversation-item:hover .delete-conversation-btn {
  opacity: 1;
}

.edit-conversation-btn,
.delete-conversation-btn {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Markdown styling for chat messages */
.message-body a {
  color: #2563eb;
  text-decoration: underline;
}

.message-body code {
  padding: 2px 4px;
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  font-family: monospace;
}

.message-body pre {
  margin: 10px 0;
  padding: 12px;
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  overflow-x: auto;
}

.message-body pre code {
  background-color: transparent;
  padding: 0;
}

.message-body ul,
.message-body ol {
  margin-left: 24px;
  margin-bottom: 16px;
}

.message-body ul {
  list-style-type: disc;
}

.message-body ol {
  list-style-type: decimal;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4,
.message-body h5,
.message-body h6 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
}

.message-body blockquote {
  border-left: 4px solid #e5e7eb;
  padding-left: 16px;
  margin: 16px 0;
  color: #6b7280;
}

/* Loading state for send button */
.btn-loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
}

.btn-loading:after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  animation: spin 1s linear infinite;
}

  .typing-indicator {
    display: flex;
    align-items: center;
    margin: 10px 0;
    font-family: sans-serif;
    font-size: 14px;
    color: #555;
  }

  .typing-dot {
    height: 8px;
    width: 8px;
    background-color: #555;
    border-radius: 50%;
    margin: 0 2px;
    animation: blink 1.4s infinite both;
  }

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

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

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



/* Sidebar toggle styles */
#sidebar {
  position: relative;
  z-index: 40;
}

/* Collapsed state for sidebar */
#sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

/* Show full sidebar on hover only on desktop when collapsed */
@media (min-width: 768px) {
  #sidebar.collapsed:hover {
    width: 64px;
    min-width: 64px;
  }

  #sidebar.collapsed:hover .conversation-item div.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #sidebar.collapsed:hover .edit-conversation-btn,
  #sidebar.collapsed:hover .delete-conversation-btn {
    display: none;
  }
}

/* Expanded sidebar icon */
#sidebar-collapse .fa-chevron-left {
  transition: transform 0.3s ease;
}

#sidebar.collapsed #sidebar-collapse .fa-chevron-left {
  transform: rotate(180deg);
}

/* Mobile sidebar toggle */
#sidebar-toggle {
  transition: left 0.3s ease;
}

#sidebar-toggle.sidebar-open {
  left: 16rem; /* 256px */
}

/* Mobile sidebar styles */
@media (max-width: 767px) {
  /* Position the sidebar for mobile */
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -100% !important; /* Start off-screen */
    width: 80% !important; /* Use percentage instead of fixed width */
    max-width: 300px !important;
    z-index: 40 !important; /* Higher z-index to overlay content */
    transition: left 0.3s ease !important; /* Smooth transition */
    height: 100vh !important; /* Full height */
  }

  /* Open state for mobile sidebar */
  #sidebar.sidebar-open {
    left: 0 !important;
  }

  /* Make sure the toggle button is visible and positioned correctly */
  #sidebar-toggle {
    display: block !important;
  }

  /* Add overlay for mobile sidebar */
  .sidebar-overlay {
    position: fixed;
    inset: 0; /* Cover the entire screen */
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 30; /* Below sidebar but above content */
  }
}

/* Adjust the chat container when sidebar is collapsed on desktop */
@media (min-width: 768px) {
  .chat-container.sidebar-collapsed {
    margin-left: 0;
  }
}

/* Hide the sidebar toggle button on desktop */
#sidebar-toggle {
  display: none;
}

@media (max-width: 767px) {
  #sidebar-toggle {
    display: block;
  }
}

/* Sources styling - updated based on the screenshot */
.sources-container {
  margin-top: 20px;
  border-top: 1px solid #e5e7eb;
  padding-top: 15px;
}

.sources-header {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: #1a365d;
}

.sources-header i {
  margin-right: 10px;
  transition: transform 0.3s ease;
}

.sources-header.collapsed i {
  transform: rotate(-90deg);
}

.sources-header h3 {
  margin: 0;
  font-size: 1rem;
}

.sources-content {
  overflow: hidden;
  transition: max-height 0.5s ease;
  max-height: 2000px; /* Increased to accommodate more content */
}

.sources-content.collapsed {
  max-height: 0;
}

.source-item {
  margin-bottom: 16px;
  border-left: 3px solid #4f46e5;
  padding-left: 15px;
  background-color: #f9fafb;
  border-radius: 0 4px 4px 0;
}

.source-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px 10px 10px;
  background-color: #f3f4f6;
  border-radius: 0 4px 0 0;
  font-weight: 600;
}

.source-title h4 {
  margin: 0;
  font-size: 0.95rem;
  color: #1f2937;
}

.source-file {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  color: #4b5563;
  margin: 10px 0;
  word-break: break-word;
}

.source-file i {
  margin-right: 5px;
  color: #6b7280;
  flex-shrink: 0;
}

.source-file a {
  color: #4f46e5;
  text-decoration: none;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.source-file a:hover {
  text-decoration: underline;
}

.source-content {
  padding: 10px 15px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #4b5563;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Make sure long file names don't overflow */
.source-file {
  display: flex;
  flex-wrap: wrap;
}

/* Ensure mobile responsiveness */
@media (max-width: 640px) {
  .source-file {
    flex-direction: column;
    align-items: flex-start;
  }

  .source-file i {
    margin-bottom: 5px;
  }
}

.message-body h1,
.message-body h2,
.message-body h3 {
  font-weight: bold;
  margin-top: 1em;
  margin-bottom: 0.5em;
}

.message-body pre {
  background-color: #f4f4f4;
  padding: 10px;
  overflow-x: auto;
}

.message-body code {
  font-family: monospace;
  background: #eee;
  padding: 2px 4px;
  border-radius: 4px;
}

/* Loading spinner fix */
#citation-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem 0;
  height: 120px; /* Explicit height */
}

/* Define the spinner explicitly without relying on Tailwind classes */
#citation-loading .animate-spin,
#citation-loading div {
  height: 48px;
  width: 48px;
  border: 4px solid #6366f1; /* Indigo-500 */
  border-top-color: transparent;
  border-radius: 50%;
  animation: spinner-animation 1s linear infinite;
}

/* Define the animation explicitly */
@keyframes spinner-animation {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Ensure the loading element is visible */
#citation-loading.hidden {
  display: none;
}
