/* ═══════════════════════════════════════════════════════════════════
   EMOS Node Editor — Styles
   Dark theme, dot-grid canvas, Blender-inspired nodes
   ═══════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Montserrat', sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ── Layout ───────────────────────────────────────────────────────── */
.node-editor-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.ne-sidebar {
    width: 260px;
    min-width: 260px;
    background: #16213e;
    border-right: 1px solid #0f3460;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

.ne-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #0f3460;
    background: #0f3460;
}

.ne-sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #e94560;
}

.ne-sidebar-section {
    border-bottom: 1px solid rgba(15, 52, 96, 0.5);
}

.ne-sidebar-section h3 {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #a0a0b0;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.ne-sidebar-section h3:hover {
    color: #e94560;
}

.ne-sidebar-items {
    padding: 0 8px 8px;
}

.ne-sidebar-item {
    padding: 6px 12px;
    margin: 2px 0;
    font-size: 12px;
    border-radius: 4px;
    cursor: grab;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}

.ne-sidebar-item:hover {
    background: rgba(233, 69, 96, 0.15);
    color: #fff;
}

.ne-sidebar-item:active {
    cursor: grabbing;
    transform: scale(0.97);
}

/* Category colour accents on sidebar items */
[data-category="databases"] .ne-sidebar-item   { border-left: 3px solid #4fc3f7; }
[data-category="generators"] .ne-sidebar-item   { border-left: 3px solid #81c784; }
[data-category="predictors"] .ne-sidebar-item   { border-left: 3px solid #ffb74d; }
[data-category="viewers"] .ne-sidebar-item       { border-left: 3px solid #ce93d8; }
[data-category="utility"] .ne-sidebar-item       { border-left: 3px solid #f06292; }

/* ── Canvas Container ─────────────────────────────────────────────── */
.ne-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #1a1a2e;
    /* Dot grid — scaled via JS transform */
    background-image: radial-gradient(circle, #2a2a4a 1px, transparent 1px);
    background-size: 24px 24px;
}

.ne-wires-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
    transform-origin: 0 0;
}

.ne-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    z-index: 2;
}

/* ── Nodes ─────────────────────────────────────────────────────────── */
.ne-node {
    position: absolute;
    min-width: 220px;
    background: #1e1e38;
    border: 1px solid #333;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 5;
    display: flex;
    flex-direction: column;
    overflow: visible;
    user-select: none;
}

.ne-node.selected {
    border-color: #e94560;
    box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.3), 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* State indicators */
.ne-node.state-waiting  { border-color: #888; }
.ne-node.state-running  { border-color: #4fc3f7; box-shadow: 0 0 12px rgba(79, 195, 247, 0.4); }
.ne-node.state-done     { border-color: #81c784; }
.ne-node.state-error    { border-color: #e57373; box-shadow: 0 0 12px rgba(229, 115, 115, 0.4); }

/* Node Header */
.ne-node-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid #333;
    position: relative;
    border-radius: 5px 5px 0 0;
}

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

.ne-node-header .ne-node-icon { font-size: 14px; }
.ne-node-header .ne-node-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Close button on header */
.ne-node-close {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 400;
    color: #888;
    cursor: pointer;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    line-height: 1;
}

.ne-node-close:hover {
    color: #e57373;
    background: rgba(229, 115, 115, 0.2);
}

/* Category-specific header colours */
.ne-node[data-type="database"]  .ne-node-header { background: linear-gradient(135deg, #0d47a1, #1565c0); }
.ne-node[data-type="generator"] .ne-node-header { background: linear-gradient(135deg, #1b5e20, #2e7d32); }
.ne-node[data-type="predictor"] .ne-node-header { background: linear-gradient(135deg, #e65100, #ef6c00); }
.ne-node[data-type="viewer"]    .ne-node-header { background: linear-gradient(135deg, #6a1b9a, #8e24aa); }
.ne-node[data-type="utility"]   .ne-node-header { background: linear-gradient(135deg, #880e4f, #ad1457); }

/* ── Wire colours for utility port type ──────────────────────────── */

/* ── Filter node ──────────────────────────────────────────────────── */
.ne-filter-rules {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 6px;
}

.ne-filter-row {
    display: grid;
    grid-template-columns: 1fr 44px 1fr 18px;
    gap: 3px;
    align-items: center;
}

.ne-filter-row select,
.ne-filter-row input {
    width: 100%;
    padding: 3px 4px;
    font-size: 10px;
    background: #0f0f24;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 3px;
    font-family: 'Montserrat', sans-serif;
}

.ne-filter-row select:focus,
.ne-filter-row input:focus {
    outline: none;
    border-color: #f06292;
}

.ne-filter-remove-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    text-align: center;
    border-radius: 2px;
}

.ne-filter-remove-btn:hover { color: #e57373; }

.ne-add-filter-btn {
    width: 100%;
    padding: 4px;
    margin-top: 2px;
    background: rgba(240, 98, 146, 0.1);
    border: 1px dashed #f06292;
    color: #f06292;
    font-size: 10px;
    border-radius: 3px;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    transition: background 0.15s;
}

.ne-add-filter-btn:hover { background: rgba(240, 98, 146, 0.2); }

/* ── Lambda node ──────────────────────────────────────────────────── */
.ne-lambda-code {
    width: 100%;
    padding: 6px;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    background: #0a0a1e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 3px;
    resize: vertical;
    min-height: 140px;
    line-height: 1.5;
    tab-size: 4;
}

.ne-lambda-code:focus {
    outline: none;
    border-color: #f06292;
}

.ne-lambda-warning {
    margin-top: 4px;
    font-size: 9px;
    color: #ffb74d;
}

/* Node Body */
.ne-node-body {
    padding: 8px 12px;
    font-size: 11px;
    overflow-y: auto;
    max-height: 400px;
    flex: 1;
}

.ne-node-body label {
    display: block;
    margin-bottom: 6px;
    color: #bbb;
}

.ne-node-body input,
.ne-node-body select,
.ne-node-body textarea {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
    background: #0f0f24;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 3px;
    margin-top: 2px;
    font-family: 'Montserrat', sans-serif;
}

.ne-node-body input:focus,
.ne-node-body select:focus,
.ne-node-body textarea:focus {
    outline: none;
    border-color: #e94560;
}

.ne-node-body input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Node Footer (ports row) */
.ne-node-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    border-top: 1px solid #333;
    min-height: 8px;
}

/* ── Ports (absolutely positioned on node edges) ───────────────────── */
.ne-port-wrap {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 10;
    transform: translateY(-50%);
}

.ne-port-wrap.ne-port-input {
    left: -7px;
}

.ne-port-wrap.ne-port-output {
    right: -7px;
}

.ne-port {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #555;
    background: #1e1e38;
    cursor: crosshair;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.ne-port:hover {
    border-color: #e94560;
    background: rgba(233, 69, 96, 0.3);
    transform: scale(1.3);
}

/* Port type colours */
.ne-port[data-port-data="cif"]    { border-color: #4fc3f7; }
.ne-port[data-port-data="result"] { border-color: #ffb74d; }
.ne-port[data-port-data="any"]    { border-color: #ce93d8; }

.ne-port.connected {
    background: currentColor;
}

.ne-port[data-port-data="cif"].connected    { background: #4fc3f7; }
.ne-port[data-port-data="result"].connected { background: #ffb74d; }
.ne-port[data-port-data="any"].connected    { background: #ce93d8; }

/* Port labels */
.ne-port-label {
    font-size: 9px;
    color: #888;
    white-space: nowrap;
    pointer-events: none;
}

.ne-port-label-input {
    margin-left: 2px;
}

.ne-port-label-output {
    margin-right: 2px;
}

/* ── Wires (SVG paths) ────────────────────────────────────────────── */
.ne-wire {
    fill: none;
    stroke-width: 2;
    pointer-events: stroke;
    cursor: pointer;
}

.ne-wire[data-wire-type="cif"]    { stroke: #4fc3f7; }
.ne-wire[data-wire-type="result"] { stroke: #ffb74d; }
.ne-wire[data-wire-type="any"]    { stroke: #ce93d8; }

.ne-wire:hover {
    stroke-width: 3;
    filter: brightness(1.4);
}

.ne-wire-temp {
    fill: none;
    stroke: #e94560;
    stroke-width: 2;
    stroke-dasharray: 6 3;
    pointer-events: none;
}

/* ── Resize Handle ─────────────────────────────────────────────────── */
.ne-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    z-index: 15;
}

.ne-resize-handle::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #555;
    border-bottom: 2px solid #555;
}

/* ── CIF Viewer specific ──────────────────────────────────────────── */
.ne-cif-viewer-container {
    width: 100%;
    height: 200px;
    min-height: 100px;
    background: #000;
    border-radius: 3px;
    position: relative;
    flex: 1 1 auto;
}

.ne-cif-viewer-controls {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.ne-cif-viewer-controls select {
    flex: 1;
}

/* ── Text Viewer specific ─────────────────────────────────────────── */
.ne-text-viewer-content {
    width: 100%;
    min-height: 80px;
    max-height: 300px;
    overflow-y: auto;
    background: #0a0a1e;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 6px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: #aaa;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Log area inside nodes ────────────────────────────────────────── */
.ne-node-log {
    margin-top: 6px;
    max-height: 80px;
    overflow-y: auto;
    background: #0a0a1e;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 4px 6px;
    font-family: 'Courier New', monospace;
    font-size: 9px;
    color: #888;
    display: none;
}

.ne-node-log.visible { display: block; }

.ne-node-log .log-info    { color: #4fc3f7; }
.ne-node-log .log-warning { color: #ffb74d; }
.ne-node-log .log-error   { color: #e57373; }
.ne-node-log .log-success { color: #81c784; }

/* ── Bottom Toolbar ───────────────────────────────────────────────── */
.ne-toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: rgba(22, 33, 62, 0.95);
    border-top: 1px solid #0f3460;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 20;
}

.ne-toolbar-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    transition: background 0.2s, transform 0.1s;
}

.ne-toolbar-btn:active { transform: scale(0.96); }

.ne-process-btn {
    background: #2e7d32;
    color: #fff;
}

.ne-process-btn:hover { background: #388e3c; }
.ne-process-btn:disabled { background: #555; cursor: not-allowed; }

.ne-cancel-btn {
    background: #c62828;
    color: #fff;
}

.ne-cancel-btn:hover { background: #d32f2f; }

.ne-toolbar-status {
    flex: 1;
    font-size: 11px;
    color: #888;
}

.ne-toolbar-zoom {
    font-size: 11px;
    color: #888;
    min-width: 50px;
    text-align: right;
}

/* ── Context Menu ─────────────────────────────────────────────────── */
.ne-context-menu {
    position: fixed;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    min-width: 160px;
    padding: 4px 0;
}

.ne-context-item {
    padding: 8px 16px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.ne-context-item:hover {
    background: rgba(233, 69, 96, 0.2);
    color: #fff;
}

/* ── Scrollbar styling ────────────────────────────────────────────── */
.ne-sidebar::-webkit-scrollbar,
.ne-node-body::-webkit-scrollbar,
.ne-text-viewer-content::-webkit-scrollbar,
.ne-node-log::-webkit-scrollbar {
    width: 6px;
}

.ne-sidebar::-webkit-scrollbar-track,
.ne-node-body::-webkit-scrollbar-track,
.ne-text-viewer-content::-webkit-scrollbar-track,
.ne-node-log::-webkit-scrollbar-track {
    background: transparent;
}

.ne-sidebar::-webkit-scrollbar-thumb,
.ne-node-body::-webkit-scrollbar-thumb,
.ne-text-viewer-content::-webkit-scrollbar-thumb,
.ne-node-log::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

/* ── Progress indicator on node ───────────────────────────────────── */
.ne-node-progress {
    height: 3px;
    background: #333;
    overflow: hidden;
}

.ne-node-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4fc3f7, #81c784);
    transition: width 0.3s ease;
}

/* ── Responsive / Mobile adjustments ──────────────────────────────── */
@media (max-width: 768px) {
    .ne-sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }
    .ne-sidebar.open {
        left: 0;
    }
}
