/* Context Chat Component Styles */
/* Scoped to prevent external interference */

/* Main component container */
.context-chat-component {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
}

/* Chat message content formatting - scoped within component */
.context-chat-component .chat-message-content {
  line-height: 1.4;
}

.context-chat-component .chat-message-content code {
  font-size: 0.875rem;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

.context-chat-component .chat-message-content pre {
  font-size: 0.75rem;
  line-height: 1.3;
  overflow-x: auto;
  border-radius: 0.375rem;
  margin: 0.5rem 0;
}

.context-chat-component .chat-message-content pre code {
  background: none !important;
  padding: 0 !important;
}

.context-chat-component .chat-message-content ul,
.context-chat-component .chat-message-content ol {
  margin: 0.5rem 0;
  padding-left: 1rem;
}

.context-chat-component .chat-message-content li {
  list-style: none;
  margin: 0.125rem 0;
  padding-left: 0.75rem;
}

.context-chat-component .chat-message-content a {
  word-break: break-word;
}

.context-chat-component .chat-message-content p {
  margin: 0;
}

.context-chat-component .chat-message-content p + p {
  margin-top: 0.5rem;
}

.context-chat-component .chat-message-content strong {
  font-weight: 600;
}

.context-chat-component .chat-message-content h1,
.context-chat-component .chat-message-content h2,
.context-chat-component .chat-message-content h3 {
  margin: 0.5rem 0 0.25rem 0;
}

.context-chat-component .chat-message-content h1:first-child,
.context-chat-component .chat-message-content h2:first-child,
.context-chat-component .chat-message-content h3:first-child {
  margin-top: 0;
}

.context-chat-component .chat-message-content blockquote {
  margin: 0.5rem 0;
}

.context-chat-component .chat-message-content hr {
  margin: 0.75rem 0;
}

.context-chat-component .chat-message-content del {
  opacity: 0.7;
}

/* Chat toggle button */
.context-chat-component .chat-toggle-btn {
  background-color: #3b82f6;
  color: white;
  border-radius: 9999px;
  padding: 0.75rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  position: relative;
  border: none;
  cursor: pointer;
  transform-origin: center;
}

.context-chat-component .chat-toggle-btn:hover {
  background-color: #2563eb;
}

.context-chat-component .chat-toggle-btn .unread-indicator {
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  width: 0.75rem;
  height: 0.75rem;
  background-color: #ef4444;
  border-radius: 9999px;
  animation: context-chat-pulse 2s infinite;
}

@keyframes context-chat-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Chat window */
.context-chat-component .chat-window {
  position: fixed;
  top: 1rem;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 20rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 2rem);
  transform-origin: bottom right;
  backdrop-filter: blur(10px);
}

@media (min-width: 640px) {
  .context-chat-component .chat-window {
    width: 24rem;
  }
}

