/* Editor flusso automazioni — mockup Flusso Automazioni.html */

body.automation-flow-open {
  overflow: hidden !important;
}

#automation-flow-editor.mt-auto-flow-editor.nsm-wf-editor-active {
  display: flex !important;
  flex-direction: column;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: var(--mt-bg) !important;
  box-shadow: none !important;
  position: fixed !important;
  inset: 0 !important;
  z-index: 12000 !important;
  max-height: 100vh !important;
}

/* Topbar */
.mt-auto-flow-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--mt-glass-bg-strong);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border-bottom: 1px solid var(--mt-divider);
  flex-shrink: 0;
  z-index: 50;
  margin: 0 !important;
}

.mt-auto-flow-topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.mt-auto-flow-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--mt-text-secondary);
  background: rgba(0, 0, 0, 0.04);
  border: none;
  padding: 9px 14px 9px 10px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

.mt-auto-flow-back:hover { background: rgba(0, 0, 0, 0.07); }

#automation-flow-name.mt-auto-flow-name {
  font-size: 16px;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--mt-text-primary);
  max-width: 340px;
  width: 100%;
  flex: 1;
  min-width: 120px;
  font-family: inherit;
  box-sizing: border-box;
}

#automation-flow-name.mt-auto-flow-name:hover,
#automation-flow-name.mt-auto-flow-name:focus {
  border-color: var(--mt-divider);
  background: rgba(255, 255, 255, 0.6);
  outline: none;
}

.mt-auto-flow-edit-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(124, 92, 246, 0.1);
  color: var(--mt-purple-deep);
  flex-shrink: 0;
}

