/* Agent pipeline visualization: beautifului Thinking trace plus Task rows,
   translated to Neribo tokens, Lucide icons, hairline borders, no shadows. */

:root,
html[data-theme="dark"] {
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.13);
}

html[data-theme="light"] {
  --ok: #047857;
  --ok-soft: rgba(4, 120, 87, 0.1);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.1);
}

html[data-theme="warm"] {
  --ok: #4d7c0f;
  --ok-soft: rgba(77, 124, 15, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
}

@keyframes trace-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes trace-shimmer {
  to { background-position: -200% 0; }
}

/* ---------- thinking trace ---------- */

.agent-trace {
  margin-bottom: 10px;
}

.trace-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin: 0;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  vertical-align: top;
}

.trace-head:hover {
  background: var(--hover);
}

.trace-glyph {
  width: 16px;
  height: 16px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: color 200ms ease;
}

.trace-head:not(.working) .trace-glyph {
  color: var(--text-3);
}

.trace-glyph svg {
  width: 16px;
  height: 16px;
}

.trace-status {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-head.working .trace-status {
  color: transparent;
  background: linear-gradient(90deg, var(--text-3) 35%, var(--text) 50%, var(--text-3) 65%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: trace-shimmer 1.4s linear infinite;
}

.trace-time {
  flex: none;
  margin-left: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.trace-chev {
  flex: none;
  display: flex;
  color: var(--text-3);
}

.trace-chev svg {
  width: 14px;
  height: 14px;
  transition: transform 300ms var(--ease-out);
}

.agent-trace:not(.closed) .trace-chev svg {
  transform: rotate(180deg);
}

.trace-body {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transition: grid-template-rows 400ms var(--ease-out), opacity 400ms var(--ease-out);
}

.agent-trace.closed .trace-body {
  grid-template-rows: 0fr;
  opacity: 0;
}

.trace-clip {
  overflow: hidden;
  min-height: 0;
}

.trace-list {
  position: relative;
  padding: 4px 0 6px 8px;
}

.trace-rail {
  position: absolute;
  left: 14px;
  top: 10px;
  width: 1px;
  height: 0;
  background: var(--border-soft);
  transition: height 500ms cubic-bezier(0.23, 1, 0.32, 1);
}

.trace-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 2px 6px 2px 0;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text);
  animation: trace-in 320ms var(--ease-out) both;
  animation-delay: var(--d, 0ms);
}

a.trace-row {
  color: var(--link);
  text-decoration: none;
}

a.trace-row:hover {
  background: var(--hover);
}

.trace-dot {
  width: 14px;
  height: 14px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--text-3);
  color: #fff;
}

.trace-dot svg {
  width: 9px;
  height: 9px;
}

.trace-dot.t-accent { background: var(--link); }
.trace-dot.t-warn { background: var(--warn); }
.trace-dot.t-ok { background: var(--ok); }

.trace-ico {
  width: 14px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
}

.trace-ico svg {
  width: 13px;
  height: 13px;
}

