/* Chats console (assets/chat-console.js): pick a Headron tool, fill its
   form, run it over /mcp. Flat harness surface: hairlines, no shadows, no
   pills, every target >= 44px. Tokens come from harness-workspace.css.
   Type: Inter (--sans) everywhere; IBM Plex Mono only for code, pre, kbd
   and .chat-record-id. Sizes 12/13/14/15/17/20, weights 400/500/600. */
.chat-console { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; padding-bottom: 8px; font-family: var(--sans); overflow-wrap: anywhere; }
.chat-console code, .chat-console pre, .chat-console kbd { font-family: var(--mono); }
.chat-status { color: var(--muted); font: 500 var(--t-xs) var(--sans); font-variant-numeric: tabular-nums; }
.chat-icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.chat-work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

.chat-toolform { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--ground); min-width: 0; }
.chat-picker { width: 100%; min-height: 44px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: 400 var(--t-md) var(--sans); }
.chat-tool-help { color: var(--muted); font-size: var(--t-md); line-height: 1.5; }
.chat-fields { display: grid; gap: 12px; }
.chat-field { display: grid; gap: 4px; min-width: 0; }
.chat-field-name { color: var(--text); font-size: var(--t-sm); font-weight: 600; }
.chat-field-name code { font-weight: 500; }
.chat-field-help { color: var(--muted); font-size: var(--t-xs); }
.chat-field input,
.chat-field select,
.chat-field textarea { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: 400 var(--t-md) var(--sans); }
.chat-field textarea { min-height: 88px; resize: vertical; }
.chat-field.is-check { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; min-height: 44px; }
.chat-field.is-check input { width: 18px; min-height: 18px; height: 18px; }
.chat-run { justify-self: start; }

