/* AI Chat Panel — token-driven so it follows the active theme
   (the original hardcoded a light "Shopify style" palette and
   ignored dark mode entirely). */

/* Message layout */
.ai-message {
  margin-bottom: 0.75rem;
  display: flex;
}

.ai-message--user {
  justify-content: flex-end;
}

.ai-message--assistant {
  justify-content: flex-start;
}

/* Message bubbles */
.ai-message__bubble {
  max-width: 90%;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.ai-message__bubble--user {
  background: var(--accent-bg);
  color: var(--text-primary);
  border: 1px solid var(--accent-dim);
  border-bottom-right-radius: 0.125rem;
}

.ai-message__bubble--assistant {
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 0.125rem;
}

/* Streaming text arrives as plain text — preserve its line structure
   until the rendered-markdown swap on completion. */
.ai-message__text {
  word-break: break-word;
  white-space: pre-wrap;
}

/* Rendered-markdown state (server-sanitised HTML swapped in when the
   stream completes). Normal flow again; markdown supplies structure. */
.ai-message__text--rendered {
  white-space: normal;
}

.ai-message__text--rendered > * + * {
  margin-top: 0.5rem;
}

.ai-message__text--rendered h1,
.ai-message__text--rendered h2,
.ai-message__text--rendered h3,
.ai-message__text--rendered h4 {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
}

.ai-message__text--rendered ul,
.ai-message__text--rendered ol {
  padding-left: 1.125rem;
}

.ai-message__text--rendered ul { list-style: disc; }
.ai-message__text--rendered ol { list-style: decimal; }

.ai-message__text--rendered li + li {
  margin-top: 0.25rem;
}

.ai-message__text--rendered a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-message__text--rendered blockquote {
  border-left: 2px solid var(--border-strong);
  padding-left: 0.625rem;
  color: var(--text-secondary);
}

.ai-message__text--rendered table {
  width: 100%;
  font-size: 0.75rem;
}

.ai-message__text--rendered th,
.ai-message__text--rendered td {
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.375rem;
  text-align: left;
}

.ai-message__text strong {
  font-weight: 600;
  color: var(--text-primary);
}

.ai-message__text code {
  background: var(--editor-code-bg);
  color: var(--accent);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8em;
}

.ai-message__text pre {
  background: var(--editor-code-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  overflow-x: auto;
}

.ai-message__text pre code {
  background: transparent;
  padding: 0;
}

/* Streaming cursor */
.ai-streaming::after {
  content: "\25AE";
  color: var(--accent);
  animation: blink-cursor 0.8s infinite;
  margin-left: 2px;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Insert button */
.ai-message__insert-btn {
  display: inline-flex;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) ease;
}

.ai-message__insert-btn:hover {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: var(--accent-dim);
}

/* Suggestion chips */
.ai-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.3125rem 0.75rem;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  white-space: nowrap;
}

.ai-chip:hover {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: var(--accent-dim);
}

/* Loading indicator */
.ai-loading {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.ai-loading__dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin: 0 1px;
  background: var(--accent);
  border-radius: 50%;
  animation: ai-dot-bounce 1.4s infinite ease-in-out both;
}

.ai-loading__dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-loading__dots span:nth-child(2) { animation-delay: -0.16s; }
.ai-loading__dots span:nth-child(3) { animation-delay: 0s; }

@keyframes ai-dot-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
