/* Helpers (components/helpers/) and sessions working together, on the card, in the sheet, in the
   thread and in their own window. Color says what a helper is (a subagent blue, a fork purple, a workflow
   teal, a teammate its own color) and how it stands (green while it works or once it is done,
   red when it failed); everything else stays quiet, the card most of all. */

:root {
  --teal: #30b0c7;
  --pink: #ff2d55;
  --yellow: #ffcc00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --teal: #40c8e0;
    --pink: #ff375f;
    --yellow: #ffd60a;
  }
}
:root[data-theme="dark"] {
  --teal: #40c8e0;
  --pink: #ff375f;
  --yellow: #ffd60a;
}

/* What a helper is: its icon in a tinted round, and the same color for its dot on a card. */
.h-icon, .hd { --hc: var(--accent); }
.k-fork { --hc: var(--purple); }
.k-workflow { --hc: var(--teal); }
.k-teammate { --hc: var(--green); }
.k-session { --hc: var(--label-2); }
[data-color="blue"] { --hc: var(--blue); }
[data-color="green"] { --hc: var(--green); }
[data-color="yellow"] { --hc: var(--yellow); }
[data-color="purple"] { --hc: var(--purple); }
[data-color="orange"] { --hc: var(--orange); }
[data-color="red"] { --hc: var(--red); }
[data-color="pink"] { --hc: var(--pink); }
[data-color="cyan"] { --hc: var(--teal); }
.h-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--hc) 15%, transparent);
  color: var(--hc);
}
.h-icon svg { width: 13px; height: 13px; stroke-width: 1.8; }

