/* 트리 구조도 스타일 */

.structure-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: none;
    padding: 0;
}

.structure-modal.active {
    display: flex;
}

.structure-content {
    background: white;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.structure-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}

.structure-header > div {
    display: flex;
    gap: 10px;
    align-items: center;
}

.add-node-button, .export-button, .zoom-drag-button, .search-button, .reorganize-button, .undo-button, .redo-button, .reset-layout-button {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.undo-button, .redo-button {
    padding: 8px 12px;
    font-size: 18px;
    font-weight: bold;
    min-width: 36px;
}

.add-node-button:hover, .export-button:hover, .zoom-drag-button:hover, .search-button:hover, .reorganize-button:hover, .undo-button:hover, .redo-button:hover, .reset-layout-button:hover {
    background: #f5f5f5;
}

.undo-button:disabled, .redo-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.structure-header h2 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.close-button {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-button:hover {
    color: #000;
}

.structure-diagram {
    flex: 1;
    overflow: hidden; /* 줌/드래그를 위해 hidden으로 변경 */
    padding: 0;
    background: #f8f9fa;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 0; /* flexbox에서 overflow 작동을 위해 필요 */
}

.tree-svg {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

.tree-svg:active {
    cursor: grabbing;
}

.node-editor-form {
    padding: 20px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* 데스크톱: 편집기 열릴 때 좌우 분할 레이아웃 */
@media (min-width: 769px) {
    .structure-content.editor-open {
        display: grid;
        grid-template-columns: 400px 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas: 
            "header header"
            "editor diagram";
    }
    
    .structure-content.editor-open .structure-header {
        grid-area: header;
    }
    
    .structure-content.editor-open .node-editor-form {
        grid-area: editor;
        border-top: 1px solid #eee;
        border-right: 1px solid #eee;
    }
    
    .structure-content.editor-open .structure-diagram {
        grid-area: diagram;
    }
}

.node-editor-form h3 {
    margin: 0 0 15px 0;
    font-size: 18px;
    flex-shrink: 0;
}

.node-editor-form input,
.node-editor-form textarea,
.node-editor-form select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
    font-size: 14px;
    flex-shrink: 0;
}

.node-editor-row {
    display: flex;
    gap: 10px;
}

/* 노드 컨텍스트 메뉴 */
.node-context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    min-width: 120px;
    padding: 5px 0;
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
}

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

.node-editor-row input,
.node-editor-row select,
.node-editor-row button {
    flex: 1;
    margin-bottom: 10px;
}

.color-select-button {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.color-select-button:hover {
    border-color: #999;
}

.node-editor-form textarea {
    min-height: 200px;
    flex: 1;
    resize: vertical;
    overflow-y: auto;
}

.node-editor-form .choices-container {
    margin-bottom: 15px;
    overflow-y: auto;
    height: 300px;
    flex-shrink: 0;
}

.choice-item {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.choice-item input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    align-self: center;
    margin-bottom: 0;
    box-sizing: border-box;
    height: 38px;
}

.delete-choice-button {
    padding: 8px 12px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    box-sizing: border-box;
    height: 38px;
}

.delete-choice-button:hover {
    background: #c0392b;
}

.add-choice-button {
    width: 100%;
    padding: 10px;
    background: #95a5a6;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.add-choice-button:hover {
    background: #7f8c8d;
}

.editor-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.editor-buttons button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

#saveNodeButton {
    background: #667eea;
    color: white;
}

#saveNodeButton:hover {
    background: #5568d3;
}

#deleteNodeButton {
    background: #e74c3c;
    color: white;
}

#deleteNodeButton:hover {
    background: #c0392b;
}

#cancelNodeButton {
    background: #ddd;
    color: #333;
}

#cancelNodeButton:hover {
    background: #ccc;
}

/* 모바일 최적화 */
@media (max-width: 768px) {
    .structure-modal {
        padding: 0;
        height: 100vh;
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
    }
    
    .structure-content {
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        max-height: calc(var(--vh, 1vh) * 100);
        height: 100vh;
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        border-radius: 0;
    }
    
    .structure-header {
        padding: 15px;
    }
    
    .structure-header h2 {
        font-size: 18px;
    }
    
    .add-node-button, .export-button, .reset-layout-button, .close-button {
        min-height: 44px;
        min-width: 44px;
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .node-editor-form {
        padding: 15px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        z-index: 1001;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .node-editor-form .choices-container {
        height: 200px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex-shrink: 0;
    }
    
    .node-editor-form input,
    .node-editor-form textarea {
        font-size: 16px;
        padding: 12px;
    }
    
    .node-editor-form textarea {
        min-height: 250px;
        flex: 1;
        overflow-y: auto;
    }
    
    .node-editor-form .editor-buttons {
        margin-top: auto;
    }
    
    .editor-buttons button,
    .add-choice-button,
    .delete-choice-button {
        min-height: 44px;
        font-size: 16px;
        padding: 10px;
    }
    
    .choice-item {
        flex-wrap: wrap;
    }
    
    .choice-item input {
        min-width: 0;
        font-size: 16px;
        height: 44px;
    }
    
    .delete-choice-button {
        height: 44px;
    }
}

/* 색상 선택 모달 */
.color-picker-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: center;
}

.color-picker-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    width: 300px;
    max-width: 90%;
    text-align: center;
}

.color-picker-content h4 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
}

.color-picker-content input[type="color"] {
    width: 100%;
    height: 60px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
    cursor: pointer;
}

.quick-colors {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.quick-color-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.quick-color-btn[data-color="#fffde7"] {
    background: #fffde7;
}

.quick-color-btn[data-color="#e3f2fd"] {
    background: #e3f2fd;
}

.quick-color-btn[data-color="#ffffff"] {
    background: #ffffff;
}

.quick-color-btn:hover {
    border-color: #999;
    transform: translateY(-2px);
}

.color-picker-buttons {
    display: flex;
    gap: 10px;
}

.color-picker-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

#confirmColorButton {
    background: #667eea;
    color: white;
}

#confirmColorButton:hover {
    background: #5568d3;
}

#cancelColorButton {
    background: #ddd;
    color: #333;
}

#cancelColorButton:hover {
    background: #ccc;
}

/* 줌/드래그 설정 모달 */
.zoom-drag-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1003;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-drag-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    width: 350px;
    max-width: 90%;
}

.zoom-drag-content h4 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.setting-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.setting-controls input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
}

.setting-controls input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.setting-controls input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

.setting-controls input[type="number"] {
    width: 80px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    text-align: center;
}

.zoom-drag-buttons {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    flex-wrap: wrap;
}

.zoom-drag-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

#applyZoomDragButton {
    background: #667eea;
    color: white;
}

#applyZoomDragButton:hover {
    background: #5568d3;
}

#cancelZoomDragButton {
    background: #ddd;
    color: #333;
}

#cancelZoomDragButton:hover {
    background: #ccc;
}

#setDefaultZoomDragButton {
    background: #95a5a6;
    color: white;
}

#setDefaultZoomDragButton:hover {
    background: #7f8c8d;
}

.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1004;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    width: 300px;
    max-width: 90%;
}

.search-modal-content h4 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
}

.search-modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
}

.reorganize-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1005;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reorganize-modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    width: 400px;
    max-width: 90%;
}

.reorganize-modal-content h4 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
}

