/**
 * Sales Flow Editor UI modernization — Phase 9B
 * Scoped under .sales-flow-editor.sales-flow-editor-modern
 * Presentation only. No !important.
 * Does NOT alter publish/runtime/version-pinning semantics.
 * Does NOT restyle Phase 9A AI Training tabs/content (only flow panel chrome).
 */

.sales-flow-editor.sales-flow-editor-modern {
  --sfe-gap: 12px;
  --sfe-radius: 8px;
  --sfe-control: 36px;
  --sfe-touch: 44px;
  --sfe-ink: var(--ds-color-ink, var(--ink, #24262d));
  --sfe-muted: var(--ds-color-muted, var(--muted, #6b7280));
  --sfe-line: var(--ds-color-line, var(--line, #e5e7eb));
  --sfe-surface: #fff;
  --sfe-surface-quiet: #f8f9fa;
  --sfe-accent: var(--ds-color-accent, var(--accent, #0f766e));
  --sfe-publish: #0f766e;
  --sfe-danger: #b91c1c;
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sfe-gap);
  padding: 14px 16px;
  border: 1px solid var(--sfe-line);
  border-radius: var(--sfe-radius);
  background: var(--sfe-surface);
  box-shadow: none;
  box-sizing: border-box;
}

.sales-flow-editor.sales-flow-editor-modern *,
.sales-flow-editor.sales-flow-editor-modern *::before,
.sales-flow-editor.sales-flow-editor-modern *::after {
  box-sizing: border-box;
}

/* —— Header —— */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  margin: 0;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__copy {
  min-width: 0;
  flex: 1 1 220px;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__eyebrow {
  margin: 0 0 2px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sfe-muted);
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--sfe-ink);
  line-height: 1.25;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-subtitle {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: var(--sfe-muted);
  max-width: 40rem;
  overflow-wrap: break-word;
  word-break: normal;
}

/* —— Toolbar: tools vs Save / Publish —— */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 10px;
  margin: 0;
  min-width: 0;
  max-width: 100%;
}

/* Desktop visual order: tools then primary (DOM has primary first for mobile priority) */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__tools {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__primary {
  order: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding-left: 8px;
  border-left: 1px solid var(--sfe-line);
}

/* Desktop: wrappers dissolve so buttons stay inline (approved chrome) */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__secondary,
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__zoom,
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__danger {
  display: contents;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .ghost-button,
.sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .primary-button {
  min-height: var(--sfe-control);
  min-width: 36px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 550;
}

.sales-flow-editor.sales-flow-editor-modern .flow-action-save {
  border: 1px solid var(--sfe-line);
  background: var(--sfe-surface-quiet);
  color: var(--sfe-ink);
}

.sales-flow-editor.sales-flow-editor-modern .flow-action-publish {
  border: 1px solid var(--sfe-publish);
  background: var(--sfe-publish);
  color: #fff;
  font-weight: 650;
  box-shadow: none;
}

.sales-flow-editor.sales-flow-editor-modern .flow-action-danger {
  color: var(--sfe-danger);
}

/* —— Meta / version / validation —— */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  min-width: 0;
}

.sales-flow-editor.sales-flow-editor-modern .flow-version-bar {
  padding: 10px 12px;
  border: 1px solid var(--sfe-line);
  border-radius: var(--sfe-radius);
  background: var(--sfe-surface-quiet);
  font-size: 0.8125rem;
  overflow-wrap: break-word;
  word-break: normal;
}

.sales-flow-editor.sales-flow-editor-modern .flow-validation {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* —— Workspace —— */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-layout {
  min-width: 0;
  max-width: 100%;
  min-height: 0;
}

.sales-flow-editor.sales-flow-editor-modern .flow-editor-layout--full .flow-canvas-wrap {
  min-height: 520px;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--sfe-line);
  border-radius: var(--sfe-radius);
}

.sales-flow-editor.sales-flow-editor-modern .flow-canvas {
  min-width: 0;
  max-width: 100%;
}

/* Desktop graph nodes — readable text, no char-by-char breaks */
.sales-flow-editor.sales-flow-editor-modern .flow-node {
  border-radius: var(--sfe-radius);
  box-shadow: none;
  border: 1px solid var(--sfe-line);
  background: var(--sfe-surface);
}

.sales-flow-editor.sales-flow-editor-modern .flow-node.is-selected {
  border-color: var(--sfe-accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.18);
}

.sales-flow-editor.sales-flow-editor-modern .flow-node header strong,
.sales-flow-editor.sales-flow-editor-modern .flow-node__preview {
  overflow-wrap: break-word;
  word-break: normal;
}

/* Mobile step list — same editorState; hidden on desktop */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-mobile-steps {
  display: none;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--sfe-line);
  border-radius: var(--sfe-radius);
  background: var(--sfe-surface-quiet);
  text-align: left;
  width: 100%;
  cursor: pointer;
  min-height: var(--sfe-touch);
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step.is-selected {
  border-color: var(--sfe-accent);
  background: #ecfdf5;
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--sfe-ink);
  overflow-wrap: break-word;
  word-break: normal;
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step__type {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--sfe-accent);
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step__preview {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--sfe-muted);
  line-height: 1.45;
  overflow-wrap: break-word;
  word-break: normal;
}

.sales-flow-editor.sales-flow-editor-modern .flow-mobile-step__badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #ecfdf5;
  color: #047857;
}

/* —— Inspector drawer —— */
.sales-flow-editor.sales-flow-editor-modern .flow-editor-drawer__panel {
  border-left: 1px solid var(--sfe-line);
  background: var(--sfe-surface);
}

.sales-flow-editor.sales-flow-editor-modern #salesFlowInspector {
  overflow-wrap: break-word;
  word-break: normal;
}

.sales-flow-editor.sales-flow-editor-modern #salesFlowInspector textarea,
.sales-flow-editor.sales-flow-editor-modern #salesFlowInspector .input-text,
.sales-flow-editor.sales-flow-editor-modern #salesFlowInspector .input-textarea {
  max-width: 100%;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

/* —— Responsive —— */
@media (max-width: 1280px) {
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .ghost-button {
    padding: 0 8px;
    font-size: 0.75rem;
  }
}

@media (max-width: 1024px) {
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar {
    gap: 8px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__primary {
    border-left: 0;
    padding-left: 0;
    justify-content: flex-end;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .ghost-button,
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .primary-button {
    padding: 0 8px;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-layout--full .flow-canvas-wrap {
    min-height: 420px;
  }
}

@media (max-width: 768px) {
  .sales-flow-editor.sales-flow-editor-modern {
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    order: 1;
  }

  /* Kill desktop flex-basis (220px) that reserved empty vertical space in column layout */
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__copy {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__eyebrow {
    font-size: 0.6875rem;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__title {
    font-size: 1.05rem;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-subtitle {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.8125rem;
    margin-top: 2px;
  }

  /* health/version meta immediately after actions, before step cards */
  .sales-flow-editor.sales-flow-editor-modern [data-flow-section="meta"] {
    order: 2;
  }

  .sales-flow-editor.sales-flow-editor-modern [data-flow-section="workspace"] {
    order: 3;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-layout {
    min-height: 0;
    height: auto;
  }

  /* Compact action hierarchy — primary first, then dense secondary grid */
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    position: static;
    padding-bottom: 0;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__primary {
    order: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    border-left: 0;
    padding-left: 0;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__tools {
    order: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__secondary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    width: 100%;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__zoom {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    width: auto;
    max-width: 100%;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__danger {
    display: block;
    width: 100%;
    margin-top: 0;
    padding-top: 6px;
    border-top: 1px solid var(--sfe-line);
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .ghost-button,
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .primary-button {
    min-height: 36px;
    width: 100%;
    justify-content: center;
    white-space: normal;
    line-height: 1.15;
    text-align: center;
    padding: 4px 6px;
    font-size: 0.6875rem;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__zoom .ghost-button {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    min-height: 36px;
    flex: 0 0 40px;
    padding: 0;
    font-size: 1.05rem;
    font-weight: 650;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__danger .flow-action-danger {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(185, 28, 28, 0.35);
    font-weight: 550;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-action-save,
  .sales-flow-editor.sales-flow-editor-modern .flow-action-publish {
    min-height: 40px;
    font-size: 0.8125rem;
  }

  /* Step cards instead of compressed graph — no desktop canvas height reservation */
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-mobile-steps {
    display: flex;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-canvas-wrap,
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-layout--full .flow-canvas-wrap {
    display: none;
    min-height: 0;
    height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-canvas,
  .sales-flow-editor.sales-flow-editor-modern .flow-canvas-viewport,
  .sales-flow-editor.sales-flow-editor-modern .flow-canvas-grid {
    min-height: 0;
    min-width: 0;
    height: 0;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-drawer__panel {
    width: 100%;
    max-width: 100%;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 430px) {
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-subtitle {
    display: none;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__secondary {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__tools {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px;
    align-items: stretch;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__secondary {
    grid-column: 1 / -1;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__zoom {
    align-self: center;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__danger {
    margin: 0;
    padding: 0;
    border-top: 0;
    align-self: stretch;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__danger .flow-action-danger {
    min-height: 36px;
  }
}

@media (max-width: 360px) {
  .sales-flow-editor.sales-flow-editor-modern {
    gap: 6px;
    padding: 8px 10px;
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading {
    gap: 4px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__eyebrow {
    display: none;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-heading__title {
    font-size: 0.95rem;
    line-height: 1.2;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar {
    gap: 4px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-action-save,
  .sales-flow-editor.sales-flow-editor-modern .flow-action-publish {
    min-height: 34px;
    font-size: 0.75rem;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .ghost-button,
  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar .primary-button {
    min-height: 32px;
    font-size: 0.625rem;
    padding: 2px 4px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__zoom .ghost-button {
    width: 34px;
    min-width: 34px;
    max-width: 34px;
    flex-basis: 34px;
    min-height: 32px;
  }

  .sales-flow-editor.sales-flow-editor-modern .flow-editor-toolbar__secondary {
    gap: 3px;
  }
}