/* How it stands: a spinner while it works, else a small round sign. */
.h-mark { display: grid; place-items: center; flex: none; width: 16px; height: 16px; border-radius: 50%; color: #fff; background: var(--gray); }
.h-mark svg { width: 10px; height: 10px; stroke-width: 2.3; }
.h-mark.run { background: none; }
.h-mark.run .spin { width: 13px; height: 13px; }
.h-mark.ok { background: var(--green); }
.h-mark.fail { background: var(--red); }
.h-mark.idle { background: none; box-shadow: inset 0 0 0 1.5px var(--label-3); color: var(--label-2); }
.h-mark.idle svg { width: 12px; height: 12px; }
.h-time { flex: none; font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- the card */
/* Helpers at work: a dot each, how many, what the newest does. Only while they work. */
/* The chip's row: a narrow card keeps the count and lets the description go. */
.helpers-row { container: helpers-row / inline-size; margin-top: 7px; }
@container helpers-row (max-width: 230px) { .helpers-chip .d { display: none; } }
.helpers-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 9px 3px 5px;
  border: 0;
  border-radius: 999px;
  background: var(--fill-2);
  color: var(--label-2);
  font-size: 12px;
  text-align: left;
  transition: transform 100ms ease-out, background 150ms ease;
}
.helpers-chip:hover { background: var(--fill); }
.helpers-chip:active { transform: scale(0.97); }
.helpers-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.helpers-chip .n { flex: 0 1 auto; min-width: 0; overflow: hidden; color: var(--label); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.helpers-chip .d { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hdots { display: inline-flex; flex: none; padding-left: 4px; }
.hd { width: 10px; height: 10px; margin-left: -4px; border-radius: 50%; background: var(--hc); box-shadow: 0 0 0 2px var(--surface); }

/* Who started it, how many it started: the card's quietest line. */
.rels { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 7px; min-width: 0; font-size: 11.5px; color: var(--label-3); }
.rel { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; }
.rel svg { width: 12px; height: 12px; }
.rel span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
button.rel:hover { color: var(--accent); }
button.rel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Pointing at a card marks the sessions it works with. */
.card.related { box-shadow: var(--shadow-card), 0 0 0 2px color-mix(in srgb, var(--accent) 42%, transparent); }
.card.related.selected { box-shadow: var(--shadow-card), 0 0 0 2px var(--accent); }

/* ---------------------------------------------------------------- the sheet */
/* What works now does not give way to the card's fields: it has a height of its own and scrolls. */
.sheet-helpers { flex: 0 0 auto; min-height: 0; max-height: min(32vh, 30cqh); overflow: auto; overscroll-behavior: contain; padding: 0 18px 10px 22px; }
.helpers-head { display: flex; align-items: baseline; gap: 8px; margin: 2px 2px 6px; }
.helpers-head h3 { margin: 0; font-size: 12px; font-weight: 600; color: var(--label-2); letter-spacing: 0.02em; }
.helpers-sum { flex: 1; min-width: 0; font-size: 12px; color: var(--label-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.helpers-all { display: inline-flex; align-items: center; gap: 2px; padding: 0 2px; border: 0; background: none; color: var(--accent); font-size: 12px; font-weight: 500; }
.helpers-all .chev { width: 11px; height: 11px; }
.helpers-all:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.helper-rows { display: flex; flex-direction: column; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-card); overflow: hidden; }
.helper-row, .helper-last, .helper-more {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 6px 12px;
  border: 0;
  background: none;
  color: var(--label);
  font: inherit;
  text-align: left;
  transition: background 120ms ease;
}
.helper-row + .helper-row, .helper-row + .helper-more, .helper-run + .helper-row { box-shadow: inset 0 0.5px 0 var(--separator); }
.helper-row:hover, .helper-last:hover, .helper-more:hover { background: var(--fill-2); }
.helper-row:active, .helper-last:active { background: var(--fill); }
.helper-row:focus-visible, .helper-last:focus-visible, .helper-more:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.helper-row.nested { padding-left: calc(12px + var(--depth, 1) * 18px); }
.h-main { display: flex; flex-direction: column; min-width: 0; }
.h-title { overflow: hidden; font-size: 13px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; }
.h-now { overflow: hidden; font-size: 12px; color: var(--label-2); white-space: nowrap; text-overflow: ellipsis; }
.h-now b { color: var(--green); font-weight: 600; }
.helper-row[data-status="stopped"] .h-title, .helper-row[data-status="failed"] .h-title { color: var(--label-2); }
.helper-last { grid-template-columns: 22px minmax(0, 1fr) 16px; min-height: 38px; font-size: 12.5px; color: var(--label-2); }
.helper-last > span:nth-child(2) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.helper-more { display: block; min-height: 34px; color: var(--accent); font-size: 12.5px; font-weight: 500; text-align: center; }

/* The sessions it works with, among the card's fields: one chip each, marked with how. */
.rel-row { align-items: flex-start; }
.rel-row .row-label { padding-top: 4px; }
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.rel-marks { display: inline-flex; gap: 1px; color: var(--label-2); }
.rel-marks svg { width: 12px; height: 12px; }
.rel-more { height: 26px; padding: 0 8px; border: 0; background: none; color: var(--accent); font-size: 12.5px; font-weight: 500; }
.rel-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 6px; }
.rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--fill-2);
  color: var(--label);
  font-size: 12.5px;
  font-weight: 500;
  transition: transform 100ms ease-out, background 150ms ease;
}
.rel-chip::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 2.5px; background: var(--lane); }
.rel-chip:hover { background: var(--fill); }
.rel-chip:active { transform: scale(0.95); }
.rel-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rel-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rel-io { display: inline-flex; gap: 4px; color: var(--label-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.rel-io i { font-style: normal; }

/* ---------------------------------------------------------------- the thread */
/* A call that works with others: a quiet line of its own, like a notice. */
.link-line { align-self: stretch; min-width: 0; font-size: 12px; line-height: 1.4; color: var(--label-2); }
div.link-line, button.link-line, .link-line > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-width: 0;
  padding: 4px 8px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
}
.link-line > summary { list-style: none; cursor: default; }
.link-line > summary::-webkit-details-marker { display: none; }
button.link-line:hover, .link-line > summary:hover { background: var(--fill-2); }
button.link-line:focus-visible, .link-line > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.link-line .h-icon { width: 18px; height: 18px; }
.link-line .h-icon svg { width: 11px; height: 11px; }
.link-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.link-title { color: var(--label); font-weight: 500; }
.link-text small { font-size: 11.5px; color: var(--label-3); }
.link-line .when { flex: none; font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.link-line.failed .link-text { color: var(--red); }
.link-line > summary .chev { flex: none; width: 11px; height: 11px; transition: transform 200ms ease; }
.link-line[open] > summary .chev { transform: rotate(90deg); }
.who { display: inline; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.who:hover { text-decoration: underline; }
.who:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
.notice-open { flex: none; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 500; cursor: pointer; }
.notice-open:hover { text-decoration: underline; }

/* Another session's or a teammate's message: their bubble, on the far side from the user's. */
.msg.peer {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: color-mix(in srgb, var(--purple) 9%, var(--surface));
  box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--purple) 28%, transparent);
}
.msg.peer.team { background: color-mix(in srgb, var(--green) 9%, var(--surface)); box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--green) 28%, transparent); }
.peer-from { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 6px; margin-bottom: 3px; font-size: 11.5px; color: var(--label-2); }
.peer-from svg { width: 12px; height: 12px; align-self: center; color: var(--purple); }
.msg.peer.team .peer-from svg { color: var(--green); }
.peer-from small { color: var(--label-3); }