.mt-auto-flow-topbar-right {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.mt-auto-flow-btn {
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.mt-auto-flow-btn--outline {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--mt-divider);
  color: var(--mt-text-primary);
}

.mt-auto-flow-btn--primary {
  background: linear-gradient(135deg, var(--mt-purple), var(--mt-purple-deep));
  color: #fff;
  box-shadow: 0 8px 20px rgba(124, 92, 246, 0.3);
}

.mt-auto-flow-close-legacy { display: none !important; }

/* Workspace */
#automation-flow-editor.nsm-wf-editor-active #automation-flow-workspace {
  flex: 1 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  gap: 0 !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-main {
  flex: 1 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  gap: 0 !important;
}

/* Briefing / template strip */
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel {
  flex-shrink: 0;
  border-bottom: 1px solid var(--mt-divider) !important;
  background: rgba(255, 255, 255, 0.45) !important;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  margin: 0 !important;
  border-radius: 0 !important;
  border-left: none !important;
  border-right: none !important;
  border-top: none !important;
  box-shadow: none !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-briefing-sticky-zone {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  gap: 0 !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-briefing-toggle-bar {
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  color: var(--mt-text-secondary) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  padding: 12px 22px !important;
  margin: 0 !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-briefing-toggle-bar:hover {
  background: rgba(124, 92, 246, 0.04) !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel:not(.nsm-wf-model-expanded) .nsm-wf-briefing-scroll-body,
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel:not(.nsm-wf-model-expanded) .nsm-wf-briefing-banner__head,
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel:not(.nsm-wf-model-expanded) .nsm-wf-model-toolbar {
  display: none !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-briefing-toggle-bar__hint {
  color: var(--mt-text-tertiary) !important;
  font-size: 11px !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-briefing-banner__badge {
  background: rgba(124, 92, 246, 0.1) !important;
  color: var(--mt-purple-deep) !important;
  border: none !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel input,
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel select,
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel textarea {
  border: 1px solid var(--mt-divider) !important;
  background: rgba(255, 255, 255, 0.6) !important;
  color: var(--mt-text-primary) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel .nsm-wf-model-btn-save,
#automation-flow-editor.nsm-wf-editor-active #automation-flow-briefing-panel #wf-generate-all-btn {
  background: linear-gradient(135deg, var(--mt-purple), var(--mt-purple-deep)) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 10px !important;
}

/* Body: canvas + sidepanel */
#automation-flow-editor.nsm-wf-editor-active #automation-flow-layout {
  flex: 1 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: row !important;
  overflow: hidden !important;
  gap: 0 !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-canvas-column {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#automation-flow-editor.nsm-wf-editor-active .mt-auto-canvas-toolbar {
  display: none !important;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-canvas-wrap {
  flex: 1;
  min-height: 0 !important;
  max-height: none !important;
  border: none !important;
  border-radius: 0 !important;
  background-color: var(--mt-bg) !important;
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.08) 1px, transparent 1px) !important;
  background-size: 22px 22px !important;
  overflow: auto !important;
  position: relative;
  cursor: grab;
  overscroll-behavior: contain;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-zoom-root {
  position: relative;
  transform-origin: 0 0;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-svg {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 1;
}

#automation-flow-editor.nsm-wf-editor-active #automation-flow-sidepanel {
  width: 300px !important;
  max-width: 300px !important;
  min-width: 300px !important;
  flex-shrink: 0;
  border: none !important;
  border-left: 1px solid var(--mt-divider) !important;
  border-radius: 0 !important;
  background: rgba(255, 255, 255, 0.5) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  padding: 0 !important;
  overflow-y: auto !important;
  align-self: stretch !important;
  height: auto !important;
  display: flex;
  flex-direction: column;
}

.mt-auto-side-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mt-text-tertiary);
  margin-bottom: 12px;
  padding: 18px 18px 0;
}

.mt-auto-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 18px 8px;
}

.mt-auto-action-grid button {
  font-size: 11.5px;
  font-weight: 600;
  padding: 10px 6px;
  text-align: center;
  border-radius: 11px;
  background: rgba(124, 92, 246, 0.07);
  color: var(--mt-purple-deep);
  border: 1px solid rgba(124, 92, 246, 0.15);
  cursor: pointer;
  font-family: inherit;
}

.mt-auto-action-grid button:hover { background: rgba(124, 92, 246, 0.13); }

.mt-auto-side-help {
  font-size: 11px;
  color: var(--mt-text-tertiary);
  line-height: 1.5;
  padding: 0 18px 18px;
}

#automation-flow-palette { flex-shrink: 0; }

#automation-flow-node-config {
  flex: 1;
  border-top: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  margin: 0 !important;
  padding: 18px !important;
  overflow-y: auto;
}

.mt-wf-node-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 10px;
}

#automation-flow-node-config-title {
  font-size: 14px !important;
  font-weight: 700 !important;
  color: var(--mt-text-primary) !important;
  margin: 0 !important;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mt-wf-node-config-close {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  color: var(--mt-text-secondary);
  flex-shrink: 0;
  padding: 0;
}

.mt-wf-node-config-close:hover { background: rgba(0, 0, 0, 0.1); }

#automation-flow-node-config-fields label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--mt-text-secondary);
  margin-bottom: 5px;
}

#automation-flow-node-config-fields input,
#automation-flow-node-config-fields select,
#automation-flow-node-config-fields textarea {
  width: 100%;
  border: 1px solid var(--mt-divider) !important;
  background: rgba(255, 255, 255, 0.6) !important;
  border-radius: 10px !important;
  color: var(--mt-text-primary) !important;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 10px;
  box-sizing: border-box;
}

.mt-wf-btn-delete-node {
  width: 100%;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #D9425A;
  background: rgba(217, 66, 90, 0.07);
  border: 1px solid rgba(217, 66, 90, 0.18);
  padding: 9px;
  border-radius: 11px;
  cursor: pointer;
  font-family: inherit;
}

.mt-wf-btn-delete-node:hover { background: rgba(217, 66, 90, 0.13); }

#automation-flow-editor.nsm-wf-editor-active .nsm-wf-editor-footer {
  display: none !important;
}

#automation-flow-editor.nsm-wf-editor-active .wf-edge-remove-btn {
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 4;
}

