Refactor sidebar animation logic