/* chat.css — session-chat mode, same token layer as gcanvas.css */
#gc-chat {
  position: absolute; inset: 44px 0 0 0;
  display: flex; flex-direction: row;         /* full mode: sessions | center | compute */
  background: var(--bg);
}
#gc-chat[hidden] { display: none; }
#gc-chat-center {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
}
#gc-chat-sessions, #gc-chat-jobsrail {
  width: 250px; flex-shrink: 0; overflow-y: auto;
  background: var(--surface);
  display: flex; flex-direction: column;
}
#gc-chat-sessions { border-right: var(--hair); }
#gc-chat-jobsrail { width: 300px; border-left: var(--hair); }
#gc-chat.docked { flex-direction: column; }
#gc-chat.docked #gc-chat-sessions,
#gc-chat.docked #gc-chat-jobsrail { display: none; }
@media (max-width: 1180px) { #gc-chat-sessions { display: none; } }
@media (max-width: 980px) { #gc-chat-jobsrail { display: none; } }

/* ── docked: fixed right column beside an open canvas (gallery's mirror) ── */
#gc-chat.docked {
  position: fixed; inset: 52px 0 0 auto;
  width: var(--chat-w, 380px); max-width: 82vw;
  border-left: var(--hair); z-index: 9340;
}
#gc-chat.docked #gc-chat-log { padding: 12px; }
#gc-chat.docked #gc-chat-form { margin: 0 10px 10px; }
#gc-chat.docked #gc-chat-model { max-width: 150px; }
#gc-chat-head { display: none; }
#gc-chat.docked #gc-chat-head {
  display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 10px;
  flex-shrink: 0; border-bottom: var(--hair);
}
#gc-chat-session {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 11px;
  background: var(--surface-2); color: var(--fg); border: var(--hair);
  border-radius: var(--r); padding: 4px 6px; appearance: none;
  text-overflow: ellipsis; overflow: hidden; cursor: pointer;
}
#gc-chat-session:focus { outline: none; border-color: var(--accent); }
#gc-chat-head button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px; border-radius: var(--r);
}
#gc-chat-head button:hover { color: var(--fg); }
/* drag-to-resize grip straddling the column's left edge */
#gc-chat-resize { display: none; }
#gc-chat.docked #gc-chat-resize {
  display: block; position: absolute; top: 0; left: -3px; width: 7px; height: 100%;
  cursor: ew-resize; z-index: 2; touch-action: none;
}
#gc-chat-resize::after {
  content: ''; position: absolute; top: 0; left: 3px; width: 1px; height: 100%;
  background: var(--accent); opacity: 0; transition: opacity .12s;
}
#gc-chat-resize:hover::after, #gc-chat-resize.dragging::after { opacity: 1; }
#gc-chat.docked #gc-chat-log::-webkit-scrollbar { width: 2px; }
#gc-chat.docked #gc-chat-log::-webkit-scrollbar-thumb { background: var(--muted); }
#gc-chat-log {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 24px calc(max(24px, (100% - 76ch) / 2));
  display: flex; flex-direction: column; gap: 10px;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
}
.ch-msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.ch-user { align-self: flex-end; align-items: flex-end; max-width: 80%; }
.ch-assistant { align-self: flex-start; align-items: flex-start; max-width: 100%; }
.ch-head {
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); display: flex; gap: 8px;
}
.ch-body { word-break: break-word; color: var(--fg); }
.ch-user .ch-body { white-space: pre-wrap; }
/* rendered markdown must stay white-space:normal — pre-wrap double-spaces it */
.ch-body.md { white-space: normal; }
.ch-body.md > :first-child { margin-top: 0; }
.ch-body.md > :last-child { margin-bottom: 0; }
.ch-body.md p { margin: 0 0 8px; }
.ch-body.md h1, .ch-body.md h2, .ch-body.md h3 {
  margin: 12px 0 6px; font-size: 13px; letter-spacing: .04em; color: var(--fg);
}
.ch-body.md h1 { font-size: 15px; }
.ch-body.md h2 { font-size: 14px; }
.ch-body.md ul, .ch-body.md ol { margin: 0 0 8px; padding-left: 20px; }
.ch-body.md li { margin: 2px 0; }
.ch-body.md code {
  background: var(--surface-2); border: var(--hair); border-radius: 3px;
  padding: 0 4px; font-size: 12px;
}
.ch-body.md blockquote {
  margin: 0 0 8px; padding: 2px 10px;
  border-left: 2px solid var(--accent); color: var(--muted);
}
.ch-body.md hr { border: 0; border-top: var(--hair); margin: 10px 0; }
.ch-body.md a { color: var(--accent); }
.ch-code { position: relative; margin: 0 0 8px; max-width: 100%; }
.ch-code pre {
  margin: 0; padding: 10px 12px; overflow-x: auto; white-space: pre;
  background: var(--surface); border: var(--hair); border-radius: var(--r);
  font-size: 12px; line-height: 1.5;
}
.ch-code pre::-webkit-scrollbar { height: 2px; }
.ch-code pre::-webkit-scrollbar-thumb { background: var(--muted); }
.ch-code code { background: none; border: 0; padding: 0; }
.ch-code-copy {
  position: absolute; top: 5px; right: 5px; opacity: 0; transition: opacity .12s;
  font-family: var(--mono); font-size: 10px; padding: 2px 8px;
  border: var(--hair); border-radius: var(--r); background: var(--surface-2);
  color: var(--muted); cursor: pointer;
}
.ch-code:hover .ch-code-copy { opacity: 1; }
.ch-code-copy:hover { color: var(--fg); }
.ch-table { overflow-x: auto; margin: 0 0 8px; max-width: 100%; }
.ch-table::-webkit-scrollbar { height: 2px; }
.ch-table table { border-collapse: collapse; font-size: 12px; }
.ch-table th, .ch-table td { border: var(--hair); padding: 4px 10px; text-align: left; }
.ch-table th { color: var(--muted); font-weight: 600; text-transform: uppercase;
  font-size: 10px; letter-spacing: .06em; }
