/*
 * Agent motion (owner decision, 2026-10-10): movement that shows an agent
 * at work, never decoration for its own sake.
 *
 * - A new chat opens on the agent orb, a soft glow and the flow of how the
 *   agent works (understand, check, investigate, answer), with a light that
 *   travels through it; the greeting and the guide rise in.
 * - While a reply runs, the message box wears a flowing gradient edge, the
 *   live line shimmers, and new messages, steps and task notices rise in as
 *   they arrive. Turns already finished do not move.
 * - Running tasks carry a slow sweep of light, in the panel and on the
 *   tasks line.
 *
 * Colors come from the FeedMob accents: teal, sky blue and amber. Everything
 * here stops for people who ask the system for reduced motion.
 */

:root {
  --agent-1: #00b5ad;
  --agent-2: #1b9bc2;
  --agent-3: #f7bd63;
  --agent-glow: rgba(0, 181, 173, 0.22);
}

[data-theme="dark"] { --agent-glow: rgba(0, 181, 173, 0.28); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --agent-glow: rgba(0, 181, 173, 0.28); }
}

@property --agent-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@keyframes agent-turn { to { --agent-angle: 360deg; } }
@keyframes agent-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes agent-breathe { 0%, 100% { transform: scale(1); opacity: 0.75; } 50% { transform: scale(1.12); opacity: 1; } }
@keyframes agent-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes agent-drift {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-46%, -6%) scale(1.08); }
}
@keyframes agent-blink { 50% { opacity: 0; } }

/* ---------- A new chat: orb, glow and the agent's flow ---------- */

.agent-hero {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 8vh;
  height: 72px;
}

/* A wide, faint glow behind the orb and the greeting. */
.agent-hero::before {
  content: "";
  position: absolute;
  top: -60px;
  left: 50%;
  width: min(640px, 90vw);
  height: 260px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, var(--agent-glow), transparent 70%),
    radial-gradient(closest-side at 70% 40%, rgba(27, 155, 194, 0.14), transparent 70%),
    radial-gradient(closest-side at 30% 60%, rgba(247, 189, 99, 0.12), transparent 70%);
  filter: blur(24px);
  transform: translate(-50%, 0);
  animation: agent-drift 12s ease-in-out infinite;
  pointer-events: none;
}

/* The orb: a turning ring of the three accents around a glassy core. */
.agent-orb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: conic-gradient(from var(--agent-angle), var(--agent-1), var(--agent-2), var(--agent-3), var(--agent-1));
  box-shadow: 0 10px 40px var(--agent-glow);
  animation: agent-turn 6s linear infinite;
}

.agent-orb::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: conic-gradient(from var(--agent-angle), var(--agent-1), var(--agent-2), var(--agent-3), var(--agent-1));
  filter: blur(18px);
  opacity: 0.55;
  animation: agent-turn 6s linear infinite reverse, agent-breathe 4s ease-in-out infinite;
  z-index: -1;
}

.agent-orb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.25) 30%, transparent 52%),
    radial-gradient(circle at 70% 78%, rgba(29, 38, 47, 0.22), transparent 55%);
}

.chat-page--fresh .agent-hero + .chat-thread { margin-top: var(--space-4); }
.chat-page--fresh .chat-reply,
.chat-welcome { animation: agent-rise 600ms ease-out both; }

/* How the agent works: four stages on a line, a light travelling through
   them, each stage lighting up as the light passes. */
.agent-flow {
  --flow-cycle: 6s;
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.agent-flow::before,
.agent-flow::after {
  content: "";
  position: absolute;
  top: 17px;
  left: 12.5%;
  right: 12.5%;
  height: 2px;
  border-radius: 1px;
}

.agent-flow::before { background: var(--color-border); }

.agent-flow::after {
  background: linear-gradient(90deg, transparent, var(--agent-1) 45%, var(--agent-2) 55%, transparent) no-repeat;
  background-size: 30% 100%;
  animation: agent-flow-light var(--flow-cycle) ease-in-out infinite;
}

@keyframes agent-flow-light {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}

.agent-flow li {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  text-align: center;
}

.agent-flow__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-raised);
  color: var(--color-text-muted);
  animation: agent-flow-stage var(--flow-cycle) ease-in-out infinite;
}

