:root {
    --bg-dark: #0a0a0a;
    --bg-panel: #141414;
    --bg-node: #1c1c1c;
    --border-color: #2a2a2a;
    --accent-color: #ffffff;
    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --node-width: 280px;
    --primary-font: 'Inter', -apple-system, sans-serif;
    --accent-font: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--primary-font);
    overflow: hidden;
    height: 100vh;
}

/* Main Layout - Full Width */
.noir-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Floating Brand */
.floating-brand {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 100;
    pointer-events: none;
}

.brand-logo {
    font-family: var(--accent-font);
    font-size: 28px;
    letter-spacing: -0.5px;
    color: var(--accent-color);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.brand-tagline {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 4px;
}

/* Context Menu */
.context-menu {
    position: fixed;
    z-index: 2000;
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    min-width: 180px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: none;
}

.context-menu-item {
    padding: 10px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    color: var(--text-primary);
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(4px);
}

.context-menu-item .icon {
    font-size: 16px;
    opacity: 0.7;
}

/* AI Assistant Floating Button */
.ai-toggle-btn {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--accent-color);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(255, 255, 255, 0.2);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 30px rgba(255, 255, 255, 0.3);
}

/* AI Assistant Modal */
.ai-modal {
    position: fixed;
    bottom: 100px;
    right: 32px;
    width: 360px;
    height: 500px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    transform-origin: bottom right;
}

/* Unified Execution Toolbar */
.unified-toolbar {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 12px;
    padding: 8px 16px;
    background: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 100px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.btn-queue {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 8px 24px;
    border-radius: 100px;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-queue:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.btn-queue:active {
    transform: translateY(0);
}

/* Canvas Area adjustment */
.canvas-area {
    flex: 1;
    position: relative;
    background-color: var(--bg-dark);
    overflow: hidden;
    height: 100vh;
    cursor: crosshair;
}

.canvas-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 30px 30px;
}

/* Node Styling */
.node-box {
    position: absolute;
    width: var(--node-width);
    min-width: 250px;
    min-height: 280px;
    background: var(--bg-node);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    user-select: none;
    z-index: 10;
    transition: box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    overflow: visible;
    /* 关键：允许插槽点溢出 */
}

.node-box:hover {
    box-shadow: 0 0 0 1px var(--accent-color), 0 15px 40px rgba(0, 0, 0, 0.6);
}

.node-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-panel);
    /* 增加背景确保不透明 */
    border-radius: 12px 12px 0 0;
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.node-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.status-dot {
    width: 6px;
    height: 6px;
    background: #444;
    border-radius: 50%;
}

.node-body {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
    /* 关键：允许内部插槽点溢出 */
    gap: 8px;
}

.slot-group {
    margin-bottom: 12px;
}

.slot {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    position: relative;
    height: 20px;
}

.slot-dot {
    width: 12px;
    height: 12px;
    background: #555;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: crosshair;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: absolute;
    /* 改为绝对定位，确保在边界上 */
    z-index: 100;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.slot-dot:hover,
.slot-dot.hover {
    background: #fff;
    border-color: var(--accent-color);
    transform: scale(1.4);
    box-shadow: 0 0 15px var(--accent-color);
}

.slot-dot.active {
    background: #4ade80;
    border-color: #fff;
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.8);
}

/* Data-type Color Coding */
.slot[data-data-type="image"] .slot-dot {
    border-color: #4ade80;
}

.slot[data-data-type="image"] .slot-dot:hover,
.slot[data-data-type="image"] .slot-dot.active {
    background: #4ade80;
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.8);
}

.slot[data-data-type="text"] .slot-dot,
.slot[data-data-type="string"] .slot-dot {
    border-color: #38bdf8;
}

.slot[data-data-type="text"] .slot-dot:hover,
.slot[data-data-type="string"] .slot-dot.active {
    background: #38bdf8;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.8);
}

/* 保持之前的通用样式，但允许覆盖 */
.input-slot {
    padding-left: 4px;
}

.input-slot .slot-dot {
    left: -18px;
    /* 精确放置在左侧边框 */
    border-color: var(--accent-color);
}

.output-slot {
    justify-content: flex-end;
    padding-right: 4px;
}

.output-slot .slot-dot {
    right: -18px;
    /* 精确放置在右侧边框 */
    border-color: #4ade80;
    /* 为输出点增加区分度 */
}

.node-input-field {
    width: 100%;
    background: #0d0d0d;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: white;
    font-family: inherit;
    font-size: 12px;
    resize: none;
    transition: border-color 0.2s;
}

.node-input-field:focus {
    outline: none;
    border-color: var(--accent-color);
}

.node-content {
    flex: 1;
    min-height: 0;
    background: #0a0a0a;
    background-image:
        linear-gradient(45deg, #111 25%, transparent 25%),
        linear-gradient(-45deg, #111 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #111 75%),
        linear-gradient(-45deg, transparent 75%, #111 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.generated-art {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    flex: 1;
    min-height: 0;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #444;
    font-size: 11px;
}

select.node-input-field {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.result-container {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.error-badge {
    background: rgba(255, 68, 68, 0.1);
    border: 1px solid #ff4444;
    color: #ff4444;
    padding: 12px;
    border-radius: 8px;
    font-size: 11px;
    width: 100%;
    text-align: center;
}

.meta-info {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animated {
    animation-duration: 0.4s;
    animation-fill-mode: both;
}

.file-upload-label {
    display: block;
    cursor: pointer;
    margin-top: 8px;
}

.upload-box {
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
}

.upload-box:focus {
    border-color: var(--accent-color);
    outline: none;
    background: rgba(255, 255, 255, 0.05);
}

.upload-box:hover {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.05);
}

.upload-icon {
    display: block;
    font-size: 20px;
    margin-bottom: 4px;
}

.upload-text {
    font-size: 11px;
    color: var(--text-secondary);
}

.hidden-input {
    display: none;
}

.file-status {
    font-size: 10px;
    margin-top: 6px;
    color: var(--accent-color);
}

.upload-success {
    color: #4ade80;
    font-weight: 600;
}

.node-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-node);
    flex-shrink: 0;
}

.btn-run {
    width: 100%;
    background: #fff;
    color: #000;
    border: none;
    padding: 8px 4px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: opacity 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-run:hover {
    opacity: 0.9;
}

/* HTMX Loading */
.htmx-indicator {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.htmx-request .htmx-indicator {
    opacity: 1;
}

/* Chat Section */
.chat-section {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-color);
    max-height: 40%;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    font-size: 12px;
    padding-bottom: 12px;
}

.msg {
    margin-bottom: 12px;
    line-height: 1.5;
}

.msg.system {
    color: var(--text-secondary);
    font-style: italic;
}

.msg.user {
    color: var(--accent-color);
    font-weight: 600;
}

.msg.ai {
    color: #fff;
    opacity: 0.8;
}

.chat-input-wrapper {
    position: relative;
}

.chat-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    padding: 12px 40px 12px 16px;
    border-radius: 20px;
    color: white;
    font-size: 12px;
}

.chat-send {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.chat-send:hover {
    color: white;
}

/* Tools */
.canvas-tools {
    position: absolute;
    bottom: 32px;
    right: 32px;
    display: flex;
    gap: 12px;
}

.tool-btn {
    width: 48px;
    height: 48px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    color: white;
    border-color: white;
    background: #1a1a1a;
}

#drag-proxy {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 0 10px var(--accent-color);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.node-delete-btn {
    background: transparent;
    border: none;
    color: #555;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.2s;
}

.node-delete-btn:hover {
    color: #ff4444;
}


.node-resizer {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, #666 50%);
    border-radius: 0 0 10px 0;
    z-index: 110;
}

.node-resizer:hover {
    background: linear-gradient(135deg, transparent 50%, var(--accent-color) 50%);
}

/* NoirConnect Native SVG Connections */
.connection-layer {
    position: absolute;
    top: -5000px;
    left: -5000px;
    width: 10000px;
    height: 10000px;
    pointer-events: none;
    z-index: 9;
    /* 放在节点下方 (假设节点 z-index > 9) 或者调整为合适层级 */
    overflow: visible;
}

.connection-path {
    fill: none;
    stroke: #4ade80;
    stroke-width: 3.5;
    stroke-linecap: round;
    cursor: pointer;
    pointer-events: stroke;
    /* 关键：仅在线条描边上响应用鼠标事件 */
    transition: stroke 0.2s, stroke-width 0.2s;
    stroke-dasharray: 10, 5;
    animation: flow 1s linear infinite;
    filter: drop-shadow(0 0 5px rgba(74, 222, 128, 0.4));
}

.connection-hit-area:hover+.connection-path {
    stroke: #ff4444;
    stroke-width: 5;
    filter: drop-shadow(0 0 8px rgba(255, 68, 68, 0.6));
    animation-play-state: paused;
}

.connection-path-temp {
    fill: none;
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 3;
    stroke-dasharray: 8, 4;
    pointer-events: none;
}

@keyframes flow {
    from {
        stroke-dashoffset: 15;
    }

    to {
        stroke-dashoffset: 0;
    }
}

/* 连线删除按钮样式 */
.line-delete-btn {
    position: fixed;
    width: 20px;
    height: 20px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    pointer-events: auto;
    box-shadow: 0 2px 10px rgba(255, 68, 68, 0.5);
    border: 2px solid white;
    transform: translate(-50%, -50%);
    transition: transform 0.1s;
    user-select: none;
}

.line-delete-btn:hover {
    transform: translate(-50%, -50%) scale(1.2);
    background: #ff0000;
}

.node-box.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 20px 50px rgba(0, 0, 0, 0.7);
    z-index: 100 !important;
}