:root {
  --canvas: #f7f6f3;
  --surface: #ffffff;
  --surface-soft: #fbfbfa;
  --ink: #111111;
  --text: #2f3437;
  --muted: #787774;
  --border: #eaeaea;
  --blue-bg: #e1f3fe;
  --blue-text: #1f6c9f;
  --green-bg: #edf3ec;
  --green-text: #346538;
  --red-bg: #fdebec;
  --red-text: #9f2f2d;
  --yellow-bg: #fbf3db;
  --yellow-text: #956400;
  --code-bg: #fbfbfa;
  --code-border: #e4e1da;
  --json-key: #7a3d8a;
  --json-string: #1f6c55;
  --json-number: #9a4d16;
  --json-bool: #1f5f9f;
  --json-null: #77706a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--canvas);
  font-family: "SF Pro Display", "Geist Sans", "Helvetica Neue", "Switzer", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow,
.meta,
.field span,
.stat span,
.step-label,
.tab-button,
h3 {
  margin: 0;
  color: var(--muted);
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  color: var(--ink);
  font-family: "Lyon Text", "Newsreader", "Playfair Display", "Instrument Serif", serif;
  font-size: 42px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
}

h2 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 650;
  line-height: 1.25;
}

h3 {
  margin-bottom: 10px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: #111111;
  cursor: pointer;
  transition: background 180ms ease, transform 180ms ease;
}

.button:hover {
  background: #333333;
}

.button:active {
  transform: scale(0.98);
}

.button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 9999px;
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.blue {
  color: var(--blue-text);
  background: var(--blue-bg);
}

.green,
.ok {
  color: var(--green-text);
  background: var(--green-bg);
}

.error {
  color: var(--red-text);
  background: var(--red-bg);
}

.disabled {
  color: var(--yellow-text);
  background: var(--yellow-bg);
}

.badge.count {
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.badge-kind.haiku,
.badge-kind.llm {
  color: var(--blue-text);
  background: var(--blue-bg);
}

.badge-kind.sonnet {
  color: var(--yellow-text);
  background: var(--yellow-bg);
}

.badge-kind.opus {
  color: var(--green-text);
  background: var(--green-bg);
}

.badge-kind.memory,
.badge-kind.neutral {
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.badge-kind.agenda {
  color: #7a5cc0;
  background: #f5f1fc;
}

.badge-kind.recordatorio {
  color: #0f7b8a;
  background: #eefafb;
}

.badge-kind.error {
  color: var(--red-text);
  background: var(--red-bg);
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  background: var(--surface);
}

.field {
  display: grid;
  gap: 7px;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid #eaeaea;
  border-radius: 6px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(17, 17, 17, 0.32);
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  min-height: 78px;
  padding: 16px;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  background: var(--surface);
}

.stat strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  min-height: calc(100vh - 260px);
  gap: 12px;
}

.list-panel,
.detail-panel {
  min-width: 0;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.panel-head,
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid #eaeaea;
}

.flow-list {
  max-height: calc(100vh - 292px);
  overflow: auto;
}

.flow-item {
  display: grid;
  width: 100%;
  gap: 7px;
  padding: 15px 16px;
  border: 0;
  border-bottom: 1px solid #eaeaea;
  color: inherit;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.flow-item:hover,
.flow-item.active {
  background: var(--surface-soft);
}

.flow-item-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.flow-item-preview {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#detail-title {
  margin-top: 4px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.empty-detail {
  display: grid;
  min-height: 420px;
  place-items: center;
  padding: 32px;
}

.empty-detail p,
.empty-list {
  margin: 0;
  color: var(--muted);
}

.empty-list {
  padding: 22px 16px;
  font-size: 13px;
}

.stage-list {
  padding: 0 16px 18px;
}

.stage {
  border-bottom: 1px solid #eaeaea;
  --accent: var(--border);
  --accent-bg: var(--surface-soft);
}

.stage.kind-haiku,
.stage.kind-llm {
  --accent: #9bccea;
  --accent-bg: #f5fbff;
}

.stage.kind-sonnet {
  --accent: #dec783;
  --accent-bg: #fffaf0;
}

.stage.kind-opus {
  --accent: #adc8a8;
  --accent-bg: #f7fbf6;
}

.stage.kind-memory,
.stage.kind-neutral {
  --accent: #d8d4cb;
  --accent-bg: #fbfbfa;
}

.stage.kind-agenda {
  --accent: #c3a9e8;
  --accent-bg: #faf7ff;
}

.stage.kind-recordatorio {
  --accent: #8fcdd6;
  --accent-bg: #f3fbfc;
}

.stage.kind-error {
  --accent: #e4a9aa;
  --accent-bg: #fff7f7;
}

.stage-toggle {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 18px 0;
  border: 0;
  border-left: 4px solid var(--accent);
  color: inherit;
  background: var(--accent-bg);
  text-align: left;
  cursor: pointer;
}

.stage-symbol {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--ink);
  background: #ffffff;
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
}

.stage-title {
  display: grid;
  gap: 3px;
}

.stage-title strong {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.25;
}

.stage-badges,
.call-badges {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.stage-body {
  display: grid;
  gap: 12px;
  padding: 0 0 18px 40px;
}

.call-card {
  border: 1px solid #eaeaea;
  border-radius: 8px;
  background: #ffffff;
  --accent: var(--border);
}

.call-card.kind-haiku,
.call-card.kind-llm {
  --accent: #9bccea;
}

.call-card.kind-sonnet {
  --accent: #dec783;
}

.call-card.kind-opus {
  --accent: #adc8a8;
}

.call-card.kind-memory,
.call-card.kind-neutral {
  --accent: #d8d4cb;
}

.call-card.kind-agenda {
  --accent: #c3a9e8;
}

.call-card.kind-recordatorio {
  --accent: #8fcdd6;
}

.call-card.kind-error {
  --accent: #e4a9aa;
}

.call-toggle {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px;
  border: 0;
  border-bottom: 1px solid #eaeaea;
  border-left: 4px solid var(--accent);
  color: inherit;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.call-card[data-open="false"] .call-toggle {
  border-bottom: 0;
}

.call-symbol {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-soft);
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 12px;
}

.call-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.call-title strong {
  color: var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 14px 0;
}

.tab-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #eaeaea;
  border-radius: 4px;
  background: var(--surface-soft);
  cursor: pointer;
}

.tab-button.active {
  color: #ffffff;
  background: #111111;
  border-color: #111111;
}

.tab-panel {
  padding: 12px 14px 14px;
}

.log-content {
  min-height: 260px;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  background: var(--code-bg);
}

.log-content.is-json {
  background:
    linear-gradient(90deg, rgba(31, 108, 159, 0.08), transparent 160px),
    var(--code-bg);
}

.log-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--code-border);
  background: rgba(251, 251, 250, 0.96);
  backdrop-filter: blur(8px);
}

