/* Custom Node Editor Styles - Modern & Sleek (Optimized) */

#workflow-editor-container {
    background-color: #050505;
    /* Deep black for better contrast */
    position: relative;
    overflow: hidden;
    user-select: none;
    cursor: grab;
    width: 100%;
    height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.workflow-controls-top {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 50;
    display: flex;
    gap: 12px;
}

.workflow-info-bar {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(20, 20, 20, 0.9);
    /* Higher opacity for performance */
    padding: 10px 20px;
    border-radius: 9999px;
    /* Pill shape */
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* backdrop-filter: blur(12px); REMOVED for performance */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.workflow-info-bar:hover {
    background: rgba(30, 30, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.15);
}

.workflow-name-display {
    color: #EDEDED;
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.02em;
}

.workflow-unsaved-indicator {
    color: #fbbf24;
    font-size: 1.2rem;
    line-height: 0.5;
    display: none;
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

.workflow-unsaved-indicator.visible {
    display: inline-block;
}

.workflow-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #D1D5DB;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    min-width: 160px;
}

.workflow-select:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #FFF;
}

.workflow-select:focus {
    border-color: #981c13;
    box-shadow: 0 0 0 2px rgba(152, 28, 19, 0.2);
}

#workflow-editor-container:active {
    cursor: grabbing;
}

/* Internal Canvas Layer (Transformed) */
#editor-canvas {
    transform-origin: 0 0;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    /* Removed will-change: transform as it can cause rasterization blur during zoom */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background Pattern */
.editor-background {
    position: absolute;
    top: -5000px;
    left: -5000px;
    width: 10000px;
    height: 10000px;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
    background-size: 40px 40px;
    z-index: 0;
    /* Opacity reduced to avoid blending costs if any */
    opacity: 1;
}

/* SVG Layer for Connections */
#connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

.connection-line {
    fill: none;
    stroke: #525252;
    /* Darker, more subtle default line */
    stroke-width: 2.5px;
    stroke-linecap: round;
    pointer-events: visibleStroke;
    transition: stroke 0.2s;
    /* Faster transition */
    opacity: 0.8;
}

.connection-line:hover {
    stroke: #981c13;
    /* Brand color on hover */
    stroke-width: 3.5px;
    cursor: pointer;
    opacity: 1;
}

/* Dragging Connection Line */
.drag-line {
    stroke: #D2F800;
    /* Lime / Neon for active interaction */
    stroke-dasharray: 5, 5;
}