.ch-actions { display: inline-flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.ch-msg:hover .ch-actions { opacity: 1; }
.ch-actions button {
  font-family: var(--mono); font-size: 9px; letter-spacing: .06em; text-transform: uppercase;
  border: var(--hair); border-radius: var(--r); background: var(--surface);
  color: var(--muted); padding: 1px 7px; cursor: pointer;
}
.ch-actions button:hover { color: var(--fg); border-color: var(--muted); }
.ch-line { font-size: 11px; color: var(--muted); }
.ch-status { color: var(--faint); animation: gc-pulse 1.4s ease-in-out infinite; }
.ch-warn { color: var(--gold); }
.ch-err { color: var(--danger); }
.ch-spend { color: var(--accent); }
.ch-tools { align-self: flex-start; max-width: 100%; }
.ch-tools > summary {
  list-style: none; cursor: pointer; user-select: none;
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  font-family: var(--mono); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border: var(--hair); border-radius: var(--r); background: var(--surface);
}
.ch-tools > summary::-webkit-details-marker { display: none; }
.ch-tools > summary::before { content: '▸'; font-size: 9px; }
.ch-tools[open] > summary::before { content: '▾'; }
.ch-tools > summary:hover { color: var(--fg); }
.ch-tools-body { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; padding-left: 2px; }
.ch-chip {
  align-self: flex-start; font-size: 11px; font-family: var(--mono);
  border: var(--hair); border-radius: var(--r);
  padding: 3px 8px; color: var(--muted); background: var(--surface);
  max-width: 100%; white-space: normal; word-break: break-word;
}
.ch-chip-run { color: var(--accent); animation: gc-pulse 1.4s ease-in-out infinite; }
.ch-chip-ok { color: var(--muted); }
.ch-chip-err { color: var(--danger); }
.ch-media { align-self: flex-start; max-width: min(520px, 100%); }
.ch-media img, .ch-media video { max-width: 100%; border: var(--hair); border-radius: var(--r); display: block; }
.ch-media audio { width: 320px; }
.ch-plan {
  align-self: stretch; border: 1px solid var(--accent); border-radius: var(--r);
  background: var(--surface); padding: 10px 12px; font-size: 12px;
}
.ch-plan-h { display: flex; justify-content: space-between; color: var(--fg);
  font-weight: 600; margin-bottom: 6px; }
.ch-plan-total { color: var(--accent); }
.ch-plan-step { display: flex; gap: 10px; justify-content: space-between;
  color: var(--muted); padding: 2px 0; flex-wrap: wrap; }
.ch-plan-tool { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 75%; }
.ch-plan-est { color: var(--fg); }
.ch-plan-warn { flex-basis: 100%; color: var(--gold); font-size: 11px; }
.ch-plan-place { display: block; margin: 8px 0 2px; color: var(--muted); font-size: 11px; cursor: pointer; }
.ch-plan-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.ch-plan-actions button {
  font-family: var(--mono); font-size: 12px; padding: 4px 14px;
  border: var(--hair); border-radius: var(--r); background: var(--surface-2);
  color: var(--fg); cursor: pointer;
}
.ch-plan-actions .ch-approve { border-color: var(--accent); color: var(--accent); }
.ch-plan-actions .ch-approve:hover { background: var(--accent); color: var(--accent-fg); }
.ch-plan-actions .ch-reject:hover { border-color: var(--danger); color: var(--danger); }
.ch-plan-note { color: var(--faint); font-size: 11px; }
#gc-chat-form {
  position: relative;
  display: flex; flex-direction: column;
  margin: 0 calc(max(24px, (100% - 76ch) / 2)) 16px;
  border: var(--hair); border-radius: var(--r); background: var(--surface);
}
/* attached-reference thumbnails, sitting above the composer text. Derived from
   the composer's own text, so the strip can never disagree with what gets sent.
   NOTE the [hidden] override: display:flex beats the hidden attribute. */
