/* 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);
}

/* Report button - subtle gray style */
.report-button {
  opacity: 0.45;
  margin-left: 4px;
}

.report-button:hover {
  opacity: 0.7;
  color: #f59e0b;
}

/* Report Modal */
.report-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: var(--space-lg);
}

.report-modal {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.report-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-light);
}

.report-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.report-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  transition: color 0.2s;
}

.report-modal-close:hover {
  color: var(--text-primary);
}

.report-modal-body {
  padding: var(--space-xl);
}

.report-modal-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.report-modal-textarea {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-sm);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  box-sizing: border-box;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.report-modal-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.report-modal-error {
  display: none;
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 6px;
  color: var(--error-color);
  font-size: 14px;
}

.report-modal-submit {
  width: 100%;
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-xl);
  background: var(--accent-primary);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--border-radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.report-modal-submit:hover:not(:disabled) {
  background: var(--color-brand-teal-light);
}

.report-modal-submit:active:not(:disabled) {
  transform: scale(0.98);
}

.report-modal-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.report-modal-success {
  text-align: center;
  padding: var(--space-xl);
}

.report-modal-success-icon {
  font-size: 48px;
  margin-bottom: var(--space-lg);
}

.report-modal-success h4 {
  margin: 0 0 var(--space-sm);
  color: var(--text-primary);
  font-weight: 600;
}

.report-modal-success p {
  margin: 0;
  color: var(--text-muted);
}

.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);
  max-width: 70%;
}

.bubble.ai {
  background: var(--ai-bubble);
  color: var(--text-primary);
  align-self: flex-start;
  margin-right: auto;
  max-width: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.ai-bubble-frozen,
.ai-bubble-live {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.ai-bubble-live {
  min-height: 1px;
}

.ai-bubble-block {
  width: 100%;
}

.ai-bubble-block+.ai-bubble-block {
  margin-top: var(--space-sm);
}

/* 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;
}

/* Link badges for external sources with favicon */
.bubble a.link-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary, #1f2937);
  text-decoration: none;
  transition: all 0.2s ease;
  margin: 0 4px;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
  white-space: nowrap;
}

.bubble a.link-badge:hover {
  background: var(--link-color, #0969da);
  border-color: var(--link-color, #0969da);
  color: white;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(9, 105, 218, 0.3);
}

.bubble a.link-badge:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(9, 105, 218, 0.2);
}

/* Favicon in link badge */
.link-badge-favicon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 2px;
  object-fit: contain;
  /* Reset bubble img styles for favicons */
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  transition: none !important;
  display: inline-block !important;
}

.bubble a.link-badge:hover .link-badge-favicon {
  filter: brightness(0) invert(1);
}

/* Dark theme support for link badges */
@media (prefers-color-scheme: dark) {
  .bubble a.link-badge {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
  }

  .bubble a.link-badge:hover {
    background: var(--link-color, #58a6ff);
    border-color: var(--link-color, #58a6ff);
    color: #1f2937;
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
  }

  .bubble a.link-badge:hover .link-badge-favicon {
    filter: none;
  }
}

/* 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;
  }
}

/* ============================================
   TABLE DISPLAY IN CHAT MESSAGES
   ============================================ */

/* Table wrapper for horizontal scroll */
.bubble .table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: var(--space-md) 0;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-light);
  -webkit-overflow-scrolling: touch;
}

/* Base table styles */
.bubble table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  margin: var(--space-md) 0;
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--bg-primary);
}

/* Tables inside wrapper should have no margin (wrapper provides it) */
.bubble .table-wrapper table {
  margin: 0;
}

/* Table headers */
.bubble th {
  background: rgba(0, 0, 0, 0.04);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border-medium);
  white-space: nowrap;
}

/* Table cells */
.bubble td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-light);
}

/* Last row - no border */
.bubble tr:last-child td {
  border-bottom: none;
}

/* Zebra striping for better readability */
.bubble tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

/* Mobile: smaller font and padding */
@media (max-width: 768px) {
  .bubble table {
    font-size: 0.8rem;
  }

  .bubble th,
  .bubble td {
    padding: var(--space-xs) var(--space-sm);
  }
}

/* Very small screens: even smaller font */
@media (max-width: 480px) {
  .bubble table {
    font-size: 0.75rem;
  }

  .bubble th,
  .bubble td {
    padding: 6px 8px;
    white-space: normal;
    word-break: break-word;
  }
}

/* Dark theme support for tables */
@media (prefers-color-scheme: dark) {
  .bubble .table-wrapper {
    border-color: rgba(255, 255, 255, 0.12);
  }

  .bubble th {
    background: rgba(255, 255, 255, 0.06);
    border-bottom-color: rgba(255, 255, 255, 0.2);
  }

  .bubble td {
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }

  .bubble tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
  }
}