.agent-flow li:nth-child(2) .agent-flow__icon { animation-delay: calc(var(--flow-cycle) * 0.22); }
.agent-flow li:nth-child(3) .agent-flow__icon { animation-delay: calc(var(--flow-cycle) * 0.44); }
.agent-flow li:nth-child(4) .agent-flow__icon { animation-delay: calc(var(--flow-cycle) * 0.66); }

@keyframes agent-flow-stage {
  0%, 30%, 100% { border-color: var(--color-border); color: var(--color-text-muted); box-shadow: none; }
  10%, 18% { border-color: var(--agent-1); color: var(--agent-1); box-shadow: 0 0 0 4px var(--agent-glow); }
}

.agent-flow strong { color: var(--color-heading); font-size: var(--text-sm); font-weight: var(--font-semibold); }
.agent-flow li > span:last-child { font-size: var(--text-xs); line-height: 1.45; color: var(--color-text-muted); }

/* ---------- While the agent works ---------- */

/* The message box: a flowing gradient edge while focused, brighter and
   with a glow while a reply runs. */
.chat-composer { position: relative; }

.chat-composer::before,
.chat-composer::after {
  content: "";
  position: absolute;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease;
  background: conic-gradient(from var(--agent-angle), transparent 0 20%, var(--agent-1) 32%, var(--agent-2) 44%, var(--agent-3) 52%, transparent 64% 100%);
  animation: agent-turn 4s linear infinite;
}

/* The edge: the gradient, masked to a 1.5px ring. */
.chat-composer::before {
  inset: -1px;
  padding: 1.5px;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

/* The glow: the same gradient, blurred, behind the box. */
.chat-composer::after {
  inset: 4px;
  z-index: -1;
  filter: blur(18px);
}

.chat-composer:focus-within::before { opacity: 0.55; }
.chat-composer.is-busy::before { opacity: 1; }
.chat-composer.is-busy::after { opacity: 0.45; }

/* The live line ("Thinking…", "Running 3 tasks…"): a light sweeps the text. */
.agent-shimmer {
  background: linear-gradient(90deg, var(--color-text-muted) 0%, var(--color-text-muted) 40%, var(--agent-1) 50%, var(--color-text-muted) 60%, var(--color-text-muted) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: agent-shimmer 2.2s linear infinite;
}

/* What arrives during a running turn rises in; finished turns stay still. */
.chat-turn.is-live .chat-user,
.chat-turn.is-live .chat-reply,
.chat-turn.is-live .chat-notice,
.chat-turn.is-live .chat-working,
.chat-turn.is-live .chat-process__step { animation: agent-rise 420ms ease-out both; }

.chat-reply.is-streaming > :last-child::after { animation: agent-blink 1s steps(1) infinite; }

/* ---------- Running tasks ---------- */

.activity__item--running,
.chat-tasks.is-running {
  background-image: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--agent-1) 10%, transparent) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: agent-shimmer 3s linear infinite;
}

.chat-tasks.is-running { border-color: color-mix(in srgb, var(--agent-1) 35%, transparent); color: var(--color-heading); }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .agent-hero::before,
  .agent-orb,
  .agent-orb::before,
  .agent-flow::after,
  .agent-flow__icon,
  .chat-page--fresh .chat-reply,
  .chat-welcome,
  .chat-composer::before,
  .chat-composer::after,
  .agent-shimmer,
  .chat-turn.is-live *,
  .chat-reply.is-streaming > :last-child::after,
  .activity__item--running,
  .chat-tasks.is-running { animation: none; }

  .agent-shimmer { color: var(--color-text-muted); background: none; }
}

@media (max-width: 760px) {
  .agent-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: var(--space-4); }
  .agent-flow::before, .agent-flow::after { display: none; }
}
