: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 admin ----- */
.app-admin-link {
  margin-left: auto;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.app-admin-link:hover {
  text-decoration: underline;
}

.admin {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #f8fafc;
}
.admin-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.admin-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 650;
}
.admin-nav {
  display: flex;
  gap: 4px;
  font-size: 13px;
}
.admin-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 7px;
  transition: background 0.12s, color 0.12s;
}
.admin-nav a:hover {
  background: #f1f5f9;
  color: var(--accent);
}
.admin-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.admin-main {
  padding: 20px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.admin-table th {
  background: #f1f5f9;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}

.admin button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.admin button:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #cbd5e1;
}
.admin button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.admin button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.admin button.primary:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
.admin button.danger {
  color: #b91c1c;
  border-color: #fecaca;
}
.admin button.danger:hover:not(:disabled) {
  background: #fef2f2;
}
.admin .error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 10px 12px;
  white-space: pre-wrap;
  font-size: 13px;
}
.admin .muted {
  color: var(--muted);
}

.wf-versions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.wf-version {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.wf-version.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.wf-status {
  font-size: 10px;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
}
.wf-status-active {
  background: #dcfce7;
  color: #166534;
}
.wf-status-draft {
  background: #fef9c3;
  color: #854d0e;
}
.wf-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

.wf-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.wf-preview {
  height: 600px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.wf-readonly {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  overflow: auto;
  max-height: 600px;
}

.wf-editor {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.wf-steps-head,
.wf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.wf-initial {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  gap: 4px;
}
.wf-steps ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wf-steps li {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--kind-color, var(--border));
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.wf-steps li:hover {
  background: #f8fafc;
}
.wf-steps li.active {
  border-color: var(--accent);
  border-left-color: var(--kind-color, var(--accent));
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}
.wf-step-id {
  font-weight: 600;
  font-size: 13px;
}
.wf-step-kind {
  font-size: 11px;
  color: var(--muted);
}
.wf-step-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wf-step-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.wf-step-form input,
.wf-step-form select,
.wf-step-form textarea {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #0f172a;
}
.wf-step-form textarea {
  min-height: 64px;
  font-family: inherit;
}
.wf-fields {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px;
}
.wf-field-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.wf-field-row input,
.wf-field-row select {
  flex: 1;
  min-width: 0;
}
.wf-inline {
  flex-direction: row !important;
  align-items: center;
  gap: 4px !important;
  white-space: nowrap;
}
.route-add {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.route-add input,
.route-add select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.wf-preview .flow {
  height: 100%;
}

/* ----- Workflow editor UX (steps list, context, warnings) ----- */
.wf-parent-note {
  font-size: 13px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 10px;
}
.wf-parent-note a {
  color: var(--accent);
}

.wf-steps li {
  gap: 4px;
}
.wf-step-line {
  display: flex;
  align-items: center;
  gap: 6px;
}
.wf-kind-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #475569;
}
/* tint the badge using the diagram kind colors */
.wf-kind-badge.kind-userInput {
  border-color: #93c5fd;
}
.wf-kind-badge.kind-decision {
  border-color: #fcd34d;
}
.wf-kind-badge.kind-apiCall {
  border-color: #c4b5fd;
}
.wf-kind-badge.kind-llm {
  border-color: #f0abfc;
}
.wf-kind-badge.kind-branch {
  border-color: #fdba74;
}
.wf-kind-badge.kind-auto {
  border-color: #a7f3d0;
}
.wf-kind-badge.kind-subWorkflow {
  border-color: #5eead4;
  background: #f0fdfa;
}
.wf-kind-badge.kind-final {
  border-color: #cbd5e1;
}

.wf-warn-dot {
  margin-left: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #f59e0b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
}
.wf-step-trans {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.wf-chip {
  font-size: 11px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  color: #475569;
  white-space: nowrap;
}
.wf-chip strong {
  color: #0f172a;
}

.wf-help {
  font-size: 12px;
  color: var(--muted);
  margin: -4px 0 4px;
}

.wf-context {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  background: #f8fafc;
}
.wf-context > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}
.wf-context-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.wf-warnings {
  margin: 0;
  padding: 8px 10px 8px 24px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 12px;
  color: #92400e;
}

.wf-transitions {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wf-transitions > legend {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 4px;
}

.wf-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.wf-row-buttons {
  display: inline-flex;
  gap: 6px;
}

.flow-node.selectable {
  cursor: pointer;
}
.flow-node.selectable:hover {
  border-color: var(--accent);
}

/* ===== Modernized workflow admin (icons, modals, templates, drawer) ===== */

.wf-count {
  background: #e2e8f0;
  color: #475569;
  border-radius: 999px;
  font-size: 11px;
  padding: 0 6px;
  margin-left: 2px;
}

/* Steps sidebar */
.wf-steps-head {
  font-weight: 600;
  font-size: 13px;
  color: #334155;
}
.wf-add-btn {
  font-size: 12px !important;
  padding: 4px 8px !important;
}
.wf-kind-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wf-kind-icon.lg {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: color-mix(in srgb, currentColor 12%, #fff);
}

/* Step form header */
.wf-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 32px 8px;
}
.wf-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.wf-form-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wf-form-title code {
  font-size: 15px;
  font-weight: 600;
}
.wf-kind-name {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

/* Kind picker grid */
.wf-modal-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.wf-kind-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.wf-kind-card {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  background: #fff;
  color: #475569 !important;
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.08s;
}
.wf-kind-card:hover {
  border-color: var(--kind-color) !important;
  transform: translateY(-1px);
}
.wf-kind-card svg {
  color: var(--kind-color);
}
.wf-kind-card.active {
  border-color: var(--kind-color) !important;
  background: color-mix(in srgb, var(--kind-color) 10%, #fff);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--kind-color) 28%, transparent);
  color: #0f172a !important;
}

/* Modal */
.wf-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
  animation: wf-fade 0.12s ease;
}
.wf-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  animation: wf-pop 0.14s ease;
}
.wf-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.wf-modal-head h3 {
  margin: 0;
  font-size: 16px;
}
.wf-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.wf-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 14px 14px;
}
.wf-modal-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}
.wf-modal-field input {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #0f172a;
}
.wf-modal-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.wf-field-error {
  color: #b91c1c;
  font-size: 12px;
}

.wf-icon-btn {
  padding: 4px !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--muted) !important;
  border-radius: 6px !important;
}
.wf-icon-btn:hover {
  background: #f1f5f9 !important;
}
.wf-icon-btn.danger {
  color: #b91c1c !important;
}
.wf-icon-btn.danger:hover {
  background: #fef2f2 !important;
}

@keyframes wf-fade {
  from {
    opacity: 0;
  }
}
@keyframes wf-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* Template input with inline {{token}} highlighting */
.wf-template {
  position: relative;
  font-size: 13px;
}
.wf-template-mirror,
.wf-template-input {
  margin: 0;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  letter-spacing: normal;
}
.wf-template-mirror {
  position: absolute;
  inset: 0;
  color: #0f172a;
  pointer-events: none;
  overflow: hidden;
  border-color: transparent;
}
.wf-template-input {
  position: relative;
  display: block;
  width: 100%;
  resize: vertical;
  background: transparent;
  color: transparent;
  caret-color: #0f172a;
  border: 1px solid var(--border);
}
.wf-template-inline .wf-template-input {
  resize: none;
  overflow: hidden;
  white-space: pre;
}
.wf-template-inline .wf-template-mirror {
  white-space: pre;
}
.wf-template-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.wf-template-mirror .tpl-ok {
  background: #dcfce7;
  color: #166534;
  border-radius: 4px;
}
.wf-template-mirror .tpl-bad {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 4px;
}

/* Field editor cards + type-aware controls */
.wf-fields-head {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}
.wf-fields-empty {
  font-size: 12px;
  margin: 4px 0;
}
.wf-field-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fff;
}
.wf-field-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.wf-type-select {
  flex: 0 0 110px !important;
}
.wf-type-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.wf-type-preview {
  width: 130px;
  font-size: 12px !important;
  padding: 4px 8px !important;
  background: #f8fafc;
}

/* Select-field options as chips */
.wf-options {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wf-options-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.wf-option-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-size: 12px;
}
.wf-option-chip button {
  border: none !important;
  background: transparent !important;
  color: #6366f1 !important;
  padding: 0 4px !important;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.wf-options-add {
  display: flex;
  gap: 6px;
}
.wf-options-add input {
  flex: 1;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.wf-case-arrow {
  color: var(--muted);
  flex: 0 0 auto;
}
.wf-kv-eq {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  flex: 0 0 auto;
}
.wf-kv-template {
  flex: 1;
  min-width: 0;
}

/* Version bar + history drawer */
.wf-version-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 13px;
}
.wf-version-current {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wf-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 40;
  animation: wf-fade 0.12s ease;
}
.wf-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 320px;
  max-width: 90vw;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  animation: wf-slide 0.16s ease;
}
@keyframes wf-slide {
  from {
    transform: translateX(100%);
  }
}
.wf-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.wf-drawer-head h3 {
  margin: 0;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wf-drawer-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}
.wf-drawer-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.wf-drawer-list li:hover {
  background: #f8fafc;
}
.wf-drawer-list li.active {
  border-color: var(--accent);
  background: #eff6ff;
}
.wf-drawer-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wf-version-num {
  font-weight: 600;
  font-size: 13px;
}
.wf-drawer-activate {
  font-size: 12px !important;
  padding: 3px 8px !important;
}

/* ===================================================================== */
/* Graph-centric workflow studio (canvas authoring, timeline, simulator)  */
/* ===================================================================== */

.wf-detail-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.wf-workflow-id {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.wf-readonly-note {
  font-size: 13px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

/* Build / Test segmented toggle */
.wf-mode-toggle {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.wf-mode-toggle button {
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  padding: 5px 12px !important;
  border-radius: 7px !important;
  font-weight: 550;
}
.wf-mode-toggle button.active {
  background: #fff !important;
  color: var(--accent) !important;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

/* Studio: hero canvas + inspector/conversation panel */
.wf-studio {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  align-items: stretch;
  height: calc(100vh - 230px);
  min-height: 520px;
}
.wf-canvas-pane {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}
.wf-canvas-pane.standalone {
  height: calc(100vh - 230px);
  min-height: 520px;
}

/* Editable canvas */
.wfc {
  height: 100%;
  width: 100%;
  position: relative;
}
.wfc .react-flow {
  height: 100%;
}
.wfc-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
}
.wfc-hint {
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 8px;
  border-radius: 6px;
  backdrop-filter: blur(2px);
}
.wfc-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
}

/* 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 3px rgba(37, 99, 235, 0.18);
}
.wfc-node.active {
  border-color: var(--kind-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kind-color) 35%, 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;
}
.wfc-node-id {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.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: 8px;
  height: 8px;
  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;
}

/* Inspector panel (right of canvas) */
.wf-inspector {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  overflow: auto;
}
.wf-inspector-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 24px 4px;
}
.wf-form-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wf-connect-choices {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Version timeline */
.wf-timeline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.wf-timeline-track {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 2px;
}
.wf-vchip {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 5px 10px !important;
  border-radius: 999px !important;
  background: #f8fafc !important;
  border: 1px solid var(--border) !important;
  position: relative;
  white-space: nowrap;
}
.wf-vchip:not(:first-child)::before {
  content: '';
  position: absolute;
  left: -8px;
  width: 8px;
  height: 2px;
  background: var(--border);
}
.wf-vchip-num {
  font-weight: 700;
  font-size: 13px;
}
.wf-vchip-status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.wf-vchip.status-active {
  border-color: #86efac !important;
  background: #f0fdf4 !important;
}
.wf-vchip.status-active .wf-vchip-status {
  color: #166534;
}
.wf-vchip.status-draft {
  border-color: #fde68a !important;
  background: #fffbeb !important;
}
.wf-vchip.status-draft .wf-vchip-status {
  color: #854d0e;
}
.wf-vchip.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.wf-timeline-actions {
  display: inline-flex;
  gap: 8px;
}

/* Version compare */
.wf-compare {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
.wf-compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.wf-compare-pick {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.wf-compare-pick select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
}
.wf-compare-body {
  padding: 12px 14px;
}
.wf-compare-initial {
  font-size: 13px;
  margin: 0 0 10px;
}
.wf-compare-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wf-compare-list > li {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.wf-diff-added {
  border-left-color: #22c55e;
  background: #f0fdf4;
}
.wf-diff-removed {
  border-left-color: #ef4444;
  background: #fef2f2;
}
.wf-diff-changed {
  border-left-color: #f59e0b;
  background: #fffbeb;
}
.wf-diff-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wf-diff-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
}
.wf-diff-status {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin-left: auto;
}
.wf-diff-changes {
  margin: 6px 0 0;
  padding-left: 26px;
  font-size: 12px;
  color: #475569;
}
.wf-diff-changes li {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Simulator (Test mode) */
.wf-sim-setup {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}
.wf-sim-card {
  width: 100%;
  max-width: 560px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wf-sim-card h3 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
}
.wf-sim-body {
  font-family: inherit;
  font-size: 13px;
  min-height: 96px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}
.wf-sim-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.wf-sim-run {
  align-self: flex-start;
  margin-top: 4px;
}
.wf-sim-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.wf-sim-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.wf-sim-status {
  font-size: 12px;
  font-weight: 650;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent);
}
.wf-sim-status[data-status='done'] {
  background: #f0fdf4;
  color: #166534;
}
.wf-sim-status[data-status='failed'] {
  background: #fef2f2;
  color: #b91c1c;
}
.wf-sim-log {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wf-sim-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 88%;
}
.wf-sim-msg.author-user {
  align-self: flex-end;
  align-items: flex-end;
}
.wf-sim-author {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.wf-sim-text {
  font-size: 13px;
  padding: 8px 11px;
  border-radius: 12px;
  background: #f1f5f9;
  color: #0f172a;
  white-space: pre-wrap;
}
.wf-sim-msg.author-user .wf-sim-text {
  background: var(--accent);
  color: #fff;
}
.wf-sim-msg.author-agent .wf-sim-text {
  background: #ecfdf5;
}
.wf-sim-msg.author-system .wf-sim-text {
  background: transparent;
  color: var(--muted);
  font-style: italic;
  padding: 2px 0;
}
.wf-sim-input {
  border-top: 1px solid var(--border);
  padding: 14px;
  background: #f8fafc;
}
.wf-sim-prompt {
  font-size: 13px;
  margin: 0 0 10px;
}
.wf-sim-ended {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
}
.wf-sim-ended.ok {
  color: #166534;
}
.wf-sim-ended.bad {
  color: #b91c1c;
}

/* Workflow list as cards */
.wf-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.wf-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  transition: box-shadow 0.12s, border-color 0.12s, transform 0.08s;
}
.wf-card:hover {
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.1);
  border-color: #cbd5e1;
  transform: translateY(-2px);
}
.wf-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.wf-card-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #eff6ff;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.wf-card-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.wf-card-title strong {
  font-size: 15px;
}
.wf-card-title .muted {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.wf-card-go {
  margin-left: auto;
  color: var(--muted);
  flex: 0 0 auto;
}
.wf-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 12px;
}
.wf-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.wf-card-badge.live {
  background: #f0fdf4;
  color: #166534;
}
.wf-card-badge.draft {
  background: #f1f5f9;
  color: #64748b;
}
.wf-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 56px 16px;
  color: var(--muted);
}
.wf-list-empty h2 {
  margin: 4px 0 0;
  font-size: 18px;
  color: #0f172a;
}

/* ===== Sub-workflow inputs + tabs ===== */

.wf-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.wf-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  padding: 8px 12px !important;
  border-radius: 0 !important;
  border-bottom: 2px solid transparent !important;
  font-weight: 550;
  margin-bottom: -1px;
}
.wf-tabs button.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}
.wf-tab-count {
  font-size: 11px;
  background: #e2e8f0;
  color: #475569;
  border-radius: 999px;
  padding: 0 6px;
}
.wf-tabs button.active .wf-tab-count {
  background: #dbeafe;
  color: var(--accent);
}

.wf-type-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.wf-type-choice button {
  display: flex !important;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 12px !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  background: #fff !important;
  cursor: pointer;
  text-align: left;
}
.wf-type-choice button span {
  font-weight: 650;
  font-size: 13px;
  color: #0f172a;
}
.wf-type-choice button small {
  font-size: 11px;
  color: var(--muted);
}
.wf-type-choice button.active {
  border-color: var(--accent) !important;
  background: #eff6ff !important;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.wf-type-choice button svg {
  color: var(--accent);
}

.wf-map-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  align-items: start;
  padding: 6px 0;
  border-top: 1px dashed var(--border);
}
.wf-map-row:first-of-type {
  border-top: none;
}
.wf-map-key {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 4px;
}
.wf-map-key code {
  font-size: 12px;
  font-weight: 600;
}
.wf-map-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.wf-map-value {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.wf-map-warn {
  font-size: 11px;
  color: #92400e;
}

.wf-map-value > input {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  box-sizing: border-box;
}
