/* Холст «Воркфлоу» — панорама, зум, узлы, связи */

main.content:has(#content-workflow) {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}

main.content:has(#content-workflow) #content-area {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#content-workflow.content-page--fullwidth {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  max-width: 100%;
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 0;
  overflow: hidden;
}

.wf-app {
  --wf-edge: #6c5ce7;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  z-index: 0;
}

.wf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.wf-toolbar__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.wf-toolbar__group--end {
  margin-left: auto;
  align-items: center;
  gap: var(--space-2);
}

.wf-toolbar__zoom {
  flex-wrap: nowrap;
}

.wf-boards-dropdown {
  position: relative;
}

.wf-boards-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  max-width: min(320px, 92vw);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 50;
}

.wf-boards-panel.hidden {
  display: none;
}

.wf-boards-list {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}

.wf-boards-list li {
  margin: 0;
}

.wf-boards-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.wf-boards-item:hover {
  background: rgba(108, 92, 231, 0.12);
}

.wf-boards-item--active {
  font-weight: 600;
  background: rgba(108, 92, 231, 0.18);
}

.wf-boards-new {
  width: 100%;
}

.wf-tb {
  min-width: 2.25rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.wf-zoom-pct-btn {
  min-width: 3.25rem;
  font-variant-numeric: tabular-nums;
}

.wf-icon-btn {
  min-width: 2.25rem;
  padding: 0.35rem 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.wf-icon-btn svg {
  display: block;
  flex-shrink: 0;
}

.wf-hint {
  display: none;
}

.wf-viewport {
  --wf-tx: 0px;
  --wf-ty: 0px;
  --wf-zoom: 1;
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
  cursor: grab;
  background: #12121a;
  outline: none;
}

/* Бесконечная сетка: слой в экране, смещение = пан/зум, как у мира. */
.wf-grid-ambient {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #12121a;
  background-image: linear-gradient(rgba(108, 92, 231, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 92, 231, 0.06) 1px, transparent 1px);
  background-size: calc(32px * var(--wf-zoom, 1)) calc(32px * var(--wf-zoom, 1));
  background-position: var(--wf-tx) var(--wf-ty);
}

.wf-marquee {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 20;
  pointer-events: none;
  box-sizing: border-box;
  border: 1px solid var(--accent, #6c5ce7);
  background: rgba(108, 92, 231, 0.12);
  border-radius: 2px;
}

.wf-edge-del {
  position: absolute;
  z-index: 26;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.wf-project-admin {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.wf-app--readonly .wf-node {
  opacity: 0.95;
}

.wf-edge-del:hover {
  color: var(--red, #f44336);
  border-color: var(--red, #f44336);
  background: rgba(244, 67, 54, 0.12);
}

.wf-viewport.wf-pan--active {
  cursor: grabbing;
}

.wf-world {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  box-sizing: border-box;
  z-index: 1;
}

.wf-surface {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  background: transparent;
}

.wf-edges,
.wf-align-guides {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
  display: block;
}

.wf-align-guides {
  z-index: 2;
}

.wf-edge--draft {
  opacity: 0.85;
  stroke: var(--accent, #6c5ce7);
  marker-end: none;
}

.wf-nodes {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  pointer-events: none;
}

.wf-nodes > * {
  pointer-events: auto;
}

.wf-node {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 0;
  max-width: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  user-select: none;
  box-sizing: border-box;
  overflow: visible;
}

.wf-node--sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-alpha-15), 0 4px 20px rgba(0, 0, 0, 0.3);
}

.wf-node--snap-hl {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35), 0 4px 20px rgba(0, 0, 0, 0.3);
}

.wf-node--text {
  padding: 0;
  min-height: 0;
  min-width: 0;
}

.wf-node--text .wf-node__close--float {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 8;
  flex-shrink: 0;
  border: none;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  font-size: 1.1rem;
}

.wf-node--text .wf-node__close--float:hover {
  color: var(--red);
  background: rgba(244, 67, 54, 0.15);
}

.wf-node__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 8px;
  background: var(--surface-header);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
}

.wf-node__head span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wf-node__close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  font-size: 1.1rem;
}

.wf-node__close:hover {
  color: var(--red);
  background: rgba(244, 67, 54, 0.12);
}

.wf-node__body {
  padding: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.wf-node__body:has(.wf-node__img),
.wf-node__body:has(.wf-node__vid) {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
}


.wf-node__vid {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #0a0a0f;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin: 0;
  object-fit: contain;
}

.wf-node__ports {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.wf-port {
  position: absolute;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--accent, #6c5ce7);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 6;
}

.wf-node:hover .wf-port,
.wf-node--sel .wf-port {
  opacity: 0.95;
  transform-origin: center;
}

.wf-port:hover {
  transform: scale(1.12);
  opacity: 1;
}

.wf-port--n {
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
}
.wf-port--n:hover {
  transform: translateX(-50%) scale(1.15);
}
.wf-port--s {
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
}
.wf-port--s:hover {
  transform: translateX(-50%) scale(1.15);
}
.wf-port--e {
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
}
.wf-port--e:hover {
  transform: translateY(-50%) scale(1.15);
}
.wf-port--w {
  left: -11px;
  top: 50%;
  transform: translateY(-50%);
}
.wf-port--w:hover {
  transform: translateY(-50%) scale(1.15);
}

.wf-node__resize {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.wf-rz {
  position: absolute;
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--accent, #6c5ce7);
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.wf-node--sel .wf-rz {
  opacity: 1;
}

.wf-rz--nw,
.wf-rz--se {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  cursor: nwse-resize;
}
.wf-rz--ne,
.wf-rz--sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  cursor: nesw-resize;
}
.wf-rz--n,
.wf-rz--s {
  height: 8px;
  left: 12px;
  right: 12px;
  border-radius: 2px;
  cursor: ns-resize;
}
.wf-rz--e,
.wf-rz--w {
  width: 8px;
  top: 12px;
  bottom: 12px;
  border-radius: 2px;
  cursor: ew-resize;
}

.wf-rz--nw {
  top: -5px;
  left: -5px;
}
.wf-rz--n {
  top: -5px;
}
.wf-rz--ne {
  top: -5px;
  right: -5px;
}
.wf-rz--e {
  right: -5px;
}
.wf-rz--se {
  bottom: -5px;
  right: -5px;
}
.wf-rz--s {
  bottom: -5px;
}
.wf-rz--sw {
  bottom: -5px;
  left: -5px;
}
.wf-rz--w {
  left: -5px;
}

.wf-node__body--text {
  padding: 0;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
}

.wf-node__img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background: transparent;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin: 0;
}

.wf-node__file-fallback {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}

.wf-node__file-fallback kbd {
  font-size: 0.7rem;
  color: var(--text);
}

.wf-node__text {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  box-sizing: border-box;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  resize: none;
  outline: none;
  flex: 1 1 auto;
  overflow: auto;
  cursor: text;
}

.wf-node__text::placeholder {
  color: var(--text-muted);
}

.wf-dlg__label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

.wf-dlg-np-name {
  width: 100%;
  box-sizing: border-box;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.wf-dlg-np-admin-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.4rem 0;
  line-height: 1.35;
}

.wf-dlg-np-users {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.5rem;
  margin: 0;
}

.wf-dlg-np-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.3rem 0;
  font-size: 0.85rem;
  line-height: 1.3;
  cursor: pointer;
}

.wf-dlg-np-row input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.wf-dlg-np-placeholder {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.25rem 0;
}

.wf-node--editing {
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.35);
}

/* Диалог связей */
.wf-dialog {
  max-width: min(440px, 100vw);
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

.wf-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.wf-dlg__title {
  margin: 0;
  padding: 16px 18px 8px;
  font-size: 1rem;
  font-weight: 600;
}

.wf-dlg__body {
  padding: 0 18px 12px;
  max-height: 50vh;
  overflow: auto;
  font-size: 0.8125rem;
}

.wf-dlg__body p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.wf-dlg__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.wf-dlg__row:last-child {
  border-bottom: none;
}

.wf-dlg__actions {
  padding: 12px 18px 16px;
  display: flex;
  justify-content: flex-end;
}

.wf-dlg__del {
  font-size: 0.75rem;
}

@media (max-width: 600px) {
  .wf-toolbar__group--end {
    width: 100%;
    margin-left: 0;
  }
  .wf-hint {
    max-width: none;
  }
}

/* Холст в общей сетке #screen-app рисуется после сайдбара; при переполнении поднимаем меню выше. */
#screen-app:has(#content-workflow) #sidebar-main {
  position: relative;
  z-index: 2;
}
#screen-app:has(#content-workflow) main.content {
  position: relative;
  z-index: 1;
}

/* Контекстное меню и панель формата текста (фикс. в body) */
.wf-cmenu {
  position: fixed;
  z-index: 500;
  min-width: 12rem;
  padding: 4px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.wf-cmenu__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
}

.wf-cmenu__item:hover {
  background: rgba(108, 92, 231, 0.15);
}

.wf-text-format {
  position: fixed;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  font-size: 0.8rem;
  max-width: 96vw;
}

.wf-text-format__label {
  color: var(--text-muted);
  white-space: nowrap;
}

.wf-text-format .wf-tf-size {
  min-width: 4.5rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.35rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.wf-text-format input[type="color"] {
  width: 2rem;
  height: 1.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--surface);
  vertical-align: middle;
}