#automation-flow-editor.nsm-wf-editor-active .wf-edge-remove-btn:hover,
#automation-flow-editor.nsm-wf-editor-active:hover .wf-edge-remove-btn {
  opacity: 1;
}

/* Canvas nodes */
#automation-flow-editor.nsm-wf-editor-active .wf-node-card.mt-wf-node {
  border-radius: 16px !important;
  padding: 0 !important;
  background: var(--mt-glass-bg-strong) !important;
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border: 1.5px solid var(--mt-glass-border) !important;
  box-shadow: var(--mt-glass-shadow) !important;
  cursor: grab;
  user-select: none;
  box-sizing: border-box;
}

#automation-flow-editor.nsm-wf-editor-active .wf-node-card.mt-wf-node:active {
  cursor: grabbing;
}

#automation-flow-editor.nsm-wf-editor-active .wf-node-card.mt-wf-node--trigger {
  background: linear-gradient(150deg, rgba(124, 92, 246, 0.16), rgba(124, 92, 246, 0.05)) !important;
  border-color: rgba(124, 92, 246, 0.3) !important;
}

#automation-flow-editor.nsm-wf-editor-active .wf-node-card.mt-wf-node--selected {
  border-color: var(--mt-purple) !important;
  box-shadow: 0 0 0 3px rgba(124, 92, 246, 0.18), var(--mt-glass-shadow) !important;
}

.mt-wf-node-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px 8px;
}

.mt-wf-node-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(124, 92, 246, 0.12);
  color: var(--mt-purple-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mt-wf-node-type {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--mt-text-primary);
  line-height: 1.25;
}

.mt-wf-node-preview {
  padding: 0 12px 12px;
  font-size: 11px;
  color: var(--mt-text-secondary);
  line-height: 1.4;
  min-height: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mt-wf-port {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--mt-purple);
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 6;
  box-sizing: border-box;
}

.mt-wf-port:hover { background: var(--mt-purple); }

.mt-wf-port--active,
.mt-wf-port.out:active {
  background: var(--mt-purple);
  box-shadow: 0 0 0 4px rgba(124, 92, 246, 0.22);
}

.mt-wf-port.in.mt-wf-port--hover {
  background: var(--mt-purple);
  box-shadow: 0 0 0 4px rgba(124, 92, 246, 0.22);
}

#automation-flow-editor.nsm-wf-editor-active .wf-node-card.mt-wf-node--drop-target {
  border-color: var(--mt-purple) !important;
  box-shadow: 0 0 0 3px rgba(124, 92, 246, 0.22), var(--mt-glass-shadow) !important;
}

body.wf-connect-dragging,
body.wf-connect-dragging #automation-flow-canvas-wrap {
  cursor: crosshair !important;
}

body.wf-connect-dragging .wf-node-card {
  cursor: crosshair;
}

body.wf-connect-dragging .mt-wf-port.out {
  cursor: crosshair;
}

#wf-connect-preview {
  pointer-events: none;
}

.mt-wf-port.out { right: -7px; }
.mt-wf-port.in { left: -7px; }

body.automation-editor-only #automation-flow-editor.mt-auto-flow-editor {
  inset: 0 !important;
  max-height: none !important;
  border-radius: 0 !important;
}

@media (max-width: 900px) {
  .mt-auto-flow-back span.mt-auto-flow-back-label { display: none; }

  #automation-flow-editor.nsm-wf-editor-active #automation-flow-layout {
    flex-direction: column !important;
  }

  #automation-flow-editor.nsm-wf-editor-active #automation-flow-sidepanel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border-left: none !important;
    border-top: 1px solid var(--mt-divider) !important;
    max-height: 42vh;
  }

  #automation-flow-editor.nsm-wf-editor-active .nsm-wf-editor-footer {
    display: flex !important;
    padding: 10px 14px !important;
    border-top: 1px solid var(--mt-divider);
    background: var(--mt-glass-bg-strong);
  }

  .mt-auto-flow-topbar-right { display: none; }
}
