/* Message bubbles */
.bubble {
  max-width: 85%;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--border-radius);
  margin: var(--space-sm) 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  position: relative;
  font-size: 1rem;
  line-height: 1.75;
  scroll-margin-bottom: 20px;
}

/* Message actions container */
.message-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

/* Rating buttons container */
.rating-buttons {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}

/* Rating button */
.rating-button {
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: currentColor;
  opacity: 0.5;
  border-radius: 4px;
  position: relative;
}

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

.rating-button:active {
  transform: scale(0.95);
}

.rating-button.active {
  opacity: 1;
}

/* Like button active state - green */
.like-button.active {
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.like-button.active:hover {
  background: rgba(16, 185, 129, 0.15);
}

/* Dislike button active state - red */
.dislike-button.active {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.dislike-button.active:hover {
  background: rgba(239, 68, 68, 0.15);
}

.rating-button .icon {
  display: block;
  flex-shrink: 0;
}

/* Copy button */
.copy-button {
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, opacity 0.2s ease;
  color: currentColor;
  opacity: 0.5;
  border-radius: 4px;
  position: relative;
}

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

.copy-button:active {
  transform: scale(0.95);
}

.copy-button .icon {
  display: block;
  flex-shrink: 0;
}

/* Copy tooltip */
.copy-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1000;
}

.copy-button:hover .copy-tooltip {
  opacity: 1;
}

.copy-tooltip.visible {
  opacity: 1 !important;
}

.bubble.user {
  background: var(--user-bubble);
  color: var(--text-primary);
  align-self: flex-end;
  margin-left: auto;
  border-bottom-right-radius: var(--space-xs);
}

.bubble.ai {
  background: var(--ai-bubble);
  color: var(--text-primary);
  align-self: flex-start;
  margin-right: auto;
}

/* Message content styling */
.bubble pre {
  background: rgba(0, 0, 0, 0.05);
  padding: var(--space-md);
  border-radius: var(--border-radius-sm);
  overflow-x: auto;
  margin: var(--space-sm) 0;
  border: 1px solid var(--border-light);
}

.bubble.user pre {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px var(--space-xs);
  border-radius: var(--space-xs);
  font-size: 0.9em;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.bubble.user code {
  background: rgba(255, 255, 255, 0.25);
}

.bubble p {
  margin: 0.5rem 0;
}

.bubble p:first-child {
  margin-top: 0;
}

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

.bubble p+p {
  margin-top: 1rem;
}

.bubble ul,
.bubble ol {
  margin: var(--space-sm) 0;
  padding-left: var(--space-xl);
}

.bubble li {
  margin: var(--space-xs) 0;
}

.bubble li::marker {
  font-weight: 700;
  color: var(--text-secondary, rgba(0, 0, 0, 0.6));
}

/* Headings */
.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  font-weight: 600;
  line-height: 1.3;
  margin: 1rem 0 0.5rem 0;
}

.bubble h1:first-child,
.bubble h2:first-child,
.bubble h3:first-child,
.bubble h4:first-child,
.bubble h5:first-child,
.bubble h6:first-child {
  margin-top: 0;
}

.bubble h1 {
  font-size: 1.875rem;
  letter-spacing: -0.04rem;
}

.bubble h2 {
  font-size: 1.5rem;
  margin-top: 2rem;
}

.bubble h3 {
  font-size: 1.25rem;
  margin-top: 1.5rem;
}

.bubble h4 {
  font-size: 1.125rem;
  margin-top: 1rem;
}

/* Blockquotes */
.bubble blockquote {
  border-left: 4px solid var(--border-medium, rgba(0, 0, 0, 0.2));
  padding: 0.5rem 0 0.5rem 1.5rem;
  margin: 1rem 0;
  position: relative;
}

.bubble blockquote p {
  margin: 0;
  font-weight: 400;
}

/* Text formatting */
.bubble strong {
  font-weight: 600;
  color: inherit;
}

.bubble em {
  font-style: italic;
}

/* Horizontal rules */
.bubble hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 1.75rem 0;
  clear: both;
}

/* Links */
.bubble a {
  color: var(--link-color, #0969da);
  text-decoration: none;
  font-weight: 500;
  word-break: break-all;
  overflow-wrap: break-word;
  hyphens: auto;
}

.bubble a:hover {
  text-decoration: underline;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble {
  animation: fadeIn 0.3s ease;
}


/* Inline typing indicator inside AI bubble */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 1em;
}

.typing-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
  animation: typingDotBlink 1s infinite ease-in-out;
}

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

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

@keyframes typingDotBlink {

  0%,
  80%,
  100% {
    opacity: 0.25;
  }

  40% {
    opacity: 1;
  }
}

