﻿/* Workflow Editor Styles */
.workflow-editor {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.workflow-toolbar {
    background: #f8f9fa;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.workflow-content {
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.workflow-content .row {
    height: 100%;
}

.workflow-content .row > [class*='col-'] {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Node Palette */
.node-palette {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.node-palette .card-header {
    flex-shrink: 0;
}

.node-palette .card-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.node-category h6 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.node-template {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.node-template:hover {
    background: #e9ecef;
    border-color: #6c757d;
    transform: translateY(-1px);
}

.node-template i {
    margin-right: 0.5rem;
    width: 16px;
    text-align: center;
}

/* Workflow Canvas */
.workflow-canvas {
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: auto !important;
    background: 
        radial-gradient(circle, #dee2e6 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    cursor: grab;
}

.canvas-container.panning {
    cursor: grabbing !important;
}

.canvas-container.connection-mode {
    cursor: crosshair;
}

.canvas-content {
    position: relative;
    width: 3000px;
    height: 2000px;
    transform-origin: 0 0;
    transition: transform 0.2s ease;
}

/* Workflow Node Styles */
.workflow-node {
    position: absolute;
    width: 220px;
    min-height: 120px;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: move;
    user-select: none;
    transition: all 0.2s;
    z-index: 10;
}

.workflow-node:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-1px);
}

.workflow-node.dragging {
    transform: rotate(2deg);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    z-index: 1000;
}

.workflow-node.node-start {
    border-color: #28a745;
    background: linear-gradient(135deg, #d4edda 0%, #ffffff 100%);
}

.workflow-node.node-communication {
    border-color: #007bff;
    background: linear-gradient(135deg, #cce7ff 0%, #ffffff 100%);
}

.workflow-node.node-api {
    border-color: #6f42c1;
    background: linear-gradient(135deg, #e2d9f3 0%, #ffffff 100%);
}

.workflow-node.node-logic {
    border-color: #fd7e14;
    background: linear-gradient(135deg, #ffeaa7 0%, #ffffff 100%);
}

.workflow-node.node-utility {
    border-color: #6c757d;
    background: linear-gradient(135deg, #e9ecef 0%, #ffffff 100%);
}

.workflow-node.node-default {
    border-color: #20c997;
    background: linear-gradient(135deg, #c3f7df 0%, #ffffff 100%);
}

.node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: rgba(0,0,0,0.03);
    border-bottom: 1px solid #dee2e6;
    border-radius: 6px 6px 0 0;
    font-weight: 600;
    font-size: 0.875rem;
}

.node-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-actions {
    opacity: 0;
    transition: opacity 0.2s;
    margin: -10px !important;
}

.workflow-node:hover .node-actions,
.workflow-node.selected .node-actions {
    opacity: 1;
}

.node-body {
    padding: 1rem;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Node Connections Adjustments */
.node-connections {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.input-container,
.output-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem !important;
}

/* Node Connections */
.node-connections {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem; /* Add spacing between parameters and connections */
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Ensure consistent spacing between input ports */
    align-items: flex-start; /* Align inputs to the left */
}

.output-container {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Ensure consistent spacing between output ports */
    align-items: flex-end; /* Align outputs to the right */
}

/* Connection Points */
.connection-point {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #6c757d;
    border: 2px solid white;
    cursor: crosshair;
    transition: all 0.2s;
    z-index: 15;
    overflow: visible; /* allow labels to extend outside the small circle */
}

.output-point .output-label {
    position: absolute;
    right: 20px; /* place label slightly left from the dot */
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-size: 0.75rem;
    color: #495057;
    pointer-events: none; /* clicks should go to the port, not the label */
}

.connection-point:hover {
    background: #007bff;
    transform: scale(1.2);
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.5);
}

.connection-point.active {
    background: #28a745;
    animation: pulse-green 1s infinite;
}

.connection-point.source {
    background: #007bff;
    animation: pulse-blue 1s infinite;
}

.input-point {
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
}

/* Input Port Labels */
.input-point .input-label {
    position: absolute;
    left: -20px; /* place label slightly to the left of the dot */
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-size: 0.75rem;
    color: #495057;
    pointer-events: none; /* clicks should go to the port, not the label */
}

/* Ensure Output Ports Align to the Right Edge */
.output-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* Align ports and labels to the right */
    gap: 10px; /* Maintain spacing between ports */
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%); /* Center the container vertically */
}

.output-point {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Ensure label stays to the right of the port */
    position: relative;
    margin-top: 0; /* Remove any additional spacing */
}

/* Adjust spacing between ports */
.connection-point {
    margin-top: 10px; /* add spacing to prevent overlap */
}

/* Connection Mode Visual Feedback */
.workflow-node.connection-active {
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.8);
    border-color: #28a745;
}

.workflow-node.connection-source {
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.8);
    border-color: #007bff;
}

.workflow-node.connection-rejected {
    box-shadow: 0 0 15px rgba(220, 53, 69, 0.8);
    border-color: #dc3545;
    animation: shake 0.5s;
}

.workflow-node.connection-rejected .connection-point {
    background: #dc3545;
}

/* Connection Lines */
.connections-svg path {
    /* Removed conflicting hover styles - now handled in JavaScript */
}

/* Pulse Animation */
@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

@keyframes pulse-blue {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 123, 255, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
    }
}

/* Shake Animation for Rejected Connections */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Properties Panel */
.properties-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.properties-panel .card-header {
    flex-shrink: 0;
}

.properties-panel .card-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
}

.node-properties .form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #495057;
}

.node-properties h6 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #dee2e6;
}

/* Responsive */
@media (max-width: 768px) {
    .workflow-content .row {
        flex-direction: column;
    }
    
    .workflow-content .row > [class*='col-'] {
        height: auto;
    }
    
    .node-palette,
    .properties-panel {
        height: auto;
        max-height: 300px;
    }
    
    .workflow-canvas {
        height: 400px;
    }
}
