/* ============================================
   CSS AUXILIAR
   Spinner, Toast, Markdown, Code Wrapper
   ============================================ */

/* ============================================
   BOT SPINNER
   ============================================ */

.bot-spinner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  min-height: 24px;
}

.bot-spinner__dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--spinner-dot-color);
  animation: bot-spinner-bounce 700ms ease-in-out infinite both;
}

.bot-spinner__dot:nth-child(1) { animation-delay: -0.32s; }
.bot-spinner__dot:nth-child(2) { animation-delay: -0.16s; }
.bot-spinner__dot:nth-child(3) { animation-delay: 0s; }

@keyframes bot-spinner-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================
   TOAST
   ============================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: var(--toast-bg);
  color: var(--toast-color);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 9999;
  opacity: 0;
  transition: opacity var(--transition-slow), transform var(--transition-slow);
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--code {
  bottom: 100px;
  font-size: var(--font-size-xs);
  padding: 8px 16px;
}

/* ============================================
   SPINNER TTS
   ============================================ */

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

/* ============================================
   MARKDOWN CONTENT
   ============================================ */

.bot-content {
  font-size: var(--font-size-base);
  line-height: 1.7;
  color: var(--bubble-bot-text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bot-content > *:first-child { margin-top: 0; }
.bot-content > *:last-child { margin-bottom: 0; }

.bot-content p {
  margin-bottom: 0.75em;
}

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

.bot-content h1, .bot-content h2, .bot-content h3,
.bot-content h4, .bot-content h5, .bot-content h6 {
  margin-top: 1.25em;
  margin-bottom: 0.5em;
  line-height: 1.3;
  color: var(--bubble-bot-text);
}

.bot-content h1 { font-size: var(--h1-size); }
.bot-content h2 { font-size: var(--h2-size); }
.bot-content h3 { font-size: var(--h3-size); }
.bot-content h4 { font-size: var(--h4-size); }
.bot-content h5 { font-size: var(--h5-size); }
.bot-content h6 { font-size: var(--h6-size); }

.bot-content ul,
.bot-content ol {
  margin-bottom: 0.75em;
  padding-left: 1.5em;
}

.bot-content ul { list-style: disc; }
.bot-content ol { list-style: decimal; }

.bot-content li {
  margin-bottom: 0.25em;
}

.bot-content li:last-child {
  margin-bottom: 0;
}

.bot-content blockquote {
  border-left: 3px solid var(--markdown-blockquote-border);
  padding-left: 1em;
  margin: 0.75em 0;
  color: var(--markdown-blockquote-color);
  font-style: italic;
}

.bot-content blockquote p {
  margin-bottom: 0;
}

.bot-content a {
  color: var(--markdown-link-color);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

.bot-content a:hover {
  color: var(--markdown-link-hover);
}

.bot-content hr {
  border: none;
  border-top: 1px solid var(--sidebar-border);
  margin: 1em 0;
}

.bot-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: var(--font-size-sm);
}

.bot-content th,
.bot-content td {
  border: 1px solid var(--markdown-table-border);
  padding: 8px 12px;
  text-align: left;
}

.bot-content th {
  font-weight: 600;
  background-color: var(--neutral-50);
}

.bot-content img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: 0.5em 0;
}

/* Código inline */
.bot-content :not(pre) > code {
  background-color: var(--markdown-code-inline-bg);
  color: var(--markdown-code-inline-color);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  font-size: 0.875em;
}

/* ============================================
   CODE WRAPPER
   ============================================ */

.code-wrapper {
  background-color: var(--code-wrapper-bg);
  border-radius: var(--radius-md);
  margin: 0.75em 0;
  overflow: hidden;
}

.code-wrapper + .code-wrapper {
  margin-top: 0.75em;
}

.code-wrapper__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 8px 16px;
  background-color: var(--code-wrapper-header-bg);
  border-bottom: 1px solid var(--code-wrapper-border);
  user-select: none;
}

.code-wrapper__language {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--code-wrapper-language);
  letter-spacing: 0.04em;
}

.code-wrapper__copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background-color: transparent;
  color: var(--code-wrapper-copy-color);
  font-size: var(--font-size-xs);
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}

.code-wrapper__copy-btn:hover {
  background-color: var(--code-wrapper-copy-hover-bg);
  color: var(--code-wrapper-copy-hover-color);
}

.code-wrapper__copy-btn.copied {
  color: var(--blue-500);
  background-color: var(--blue-50);
}

.code-wrapper__body {
  overflow-x: auto;
  overflow-y: hidden;
}

.code-wrapper__body pre {
  margin: 0;
  padding: 16px;
  background-color: var(--code-wrapper-bg);
  border-radius: 0;
  overflow: visible;
}

.code-wrapper__body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--code-wrapper-code-color);
  font-size: 0.820rem;
  line-height: 1.6;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
}

/* ============================================
   MENSAJE DE ERROR DEL BOT
   ============================================ */

.bot-content:has(blockquote) blockquote:first-child:has(> p:first-child:contains("⚠️")) {
  border-left-color: var(--color-warning);
  background-color: var(--color-warning-bg);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: normal;
  color: var(--color-warning-text);
}

/* ============================================
   BOTÓN DESHABILITADO
   ============================================ */

.message-actions__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.message-actions__btn:disabled .material-symbols-outlined {
  animation: spin 1s linear infinite;
}

/* ============================================
   UTILIDADES
   ============================================ */

.message-actions--bot,
.message-actions--user {
  will-change: opacity;
}

[title] {
  position: relative;
}

/* ============================================
   SPINNER EN BOTÓN TTS
   ============================================ */

.message-actions__icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  position: relative;
}

.message-actions__icon-svg {
  display: block;
  flex-shrink: 0;
}