/* web/css/tools.css
 *
 * What a turn is made of once it is drawn: tool calls, the prose of an
 * answer (markdown), and the terminal pane.
 *
 * Linked from web/index.html in the order the sections had in the old
 * web/styles.css, and concatenated in that order they reproduce it exactly, so
 * the cascade is unchanged. A rule that moves between these files moves in the
 * cascade too: check what it now comes before and after.
 */

/* ── tool calls ──────────────────────────────────────────────────────── */

.tool {
    margin: var(--sp-2) 0;
    background: var(--s2);
    border-radius: var(--r);
    overflow: hidden;
    transition: background var(--t-fast) var(--ease);
}
.tool[open] { background: var(--s2); }

/* Calls in a row are one block: a seam between them instead of a gap and a
   separate rounded card each, which made a turn of twelve Reads a column of
   twelve identical pills. The outer corners stay round. Adjacent `.ev` rows
   only — a message, a thought or a card between two calls breaks the block. */
.ev-tool + .ev-tool { padding-top: 0; }
.ev-tool:has(+ .ev-tool) { padding-bottom: 0; }
.ev-tool + .ev-tool > .ev-body > .tool {
    margin-top: 0;
    border-top: 1px solid var(--s1);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.ev-tool:has(+ .ev-tool) > .ev-body > .tool {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.ev-tool > .ev-body > .tool > summary { border-radius: inherit; }

/* The row itself is shared with the fold a run of tool calls collapses into
   (.trow, below) — one more row of the same kind, and it should be impossible
   for the two to drift apart by editing only one of them.

   On the baseline, so the name, the argument and the time — three sizes and
   two faces — read as one line, and so the row has a baseline of its own for
   the time gutter beside it to sit on (.ev). The dot, which has no text,
   centres instead. */
:is(.tool > summary, .trow) {
    display: flex;
    align-items: baseline;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-7);
    cursor: pointer;
    list-style: none;
    font: 400 var(--fs-md)/var(--lh-base) var(--sans);
    color: var(--text-3);
    border-radius: var(--r);
    transition: background var(--t-fast) var(--ease);
}
.tool > summary::-webkit-details-marker { display: none; }
:is(.tool > summary, .trow):hover { background: var(--s3); }

/* Status is a dot, not a coloured slab — and the row's only marker. There used
   to be a disclosure caret beside it, two glyphs before every summary saying
   "this is a row" between them. The dot carries the status, which the caret
   never did; that the row opens is said by its hover ground and its cursor,
   and by <details> to anything reading the page. */
:is(.tool > summary, .trow)::before {
    content: "";
    flex: none;
    align-self: center;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-4);
}
:is(.tool[data-status="ok"] > summary, .trow[data-status="ok"])::before { background: var(--s6); }
:is(.tool[data-status="error"] > summary, .trow[data-status="error"])::before { background: var(--red); }
.tool[data-status="pending"] > summary::before {
    background: var(--yellow);
    animation: breathe var(--dur-loop) var(--ease) infinite;
}

:is(.tool, .trow) .tname {
    font-family: var(--mono);
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text-2);
    flex: none;
}
:is(.tool[data-status="error"], .trow[data-status="error"]) .tname { color: var(--red); }

:is(.tool, .trow) .targ {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
    font-size: var(--fs-sm);
    color: var(--text-4);
}

:is(.tool, .trow) .tmeta {
    flex: none;
    font-size: var(--fs-sm);
    color: var(--text-4);
    font-variant-numeric: tabular-nums;
}

/* A run of tool calls, folded into one row once a message closed it.
   The <summary> is display:block and the grid lives inside it, so the rows the
   fold holds stay top-level .ev grids: nesting them inside an .ev-body would
   indent every one of them by a gutter they already have. */
.trun { display: block; }
.trun > summary {
    display: block;
    cursor: pointer;
    list-style: none;
}
.trun > summary::-webkit-details-marker { display: none; }
.trow {
    margin: var(--sp-2) 0;
    background: var(--s2);
}

.tool-body { padding: var(--sp-2) var(--sp-7) var(--sp-7); }