/* Thread: one reading column; answers and the user's lines share Inter 15. */
.chat-thread { display: grid; gap: 12px; min-width: 0; max-height: min(64vh, 720px); overflow-y: auto; margin: 0; padding: 0 2px 0 0; list-style: none; scrollbar-width: thin; }
.chat-empty { display: grid; justify-items: center; gap: 8px; padding: 24px 12px 16px; color: var(--muted); font-size: var(--t-md); text-align: center; }
.chat-prompt-title { margin: 0; color: var(--text); font-size: var(--t-2xl); line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
.chat-msg { display: grid; gap: 8px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-width: 0; }
.chat-msg.chat-run { border-left: 3px solid var(--accent); justify-self: stretch; }
.chat-msg.chat-result { border-left: 3px solid var(--pass); }
.chat-msg.chat-failed { border-left-color: var(--fail); background: var(--fail-bg); }
.chat-msg.chat-answer { border-left: 3px solid var(--accent); }
.chat-msg.chat-answer[data-agent="local"] { border-left-color: var(--pass); }
.chat-msg.chat-answer[data-agent="guide"] { border-left-color: var(--muted); }
.chat-msg.chat-note { border-left: 3px solid var(--skip); background: var(--skip-bg); }
.chat-msg.chat-user { justify-self: end; max-width: min(34rem, 100%); background: var(--well); border-color: var(--line-strong); }
.chat-msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.chat-msg-copy { margin-left: auto; min-width: 44px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--ground); color: var(--muted); font: 500 var(--t-xs) var(--sans); cursor: pointer; }
.chat-msg-copy:hover { color: var(--text); border-color: var(--line-strong); background: var(--well); }
.chat-msg-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Sender reads as text with a status dot, not a pill. */
.chat-agent-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font: 600 var(--t-xs)/1.35 var(--sans); white-space: nowrap; }
.chat-agent-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.chat-agent-badge[data-agent="tools"]::before { background: var(--accent); }
.chat-agent-badge[data-agent="local"]::before { background: var(--pass); }
.chat-agent-badge[data-agent="note"]::before { background: var(--skip); }
.chat-agent-badge[data-agent="user"] { color: var(--muted); }
.chat-meta { color: var(--muted); font: 500 var(--t-xs) var(--sans); font-variant-numeric: tabular-nums; }
.chat-body { margin: 0; min-width: 0; color: var(--body); font: 400 var(--t-lg)/1.6 var(--sans); overflow-wrap: anywhere; text-wrap: pretty; }
.chat-body p { margin: 0; white-space: pre-wrap; }
.chat-body > * + * { margin-top: 8px; }
pre.chat-body, .chat-body pre { margin: 0; max-height: 360px; overflow: auto; font: 400 var(--t-sm)/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Folded blobs and tool-call cards: native <details>, flat. */
.chat-blob, .chat-toolcard { border: 1px solid var(--line); border-radius: 8px; background: var(--ground); min-width: 0; }
.chat-blob > summary, .chat-toolcard > summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; color: var(--muted); font: 500 var(--t-sm) var(--sans); list-style: none; cursor: pointer; }
.chat-blob > summary::-webkit-details-marker, .chat-toolcard > summary::-webkit-details-marker { display: none; }
.chat-blob > summary::before, .chat-toolcard > summary::before { content: ""; width: 12px; height: 8px; flex: none; background: var(--select-chevron) no-repeat center / 12px 8px; transform: rotate(-90deg); }
.chat-blob[open] > summary::before, .chat-toolcard[open] > summary::before { transform: none; }
.chat-blob > summary:focus-visible, .chat-toolcard > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-blob > pre, .chat-toolcard > pre { padding: 12px; border-top: 1px solid var(--line); }
.chat-toolcard-name { color: var(--text); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-toolcard-state { margin-left: auto; color: var(--pass); font-variant-numeric: tabular-nums; }
.chat-toolcard-failed .chat-toolcard-state { color: var(--fail); }

/* Verification line: one quiet row under a result; checks fold beneath. */
.chat-verify { margin-top: 8px; min-width: 0; }
.chat-verify > summary { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--muted); font: 500 var(--t-sm) var(--sans); font-variant-numeric: tabular-nums; list-style: none; cursor: pointer; }
.chat-verify > summary::-webkit-details-marker { display: none; }
.chat-verify > summary::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--muted); }
.chat-verify[data-state="passed"] > summary::before { background: var(--pass); }
.chat-verify[data-state="failed"] > summary::before { background: var(--fail); }
.chat-verify[data-state="failed"] > summary { color: var(--fail); }
.chat-verify > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-verify-list { list-style: none; margin: 0; padding: 0 0 0 16px; max-height: 240px; overflow-y: auto; }
.chat-verify-check { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 4px 0; font: 400 var(--t-sm)/1.5 var(--sans); color: var(--body); }
.chat-verify-state { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-verify-check[data-state="passed"] .chat-verify-state { color: var(--pass); }
.chat-verify-check[data-state="failed"] .chat-verify-state { color: var(--fail); }
.chat-verify-why { flex-basis: 100%; color: var(--muted); }
.chat-verify-hash { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 0 16px; font: 400 var(--t-xs)/1.5 var(--sans); color: var(--muted); }
.chat-verify-digest { font: 400 var(--t-xs)/1.5 var(--mono); color: var(--body); overflow-wrap: anywhere; }
.chat-verify-evidence { display: inline-flex; align-items: center; min-height: 44px; margin-left: 16px; font: 500 var(--t-sm) var(--sans); }

/* Handoff divider: the thread continues with another agent. */
.chat-divider { display: flex; align-items: center; gap: 12px; padding: 8px 0; color: var(--muted); font: 400 var(--t-xs) var(--sans); list-style: none; }
.chat-divider::before, .chat-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Tool access lives in the tools panel. */
.chat-token { display: grid; gap: 8px; }
.chat-token summary { display: flex; align-items: center; width: fit-content; min-height: 44px; padding-inline: 8px; color: var(--muted); font-size: var(--t-sm); font-weight: 500; cursor: pointer; }
.chat-token summary:hover { color: var(--text); }
.chat-token-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-token-row input { flex: 1 1 240px; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: 400 var(--t-md) var(--sans); }
.chat-token-note { margin: 0; color: var(--muted); font-size: var(--t-xs); }

/* The per-run execution record. */
.chat-record { border-top: 1px solid var(--line); padding-top: 4px; }
.chat-record summary { display: flex; align-items: center; min-height: 44px; color: var(--muted); font: 500 var(--t-xs) var(--sans); cursor: pointer; }
.chat-record summary:hover { color: var(--text); }
.chat-record-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; font: 400 var(--t-xs)/1.6 var(--sans); font-variant-numeric: tabular-nums; color: var(--body); }
.chat-record-list li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; }
.chat-record-seq, .chat-record-at, .chat-record-id { color: var(--muted); }
.chat-record-id { margin-top: 6px; font: 400 var(--t-xs) var(--mono); overflow-wrap: anywhere; }

