:root {
  --bg: #f3f4f6;
  --bg-soft: #eef1f4;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --text: #111827;
  --muted: #667085;
  --line: #d8dee6;
  --line-strong: #c5ced8;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --success: #15803d;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.03), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "IBM Plex Mono", "JetBrains Mono", "Fira Code", "Roboto Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  padding: 14px;
}

.topbar,
.workspace {
  max-width: 1480px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) 380px;
  gap: 12px;
  align-items: stretch;
}

.panel,
.canvas-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

.canvas-panel {
  border-radius: 10px;
  padding: 10px;
  min-height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
}

.panel {
  border-radius: 10px;
  padding: 10px;
}

.panel-header,
.panel-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-header {
  margin-bottom: 10px;
}

.panel-header h2,
.panel-section-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meta-line,
.meta-item,
.meta-label,
.status-chip {
  color: var(--muted);
}

.status-chip,
.ghost-button,
button,
input,
textarea,
select {
  border-radius: 8px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  min-height: 30px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 6px 10px;
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
}

button:hover {
  filter: brightness(0.97);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

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

label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidepanel {
  min-height: calc(100vh - 52px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.session-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

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

.inline-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.session-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding-top: 4px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.meta-label {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.run-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
}

.run-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #94a3b8;
}

.run-state.running {
  color: var(--success);
  border-color: rgba(21, 128, 61, 0.25);
  background: rgba(21, 128, 61, 0.06);
}

.run-state.running .run-dot {
  background: var(--success);
}

.canvas {
  position: relative;
  flex: 1;
  min-height: 640px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(148, 163, 184, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.14) 1px, transparent 1px),
    linear-gradient(180deg, #fafbfc, #f4f6f8);
  background-size: 24px 24px, 24px 24px, auto;
}

.node-card {
  position: absolute;
  width: 248px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
  cursor: grab;
  user-select: none;
  overflow: hidden;
}

.node-card.dragging {
  cursor: grabbing;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1);
}

.node-card.selected {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.12), var(--shadow-md);
}

.node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fcfdff, #f4f7fb);
}

.node-kind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.node-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-strong);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.node-type {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.node-status {
  color: var(--muted);
  font-size: 10px;
}

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

.node-title {
  font-size: 13px;
  font-weight: 600;
}

.node-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.node-preview {
  border: 1px solid var(--line);
  background: var(--surface-2);
  min-height: 72px;
  overflow: hidden;
}

.node-preview img,
.node-preview video {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  background: #fff;
}

.node-preview audio {
  display: block;
  width: 100%;
  height: 36px;
}

.log-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#events {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  min-height: 0;
  overflow: auto;
}

.event {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px;
}

.event-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.event-role {
  color: var(--text);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.event-time {
  color: var(--muted);
  font-size: 11px;
}

.event-title {
  margin-top: 4px;
  font-weight: 600;
  font-size: 12px;
}

.event-message {
  margin-top: 4px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.event details {
  margin-top: 6px;
}

.event summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
}

.event pre {
  margin: 6px 0 0;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow: auto;
}

.composer-panel textarea {
  margin-top: 10px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.28);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(460px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);
  padding: 14px;
}

.modal-card h2 {
  margin: 0 0 4px;
  font-size: 13px;
}

.modal-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-panel,
  .sidepanel {
    min-height: auto;
  }

  .sidepanel {
    grid-template-rows: auto auto auto;
  }

  .canvas {
    min-height: 520px;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
  }

  .topbar,
  .panel-header,
  .panel-section-head,
  .topbar-actions,
  .inline-controls {
    flex-wrap: wrap;
  }

  .inline-controls {
    grid-template-columns: 1fr;
  }

  .node-card {
    width: 220px;
  }
}
