/* ==========================================================================
   Workflow Designer - Modern Node Graph Editor
   ========================================================================== */

/* --------------------------------------------------------------------------
   Designer Container - Full height, no page overflow
   -------------------------------------------------------------------------- */
.workflow-designer-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Canvas Container
   -------------------------------------------------------------------------- */
.workflow-canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0; /* Important: allows flex child to shrink */
    overflow: hidden;
    border-radius: var(--mud-default-borderradius);
    border: 1px solid var(--mud-palette-lines-default);
    background-color: var(--mud-palette-surface);
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
}

.workflow-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
    transform-origin: 0 0;
}

.workflow-canvas.dragging {
    cursor: grabbing;
}

.workflow-canvas-container.workflow-pan-active,
.workflow-canvas-container.workflow-pan-active * {
    cursor: grabbing !important;
}

.workflow-canvas.connecting {
    cursor: crosshair;
}

/* --------------------------------------------------------------------------
   Node Search
   -------------------------------------------------------------------------- */
.workflow-node-search {
    position: absolute;
    top: 16px;
    left: 16px;
    width: min(280px, calc(100% - 32px));
    z-index: 110;
}

.workflow-node-search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 8px 0 10px;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    box-shadow: var(--mud-elevation-2);
}

.workflow-node-search:focus-within .workflow-node-search-input-wrap {
    border-color: var(--mud-palette-primary);
}

.workflow-node-search-input {
    min-width: 0;
    flex: 1;
    border: 0;
    outline: 0;
    color: var(--mud-palette-text-primary);
    background: transparent;
    font: inherit;
    font-size: 13px;
    letter-spacing: 0;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.workflow-node-search-input::placeholder {
    color: var(--mud-palette-text-secondary);
}

.workflow-node-search-clear {
    display: grid;
    width: 24px;
    height: 24px;
    padding: 0;
    place-items: center;
    color: var(--mud-palette-text-secondary);
    background: transparent;
    border: 0;
    border-radius: var(--mud-default-borderradius);
    cursor: pointer;
}

.workflow-node-search-clear:hover {
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-action-default-hover);
}

.workflow-node-search-results {
    max-height: 320px;
    margin-top: 4px;
    padding: 4px;
    overflow-y: auto;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    box-shadow: var(--mud-elevation-4);
}

.workflow-node-search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 6px 8px;
    color: var(--mud-palette-text-primary);
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: var(--mud-default-borderradius);
    cursor: pointer;
}

.workflow-node-search-result:hover,
.workflow-node-search-result.active {
    background: var(--mud-palette-action-default-hover);
}

.workflow-node-search-result-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
}

.workflow-node-search-result-name,
.workflow-node-search-result-detail {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workflow-node-search-result-name {
    font-size: 13px;
    font-weight: 600;
}

.workflow-node-search-result-detail,
.workflow-node-search-empty {
    color: var(--mud-palette-text-secondary);
    font-size: 11px;
}

.workflow-node-search-empty {
    padding: 10px;
    text-align: center;
}

/* Grid Background Pattern - Dynamic infinite tiling via background-position */
.workflow-canvas-grid {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: radial-gradient(var(--mud-palette-lines-default) 1.5px, transparent 1px);
    background-size: 20px 20px;
    background-repeat: repeat;
    opacity: 0.4;
}

.workflow-canvas-grid-major {
    background-image: radial-gradient(var(--mud-palette-lines-default) 2px, transparent 1px);
    background-size: 100px 100px;
    opacity: 0.6;
}

/* --------------------------------------------------------------------------
   SVG Edge Layer
   -------------------------------------------------------------------------- */
.workflow-edges-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

/* Edge Styles */
.workflow-edge {
    fill: none;
    stroke: var(--mud-palette-text-secondary);
    stroke-width: 2;
    transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.workflow-edge:hover {
    stroke: var(--mud-palette-primary);
    stroke-width: 4;
}

.workflow-edge.selected {
    stroke: var(--mud-palette-primary);
    stroke-width: 4;
    filter: drop-shadow(0 0 2px var(--mud-palette-primary));
}

.workflow-edge.conditional {
    stroke: var(--mud-palette-warning);
}

.workflow-edge.draft {
    stroke: var(--mud-palette-primary);
    stroke-dasharray: 8 4;
    stroke-width: 3;
    opacity: 0.8;
}

.workflow-edge.invalid {
    stroke: var(--mud-palette-error);
}

/* Edge Arrow Markers */
.workflow-edge-arrow {
    fill: var(--mud-palette-text-secondary);
}

.workflow-edge-arrow.primary {
    fill: var(--mud-palette-primary);
}

.workflow-edge-arrow.warning {
    fill: var(--mud-palette-warning);
}

.workflow-edge-arrow.error {
    fill: var(--mud-palette-error);
}

/* Edge Labels */
.workflow-edge-label {
    font-size: 11px;
    font-family: var(--mud-typography-default-family);
    fill: var(--mud-palette-text-secondary);
    pointer-events: auto;
    cursor: pointer;
}

.workflow-edge-label-bg {
    fill: var(--mud-palette-surface);
    rx: 4;
    ry: 4;
}

.workflow-edge-label:hover {
    fill: var(--mud-palette-primary);
}

/* --------------------------------------------------------------------------
   Node Base Styles
   -------------------------------------------------------------------------- */
.workflow-node {
    position: absolute;
    width: 220px !important;
    min-width: 220px !important;
    max-width: 220px !important;
    /* height: 80px !important; REMOVED to allow auto-height */
    min-height: 80px !important;
    /* max-height: 80px !important; REMOVED to allow auto-height */
    overflow: visible; /* Changed from hidden to visible */
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition: box-shadow 0.15s ease, transform 0.1s ease;
    z-index: 10;
}

.workflow-node:hover {
    z-index: 10;
}

.workflow-node.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow: var(--mud-elevation-8);
}

.workflow-node.selected {
    z-index: 50;
}

.workflow-node.selected .workflow-node-inner {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.workflow-node-inner {
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-inputs);
    transition: all 0.2s ease;
}

/* Node Header */
.workflow-node.decision-node .workflow-node-inner {
    min-height: inherit;
}

.workflow-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--mud-palette-table-lines);
    background-color: var(--mud-palette-background-grey);
}

.workflow-node-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 14px;
}

.workflow-node-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workflow-node-id {
    font-size: 10px;
    opacity: 0.6;
    font-family: monospace;
}

/* Node Content */
.workflow-node-content {
    padding: 8px 12px;
    font-size: 12px;
    min-height: 40px;
}

.workflow-node-property {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 4px;
}

.workflow-node-property:last-child {
    margin-bottom: 0;
}

.workflow-node-property-label {
    color: var(--mud-palette-text-secondary);
    font-size: 11px;
    min-width: 60px;
}

.workflow-node-property-value {
    color: var(--mud-palette-text-primary);
    font-family: monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workflow-node-property-value.expression {
    color: var(--mud-palette-info);
}

.workflow-node-property-value.missing {
    color: var(--mud-palette-error);
    font-style: italic;
}

/* --------------------------------------------------------------------------
   Node Type Variations
   -------------------------------------------------------------------------- */

/* Start Node */
.workflow-node.node-start {
    width: 120px !important;
    min-width: 120px !important;
    max-width: 120px !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
}

.workflow-node.node-start .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-success), var(--mud-palette-success-darken));
    color: var(--mud-palette-success-text);
}

.workflow-node.node-start .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* End Node */
.workflow-node.node-end {
    width: 120px !important;
    min-width: 120px !important;
    max-width: 120px !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
}

.workflow-node.node-end .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-error), var(--mud-palette-error-darken));
    color: var(--mud-palette-error-text);
}

.workflow-node.node-end .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Invoke Agent Node */
.workflow-node.node-invoke-agent .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-primary), var(--mud-palette-primary-darken));
    color: var(--mud-palette-primary-text);
}

.workflow-node.node-invoke-agent .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Send Activity Node */
.workflow-node.node-send-activity .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-info), var(--mud-palette-info-darken));
    color: var(--mud-palette-info-text);
}

.workflow-node.node-send-activity .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Variables Node */
.workflow-node.node-set-variable .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-secondary), var(--mud-palette-secondary-darken));
    color: var(--mud-palette-secondary-text);
}

.workflow-node.node-set-variable .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Condition Group Node */
.workflow-node.node-condition-group .workflow-node-header {
    background: linear-gradient(135deg, var(--mud-palette-warning), var(--mud-palette-warning-darken));
    color: var(--mud-palette-warning-text);
}

