/* assistant: page styles on top of the design-system primitives in /styles.css.
   Tokens only (var(--...)); no hex, no rgba, no new hues.
   Core v11 board « 01 Assistant »: screens/ai-chat.js, lib/chat-core.js (also
   the agent conversation), lib/thought-line.js, lib/refine-modal.js,
   lib/term-classify-modal.js. */

/* ── Frame: fixed bar, a scrolling conversation, a floating composer ── */
.asst { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.asst-bar {
  height: 60px; flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 24px; border-bottom: 1px solid var(--line-2); min-width: 0;
}
.asst-bar .asst-convs { height: 34px; padding: 0 10px; }
.asst-sep { color: var(--line); }
.asst-title {
  flex: 0 1 auto; min-width: 0; font-size: var(--fs-body); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.asst-pane { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; position: relative; }
/* A file dragged over a drop target (chat-core). */
.chat-drop { outline: 2px dashed var(--green); outline-offset: -10px; }

/* ── Conversation (chat-core root) ─────────────────────────────── */
.chat-root { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; position: relative; }
.assistant-conv {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  scrollbar-width: none;
}
.assistant-conv::-webkit-scrollbar { display: none; }
.assistant-msgs {
  width: min(740px, calc(100% - 32px)); margin: 0 auto;
  padding: 36px 0 230px; /* the bottom is re-reserved for the dock by chat-core */
  display: flex; flex-direction: column; gap: 30px;
}
.composer-anchor {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 2;
  width: min(740px, calc(100% - 32px));
  display: flex; flex-direction: column; gap: 10px;
}
.chat-loading { width: min(740px, calc(100% - 32px)); margin: 36px auto 0; }

/* Embedded (the agent page): the dock sits in flow under the conversation. */
.chat-root--embedded .assistant-msgs { flex: 1 0 auto; width: auto; margin: 0; padding: 18px 18px 12px; gap: 22px; }
.chat-root--embedded .composer-anchor {
  position: sticky; left: auto; bottom: 0; transform: none; width: auto;
  padding: 0 12px 12px; background: var(--panel);
}
.chat-root--embedded .composer { box-shadow: none; }
.chat-root--embedded .chat-loading { width: auto; margin: 18px; }

/* Empty state: a greeting, the composer, a few suggestions. */
.asst-empty {
  flex: 1 1 auto; width: min(740px, calc(100% - 32px)); margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; padding: 40px 0 72px;
}
/* The resting mark: the thinking orb breathing, as the old sparkle did. */
.asst-mark { width: 44px; height: 44px; color: var(--ink); }
.asst-note { margin: 0; max-width: 520px; text-align: center; font-size: var(--fs-meta); color: var(--ink-3); }
.asst-history { margin-right: 2px; }
.asst-hint { max-width: 520px; margin: 0; text-align: center; font-size: var(--fs-body); color: var(--ink-2); }
.asst-suggests { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.asst-suggest {
  min-height: 36px; padding: 7px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  font-size: var(--fs-ui); line-height: 1.35; text-align: left;
  transition: background 140ms var(--ease-out), color 140ms var(--ease-out), transform 160ms var(--ease-out);
  animation: asstIn 260ms var(--ease-out) both;
}
.asst-suggest:hover { background: var(--soft); color: var(--ink); }
.asst-suggest:active { transform: scale(.97); }
.asst-suggests.is-swapping .asst-suggest { animation: asstOut 200ms var(--ease-out) forwards; }
@keyframes asstIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes asstOut { to { opacity: 0; transform: translateY(-6px); } }

/* Messages: the user's in a soft bubble, the answer with no panel at all. */
.user-bubble {
  align-self: flex-end; max-width: min(520px, 85%);
  background: var(--soft); padding: 12px 16px; border-radius: 18px 18px 6px 18px;
  font-size: var(--fs-body); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ai-reply { display: flex; flex-direction: column; gap: 16px; min-width: 0; animation: rowFadeIn 320ms var(--ease-out) both; }
.ai-reply-text { font-size: var(--fs-lead); line-height: 1.65; text-wrap: pretty; overflow-wrap: anywhere; }
.ai-reply-text p { margin: 0 0 12px; }
.ai-reply-text > :last-child { margin-bottom: 0; }
.ai-reply-text ul, .ai-reply-text ol { margin: 0 0 12px; padding-left: 1.3em; }
.ai-reply-text li + li { margin-top: 4px; }
.ai-reply-text strong { font-weight: 600; }
.ai-reply-error .ai-reply-text { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-body); color: var(--alert-ink); }
.ai-reply-error .ai-reply-text > svg { color: var(--alert); margin-top: 3px; }
/* The thought line sits 16px above its answer (the list gap is 30px). */
.ai-thought-row { margin-bottom: -14px; }
.ai-thought-live { margin-bottom: 0; }
.choice-past { display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-ui); color: var(--ink-3); }
.choice-past > svg { margin-top: 2px; }

/* Answer insert: a markdown table; a rank bar when a column is a figure. */
.reply-table { margin: 4px 0 16px; }
.reply-table th { padding-top: 0; }
.reply-table td, .reply-table th { padding-top: 12px; padding-bottom: 12px; }
.reply-table thead th { padding-top: 0; padding-bottom: 8px; }
.reply-table td.fig { font-weight: 600; }
.rank-bar-cell { width: 30%; }
.rank-bar { display: block; height: 8px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.rank-bar > span { display: block; height: 100%; border-radius: 99px; background: var(--ink); }

/* Under an answer: copy, save, then the sources. */
.msg-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg-actions-sep { width: 1px; height: 16px; background: var(--line); margin: 0 6px; }

/* ── ThoughtLine (lib/thought-line.js) ─────────────────────────── */
.thought-line { display: flex; flex-direction: column; align-items: flex-start; font-size: var(--fs-body); font-weight: 500; line-height: 1.3; color: var(--ink); }
.thought-line__head {
  display: inline-flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; white-space: nowrap; cursor: default; text-align: left;
}
.thought-line__head[data-toggle] { cursor: pointer; }
.thought-line__glyph { width: 20px; height: 20px; flex: none; }
.thought-line:not([data-working]) .thought-line__glyph { display: none; }
.thought-line__label { display: inline-grid; }
.thought-line__text {
  grid-area: 1 / 1; width: max-content; opacity: 0; visibility: hidden; filter: blur(2px);
  transition: opacity 350ms var(--ease-out), filter 350ms var(--ease-out), visibility 350ms;
}
.thought-line__text[data-active] { opacity: 1; visibility: visible; filter: none; }
.thought-line__text--done { color: var(--ink-3); }
.thought-line[data-working] .thought-line__breath {
  background: linear-gradient(100deg, color-mix(in srgb, var(--ink) 45%, transparent) 30%, var(--ink) 50%, color-mix(in srgb, var(--ink) 45%, transparent) 70%);
  background-size: 250% 100%; background-position: 125% 0;
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  animation: tlShimmer 1.8s linear infinite;
}
@keyframes tlShimmer { to { background-position: -125% 0; } }
.thought-line__timer { color: var(--ink-3); font-variant-numeric: tabular-nums; transition: transform 350ms var(--ease-in-out); }
.thought-line__chevron { display: inline-flex; color: var(--ink-3); opacity: 0; transition: opacity 200ms, transform 200ms var(--ease-out); }
.thought-line__chevron[data-on] { opacity: 1; }
.thought-line[data-open] .thought-line__chevron { transform: rotate(180deg); }
.thought-line__trace { display: grid; grid-template-rows: 0fr; align-self: stretch; transition: grid-template-rows 350ms var(--ease-out); }
.thought-line__trace[data-open] { grid-template-rows: 1fr; }
.thought-line__fold { min-height: 0; overflow: hidden; }
.thought-line__steps {
  display: flex; flex-direction: column; gap: 9px; margin-top: 12px; padding: 2px 0 4px 16px;
  border-left: 1px solid var(--line); font-size: var(--fs-ui); font-weight: 400; color: var(--ink-3);
}
.thought-line[data-working] .thought-line__steps { margin-left: 9px; }
.thought-line__step { display: flex; align-items: center; gap: 9px; transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
@starting-style { .thought-line__step { opacity: 0; transform: translateY(-4px); } }
.thought-line__step:not([data-done]) { color: var(--ink); }
.thought-line__mark { display: inline-grid; place-items: center; flex: none; color: var(--ink-3); }
.thought-line__step[data-done] .thought-line__mark { color: var(--good); }

/* ── Composer ──────────────────────────────────────────────────── */
.composer {
  position: relative; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
  padding: 18px 16px 14px 20px; display: flex; flex-direction: column; gap: 16px;
  transition: border-color 150ms var(--ease-out);
}
.composer:focus-within { border-color: color-mix(in oklch, var(--line) 50%, var(--ink-3)); }
.composer-input,
.composer-input:hover,
.composer-input:focus {
  height: auto; min-height: 26px; max-height: 220px; /* COMPOSER_INPUT_MAX_PX in chat-core */
  padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; resize: none;
  font-size: var(--fs-lead); line-height: 1.6; overflow-y: auto; scrollbar-width: none;
}
.composer-input::-webkit-scrollbar { display: none; }
.composer-actions { display: flex; align-items: center; gap: 8px; margin-left: -4px; }
.composer-round {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--btn), var(--panel); color: var(--ink-2);
  transition: transform 160ms var(--ease-out), background 140ms ease, color 140ms ease, opacity 140ms;
}
.composer-round:hover { background: var(--btn), var(--soft); color: var(--ink); }
.composer-round:active { transform: scale(.96); }
.composer-round svg { transition: transform 220ms var(--ease-out); }
.composer-round.send-btn { border-color: transparent; background: var(--ink-btn), var(--ink); color: var(--panel); box-shadow: 0 1px 2px color-mix(in oklch, var(--ink) 25%, transparent); }
.composer-round.send-btn:hover { background: var(--ink-btn), color-mix(in oklch, var(--ink) 88%, var(--panel)); }
.composer-round.send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.composer .ai-budget { padding: 10px 12px; font-size: var(--fs-meta); }


/* Files attached to the next message. */
.context-bar { display: flex; align-items: flex-start; gap: 10px; }
.ctx-files { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-file {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 32px; padding: 0 4px 0 10px;
  border-radius: 10px; background: var(--soft); font-size: var(--fs-meta); color: var(--ink-2);
}
.ctx-file-ic { display: inline-flex; color: var(--ink-3); }
.ctx-file-ic.is-failed { color: var(--alert); }
.ctx-file.uploading .ctx-file-ic svg { animation: spin 1.4s linear infinite; }
.ctx-file-name { min-width: 0; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-file-x { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--ink-3); }
.ctx-file-x:hover { background: var(--line-2); color: var(--ink); }
.ctx-count { flex: none; font-size: var(--fs-meta); line-height: 32px; color: var(--ink-3); white-space: nowrap; }

/* ── askUserChoice tray (chat dock and the Improve dialog) ──────── */
.choice-dock { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.choice-chip {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 7px; max-width: 100%;
  height: 32px; padding: 0 12px; border-radius: 99px; background: var(--tint-c); color: var(--good-ink);
  font-size: var(--fs-meta); font-weight: 500; transition: box-shadow 140ms;
}
.choice-chip > svg { color: var(--good); }
.choice-chip:not(:disabled):hover { box-shadow: inset 0 0 0 1px var(--good); }
.choice-chip:disabled { cursor: default; }
.choice-chip .chip-n { font-variant-numeric: tabular-nums; opacity: .75; }
.choice-chip .chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice-tray {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  overflow: hidden; transform-origin: bottom center; animation: popIn 180ms var(--ease-out) both;
}
.dlg .choice-tray { box-shadow: none; animation: none; }
.choice-tray-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.choice-tray-head .icon-btn { width: 32px; height: 32px; margin-left: -8px; }
.choice-tray-head .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.choice-tray-q { flex: 1; min-width: 0; font-size: var(--fs-body); font-weight: 600; }
.choice-tray-counter { flex: none; font-size: var(--fs-meta); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.choice-tray-opts { max-height: 240px; overflow-y: auto; overscroll-behavior: contain; }
.choice-opt {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--line-2); transition: background 140ms var(--ease-out);
}
.choice-tray-opts > .choice-opt:last-child { border-bottom: 0; }
.choice-tray-opts:not(:empty) + * { border-top: 1px solid var(--line-2); }
.choice-opt:hover, .choice-opt.prev-pick { background: var(--soft); }
.choice-opt:focus-visible { outline-offset: -2px; }
.choice-opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.choice-opt-label { font-size: var(--fs-body); font-weight: 500; }
.choice-opt-desc { font-size: var(--fs-meta); color: var(--ink-3); }
.choice-opt .opt-check { display: inline-flex; color: var(--good); }
.choice-opt .opt-chev { display: inline-flex; color: var(--ink-3); }
.choice-ff-closed {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px; text-align: left;
  font-size: var(--fs-ui); color: var(--ink-2); transition: background 140ms var(--ease-out);
}
.choice-ff-closed:hover { background: var(--soft); color: var(--ink); }
.choice-ff-open { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; }
.choice-ff-field { flex: 1; min-width: 0; height: 36px; }

/* ── Artifact, proposal and action cards ───────────────────────── */
.artifact-stack { display: flex; flex-direction: column; gap: 8px; }
.artifact-card {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel);
}
.proposal-card { align-items: start; }
.artifact-icon { width: 40px; height: 40px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--soft); color: var(--ink-2); }
.artifact-body { min-width: 0; }
.artifact-name { font-size: var(--fs-body); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proposal-card .artifact-name { white-space: normal; }
.artifact-meta { margin-top: 2px; font-size: var(--fs-meta); color: var(--ink-3); }
.artifact-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.proposal-card .artifact-actions { align-self: center; }
.proposal-kind { font-size: var(--fs-meta); color: var(--ink-3); }
.proposal-fields { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 8px 0 0; font-size: var(--fs-ui); }
.proposal-fields dt { color: var(--ink-3); }
.proposal-fields dd { margin: 0; color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.proposal-bad { margin-top: 6px; font-size: var(--fs-meta); font-weight: 500; color: var(--alert-ink); }

/* ── Agent mode (the Assistant hands the pane to an agent) ─────── */
.asst-agent { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.asst-agent-acts { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.asst-agent-acts:empty { display: none; }

/* ── Conversations drawer ──────────────────────────────────────── */
.asst-hist-back .dlg--drawer { width: min(420px, 100%); }
.asst-hist { display: flex; flex-direction: column; }
.asst-hist-row { position: relative; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-2); }
.asst-hist-row:last-child { border-bottom: 0; }
.asst-hist-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  margin: 3px 0 3px -10px; padding: 10px; border-radius: var(--r-md); text-align: left;
  transition: background 140ms var(--ease-out);
}
.asst-hist-open:hover, .asst-hist-row.is-active .asst-hist-open { background: var(--soft); }
.asst-hist-open .row-title { max-width: 100%; }
.asst-hist-row.is-active .row-title { font-weight: 600; }
.asst-hist-open .row-meta { margin-top: 0; }
/* Hold to delete shows over the row end on hover or focus; always on touch. */
.asst-hist-row .btn-hold { position: absolute; right: 0; opacity: 0; transition: opacity 140ms var(--ease-out); }
.asst-hist-row:hover .btn-hold, .asst-hist-row:focus-within .btn-hold { opacity: 1; }
@media (hover: none) { .asst-hist-row .btn-hold { position: static; opacity: 1; } }

/* ── Improve with AI (lib/refine-modal.js) ─────────────────────── */
.refine-trigger { margin-top: 6px; }
.refine-body { display: flex; flex-direction: column; gap: 12px; }
.refine-loading { display: flex; align-items: center; gap: 10px; padding: 20px 0; font-size: var(--fs-body); color: var(--ink-2); }
.refine-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.refine-diff-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.refine-diff-h { font-size: var(--fs-meta); color: var(--ink-3); }
.refine-diff-box {
  max-height: 50vh; overflow: auto; padding: 12px 14px; border-radius: var(--r-md);
  font-size: var(--fs-body); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.refine-diff-box.is-old { background: var(--soft); color: var(--ink-2); }
.refine-diff-box.is-new { border: 1px solid var(--line); color: var(--ink); }
.refine-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding-top: 4px; }

/* ── "Is this a client name?" (lib/term-classify-modal.js) ─────── */
.term-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 8px; color: var(--ink-2); }
.term-head > svg { margin-top: 2px; }
.term-head p { margin: 0; font-size: var(--fs-body); line-height: 1.55; }
.term-rows { display: flex; flex-direction: column; }
.term-row { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line-2); }
.term-word { font-size: var(--fs-body); font-weight: 600; overflow-wrap: anywhere; }
.term-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.term-opt {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel);
  transition: background 140ms var(--ease-out), border-color 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}
.term-opt:hover { background: var(--soft); }
.term-opt[aria-pressed="true"] { background: var(--soft); border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.term-opt-label { font-size: var(--fs-ui); font-weight: 500; }
.term-opt-hint { font-size: var(--fs-min); color: var(--ink-3); }
.term-once { margin: 14px 0 0; font-size: var(--fs-meta); color: var(--ink-3); }

/* ── Narrow screens ────────────────────────────────────────────── */
@media (max-width: 640px) {
  .asst-bar { height: 56px; padding: 0 12px; gap: 6px; }
  .asst-bar .lbl, .asst-sep { display: none; }
  .assistant-msgs, .asst-empty, .chat-loading { width: calc(100% - 24px); }
  .assistant-msgs { padding-top: 24px; gap: 24px; }
  .composer-anchor { bottom: 12px; width: calc(100% - 16px); }
  .composer { padding: 14px 12px 10px 16px; gap: 12px; border-radius: 20px; }
  .composer-round { width: 36px; height: 36px; }
  .asst-empty { gap: 20px; padding-bottom: 40px; }
  .artifact-card { grid-template-columns: 40px minmax(0, 1fr); }
  .artifact-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .refine-diff, .term-opts { grid-template-columns: 1fr; }
  .rank-bar-cell { width: 22%; }
}