/* ---------------------------------------------------------------- the window */
/* Just under the quick look: a file in a helper's conversation opens over it. */
.ql.helpers { z-index: 69; }
.helpers .ql-win { width: min(880px, calc(100vw - 48px)); }
.helper-head .ql-icon .h-icon { width: 30px; height: 30px; }
.helper-head .ql-icon .h-icon svg { width: 17px; height: 17px; stroke-width: 1.6; }
.helper-head .ql-icon > svg { width: 26px; height: 26px; color: var(--accent); stroke-width: 1.5; }
.helper-sub { margin: 1px 0 0; overflow: hidden; font: 12px/1.35 var(--font); color: var(--label-2); white-space: nowrap; text-overflow: ellipsis; }
.helper-state { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 999px; background: var(--fill); font-size: 12px; font-weight: 500; white-space: nowrap; }
.helper-state:empty { display: none; }
.helper-state[data-tone="ok"] { color: var(--green); }
.helper-state[data-tone="fail"] { color: var(--red); }
.helper-body.k-list { padding: 4px 16px 20px; }
.helper-section h4 { margin: 18px 0 8px 2px; font-size: 12px; font-weight: 600; color: var(--label-2); letter-spacing: 0.02em; }
.helper-run { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-size: 12px; color: var(--label-2); }
.helper-thread { max-width: 860px; margin: 0 auto; padding: 14px 18px 24px; }
.helper-foot { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- layouts */
/* The card's fields and the helpers give way before the conversation does: it keeps a third of
   the sheet (they scroll instead). */
#sheet .sheet-body { min-height: max(96px, min(36cqh, 280px)); }
/* Side by side (a wide, low sheet): the helpers go above the conversation, beside the card. */
@container sheet (min-width: 680px) and (min-aspect-ratio: 5 / 4) {
  #sheet .sheet-inner { grid-template-rows: auto auto auto minmax(0, 1fr) auto; }
  #sheet .sheet-card { grid-row: 2 / 6; }
  #sheet .sheet-helpers { grid-column: 2; grid-row: 3; padding-left: 8px; }
  #sheet .sheet-body { grid-row: 4; min-height: 0; }
  #sheet .composer { grid-row: 5; }
}
@media (max-width: 760px) {
  #sheet .sheet-helpers { max-height: 24vh; padding: 0 16px 8px; }
  .helper-row { min-height: 48px; }
  .helpers .helper-thread { padding: 12px 12px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .helpers-chip, .rel-chip, .helper-row, .link-line > summary .chev { transition: none; }
}
@media (prefers-contrast: more) {
  .helper-rows { box-shadow: 0 0 0 1px var(--label-3); }
  .msg.peer { box-shadow: inset 0 0 0 1px var(--label-3); }
}
