/* ==========================================================================
   BeautifulUI-Inspired Animations & Patterns
   Adapted from beui.dev for vanilla HTML/CSS/JS
   ========================================================================== */

/* -------------------------------------------------------------------------
   1. AGENT LOADING STATES
   ------------------------------------------------------------------------- */

/* Reasoning Text - Shimmering phrases with cascade animation */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes cascadeIn {
  0% {
    opacity: 0;
    transform: translateY(-8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cascadeOut {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(8px);
  }
}

.reasoning-text {
  position: relative;
  display: inline-block;
  min-height: 1.5em;
}

.reasoning-text__phrase {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  background: linear-gradient(
    90deg,
    var(--color-text-faint) 0%,
    var(--color-text-muted) 50%,
    var(--color-text-faint) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.2s linear infinite;
}

.reasoning-text__phrase--entering {
  animation: cascadeIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards,
             shimmer 2.2s linear infinite;
}

.reasoning-text__phrase--exiting {
  animation: cascadeOut 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* ASCII Loader Indicator */
@keyframes asciiSpin {
  0%, 100% { content: "⠋"; }
  12.5% { content: "⠙"; }
  25% { content: "⠹"; }
  37.5% { content: "⠸"; }
  50% { content: "⠼"; }
  62.5% { content: "⠴"; }
  75% { content: "⠦"; }
  87.5% { content: "⠧"; }
}

.ascii-loader::before {
  content: "⠋";
  animation: asciiSpin 1s steps(8) infinite;
  font-family: monospace;
  color: var(--color-accent);
  margin-right: 0.5em;
}

/* Agent Progress Timer */
.agent-progress {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.agent-progress__timer {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--color-text-faint);
  min-width: 3.5em;
}

/* -------------------------------------------------------------------------
   2. AGENT ACTIVITY (THINKING TRACES)
   ------------------------------------------------------------------------- */

/* Activity Stream Container */
.activity-stream {
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0%, black 8px, black calc(100% - 8px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 8px, black calc(100% - 8px), transparent 100%);
}

.activity-stream::-webkit-scrollbar {
  width: 6px;
}

.activity-stream::-webkit-scrollbar-track {
  background: transparent;
}

.activity-stream::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

/* Activity Item */
@keyframes activitySlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.activity-item {
  animation: activitySlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--color-border);
  margin-bottom: var(--space-2);
  position: relative;
}

.activity-item--working {
  border-left-color: var(--color-accent);
}

.activity-item--complete {
  border-left-color: var(--color-success);
}

.activity-item__dot {
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
}

.activity-item--working .activity-item__dot {
  background: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
  animation: pulseDot 1s ease-in-out infinite;
}

.activity-item--complete .activity-item__dot {
  background: var(--color-success);
}

/* -------------------------------------------------------------------------
   3. STREAMING RESPONSE
   ------------------------------------------------------------------------- */

/* Stable Response Surface */
.streaming-response {
  position: relative;
  transition: opacity 0.3s ease;
}

.streaming-response[aria-busy="true"] {
  opacity: 0.95;
}

.streaming-response[aria-busy="false"] {
  opacity: 1;
}

/* Completion Actions */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.completion-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  animation: fadeInUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: 0.2s;
}

.completion-action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.completion-action:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-accent-border);
  color: var(--color-text);
}

.completion-action svg {
  width: 14px;
  height: 14px;
}

/* Copy Feedback */
@keyframes copySuccess {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.completion-action--copied {
  animation: copySuccess 0.3s ease;
  color: var(--color-success);
  border-color: var(--color-success);
}

/* -------------------------------------------------------------------------
   4. CITATIONS
   ------------------------------------------------------------------------- */

/* Inline Citation Marker */
.citation-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7em;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  margin: 0 0.15em;
  vertical-align: super;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  line-height: 1;
}

.citation-marker:hover {
  background: var(--color-accent);
  color: var(--color-accent-text);
  transform: translateY(-1px);
}

/* Citation List */
@keyframes citationSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.citation-list {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.citation-list__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.citation-list__title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.citation-list__chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.citation-list__chevron--open {
  transform: rotate(180deg);
}

.citation-list__items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.citation-list__items--open {
  max-height: 500px;
}

.citation-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  animation: citationSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.citation-item__index {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.citation-item__content {
  flex: 1;
  min-width: 0;
}

.citation-item__title {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 2px;
}

.citation-item__domain {
  font-size: var(--fs-xs);
  color: var(--color-text-faint);
  font-family: var(--font-mono);
}

.citation-item__link {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  transition: color 0.2s ease;
}

.citation-item__link:hover {
  color: var(--color-accent);
}

/* -------------------------------------------------------------------------
   5. ENHANCED TRACE COMPONENT
   ------------------------------------------------------------------------- */

/* Breathing animation for active trace */
@keyframes traceBreathe {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.01);
  }
}

.trace.is-thinking {
  animation: traceBreathe 2.4s ease-in-out infinite;
}

/* Trace collapse animation */
@keyframes traceCollapse {
  from {
    max-height: var(--trace-height, 300px);
    opacity: 1;
  }
  to {
    max-height: 0;
    opacity: 0;
  }
}

.trace__body--collapsing {
  animation: traceCollapse 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* -------------------------------------------------------------------------
   6. BEAUTIFUL UI ADDITIONAL ANIMATIONS
   ------------------------------------------------------------------------- */

@keyframes shimmer-text {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes stream-in {
  from {
    opacity: 0;
    filter: blur(4px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

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

/* Pixel grid animation for loading state */
@keyframes pixel-on {
  0%, 100% {
    opacity: 0.15;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* -------------------------------------------------------------------------
   7. REDUCED MOTION SUPPORT
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .reasoning-text__phrase,
  .ascii-loader::before,
  .activity-item,
  .citation-item,
  .trace.is-thinking {
    animation: none !important;
  }
  
  .activity-stream {
    scroll-behavior: auto;
  }
  
  .citation-list__items {
    transition: none;
  }
}