#gc-chat-refs { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 2px; }
#gc-chat-refs[hidden] { display: none; }
.ch-ref {
  position: relative; width: 54px; height: 54px; flex: 0 0 auto;
  border: var(--hair); border-radius: var(--r); overflow: hidden;
  background: var(--surface-2);
}
.ch-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ch-ref.ch-ref-gone img { display: none; }
.ch-ref.ch-ref-gone::after {
  content: '?'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-family: var(--mono); font-size: 16px;
}
.ch-ref-x {
  position: absolute; top: 2px; right: 2px; width: 16px; height: 16px;
  padding: 0; border: 0; border-radius: 3px; cursor: pointer;
  background: rgba(0, 0, 0, 0.65); color: #fff;
  font-size: 10px; line-height: 16px; text-align: center;
  opacity: 0; transition: opacity 0.12s;
}
.ch-ref:hover .ch-ref-x, .ch-ref:focus-within .ch-ref-x { opacity: 1; }
.ch-ref-x:hover { background: var(--danger); }

/* slash-command autocomplete, anchored above the composer */
#gc-chat-slash {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: var(--hair); border-radius: var(--r);
  overflow: hidden; z-index: 5; font-family: var(--mono); font-size: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.ch-slash-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 10px; cursor: pointer; color: var(--muted);
}
.ch-slash-item code { color: var(--accent); min-width: 62px; }
.ch-slash-item.sel, .ch-slash-item:hover { background: var(--surface-2); color: var(--fg); }
.ch-cmd { color: var(--accent); font-family: var(--mono); }
.ch-help {
  align-self: flex-start; display: flex; flex-direction: column; gap: 3px;
  border: var(--hair); border-radius: var(--r); background: var(--surface);
  padding: 8px 12px; font-size: 12px; font-family: var(--mono); color: var(--muted);
}
.ch-help code { color: var(--accent); margin-right: 10px; }
#gc-chat-input {
  width: 100%; box-sizing: border-box; resize: vertical;
  min-height: 40px; max-height: 200px;
  background: transparent; color: var(--fg); border: 0;
  padding: 10px 12px 4px;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
}
#gc-chat-input:focus { outline: none; }
#gc-chat-controls { display: flex; align-items: center; gap: 8px; padding: 4px 8px 8px; }
#gc-chat-controls .gc-spacer { flex: 1; }
#gc-chat-attach {
  border: 0; background: transparent; color: var(--muted); font-size: 15px;
  line-height: 1; padding: 5px 6px; border-radius: var(--r); cursor: pointer;
}
#gc-chat-attach:hover { color: var(--fg); background: var(--surface-2); }
/* plan/build toggle — a mode you can't see is a mode you forget you're in, so
   plan state also tints the whole composer border, not just this pill */
