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

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

#header {
    background-color: #2d2d2d;
    border-bottom: 2px solid #3d3d3d;

    #title {
        color: white;
    }
}

.container {
    position: fixed;
    top: 60px;
    left: 0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    width: 100vw;
}

.toolbar-buttons button {
    background: #4fc3f7;
    color: #1e1e1e;
    border: none;
    padding: 8px 16px;
    margin-left: 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.toolbar-buttons button:hover {
    background: #29b6f6;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.node-palette {
    width: 200px;
    background: #252525;
    border-right: 2px solid #3d3d3d;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.palette-header {
    padding: 15px;
    border-bottom: 1px solid #3d3d3d;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 56px;
    min-height: 56px;
    max-height: 56px;
}

.palette-header h3 {
    color: #4fc3f7;
    font-size: 16px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.back-btn {
    background: transparent;
    color: #4fc3f7;
    border: none;
    padding: 5px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 20px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
}

.back-btn:hover {
    background: #2d2d2d;
}

.back-btn .material-symbols-outlined {
    font-size: 20px;
}

.palette-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.palette-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 15px;
    overflow-y: auto;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.palette-view.active {
    display: block;
    opacity: 1;
}

/* スライドアニメーション */
.palette-view.slide-out-left {
    animation: slideOutLeft 0.3s ease forwards;
}

.palette-view.slide-out-right {
    animation: slideOutRight 0.3s ease forwards;
}

.palette-view.slide-in-left {
    animation: slideInLeft 0.3s ease forwards;
}

.palette-view.slide-in-right {
    animation: slideInRight 0.3s ease forwards;
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.category-item,
.add-node {
    width: 100%;
    background: #3d3d3d;
    color: #fff;
    border: none;
    border-left: 3px solid #4fc3f7;
    padding: 10px 12px;
    margin-bottom: 5px;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: background 0.2s, transform 0.1s, border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.category-item span:not(.category-icon),
.add-node span:not(.node-icon) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.5;
}

.add-node {
    cursor: grab;
}

.add-node:active {
    cursor: grabbing;
}

.category-item:hover,
.add-node:hover {
    background: #4d4d4d;
}

.category-item:active,
.add-node:active {
    transform: scale(0.98);
}

.category-item::after {
    content: 'arrow_right';
    font-family: 'Material Symbols Outlined';
    color: #4fc3f7;
    flex-shrink: 0;
    margin-left: auto;
    padding-left: 8px;
}

.material-symbols-outlined {
    font-variation-settings:
        'FILL' 0,
        'wght' 400,
        'GRAD' 0,
        'opsz' 24;
}

.category-icon,
.node-icon {
    font-size: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    flex-shrink: 0;
    line-height: 1;
}

/* カテゴリとノードタイプの色は JavaScript で動的に適用 */

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: grab;
}

.canvas-container:active {
    cursor: grabbing;
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#nodes-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.node {
    position: absolute;
    background: #2d2d2d;
    border: 2px solid #4fc3f7;
    border-radius: 8px;
    padding: 10px;
    min-width: 180px;
    pointer-events: all;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.node.selected {
    border-color: #ffd54f;
    box-shadow: 0 0 10px rgba(255, 213, 79, 0.5);
}

/* ノードカテゴリごとの色は JavaScript で動的に適用 */

/* ドラッグプレビュー */
.node.drag-preview {
    pointer-events: none;
    opacity: 0.7;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.node-header {
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #3d3d3d;
    color: #fff;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.node-header-icon {
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.node-content {
    margin: 10px 0;
}

.node-input,
.node-output {
    margin: 8px 0;
    font-size: 12px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
}

.node-input {
    padding-left: 12px;
    padding-right: 0;
    text-align: left;
}

.node-output {
    padding-left: 0;
    padding-right: 12px;
    text-align: right;
}

.node-input input,
.node-input select,
.node-content input,
.node-content select {
    width: 100%;
    padding: 6px 8px;
    background: #1e1e1e;
    border: 1px solid #3d3d3d;
    color: #fff;
    border-radius: 4px;
    margin-top: 3px;
    font-size: 12px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    transition: border-color 0.2s, background 0.2s;
}

.node-input input:focus,
.node-input select:focus,
.node-content input:focus,
.node-content select:focus {
    outline: none;
    border-color: #4fc3f7;
    background: #252525;
}

.node-input input:hover,
.node-input select:hover,
.node-content input:hover,
.node-content select:hover {
    border-color: #4d4d4d;
}

.node-content select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234fc3f7' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

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

.node-content input[type="number"]::-webkit-inner-spin-button,
.node-content input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.port {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4fc3f7;
    position: absolute;
    cursor: crosshair;
    transition: all 0.2s;
    z-index: 10;
}

.port[data-flow-type="control"] {
    background: #ffffff;
    border-radius: 2px;
    transform: translateY(-50%) rotate(45deg);
}

.port[data-flow-type="control"]:hover {
    transform: translateY(-50%) rotate(45deg) scale(1.3);
}

.port:hover {
    background: #ffd54f;
    box-shadow: 0 0 8px rgba(255, 213, 79, 0.8);
}

.input-port:hover {
    transform: translateY(-50%) scale(1.3);
}

.output-port:hover {
    transform: translateY(-50%) scale(1.3);
}

.input-port {
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.output-port {
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.output-panel {
    width: 250px;
    background: #252525;
    padding: 15px;
    overflow-y: auto;
    border-left: 2px solid #3d3d3d;
}

.output-panel h3 {
    margin-bottom: 15px;
    color: #4fc3f7;
}

#output {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #a5d6a7;
    white-space: pre-wrap;
}

.output-line {
    margin-bottom: 5px;
    padding: 5px;
    background: #1e1e1e;
    border-radius: 3px;
    white-space: pre-wrap;
}

.delete-btn {
    background: #f44336;
    color: #fff;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    margin-top: 5px;
}

.delete-btn:hover {
    background: #d32f2f;
}


.context-menu {
    position: fixed;
    background: #2d2d2d;
    border: 1px solid #4fc3f7;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    min-width: 120px;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    color: #fff;
    font-size: 14px;
    transition: background 0.2s;
}

.context-menu-item:hover {
    background: #3d3d3d;
}

.context-menu-item:first-child {
    border-radius: 4px 4px 0 0;
}

.context-menu-item:last-child {
    border-radius: 0 0 4px 4px;
}


/* ダイアログスタイル */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.dialog-content {
    background: #2d2d2d;
    border-radius: 8px;
    padding: 20px;
    min-width: 400px;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.dialog-content h3 {
    margin-bottom: 20px;
    color: #4fc3f7;
}

.dialog-body {
    margin-bottom: 20px;
}

.dialog-body label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    color: #aaa;
}

.dialog-body input[type="text"] {
    width: 100%;
    padding: 8px;
    background: #1e1e1e;
    border: 1px solid #3d3d3d;
    border-radius: 4px;
    color: #fff;
    font-size: 14px;
}

.dialog-body input[type="text"]:focus {
    outline: none;
    border-color: #4fc3f7;
}

.small-btn {
    background: #3d3d3d;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    margin-top: 5px;
}

.small-btn:hover {
    background: #4d4d4d;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.dialog-footer .btn {
    background: #4fc3f7;
    color: #1e1e1e;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.dialog-footer .btn:hover {
    background: #29b6f6;
}

.dialog-footer .btn:last-child {
    background: #3d3d3d;
    color: #fff;
}

.dialog-footer .btn:last-child:hover {
    background: #4d4d4d;
}

.port-config {
    background: #1e1e1e;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.port-config input {
    flex: 1;
    padding: 6px;
    background: #2d2d2d;
    border: 1px solid #3d3d3d;
    border-radius: 4px;
    color: #fff;
}

.port-config button {
    background: #f44336;
    color: #fff;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.port-config button:hover {
    background: #d32f2f;
}

/* 
インライン入力フィールド */
.inline-input {
    display: inline-block;
    margin-left: 8px;
    width: 60px;
    padding: 2px 4px;
    background: #1e1e1e;
    border: 1px solid #3d3d3d;
    border-radius: 3px;
    color: #fff;
    font-size: 11px;
    vertical-align: middle;
    box-sizing: border-box;
}

.inline-input:focus {
    outline: none;
    border-color: #4fc3f7;
    background: #252525;
}

.inline-input[type="number"] {
    width: 50px;
}

.inline-input[type="text"] {
    width: 80px;
}

.inline-input select {
    width: 70px;
    background: #1e1e1e;
    color: #fff;
    border: 1px solid #3d3d3d;
    border-radius: 3px;
    font-size: 11px;
    padding: 2px;
}

.node-input {
    display: flex;
    align-items: center;
    justify-content: space-between;
}