* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #1c1e21;
  background: #f5f6f8;
}
#app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid #dcdfe3;
}
header h1 { font-size: 15px; margin: 0; font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  padding: 6px 14px; border: 1px solid #dcdfe3; background: #fff; border-radius: 6px;
  cursor: pointer; font-size: 13px;
}
.tabs button.active { background: #1c4ed8; color: #fff; border-color: #1c4ed8; }

.api-base-field { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.api-base-field label { font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase; }
.api-base-field select { padding: 5px 6px; font-size: 12px; width: auto; }
.api-base-field input { width: 190px; padding: 5px 8px; font-size: 12px; }
.api-base-field button { padding: 5px 10px; font-size: 12px; }
.api-base-field #api-base-status { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

main { flex: 1; display: flex; overflow: hidden; }

.sidebar {
  width: 220px; background: #fff; border-right: 1px solid #dcdfe3;
  padding: 12px; overflow-y: auto; flex-shrink: 0;
}
.sidebar h3 { font-size: 11px; text-transform: uppercase; color: #6b7280; margin: 16px 0 6px; }
.sidebar h3:first-child { margin-top: 0; }
.agent-group-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #9ca3af; margin: 14px 0 4px; }
.agent-group-label:first-child { margin-top: 0; }
.agent-btn {
  display: flex; align-items: center; justify-content: space-between; width: 100%; text-align: left;
  padding: 8px 10px; margin-bottom: 4px;
  border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; font-size: 13px;
}
.agent-btn:hover { background: #f0f2f5; }
.agent-btn.active { background: #e8edff; border-color: #1c4ed8; color: #1c4ed8; font-weight: 600; }
.agent-dot { width: 7px; height: 7px; border-radius: 50%; background: #10b981; flex-shrink: 0; display: none; }

select, input[type=text], input[type=number], textarea {
  width: 100%; padding: 6px 8px; border: 1px solid #dcdfe3; border-radius: 5px; font-size: 12.5px;
  font-family: inherit; background: #fff;
}
.email-item {
  padding: 6px 8px; border-radius: 5px; cursor: pointer; margin-bottom: 3px; font-size: 12px;
  border: 1px solid transparent; line-height: 1.3;
}
.email-item:hover { background: #f0f2f5; }
.email-item.active { background: #e8edff; border-color: #1c4ed8; }
.email-item .snippet { color: #6b7280; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Stage/Flow panel and its output stack vertically in one column now —
   output shows below the Run button instead of in a separate side panel,
   for either tab. */
.center-column {
  flex: 1; display: flex; flex-direction: column; overflow-y: auto; min-width: 480px;
}
.center {
  padding: 14px;
}
.right {
  padding: 14px 14px 24px; background: #fafbfc; border-top: 1px solid #dcdfe3;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; font-weight: 600; color: #4b5563; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .02em; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

textarea.prompt-editor { min-height: 320px; font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; line-height: 1.5; resize: vertical; }
textarea.input-editor { min-height: 140px; font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; resize: vertical; }

/* Read-only info, not an editable field — flat/muted so it doesn't look
   like an input box a tester could type into (it can't). */
.field-list {
  min-height: 110px; padding: 8px 10px; border-radius: 6px; background: #f3f4f6;
  font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; line-height: 1.6;
  color: #4b5563; white-space: pre-line; overflow-y: auto;
}

/* Collapsed by default (no `open` attribute in the HTML) — the prompt
   text isn't what a tester needs to see first; the input/run controls
   below it are. */
.prompt-section-row { display: flex; align-items: flex-start; gap: 6px; margin-bottom: 12px; }
.collapsible { flex: 1; border: 1px solid #dcdfe3; border-radius: 6px; background: #fff; overflow: hidden; }
.collapsible summary {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; list-style: none;
  font-size: 11px; font-weight: 600; color: #4b5563; text-transform: uppercase; letter-spacing: .02em;
  user-select: none;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::marker { content: ""; }
.collapsible summary::before {
  content: "▸"; display: inline-block; color: #9ca3af; font-size: 10px; transition: transform .12s;
}
.collapsible[open] summary::before { transform: rotate(90deg); }
.collapsible summary .shared-note { text-transform: none; }
.collapsible textarea { border: none; border-top: 1px solid #dcdfe3; border-radius: 0; margin: 0; }

.icon-btn {
  width: 30px; height: 30px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  padding: 0; background: #fff; color: #1c4ed8; border: 1px solid #1c4ed8; border-radius: 6px; cursor: pointer;
}
.icon-btn:hover { background: #f0f4ff; }

.chain-fields { border: 1px solid #dcdfe3; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; background: #fff; }
.chain-fields > label { display: block; font-size: 11px; font-weight: 600; color: #4b5563; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .02em; }
.run-source-group { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.run-source-label { font-size: 12px; color: #374151; min-width: 130px; flex-shrink: 0; line-height: 1.3; }
.run-source-select { flex: 1; padding: 4px 6px; font-size: 12px; }
.run-source-scope { max-width: 200px; padding: 4px 6px; font-size: 12px; }
.run-source-load { padding: 5px 12px; font-size: 12px; flex-shrink: 0; }

.flow-section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #1c4ed8; margin: 16px 0 6px; }
.flow-section-label:first-child { margin-top: 0; }
.flow-stage-card { border: 1px solid #dcdfe3; border-radius: 6px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.flow-stage-card > label { margin-bottom: 6px; }
.flow-stage-card .collapsible { border-color: #e5e7eb; }

.model-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; border: 1px solid #dcdfe3; border-radius: 6px; padding: 8px; max-height: 160px; overflow-y: auto; background: #fff; }
.model-list label { display: flex; align-items: center; gap: 6px; font-weight: 400; text-transform: none; font-size: 12.5px; min-width: 0; }
.model-list label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-list .badge { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #eee; color: #666; }
.model-list .badge.confirmed { background: #d1fae5; color: #065f46; }
.model-list .badge.unverified { background: #fef3c7; color: #92400e; }

button.primary {
  padding: 8px 16px; background: #1c4ed8; color: #fff; border: none; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
button.primary:hover { background: #1640b0; }
button.secondary {
  padding: 8px 16px; background: #fff; color: #1c4ed8; border: 1px solid #1c4ed8; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
button.secondary:hover { background: #f0f4ff; }
button:disabled { opacity: .5; cursor: default; }

.result-card { background: #fff; border: 1px solid #dcdfe3; border-radius: 8px; margin-bottom: 12px; overflow: hidden; }
.result-card .rc-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #f0f2f5; font-size: 12.5px; }
.result-card .rc-header .meta { color: #6b7280; }
.result-card .rc-body { padding: 10px 12px; }
.result-card.error { border-color: #ef4444; }
.result-card.error .rc-header { background: #fef2f2; }

.checks { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.check-badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; cursor: default; }
.check-badge.pass { background: #d1fae5; color: #065f46; }
.check-badge.fail { background: #fee2e2; color: #991b1b; }

pre.output {
  background: #0d1117; color: #c9d1d9; padding: 10px; border-radius: 6px; font-size: 11.5px;
  max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.stage-label { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; color: #1c4ed8; margin-bottom: 4px; }
.stopped-banner { background: #fef2f2; border: 1px solid #ef4444; color: #991b1b; padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.warn-banner { background: #fef3c7; border: 1px solid #f59e0b; color: #92400e; padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.empty-hint { color: #9ca3af; font-size: 13px; padding: 20px; text-align: center; }
.shared-note { text-transform: none; font-weight: 400; color: #92400e; font-size: 11px; }

/* Clean output rendering */
.email-preview { background: #fff; border: 1px solid #dcdfe3; border-radius: 6px; padding: 12px 14px; margin-bottom: 8px; }
.template-name { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #1c4ed8; margin-bottom: 6px; }
.email-subject { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.email-body { white-space: pre-wrap; line-height: 1.5; font-size: 13px; }

.qa-verdict { font-weight: 600; font-size: 13px; padding: 8px 10px; border-radius: 6px; margin-bottom: 8px; background: #fee2e2; color: #991b1b; }
.qa-verdict.valid { background: #d1fae5; color: #065f46; }
.qa-issues { margin: 0 0 8px; padding-left: 18px; font-size: 12.5px; line-height: 1.6; }

.scope-card { background: #fff; border: 1px solid #dcdfe3; border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; }
.scope-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.screener-list { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.7; }
.source-tag { font-size: 10px; color: #6b7280; text-transform: uppercase; letter-spacing: .03em; }

.raw-details { margin-top: 6px; }
.raw-details summary { cursor: pointer; font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: .03em; }
.raw-details pre.output { margin-top: 6px; }
