/*
 * ai-explain.css
 *
 * Styles for the "Explain with AI" offcanvas, chat bubbles, and related controls.
 * All colours use Bootstrap CSS variables so dark-mode is supported automatically.
 */

/* ── Offcanvas width ─────────────────────────────────────────────────────── */

.ai-offcanvas {
  /* Wider than Bootstrap default on desktop; full-width on mobile (default) */
  --bs-offcanvas-width: min(500px, 100vw);
}

/* ── Locked button state (non-premium users) ─────────────────────────────── */

.ai-explain-btn--locked {
  opacity: 0.65;
  cursor: default;
  pointer-events: auto; /* keep link behaviour for the upgrade CTA */
}

/* ── Selectable text area ─────────────────────────────────────────────────── */

.ai-selectable-text {
  font-size: 1.1rem;
  line-height: 1.9;
  /* Allow text selection — prevents accidental drag-scroll on mobile */
  user-select: text;
  -webkit-user-select: text;
}

/* Highlight the selected text visually (handled by the browser natively) */
.ai-selectable-text::selection,
.ai-selectable-text *::selection {
  background-color: rgba(var(--bs-primary-rgb), 0.2);
}

/* ── Chat messages ───────────────────────────────────────────────────────── */

.ai-message {
  display: flex;
  margin-bottom: 0.75rem;
}

.ai-message--user {
  justify-content: flex-end;
}

.ai-message--assistant {
  justify-content: flex-start;
}

.ai-bubble {
  max-width: 88%;
  padding: 0.55rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

.ai-message--user .ai-bubble {
  background-color: var(--bs-primary);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.ai-message--assistant .ai-bubble {
  background-color: var(--bs-tertiary-bg, #f8f9fa);
  color: var(--bs-body-color);
  border-bottom-left-radius: 0.25rem;
  border: 1px solid var(--bs-border-color);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */

.ai-bubble--typing {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.65rem 0.85rem;
}

.ai-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--bs-secondary-color);
  animation: ai-dot-bounce 1.2s ease-in-out infinite;
}

.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-dot-bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.6; }
  40%           { transform: scale(1.2); opacity: 1; }
}

/* ── Selection action bar ─────────────────────────────────────────────────── */

#ai-selection-bar {
  /* Stick to the bottom of the text area, above the offcanvas border */
  position: sticky;
  bottom: 0;
  z-index: 5;
}

/* ── Markdown rendering inside AI assistant bubbles ─────────────────────── */

/* Remove excess margin from the first/last block so bubble padding controls spacing */
.ai-message--assistant .ai-bubble > *:first-child { margin-top: 0; }
.ai-message--assistant .ai-bubble > *:last-child  { margin-bottom: 0; }

/* Scale headings down — ### inside a chat bubble should not be page-heading size */
.ai-message--assistant .ai-bubble h1,
.ai-message--assistant .ai-bubble h2 { font-size: 1rem; font-weight: 700; margin: 0.6em 0 0.3em; }
.ai-message--assistant .ai-bubble h3,
.ai-message--assistant .ai-bubble h4 { font-size: 0.92rem; font-weight: 700; margin: 0.5em 0 0.25em; }

/* Compact lists */
.ai-message--assistant .ai-bubble ul,
.ai-message--assistant .ai-bubble ol { padding-left: 1.25rem; margin: 0.35rem 0; }
.ai-message--assistant .ai-bubble li { margin-bottom: 0.2rem; }

/* Inline code */
.ai-message--assistant .ai-bubble code {
  font-size: 0.82em;
  background-color: var(--bs-secondary-bg, rgba(0,0,0,.06));
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
}

/* Code blocks */
.ai-message--assistant .ai-bubble pre {
  background-color: var(--bs-secondary-bg, rgba(0,0,0,.06));
  border-radius: 0.4rem;
  padding: 0.6rem 0.75rem;
  overflow-x: auto;
  margin: 0.4rem 0;
}
.ai-message--assistant .ai-bubble pre code { background: none; padding: 0; }

/* Blockquotes — useful for example sentences in Japanese explanations */
.ai-message--assistant .ai-bubble blockquote {
  border-left: 3px solid var(--bs-primary);
  margin: 0.4rem 0;
  padding: 0.2rem 0.75rem;
  color: var(--bs-secondary-color);
  font-style: italic;
}

/* Horizontal rules */
.ai-message--assistant .ai-bubble hr { border-color: var(--bs-border-color); margin: 0.5rem 0; }
