/* Owner: d-thread */

/* Rich bot-chat controls use theme tokens only, keeping every palette monochrome. */
.bot-reply-card { display:grid; gap:8px; margin-top:18px; padding:16px; border:1px solid var(--border); border-radius:20px; background:var(--bg-panel); box-shadow:0 12px 34px color-mix(in srgb,#000 8%,transparent); }
.bot-reply-label { margin:0 2px 3px; color:var(--text-muted); font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.1em; }
.bot-reply-choice { display:grid; grid-template-columns:32px 1fr; align-items:center; gap:11px; width:100%; min-height:48px; padding:8px 12px; border:1px solid var(--border-subtle); border-radius:14px; background:var(--bg); color:var(--text); font:inherit; text-align:start; cursor:pointer; transition:background 120ms ease,border-color 120ms ease,transform 120ms ease; }
.bot-reply-choice > span:first-child { display:grid; width:28px; height:28px; place-items:center; color:var(--text); border:1px solid var(--border); border-radius:10px; font-size:11px; font-weight:750; }
.bot-reply-choice:hover,.bot-reply-choice:focus-visible,.bot-reply-choice.is-selected { border-color:var(--text); background:var(--bg-hover); outline:none; transform:translateY(-1px); }
.bot-reply-choice.is-selected > span:first-child { color:var(--btn-primary-fg); background:var(--btn-primary-bg); border-color:var(--btn-primary-bg); }
.bot-file-results { display:flex; flex-wrap:wrap; gap:7px; margin-top:14px; }
.bot-file-chip { padding:7px 10px; border:1px solid var(--border); border-radius:999px; background:var(--bg); color:var(--text); font:inherit; font-size:12px; cursor:pointer; }
.bot-file-chip::before { content:'↗'; margin-inline-end:7px; }
.bot-doc-shade { position:fixed; inset:0; z-index:120; display:grid; place-items:end center; padding:20px; background:color-mix(in srgb,#000 62%,transparent); backdrop-filter:blur(8px); }
.bot-doc-viewer { display:flex; width:min(780px,100%); max-height:min(760px,calc(100vh - 40px)); flex-direction:column; overflow:hidden; border:1px solid var(--border); border-radius:24px; background:var(--bg); color:var(--text); box-shadow:0 30px 90px rgba(0,0,0,.38); }
.bot-doc-viewer > header { display:flex; align-items:center; justify-content:space-between; gap:16px; min-height:60px; padding:13px 18px; border-bottom:1px solid var(--border-subtle); }
.bot-doc-close { min-height:34px; padding:6px 14px; color:var(--btn-primary-fg); font-weight:650; border:0; border-radius:999px; background:var(--btn-primary-bg); cursor:pointer; }
.bot-doc-content { margin:12px; padding:22px; overflow:auto; background:var(--bg-elev); border:1px solid var(--border-subtle); border-radius:16px; }
.bot-doc-content table { width:100%; border-collapse:collapse; }
.bot-doc-content th,.bot-doc-content td { padding:8px; border:1px solid var(--border); text-align:start; }
.bot-message-menu { position:fixed; z-index:130; display:grid; grid-template-columns:repeat(4,1fr); width:240px; gap:4px; padding:10px; border:1px solid var(--border); border-radius:20px; background:var(--bg-elev); box-shadow:0 24px 70px rgba(0,0,0,.32); }
.bot-message-menu button { grid-column:1/-1; min-height:38px; padding:9px 11px; border:0; border-radius:11px; background:transparent; color:var(--text); font:inherit; font-size:13px; text-align:start; cursor:pointer; }
.bot-message-menu button:hover,.bot-message-menu button:focus-visible { background:var(--bg-hover); outline:none; }
.bot-message-menu .bot-reaction { grid-column:auto; display:grid; width:44px; height:40px; place-items:center; padding:0; overflow:hidden; font-size:0; text-align:center; background:var(--bg); border:1px solid var(--border-subtle); border-radius:12px; }
.bot-message-menu .bot-reaction::before { font-size:20px; line-height:1; }
.bot-message-menu .bot-reaction:nth-child(1)::before { content:'👍'; }
.bot-message-menu .bot-reaction:nth-child(2)::before { content:'♥'; }
.bot-message-menu .bot-reaction:nth-child(3)::before { content:'☺'; }
.bot-message-menu .bot-reaction:nth-child(4)::before { content:'!'; font-weight:800; }
:root[data-bot-screen="thread"] [data-unread='true'] { box-shadow:inset 3px 0 0 var(--text); }

.message-text,
.md :is(li, th, td) > p { margin: 0; }

/* Explicit technical direction also applies to the pinned approval host. */
:is(.thread, .pending-approval-host, .rules-sheet) [dir="ltr"] {
  direction: ltr;
  unicode-bidi: isolate;
}

/* Technical tokens keep their internal order without moving adjacent Arabic
   punctuation. Message direction itself comes from dir="auto". */
.thread :is(code, pre, .approval-change-path, .approval-edit-path, .rewind-file-path, .rules-row-path) {
  direction: ltr;
  unicode-bidi: isolate;
}
.thread :is(.msg-user, .msg-agent, .chat-message-source, .secret-label) {
  unicode-bidi: isolate;
}

.chat-message-source {
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.25;
  margin-bottom: 0.25rem;
}

.md .secret-label {
  display: inline-block;
  padding: 0 0.35em;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-ui, sans-serif);
  font-size: 0.8em;
  font-weight: 400;
  line-height: 1.4;
  vertical-align: baseline;
}

.thread-inner {
  width: 100%;
  max-width: 51rem;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

/* Host visibility changes must not anchor the transcript back under it. */
.pending-approval-host {
  overflow-anchor: none;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 0 28px;
  padding: 0;
}

.thread-inner .msg-user {
  align-self: flex-end;
  max-width: min(78%, 46rem);
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px 8px 8px 8px;
  background: var(--bg-element);
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread-inner .msg-agent {
  position: relative;
  width: 100%;
  max-width: 47.5rem;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
}

:root[data-bot-screen="thread"] .thread-inner .msg-user {
  border-radius: 18px 18px 6px 18px;
}

:root[data-bot-screen="thread"] .thread-inner .msg-agent::before {
  position: absolute;
  top: 4px;
  left: -13px;
  width: 4px;
  height: 18px;
  background: var(--bot-accent, var(--accent));
  border-radius: 999px;
  content: "";
}

.reply-speed {
  position: static;
  display: block;
  flex: 0 0 auto;
  overflow: visible;
  margin-top: 8px;
  font-size: 12px;
  line-height: 18px;
}

.reply-speed > summary {
  cursor: pointer;
  line-height: 18px;
  min-height: 20px;
  padding-block: 1px;
}
.reply-speed-values { margin-top: 4px; }

.thread-inner .msg-agent > :first-child,
.thread-inner .msg-agent .md > :first-child {
  margin-top: 0;
}

.thread-inner .msg-agent > :last-child,
.thread-inner .msg-agent .md > :last-child {
  margin-bottom: 0;
}

.msg-agent[data-thread-answer] {
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  align-items: start;
  gap: 7px;
}

.reply-orax,
.reply-orax img {
  display: block;
  width: 22px;
  height: 22px;
}

.reply-orax {
  flex-shrink: 0;
  position: relative;
  transform-origin: 50% 80%;
}

/* Emotion marks sit over the existing character image; the character artwork
   and its state loops remain unchanged. */
.reply-orax[data-emotion]::before,
.reply-orax[data-emotion]::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.reply-orax.is-anger::before {
  inset: 5px 4px auto;
  height: 3px;
  border-top: 1.5px solid currentColor;
  transform: skewY(14deg);
}

.reply-orax.is-anger::after {
  inset: 5px 4px auto;
  height: 3px;
  border-top: 1.5px solid currentColor;
  transform: skewY(-14deg);
}

.reply-orax.is-smile::after,
.reply-orax.is-laugh::after {
  left: 8px;
  top: 12px;
  width: 7px;
  height: 4px;
  border-bottom: 1.5px solid currentColor;
  border-radius: 0 0 8px 8px;
}

.reply-orax.is-laugh::before {
  left: 5px;
  top: 8px;
  width: 12px;
  height: 2px;
  border-block: 1.5px solid currentColor;
}

.reply-orax.is-anger.is-animated { animation: orax-emotion-shake 160ms ease-in-out 3; }
.reply-orax.is-smile.is-animated { animation: orax-emotion-nod 420ms ease-in-out 2; }
.reply-orax.is-laugh.is-animated { animation: orax-emotion-laugh 300ms ease-in-out 3; }

@keyframes orax-emotion-shake { 50% { transform: translateX(1.5px) rotate(2deg); } }
@keyframes orax-emotion-nod { 50% { transform: translateY(1px) rotate(2deg); } }
@keyframes orax-emotion-laugh { 50% { transform: translateY(-1.5px) rotate(-3deg); } }

@media (prefers-reduced-motion: reduce) {
  .reply-orax[data-emotion] {
    animation: none;
    transition: none;
    transform: none;
  }
}

.msg-agent[data-thread-answer]:has(> .reply-orax) {
  grid-template-columns: 22px minmax(0, 1fr);
}

.msg-agent > .reply-orax {
  align-self: start;
  margin-block-start: calc((1lh - 22px) / 2);
}

.turn-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.work-group {
  width: 100%;
  max-width: 47.5rem;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
}

.work-group-header {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 12px 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.work-group-header:hover {
  background: var(--bg);
  color: var(--text);
}

.work-group-header:focus-visible,
.work-step-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.work-group-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-group-header .chevron {
  display: inline-flex;
  flex: none;
  transition: transform 160ms ease;
}

.work-group.open .work-group-header .chevron {
  transform: rotate(90deg);
}

.work-group-body {
  display: none;
  border-top: 1px solid var(--border-subtle);
}

.work-group.open .work-group-body {
  display: block;
}

.work-step + .work-step,
.work-meta + .work-step,
.work-step + .work-meta,
.work-meta + .work-meta {
  border-top: 1px solid var(--border-subtle);
}

.work-step-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.work-step-button:hover {
  background: var(--bg);
}

.engine-step-group > summary::-webkit-details-marker {
  display: none;
}

.engine-step-group > summary .chevron {
  display: inline-flex;
}

.engine-step-group[open] > summary .chevron {
  transform: rotate(90deg);
}

.work-step-icon,
.work-meta-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  color: var(--text-muted);
}

.work-step-label {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-step-button.is-error .work-step-label {
  white-space: normal;
  overflow-wrap: anywhere;
}

.work-step-duration {
  flex: none;
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.step-status-dot {
  width: 0.375rem;
  height: 0.375rem;
  flex: none;
  border-radius: 8px;
  background: var(--text-muted);
  opacity: 0.55;
}

.step-status-dot.is-running {
  background: var(--primary);
  opacity: 1;
  
}

.step-status-dot.is-error {
  background: var(--text);
  opacity: 0.9;
}

.work-step-detail {
  display: none;
  padding: 0 12px 12px 40px;
}

.work-step.open .work-step-detail {
  display: block;
}

.change-stack {
  display: grid;
  gap: 10px;
  margin-block: 4px 8px;
  color: var(--text);
}

.change-stack-title {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.change-file-cards {
  display: flex;
  flex-direction: column;
  padding: 0 8px 8px 0;
}

.change-file-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-s, 8px);
  background: var(--bg-panel);
  box-shadow: 4px 4px 0 var(--bg-element);
  transform: translateX(calc(var(--change-layer, 0) * 4px));
}

.change-file-card:nth-child(2) { --change-layer: 1; }
.change-file-card:nth-child(n + 3) { --change-layer: 2; }
.change-file-card + .change-file-card { margin-top: -3px; }
.change-file-card.is-front { position: relative; z-index: 3; transform: none; }

.change-file-header,
.change-show-more {
  width: 100%;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.change-file-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  text-align: left;
}

.change-file-header:hover { background: var(--bg-hover); }
.change-file-header:focus-visible,
.change-show-more:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.change-file-path { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px/1.4 var(--font-mono, monospace); }
.change-file-counts { display: inline-flex; flex: none; gap: 7px; font: 600 12px/1 var(--font-mono, monospace); }
.change-add-count { color: var(--success, #55a56d); }
.change-remove-count { color: var(--danger, #d26464); }
.change-file-card:not(.is-front) .change-file-diff,
.change-file-card:not(.is-front) .change-show-more { display: none; }

.change-file-diff { overflow-x: auto; border-top: 1px solid var(--border-subtle); background: var(--bg-code); }
.change-diff-line { display: grid; grid-template-columns: 3.2em 3.2em minmax(max-content, 1fr); min-height: 20px; color: var(--text-muted); font: 12px/20px var(--font-mono, monospace); }
.change-diff-line.is-add { color: var(--success, #55a56d); background: color-mix(in srgb, var(--success, #55a56d) 12%, transparent); }
.change-diff-line.is-remove { color: var(--danger, #d26464); background: color-mix(in srgb, var(--danger, #d26464) 12%, transparent); }
.change-diff-line.is-hunk { color: var(--text-faint); background: var(--bg-element); }
.change-line-number { padding-inline: 6px; border-inline-end: 1px solid var(--border-subtle); color: var(--text-faint); text-align: end; user-select: none; }
.change-diff-line code { padding-inline: 10px; white-space: pre; color: inherit; }
.change-show-more { padding: 8px 12px; border-top: 1px solid var(--border-subtle); color: var(--text-muted); font-size: 12px; text-align: center; }
.change-show-more[hidden] { display: none; }
.change-show-more:hover { color: var(--text); background: var(--bg-hover); }

.change-terminal-card { overflow: hidden; border: 1px solid var(--border-subtle); border-radius: var(--radius-s, 8px); background: var(--bg-code); }
.change-terminal-title { display: flex; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border-subtle); color: var(--text-muted); font-size: 12px; }
.change-terminal-title code { min-width: 0; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.change-terminal-card pre { max-height: 16rem; margin: 0; padding: 12px; overflow: auto; color: var(--text-2); font: 12px/1.55 var(--font-mono, monospace); white-space: pre-wrap; }

@media (prefers-reduced-motion: reduce) {
  .change-file-card { transform: none; }
}

.work-detail-section + .work-detail-section {
  margin-top: 12px;
}

.work-detail-label {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.work-detail-code {
  max-height: 16rem;
  margin: 0;
  padding: 12px 12px;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.work-step .step-thumb {
  display: block;
  max-width: 100%;
  max-height: 18rem;
  margin-top: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  object-fit: contain;
}

.work-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

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

.work-meta .step-status-dot {
  width: 0.25rem;
  height: 0.25rem;
}

.work-group .approval,
.work-group .delegate-card {
  margin: 0 12px 12px 40px;
}

.thread-inner .thinking-block {
  max-width: 47.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
}

.thread-inner .thinking-summary {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.thread-inner .thinking-text {
  max-height: 18rem;
  overflow: auto;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}

.md .codeblock {
  width: 100%;
  max-width: 47.5rem;
  margin: 16px 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
}

.md .codeblock-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 2.25rem;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.md .codeblock-lang {
  min-width: 0;
  flex: 1;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.4;
  
}

.md .codeblock-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 1.625rem;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}

.md .codeblock-copy:hover {
  border-color: var(--border-subtle);
  background: var(--bg-element);
  color: var(--text);
}

.md .codeblock-copy:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.md .code-copy {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
}

.md .codeblock-header .code-copy {
  margin-left: auto;
}

.md .codeblock pre {
  max-height: 26.25rem;
  margin: 0;
  padding: 16px 16px;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.md .codeblock code {
  font-family: var(--mono);
  font-size: inherit;
}

.thread-inner .msg-actions {
  max-width: 47.5rem;
}

.msg-user-row {
  display: flex;
  width: 100%;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
}

.msg-user-row .msg-user {
  align-self: auto;
}

.rewind-trigger {
  display: inline-flex;
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  opacity: 0;
  cursor: pointer;
  transition: opacity 140ms ease, background 140ms ease, border-color 140ms ease;
}

.msg-user-row:hover .rewind-trigger,
.work-group-head:hover .rewind-trigger,
.rewind-trigger:focus-visible {
  opacity: 1;
}

.rewind-trigger:hover,
.rewind-trigger:focus-visible {
  border-color: var(--border-subtle);
  background: var(--bg-element);
  color: var(--text);
  outline: none;
}

.msg-user-row .message-edit-trigger {
  margin-inline-end: 2px;
}

.work-group-head {
  display: flex;
  align-items: center;
}

.work-group-head .work-group-header {
  min-width: 0;
  flex: 1;
}

.work-group-head .rewind-trigger {
  margin-right: 8px;
  margin-top: 0;
}

.rewind-dismiss {
  position: fixed;
  inset: 0;
  z-index: 82;
  pointer-events: auto;
}

.rewind-pop {
  position: fixed;
  z-index: 83;
  pointer-events: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  
}

.rewind-pop-label {
  padding: 4px 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  
}

.rewind-item {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rewind-item:hover,
.rewind-item:focus-visible {
  background: var(--bg-panel);
  outline: none;
}

.rewind-item-title {
  font-size: 13px;
  font-weight: 600;
}

.rewind-item-detail {
  color: var(--text-muted);
  font-size: 12px;
}

.rewind-sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.34);
}

.rewind-sheet {
  display: flex;
  width: min(34rem, 100%);
  max-height: min(38rem, calc(100vh - 2rem));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  
}

.rewind-sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px;
}

.rewind-sheet-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
}

.rewind-sheet-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.rewind-sheet-sub {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.rewind-sheet-body {
  min-height: 5rem;
  overflow: auto;
  padding: 0 16px 12px;
}

.rewind-loading,
.rewind-empty {
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.rewind-section {
  margin-top: 12px;
}

.rewind-section-title {
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  
}

.rewind-list {
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
}

.rewind-file,
.rewind-message {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
}

.rewind-file + .rewind-file,
.rewind-message + .rewind-message {
  border-top: 1px solid var(--border-subtle);
}

.rewind-file-action {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  
}

.rewind-file-path {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rewind-file-size,
.rewind-message-role {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

.rewind-message-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rewind-warning {
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--warning, #D4D4D7) 10%, transparent);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.rewind-note {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.rewind-sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-subtle);
}

.rewind-toast {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.rewind-toast-undo {
  flex: none;
  padding: 4px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.rewind-toast-undo:hover {
  border-color: var(--border);
  background: var(--bg-element);
}

.thread-worktree-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: -8px 0 16px;
  padding: 8px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  
}

.thread-worktree-chip {
  display: inline-flex;
  min-width: 0;
  max-width: min(100%, 34rem);
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 8%, var(--bg-panel));
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
}

.thread-worktree-chip:hover {
  border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-element));
  color: var(--text);
}

.thread-worktree-chip:focus-visible,
.thread-worktree-note-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.thread-worktree-icon,
.thread-worktree-chevron {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  color: color-mix(in srgb, var(--primary) 72%, var(--text-muted));
}

.thread-worktree-branch {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
}

.thread-worktree-chevron {
  margin-left: 4px;
  color: var(--text-muted);
}

.thread-worktree-note {
  display: inline-flex;
  min-width: 0;
  max-width: min(100%, 42rem);
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.thread-worktree-note.ok {
  border-color: color-mix(in srgb, var(--success, #4d9b72) 34%, var(--border-subtle));
}

.thread-worktree-note.bad {
  border-color: color-mix(in srgb, var(--error, #c65b5b) 45%, var(--border-subtle));
  color: var(--error-fg, var(--text));
  background: color-mix(in srgb, var(--error, #c65b5b) 8%, var(--bg-panel));
}

.thread-worktree-note > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.thread-worktree-note-close {
  display: inline-flex;
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.thread-worktree-note-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.popup.worktree-menu {
  width: min(22rem, calc(100vw - 1rem));
}

.worktree-menu-branch {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px 8px;
}

.worktree-menu-branch code {
  overflow: hidden;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.worktree-menu-branch span {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popup-item.worktree-menu-item {
  align-items: flex-start;
  padding: 8px 8px;
}

.worktree-menu-icon {
  display: inline-flex;
  width: 1rem;
  flex: none;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  color: var(--text-muted);
}

.worktree-menu-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.worktree-confirm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.worktree-confirm-copy {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.worktree-confirm-branch {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
  font-size: 12px;
}

.worktree-confirm-branch > span {
  color: var(--text-muted);
}

.worktree-confirm-branch code {
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.worktree-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.worktree-inline-error {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--error, #c65b5b) 9%, transparent);
  color: var(--error-fg, var(--text));
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .thread-inner {
    padding: 16px 16px 48px;
  }

  .thread-inner .msg-user {
    max-width: 90%;
  }

  .thread-inner .msg-agent,
  .work-group,
  .md .codeblock,
  .thread-inner .thinking-block {
    max-width: 100%;
  }

  .work-step-detail {
    padding-left: 12px;
  }

  .work-group .approval,
  .work-group .delegate-card {
    margin-left: 12px;
  }
}

/* Approval safety card */
.approval {
  margin: 8px 0 16px;
  padding: 16px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
}

.approval.risk-irreversible {
  background: color-mix(in srgb, var(--error, #f85149) 5%, var(--bg-panel));
}

.approval-head {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.approval-title {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

.approval-badges {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.approval-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.25rem;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-element);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.approval-risk.risk-high {
  border-color: color-mix(in srgb, var(--warning, #D4D4D7) 38%, var(--border-subtle));
  color: var(--warning, #D4D4D7);
}

.approval-risk.risk-irreversible {
  border-color: color-mix(in srgb, var(--error, #f85149) 42%, var(--border-subtle));
  color: var(--error, #f85149);
}

.approval-origin {
  display: inline-flex;
  margin-top: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--warning, #D4D4D7) 10%, transparent);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.approval-reasons {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.approval.risk-irreversible .approval-reasons {
  color: var(--error, #f85149);
}

.approval-payload-label {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.approval-payload {
  max-height: 12rem;
  margin: 4px 0 12px;
  padding: 8px 12px;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.approval-payload.approval-command-args {
  max-height: 8rem;
  font-size: 11px;
}

.approval-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.approval-note {
  color: var(--text-muted);
  font-size: 12px;
}

.approval-note.approval-warning {
  color: var(--danger, #d26464);
  font-weight: 550;
}

.approval-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}

.approval-spinner {
  width: 0.75rem;
  height: 0.75rem;
  flex: none;
  border: 1.5px solid color-mix(in srgb, currentColor 20%, transparent);
  border-top-color: var(--primary);
  border-radius: 6px;
  opacity: 0;
  animation: spin 0.9s linear infinite 0.3s, spinner-reveal 1ms linear 0.3s forwards;
}

/* A hidden or unfocused window freezes every looping animation. */
html[data-anim-paused] .approval-spinner {
  animation-play-state: paused;
}

.approval-ended {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.approval-ended-note {
  color: var(--warning);
  font-size: 12px;
  line-height: 1.45;
}

.approval-ended .btn {
  min-height: 1.875rem;
}

.rules-chip {
  display: inline-flex;
  min-width: 0;
  max-width: 18rem;
  min-height: 1.75rem;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.rules-chip[hidden] {
  display: none;
}

.rules-chip:hover {
  border-color: var(--border);
  background: var(--bg-element);
  color: var(--text);
}

.rules-chip:focus-visible,
.rules-review:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.rules-chip-icon {
  display: inline-flex;
  flex: none;
}

.rules-chip-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rules-chip-count {
  min-width: 1rem;
  padding: 0 4px;
  border-radius: 6px;
  background: var(--bg-element);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.rules-chip-warn {
  color: var(--warning, #D4D4D7);
  white-space: nowrap;
}

.rules-sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  
  pointer-events: auto;
}

.rules-sheet {
  display: flex;
  width: min(36rem, 100%);
  max-height: min(42rem, calc(100vh - 2rem));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  
}

.rules-sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px;
}

.rules-sheet-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
}

.rules-sheet-copy {
  min-width: 0;
  flex: 1;
}

.rules-sheet-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.rules-sheet-sub {
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.rules-sheet-body {
  min-height: 5rem;
  overflow: auto;
  padding: 0 16px 12px;
}

.rules-list {
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

.rules-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
}

.rules-row + .rules-row {
  border-top: 1px solid var(--border-subtle);
}

.rules-row-main {
  min-width: 0;
  flex: 1;
}

.rules-row-path {
  overflow: hidden;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rules-row-meta {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.rules-trust {
  flex: none;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
}

.rules-trust.is-trusted {
  background: color-mix(in srgb, var(--success, #3fb950) 14%, transparent);
  color: var(--success, #3fb950);
}

.rules-trust.is-untrusted {
  background: color-mix(in srgb, var(--warning, #D4D4D7) 14%, transparent);
  color: var(--warning, #D4D4D7);
}

.rules-review {
  flex: none;
  min-height: 1.75rem;
  padding: 0 8px;
  font-size: 12px;
}

.rules-diff-label {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.rules-diff {
  max-height: 18rem;
  margin: 0;
  padding: 12px 12px;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rules-empty,
.rules-loading {
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.rules-sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-subtle);
}

.composer-disclaimer {
  margin: 8px 0 0;
  color: var(--text-faint, var(--text-muted));
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

/* Security settings */
.security-audit {
  overflow: hidden;
}

.security-audit-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 12px;
}

.security-audit-row + .security-audit-row {
  border-top: 1px solid var(--border-subtle);
}

.security-audit-main {
  min-width: 0;
  flex: 1;
}

.security-audit-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.security-audit-detail,
.security-audit-time,
.security-loading,
.security-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.security-loading,
.security-empty {
  padding: 12px 12px;
}

.security-audit-meta {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.security-risk {
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--bg-element);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.security-risk.is-high {
  background: color-mix(in srgb, var(--error, #f85149) 12%, transparent);
  color: var(--error, #f85149);
}

.security-account {
  padding: 12px 12px;
}

.security-account + .security-account {
  border-top: 1px solid var(--border-subtle);
}

.security-account-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.security-account-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.security-account-provider {
  color: var(--text-muted);
  font-size: 12px;
}

.security-account-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.security-cap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.security-cap-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.security-cap-input {
  width: 7rem;
}

/* Pinned acceptance contract */
.contract-strip {
  position: sticky;
  top: 0.5rem;
  z-index: 18;
  margin: 0 0 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  
  
}

.contract-strip.is-collapsed .contract-body {
  display: none;
}

.contract-head {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.contract-head:hover {
  background: color-mix(in srgb, var(--text) 4%, transparent);
}

.contract-sigil {
  display: inline-flex;
  width: 1.375rem;
  height: 1.375rem;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent, #c96b3b) 14%, transparent);
  color: var(--accent, #c96b3b);
}

.contract-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
}

.contract-status {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  
  letter-spacing: 0;
}

.contract-status.accepted {
  background: color-mix(in srgb, var(--success, #3fb950) 12%, transparent);
  color: var(--success, #3fb950);
}

.contract-status.needs-confirmation {
  background: color-mix(in srgb, var(--warning, #D4D4D7) 15%, transparent);
  color: var(--warning, #D4D4D7);
}

.contract-count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.contract-head .chevron {
  display: inline-flex;
  color: var(--text-muted);
  transition: transform 160ms ease;
}

.contract-strip.is-collapsed .contract-head .chevron {
  transform: rotate(-90deg);
}

.contract-body {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.contract-group {
  display: grid;
  gap: 4px;
}

.contract-group-label {
  margin-bottom: 4px;
  color: var(--text-faint, var(--text-muted));
  font-size: 12px;
  font-weight: 500;
  
  letter-spacing: 0;
}

.contract-item {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.42;
}

.contract-item-dot {
  width: 0.375rem;
  height: 0.375rem;
  flex: none;
  border: 1px solid var(--text-faint, var(--text-muted));
  border-radius: 8px;
  transform: translateY(-0.0625rem);
}

.contract-item.is-met {
  color: var(--text);
}

.contract-item.is-met .contract-item-dot {
  border-color: var(--success, #3fb950);
  background: var(--success, #3fb950);
}

.contract-item-text {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.contract-evidence-link {
  flex: none;
  max-width: 15rem;
  overflow: hidden;
  padding: 4px 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--accent, #c96b3b);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contract-evidence-link:hover {
  border-color: color-mix(in srgb, var(--accent, #c96b3b) 35%, var(--border-subtle));
}

.contract-actions,
.contract-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.contract-action {
  min-height: 1.75rem;
  padding: 0 12px;
  font-size: 12px;
}

.contract-empty {
  color: var(--text-muted);
  font-size: 12px;
}

.contract-edit-body {
  display: grid;
  gap: 12px;
  min-width: min(34rem, 80vw);
}

.contract-edit-copy {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.contract-edit-field {
  display: grid;
  gap: 4px;
}

.contract-edit-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  
  letter-spacing: 0;
}

.contract-edit-input {
  min-height: 4.75rem;
  padding: 8px 8px;
  resize: vertical;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.work-step.contract-evidence-hit {
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent, #c96b3b) 13%, transparent);
}

/* VU1: centred reading column, quiet single-line work, one card level. */
.thread-inner {
  max-width: calc(var(--message-max-width) + var(--space-8) * 2);
  padding: var(--space-5) 0 var(--space-6);
}

.turn {
  gap: var(--space-3);
  margin: 0;
  margin-bottom: var(--space-6);
}

/* Turn spacing belongs between turns. Reserving it after Copy compounds the
   reading column's padding, including after an empty changes panel disappears. */
.thread-inner > .turn:last-child {
  margin-bottom: 0;
}

#thread:not(:has(.home)) > .thread-inner {
  padding-bottom: 16px;
}

/* Native details uses content-visibility for its closed body, which can retain
   descendant geometry after keyboard toggles. Remove that body from layout so
   following and gap measurements both use the painted summary edge. */
.thread-inner details:not([open]) > :not(summary) {
  display: none;
}

.thread-inner .msg-user {
  max-width: none;
  max-inline-size: min(80%, var(--message-max-width));
  padding: var(--space-2) var(--space-4);
  color: var(--text);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  background: var(--bg-bubble);
  border: 0;
  border-radius: var(--radius-l);
}

.thread-inner .msg-user-row {
  align-items: center;
}

:root[data-theme] .msg-user {
  border-left: 0;
}

.thread-inner .msg-agent {
  max-width: none;
  max-inline-size: var(--message-max-width);
  color: var(--text);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

.turn-body {
  gap: 12px;
}

.computer-live-view {
  width: min(100%, 760px);
  overflow: hidden;
  background: var(--bg-elevated, var(--bg-bubble));
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
}

.computer-live-view > summary {
  padding: var(--space-2) var(--space-3);
  color: var(--text);
  font-size: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
}

.computer-live-content {
  display: grid;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}

.computer-live-image-button {
  display: block;
  width: 100%;
  max-height: min(52vh, 480px);
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  border: 0;
  border-radius: var(--radius-s);
  cursor: zoom-in;
}

.computer-live-image {
  display: block;
  width: 100%;
  max-height: min(52vh, 480px);
  object-fit: contain;
}

.computer-live-action {
  color: var(--text-muted);
  font-size: var(--text-secondary);
  line-height: var(--leading-secondary);
}

.computer-live-footer .computer-live-action {
  min-width: 0;
  flex: 1;
}

.computer-live-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.computer-live-stop {
  flex: 0 0 auto;
  color: var(--danger, var(--text));
}

@media (max-width: 600px) {
  .computer-live-image-button,
  .computer-live-image {
    max-height: 38vh;
  }
}

.work-group,
.thread-inner .thinking-block {
  max-width: 760px;
  overflow: visible;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.work-group-header {
  gap: var(--space-2);
  padding: var(--space-1) 0;
  color: var(--text-muted);
  font-size: var(--text-secondary);
  line-height: var(--leading-secondary);
  font-weight: 400;
  border-radius: var(--radius-s);
}

.work-group-header:hover {
  color: var(--text);
  background: transparent;
}

.work-group-header .chevron {
  opacity: 0.7;
  transition: transform 120ms ease, opacity 120ms ease;
}

/* The live row states the phase once, with the newest reasoning line, instead
   of repeating a heading for every call. */
.work-group-preview {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-faint, var(--text-muted));
  font-size: var(--text-secondary);
}

/* A step group folded into the turn's work row is content, not a second row:
   its own heading never competes with "Worked for ...". */
.turn-work-content > .work-group[data-nested] > .work-group-head > .work-group-header {
  display: none;
}

/* A notice keeps its own place in the transcript, outside collapsed work. */
.work-notice {
  max-width: 760px;
  margin: 4px 0;
}

/* Repeated identical notices share one row instead of piling up. */
.work-notice-count {
  margin-inline-start: 6px;
  color: var(--text-faint, var(--text-muted));
  font-variant-numeric: tabular-nums;
}

.turn-work-content > .thinking-block {
  margin: 2px 0;
}

.work-group-header:hover .chevron {
  opacity: 1;
}

.work-group-body {
  padding: 4px 0 4px 20px;
  border-top: 0;
}

.work-group-inline {
  position: relative;
}

.work-group-inline > .work-group-head {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
}

.work-group-inline > .work-group-head > .work-group-header {
  display: none;
}

.work-group-inline > .work-group-body {
  display: block;
  padding: 0;
}

.work-group-inline:has(> .work-group-head > .rewind-trigger) > .work-group-body {
  padding-inline-end: 2rem;
}

.work-group-inline:hover > .work-group-head > .rewind-trigger {
  opacity: 1;
}

.turn-work-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}

.turn-work-toggle::-webkit-details-marker {
  display: none;
}

.turn-work-toggle .chevron {
  display: inline-flex;
}

.turn-work[open] > .turn-work-toggle .chevron {
  transform: rotate(90deg);
}

.turn-work + [data-thread-answer] {
  scroll-margin-block-start: 44px;
}

.turn-work-content {
  display: grid;
  gap: 8px;
  padding: 4px 0 4px 16px;
}

.thread-inner .work-progress {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
}

.work-progress > .reply-orax {
  display: none;
}

.work-group .approval,
.work-group .delegate-card {
  margin: 8px 0 8px 0;
}

.work-step + .work-step,
.work-meta + .work-step,
.work-step + .work-meta,
.work-meta + .work-meta {
  border-top: 0;
}

.work-step-button {
  gap: 8px;
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  border-radius: var(--radius-s);
}

.work-step-button:hover {
  color: var(--text);
  background: transparent;
}

.work-step-icon {
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.work-step-icon svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.6;
}

.work-step-duration {
  color: var(--text-faint);
  font-weight: 400;
}

.step-status-dot {
  width: 5px;
  height: 5px;
  opacity: 0.4;
}

.step-status-dot.is-running {
  background: var(--accent);
  opacity: 0.9;
  
}

.work-step-detail {
  padding: 4px 0 8px 24px;
}

.work-detail-code,
.work-detail-code + .work-detail-code {
  padding: 12px 12px;
  color: var(--text-2);
  background: var(--bg-code);
  border: 0;
  border-radius: var(--radius-s);
  font-size: 12px;
}

.work-meta {
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
}

.thread-inner .thinking-summary {
  color: var(--text-muted);
  font-size: var(--text-secondary);
  line-height: var(--leading-secondary);
  font-weight: 400;
  padding: var(--space-1) 0;
}

.thread-inner .thinking-text {
  padding: var(--space-1) 0 var(--space-2) var(--space-5);
  color: var(--text-muted);
  background: transparent;
  border-top: 0;
  font-size: var(--text-secondary);
  font-style: normal;
  line-height: var(--leading-secondary);
}

.md .codeblock {
  max-width: 760px;
  margin: 12px 0;
  background: var(--bg-code);
  border: 0;
  border-radius: var(--radius);
}

.md .codeblock-header {
  min-height: 32px;
  padding: 4px 8px 4px 12px;
  border-bottom: 0;
}

.md .codeblock-lang {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
}

.md .codeblock-copy {
  color: var(--text-muted);
  font-size: 12px;
}

.md .codeblock-copy:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: transparent;
}

.md .codeblock pre {
  padding: 0 12px 12px;
  color: var(--text);
  background: transparent;
  border: 0;
  font-size: 13px;
}

.md pre {
  background: var(--bg-code);
  border: 0;
  border-radius: var(--radius);
}

.md code {
  padding: var(--space-1) var(--space-1);
  color: var(--text);
  background: var(--bg-code);
  border: 0;
  border-radius: var(--radius-s);
  font-size: var(--text-code);
  line-height: var(--leading-code);
}

.md h1,
.md h2,
.md h3,
.md h4 {
  font-weight: 500;
  letter-spacing: 0;
}

.md h1 { font-size: var(--text-h1); line-height: var(--leading-h1); font-weight: 400; }
.md h2 { font-size: var(--text-h2); line-height: var(--leading-h2); }
.md h3,
.md h4 { font-size: var(--text-h3); line-height: var(--leading-h3); }

.md table {
  border-collapse: collapse;
}

.md th,
.md td {
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.md th {
  color: var(--text-muted);
  font-weight: 500;
  background: transparent;
}

.md tr:nth-child(even) td {
  background: transparent;
}

.md blockquote {
  padding-left: 12px;
  color: var(--text-muted);
  border-left: 1px solid var(--border-active);
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  opacity: 0.45;
}

.msg-actions:hover {
  opacity: 1;
}

.message-speak-trigger.is-speaking {
  color: var(--primary);
}

.site-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.site-actions:empty { display: none; }
.preview-load-error { padding: 10px; color: var(--text); font-size: 13px; line-height: 1.5; }

.msg-stopped {
  color: var(--text-faint);
  font-size: 12px;
}

/* Approval: neutral surface with a single border in every state. */
.approval,
.approval.risk-irreversible {
  margin: 8px 0 12px;
  padding: 10px 12px;
  background: var(--bg-element);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.approval-title {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.approval-badges {
  gap: 8px;
}

.approval-badge {
  min-height: 20px;
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border-subtle);
}

.approval-risk.risk-high {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border-subtle));
}

.approval-risk.risk-medium {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border-subtle));
}

.approval-risk.risk-irreversible {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 34%, var(--border-subtle));
}

.approval-origin {
  margin-top: 8px;
  padding: 4px 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-s);
}

.approval-reasons {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.approval.risk-irreversible .approval-reasons {
  color: var(--text-muted);
}

.approval-payload-label {
  margin-top: 12px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
}

.approval-payload {
  max-height: 40vh;
  overflow: auto;
  margin: 8px 0 12px;
  padding: 12px 12px;
  color: var(--text-2);
  background: var(--bg-code);
  border: 0;
  border-radius: var(--radius-s);
  font-size: 12px;
  line-height: 1.55;
}

.approval-actions {
  gap: 6px;
  flex-wrap: wrap;
}

.approval-actions .btn {
  flex: 1 1 0;
  min-height: 30px;
  height: auto;
  max-width: min(100%, 16rem);
  min-width: 0;
  padding: 5px 12px;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  border-radius: var(--radius-s);
}

.approval-actions > :is(.approval-note, .approval-progress, .approval-ended) {
  flex: 1 1 100%;
}

.approval-diff {
  width: 100%;
  min-width: 0;
}

.approval-actions .btn:not(.btn-primary) {
  color: var(--text-2);
  background: transparent;
  border-color: var(--border-subtle);
}

.approval-actions .btn:not(.btn-primary):hover {
  color: var(--text);
  background: var(--bg-hover);
}

.approval-note,
.approval-ended-note {
  color: var(--text-faint);
  font-size: 12px;
}

.approval-progress {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
}

.approval-spinner {
  border-top-color: var(--text-muted);
}

.contract-strip {
  border-color: var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-element);
  
}

.thread-worktree-header {
  margin: -4px 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.thread-worktree-chip {
  color: var(--text-muted);
  font-weight: 400;
  background: transparent;
  border-color: var(--border-subtle);
}

.thread-worktree-chip:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border);
}

.day-divider {
  color: var(--text-faint);
}

@media (max-width: 900px) {
  .thread-inner {
    padding: var(--space-5) 0 var(--space-6);
  }

  .thread-inner .msg-user {
    max-width: none;
    max-inline-size: min(80%, var(--message-max-width));
  }
}

@media (prefers-reduced-motion: reduce) {
  .work-group-header .chevron,
  .msg-actions {
    transition: none;
  }
}

/* Visible model reasoning. Open while streaming by default, respecting the
   person's explicit preference across renders. */
.thinking-block {
  margin: 8px 0;
  overflow: visible;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
}

.thinking-block.is-live {
  border-color: transparent;
  box-shadow: none;
}

.thinking-head {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--text-muted, #8b949e);
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}

.thinking-head:hover {
  color: var(--text, #F2F2F2);
}

.thinking-head:focus-visible {
  outline: 2px solid var(--accent, #D4D4D7);
  outline-offset: -2px;
}

.thinking-title {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.thinking-preview {
  flex: 0 1 auto;
  min-width: 0;
  max-height: 1.4em;
  line-height: 1.4em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.thinking-block.open .thinking-preview {
  display: none;
}

.thinking-time {
  flex-shrink: 0;
  white-space: nowrap;
  color: var(--text-faint, var(--text-muted, #8b949e));
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.thinking-head .chevron {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  transition: transform 160ms ease;
}

.thinking-block.open .thinking-head .chevron {
  transform: rotate(90deg);
}

.thinking-body {
  display: none;
  max-height: min(38vh, 360px);
  overflow: auto;
  padding: 4px 0 8px 20px;
}

.thinking-block.open .thinking-body {
  display: block;
}

/* Reserve the space once, so streamed words do not move the conversation. */
.thinking-block.is-live .thinking-body {
  height: min(38vh, 360px);
  scrollbar-gutter: stable;
  overflow-anchor: none;
  scroll-behavior: auto;
}

/* A paused block is not streaming, so it must not hold the fixed blank area
   above the approval that paused it. */
.thinking-block.is-live.is-paused .thinking-body {
  height: auto;
}

.thinking-text {
  margin: 0;
  color: var(--text-muted, #a7b0ba);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 12.5px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thinking-block.is-live .thinking-text {
  color: var(--text, #d6dde5);
}

/* The body owns scrolling while reasoning streams, including inside the thread. */
.thread-inner .thinking-block.is-live .thinking-text {
  max-height: none;
  overflow: visible;
}

.thinking-foot {
  display: none;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 0 12px 10px;
}

.thinking-block.open .thinking-foot {
  display: flex;
}

.thinking-correct,
.thinking-copy {
  padding: 3px 8px;
  border: 1px solid var(--border, rgba(148, 163, 184, 0.24));
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-muted, #8b949e);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.thinking-correct:hover,
.thinking-copy:hover {
  border-color: var(--accent, #D4D4D7);
  color: var(--text, #F2F2F2);
}

.steer-row {
  align-items: flex-end;
  flex-wrap: wrap;
}

.steer-badge {
  flex: 0 0 auto;
  margin-bottom: 6px;
  color: var(--accent, #D4D4D7);
  font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .thinking-head .chevron,
  .thinking-block {
    transition: none;
  }
}


.approval-change-path {
  font: 12px/1.4 var(--mono);
  overflow-wrap: anywhere;
}

.approval-change-first {
  max-height: 3.9em;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.3 var(--mono);
  margin: 6px 0;
}

.approval-change-full > summary {
  cursor: pointer;
  font-size: 12px;
}

/* A long command must not push Approve and Deny out of reach: the card is
   capped to the visible thread, its details scroll, and the buttons stay below.
   The one-line heading plus a collapsed Details toggle keeps the card compact. */
.approval {
  display: flex;
  flex-direction: column;
  max-height: min(78vh, 46rem);
  box-sizing: border-box;
  min-height: 0;
  container: approval / inline-size;
}

.approval > .approval-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.approval-details > .approval-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.approval > .approval-actions {
  flex: 0 0 auto;
  padding-top: 6px;
}

/* The details are one native disclosure: keyboard toggle with Enter or Space,
   and nothing tall is painted until the person asks for it. */
.approval-details {
  min-width: 0;
  margin-top: 4px;
}

/* Short safety notices stay in place under the summary line. */
.approval > .approval-note,
.approval > .approval-sandbox {
  margin-top: 4px;
}

.approval-sandbox {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.approval-details[open] {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.approval-details-summary {
  width: fit-content;
  padding: 1px 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
}

.approval-details-summary:hover,
.approval-details[open] > .approval-details-summary {
  color: var(--text);
}

.approval-details[open] > .approval-body {
  padding-top: 6px;
}

/* Wrapping belongs to cards narrower than 800px. Above that every action keeps
   one row: flex-basis 0 means the buttons never take a line of their own. */
@container approval (width < 800px) {
  .approval-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .approval-actions .btn {
    width: 100%;
    max-width: none;
  }

  .approval-actions > :is(.approval-note, .approval-progress, .approval-ended) {
    grid-column: 1 / -1;
  }
}


.design-options { margin: 16px 0; }
.design-options-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.design-option { min-width: 0; padding: 12px; border: 1px solid var(--border, #888); border-radius: 12px; }
.design-option h3 { margin: 0 0 10px; font-size: 15px; }
.design-option p { font-size: 14px; line-height: 1.5; }
.design-option button { width: 100%; white-space: normal; }
@media (max-width: 680px) { .design-options-grid { grid-template-columns: 1fr; } }

.ask-user-card { margin: 12px 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-element); outline: none; }
.ask-user-card:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }
.ask-user-question { margin: 0 0 12px; color: var(--text); font-size: 15px; line-height: 1.45; }
.ask-user-choices { display: grid; gap: 8px; }
.ask-user-choice { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; min-height: 48px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); text-align: start; cursor: pointer; }
.ask-user-choice:hover, .ask-user-choice.selected { border-color: var(--accent); background: var(--bg-hover); }
.ask-user-number { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--bg-hover); color: var(--text-2); font-variant-numeric: tabular-nums; }
.ask-user-choice-copy { display: grid; gap: 2px; min-width: 0; }
.ask-user-choice-label { font-weight: 600; }
.ask-user-choice-description { color: var(--text-2); font-size: 12px; line-height: 1.35; }
.ask-user-recommended { color: var(--accent); font-size: 11px; font-weight: 600; }
.ask-user-other-editor { position: relative; margin-top: 8px; }
.ask-user-other-input { width: 100%; min-height: 64px; padding: 10px 42px 10px 10px; resize: vertical; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); font: inherit; }
.ask-user-mic { position: absolute; inset-inline-end: 8px; bottom: 8px; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 50%; background: var(--bg-hover); color: var(--text-2); cursor: pointer; }
.ask-user-mic.listening { color: var(--danger); }
.ask-user-footer { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; }
.ask-user-status { margin-inline-end: auto; color: var(--text-2); font-size: 12px; }

/* The pinned card sits in a host capped at 42vh (inline style in thread.js), so
   the card is capped to what is left of it after the heading line. Without this
   the host scrolled and Approve went out of sight below the composer. */
#pendingApprovalHost > .approval {
  max-height: calc(42vh - 52px);
}

/* Compact chat totals; long tool names wrap on narrow windows. */
.chat-usage {
  flex-shrink: 0;
  margin: 4px 16px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12px;
  max-height: 220px;
  overflow: auto;
}
.chat-usage[hidden] { display: none; }
.chat-usage summary { cursor: pointer; }
.chat-usage dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 8px 0 0; }
.chat-usage dd { margin: 0; overflow-wrap: anywhere; }

.context-popover .usage-details { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.context-popover { max-height: calc(100vh - 64px); overflow-y: auto; }
.context-popover dl.chat-usage { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; max-height: none; }

/* Responsive decision cards below the drawer boundary. The column is whole
   again after the main fix; cards stack their head and give every action a
   full-width 44px target so Deny never leaves the viewport. */
@media (max-width: 900px) {
  html body .approval { padding: 14px 12px; }
  html body .approval-head {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  html body .approval-badges { justify-content: flex-start; }
  html body .approval-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
  html body .approval-actions .btn {
    width: 100%;
    min-height: 44px;
    max-width: none;
  }
  html body .approval-actions > :is(.approval-note, .approval-progress, .approval-ended) {
    grid-column: 1 / -1;
  }
  html body .approval > .approval-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }
  html body .design-options-grid { grid-template-columns: 1fr; }
  html body .design-option button { min-height: 44px; }
}

/* Phone landscape has little height: collapse the long command/explanation
   first and keep the head compact, so the two-column action row survives. */
@media (max-width: 900px) and (max-height: 560px) {
  html body .approval { padding: 10px 12px; }
  html body .approval-head {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  html body .approval-title { font-size: 14px; }
  html body .approval-badges {
    flex: 0 0 auto;
    justify-content: flex-end;
  }
  html body .approval-payload { max-height: 4.5rem; }
  html body .approval-reasons { margin-top: 4px; }
  html body .approval > .approval-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* From 800px of card width every action shares one row. This comes after the
   responsive blocks and repeats the html body prefix, so no earlier grid rule
   can leave a wider card in the two-column layout. A zero flex basis plus
   min-width: 0 keeps all buttons on the first flex line; notes still request a
   full line and sit below. */
@container approval (width >= 800px) {
  html body .approval-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  html body .approval-actions .btn {
    flex: 1 1 0;
    width: auto;
    max-width: min(100%, 16rem);
  }
}

@media (width < 900px) {
  /* The sheet is a flow sibling; reserve only the transcript's clearance. */
  html body #thread:not(:has(.home)) > .thread-inner {
    padding-bottom: 16px;
  }
}

.md .terminal-proposal { padding: 12px; box-sizing: border-box; }
.md .terminal-proposal-preview { width: 100%; box-sizing: border-box; resize: vertical; font-family: var(--font-mono, monospace); background: var(--bg); color: var(--text); }
.md .terminal-proposal-actions { display: flex; gap: 8px; }
.md .terminal-proposal-actions .btn:not(.btn-primary) { color: var(--text-2); background: transparent; border-color: var(--border-subtle); }
.md .terminal-proposal-actions .btn:not(.btn-primary):hover { color: var(--text); background: var(--bg-hover); }
.md .terminal-proposal-actions .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 600px) {
  .md .terminal-proposal-actions { flex-direction: column; align-items: stretch; }
  .md .terminal-proposal-actions button { justify-content: center; min-height: 44px; }
  .md .codeblock-header { flex-wrap: wrap; }
}

.md .terminal-run-destination { padding: 0 12px 12px; color: var(--text-muted); font-size: 12px; }
.md .terminal-proposal-actions button:disabled { opacity: .5; cursor: default; }
@media (max-width: 600px) {
  .md .codeblock-shell .codeblock-header { flex-direction: column; align-items: stretch; }
  .md .codeblock-shell .codeblock-header button { justify-content: center; min-height: 44px; }
}

/* Settings > Appearance > Wrap long lines in code blocks. */
html.code-wrap .thread .md pre,
html.code-wrap .thread .md code {
  white-space: pre-wrap;
  word-break: break-word;
}

.thread-history {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}
.preference-save-card {
  max-width: 32rem;
  margin: .5rem 0 0 2.25rem;
  padding: .75rem;
  border: 1px solid var(--border-subtle);
  border-radius: .75rem;
  background: var(--surface-1);
  display: grid;
  gap: .5rem;
}

.preference-choice { display: flex; align-items: flex-start; gap: .5rem; font-size: .875rem; }
