/* thread-extras: what a thread shows over its composer (js/features/thread-extras.js), and the
   actions under its turns and messages (js/features/turn-actions.js). Compact: a phone has little
   room over its keyboard, so a bar is a line or two and its buttons, and lists start folded. */

/* ---------------------------------------------------------------- Bars over the composer */

.te-bar {
  container-type: inline-size;
  margin: 0 0 6px;
  padding: 9px 10px 9px 11px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.te-bar.approval {
  border-color: color-mix(in srgb, var(--approval) 40%, var(--border));
}

.te-bar.failed {
  border-color: color-mix(in srgb, var(--failed) 40%, var(--border));
}

.te-head {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.te-glyph {
  display: inline-flex;
  padding-top: 1px;
  color: var(--muted);
}

.te-glyph.approval {
  color: var(--approval);
}

.te-glyph.failed {
  color: var(--failed);
}

.te-head > .spinner {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  color: var(--muted);
}

.te-words {
  flex: 1;
  min-width: 0;
}

.te-title {
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  color: var(--fg-strong);
}

.te-detail {
  margin-top: 1px;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.te-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.te-btn {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 15px;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  color: var(--fg-strong);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  text-decoration: none;
}

.te-btn.strong {
  background: var(--fg-strong);
  color: var(--bg);
  font-weight: 650;
}

.te-btn:active {
  opacity: 0.8;
}

.te-btn[disabled] {
  opacity: 0.5;
}

/* The long words where they fit, the short ones where not (as the iPhone's ViewThatFits). */
.te-short {
  display: none;
}

@container (max-width: 345px) {
  .te-long {
    display: none;
  }

  .te-short {
    display: inline;
  }
}

/* ---------------------------------------------------------------- Lists: background, queued, sub-agents */

.te-list {
  margin: 0 0 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.te-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding-right: 4px;
}

.te-row + .te-row,
.te-list > .te-sub {
  border-top: 1px solid var(--border-soft);
}

.te-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 5px 0 5px 11px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

button.te-row-main[disabled] {
  cursor: default;
}

.te-list > button.te-row-main {
  width: 100%;
  padding-right: 10px;
}

.te-row-lead {
  width: 16px;
  flex: none;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}

.te-row-lead .spinner {
  width: 13px;
  height: 13px;
  border-width: 1.5px;
}

.te-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.te-row-title {
  font-size: 13.5px;
  color: var(--fg-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.te-row-title.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.te-row-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.te-row-sub .mono {
  font-size: 11px;
}

.te-icon,
.te-stop {
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.te-icon:active {
  background: var(--hover);
}

.te-stop {
  color: var(--fg);
}

.te-stop > span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
}

.te-stop[disabled] {
  opacity: 0.45;
}

.te-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 26px;
  padding: 0 8px;
  border: 0;
  border-radius: 13px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Sub-agents */

.te-counts {
  display: flex;
  gap: 7px;
  font-weight: 600;
}

.te-time {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.te-chev {
  width: 13px;
  flex: none;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}

.te-state {
  flex: none;
  font-size: 12px;
  font-weight: 600;
}

.te-sdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.te-sdot.pulse {
  animation: pulse 1.4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .te-sdot.pulse {
    animation: none;
  }
}

.te-working {
  color: var(--accent);
}

.te-approval {
  color: var(--approval);
}

.te-failed {
  color: var(--failed);
}

.te-done {
  color: var(--done);
}

.te-muted {
  color: var(--muted);
}

/* ---------------------------------------------------------------- Lines and the Compact chip */

.te-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0 4px 6px;
  font-size: 12px;
  color: var(--muted);
}

.te-line > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.te-line .icon {
  color: var(--approval);
}

.te-line.side .icon {
  color: var(--muted);
}

.te-chips {
  margin: 0 0 6px;
}

.te-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 32px;
  padding: 0 3px 0 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

.te-chip-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 4px 0 0;
  border: 0;
  background: transparent;
  color: var(--fg-strong);
  font-weight: 550;
}

.te-chip-main .icon {
  color: var(--muted);
}

.te-chip-icon {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
}

.te-chip-icon:active {
  background: var(--hover);
}

.te-why {
  margin-top: 6px;
  padding: 9px 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--raised);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--fg);
  white-space: pre-line;
}

/* ---------------------------------------------------------------- Sheets */

.te-sheet-sub {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.te-ask-msg {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.te-ask-btns {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.te-ask-btns > .btn {
  flex: 1;
}

.te-ask-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.te-note {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.te-note.te-rule {
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.te-checking {
  display: flex;
  align-items: center;
  gap: 8px;
}

.te-checking .spinner {
  width: 14px;
  height: 14px;
}

.te-para {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
}

.te-edit {
  min-height: 120px;
}

/* A background task's output */

.te-task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.te-task-title {
  margin: 4px 0 10px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-strong);
  overflow-wrap: anywhere;
}

.te-output {
  margin: 0;
  max-height: 52vh;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--fg);
}

/* A sub-agent */

.te-agent-head {
  margin-bottom: 12px;
}

.te-agent-head .te-title {
  font-size: 16px;
}

.te-label {
  margin: 14px 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.te-quote {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg-strong);
  white-space: pre-wrap;
}

.te-asking {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--approval) 11%, transparent);
  font-size: 13px;
  color: var(--fg-strong);
}

.te-asking .icon {
  color: var(--approval);
}

.te-asking .grow {
  flex: 1;
}

.te-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  font-size: var(--convo);
}

.te-steps .msg-user {
  align-self: flex-end;
}

.te-say {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.te-say textarea {
  flex: 1;
  min-height: 40px;
  font-size: 16px;
}

.te-say .send {
  margin-bottom: 2px;
}

/* What fills the context */

.te-ctx-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0 14px;
}

.te-ring {
  width: 38px;
  height: 38px;
  flex: none;
  transform: rotate(-90deg);
}

.te-ring circle {
  fill: none;
  stroke-width: 3.5;
  stroke-linecap: round;
}

.te-ring .track {
  stroke: color-mix(in srgb, var(--fg) 14%, transparent);
}

.te-meter {
  display: flex;
  gap: 1.5px;
  height: 8px;
  margin-bottom: 8px;
  border-radius: 4px;
  overflow: hidden;
}

.te-meter > span {
  display: block;
  min-width: 2px;
}

.te-meter-free {
  flex: 1;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
}

.te-meter-held {
  background: color-mix(in srgb, var(--fg) 18%, transparent);
}

.te-part {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  text-align: left;
}

.te-part .grow {
  flex: 1;
}

.te-swatch {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 2px;
}

.te-num {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.te-part-more {
  padding: 0 0 8px 18px;
  font-size: 12.5px;
  color: var(--muted);
}

.te-part-line {
  display: flex;
  gap: 8px;
  padding: 1px 0;
  color: var(--fg);
}

.te-part-line .grow {
  flex: 1;
}

.te-part-note {
  margin-top: 3px;
}

.te-compact {
  margin-top: 14px;
}

.te-compact .spinner {
  width: 16px;
  height: 16px;
}

.te-cost {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.te-cost .te-detail {
  margin-top: 4px;
  -webkit-line-clamp: unset;
}

/* A side chat not started yet */

.te-side {
  padding: 18px 8px 4px;
  text-align: center;
  color: var(--muted);
}

.te-side h3 {
  margin: 8px 0 6px;
  font-size: 17px;
  color: var(--fg-strong);
}

.te-side p {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

/* What undo, retry or rewind would put back */

.te-check {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-strong);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}

.te-check .icon {
  color: var(--muted);
}

.te-check[aria-checked='true'] .icon {
  color: var(--accent);
}

.te-file-list {
  padding-left: 30px;
}

.te-file-list.off {
  opacity: 0.5;
}

.te-file {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
  font-size: 12.5px;
}

.te-path {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.te-verb {
  flex: none;
  color: var(--muted);
}

/* ---------------------------------------------------------------- Under a turn and a message */

.te-acts {
  display: flex;
  align-items: center;
  min-height: 30px;
  margin: -6px -6px -6px 0;
  color: var(--muted);
}

.te-acts.user {
  align-self: flex-end;
}

.te-acts.end,
.te-acts.stop {
  margin-left: -6px;
}

/* The turn's end says itself here, its actions at the end of its line. */
.te-acts.end + .turn-end {
  display: none;
}

.te-acts .badge {
  margin-left: 8px;
}

.te-when {
  margin: 0 4px;
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.te-fill {
  flex: 1;
  min-width: 12px;
  margin: 0 8px;
  border-top: 1px solid var(--border-soft);
}

.te-act {
  width: 34px;
  height: 30px;
  flex: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.te-act .icon {
  width: 15px;
  height: 15px;
}

.te-act.narrow {
  width: 22px;
}

.te-act.narrow .icon {
  width: 13px;
  height: 13px;
}

.te-act:active {
  background: var(--hover);
  color: var(--fg);
}

.te-act[disabled] {
  opacity: 0.35;
}