.workflow-node.node-condition-group .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Goto Action Node */
.workflow-node.node-goto-action .workflow-node-header {
    background: linear-gradient(135deg, #7c4dff, #651fff);
    color: white;
}

.workflow-node.node-goto-action .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Create Conversation Node */
.workflow-node.node-create-conversation .workflow-node-header {
    background: linear-gradient(135deg, #00bcd4, #00acc1);
    color: white;
}

.workflow-node.node-create-conversation .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Request Approval Node (Human-in-the-Loop) */
.workflow-node.node-request-approval .workflow-node-header {
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: white;
}

.workflow-node.node-request-approval .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* Wait For Action Node */
.workflow-node.node-wait-action .workflow-node-header {
    background: linear-gradient(135deg, #64748b, #475569);
    color: white;
}

.workflow-node.node-wait-action .workflow-node-icon {
    background: rgba(255,255,255,0.2);
    color: inherit;
}

/* --------------------------------------------------------------------------
   Node Ports
   -------------------------------------------------------------------------- */
.workflow-node-ports {
    position: absolute;
    pointer-events: none;
}

.workflow-node-port {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--mud-palette-surface);
    border: 3px solid var(--mud-palette-text-disabled);
    cursor: crosshair;
    pointer-events: auto;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    box-shadow: 0 0 0 2px transparent;
}

.workflow-node-port:hover {
    transform: scale(1.2);
    background: var(--mud-palette-primary);
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 4px rgba(var(--mud-palette-primary-rgb), 0.2);
}

.workflow-node-port.connected {
    background: var(--mud-palette-primary);
    border-color: var(--mud-palette-primary);
}

/* Larger hit area for easier dragging */
.workflow-node-port::after {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    z-index: 10;
}

/* Input port - fixed vertical alignment to match C# logic (40px) */
.workflow-node-port.input {
    top: 40px;
    left: -7px;
    transform: translateY(-50%);
}

.workflow-node-port.input:hover {
    transform: translateY(-50%) scale(1.2);
}

/* Output port - fixed vertical alignment to match C# logic (40px) */
.workflow-node-port.output {
    top: 40px;
    right: -7px;
    transform: translateY(-50%);
}

.workflow-node-port.output:hover {
    transform: translateY(-50%) scale(1.2);
}

/* Override for start/end nodes (60px height, center at 30px) */
.workflow-node.node-start .workflow-node-port.output,
.workflow-node.node-end .workflow-node-port.input {
    top: 30px;
}

/* Conditional Branch Ports */
.workflow-node-port.branch {
    right: -7px;
    background: var(--mud-palette-warning);
    border-color: var(--mud-palette-warning);
}

.workflow-node-port.branch.failure {
    background: var(--mud-palette-error);
    border-color: var(--mud-palette-error);
}

.workflow-node-port.branch.low-confidence {
    background: var(--mud-palette-info);
    border-color: var(--mud-palette-info);
}

.workflow-node-port.branch.otherwise {
    background: var(--mud-palette-text-secondary);
    border-color: var(--mud-palette-text-secondary);
}

/* Decision cards: one header row per question followed by its answer ports. */
.workflow-node-decision-question {
    position: absolute;
    left: 12px;
    right: 12px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    border-top: 1px solid var(--mud-palette-table-lines);
}

.workflow-node-decision-question .decision-question-key {
    flex: none;
    font-weight: 700;
}

.workflow-node-decision-question .decision-question-type {
    flex: none;
    font-size: 9px;
    line-height: 14px;
    padding: 0 4px;
    border-radius: 6px;
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-secondary);
}

.workflow-node-decision-question .decision-question-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--mud-palette-text-secondary);
}

.workflow-node-port-label.decision-port-label {
    z-index: 2;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--mud-palette-text-primary);
}

.workflow-node-port-label {
    position: absolute;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
    pointer-events: none;
}

.workflow-node-port-label.output {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* --------------------------------------------------------------------------
   Validation Badges
   -------------------------------------------------------------------------- */
.workflow-node-validation {
    position: absolute;
    top: -8px;
    right: -8px;
    z-index: 20;
}

.workflow-node-validation-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: var(--mud-elevation-2);
}

.workflow-node-validation-badge.error {
    background: var(--mud-palette-error);
    color: var(--mud-palette-error-text);
}

.workflow-node-validation-badge.warning {
    background: var(--mud-palette-warning);
    color: var(--mud-palette-warning-text);
}

