* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1b26;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* ========== 左侧边栏 ========== */
.sidebar {
    width: 280px;
    background: #1e1e2f;
    border-right: 1px solid #313244;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #313244;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    color: #89b4fa;
    font-size: 14px;
}

#refresh-functions {
    background: #313244;
    border: none;
    color: #cdd6f4;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.function-tree {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.category {
    margin-bottom: 16px;
}

.category-header {
    padding: 8px 12px;
    background: #313244;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    color: #89b4fa;
    user-select: none;
}

.category-items {
    margin-left: 8px;
    margin-top: 8px;
}

.function-item {
    padding: 8px 12px;
    margin: 4px 0;
    background: #2a2a3c;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s;
    border-left: 3px solid #89b4fa;
    user-select: none;
}

.function-item:active {
    cursor: grabbing;
}

.function-item:hover {
    background: #89b4fa;
    color: #1a1b26;
    transform: translateX(4px);
}

.function-item strong {
    font-size: 12px;
    display: block;
}

.function-item small {
    font-size: 10px;
    opacity: 0.7;
}

/* ========== 中间画布 ========== */
.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1a1b26;
    position: relative;
}

.toolbar {
    padding: 12px 16px;
    background: #24273a;
    border-bottom: 1px solid #313244;
    display: flex;
    gap: 12px;
    align-items: center;
}

.toolbar button {
    background: #313244;
    border: none;
    color: #cdd6f4;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: 0.2s;
}

.toolbar button:hover {
    background: #89b4fa;
    color: #1a1b26;
}

.status-ready {
    margin-left: auto;
    color: #a6e3a1;
    font-size: 12px;
}

.react-flow {
    flex: 1;
    position: relative;
    overflow: auto;
    background: 
        linear-gradient(90deg, #313244 1px, transparent 1px),
        linear-gradient(180deg, #313244 1px, transparent 1px);
    background-size: 20px 20px;
}

/* 节点样式（不使用 ReactFlow 内置，完全自定义） */
.flow-node {
    position: absolute;
    min-width: 220px;
    background: #2d2d3f;
    border-radius: 8px;
    border: 2px solid #89b4fa;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: move;
    z-index: 100;
    background-color: #2d2d3f;
}

.node-header {
    padding: 8px 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px 6px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    user-select: none;
}

.node-title {
    color: #89b4fa;
    font-weight: bold;
    font-size: 13px;
}

.delete-node-btn {
    background: none;
    border: none;
    color: #f38ba8;
    cursor: pointer;
    font-size: 14px;
}

.node-content {
    padding: 8px 12px;
}

.section-title {
    font-size: 10px;
    color: #6c7086;
    margin-bottom: 4px;
}

.input-port, .output-port {
    display: flex;
    align-items: center;
    margin: 4px 0;
    padding: 4px 6px;
    background: #24273a;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
}

.input-port {
    border-left: 2px solid #a6e3a1;
}

.output-port {
    border-left: 2px solid #f38ba8;
    cursor: pointer;
}

.port-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.input-port .port-dot {
    background: #a6e3a1;
}

.output-port .port-dot {
    background: #f38ba8;
}

.port-name {
    flex: 1;
}

.input-value {
    width: 80px;
    background: #1a1b26;
    border: none;
    color: #cdd6f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
}

.output-value {
    color: #a6e3a1;
    font-size: 10px;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.connected-badge {
    font-size: 9px;
    color: #6c7086;
    margin-left: auto;
}

.node-footer {
    padding: 8px 12px;
    border-top: 1px solid #313244;
}

.run-node-btn {
    width: 100%;
    background: #313244;
    border: none;
    color: #cdd6f4;
    padding: 5px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
}

.run-node-btn:hover {
    background: #89b4fa;
    color: #1a1b26;
}

/* 连线层 */
.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.connection-line {
    stroke: #89b4fa;
    stroke-width: 2;
    fill: none;
    pointer-events: visibleStroke;
    cursor: pointer;
}

/* ========== 右侧代码面板 ========== */
.code-panel {
    width: 420px;
    background: #1e1e2f;
    border-left: 1px solid #313244;
    display: flex;
    flex-direction: column;
}

.code-header {
    padding: 12px 16px;
    border-bottom: 1px solid #313244;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-header h3 {
    color: #89b4fa;
    font-size: 14px;
}

.code-actions {
    display: flex;
    gap: 8px;
}

.code-actions button {
    background: #313244;
    border: none;
    color: #cdd6f4;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

#code-editor {
    height: 45%;
    font-family: monospace;
    font-size: 12px;
    border: none;
    resize: none;
    padding: 12px;
    background: #1a1b26;
    color: #cdd6f4;
}

.output-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-top: 1px solid #313244;
}

.output-header {
    padding: 8px 12px;
    background: #24273a;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #89b4fa;
}

.output-header button {
    background: none;
    border: none;
    color: #6c7086;
    cursor: pointer;
}

.output-log {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    font-family: monospace;
    font-size: 11px;
}

.log-entry {
    padding: 4px 8px;
    margin: 2px 0;
    background: #24273a;
    border-radius: 4px;
    border-left: 2px solid #89b4fa;
}
