/**
 * Advanced Workflow Designer CSS
 * Complete styling for the visual workflow builder
 */

/* Main Layout */
.workflow-designer {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Toolbar */
.toolbar {
    background: #ffffff;
    border-bottom: 1px solid #e0e0e0;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-section:not(:last-child) {
    border-right: 1px solid #e0e0e0;
    padding-right: 16px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-primary:hover {
    background: #1976d2;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

.btn-warning {
    background: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background: #e0a800;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info:hover {
    background: #138496;
}

/* Main Body */
.designer-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Node Palette */
.node-palette {
    width: 280px;
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.palette-header {
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.palette-header h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.palette-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.palette-search input:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.palette-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.palette-category {
    margin-bottom: 16px;
}

.palette-category h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    background: #f1f3f4;
    border-radius: 4px;
}

.palette-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s ease;
    user-select: none;
}

.palette-item:hover {
    background: #f8f9fa;
    border-color: #2196f3;
    transform: translateX(4px);
}

.palette-item:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.palette-item i {
    font-size: 16px;
    color: #666;
    width: 20px;
    text-align: center;
}

.palette-item span {
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #fafafa;
}

#workflowCanvas {
    display: block;
    cursor: crosshair;
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
}

.execution-status {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    font-weight: 500;
    display: none;
}

.execution-status.active {
    display: block;
}

.execution-status.executing {
    color: #ff9800;
    border-left: 4px solid #ff9800;
}

.execution-status.completed {
    color: #4caf50;
    border-left: 4px solid #4caf50;
}

.execution-status.error {
    color: #f44336;
    border-left: 4px solid #f44336;
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    background: #ffffff;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.no-selection {
    text-align: center;
    color: #666;
    padding: 32px 16px;
}

.no-selection p {
    margin: 0;
    font-style: italic;
}

/* Properties Form */
.properties-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.properties-form h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    padding-bottom: 8px;
    border-bottom: 2px solid #e0e0e0;
}

.property-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.property-field label {
    font-size: 13px;
    font-weight: 500;
    color: #555;
    text-transform: capitalize;
}

.property-field input,
.property-field select,
.property-field textarea {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.property-field input:focus,
.property-field select:focus,
.property-field textarea:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.property-field textarea {
    resize: vertical;
    min-height: 60px;
    font-family: 'Courier New', monospace;
}

.property-field input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

/* Bottom Panel */
.bottom-panel {
    height: 300px;
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}

.panel-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.tab-button {
    padding: 12px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-button:hover {
    color: #2196f3;
    background: #f0f0f0;
}

.tab-button.active {
    color: #2196f3;
    border-bottom-color: #2196f3;
    background: #ffffff;
}

.bottom-panel .panel-content {
    flex: 1;
    overflow-y: auto;
}

.tab-content {
    display: none;
    height: 100%;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

/* Template Gallery */
.template-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    padding: 8px;
}

.template-card {
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.template-card:hover {
    border-color: #2196f3;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.15);
    transform: translateY(-2px);
}

.template-card h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.template-card p {
    margin: 0 0 12px 0;
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.template-card .load-template {
    font-size: 12px;
    padding: 6px 12px;
}

/* Execution Log */
.execution-log {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    max-height: 100%;
    overflow-y: auto;
    background: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
}

.log-entry {
    padding: 6px 12px;
    margin-bottom: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.log-entry.info {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.log-entry.success {
    background: #e8f5e8;
    border-left: 4px solid #4caf50;
}

.log-entry.warning {
    background: #fff3e0;
    border-left: 4px solid #ff9800;
}

.log-entry.error {
    background: #ffebee;
    border-left: 4px solid #f44336;
}

.log-entry .timestamp {
    font-weight: 600;
    color: #666;
    min-width: 80px;
}

.log-entry .message {
    flex: 1;
}

/* Validation Results */
.validation-results {
    font-size: 14px;
}

.validation-section {
    margin-bottom: 20px;
}

.validation-section h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.validation-section.errors h4 {
    color: #f44336;
}

.validation-section.warnings h4 {
    color: #ff9800;
}

.validation-section.info h4 {
    color: #2196f3;
}

.validation-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.validation-section li {
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: 4px;
    border-left: 4px solid;
}

.validation-section li.error {
    background: #ffebee;
    border-left-color: #f44336;
}

.validation-section li.warning {
    background: #fff3e0;
    border-left-color: #ff9800;
}

.validation-section li.info {
    background: #e3f2fd;
    border-left-color: #2196f3;
}

.validation-success {
    text-align: center;
    padding: 32px;
    color: #4caf50;
    font-size: 16px;
    font-weight: 500;
}

.validation-success i {
    font-size: 24px;
    margin-bottom: 8px;
    display: block;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    min-width: 150px;
    overflow: hidden;
}

.context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.context-menu-item:hover {
    background: #f8f9fa;
}

.context-menu-item i {
    width: 16px;
    color: #666;
}

/* Node Styles (for canvas rendering reference) */
.node {
    fill: #ffffff;
    stroke: #cccccc;
    stroke-width: 1;
    rx: 4;
    ry: 4;
}

.node.selected {
    fill: #e3f2fd;
    stroke: #2196f3;
    stroke-width: 2;
}

.node.executing {
    fill: #fff3e0;
    stroke: #ff9800;
    stroke-width: 2;
}

.node.error {
    fill: #ffebee;
    stroke: #f44336;
    stroke-width: 2;
}

.node.completed {
    fill: #e8f5e8;
    stroke: #4caf50;
    stroke-width: 2;
}

/* Connection Styles */
.connection {
    fill: none;
    stroke: #666666;
    stroke-width: 2;
    marker-end: url(#arrowhead);
}

.connection.active {
    stroke: #2196f3;
    stroke-width: 3;
}

.connection.temp {
    stroke: #2196f3;
    stroke-width: 2;
    stroke-dasharray: 5,5;
}

/* Input/Output Points */
.input-point {
    fill: #4caf50;
    stroke: #ffffff;
    stroke-width: 2;
    r: 4;
}

.output-point {
    fill: #2196f3;
    stroke: #ffffff;
    stroke-width: 2;
    r: 4;
}

/* Animations */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.executing .node {
    animation: pulse 1s infinite;
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.log-entry {
    animation: slideIn 0.3s ease-out;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .node-palette {
        width: 250px;
    }
    
    .properties-panel {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .workflow-designer {
        height: 100vh;
    }
    
    .toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .toolbar-section {
        border: none;
        padding: 0;
    }
    
    .designer-body {
        flex-direction: column;
    }
    
    .node-palette {
        width: 100%;
        height: 200px;
        order: 2;
    }
    
    .properties-panel {
        width: 100%;
        height: 200px;
        order: 3;
    }
    
    .canvas-container {
        height: 400px;
        order: 1;
    }
    
    .bottom-panel {
        height: 200px;
        order: 4;
    }
}

/* Accessibility */
.btn:focus {
    outline: 2px solid #2196f3;
    outline-offset: 2px;
}

.palette-item:focus {
    outline: 2px solid #2196f3;
    outline-offset: 2px;
}

.tab-button:focus {
    outline: 2px solid #2196f3;
    outline-offset: 2px;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .workflow-designer {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .toolbar,
    .node-palette,
    .properties-panel,
    .bottom-panel {
        background: #2d2d2d;
        border-color: #444444;
    }
    
    .palette-header,
    .panel-header {
        background: #333333;
    }
    
    .canvas-container {
        background: #1a1a1a;
    }
    
    #workflowCanvas {
        background: #1a1a1a;
    }
    
    .palette-item {
        background: #2d2d2d;
        border-color: #444444;
        color: #ffffff;
    }
    
    .palette-item:hover {
        background: #333333;
        border-color: #2196f3;
    }
    
    .template-card {
        background: #2d2d2d;
        border-color: #444444;
        color: #ffffff;
    }
    
    .execution-log {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .context-menu {
        background: #2d2d2d;
        border-color: #444444;
        color: #ffffff;
    }
}

/* Print Styles */
@media print {
    .workflow-designer {
        height: auto;
    }
    
    .toolbar,
    .node-palette,
    .properties-panel,
    .bottom-panel {
        display: none;
    }
    
    .canvas-container {
        width: 100%;
        height: auto;
    }
    
    #workflowCanvas {
        max-width: 100%;
        height: auto;
    }
}

/* High DPI Support */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    .palette-item i {
        font-size: 18px;
    }
    
    .btn i {
        font-size: 16px;
    }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Loading States */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2196f3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Drag and Drop States */
.drag-over {
    background: #e3f2fd;
    border: 2px dashed #2196f3;
}

.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

/* Tooltips */
.tooltip {
    position: absolute;
    background: #333333;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 10001;
    pointer-events: none;
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333333 transparent transparent transparent;
}

/* Error States */
.error-state {
    border-color: #f44336 !important;
    background: #ffebee !important;
}

.error-message {
    color: #f44336;
    font-size: 12px;
    margin-top: 4px;
}

/* Success States */
.success-state {
    border-color: #4caf50 !important;
    background: #e8f5e8 !important;
}

.success-message {
    color: #4caf50;
    font-size: 12px;
    margin-top: 4px;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.p-1 { padding: 8px; }
.p-2 { padding: 16px; }
.p-3 { padding: 24px; }

.flex {
    display: flex;
}

.flex-column {
    flex-direction: column;
}

.flex-center {
    justify-content: center;
    align-items: center;
}

.flex-1 {
    flex: 1;
}

.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }