:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --user: #dbeafe;
  --backend: #ede9fe;
  --system: #f1f5f9;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: #0f172a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f8fafc;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--bg);
  color: #fff;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

.selector {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.selector label {
  font-size: 13px;
  opacity: 0.8;
}

.selector select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #fff;
  font-size: 14px;
}

.selector-desc {
  margin: 0;
  font-size: 12px;
  color: #94a3b8;
  flex: 1;
}

.app-main {
  flex: 1;
  min-height: 0;
}

.studio {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 1.2fr;
  gap: 16px;
  height: 100%;
  padding: 16px;
}

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-title {
  font-weight: 600;
}

.chat-party {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
}

.reset-btn {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.reset-btn:hover {
  background: var(--border);
  color: inherit;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.bubble {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.bubble-author {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.bubble-system {
  align-self: flex-start;
  background: var(--system);
}

.bubble-backend {
  align-self: flex-start;
  background: var(--backend);
}

.bubble-user {
  align-self: flex-end;
  background: var(--user);
}

.typing {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
  vertical-align: middle;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

.chat-input {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  min-height: 56px;
}

.composer {
  display: flex;
  gap: 8px;
}

.composer input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

button {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

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

.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* Flow */
.flow {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.flow-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.flow-title {
  white-space: nowrap;
}

.flow-breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  font-weight: 400;
  font-size: 12px;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.crumb-sep {
  color: var(--muted);
  margin: 0 2px;
}

.crumb-link {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}
.crumb-link:hover {
  text-decoration: underline;
}

.crumb-current {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--text, inherit);
  font-weight: 600;
  font-size: 12px;
  cursor: default;
}

.flow-canvas {
  flex: 1;
  min-height: 0;
}

.flow-node {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 200px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  text-align: center;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.flow-node-kind {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.flow-node-icon {
  flex: 0 0 auto;
}

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

.kind-userInput {
  border-color: #93c5fd;
}
.kind-decision {
  border-color: #fcd34d;
}
.kind-apiCall {
  border-color: #c4b5fd;
}
.kind-llm {
  border-color: #f0abfc;
}
.kind-branch {
  border-color: #fdba74;
}
.kind-subWorkflow {
  border-color: #5eead4;
  background: #f0fdfa;
}
.kind-auto {
  border-color: #a7f3d0;
}
.kind-final {
  border-color: #cbd5e1;
}

/* start / end dots shown around a sub-workflow */
.flow-dot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #111827;
  background: #fff;
}
.flow-dot-start {
  background: #111827;
}
.flow-dot-end {
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px #111827;
}
.flow-dot-label {
  position: absolute;
  left: 28px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.flow-node.drillable {
  cursor: pointer;
}
.flow-node.drillable:hover {
  border-color: #14b8a6;
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.18);
}

.flow-node-drill {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #0d9488;
}

.flow-node.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
  transform: scale(1.03);
}

.edge-changes .react-flow__edge-path {
  stroke: #f59e0b;
}

/* User input form */
.user-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.form-field .req {
  color: #dc2626;
}

.form-field input[type='text'],
.form-field input[type='email'],
.form-field input[type='number'],
.form-field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.form-field input[type='checkbox'] {
  width: 16px;
  height: 16px;
}

.field-error {
  font-size: 12px;
  color: #dc2626;
}

.user-form .primary {
  align-self: flex-start;
}

/* Inbox / email list */
.app-sub {
  font-size: 13px;
  color: #94a3b8;
}

.back-btn {
  background: #1e293b;
  color: #fff;
  border-color: #334155;
}

.inbox {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
}

.inbox-error {
  color: #dc2626;
}

.email-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 820px;
}

.inbox-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 820px;
  margin: 0 auto 12px;
}

.inbox-filters input,
.inbox-filters select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

.inbox-filters .filter-search {
  flex: 1;
  min-width: 180px;
}

.inbox-filters .filter-count {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

.email-item {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.email-item:hover {
  border-color: var(--accent);
}

.email-subject {
  font-weight: 600;
  font-size: 14px;
}

.email-meta {
  font-size: 12px;
  color: var(--muted);
}

.email-row2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}

.email-date {
  font-size: 12px;
  color: var(--muted);
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge-active {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-done {
  background: #dcfce7;
  color: #15803d;
}

.badge-failed {
  background: #fee2e2;
  color: #b91c1c;
}

/* ----- Workflow editor and canvas ----- */
.wf-step-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Editable canvas */
.wfc {
  height: 100%;
  width: 100%;
  position: relative;
}
.wfc .react-flow {
  height: 100%;
}
/* Canvas nodes */
.wfc-node {
  width: 188px;
  background: #fff;
  border: 1px solid var(--border);
  border-top: 3px solid var(--kind-color, var(--border));
  border-radius: 10px;
  padding: 9px 12px 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  transition: box-shadow 0.12s, border-color 0.12s, transform 0.08s;
}
.wfc-node:hover {
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.14);
  transform: translateY(-1px);
}
.wfc-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 10px rgba(37, 99, 235, 0.38);
}
.wfc-node.active {
  border-color: var(--kind-color);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--kind-color) 50%, transparent);
}
.wfc-node.visited {
  background: color-mix(in srgb, var(--kind-color) 7%, #fff);
}
.wfc-node-kind {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 650;
}
.wfc-node-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin-top: 3px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wfc-node-id {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wfc-node-badges {
  position: absolute;
  top: 6px;
  right: 8px;
  display: flex;
  gap: 4px;
}
.wfc-start {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  font-weight: 700;
}
.wfc-warn {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #f59e0b;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wfc .react-flow__handle {
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--kind-color, #94a3b8);
}
.wfc-node:not(.selected):not(.active) .react-flow__handle {
  opacity: 0.55;
}
.wfc-edge-traversed .react-flow__edge-path {
  stroke: var(--accent);
  stroke-width: 2.5;
}