.trace-primary {
  min-width: 0;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-sub {
  min-width: 0;
  font-size: 11.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-row .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.trace-query {
  color: var(--text-2);
}

.trace-diff {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.trace-diff .add { color: var(--ok); }
.trace-diff .del { color: var(--danger); }

.trace-more {
  padding: 2px 0 2px 22px;
  font-size: 12.5px;
  color: var(--text-3);
  animation: trace-in 320ms var(--ease-out) both;
  animation-delay: var(--d, 0ms);
}

/* ---------- plan task rows ---------- */

.plan-rows {
  margin: 2px 0 10px;
  border-top: 1px solid var(--border-soft);
}

.plan-row {
  border-bottom: 1px solid var(--border-soft);
  animation: trace-in 320ms var(--ease-out) both;
  animation-delay: var(--d, 0ms);
}

.plan-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 6px 4px 6px 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.plan-badge {
  position: relative;
  width: 24px;
  height: 24px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  color: var(--text-2);
  background: conic-gradient(var(--link) calc(var(--p, 0) * 1%), var(--border-soft) 0);
  transition: background-color 0.15s, color 0.15s;
}

.plan-badge::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--bg);
}

.plan-badge > * {
  position: relative;
  z-index: 1;
}

.plan-badge svg {
  width: 13px;
  height: 13px;
}

.plan-badge.pending {
  color: var(--text-3);
}

.plan-badge.done {
  background: var(--ok-soft);
  color: var(--ok);
}

.plan-badge.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.plan-badge.done::after,
.plan-badge.failed::after {
  display: none;
}

.plan-label {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-meta {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.plan-pill {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.plan-pill.done {
  background: var(--ok-soft);
  color: var(--ok);
}

.plan-pill.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.plan-retry {
  flex: none;
}

.plan-chev {
  display: flex;
  color: var(--text-3);
}

.plan-chev svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s var(--ease-out);
}

.plan-row.closed .plan-chev svg {
  transform: rotate(-90deg);
}

.plan-detail {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.24s var(--ease-out);
}

.plan-row.closed .plan-detail {
  grid-template-rows: 0fr;
}

.plan-dbody {
  overflow: hidden;
  min-height: 0;
  padding-bottom: 6px;
}

.plan-dline {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 5px 8px 5px 34px;
  font-size: 12.5px;
  color: var(--text-2);
}

.plan-dline .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

/* ---------- demo ---------- */

.demo-note {
  font-size: 12px;
  color: var(--text-3);
  padding: 2px 0 8px;
}

html.reduce-motion .trace-head.working .trace-status {
  color: var(--text-2);
  background: none;
  animation: none;
}

html.reduce-motion .trace-row,
html.reduce-motion .plan-row,
html.reduce-motion .trace-more {
  animation: none;
}

html.reduce-motion .trace-ring,
html.reduce-motion .trace-head:not(.working) .trace-status {
  animation: none;
}


@keyframes trace-spin { to { transform: rotate(360deg); } }
.trace-ring { width: 12px; height: 12px; flex: none; margin: 0 1px; border-radius: 50%; border: 1.5px solid var(--border); border-top-color: var(--text-2); animation: trace-spin 700ms linear infinite; }
@keyframes trace-settled { from { opacity: 0; } to { opacity: 1; } }
.trace-head:not(.working) .trace-status { animation: trace-settled 350ms ease-out both; }

/* the working loader lives in the header glyph, not the body */

.trace-glyph .dots { display: none; padding: 0; vertical-align: baseline; }
.trace-head.working .trace-glyph .dots { display: inline-grid; }
.trace-head.working .trace-glyph svg { display: none; }

/* ---------- polish: settle sweep, live pulse, progress hairline ---------- */

.trace-head.settled-flash {
  background-image: linear-gradient(100deg, transparent 20%, var(--press) 50%, transparent 80%);
  background-size: 280% 100%;
  animation: settle-sweep 650ms var(--ease-out);
}

@keyframes settle-sweep {
  from { background-position: 110% 0; }
  to { background-position: -30% 0; }
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.trace-row.live .trace-dot,
.trace-row.live .trace-ico {
  animation: live-pulse 1.5s ease-in-out infinite;
}

.trace-progress {
  height: 2px;
  margin: 2px 0 0 8px;
  max-width: 220px;
  border-radius: 2px;
  background: var(--border-soft);
  overflow: hidden;
  opacity: 0;
  transition: opacity 240ms ease;
}

.agent-trace.working .trace-progress { opacity: 1; }

.trace-progress span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: 2px;
  background: var(--text-3);
  transform: translateX(-110%);
}

.agent-trace.working .trace-progress span { animation: prog-slide 1.15s var(--ease-in-out) infinite; }

@keyframes prog-slide {
  from { transform: translateX(-110%); }
  to { transform: translateX(290%); }
}

.trace-progress.done { opacity: 0; transition: opacity 380ms ease 120ms; }

.trace-progress.done span { animation: none; width: 100%; transform: none; }

html.reduce-motion .trace-head.settled-flash { animation: none; background-image: none; }

html.reduce-motion .trace-row.live .trace-dot,
html.reduce-motion .trace-row.live .trace-ico { animation: none; }

html.reduce-motion .agent-trace.working .trace-progress span { animation: none; transform: none; width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .trace-head.settled-flash { animation: none; background-image: none; }
  .trace-row.live .trace-dot,
  .trace-row.live .trace-ico { animation: none; }
  .agent-trace.working .trace-progress span { animation: none; transform: none; width: 100%; }
}