.log-label,
.json-segment-title {
  color: var(--muted);
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.copy-button,
.json-copy {
  min-width: 58px;
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  color: var(--ink);
  background: #ffffff;
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.copy-button:hover,
.json-copy:hover {
  border-color: rgba(17, 17, 17, 0.28);
  background: #f3f1eb;
}

.copy-button.copied,
.json-copy.copied {
  color: var(--green-text);
  border-color: rgba(52, 101, 56, 0.28);
  background: var(--green-bg);
}

.copy-button.copy-error,
.json-copy.copy-error {
  color: var(--red-text);
  border-color: rgba(159, 47, 45, 0.28);
  background: var(--red-bg);
}

.plain-log {
  min-height: 260px;
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #2f3437;
  background: transparent;
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.json-segment-title {
  padding: 12px 14px 4px;
}

.json-viewer {
  padding: 12px 14px 16px;
  color: #2f3437;
  font-family: "Geist Mono", "SF Mono", "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.65;
}

.json-node {
  min-width: 0;
}

.json-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  list-style: none;
  cursor: pointer;
  overflow-wrap: anywhere;
}

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

.json-summary::before {
  content: "+";
  display: grid;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  color: var(--muted);
  background: #ffffff;
  font-size: 11px;
  line-height: 1;
}

details[open] > .json-summary::before {
  content: "-";
}

.json-key {
  color: var(--json-key);
  font-weight: 650;
}

.json-type {
  color: var(--muted);
}

.json-copy {
  min-width: 52px;
  min-height: 22px;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.json-summary:hover .json-copy,
.json-leaf:hover .json-copy,
.json-copy:focus {
  opacity: 1;
}

.json-children {
  margin-left: 9px;
  padding-left: 18px;
  border-left: 1px solid var(--code-border);
}

.json-leaf {
  min-height: 24px;
  padding-left: 24px;
  overflow-wrap: anywhere;
}

.json-value-string {
  color: var(--json-string);
}

.json-value-number {
  color: var(--json-number);
}

.json-value-boolean {
  color: var(--json-bool);
}

.json-value-null {
  color: var(--json-null);
  font-style: italic;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 24px, 1480px);
    padding-top: 20px;
  }

  .topbar,
  .detail-head,
  .call-toggle {
    align-items: stretch;
  }

  .controls,
  .summary-row,
  .workspace {
    grid-template-columns: 1fr;
  }

  .flow-list {
    max-height: none;
  }

  .stage-body {
    padding-left: 0;
  }

  .stage-toggle,
  .call-toggle {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .stage-badges,
  .call-badges {
    grid-column: 2;
    justify-content: flex-start;
  }

  .json-copy {
    opacity: 1;
  }
}