.tool-section { margin-top: var(--sp-6); }
.tool-section > h4 {
    margin: 0 0 var(--sp-3);
    font: 500 var(--fs-sm)/var(--lh-none) var(--sans);
    color: var(--text-4);
    letter-spacing: 0.02em;
}

/* An image a tool result carried (a Read of a PNG, a screenshot). Fitted to
   the column; a click opens it in #img-scrim (see dialogs.css). */
.tool-images { display: flex; flex-direction: column; gap: 8px; }
.tool-image {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--outline-soft);
    border-radius: var(--r-sm);
    background: var(--bg);
    cursor: zoom-in;
}

.io {
    margin: 0;
    padding: var(--sp-6);
    background: var(--bg);
    border-radius: var(--r-sm);
    font: 400 var(--fs-md)/var(--lh-prose) var(--mono);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 420px;
    overflow-y: auto;
    color: var(--text-2);
}
.io.err { color: var(--red-soft); }

.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--sp-2) var(--sp-7);
    font: 400 var(--fs-md)/var(--lh-prose) var(--mono);
    padding: var(--sp-6);
    background: var(--bg);
    border-radius: var(--r-sm);
}
.kv dt { color: var(--text-4); }
.kv dd { margin: 0; color: var(--text-2); word-break: break-all; }

.more-btn {
    margin-top: var(--sp-5);
    height: var(--ctl-sm);
    padding: 0 var(--sp-7);
    font: 500 var(--fs-md)/var(--lh-none) var(--sans);
    color: var(--blue);
    background: transparent;
    border-radius: var(--pill);
    transition: background var(--t-fast) var(--ease);
}
.more-btn:hover { background: var(--blue-tint); }
.more-btn:disabled { color: var(--text-4); background: none; }

/* diff */
.diff {
    background: var(--bg);
    border-radius: var(--r-sm);
    font: 400 var(--fs-md)/var(--lh-prose) var(--mono);
    overflow-x: auto;
    padding: var(--sp-3) 0;
}
.diff .hunk {
    padding: var(--sp-2) var(--sp-6);
    color: var(--text-4);
    font-size: var(--fs-sm);
}
.diff .dl { padding: 0 var(--sp-6); white-space: pre; }
/* Kept low-saturation: a long diff should not become a wall of colour. */
.diff .dl.add { background: var(--diff-add-bg); color: var(--diff-add-fg); }
.diff .dl.del { background: var(--diff-del-bg); color: var(--diff-del-fg); }
.diff .dl.ctx { color: var(--text-4); }

/* subagent */
.subagent-log {
    margin-top: var(--sp-5);
    padding-left: var(--sp-7);
    border-left: 2px solid var(--outline-soft);
}
.subagent-log .ev { grid-template-columns: 44px 1fr; column-gap: var(--sp-6); }

.subagent-meta {
    font: 400 var(--fs-xs)/var(--lh-prose) var(--mono);
    color: var(--text-3);
}
.subagent[data-status="running"] .subagent-meta { color: var(--yellow); }
.subagent[data-status="failed"] .subagent-meta { color: var(--red); }