/* Node Container - Optimized for Performance */
.node {
    position: absolute;
    /* Use solid color closest to the desired glass look to avoid blur calculation */
    background: #181818;
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Very subtle border */
    border-radius: 16px;
    /* Smoother corners */
    /* Simpler box-shadow */
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(0, 0, 0, 0.2);
    /* backdrop-filter: blur(16px); REMOVED: Major performance killer */
    min-width: 280px;
    color: #F8F8F8;
    font-family: 'Inter', sans-serif;
    z-index: 2;
    display: flex;
    flex-direction: column;
    /* Remove transition on transform to make JS drag feel instant
       Only transition box-shadow/border for hover effects */
    transition: box-shadow 0.2s, border-color 0.2s;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.node * {
    box-sizing: border-box;
}

.node:hover {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(0, 0, 0, 0.2);
    z-index: 5;
    /* Slight z-index bump on hover */
}

.node.selected {
    border: 1px solid rgba(210, 248, 0, 0.6);
    /* Lime highlight */
    box-shadow:
        0 0 0 2px rgba(210, 248, 0, 0.15),
        0 10px 30px rgba(0, 0, 0, 0.7);
    z-index: 10;
}

.node.collapsed {
    min-height: 0 !important;
    height: 40px !important;
    overflow: visible !important;
}

/* Squash and fade content instead of hiding, to keep socket positions valid */
.node.collapsed .node-content,
.node.collapsed .node-extension-badge {
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Position sockets container on top of header when collapsed */
.node.collapsed .node-sockets {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    pointer-events: none;
    z-index: 10;
    overflow: visible !important;
}

/* Force all socket wrappers (divs with absolute positioning) to align to top */
.node.collapsed .node-sockets>div {
    top: 0 !important;
    height: 40px !important;
}

.node.collapsed .socket,
.node.collapsed .node-sockets .socket {
    top: 20px !important;
    /* Centered on header */
    transform: translateY(-50%) !important;
    opacity: 1 !important;
    /* Keep sockets visible */
    pointer-events: auto !important;
    display: block !important;
}

.node.collapsed .node-header {
    border-bottom: none;
    border-radius: 16px;
    height: 40px;
    box-sizing: border-box;
}

.node.bypassed {
    opacity: 0.6;
    filter: grayscale(100%) contrast(0.8);
    pointer-events: none;
}

.node.bypassed .node-header,
.node.bypassed .node-content {
    pointer-events: auto;
}

/* Node Header */
.node-header {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 500;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px 16px 0 0;
    letter-spacing: 0.03em;
}

.node-title {
    color: #E5E5E5;
    pointer-events: none;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    opacity: 0.9;
}

.node-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.node-collapse-btn {
    background: transparent;
    border: none;
    color: #888;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.node-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #FFF;
}

.node-dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background: rgba(25, 25, 25, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    min-width: 140px;
    padding: 6px;
    display: none;
    flex-direction: column;
    animation: nodeMenuFade 0.15s ease-out;
}

.node-dropdown-menu.active {
    display: flex;
}

@keyframes nodeMenuFade {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.node-dropdown-item {
    padding: 8px 12px;
    color: #D1D5DB;
    font-size: 0.8rem;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.1s;
}

.node-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #FFF;
}

.node-dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

/* Node Content */
.node-content {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
}

/* Inputs in Node */
.node-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.node-label {
    font-size: 0.7rem;
    color: #888888;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-left: 2px;
}

.node-control {
    background-color: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #EDEDED;
    padding: 10px 14px;
    border-radius: 8px;
    /* Slightly tighter radius */
    font-family: inherit;
    font-size: 0.8rem;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.node-control:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.node-control:focus {
    outline: none;
    border-color: #D2F800;
    /* Use brand color logic if applicable, or Keep Red */
    background-color: rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 0 1px rgba(210, 248, 0, 0.2);
}

textarea.node-control {
    resize: vertical;
    min-height: 90px;
    line-height: 1.5;
}

/* Custom Select Styling */
select.node-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    padding-right: 32px;
    /* Space for the arrow */
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.4);
    /* Explicit bg color to interact nicely with image */
}

select.node-control:hover {
    background-color: rgba(255, 255, 255, 0.05);
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

select.node-control option {
    background-color: #1F1F1F;
    color: #EDEDED;
    padding: 12px;
}

/* Sockets Container */
.node-sockets {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 5;
}

.node-sockets .socket {
    pointer-events: auto;
}

/* Sockets (Ports) - Minimal Dots */
.socket {
    width: 10px;
    height: 10px;
    background: #525252;
    border: 2px solid #1F1F1F;
    /* Match background somewhat to mask */
    border-radius: 50%;
    position: absolute;
    cursor: crosshair;
    transition: transform 0.2s;
    /* Simplified transition */
    z-index: 10;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.socket:hover {
    transform: scale(1.4);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    border-color: #FFF;
}

/* Adjusted for JS wrapper offsets to center on border */
.socket.input {
    left: -6px;
    /* Wrapper is ~2px from edge. -7px puts center roughly on border */
    background: #FF5A5A;
    /* Softer red connection point */
}

.socket.output {
    right: -6px;
    /* Tucked closer to border. Wrapper is at right:0 (inside). -6px puts center on border. */
    background: #62C554;
    /* Softer green connection point */
}

/* Custom Select Dropdowns */
select.node-control option {
    background-color: #181818;
    color: #F8F8F8;
    padding: 10px;
}

/* Context Menu - Fixed Overflow bug */
.context-menu {
    position: fixed;
    background: rgba(20, 20, 20, 0.95);
    /* backdrop-filter: blur(12px); Removed for safety/performance consistency */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow:
        0 10px 30px -5px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    padding: 8px;
    min-width: 200px;
    z-index: 1000;
    display: none;
    /* overflow: hidden; REMOVED to allow submenus to show */
}

.context-menu.active {
    display: block;
    animation: fadeInScale 0.15s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.menu-item {
    padding: 10px 14px;
    color: #D1D5DB;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.1s;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #FFF;
}

.menu-group-label {
    padding: 12px 14px 6px;
    font-size: 0.65rem;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
}

/* Submenu Support */
.menu-item.has-submenu {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    /* Ensure no overflow hidden here either */
    overflow: visible;
}

.menu-item.has-submenu::after {
    content: "â–¶";
    font-size: 8px;
    margin-left: 8px;
    opacity: 0.4;
    transition: transform 0.2s;
}

.menu-item.has-submenu:hover::after {
    opacity: 0.8;
    transform: translateX(2px);
}

.submenu {
    position: absolute;
    left: 100%;
    /* Position to the right */
    top: -4px;
    background: #181818;
    /* Solid bg for performance */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.8);
    padding: 8px;
    min-width: 180px;
    display: none;
    z-index: 1001;
    margin-left: 10px;
    /* Slight offset */
}

/* Bridge gap for hover stability */
.submenu::before {
    content: "";
    position: absolute;
    top: 0;
    left: -20px;
    width: 20px;
    height: 100%;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-5px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.menu-item.has-submenu:hover>.submenu {
    display: block;
    animation: slideIn 0.15s ease-out;
}