/* ABOUTME: Styles for the AI chat interface and message display */

/* ABOUTME: Covers message bubbles, input area, typing indicators, and tools */

/* Chat Interface Styles */

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  background: var(--bg);
}

.message {
  max-width: 100%;
  padding: 0;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: var(--space-3);
}

.message.user {
  align-self: flex-end;
  background: var(--orange);
  color: white;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}


.message-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.message-author {
  font-weight: 600;
  color: var(--gray-900);
  font-size: 0.875rem;
}

.message-author.user {
  color: var(--yafa-orange);
}

.message-author.assistant {
  color: var(--success-600);
}

.message-time {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.message-content {
  background: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--elev-1);
}

.message-content.user {
  background: color-mix(in oklab, var(--yafa-orange) 8%, white);
  border-color: color-mix(in oklab, var(--yafa-orange) 25%, white);
}

.message-content.assistant {
  background: white;
}

.message-content p {
  margin: 0 0 0.75rem;
  line-height: 1.6;
}

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

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  max-width: 200px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.typing-dots {
  display: flex;
  gap: 0.25rem;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

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

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    background: var(--gray-400);
  }

  30% {
    transform: translateY(-10px);
    background: var(--gray-600);
  }
}

.typing-text {
  font-size: 0.875rem;
  color: var(--gray-600);
  font-style: italic;
}

/* Chat Form */
.chat-form {
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-input-group,
.chat-input-row {
  display: flex;
  gap: var(--space-2);
}

.chat-input {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--bg);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
}

.chat-input:focus {
  outline: none;
  border-color: var(--orange);
  background: var(--surface);
}

.chat-input:disabled {
  background: var(--gray-100);
  color: var(--text-muted);
}

.chat-submit,
.chat-send {
  width: 44px;
  height: 44px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-submit:hover:not(:disabled),
.chat-send:hover:not(:disabled) {
  background: var(--orange-600);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.chat-submit:disabled,
.chat-send:disabled {
  background: var(--gray-400);
  cursor: not-allowed;
  transform: none;
}

/* Loading State */
.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--gray-500);
}

.chat-loading-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Error State */
.chat-error {
  background: var(--error-50);
  border: 1px solid var(--error-200);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem;
}

.chat-error-message {
  color: var(--error-700);
  margin: 0;
  font-size: 0.9375rem;
}

/* Mutation Display */
.mutation-row {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.mutation-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--gray-900);
}

.mutation-icon {
  font-size: 1.25rem;
}

.mutation-table {
  width: 100%;
  font-size: 0.875rem;
}

.mutation-table th {
  text-align: left;
  padding: 0.5rem;
  background: var(--gray-100);
  font-weight: 600;
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}

.mutation-table td {
  padding: 0.5rem;
  border: 1px solid var(--gray-200);
  color: var(--gray-900);
}

.mutation-added {
  background: var(--success-50);
  border-color: var(--success-200);
}

.mutation-added .mutation-header {
  color: var(--success-700);
}

.mutation-edited {
  background: var(--warning-50);
  border-color: var(--warning-200);
}

.mutation-edited .mutation-header {
  color: var(--warning-700);
}

.mutation-deleted {
  background: var(--error-50);
  border-color: var(--error-200);
}

.mutation-deleted .mutation-header {
  color: var(--error-700);
}

.mutation-suggested {
  background: var(--primary-50);
  border-color: var(--primary-200);
}

.mutation-suggested .mutation-header {
  color: var(--primary-700);
}

/* Chat Interface Layout */
.chat-interface {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.chat-messages {
  height: 100%;
  overflow: hidden auto;
  padding: 1rem;
  background: var(--gray-50);

  /* Never smooth during history */
  scroll-behavior: auto !important;

  /* Disable UA scroll anchoring */
  overflow-anchor: none !important;

  /* Avoid flex - it interferes with our spacer approach */
  display: block;
}

/* Disable animations during infinite scroll operations */

/* Ensure measurement parity & no animations fire during prepend */
.loading-history .message {
  transition: none !important;
  animation: none !important;
  overflow-anchor: none;  /* belt-and-suspenders */
}

/* Helper classes for critical section */
.chat-messages.no-animate { 
  scroll-behavior: auto !important; 
}

.chat-messages.no-anchor { 
  overflow-anchor: none !important; 
}

/* Messages container needs relative positioning for spacer */
#messages {
  position: relative;
  overflow-anchor: none;  /* belt-and-suspenders */
}

/* Top spacer for infinite scroll - keeps viewport pinned */
#top-spacer {
  height: 0;
  pointer-events: none;

  /* Make it invisible but keep it in layout */
  visibility: hidden;
  overflow-anchor: none;  /* belt-and-suspenders */
}

.chat-spacer {
  flex: 1;
  min-height: 100px;
}

.chat-content {
  width: 100%;
}

.chat-welcome {
  padding: 1.5rem 1rem;
  max-width: 32rem;
  margin: 0 auto;
}

/* Welcome date card */
.welcome-date-card {
  display: flex;
  gap: 1rem;
  align-items: start;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.welcome-date-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.welcome-date-content {
  flex: 1;
}

.welcome-date-title {
  margin: 0 0 0.25rem;
  color: var(--gray-800);
  font-size: 0.875rem;
  font-weight: 600;
}

.welcome-date-text {
  margin: 0;
  color: var(--gray-600);
  font-size: 0.8125rem;
  line-height: 1.4;
}

/* Capabilities grid */
.chat-capabilities {
  background: var(--gray-50);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid var(--gray-200);
  margin-top: 1rem;
}

.chat-capabilities-title {
  margin: 0 0 0.75rem;
  color: var(--gray-700);
  font-size: 0.875rem;
  font-weight: 600;
}

.chat-capabilities-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.capability-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: white;
  border-radius: 8px;
  font-size: 0.8125rem;
  color: var(--gray-700);
  cursor: default;
  border: 1px solid var(--gray-200);
}

.capability-icon {
  font-size: 1rem;
  width: 24px;
  text-align: center;
}

/* Override chat form for proper layout */
.chat-interface .chat-form {
  flex-shrink: 0; /* Don't shrink the form */
  padding: 1rem;
  border-top: 1px solid var(--gray-200);
  background: linear-gradient(to bottom, var(--gray-50), white);
}

/* Enhanced chat input styling */
#message_input {
  border: 2px solid var(--gray-200) !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
  box-shadow: 0 1px 2px rgb(0 0 0 / 5%);
}

#message_input:focus {
  border-color: var(--primary-400) !important;
  box-shadow: 0 0 0 3px rgb(59 130 246 / 10%), 0 1px 2px rgb(0 0 0 / 5%) !important;
  outline: none !important;
}

#message_input:hover:not(:disabled) {
  border-color: var(--gray-300) !important;
}

#send_button {
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

#send_button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgb(0 0 0 / 10%);
}

/* Ensure messages don't overflow */
#messages {
  max-width: 100%;
}

#welcome_message {
  max-width: 100%;
}

/* Mobile Responsive */

@media (width <= 768px) {
  .chat-messages {
    padding: 1rem;
  }
  
  .chat-form {
    padding: 0.75rem;
  }
  
  .chat-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}