/* --------------------------------------------------------------------------
   Node Palette (Sidebar)
   -------------------------------------------------------------------------- */
.workflow-palette {
    height: 100%;
    overflow-y: auto;
}

.workflow-palette-section {
    margin-bottom: 16px;
}

.workflow-palette-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mud-palette-text-secondary);
    padding: 8px 16px 4px;
}

.workflow-palette-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: grab;
    user-select: none;
    transition: background 0.15s ease;
    border-radius: var(--mud-default-borderradius);
    margin: 2px 8px;
}

.workflow-palette-item:hover {
    background: var(--mud-palette-action-default-hover);
}

.workflow-palette-item:active {
    cursor: grabbing;
    background: var(--mud-palette-action-default);
}

.workflow-palette-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 16px;
}

.workflow-palette-item-info {
    flex: 1;
    min-width: 0;
}

.workflow-palette-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
}

.workflow-palette-item-desc {
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Palette Item Colors by Type */
.workflow-palette-item.type-start .workflow-palette-item-icon {
    background: var(--mud-palette-success);
    color: var(--mud-palette-success-text);
}

.workflow-palette-item.type-end .workflow-palette-item-icon {
    background: var(--mud-palette-error);
    color: var(--mud-palette-error-text);
}

.workflow-palette-item.type-invoke-agent .workflow-palette-item-icon {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.workflow-palette-item.type-send-activity .workflow-palette-item-icon {
    background: var(--mud-palette-info);
    color: var(--mud-palette-info-text);
}

.workflow-palette-item.type-set-variable .workflow-palette-item-icon {
    background: var(--mud-palette-secondary);
    color: var(--mud-palette-secondary-text);
}

.workflow-palette-item.type-condition-group .workflow-palette-item-icon {
    background: var(--mud-palette-warning);
    color: var(--mud-palette-warning-text);
}

.workflow-palette-item.type-goto-action .workflow-palette-item-icon {
    background: #7c4dff;
    color: white;
}

.workflow-palette-item.type-create-conversation .workflow-palette-item-icon {
    background: #00bcd4;
    color: white;
}

/* --------------------------------------------------------------------------
   Power Fx expression field
   -------------------------------------------------------------------------- */
.pfx-field {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    padding: 8px 10px 6px;
    background: var(--mud-palette-surface);
}

.pfx-field-invalid {
    border-color: var(--mud-palette-error);
}

.pfx-field-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.pfx-field-label {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.pfx-field-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 10px;
}

.pfx-status-valid {
    color: var(--mud-palette-success);
    background: rgba(76, 175, 80, 0.12);
}

.pfx-status-invalid {
    color: var(--mud-palette-error);
    background: rgba(244, 67, 54, 0.12);
}

.pfx-status-warning {
    color: var(--mud-palette-warning);
    background: rgba(255, 152, 0, 0.14);
}

.pfx-status-neutral {
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-action-default-hover);
}

.pfx-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 6px;
}

.pfx-toolbar .mud-button {
    min-width: 0;
    text-transform: none;
}

.pfx-toolbar-divider {
    width: 1px;
    align-self: stretch;
    margin: 2px 6px;
    background: var(--mud-palette-lines-default);
}

.pfx-input {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-background);
    outline: none;
    tab-size: 2;
}

.pfx-input:focus {
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 2px rgba(var(--mud-palette-primary-rgb), 0.18);
}

.pfx-field-footer {
    min-height: 18px;
    margin-top: 4px;
}

.pfx-menu-group {
    display: block;
    padding: 6px 14px 2px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary);
}

.pfx-menu-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pfx-menu-item code {
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 12.5px;
}

.pfx-menu-item-hint {
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary);
}

/* --------------------------------------------------------------------------
   Workflow variables panel
   -------------------------------------------------------------------------- */
.wf-variables-panel {
    padding: 12px;
}

.wf-variables-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.wf-variables-group {
    margin-bottom: 10px;
}

.wf-variable-row {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid transparent;
}

.wf-variable-row:hover {
    background: var(--mud-palette-action-default-hover);
    border-color: var(--mud-palette-lines-default);
}

.wf-variable-row-unavailable {
    opacity: 0.5;
}

.wf-variable-main {
    display: flex;
    align-items: center;
    gap: 6px;
}