.subagent-btns { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.more-btn.primary { background: var(--blue-tint); }
.more-btn.primary:hover { background: var(--blue-deep); color: var(--on-blue-deep); }

/* A subagent has nothing to send to, so the composer reads as unavailable
   rather than merely inert. */
.conv[data-scope="agent"] .composer { opacity: 0.55; }
.conv[data-scope="agent"] .input-row textarea { cursor: not-allowed; }

/* ── prose ───────────────────────────────────────────────────────────── */

.prose { font-size: var(--fs-base); line-height: var(--lh-prose); color: var(--text-2); }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 0.8em; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
    margin: 1.5em 0 0.55em;
    line-height: var(--lh-tight);
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.002em;
}
.prose h1 { font-size: 1.35em; }
.prose h2 { font-size: 1.2em; }
.prose h3 { font-size: 1.08em; }
.prose h4, .prose h5, .prose h6 { font-size: 1em; color: var(--text-2); }
.prose ul, .prose ol { margin: 0 0 0.8em; padding-left: 1.45em; }
.prose li { margin: 0.22em 0; }
.prose li::marker { color: var(--text-4); }
.prose li.task { list-style: none; margin-left: -1.3em; display: flex; gap: var(--sp-4); }
.prose li.task input { margin-top: var(--sp-2); accent-color: var(--blue); }
.prose li > p { margin: 0 0 0.35em; }
.prose blockquote {
    margin: 0 0 0.8em;
    padding: var(--sp-1) 0 var(--sp-1) var(--sp-7);
    border-left: 3px solid var(--outline);
    color: var(--text-3);
}
.prose hr { border: none; border-top: 1px solid var(--outline-soft); margin: 1.5em 0; }
.prose img { max-width: 100%; border-radius: var(--r-sm); }
.prose strong { color: var(--text); font-weight: 500; }
.prose em { color: var(--text-2); }
.prose del { color: var(--text-4); }

/* A path in prose opens the file on the Windows host. A dotted rule rather than
   the link blue: half of these sit inside a code span, where blue would fight the
   peach that says "this is code" — and a URL and a path visibly going to
   different places is worth more than both of them being loud. `color: inherit`
   is what makes the nested case need no second rule. */
.prose a.fs-path {
    color: inherit;
    text-decoration: underline dotted var(--text-4);
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    cursor: pointer;
}
.prose a.fs-path:hover { text-decoration: underline solid currentColor; }

.prose code {
    font: 400 0.87em/var(--lh-base) var(--mono);
    background: var(--s3);
    border-radius: var(--r-xs);
    padding: 0.12em 0.4em;
    color: var(--peach);
    word-break: break-word;
}

.table-wrap { overflow-x: auto; margin: 0 0 1em; border-radius: var(--r-sm); }
.prose table { border-collapse: collapse; font-size: var(--fs-md); min-width: 100%; }
.prose th, .prose td { padding: var(--sp-4) var(--sp-6); text-align: left; }
.prose th {
    background: var(--s3);
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}
.prose td { background: var(--s2); }
.prose tbody tr:not(:last-child) td { box-shadow: inset 0 -1px 0 var(--outline-soft); }

/* code blocks */
.code-block {
    margin: 0 0 1em;
    background: var(--bg);
    border-radius: var(--r);
    overflow: hidden;
}
.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-4) var(--sp-3) var(--sp-7);
    min-height: 34px;
}
.code-lang {
    font: 400 var(--fs-sm)/var(--lh-none) var(--sans);
    color: var(--text-4);
    letter-spacing: 0.02em;
}
.copy-btn {
    margin-left: auto;
    height: 26px;
    padding: 0 var(--sp-6);
    border-radius: var(--pill);
    font: 500 var(--fs-sm)/var(--lh-none) var(--sans);
    color: var(--text-3);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.copy-btn:hover { color: var(--text); background: var(--s3); }
.copy-btn.done { color: var(--green); }

.code-block pre { margin: 0; padding: var(--sp-2) var(--sp-7) var(--sp-7); overflow-x: auto; max-height: 520px; }
.code-block code {
    font: 400 var(--fs-md)/var(--lh-prose) var(--mono);
    background: none;
    padding: 0;
    color: var(--text-2);
    white-space: pre;
}

/* tokens — muted, close in value, so code reads as text not confetti */
.tok-comment   { color: var(--syn-comment); font-style: italic; }
.tok-string    { color: var(--syn-string); }
.tok-regex     { color: var(--syn-regex); }
.tok-number    { color: var(--syn-number); }
.tok-keyword   { color: var(--syn-keyword); }
.tok-builtin   { color: var(--syn-builtin); }
.tok-fn        { color: var(--syn-fn); }
.tok-type      { color: var(--syn-type); }
.tok-var       { color: var(--syn-var); }
.tok-flag      { color: var(--syn-flag); }
.tok-decorator { color: var(--syn-number); }
.tok-key       { color: var(--syn-fn); }
.tok-prop      { color: var(--syn-fn); }
.tok-selector  { color: var(--syn-keyword); }
.tok-at        { color: var(--syn-keyword); }
.tok-tag       { color: var(--syn-keyword); }
.tok-attr      { color: var(--syn-number); }
.tok-doctype   { color: var(--syn-comment); }
.tok-punct     { color: var(--syn-punct); }
.tok-diff-meta { color: var(--syn-builtin); }
.tok-diff-add  { color: var(--syn-add); }
.tok-diff-del  { color: var(--syn-del); }

/* ── terminal ────────────────────────────────────────────────────────── */

/* Height is set by dragging the grip and remembered; the flex rules only stop
   it eating the transcript entirely, which a drag to the top otherwise would. */
.term-pane {
    flex: none;
    display: flex;
    flex-direction: column;
    height: var(--term-h, 300px);
    min-height: 120px;
    max-height: 78vh;
    background: var(--s2);
    border-top: 1px solid var(--outline-soft);
}
.term-pane[hidden] { display: none; }

.term-grip {
    flex: none;
    height: 7px;
    margin-top: calc(-1 * var(--sp-2));
    cursor: row-resize;
    background: transparent;
    transition: background var(--t-fast) var(--ease);
}
.term-grip:hover, .term-grip.dragging { background: var(--blue-cont); }

.term-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    padding: var(--sp-1) var(--sp-6) var(--sp-2);
}
/* Shrinkable, not fixed: this holds the shell's directory, which homely() has
   already shortened, but also a run's whole command line, which nothing has. */