/* Composer: ONE framed box. Textarea on top; agent picker bottom-left and
   send (or stop) bottom-right, both inside the frame. No row outside it. */
.chat-composer { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 8px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); }
.chat-composer:focus-within { border-color: var(--accent); }
.chat-composer textarea { display: block; width: 100%; min-height: 44px; max-height: 200px; padding: 10px 8px; border: 0; background: none; color: var(--text); font: 400 var(--t-lg)/1.6 var(--sans); resize: none; overflow-y: auto; }
.chat-composer textarea:focus { outline: none; }
.chat-composer textarea::placeholder { color: var(--muted); }
.chat-composer-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-send { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; margin-left: auto; width: 44px; height: 44px; border: 0; border-radius: 8px; background: var(--primary-bg); color: var(--primary-fg); cursor: pointer; }
.chat-send:hover { background: var(--primary-hover); }
.chat-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-send:disabled { background: var(--well); color: var(--muted); cursor: not-allowed; }
.chat-send .chat-icon { width: 18px; height: 18px; stroke-width: 1.8; }
.chat-stop { background: var(--text); }

/* Agent picker: menu button + menu. Locked items stay readable, not pickable. */
.chat-runtime-wrap { position: relative; flex: 0 1 auto; min-width: 0; }
.chat-runtime { display: inline-flex; align-items: center; gap: 6px; max-width: min(260px, 100%); min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid transparent; border-radius: 8px; background: var(--well); color: var(--text); font: 500 var(--t-sm) var(--sans); cursor: pointer; }
.chat-runtime:hover { border-color: var(--line-strong); }
.chat-runtime:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-runtime:disabled { color: var(--muted); cursor: not-allowed; }
.chat-runtime-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-runtime[aria-expanded="true"] .chat-icon { transform: rotate(180deg); }
.chat-runtime-menu { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 40; display: grid; width: max-content; min-width: 240px; max-width: min(320px, calc(100vw - 32px)); max-height: min(60vh, 420px); overflow-y: auto; overscroll-behavior: contain; padding: 4px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); }
.chat-runtime-menu[hidden] { display: none; }
.chat-menu-label { margin: 0; padding: 8px 12px 4px; color: var(--muted); font: 500 var(--t-xs) var(--sans); }
.chat-menu-sep { margin: 4px 0; border: 0; border-top: 1px solid var(--line); }
.chat-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 4px 12px; border: 0; border-radius: 6px; background: none; color: var(--text); font: 400 var(--t-md) var(--sans); text-align: left; cursor: pointer; }
.chat-agent-choice { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.chat-open-agent { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 10px; border-radius: 6px; color: var(--accent); font-size: var(--t-sm); text-decoration: none; }
.chat-open-agent:hover { background: var(--well); }
.chat-menu-item[hidden] { display: none; }
.chat-menu-item:hover, .chat-menu-item:focus-visible { background: var(--well); outline: none; }
.chat-menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-menu-item[aria-checked="true"] { color: var(--accent); font-weight: 600; }
.chat-menu-item[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; }
.chat-menu-text { display: grid; flex: 1 1 auto; min-width: 0; }
.chat-menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-menu-note { color: var(--muted); font-size: var(--t-xs); font-weight: 400; }
.chat-menu-connect { color: var(--accent); font-weight: 500; }

/* Empty thread = start screen: three suggestions as one quiet row. */
.chat-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.chat-action { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: 500 var(--t-sm) var(--sans); cursor: pointer; }
.chat-action:hover { border-color: var(--line-strong); }
.chat-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Header: title + one saved-chats control. The panel anchors to the banner,
   not the summary, so it never runs off the left edge on a phone. */
.chat-banner { position: relative; display: flex; align-items: center; gap: 8px; padding-block: 0 12px; border-bottom: 1px solid var(--line); }
.chat-banner-text { flex: 1 1 auto; margin: 0; min-width: 0; line-height: 44px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: var(--t-lg); font-weight: 600; }
.chat-icon-btn { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.chat-icon-btn:hover { background: var(--well); color: var(--text); }
.chat-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-sessions { position: static; flex: none; }
.chat-sessions > summary { list-style: none; }
.chat-sessions > summary::-webkit-details-marker { display: none; }
.chat-sessions[open] > summary { background: var(--well); color: var(--text); }
.chat-sessions-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; display: grid; width: min(360px, 100%); border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); overflow: hidden; }
.chat-sessions:not([open]) > .chat-sessions-panel { display: none; }
.chat-session-new { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--accent); font: 500 var(--t-sm) var(--sans); text-align: left; cursor: pointer; }
.chat-session-new:hover { background: var(--well); }
.chat-session-new:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-session-list { display: grid; grid-template-columns: minmax(0, 1fr); max-height: min(50vh, 352px); overflow-y: auto; overscroll-behavior: contain; margin: 0; padding: 0; list-style: none; }
.chat-session-list:empty, .chat-session-list[hidden], .chat-session-bar[hidden] { display: none; }
.chat-session { display: flex; align-items: stretch; border-left: 2px solid transparent; }
.chat-session + .chat-session { border-top: 1px solid var(--line); }
.chat-session.current { border-left-color: var(--accent); background: var(--well); }
.chat-session.current .chat-session-open { color: var(--accent); font-weight: 600; }
.chat-session-open { display: flex; flex: 1 1 auto; align-items: center; min-width: 0; min-height: 44px; padding: 0 16px; border: 0; background: none; color: var(--body); font: 400 var(--t-sm) var(--sans); text-align: left; cursor: pointer; }
.chat-session-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-session-del:hover { color: var(--fail); }
.chat-session-open:hover { background: var(--well); }
.chat-session-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-session-bar { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 16px; border-top: 1px solid var(--line); background: var(--ground); }
.chat-sessions .chat-token-note { flex: 1 1 auto; }
.chat-session-bar .btn { flex: none; color: var(--muted); }
.chat-session-bar .btn:hover { color: var(--fail); }
.chat-session-list:empty + .chat-session-bar { border-top: 0; }

