/* Ask AI button styling */
.ai-button {
  position: relative;
  transition: all 0.3s ease;
}

.ai-button:hover {
  transform: scale(1.05);
}

.ai-indicator {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 0 2px #ffffff;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Ask AI Sidebar styling */
.ask-ai-sidebar {
  position: fixed;
  top: 0;
  right: -450px;
  width: 450px;
  height: 100vh;
  background-color: #fff;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  z-index: 1050;
  transition: right 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* When sidebar is in a turbo-permanent container */
#permanent_elements_container .ask-ai-sidebar {
  position: fixed;
}

.ask-ai-sidebar.visible {
  right: 0;
}

/* Add overlay for mobile devices */
.ask-ai-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1040;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ask-ai-overlay.visible {
  display: block;
  opacity: 1;
}

/* Debug styles for visibility issues */
.debug-outline {
  /* Removed red outline - was distracting */
}

.ask-ai-sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.ask-ai-sidebar .chat-container {
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.ask-ai-sidebar .chat-messages-container {
  height: calc(100% - 150px);
  /* Adjust for header and input container in sidebar */
}

@media (max-width: 576px) {
  .ask-ai-sidebar {
    width: 100%;
    right: -100%;
  }
}

/* Chat UI Components */
.ask-ai-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100vh;
  overflow: hidden;
}

.chat-header {
  padding: 1rem;
  border-bottom: 1px solid #ddd;
  background-color: #f8f9fa;
  flex-shrink: 0;
}

.chat-messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  scroll-behavior: smooth;
  height: calc(100% - 120px);
  min-height: 100px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  overflow-anchor: none;
}

.chat-message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  position: relative;
  transition: all 0.3s ease-in-out;
}

.user-message {
  align-self: flex-end;
  background-color: #007bff;
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.assistant-message {
  align-self: flex-start;
  background-color: #f0f0f0;
  border-radius: 18px 18px 18px 4px;
}

.chat-input-container {
  padding: 1rem;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

.message-time {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  opacity: 0.7;
  text-align: right;
}

.chat-welcome {
  text-align: center;
  margin: 3rem 0;
  color: #6c757d;
}

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

.date-separator {
  text-align: center;
  margin: 1rem 0;
  position: relative;
}

.date-separator::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #ddd;
  z-index: 1;
}

.date-separator span {
  background-color: #fff;
  padding: 0 1rem;
  position: relative;
  z-index: 2;
  font-size: 0.85rem;
  color: #6c757d;
}

/* Typing indicator styles */
.typing-indicator {
  padding: 0.75rem;
  min-width: 100px;
}

.typing-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
}

.typing-dots .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #888;
  animation: typing-dot 1.4s infinite ease-in-out both;
}

.typing-dots .dot:nth-child(1) {
  animation-delay: -0.32s;
}

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

@keyframes typing-dot {

  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.5;
  }

  40% {
    transform: scale(1.0);
    opacity: 1;
  }
}

/* Typewriter effect cursor */
.typewriting .message-content::after {
  content: '|';
  display: inline-block;
  opacity: 1;
  animation: cursor-blink 0.7s infinite;
  margin-left: 2px;
}

@keyframes cursor-blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

/* Markdown content styling */
.message-content pre {
  background-color: #f5f5f5;
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content code {
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 0.9rem;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.message-content ul,
.message-content ol {
  padding-left: 1.5rem;
}

.message-content p {
  margin-bottom: 0.5rem;
}

.message-content a {
  color: #0066cc;
  text-decoration: underline;
}

.message-content table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  width: 100%;
}

.message-content th,
.message-content td {
  border: 1px solid #ddd;
  padding: 0.3rem 0.5rem;
}

.message-content th {
  background-color: #f2f2f2;
}

/* Scroll marker to ensure scrolling works */
#chat-scroll-marker {
  height: 2px;
  width: 100%;
  margin-top: 20px;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
}

/* System message styling */
.system-message {
  align-self: center;
  background-color: #f8f9fa;
  border-radius: 12px;
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  max-width: 80%;
  text-align: center;
  border: 1px solid #dee2e6;
  opacity: 0.85;
  transition: all 0.3s ease;
}

.system-message:hover {
  opacity: 1;
}

/* System message types */
.system-message.error {
  background-color: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

.system-message.warning {
  background-color: #fff3cd;
  border-color: #ffeeba;
  color: #856404;
}

.system-message.info {
  background-color: #d1ecf1;
  border-color: #bee5eb;
  color: #0c5460;
}

.system-message.success {
  background-color: #d4edda;
  border-color: #c3e6cb;
  color: #155724;
}

/* Animation for message removal during conversation clearing */
.chat-message.clearing {
  animation: fadeOutBlur 0.5s forwards;
}

@keyframes fadeOutBlur {
  from {
    opacity: 1;
    filter: blur(0);
  }

  to {
    opacity: 0.3;
    filter: blur(3px);
  }
}