.wf-variable-ref {
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 12.5px;
    word-break: break-all;
}

.wf-variable-chip {
    height: 18px;
    font-size: 0.65rem;
}

.wf-variable-availability {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--mud-palette-text-secondary);
}

/* --------------------------------------------------------------------------
   Property Editor Panel
   -------------------------------------------------------------------------- */
.workflow-property-editor {
    height: 100%;
    overflow-y: auto;
    padding: 16px;
    background: var(--mud-palette-surface);
}

/* --------------------------------------------------------------------------
   Node details page: header with identity and actions, the editor in the main
   column and context cards (issues, connections, variables) beside it.
   -------------------------------------------------------------------------- */
.node-details-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--mud-palette-background-grey);
}

.node-details-header {
    flex: none;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.node-details-header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.node-details-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.node-details-heading {
    flex: 1;
    min-width: 220px;
}

.node-details-breadcrumb {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

.node-details-title {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-details-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

.node-details-meta code {
    font-size: 12px;
}

.node-details-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.node-details-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.node-details-grid {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 24px;
    align-items: start;
}

.node-details-main {
    min-width: 0;
}

.node-details-aside {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.node-details-card {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 12px;
    padding: 16px;
}

.node-details-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.node-details-muted {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

.node-details-warning {
    font-size: 12px;
    color: var(--mud-palette-warning-darken);
}

.node-details-issues {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    color: var(--mud-palette-error);
}

.node-details-issues li + li {
    margin-top: 4px;
}

.node-details-port-group {
    margin: 10px 0 4px;
    font-size: 12px;
    font-weight: 600;
}

.node-details-port-group span {
    font-weight: 400;
    color: var(--mud-palette-text-secondary);
}

.node-details-connection {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.node-details-port {
    font-size: 12px;
    padding: 1px 8px;
    border-radius: 10px;
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.node-details-node-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    padding: 2px 8px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
}

.node-details-node-link:hover,
.node-details-node-link:focus-visible {
    border-color: var(--mud-palette-primary);
    color: var(--mud-palette-primary);
    outline: none;
}

.node-details-node-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex: none;
}

.node-details-node-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-details-node-id {
    font-family: monospace;
    font-size: 10px;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90px;
}

.node-details-variable + .node-details-variable {
    margin-top: 8px;
}

.node-details-variable-ref {
    display: flex;
    align-items: center;
    gap: 4px;
}

.node-details-variable-ref code {
    font-size: 12px;
    word-break: break-all;
}

/* The property editor becomes a card that grows with the page instead of scrolling itself. */
.workflow-property-editor.detail-view {
    height: auto;
    overflow: visible;
    padding: 24px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 12px;
}

@media (max-width: 1100px) {
    .node-details-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .node-details-aside {
        position: static;
    }
}

.workflow-property-editor-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.workflow-property-editor-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    font-size: 20px;
}

.workflow-property-editor-title {
    flex: 1;
}

.workflow-property-editor-kind {
    font-size: 14px;
    font-weight: 600;
    color: var(--mud-palette-text-primary);
}

.workflow-property-editor-id {
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    font-family: monospace;
}

.workflow-property-section {
    margin-bottom: 20px;
}

.workflow-property-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mud-palette-text-secondary);
    margin-bottom: 12px;
}

.workflow-property-field {
    margin-bottom: 12px;
}

.workflow-property-field:last-child {
    margin-bottom: 0;
}

.workflow-property-error {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(var(--mud-palette-error-rgb), 0.1);
    border-left: 3px solid var(--mud-palette-error);
    border-radius: 0 4px 4px 0;
    margin-bottom: 8px;
}

.workflow-property-error-icon {
    color: var(--mud-palette-error);
    font-size: 16px;
    margin-top: 2px;
}

.workflow-property-error-text {
    font-size: 12px;
    color: var(--mud-palette-error);
}

/* --------------------------------------------------------------------------
   Minimap
   -------------------------------------------------------------------------- */
.workflow-minimap {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 180px;
    height: 120px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    box-shadow: var(--mud-elevation-4);
    overflow: hidden;
    z-index: 100;
    cursor: grab;
    touch-action: none;
}

.workflow-minimap-content {
    width: 100%;
    height: 100%;
    position: relative;
    pointer-events: none;
}

.workflow-minimap-node {
    position: absolute;
    background: var(--mud-palette-primary);
    border-radius: 2px;
    opacity: 0.7;
}

.workflow-minimap-viewport {
    position: absolute;
    border: 2px solid var(--mud-palette-primary);
    background: rgba(var(--mud-palette-primary-rgb), 0.1);
    border-radius: 2px;
    cursor: grab;
}

/* --------------------------------------------------------------------------
   Zoom Controls
   -------------------------------------------------------------------------- */
.workflow-zoom-controls {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
}

.workflow-zoom-button {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    cursor: pointer;
    transition: background 0.15s ease;
    box-shadow: var(--mud-elevation-2);
}

.workflow-zoom-button:hover {
    background: var(--mud-palette-action-default-hover);
}

.workflow-zoom-level {
    text-align: center;
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    padding: 4px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    box-shadow: var(--mud-elevation-2);
}

/* --------------------------------------------------------------------------
   Toolbar
   -------------------------------------------------------------------------- */
.workflow-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0; /* Prevent header from shrinking */
}

.workflow-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.workflow-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.workflow-status-chip {
    font-size: 11px;
    height: 20px;
}

.workflow-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.workflow-version-info {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
    margin-right: 8px;
}

.workflow-tabs-bar {
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.workflow-tabs {
    min-height: 40px;
}

.workflow-view-toggle {
    display: flex;
    align-items: center;
    background: var(--mud-palette-background-grey);
    border-radius: var(--mud-default-borderradius);
    padding: 2px;
}

.workflow-view-tabs {
    border-radius: var(--mud-default-borderradius);
}

.workflow-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0; /* Prevent toolbar from shrinking */
}

.workflow-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.workflow-toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--mud-palette-lines-default);
    margin: 0 8px;
}

