/* ==========================================================================
   MAGNETIC NODES - SPATIAL MIND MAP & NODE GRAPH
   Cyber-Cosmic Aesthetics for Wrench Lab
   ========================================================================== */

/* DESIGN TOKENS */
:root {
    --bg-void: #040108;
    --bg-surface: rgba(18, 7, 32, 0.75);
    --bg-surface-elevated: rgba(28, 12, 48, 0.85);
    --bg-card: rgba(20, 8, 36, 0.94);
    
    --primary-cyan: #06b6d4;
    --primary-fuchsia: #d946ef;
    --primary-purple: #c026d3;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    
    --text-main: #f3e8ff;
    --text-muted: #c4b5fd;
    --text-dim: rgba(243, 232, 255, 0.5);

    --border-glow: rgba(192, 38, 211, 0.35);
    --border-cyan: rgba(6, 182, 212, 0.5);
    --border-bright: rgba(217, 70, 239, 0.7);

    --font-heading: 'Cinzel', serif;
    --font-body: 'Syne', sans-serif;
    --font-mono: 'Courier Prime', monospace;
    --font-code: 'JetBrains Mono', monospace;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
}

/* RESET & BASE */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-void);
    color: var(--text-main);
    font-family: var(--font-body);
}

#noise {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* APP SHELL LAYOUT */
.app-layout {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 16px 24px 20px 24px;
    gap: 16px;
    background: 
        radial-gradient(circle at 10% 15%, rgba(217, 70, 239, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 90% 85%, rgba(6, 182, 212, 0.08) 0%, transparent 40%);
}

/* HEADER */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-glow);
    flex-shrink: 0;
}

.brand-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 2px;
    color: var(--primary-cyan);
    background: rgba(6, 182, 212, 0.12);
    border: 1px solid rgba(6, 182, 212, 0.3);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-bottom: 4px;
}

.header-brand h1 {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    background: linear-gradient(135deg, #ffffff 0%, #d8b4fe 40%, #c026d3 70%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1;
}

.header-subtitle {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* SUPPORT PILL */
.support-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: rgba(18, 7, 32, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.support-pill .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-amber);
    box-shadow: 0 0 8px var(--accent-amber);
    animation: pulse-dot 2s infinite ease-in-out;
}

.support-pill.supported {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.1);
}
.support-pill.supported .status-dot {
    background: var(--accent-emerald);
    box-shadow: 0 0 8px var(--accent-emerald);
}

.support-pill.fallback {
    border-color: rgba(245, 158, 11, 0.4);
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

/* COSMIC BUTTONS */
.btn-cosmic {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(192, 38, 211, 0.3);
    color: var(--text-main);
    padding: 8px 18px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-decoration: none;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    cursor: pointer;
}

.btn-cosmic:hover {
    background: rgba(192, 38, 211, 0.25);
    border-color: var(--primary-fuchsia);
    color: #ffffff;
    box-shadow: 0 0 15px rgba(217, 70, 239, 0.4);
    transform: translateY(-1px);
}

.btn-cosmic-mini {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glow);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-cosmic-mini:hover {
    background: rgba(217, 70, 239, 0.3);
    border-color: var(--primary-fuchsia);
    color: #ffffff;
}

/* WORKSPACE GRID */
.workspace-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

/* SIDEBAR PANEL */
.sidebar-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-title {
    font-family: var(--font-heading);
    font-size: 0.82rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--primary-cyan);
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title .icon {
    font-size: 0.9rem;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* PRESET BUTTONS */
.preset-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.preset-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.preset-btn .btn-icon {
    font-size: 1.1rem;
}

.preset-btn .preset-text strong {
    display: block;
    font-size: 0.82rem;
    font-family: var(--font-body);
}

.preset-btn .preset-text small {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
}

.preset-btn:hover {
    background: rgba(217, 70, 239, 0.15);
    border-color: rgba(217, 70, 239, 0.4);
    transform: translateX(3px);
}

.preset-btn.active {
    background: rgba(6, 182, 212, 0.15);
    border-color: var(--primary-cyan);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.25);
}

.preset-btn.active .preset-text strong {
    color: #ffffff;
}

/* ACTION GRID */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tool-btn:hover {
    background: rgba(217, 70, 239, 0.2);
    border-color: var(--primary-fuchsia);
}

.tool-btn.primary {
    background: linear-gradient(135deg, rgba(217, 70, 239, 0.3), rgba(6, 182, 212, 0.3));
    border-color: var(--primary-fuchsia);
    font-weight: bold;
}
.tool-btn.primary:hover {
    background: linear-gradient(135deg, rgba(217, 70, 239, 0.5), rgba(6, 182, 212, 0.5));
    box-shadow: 0 0 12px rgba(217, 70, 239, 0.4);
}

.tool-btn.active {
    border-color: var(--primary-cyan);
    color: #ffffff;
    background: rgba(6, 182, 212, 0.2);
}

/* INSPECTOR SECTION */
.inspector-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.inspector-hint {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-dim);
}

.code-preview {
    flex: 1;
    background: rgba(5, 2, 10, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 10px;
    overflow-y: auto;
    font-family: var(--font-code);
    font-size: 0.7rem;
    line-height: 1.45;
    color: #a78bfa;
    white-space: pre-wrap;
    word-break: break-word;
}

/* CANVAS WRAPPER & ARENA */
.canvas-wrapper {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-lg);
    overflow: hidden;
    backdrop-filter: blur(16px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7);
    position: relative;
}

.canvas-meta-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 18px;
    background: rgba(10, 3, 20, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.canvas-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-indicator {
    width: 6px;
    height: 6px;
    background: var(--primary-cyan);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary-cyan);
}