/* Chat header */
.context-chat-component .chat-header {
  background-color: #3b82f6;
  color: white;
  padding: 1rem;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.context-chat-component .chat-header .header-content {
  flex: 1;
}

.context-chat-component .chat-header .header-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.context-chat-component .chat-header .header-title h3 {
  font-weight: 600;
  margin: 0;
}

.context-chat-component .chat-header .context-info {
  font-size: 0.75rem;
  opacity: 0.9;
  margin-top: 0.25rem;
}

.context-chat-component .chat-header .header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.context-chat-component .chat-header .header-btn {
  color: white;
  background: none;
  border: none;
  padding: 0.25rem;
  border-radius: 0.25rem;
  transition: all 0.2s ease;
  cursor: pointer;
  transform-origin: center;
}

.context-chat-component .chat-header .header-btn:hover {
  color: #d1d5db;
}

.context-chat-component .chat-header .header-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Messages container */
.context-chat-component .messages-container {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.context-chat-component .loading-indicator {
  text-align: center;
  color: #6b7280;
  font-size: 0.875rem;
}

.context-chat-component .loading-indicator .spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #6b7280;
  border-radius: 50%;
  animation: context-chat-spin 1s linear infinite;
  margin-right: 0.5rem;
}

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

/* Enhanced loading animation */
.context-chat-component .loading-indicator {
  text-align: center;
  color: #6b7280;
  font-size: 0.875rem;
  animation: context-chat-fade-in-out 2s ease-in-out infinite;
}

@keyframes context-chat-fade-in-out {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Message bubbles */
.context-chat-component .message-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transform-origin: bottom;
}

.context-chat-component .user-message {
  display: flex;
  justify-content: flex-end;
}

.context-chat-component .user-message .message-bubble {
  background-color: #dbeafe;
  color: #1e40af;
  border-radius: 0.5rem;
  padding: 0.75rem;
  max-width: 14rem;
  font-size: 0.875rem;
  transform-origin: bottom right;
  transition: all 0.2s ease;
}

.context-chat-component .assistant-message {
  display: flex;
  justify-content: flex-start;
}

.context-chat-component .assistant-message .message-bubble {
  background-color: #f3f4f6;
  color: #1f2937;
  border-radius: 0.5rem;
  padding: 0.75rem;
  max-width: 14rem;
  font-size: 0.875rem;
  transform-origin: bottom left;
  transition: all 0.2s ease;
}

.context-chat-component .message-meta {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.25rem;
  transition: opacity 0.2s ease;
}

/* Empty state */
.context-chat-component .empty-state {
  text-align: center;
  color: #6b7280;
  padding: 2rem 0;
  font-size: 0.875rem;
}

.context-chat-component .empty-state p {
  margin: 0;
}

.context-chat-component .empty-state p + p {
  margin-top: 0.25rem;
  font-size: 0.75rem;
}

/* Input section */
.context-chat-component .input-section {
  padding: 1rem;
  border-top: 1px solid #e5e7eb;
}

.context-chat-component .input-form {
  display: flex;
  gap: 0.5rem;
}

.context-chat-component .input-field {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s ease;
}

.context-chat-component .input-field:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.context-chat-component .input-field:disabled {
  background-color: #f9fafb;
  cursor: not-allowed;
}

.context-chat-component .send-btn {
  background-color: #3b82f6;
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center;
}

.context-chat-component .send-btn:hover:not(:disabled) {
  background-color: #2563eb;
}

.context-chat-component .send-btn:disabled {
  background-color: #9ca3af;
  cursor: not-allowed;
}

.context-chat-component .send-btn .send-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid #ffffff40;
  border-top: 2px solid #ffffff;
  border-radius: 50%;
  animation: context-chat-spin 1s linear infinite;
}

/* Error message */
.context-chat-component .error-message {
  color: #ef4444;
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

/* Dark mode styles */
.dark .context-chat-component .chat-window {
  background-color: #1e293b;
}

.dark .context-chat-component .assistant-message .message-bubble {
  background-color: #374151;
  color: #e5e7eb;
}

.dark .context-chat-component .user-message .message-bubble {
  background-color: #1e3a8a;
  color: #bfdbfe;
}

.dark .context-chat-component .input-section {
  border-top-color: #374151;
}

.dark .context-chat-component .input-field {
  background-color: #334155;
  border-color: #374151;
  color: white;
}

.dark .context-chat-component .input-field:focus {
  border-color: #3b82f6;
}

.dark .context-chat-component .loading-indicator,
.dark .context-chat-component .empty-state {
  color: #9ca3af;
}

.dark .context-chat-component .error-message {
  color: #fca5a5;
}

/* Dark mode code blocks */
.dark .context-chat-component .chat-message-content pre {
  background-color: rgb(75 85 99) !important;
}

.dark .context-chat-component .chat-message-content code {
  background-color: rgb(75 85 99) !important;
}

/* Filament-specific adjustments */
.fi-dark .context-chat-component .chat-window {
  background-color: rgb(30 41 59) !important;
}

.fi-dark .context-chat-component .assistant-message .message-bubble {
  background-color: rgb(55 65 81) !important;
  color: rgb(229 231 235) !important;
}

.fi-dark .context-chat-component .user-message .message-bubble {
  background-color: rgb(30 58 138) !important;
  color: rgb(191 219 254) !important;
}

.fi-dark .context-chat-component .input-section {
  border-top-color: rgb(75 85 99) !important;
}

.fi-dark .context-chat-component .input-field {
  background-color: rgb(51 65 85) !important;
  border-color: rgb(75 85 99) !important;
  color: rgb(255 255 255) !important;
}

.fi-dark .context-chat-component .loading-indicator,
.fi-dark .context-chat-component .empty-state {
  color: rgb(156 163 175) !important;
}

.fi-dark .context-chat-component .error-message {
  color: rgb(252 165 165) !important;
}

/* Responsive adjustments for Filament's sidebar */
@media (min-width: 1024px) {
  .context-chat-component {
    right: 1.5rem;
  }
}

/* Ensure component isolation */
.context-chat-component * {
  box-sizing: border-box;
}

.context-chat-component .fixed {
  position: fixed !important;
}

/* Prevent external style interference */
.context-chat-component button,
.context-chat-component input,
.context-chat-component div {
  all: unset;
  box-sizing: border-box;
}

.context-chat-component button {
  cursor: pointer;
}

.context-chat-component input {
  background: white;
  border: 1px solid #d1d5db;
  color: #1f2937;
}
