/* Run recovery (frontend/chat/run-recovery.js): retry/fallback status beside the typing dots, the failure notice
   row and the Interrupted label. Ported from the Control UI 2026.11.6 ui/src/styles/chat/run-failure.css and
   working-indicator.css (.chat-working-indicator__status, .chat-turn-recap); colours are ClawChats'. */

.message.run-failure,
.message .chat-turn-recap {
  --rr-text: var(--text-primary);
  --rr-muted: var(--text-muted);
  --rr-warn: #f59e0b;
  --rr-border: var(--border-color);
}

[data-theme="light"] .message.run-failure,
[data-theme="light"] .message .chat-turn-recap {
  --rr-warn: #92400e;
}

/* Working status: muted text after the dots, before the thinking timer. */
.typing-indicator span.typing-status {
  width: auto;
  height: auto;
  background: none;
  border-radius: 0;
  animation: none;
  margin-left: 4px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Interrupted: the Control UI's settled-turn recap line under the saved output. */
.message .chat-turn-recap {
  display: inline-flex;
  align-items: center;
  margin: 4px 0 0;
  color: var(--rr-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chat-run-failure {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 16px 0;
  padding: 4px 0 4px 16px;
  border-inline-start: 2px solid color-mix(in srgb, var(--rr-warn) 55%, var(--rr-border));
  font-size: 12px;
  color: var(--rr-text);
}

.chat-run-failure__icon {
  display: inline-flex;
  flex: 0 0 18px;
  margin-top: 7px;
  color: var(--rr-warn);
}

.chat-run-failure__icon svg {
  width: 18px;
  height: 18px;
}

.chat-run-failure__content {
  min-width: 0;
  flex: 1;
}

.chat-run-failure__title {
  font-weight: 600;
}

.chat-run-failure__repeat {
  color: var(--rr-muted);
  font-size: 11px;
  white-space: nowrap;
}

.chat-run-failure__summary,
.chat-run-failure__details p {
  margin: 6px 0 0;
  color: var(--rr-muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.chat-run-failure__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}

.chat-run-failure__heading {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* Try again: the Control UI's .btn.primary.btn--sm. */
.chat-run-failure__retry {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent-color);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: default;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--accent-color) 12%, transparent);
  transition: background 100ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 100ms cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-run-failure__retry:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--accent-color) 25%, transparent);
}

.chat-run-failure__retry svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.chat-run-failure__copy {
  display: inline-flex;
  flex-shrink: 0;
}

.chat-run-failure__copy .chat-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--rr-muted);
  opacity: 0;
  pointer-events: none;
}

.chat-run-failure__copy svg {
  width: 14px;
  height: 14px;
}

.chat-run-failure:hover .chat-copy-btn,
.chat-run-failure:focus-within .chat-copy-btn,
.chat-run-failure__copy .chat-copy-btn:is([data-copy-state="copied"], [data-copy-state="error"]) {
  opacity: 1;
  pointer-events: auto;
}

.chat-run-failure__copy .chat-copy-btn[data-copy-state="copied"] {
  color: var(--accent-text);
}

@media (hover: none) {
  .chat-run-failure__copy .chat-copy-btn {
    width: 32px;
    height: 32px;
    opacity: 1;
    pointer-events: auto;
  }
}

.chat-run-failure__details {
  margin-top: 12px;
  color: var(--rr-muted);
  font-size: 11px;
}

.chat-run-failure__details summary {
  width: fit-content;
  cursor: default;
}

.chat-run-failure__details pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 100%;
  max-height: 240px;
  overflow: auto;
  margin: 8px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Error card above the composer while a failure isn't in the transcript yet (Control UI layout.css .chat-error +
   .chat-composer-neighbor-card, the quiet frame: tone only on the icon, heading and a low-opacity edge). */
[data-ref="runError"] {
  --rr-danger: #ef4444;
  --rr-surface: var(--input-bg, var(--bg-secondary));
  --rr-border: var(--border-color);
}

[data-theme="light"] [data-ref="runError"] {
  --rr-danger: #b91c1c;
}

[data-ref="runError"] .chat-composer-neighbor-card.chat-error {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  width: 100%;
  max-width: var(--chat-thread-max-width, 48rem);
  min-height: 52px;
  margin: 8px auto 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--rr-danger) 16%, transparent);
  border-radius: 16px;
  background: var(--rr-surface);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

[data-ref="runError"] .chat-error:has(details[open]) {
  align-items: start;
}

[data-ref="runError"] .chat-composer-neighbor-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: color-mix(in srgb, var(--rr-danger) 80%, var(--text-secondary));
}

[data-ref="runError"] .chat-composer-neighbor-card__icon svg {
  width: 16px;
  height: 16px;
}

[data-ref="runError"] .chat-error__content {
  min-width: 0;
  overflow-wrap: anywhere;
  user-select: text;
}

[data-ref="runError"] .chat-error__summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: default;
}

[data-ref="runError"] .chat-error__summary::-webkit-details-marker {
  display: none;
}

[data-ref="runError"] .chat-error__summary strong {
  flex: 1;
  min-width: 0;
  white-space: normal;
  font-weight: 600;
  color: color-mix(in srgb, var(--rr-danger) 80%, var(--text-secondary));
}

[data-ref="runError"] .chat-error__summary > span {
  flex: 0 0 auto;
  color: var(--text-muted);
}

[data-ref="runError"] .chat-error__chevron {
  display: inline-flex;
}

[data-ref="runError"] .chat-error__chevron svg {
  width: 14px;
  height: 14px;
}

[data-ref="runError"] .chat-error__content[open] .chat-error__chevron {
  transform: rotate(180deg);
}

[data-ref="runError"] .chat-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
}

[data-ref="runError"] .chat-copy-btn svg {
  width: 14px;
  height: 14px;
}

[data-ref="runError"] .chat-copy-btn[data-copy-state="copied"] {
  color: var(--accent-text);
}

[data-ref="runError"] .chat-error__diagnostic {
  max-height: min(16rem, 35dvh);
  margin: 10px 0;
  overflow: auto;
  overscroll-behavior: contain;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  user-select: text;
}

/* Refresh: the Control UI's plain .btn.btn--sm. */
[data-ref="runError"] .chat-error__refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid var(--rr-border);
  border-radius: 10px;
  background: var(--rr-surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
}

[data-ref="runError"] .chat-error__refresh:hover:not(:disabled) {
  background: color-mix(in srgb, var(--text-primary) 7%, var(--rr-surface));
}

[data-ref="runError"] .chat-error__refresh:disabled {
  opacity: 0.5;
}

@media (max-width: 560px) {
  [data-ref="runError"] .chat-error {
    grid-template-columns: 18px minmax(0, 1fr);
  }

  [data-ref="runError"] .chat-error__refresh {
    grid-column: 2;
    justify-self: start;
  }

  [data-ref="runError"] .chat-error__summary {
    flex-wrap: wrap;
  }

  [data-ref="runError"] .chat-error__summary strong {
    flex-basis: 100%;
  }
}
