/* ===================================================================================
   NODE EDITOR — Overlay, Canvas Layers, Node Cards, Ports, Wires
   =================================================================================== */

/* ── Overlay Container ─────────────────────────────────────────────────────── */
#nodeEditorCanvas {
    position: absolute;
    inset: 0;
    display: none;   /* toggled to flex by JS */
    flex-direction: column;
    background: var(--t-bg-workspace);
    z-index: 50;
    overflow: hidden;
}

/* ── Toolbar / Header ──────────────────────────────────────────────────────── */
.node-editor-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--t-bg-surface);
    border-bottom: 1px solid var(--t-border);
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--t-text-muted);
    user-select: none;
}

.node-editor-header > span:first-child {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

.node-editor-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Viewport (where canvas + HTML layer live) ─────────────────────────────── */
#nodeEditorViewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: default;
}

/* Space-bar grab cursor applied via JS */
#nodeEditorViewport.grabbing { cursor: grabbing !important; }

/* ── Canvas layers ─────────────────────────────────────────────────────────── */
#nodeCanvasLayer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none; /* mouse events go to the viewport container */
}

/* Offscreen buffers — always hidden */
#neBgBuffer,
#neStaticBuffer {
    display: none;
}

/* ── HTML Overlay Layer ────────────────────────────────────────────────────── */
#nodeHtmlLayer {
    position: absolute;
    top: 0;
    left: 0;
    /* transform set via JS: translate + scale in sync with canvas viewport */
    transform-origin: 0 0;
    pointer-events: none; /* children re-enable pointer-events individually */
}

/* ── Node Card ─────────────────────────────────────────────────────────────── */
.ne-node {
    position: absolute;
    width: 280px;
    background: var(--t-bg-surface);
    border: 1.5px solid var(--t-border);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    font-size: 12px;
    color: var(--t-text);
    pointer-events: all;   /* re-enable inside the overlay layer */
    transition: box-shadow 120ms ease, border-color 120ms ease;
    user-select: none;
    min-width: 180px;
}

.ne-node:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.ne-node.selected {
    border-color: var(--t-primary);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.25), 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ── Node Header ───────────────────────────────────────────────────────────── */
.ne-node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 8px 7px 6px;
    background: var(--t-toolbar-bg);
    border-bottom: 1px solid var(--t-border);
    border-radius: 8px 8px 0 0;
    cursor: grab;
}

.ne-node.collapsed .ne-node-header {
    border-radius: 8px;
    border-bottom: none;
}

.ne-node-header:active {
    cursor: grabbing;
}

.ne-node-collapse-btn {
    font-size: 9px;
    color: var(--t-text-muted);
    cursor: pointer;
    padding: 2px 3px;
    border-radius: 3px;
    flex-shrink: 0;
    line-height: 1;
    transition: color 100ms;
}

.ne-node-collapse-btn:hover {
    color: var(--t-primary);
}

