/* Reply sources + the working-bubble elapsed counter.
 *
 * Kept in its own file so the generated workspace.css stays untouched. Uses the
 * workspace tokens (panel / border / muted / accent) and stays compact.
 */

/* --------------------------------- sources -------------------------------- */
/* Retrieved items for a reply. A source is shown even when the answer did not
 * cite it, and the marker matches any [n] the answer used. */

.msg-sources {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 12px;
}

.msg-sources-head {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.msg-sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-source {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.msg-source-marker {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
  min-width: 18px;
  text-align: right;
}

.msg-source-link {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.msg-source-link:hover,
.msg-source-link:focus-visible {
  border-bottom-color: currentColor;
  outline: none;
}

.msg-source-domain {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.msg-source-cited {
  flex: 0 0 auto;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent, #7c8cff);
  border: 1px solid color-mix(in srgb, var(--accent, #7c8cff) 45%, transparent);
  border-radius: 999px;
  padding: 0 5px;
}

.msg-source-retrievals {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
}

/* -------------------------------- tool trace ------------------------------ */
/* One line per tool call: a spinner while it runs, then a line that expands to
 * its output. A failed call keeps the error on the line in the danger colour so
 * it is visible without opening anything. */

.msg-trace {
  margin: 6px 0 2px;
}

.msg-trace:empty {
  display: none;
}

.trace-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trace-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 3px 6px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.trace-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.trace-icon-svg {
  width: 14px;
  height: 14px;
  opacity: 0.85;
}

.trace-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-elapsed {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.trace-chevron {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  margin-left: auto;
  color: var(--muted);
  transition: transform 120ms ease;
}

.trace-collapsible[open] .trace-chevron {
  transform: rotate(90deg);
}

.trace-collapsible > summary {
  list-style: none;
  cursor: pointer;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.trace-collapsible > summary::-webkit-details-marker {
  display: none;
}

.trace-collapsible > summary > .trace-line {
  flex: 1 1 auto;
  padding-right: 0;
}

.trace-collapsible > summary:hover > .trace-line,
.trace-collapsible > summary:focus-visible > .trace-line {
  color: var(--text);
  background: var(--panel-2);
}

.trace-collapsible > summary:focus-visible {
  outline: 2px solid var(--accent-line, var(--accent));
  outline-offset: 1px;
}

.trace-content {
  margin: 2px 0 6px 22px;
  padding: 6px 8px;
  border-left: 1px solid var(--border);
}

.trace-input {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11.5px;
  word-break: break-word;
}

.trace-code {
  margin: 0;
  padding: 6px 8px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.trace-collapsible.is-error > summary > .trace-line,
.trace-line.is-error {
  color: var(--danger, #e5484d);
}

.trace-collapsible.is-error .trace-icon-svg {
  opacity: 1;
}

.trace-line.is-running .trace-icon::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent, #7c8cff) 35%, transparent);
  border-top-color: var(--accent, #7c8cff);
  animation: thinking-spin 900ms linear infinite;
}

.trace-line.is-running .trace-icon-svg {
  display: none;
}

.trace-line.is-cancelled {
  color: var(--muted);
  opacity: 0.85;
}

/* The working bubble keeps its trace above the streaming text. */
.thinking-trace:empty {
  display: none;
}

.thinking-trace {
  margin: 0 0 6px;
}

/* --------------------------- working-bubble clock -------------------------- */
/* "Agent is working… 12s". Tabular figures keep the label from shifting as the
 * number changes; the counter is decorative for screen readers because the
 * bubble already announces that the agent is working. */

.thinking-elapsed {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}

@media (max-width: 640px) {
  .msg-source {
    flex-wrap: wrap;
  }
  .msg-source-domain {
    width: 100%;
    padding-left: 24px;
  }
}
