:root {
  --bg: #f1f4ff;
  --card: #ffffff;
  --line: #d9e0ef;
  --ink: #17233b;
  --muted: #556078;
  --accent: #2f59ff;
  --good: #0b8f4f;
  --bad: #b00020;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  background: radial-gradient(1100px 540px at 100% -20%, #e8efff 0%, transparent 46%), var(--bg);
  color: var(--ink);
  line-height: 1.35;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

h1, h2 {
  margin: 0 0 8px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(0, 10, 60, 0.08);
}

.card.full { grid-column: 1 / -1; }

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea,
button {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 9px 10px;
  margin-top: 6px;
  font-size: 14px;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

button {
  background: #eef3ff;
  color: #20315f;
  font-weight: 600;
  border-color: #bac8ea;
  cursor: pointer;
}

button.primary { background: #20315f; color: #fff; border-color: #20315f; }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.metric-row {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #f8faff;
  color: var(--ink);
}

.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { font-size: 18px; }

.log, .state, .state-block {
  margin-top: 12px;
  border-radius: 10px;
  background: #f8f8ff;
  border: 1px dashed var(--line);
  padding: 10px;
  min-height: 62px;
  color: #1f2a47;
  font-size: 13px;
  white-space: pre-wrap;
}

.state-block { min-height: 40px; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}

thead th {
  text-align: left;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 7px 6px;
}

tbody td {
  padding: 8px 6px;
  border-bottom: 1px solid #edf0f6;
  vertical-align: top;
}

.run-row.is-selected td {
  background: #eef3ff;
}

.run-open-btn {
  width: auto;
  margin-top: 0;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.run-wave {
  font-weight: 600;
  color: var(--ink);
}

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 8px 0;
  overflow: hidden;
}

.item-header {
  background: #f4f6fc;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
}

.item-header b { display: block; }

.item-body { padding: 8px; display: grid; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: #355;
  background: #f4fbf5;
}

.chat-fold {
  background: #fcfdff;
  border: 1px solid #edf2ff;
  border-radius: 10px;
  overflow: hidden;
}

.chat-summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8faff;
}

.chat-summary::-webkit-details-marker {
  display: none;
}

.chat-summary::after {
  content: "▾";
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
}

.chat-fold[open] .chat-summary::after {
  transform: rotate(180deg);
}

.summary-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-content {
  padding: 10px 12px;
  border-top: 1px solid #edf2ff;
}

.empty-note {
  background: #fcfdff;
  border: 1px solid #edf2ff;
  border-radius: 10px;
  padding: 12px;
  color: var(--muted);
}

.msg {
  margin: 8px 0;
  border-left: 3px solid #adc0ff;
  padding-left: 10px;
}

.msg.outbound { border-left-color: #5d89ff; }
.msg.inbound { border-left-color: var(--good); }

.msg .meta {
  color: #596680;
  font-size: 12px;
}

.msg pre {
  white-space: pre-wrap;
  margin: 4px 0 0;
  font-size: 13px;
}

@media (max-width: 1000px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .metric-row {
    grid-template-columns: 1fr 1fr;
  }
  .chat-summary {
    align-items: flex-start;
    flex-direction: column;
  }
}