.ne-node-label {
    flex: 1;
    font-weight: 600;
    font-size: 12px;
    color: var(--t-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ne-node-meta {
    font-size: 10px;
    color: var(--t-text-light);
    flex-shrink: 0;
}

.ne-node-delete-btn {
    background: none;
    border: none;
    color: var(--t-text-light);
    cursor: pointer;
    font-size: 12px;
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 100ms, background 100ms;
}

.ne-node-delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* ── Node Body ─────────────────────────────────────────────────────────────── */
.ne-node-body {
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}

.ne-node-body.ne-hidden {
    display: none;
}

/* ── Column (port) rows ────────────────────────────────────────────────────── */
.ne-node-col-rows {
    border-bottom: 1px solid var(--t-border);
}

.ne-node-col-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 4px 4px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    background: var(--t-bg-surface);
    min-height: 28px;
}

.ne-node-col-row:last-child {
    border-bottom: none;
}

.ne-cell-label {
    flex: 1;
    font-weight: 500;
    font-size: 11px;
    color: var(--t-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
}

/* ── Data rows ─────────────────────────────────────────────────────────────── */
.ne-node-data-rows {
    background: var(--t-bg-workspace);
}

.ne-node-data-row {
    display: flex;
    border-bottom: 1px solid var(--t-border);
}

.ne-node-data-row:last-child {
    border-bottom: none;
}

.ne-cell-value {
    flex: 1;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--t-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: text;
    min-width: 0;
    border-right: 1px solid var(--t-border);
    transition: background 80ms;
}

.ne-cell-value:last-child {
    border-right: none;
}

.ne-cell-value:hover {
    background: var(--t-hover-bg);
}

.ne-cell-empty {
    color: var(--t-text-light);
    font-style: normal;
}

/* ── Inline edit input ─────────────────────────────────────────────────────── */
.ne-cell-edit-input {
    flex: 1;
    padding: 2px 7px;
    font-size: 11px;
    font-family: inherit;
    color: var(--t-text);
    background: var(--t-bg-input);
    border: 1.5px solid var(--t-primary);
    border-radius: 3px;
    outline: none;
    min-width: 0;
    width: 100%;
}

/* ── Overflow hint ─────────────────────────────────────────────────────────── */
.ne-node-overflow-hint {
    padding: 4px 8px;
    font-size: 10px;
    color: var(--t-text-light);
    background: var(--t-bg-workspace);
    text-align: center;
    border-top: 1px dashed var(--t-border);
}

/* ── Ports ─────────────────────────────────────────────────────────────────── */
.ne-port {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--t-primary);
    background: var(--t-bg-surface);
    cursor: crosshair;
    flex-shrink: 0;
    transition: background 100ms, transform 100ms, border-color 100ms;
    position: relative;
    z-index: 1;
}

.ne-port:hover {
    background: var(--t-primary);
    transform: scale(1.3);
}

.ne-port-in {
    border-color: var(--t-primary);
}

.ne-port-out {
    border-color: #10b981;  /* teal for output */
}

.ne-port-out:hover {
    background: #10b981;
    border-color: #10b981;
}

/* ── Minimap (bottom-right overlay) ───────────────────────────────────────── */
.node-editor-minimap {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: var(--t-bg-surface);
    border: 1px solid var(--t-border);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    opacity: 0.85;
    transition: opacity 150ms;
    pointer-events: none;
}

.node-editor-minimap:hover {
    opacity: 1;
}

/* ── Responsive: hide minimap on small containers ─────────────────────────── */
@media (max-width: 600px) {
    .node-editor-minimap {
        display: none;
    }
    .node-editor-header-actions .btn {
        display: none;
    }
    .node-editor-header-actions .btn:last-child {
        display: inline-flex;
    }
}

/* ── Port spacer (placeholder when direction hides a port) ─────────────────── */
.ne-port-spacer {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
}

/* ── Operator node — header stripe by type ─────────────────────────────────── */
:root {
    --ne-type-table:   #1a73e8;
    --ne-type-filter:  #f59e0b;
    --ne-type-vlookup: #8b5cf6;
    --ne-type-formula: #10b981;
    --ne-type-api:     #ef4444;
    --ne-type-join:    #0ea5e9;
}

.ne-node.ne-operator .ne-node-header {
    border-left: 4px solid currentColor;
}
.ne-node.ne-type-filter  .ne-node-header { color: var(--ne-type-filter);  border-left-color: var(--ne-type-filter);  }
.ne-node.ne-type-vlookup .ne-node-header { color: var(--ne-type-vlookup); border-left-color: var(--ne-type-vlookup); }
.ne-node.ne-type-formula .ne-node-header { color: var(--ne-type-formula); border-left-color: var(--ne-type-formula); }
.ne-node.ne-type-api     .ne-node-header { color: var(--ne-type-api);     border-left-color: var(--ne-type-api);     }
.ne-node.ne-type-join    .ne-node-header { color: var(--ne-type-join);    border-left-color: var(--ne-type-join);    }

/* Label stays readable */
.ne-node.ne-operator .ne-node-label { color: var(--t-text); }

/* ── Type badge ────────────────────────────────────────────────────────────── */
.ne-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    line-height: 1.5;
}