/* Main content grid - fills remaining space */
.workflow-main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.workflow-main-content > .mud-grid-item {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.workflow-property-actions {
    position: sticky;
    bottom: 0;
    padding: 16px;
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-lines-default);
    margin-top: auto;
}

/* Hide description in the selected value display; show it only inside the dropdown list */
.email-template-description {
    display: none;
}

.mud-popover .email-template-description {
    display: block;
}

/* --------------------------------------------------------------------------
   Responsive Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 960px) {
    .workflow-minimap {
        width: 140px;
        height: 90px;
    }
    
    /* Removed responsive node sizing to keep C# coordinate sync
    .workflow-node {
        min-width: 160px;
        max-width: 200px;
    }
    
    .workflow-node.node-start,
    .workflow-node.node-end {
        min-width: 100px;
        max-width: 100px;
    }
    */
}

/* --------------------------------------------------------------------------
   Add Action Dialog
   -------------------------------------------------------------------------- */
.add-action-dialog {
    min-width: 400px;
    max-height: 500px;
}

.add-action-search {
    padding: 16px 16px 8px;
}

.add-action-categories {
    padding: 0 8px 16px;
    overflow-y: auto;
    max-height: 380px;
}

.add-action-category {
    margin-bottom: 8px;
}

.add-action-category-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
    padding: 8px 8px 4px;
    letter-spacing: 0.5px;
}

.add-action-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.add-action-item:hover {
    background-color: var(--mud-palette-action-default-hover);
}

.add-action-item.selected {
    background-color: var(--mud-palette-primary-hover);
}

.add-action-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.add-action-item-icon .mud-icon-root {
    font-size: 18px;
    color: white;
}

.add-action-item-icon.invoke {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
}

.add-action-item-icon.data {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
}

.add-action-item-icon.control {
    background: linear-gradient(135deg, #059669, #10b981);
}

.add-action-item-icon.communication {
    background: linear-gradient(135deg, #d97706, #f59e0b);
}

.add-action-item-content {
    flex: 1;
    min-width: 0;
}

.add-action-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
    margin-bottom: 2px;
}

.add-action-item-description {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-action-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--mud-palette-text-secondary);
}

/* --------------------------------------------------------------------------
   Context Menu
   -------------------------------------------------------------------------- */
.workflow-context-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
}

.workflow-context-menu {
    min-width: 160px;
    border-radius: var(--mud-default-borderradius);
    overflow: hidden;
}

.workflow-context-menu .mud-list-item {
    padding: 8px 16px;
    font-size: 13px;
}

.workflow-context-menu .mud-list-item:hover {
    background: var(--mud-palette-action-default-hover);
}