.canvas-zoom-info {
    font-size: 0.7rem;
    color: var(--text-dim);
}

/* CANVAS ARENA */
.canvas-arena {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #080312;
    background-image: 
        radial-gradient(circle at center, rgba(192, 38, 211, 0.05) 0%, transparent 70%),
        linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 100% 100%, 30px 30px, 30px 30px;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

.canvas-arena.connecting-mode {
    cursor: crosshair !important;
}

.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.cable-line {
    stroke: rgba(6, 182, 212, 0.5);
    stroke-width: 2.5;
    stroke-dasharray: 6 3;
    fill: none;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke 0.2s ease, stroke-width 0.2s ease;
    animation: cable-flow 1.5s linear infinite;
}

.cable-line:hover {
    stroke: var(--accent-rose);
    stroke-width: 4;
    filter: drop-shadow(0 0 6px rgba(244, 63, 94, 0.8));
}

.cable-preview-line {
    stroke: var(--primary-fuchsia);
    stroke-width: 2.5;
    stroke-dasharray: 4 4;
    fill: none;
    filter: drop-shadow(0 0 8px var(--primary-fuchsia));
    pointer-events: none;
    animation: cable-flow 0.8s linear infinite;
}

@keyframes cable-flow {
    to { stroke-dashoffset: -18; }
}

/* ==========================================================================
   CLEAN MINIMALIST SPATIAL NODES
   ========================================================================== */

#nodes-container {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

.hud-node {
    position: absolute;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1.5px solid var(--border-glow);
    padding: 14px 18px;
    min-width: 180px;
    max-width: 280px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6), 0 0 20px rgba(192, 38, 211, 0.15);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    z-index: 10;
}

.hud-node:hover {
    border-color: var(--primary-fuchsia);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8), 0 0 25px rgba(217, 70, 239, 0.3);
}

.hud-node.dragging {
    cursor: grabbing;
    border-color: var(--primary-cyan);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.9), 0 0 30px rgba(6, 182, 212, 0.5);
    z-index: 100;
}

.hud-node.selected {
    border-color: var(--primary-cyan);
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.4), 0 10px 25px rgba(0, 0, 0, 0.6);
}

.hud-node.connect-target {
    border-color: var(--accent-emerald) !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.5), 0 0 30px rgba(16, 185, 129, 0.4) !important;
    animation: target-pulse 1s infinite alternate ease-in-out;
}

@keyframes target-pulse {
    from { transform: scale(1); }
    to { transform: scale(1.03); }
}

/* CONNECTOR PORTS */
.node-port {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg-void);
    border: 2px solid var(--primary-cyan);
    top: 50%;
    transform: translateY(-50%);
    cursor: crosshair;
    z-index: 25;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.5);
}

.node-port::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-cyan);
}

.node-port.port-out {
    right: -7px;
}

.node-port.port-in {
    left: -7px;
    border-color: var(--primary-fuchsia);
}
.node-port.port-in::after {
    background: var(--primary-fuchsia);
}

.node-port:hover {
    transform: translateY(-50%) scale(1.4);
    border-color: #ffffff;
    box-shadow: 0 0 14px var(--primary-cyan);
}

/* NODE HEADER (TITLE & DELETE ONLY) */
.node-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}

.node-title-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.node-icon {
    font-size: 1.05rem;
    flex-shrink: 0;
}

.node-title {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    letter-spacing: 1px;
    color: #ffffff;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: text;
    -webkit-user-select: text;
}

.node-title:hover {
    background: rgba(255, 255, 255, 0.1);
    outline: 1px dashed var(--primary-cyan);
}

.node-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    transition: all 0.15s ease;
    opacity: 0.35;
    flex-shrink: 0;
}

.hud-node:hover .node-delete-btn {
    opacity: 1;
}

.node-delete-btn:hover {
    color: var(--accent-rose);
    background: rgba(244, 63, 94, 0.2);
}

/* NODE BODY (DESCRIPTION ONLY) */
.node-body {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.35;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    word-break: break-word;
    transition: background 0.15s ease;
    user-select: text;
    -webkit-user-select: text;
}

.node-body:hover {
    background: rgba(255, 255, 255, 0.08);
    outline: 1px dashed var(--primary-fuchsia);
}

/* INLINE EDIT INPUTS */
.node-inline-input {
    background: rgba(6, 182, 212, 0.15);
    border: 1px solid var(--primary-cyan);
    color: #ffffff;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    padding: 2px 6px;
    border-radius: 4px;
    width: 100%;
    outline: none;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
    user-select: text;
    -webkit-user-select: text;
}

.node-inline-textarea {
    background: rgba(217, 70, 239, 0.15);
    border: 1px solid var(--primary-fuchsia);
    color: #ffffff;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    padding: 4px 6px;
    border-radius: 4px;
    width: 100%;
    outline: none;
    box-shadow: 0 0 10px rgba(217, 70, 239, 0.4);
    resize: none;
    user-select: text;
    -webkit-user-select: text;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

.toast-msg {
    pointer-events: auto;
    background: rgba(18, 7, 34, 0.95);
    border: 1px solid var(--primary-cyan);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(6, 182, 212, 0.4);
    color: #ffffff;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-msg.toast-success {
    border-color: var(--accent-emerald);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(16, 185, 129, 0.4);
}

.toast-msg.toast-fadeout {
    opacity: 0;
    transform: translateY(10px);
}

/* RESPONSIVE LAYOUT */
@media (max-width: 1024px) {
    .workspace-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 320px 1fr;
    }
    
    .app-layout {
        padding: 12px;
    }
}
