/* The stored trace of a run and its steps (js/agent-trace.js), and the analysis solution block.
   Moved out of base.css, shared-components.css and features.css in their
   original cascade order; loaded after features.css and before type.css. */

.agent-trace-toggle,
.analysis-solution-toggle {
  display: inline-block;
  margin-top: 12px;
  margin-right: 12px;
  font-size: var(--text-xs);
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  padding: 4px 0;
  opacity: 0.92;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.agent-trace-toggle:hover,
.analysis-solution-toggle:hover {
  text-decoration: none;
  opacity: 1;
}

.analysis-solution {
  display: none;
  margin-top: 8px;
  font-size: var(--text-xs);
}

.analysis-solution.open {
  display: block;
}

.analysis-solution-card {
  padding: 2px 0 0;
}

.analysis-solution-section + .analysis-solution-section {
  margin-top: 12px;
}

.analysis-solution-code {
  margin: 8px 0 0;
  max-height: 520px;
  overflow: auto;
  border-radius: var(--r-sm);
  border: none;
  padding: 12px;
  font-size: var(--text-xs);
  line-height: 1.45;
}

.agent-trace { display: none; margin-top: 8px; }

.agent-trace.open { display: block; }

.agent-step {
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin-top: 8px;
  font-size: var(--text-sm);
}

.agent-step.error { border-color: rgba(239, 68, 68, 0.42); }

.agent-step.finish { border-color: rgba(16, 185, 129, 0.36); }

.agent-step.nested {
  margin-left: 22px;
  position: relative;
}

.agent-step.nested::before {
  content: "└";
  position: absolute;
  left: -16px;
  top: 6px;
  color: var(--text);
  font-size: var(--text-md);
}

.agent-step-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.agent-step .step-body {
  margin-top: 6px;
  font-size: var(--text-xs);
}

.agent-step .step-body .step-arg-label {
  margin-top: 2px;
  margin-bottom: 6px;
  font-weight: 600;
}

.agent-step .step-body .step-code-kind {
  margin-top: 4px;
  margin-bottom: 4px;
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.agent-step .step-body pre {
  border: 0;
  border-radius: 0;
  padding: 4px 0 0;
  margin: 4px 0 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.agent-step .step-error {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.agent-step,
.agent-step.nested,
.agent-step .step-body pre {
  border-color: transparent;
  color: var(--text);
}

.agent-step .step-body .step-arg-label {
  color: var(--ink);
}

.agent-step .step-body {
  color: var(--muted) !important;
}

.agent-step-head,
.agent-step-head .step-label {
  color: var(--ink);
}

.agent-step .step-error {
  color: var(--red);
}

.agent-trace-toggle,
.analysis-solution-toggle {
  color: var(--muted);
  font-weight: 400;
}

.agent-trace-toggle:hover,
.analysis-solution-toggle:hover {
  color: var(--text);
}

.analysis-solution {
  color: var(--text);
}

.analysis-solution-card {
  background: transparent;
}

.analysis-solution-code {
  background: rgba(248, 250, 252, 0.72);
  color: var(--ink-strong);
}

.agent-step {
  background: rgba(248, 250, 252, 0.82);
  border-color: var(--border-soft);
}

.agent-step.nested {
  background: rgba(241, 245, 249, 0.74);
}

.agent-step-head .step-action {
  color: var(--text);
  font-weight: 650;
}

.agent-trace-summary {
  flex: 0 0 auto;
  margin: 0 0 12px;
  padding: 2px 4px 14px;
  border-bottom: 1px solid var(--border-soft);
}

.agent-trace-summary-group + .agent-trace-summary-group {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--border-soft);
}

.agent-trace-summary-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.agent-trace-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 12px;
}

.agent-trace-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.agent-trace-metric strong {
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.agent-trace-metric span {
  color: var(--muted);
  font-size: var(--text-2xs);
  font-weight: 400;
}

@media (max-width: 560px) {
  .agent-trace-summary-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      column-gap: 8px;
    }
}
.agent-step-head .step-label,
.agent-step .step-body .step-code-kind {
  color: var(--muted);
}

.agent-step .step-body pre {
  background: transparent;
  border-color: transparent;
}

.agent-step > summary.agent-step-head {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.agent-step > summary.agent-step-head::-webkit-details-marker {
  display: none;
}

.agent-step .step-toggle-icon {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}

.agent-step[open] .step-toggle-icon {
  transform: rotate(225deg);
}

.agent-trace.open,
.analysis-solution.open {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface-inset);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: none;
  overflow: hidden;
}

.agent-trace,
.agent-step,
.agent-step .step-body {
  min-width: 0;
  max-width: 100%;
}

.agent-step .step-body {
  max-height: min(560px, 60vh);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.agent-step .step-body pre,
.agent-step .step-body pre.step-code {
  max-width: 100%;
  box-sizing: border-box;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: hidden;
}

.agent-trace.open > .agent-step:first-child,
.analysis-solution.open > .analysis-solution-card:first-child {
  margin-top: 0;
}
