/* Studio Modular — Camada de Animações & Micro-interações do Streaming
   Estágios ao vivo, shimmer no raciocínio/ferramentas, entrada suave de itens
   e respeito a `reduceMotion` / `prefers-reduced-motion`. */

/* === Pulso de atividade ao vivo === */
@keyframes vm-live-breathe {
  0%, 100% {
    opacity: 0.45;
    transform: scale(0.88);
    box-shadow: 0 0 0 0 rgba(211, 173, 120, 0.35);
  }
  50% {
    opacity: 1;
    transform: scale(1.12);
    box-shadow: 0 0 0 5px rgba(211, 173, 120, 0);
  }
}

/* === Shimmer discreto para status e raciocínio ativo === */
@keyframes vm-text-shimmer {
  0% { background-position: -180% 0; }
  100% { background-position: 180% 0; }
}

/* === Entrada suave de cada linha de ferramenta / fonte === */
@keyframes vm-step-enter {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === Rotação limpa para spinner de ferramenta ativa === */
@keyframes vm-spin {
  to { transform: rotate(360deg); }
}

/* === Constelação / glifo giratório / onda de leitura === */
@keyframes vm-orbit-spin {
  to { transform: rotate(360deg); }
}

@keyframes vm-constellation-twinkle {
  0%, 100% {
    opacity: 0.35;
    transform: scale(0.75);
  }
  50% {
    opacity: 1;
    transform: scale(1.25);
  }
}

@keyframes vm-scan-wave {
  0%, 100% {
    opacity: 0.35;
    transform: translateY(1.5px) scale(0.92);
  }
  50% {
    opacity: 1;
    transform: translateY(-1.5px) scale(1.08);
  }
}

@keyframes vm-favicon-pop {
  from {
    opacity: 0;
    transform: scale(0.65);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Container de espera antes do primeiro token */
.thinking-live {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.thinking-stage {
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: linear-gradient(
    90deg,
    var(--muted) 0%,
    var(--accent-text) 45%,
    var(--muted) 90%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: vm-text-shimmer 2.2s linear infinite;
}

.thinking-age {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* Painel de raciocínio durante e após o turno */
.thought-panel {
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
}

.thought-panel.is-thinking {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 1px rgba(211, 173, 120, 0.08);
}

.thought-panel summary {
  display: flex;
  align-items: center;
  gap: 7px;
}

.thought-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: vm-live-breathe 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

.thought-panel:not(.is-thinking) .thought-live-dot {
  display: none;
}

.thought-summary-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* Refinamento do painel de ferramentas ao vivo */
.tools-panel.is-live .tools-summary {
  color: var(--text);
}

.tools-panel.is-live .tools-live-pulse {
  background: var(--accent);
  animation: vm-live-breathe 1.4s ease-in-out infinite;
}

.tool-exec-item.is-new {
  animation: vm-step-enter 0.22s var(--ease-smooth) both;
}

.tool-exec-item.running .tool-item-row {
  background: linear-gradient(90deg, var(--accent-soft), transparent 75%);
}

.tool-item-spin {
  width: 9px;
  height: 9px;
  border: 1.6px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: vm-spin 0.75s linear infinite;
}

.tool-item-domain {
  flex-shrink: 0;
  padding: 1px 6px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  max-width: 165px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-item-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--accent-text);
  font-size: 0.64rem;
  text-decoration: none;
  transition: border-color var(--trans-fast), background var(--trans-fast);
}

.tool-item-link:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

/* Fontes consultadas na internet (domínio + título + link externo) */
.msg-web-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  animation: vm-step-enter 0.25s var(--ease-smooth) both;
}

.msg-web-sources[hidden] {
  display: none;
}

.web-source-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-soft);
  font-size: 0.68rem;
  text-decoration: none;
  max-width: 300px;
  transition: border-color var(--trans-fast), transform var(--trans-fast), background var(--trans-fast);
}

.web-source-pill:hover {
  border-color: var(--accent-line);
  background: var(--panel-hover);
  transform: translateY(-1px);
}

.web-source-domain {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--accent-text);
  flex-shrink: 0;
}

.web-source-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
}

.web-source-ext {
  color: var(--faint);
  font-size: 0.65rem;
  flex-shrink: 0;
}

/* Ícones animados de atividade (constelação, glifo giratório, ondas e favicons) */
.vm-activity-glyph {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--accent-text);
  flex-shrink: 0;
}

.vm-glyph-orbit {
  width: 15px;
  height: 15px;
  animation: vm-orbit-spin 4.2s linear infinite;
}

.vm-glyph-orbit circle {
  animation: vm-constellation-twinkle 1.6s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.vm-glyph-orbit circle:nth-child(2) { animation-delay: 0.25s; }
.vm-glyph-orbit circle:nth-child(3) { animation-delay: 0.5s; }
.vm-glyph-orbit circle:nth-child(4) { animation-delay: 0.75s; }
.vm-glyph-orbit circle:nth-child(5) { animation-delay: 1.0s; }
.vm-glyph-orbit circle:nth-child(6) { animation-delay: 1.25s; }

.vm-glyph-bars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 12px;
}

.vm-glyph-bars i {
  display: block;
  width: 2.5px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  animation: vm-scan-wave 1.1s ease-in-out infinite;
}

.vm-glyph-bars i:nth-child(2) { animation-delay: 0.16s; height: 12px; }
.vm-glyph-bars i:nth-child(3) { animation-delay: 0.32s; height: 8px; }

.vm-favicon-stack {
  display: inline-flex;
  align-items: center;
  margin-left: 2px;
}

.vm-favicon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--panel);
  background: var(--panel-soft);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 700;
  margin-left: -4px;
  overflow: hidden;
  animation: vm-favicon-pop 0.24s var(--ease-spring) both;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.vm-favicon-chip:first-child {
  margin-left: 0;
}

.vm-favicon-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.web-source-favicon {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: cover;
}

/* Respeito total à preferência de reduzir movimento */
html[data-motion="reduced"] .thinking-stage,
html[data-motion="reduced"] .thought-live-dot,
html[data-motion="reduced"] .tools-live-pulse,
html[data-motion="reduced"] .tool-exec-item.is-new,
html[data-motion="reduced"] .tool-item-spin,
html[data-motion="reduced"] .msg-web-sources,
html[data-motion="reduced"] .web-source-pill,
html[data-motion="reduced"] .vm-glyph-orbit,
html[data-motion="reduced"] .vm-glyph-orbit circle,
html[data-motion="reduced"] .vm-glyph-bars i,
html[data-motion="reduced"] .vm-favicon-chip {
  animation: none !important;
  transition: none !important;
}

html[data-motion="reduced"] .thinking-stage {
  background: none;
  color: var(--text-soft);
}

@media (prefers-reduced-motion: reduce) {
  .thinking-stage,
  .thought-live-dot,
  .tools-live-pulse,
  .tool-exec-item.is-new,
  .tool-item-spin,
  .msg-web-sources,
  .web-source-pill,
  .vm-glyph-orbit,
  .vm-glyph-orbit circle,
  .vm-glyph-bars i,
  .vm-favicon-chip {
    animation: none !important;
    transition: none !important;
  }

  .thinking-stage {
    background: none;
    color: var(--text-soft);
  }
}

/* Histórico unificado: narração e ferramentas sob um único acionador. */
.thought-panel .thought-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thought-panel .tools-row {
  margin-top: 10px;
}
