:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --cta: #f97316;
  --cta-hover: #ea580c;
  --dark: #0f172a;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --ok-border: #bbf7d0;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Fira Sans", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }

.app-shell { max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }
.hero > *, .workspace > *, .registry-grid > * { min-width: 0; }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1 {
  margin: 10px 0 12px;
  font-size: 34px;
  line-height: 1.25;
  letter-spacing: -.01em;
}

.hero p { max-width: 640px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.hero-actions { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }

.primary, .secondary, .add-node {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}

.primary { background: var(--cta); color: #fff; }
.primary:hover { background: var(--cta-hover); }
.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.secondary:hover { border-color: #cbd5e1; background: var(--bg); }

.publish-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  align-self: start;
}

.card-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.card-title::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); flex: none; }
.publish-card ul { list-style: none; margin: 12px 0 0; padding: 0; }
.publish-card li { padding: 9px 0; border-top: 1px solid var(--border-soft); font-size: 13.5px; color: #475569; }
.publish-card li:first-child { border-top: 0; }

.status { margin-top: 14px; border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; line-height: 1.5; }
.status.good { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-border); }
.status.bad { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); }

/* ---------- Panels ---------- */
.workspace { display: grid; grid-template-columns: 300px 1fr; gap: 20px; margin-top: 20px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.panel h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -.01em; }
.panel p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.65; }

/* ---------- Operator palette ---------- */
.operator-list { display: grid; gap: 10px; margin: 18px 0; }

.operator {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.operator:hover { border-color: #93c5fd; transform: translateY(-1px); }
.operator > span:first-child {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  background: #f1f5f9;
  color: #475569;
}
.operator span:nth-child(2) { font-weight: 700; font-size: 14.5px; }
.operator small { grid-column: 2; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.operator.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }

.operator[data-select="start"] > span:first-child { background: #eff6ff; color: #2563eb; }
.operator[data-select="condition"] > span:first-child { background: #fffbeb; color: #d97706; }
.operator[data-select="tool"] > span:first-child { background: #f5f3ff; color: #7c3aed; }
.operator[data-select="function"] > span:first-child { background: #ecfdf5; color: #059669; }
.operator[data-select="data"] > span:first-child { background: #fff1f2; color: #e11d48; }
.operator[data-select="publish"] > span:first-child { background: #fff7ed; color: #ea580c; }

.add-node { width: 100%; background: var(--dark); color: #fff; }
.add-node:hover { background: #1e293b; }

.ghost {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: background .15s, border-color .15s;
}
.ghost:hover { background: var(--bg); border-color: #cbd5e1; }
.palette .ghost { width: 100%; margin-top: 12px; }

/* ---------- Canvas ---------- */
.section-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.section-header.compact { margin-bottom: 12px; }

.section-header input, .flow-node input, textarea, select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}
.section-header input:focus, .flow-node input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.field-row { display: flex; gap: 10px; }
.field-row input:first-child { min-width: 240px; }
.field-row input:last-child { width: 100px; }

.flow-list { position: relative; display: grid; gap: 14px; }
.flow-list::before {
  content: "";
  position: absolute;
  left: 36px;
  top: 28px;
  bottom: 28px;
  width: 2px;
  background: var(--border);
}

.flow-node {
  position: relative;
  display: grid;
  grid-template-columns: 40px 40px 1fr 34px;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--border);
  border-left: 3px solid var(--node-accent, var(--border));
  border-radius: 14px;
  padding: 16px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.flow-node:hover { border-color: #cbd5e1; box-shadow: 0 2px 8px rgba(15, 23, 42, .05); }
.flow-node.type-start { --node-accent: #2563eb; }
.flow-node.type-condition { --node-accent: #d97706; }
.flow-node.type-tool { --node-accent: #7c3aed; }
.flow-node.type-function { --node-accent: #059669; }
.flow-node.type-data { --node-accent: #e11d48; }
.flow-node.type-publish { --node-accent: #ea580c; }

.node-index, .node-icon { display: grid; place-items: center; font-weight: 700; }
.node-index {
  position: relative;
  z-index: 1;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 14px;
}
.node-icon { height: 40px; border-radius: 10px; font-size: 16px; background: #f1f5f9; color: #475569; }
.node-icon.type-start { background: #eff6ff; color: #2563eb; }
.node-icon.type-condition { background: #fffbeb; color: #d97706; }
.node-icon.type-tool { background: #f5f3ff; color: #7c3aed; }
.node-icon.type-function { background: #ecfdf5; color: #059669; }
.node-icon.type-data { background: #fff1f2; color: #e11d48; }
.node-icon.type-publish { background: #fff7ed; color: #ea580c; }

.node-body { display: grid; gap: 10px; min-width: 0; }
.node-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.node-meta span { font-weight: 700; font-size: 14.5px; }
.node-meta label { margin-left: auto; color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.node-meta input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

code {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 12px;
}

textarea { min-height: 68px; resize: vertical; line-height: 1.6; }

.icon-button {
  border: 0;
  background: #fef2f2;
  color: #dc2626;
  border-radius: 9px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: background .15s;
}
.icon-button:hover { background: #fee2e2; }
.flow-node.disabled { opacity: .55; }

/* ---------- Registry ---------- */
.registry-grid { display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 20px; margin-top: 20px; }

.registry-item { padding: 14px 0; display: grid; gap: 6px; }
.registry-item + .registry-item { border-top: 1px solid var(--border-soft); }
.registry-item strong { font-size: 15px; }
.registry-item p { font-size: 13.5px; }
.auth-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.payload-panel label { display: grid; gap: 8px; font-weight: 600; font-size: 13.5px; margin-bottom: 14px; }

pre {
  max-width: 100%;
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border-radius: 12px;
  background: var(--dark);
  color: #cbd5e1;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ---------- Log ---------- */
.log-panel { margin-top: 20px; }
.log-panel ol { margin: 0; padding-left: 20px; color: #475569; font-size: 13.5px; line-height: 1.6; }
.log-panel li { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.log-panel li:last-child { border-bottom: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .hero, .workspace, .registry-grid { grid-template-columns: 1fr; }
  .publish-card { width: 100%; }
}

@media (max-width: 720px) {
  .app-shell { padding: 16px 12px 32px; }
  .hero { padding: 22px; border-radius: 14px; }
  h1 { font-size: 26px; }
  .hero p { font-size: 14px; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .primary, .secondary, .add-node, .ghost { width: 100%; }
  .panel { padding: 18px; border-radius: 14px; }
  .section-header { flex-direction: column; align-items: stretch; }
  .field-row { flex-direction: column; }
  .field-row input:first-child, .field-row input:last-child { min-width: 0; width: 100%; }
  .flow-node { grid-template-columns: 32px 1fr 32px; gap: 10px; padding: 14px; }
  .flow-list::before { left: 31px; }
  .node-icon { display: none; }
  .node-index { height: 32px; font-size: 13px; }
  .node-meta label { width: 100%; margin-left: 0; }
  pre { font-size: 11.5px; }
}