#gc-chat-mode {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
  padding: 4px 9px; border: var(--hair); border-radius: var(--r);
  background: var(--surface-2); color: var(--muted); cursor: pointer;
}
#gc-chat-mode:hover { color: var(--fg); }
#gc-chat-mode[data-mode="plan"] {
  border-color: var(--accent); color: var(--accent); background: transparent;
}
#gc-chat-form[data-mode="plan"] { border-color: var(--accent); }
#gc-chat-model, #gc-chat-send {
  font-family: var(--mono); font-size: 12px; padding: 6px 12px;
  border: var(--hair); border-radius: var(--r);
  background: var(--surface-2); color: var(--fg); cursor: pointer;
}
#gc-chat-model {
  color: var(--gold); max-width: 260px; appearance: none;
  text-overflow: ellipsis; overflow: hidden;
}
#gc-chat-model:focus { outline: none; border-color: var(--accent); }
#gc-chat-send { border-color: var(--accent); color: var(--accent); }
#gc-chat-send:hover:not(:disabled) { background: var(--accent); color: var(--accent-fg); }
#gc-chat-send:disabled { opacity: .5; cursor: default; }
#gc-home-actions { display: flex; gap: 10px; justify-content: center; margin: 0 0 24px; }

/* @tag chips sit above the attached-image strip, inside the composer */
#gc-chat-tagchips { padding: 6px 10px 0; }

/* ── rails: sessions (left) + compute/jobs/artifacts (right) ────────────── */
.ch-rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint);
}
.ch-rail-head button {
  background: none; border: var(--hair); border-radius: var(--r);
  color: var(--muted); cursor: pointer; font-family: var(--mono);
  font-size: 12px; line-height: 1; padding: 2px 8px;
}
.ch-rail-head button:hover { color: var(--fg); border-color: var(--muted); }
.ch-rail-empty { padding: 6px 12px 12px; color: var(--faint); font-size: 11px; }