/* ── Exec state badges ─────────────────────────────────────────────────────── */
.ne-exec-badge {
    font-size: 11px;
    flex-shrink: 0;
    line-height: 1;
}
.ne-exec-running { color: #f59e0b; animation: ne-pulse 1s infinite; }
.ne-exec-done    { color: #10b981; }
.ne-exec-error   { color: #ef4444; cursor: help; }

@keyframes ne-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* Tint card border when running/done/error */
.ne-node.ne-exec-running { border-color: #f59e0b; }
.ne-node.ne-exec-done    { border-color: #10b981; }
.ne-node.ne-exec-error   { border-color: #ef4444; }

/* ── Config button ──────────────────────────────────────────────────────────── */
.ne-node-config-btn {
    background: none;
    border: none;
    color: var(--t-text-light);
    cursor: pointer;
    font-size: 12px;
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 100ms, background 100ms;
}
.ne-node-config-btn:hover {
    color: var(--t-primary);
    background: rgba(26, 115, 232, 0.1);
}
.ne-node-config-btn.ne-config-btn-disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Port right-click context menu ──────────────────────────────────────────── */
.ne-port-menu {
    position: fixed;
    z-index: 9999;
    background: var(--t-bg-surface);
    border: 1px solid var(--t-border);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
    min-width: 170px;
    padding: 4px 0;
    user-select: none;
}

.ne-port-menu-heading {
    padding: 5px 12px 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--t-text-muted);
}

.ne-port-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 12px;
    color: var(--t-text);
    transition: background 80ms;
}
.ne-port-menu-item:hover {
    background: var(--t-hover-bg);
}

.ne-port-menu-icon {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #fff;
    flex-shrink: 0;
}

/* ── Operator placeholder ───────────────────────────────────────────────────── */
.ne-operator-placeholder {
    padding: 12px 8px;
    font-size: 11px;
    color: var(--t-text-light);
    text-align: center;
    font-style: italic;
    border-bottom: 1px dashed var(--t-border);
}

/* ── Join wire status ───────────────────────────────────────────────────────── */
.ne-join-wire-status {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.ne-join-side {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.ne-join-connected {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.ne-join-missing {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ── Palette flyout ─────────────────────────────────────────────────────────── */
.ne-palette {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    background: var(--t-bg-surface);
    border: 1px solid var(--t-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
    overflow: hidden;
    padding: 4px 0;
}

.ne-palette-heading {
    padding: 6px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--t-text-muted);
}

.ne-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 12px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background 100ms;
}
.ne-palette-item:hover { background: var(--t-hover-bg); }

.ne-palette-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #fff;
    flex-shrink: 0;
}

.ne-palette-info { display: flex; flex-direction: column; gap: 1px; }
.ne-palette-info strong { font-size: 12px; color: var(--t-text); }
.ne-palette-info em     { font-size: 10px; color: var(--t-text-muted); font-style: normal; }

/* ── Config panel ───────────────────────────────────────────────────────────── */
.ne-config-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    background: var(--t-bg-surface);
    border-left: 1px solid var(--t-border);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.10);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 200ms ease;
    pointer-events: all;
}
.ne-config-panel.ne-config-open { transform: translateX(0); }

.ne-config-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--t-toolbar-bg);
    border-bottom: 1px solid var(--t-border);
    font-size: 13px;
    font-weight: 600;
    color: var(--t-text);
    flex-shrink: 0;
}
.ne-config-type-icon {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    flex-shrink: 0;
}
.ne-config-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--t-text-muted);
    font-size: 13px;
    padding: 2px 5px;
    border-radius: 4px;
    transition: color 100ms, background 100ms;
}
.ne-config-close:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

.ne-config-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ne-config-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ne-config-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--t-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.ne-config-field input,
.ne-config-field select,
.ne-config-field textarea {
    width: 100%;
    padding: 5px 8px;
    font-size: 12px;
    font-family: inherit;
    background: var(--t-bg-input, var(--t-bg-workspace));
    color: var(--t-text);
    border: 1px solid var(--t-border);
    border-radius: 5px;
    outline: none;
    transition: border-color 100ms;
    box-sizing: border-box;
}
.ne-config-field input:focus,
.ne-config-field select:focus,
.ne-config-field textarea:focus { border-color: var(--t-primary); }

.ne-config-hint {
    font-size: 10px;
    color: var(--t-text-light);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.ne-config-hint-inline { font-size: 10px; color: var(--t-text-light); font-weight: 400; }
.ne-config-hint kbd {
    background: var(--t-toolbar-bg);
    border: 1px solid var(--t-border);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 10px;
    font-family: monospace;
}

.ne-config-error {
    font-size: 11px;
    color: #ef4444;
    padding: 3px 0;
}

.ne-config-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--t-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
