/* run-stream.css — Compact streaming UI for Tower runs.
 * Light-theme only. Uses Tower's existing tokens where possible. */

.trs-mount {
  margin-top: 12px;
  border: 1px solid rgba(13, 28, 36, 0.08);
  border-radius: 12px;
  background: var(--air-card-bg, #ffffff);
  font-family: 'DM Sans', system-ui, sans-serif;
  overflow: hidden;
}

/* Header */
.trs-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(13, 28, 36, 0.06);
  background: rgba(13, 28, 36, 0.02);
  gap: 12px;
}
.trs-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #0d1c24;
  min-width: 0;
  flex: 1;
}
.trs-title > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}
.trs-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: rgba(13, 28, 36, 0.6);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.trs-editcount {
  font-weight: 500;
}
.trs-close {
  background: none;
  border: none;
  font-size: 14px;
  color: rgba(13, 28, 36, 0.5);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.trs-close:hover { background: rgba(13, 28, 36, 0.05); color: #0d1c24; }

/* Spinner */
.trs-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(13, 28, 36, 0.15);
  border-top-color: #0d1c24;
  border-radius: 50%;
  animation: trs-spin 0.8s linear infinite;
  flex-shrink: 0;
}
.trs-spinner-done {
  border-color: #1a7f4a;
  border-top-color: #1a7f4a;
  animation: none;
  background: #1a7f4a;
  position: relative;
}
.trs-spinner-done::after {
  content: '✓';
  color: #fff;
  font-size: 9px;
  display: block;
  text-align: center;
  line-height: 8px;
  font-weight: 700;
}
.trs-spinner-err {
  border-color: #b4231f;
  border-top-color: #b4231f;
  animation: none;
}
@keyframes trs-spin { to { transform: rotate(360deg); } }

/* Phase legend (shown when phases.length > 1) */
.trs-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(13, 28, 36, 0.015);
  border-bottom: 1px solid rgba(13, 28, 36, 0.04);
  font-size: 10px;
  color: rgba(13, 28, 36, 0.5);
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-weight: 600;
}
.trs-legend-item {
  white-space: nowrap;
}
.trs-legend-sep {
  color: rgba(13, 28, 36, 0.25);
  font-weight: 400;
}

/* Rows */
.trs-rows {
  max-height: 420px;
  overflow-y: auto;
}
.trs-row {
  border-bottom: 1px solid rgba(13, 28, 36, 0.04);
}
.trs-row:last-child { border-bottom: none; }
.trs-row-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
}
.trs-row-hdr:hover { background: rgba(13, 28, 36, 0.02); }
.trs-row-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #0d1c24;
  min-width: 0;
  flex: 1;
}
.trs-row-nametxt {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trs-chev {
  display: inline-block;
  width: 10px;
  font-size: 13px;
  color: rgba(13, 28, 36, 0.4);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.trs-row-dom {
  color: rgba(13, 28, 36, 0.5);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Phase pills (1+ per row) */
.trs-phases {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Status pills */
.trs-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  font-family: 'DM Sans', system-ui, sans-serif;
  letter-spacing: 0.2px;
  text-transform: lowercase;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}
.trs-pill-wait {
  background: rgba(13, 28, 36, 0.04);
  color: rgba(13, 28, 36, 0.4);
  border-color: rgba(13, 28, 36, 0.06);
}
.trs-pill-think {
  background: #fff3d6;
  color: #8a5a00;
  border-color: rgba(138, 90, 0, 0.15);
  position: relative;
  padding-right: 18px;
}
.trs-pill-think::after {
  content: '';
  position: absolute;
  right: 5px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border: 1.5px solid rgba(138, 90, 0, 0.3);
  border-top-color: #8a5a00;
  border-radius: 50%;
  animation: trs-spin 0.8s linear infinite;
}
.trs-pill-done {
  background: #d6f0e0;
  color: #1a7f4a;
  border-color: rgba(26, 127, 74, 0.18);
}
.trs-pill-fail {
  background: #fde2dd;
  color: #b4231f;
  border-color: rgba(180, 35, 31, 0.2);
}
.trs-pill-skip {
  background: rgba(13, 28, 36, 0.03);
  color: rgba(13, 28, 36, 0.35);
  border-color: rgba(13, 28, 36, 0.06);
  font-style: italic;
}

/* Detail panel (expanded row body) */
.trs-detail {
  padding: 6px 12px 10px 30px;
  background: rgba(13, 28, 36, 0.015);
  border-top: 1px solid rgba(13, 28, 36, 0.04);
}

/* Log lines (free-form text per row) */
.trs-log {
  font-size: 11px;
  color: rgba(13, 28, 36, 0.65);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  line-height: 1.5;
}
.trs-log-line {
  padding: 2px 0;
}
.trs-log-line:empty { display: none; }

/* Edits container (refine-style cards inside detail) */
.trs-edits-inner {
  margin-top: 6px;
}
.trs-edits-inner:empty { display: none; }

/* Edit cards */
.trs-edit {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #ffffff;
  border: 1px solid rgba(13, 28, 36, 0.06);
  border-radius: 8px;
  font-size: 11px;
}
.trs-edit:last-child { margin-bottom: 0; }
.trs-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.trs-edit-caption {
  font-weight: 500;
  color: #0d1c24;
  font-size: 11px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trs-edit-badge {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  text-transform: lowercase;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}
.trs-edit-applied { background: #d6f0e0; color: #1a7f4a; }
.trs-edit-ready   { background: #d6f0e0; color: #1a7f4a; }
.trs-edit-no_match{ background: #fde2dd; color: #b4231f; }
.trs-edit-failed  { background: #fde2dd; color: #b4231f; }

.trs-edit-search, .trs-edit-replace {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.5;
}
.trs-edit-lbl {
  flex-shrink: 0;
  width: 50px;
  color: rgba(13, 28, 36, 0.45);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding-top: 1px;
}
.trs-edit-search code {
  flex: 1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  background: #fef4f3;
  color: #6e1a16;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  word-break: break-word;
  white-space: pre-wrap;
}
.trs-edit-replace code {
  flex: 1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  background: #ecf6ef;
  color: #134d2c;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Footer */
.trs-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(13, 28, 36, 0.06);
  background: rgba(13, 28, 36, 0.02);
  font-size: 11px;
  color: #1a7f4a;
  font-weight: 500;
}

/* Modal-host variant — used by autonomous flows where there's no host
 * preview modal to nest inside. The shell becomes a centered dialog. */
.trs-host-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(13, 28, 36, 0.45);
  backdrop-filter: blur(4px);
}
/* `[hidden]` attribute would normally set display:none, but our explicit
 * `display: flex` above wins by specificity. Force the hide explicitly. */
.trs-host-modal[hidden] {
  display: none !important;
}
.trs-host-modal .trs-mount {
  margin-top: 0;
  max-width: 720px;
  width: 100%;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(13, 28, 36, 0.25);
}
.trs-host-modal .trs-rows {
  flex: 1;
  max-height: none;
}

/* ── Rich content (autonomous flows) ─────────────────────────────────── */

/* Contacts row — "Sending to: <chip> <chip> <chip>" */
.trs-contacts {
  padding: 2px 0 8px;
}
.trs-contacts:empty { display: none; }
.trs-contacts-label {
  font-size: 9.5px;
  font-weight: 600;
  color: rgba(13, 28, 36, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.trs-contact-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 8px;
  margin: 2px 4px 2px 0;
  background: #ffffff;
  border: 1px solid rgba(13, 28, 36, 0.10);
  border-radius: 8px;
  font-size: 11px;
}
.trs-contact-name {
  color: #0d1c24;
  font-weight: 600;
}
.trs-contact-title {
  color: rgba(13, 28, 36, 0.55);
  font-size: 10px;
}
.trs-contact-email {
  color: rgba(13, 28, 36, 0.45);
  font-size: 10px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

/* Draft cards (one per recipient) */
.trs-drafts-list {
  margin-top: 4px;
}
.trs-drafts-list:empty { display: none; }
.trs-draft-card {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #ffffff;
  border: 1px solid rgba(13, 28, 36, 0.08);
  border-radius: 10px;
  font-size: 11.5px;
}
.trs-draft-card:last-child { margin-bottom: 0; }
.trs-draft-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.trs-draft-to {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.trs-draft-to-name {
  color: #0d1c24;
  font-weight: 600;
  font-size: 12px;
}
.trs-draft-to-email {
  color: rgba(13, 28, 36, 0.5);
  font-size: 10.5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.trs-draft-status {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: lowercase;
  letter-spacing: 0.2px;
  border: 1px solid transparent;
}
.trs-draft-status-draft {
  background: #fff3d6;
  color: #8a5a00;
  border-color: rgba(138, 90, 0, 0.18);
}
.trs-draft-status-sent {
  background: #d6f0e0;
  color: #1a7f4a;
  border-color: rgba(26, 127, 74, 0.22);
}
.trs-draft-status-failed {
  background: #fde2dd;
  color: #b4231f;
  border-color: rgba(180, 35, 31, 0.22);
}
.trs-draft-subject {
  display: flex;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11.5px;
  line-height: 1.45;
}
.trs-draft-lbl {
  flex-shrink: 0;
  width: 52px;
  color: rgba(13, 28, 36, 0.45);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 9.5px;
  padding-top: 2px;
}
.trs-draft-subject-txt {
  color: #0d1c24;
  font-weight: 500;
  word-break: break-word;
}
.trs-draft-body {
  margin-top: 6px;
}
.trs-draft-body-pre {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 11.5px;
  line-height: 1.55;
  color: rgba(13, 28, 36, 0.78);
  background: #fafaf7;
  border: 1px solid rgba(13, 28, 36, 0.05);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
}
.trs-draft-expand {
  margin-top: 5px;
  background: none;
  border: 1px solid rgba(13, 28, 36, 0.12);
  color: rgba(13, 28, 36, 0.65);
  font-size: 10px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'DM Sans', system-ui, sans-serif;
}
.trs-draft-expand:hover {
  background: rgba(13, 28, 36, 0.04);
  color: #0d1c24;
}