/* Task bar and stage. */
.chat-task { display: flex; align-items: center; min-height: 44px; margin: 0; padding: 0 16px; border: 1px solid var(--line); border-left: 3px solid var(--skip); border-radius: 8px; background: var(--surface); color: var(--text); font-size: var(--t-md); }
.chat-task[data-state="running"] { border-left-color: var(--accent); }
.chat-task[data-state="done"] { border-left-color: var(--pass); }
.chat-task[data-state="failed"] { border-left-color: var(--fail); background: var(--fail-bg); }
.chat-stage { width: min(100%, 760px); margin-inline: auto; min-width: 0; display: grid; gap: 12px; align-content: start; }
.chat-stage:has(.chat-empty) { padding-top: clamp(4px, 4vh, 40px); }
.chat-dock { display: grid; gap: 8px; min-width: 0; }

/* Hand-off links: flat, 8px radius (no pills). */
.chat-handoff { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.chat-handoff .text-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--ground); color: var(--body); font-size: var(--t-xs); font-weight: 500; text-decoration: none; }
.chat-handoff .text-link:hover { border-color: var(--line-strong); color: var(--text); background: var(--well); text-decoration: none; }

@media (prefers-reduced-motion: reduce) { .chat-runtime .chat-icon { transition: none; } }
@container harness (max-width: 600px) {
  .chat-stage:has(.chat-empty) { padding-top: 0; }
  .chat-empty { padding: 16px 0 8px; }
  .chat-msg { padding: 12px; }
  .chat-thread { max-height: min(56vh, 560px); }
  .chat-runtime { max-width: 100%; }
  .chat-runtime-menu { min-width: 0; width: calc(100cqw - 32px); max-width: calc(100cqw - 32px); }
}