#gc-chat-sessionlist { display: flex; flex-direction: column; padding: 0 6px 10px; }
.ch-session {
  padding: 7px 8px; border-radius: var(--r); cursor: pointer;
  border: 1px solid transparent;
}
.ch-session:hover { background: var(--surface-2); }
.ch-session.active { border-color: var(--accent); background: var(--surface-2); }
.ch-session-name {
  color: var(--fg); font-size: 12px; font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-session-meta { color: var(--faint); font-size: 10px; font-family: var(--mono); margin-top: 1px; }

/* backend readiness chips */
#gc-chat-backends { display: flex; flex-direction: column; gap: 4px; padding: 0 12px 10px; }
.ch-backend {
  display: flex; align-items: baseline; gap: 7px;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
}
.ch-backend-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; align-self: center; }
.ch-backend.ok .ch-backend-dot { background: #5dbb6b; }
.ch-backend.busy .ch-backend-dot { background: var(--gold); animation: gc-pulse 1.4s ease-in-out infinite; }
.ch-backend.down .ch-backend-dot { background: var(--danger); }
.ch-backend-name { color: var(--fg); }
.ch-backend-state { color: var(--faint); margin-left: auto; text-align: right; }

/* jobs rail cards */
#gc-chat-jobs { display: flex; flex-direction: column; gap: 6px; padding: 0 10px 10px; }
.ch-railjob {
  border: var(--hair); border-radius: var(--r); background: var(--bg);
  padding: 7px 9px; font-family: var(--mono);
}
.ch-railjob[data-status="running"] { border-color: var(--accent); }
.ch-railjob[data-status="failed"] { border-color: var(--danger); }
.ch-railjob-top {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--fg);
}
.ch-railjob-state { color: var(--muted); font-size: 10px; white-space: nowrap; }
.ch-railjob[data-status="running"] .ch-railjob-state { color: var(--accent); animation: gc-pulse 1.4s ease-in-out infinite; }
.ch-railjob[data-status="failed"] .ch-railjob-state { color: var(--danger); }
.ch-railjob-sub {
  color: var(--faint); font-size: 10px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-railjob-acts { display: flex; gap: 6px; margin-top: 5px; }
.ch-railjob-acts:empty { display: none; }
.ch-railjob-acts button {
  font-family: var(--mono); font-size: 10px; padding: 1px 8px;
  border: var(--hair); border-radius: var(--r); background: var(--surface-2);
  color: var(--muted); cursor: pointer;
}
.ch-railjob-acts button:hover { color: var(--fg); border-color: var(--muted); }
.ch-railjob-acts button:disabled { opacity: .5; cursor: default; }

/* artifacts grid */
#gc-chat-artifacts { display: flex; flex-direction: column; gap: 8px; padding: 2px 10px 14px; }
.ch-art { position: relative; border: var(--hair); border-radius: var(--r); overflow: hidden; background: var(--bg); }
.ch-art img, .ch-art video { width: 100%; display: block; }
.ch-art audio { width: 100%; }
.ch-art-acts {
  display: flex; gap: 4px; padding: 5px 6px; background: var(--surface);
}
.ch-art-acts button {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .04em;
  padding: 2px 7px; border: var(--hair); border-radius: var(--r);
  background: transparent; color: var(--muted); cursor: pointer;
}
.ch-art-acts button:hover { color: var(--fg); border-color: var(--muted); }

/* job cards in the conversation log */
.ch-job {
  align-self: stretch; max-width: 520px;
  border: var(--hair); border-left: 2px solid var(--muted);
  border-radius: var(--r); background: var(--surface);
  padding: 8px 12px; font-family: var(--mono);
  display: flex; flex-direction: column; gap: 4px;
}
.ch-job[data-status="running"] { border-left-color: var(--accent); }
.ch-job[data-status="done"] { border-left-color: #5dbb6b; }
.ch-job[data-status="failed"] { border-left-color: var(--danger); }
.ch-job[data-status="cancelled"] { opacity: .65; }
.ch-job-top { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--fg); }
.ch-job-status { margin-left: auto; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ch-job-status[data-status="running"] { color: var(--accent); animation: gc-pulse 1.4s ease-in-out infinite; }
.ch-job-status[data-status="failed"] { color: var(--danger); }
.ch-job-status[data-status="done"] { color: #5dbb6b; }
.ch-job-prompt {
  font-size: 11px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ch-job-meta { display: flex; gap: 10px; font-size: 10px; color: var(--faint); }
.ch-job-out { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.ch-job-out:empty { display: none; margin: 0; }
.ch-job-out .ch-art { max-width: 460px; }
.ch-job-error { color: var(--danger); font-size: 11px; }

/* skill chips: which playbooks shaped the turn */
.ch-skills { display: flex; gap: 6px; flex-wrap: wrap; align-self: flex-start; }
.ch-skill {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  border-radius: 99px; padding: 2px 9px;
}