/* Thinking indicator for reasoning process */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  color: var(--text-color-secondary, rgba(0, 0, 0, 0.6));
  font-size: 0.95rem;
}

.thinking-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: thinkingSpinnerRotate 0.8s linear infinite;
  flex-shrink: 0;
}

.thinking-text {
  opacity: 0.75;
  line-height: 1.4;
  font-weight: 400;
}

@keyframes thinkingSpinnerRotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
  .thinking-indicator {
    color: rgba(255, 255, 255, 0.6);
  }
}

/* Reasoning wrapper - collapsible gray blocks */
.reasoning-wrapper {
  margin: 8px 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
}

.reasoning-wrapper:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.12);
}

/* Collapsed preview (default state) */
.reasoning-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  color: rgba(0, 0, 0, 0.6);
  transition: color 0.2s ease;
}

.reasoning-preview:hover {
  color: rgba(0, 0, 0, 0.8);
}

.reasoning-icon {
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.7;
}

.reasoning-preview-text {
  flex: 1;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reasoning-toggle {
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  opacity: 0.5;
}

.reasoning-wrapper.expanded .reasoning-toggle {
  transform: rotate(180deg);
}

/* Expanded content (hidden by default) */
.reasoning-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 12px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: rgba(0, 0, 0, 0.65);
  font-style: italic;
}

.reasoning-wrapper.expanded .reasoning-content {
  max-height: 1000px;
  padding: 0 12px 12px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  margin-top: 4px;
}

.reasoning-content p {
  margin: 8px 0;
}

.reasoning-content p:first-child {
  margin-top: 8px;
}

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

/* Emphasize the thinking marker */
.reasoning-content strong {
  color: rgba(0, 0, 0, 0.75);
  font-weight: 600;
  font-style: normal;
}

/* Dark theme support for reasoning blocks */
@media (prefers-color-scheme: dark) {
  .reasoning-wrapper {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .reasoning-wrapper:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
  }

  .reasoning-preview {
    color: rgba(255, 255, 255, 0.6);
  }

  .reasoning-preview:hover {
    color: rgba(255, 255, 255, 0.8);
  }

  .reasoning-content {
    color: rgba(255, 255, 255, 0.65);
  }

  .reasoning-wrapper.expanded .reasoning-content {
    border-top-color: rgba(255, 255, 255, 0.08);
  }

  .reasoning-content strong {
    color: rgba(255, 255, 255, 0.8);
  }
}

/* ============================================
   IMAGE DISPLAY IN CHAT MESSAGES
   ============================================ */

/* Images in message bubbles - base styling */
.bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 12px 0;
  display: block;
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
  cursor: default;
}

/* Subtle hover effect for images */
.bubble img:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Loading state - subtle pulsing animation */
.bubble img[data-loading="true"] {
  opacity: 0.6;
  animation: imageLoading 1.5s ease-in-out infinite;
}

@keyframes imageLoading {

  0%,
  100% {
    opacity: 0.6;
  }

  50% {
    opacity: 0.9;
  }
}

/* Error state - dimmed with dashed border */
.bubble img[data-error="true"] {
  opacity: 0.3;
  border: 2px dashed var(--border-medium, rgba(0, 0, 0, 0.3));
  box-shadow: none;
  filter: grayscale(100%);
  cursor: not-allowed;
}

.bubble img[data-error="true"]:hover {
  transform: none;
  box-shadow: none;
}

/* Multiple images in sequence - tighter spacing */
.bubble img+img {
  margin-top: 8px;
}

/* Images inside paragraphs (inline context) */
.bubble p img {
  margin: 8px 0;
}

/* Images at the start/end of bubble - remove extra margin */
.bubble img:first-child {
  margin-top: 0;
}

.bubble img:last-child {
  margin-bottom: 0;
}

/* Images inside list items */
.bubble li img {
  margin: 8px 0;
}

/* Image captions (if wrapped in figure) */
.bubble figure {
  margin: 12px 0;
}

.bubble figure img {
  margin: 0 0 8px 0;
}

.bubble figcaption {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
  margin-top: 8px;
}

/* Dark theme support for images */
@media (prefers-color-scheme: dark) {
  .bubble img {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  }

  .bubble img:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
  }

  .bubble img[data-error="true"] {
    border-color: rgba(255, 255, 255, 0.2);
  }

  .bubble figcaption {
    color: rgba(255, 255, 255, 0.6);
  }
}

/* Responsive sizing for mobile devices */
@media (max-width: 768px) {
  .bubble img {
    border-radius: 6px;
    margin: 10px 0;
  }

  .bubble img+img {
    margin-top: 6px;
  }
}

/* Responsive sizing for very small screens */
@media (max-width: 480px) {
  .bubble img {
    border-radius: 4px;
  }
}