.term-dir {
    flex: 0 1 auto;
    min-width: 0;
    font: 400 var(--fs-xs)/var(--lh-base) var(--mono);
    color: var(--text-4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Only shown when the session has moved on from where this shell opened —
   a worktree it entered after the pane was already running. */
.term-moved {
    flex: 0 1 auto;
    min-width: 0;
    font: 400 var(--fs-sm)/var(--lh-base) var(--sans);
    color: var(--yellow);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.term-moved[hidden] { display: none; }
.term-head .spacer { flex: 1; }

.term-btn {
    flex: none;
    padding: var(--sp-1) var(--sp-5);
    border-radius: var(--pill);
    font: 400 var(--fs-sm)/var(--lh-snug) var(--sans);
    color: var(--text-3);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.term-btn:hover { background: var(--s3); color: var(--text); }
.term-btn[hidden] { display: none; }
/* A task's page is the thing most people start one for, and the button that
   shows it would otherwise look exactly like Hide. */
#term-preview:not(:disabled) { color: var(--blue); }
#term-preview:not(:disabled):hover { background: var(--s3); }
.term-btn:disabled { opacity: .5; cursor: default; }
.term-btn:disabled:hover { background: none; color: var(--text-3); }

/* The shell, then a run per declared command that has been started. Absent
   entirely until there is a run, so a project that declares nothing sees the
   pane exactly as it was. */
.term-tabs {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--sp-1);
}
.term-tabs[hidden] { display: none; }

.term-tab {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-4);
    border-radius: var(--pill);
    font: 400 var(--fs-sm)/var(--lh-base) var(--sans);
    color: var(--text-4);
    white-space: nowrap;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.term-tab:hover { background: var(--s3); color: var(--text-2); }
.term-tab.on { background: var(--s3); color: var(--text); }
/* Green only for something actually answering on its port. */
.term-tab.on-air::before,
.term-tab.dead::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--green);
}
.term-tab.dead::before { background: var(--text-4); }

/* xterm measures itself against this box, so it has to be the one that scrolls
   and it has to have a real height of its own. */
.term-body {
    flex: 1;
    min-height: 0;
    padding: 0 var(--sp-3) var(--sp-3) var(--sp-6);
    overflow: hidden;
}
.term-body .xterm { height: 100%; }
.term-body .xterm-viewport { background: transparent !important; }
.term-body .xterm-viewport::-webkit-scrollbar { width: 10px; }

/* Dragging the grip over the transcript would otherwise select all of it. */
body.term-resizing { user-select: none; cursor: row-resize; }

