               item.classList.remove("highlighted");
            }
        });
    }

    // Add event listeners for search bar input and keydown
    searchBar.addEventListener("input", () => {
        const query = searchBar.value.trim();
        if (query) updateAutocomplete(query);
        else {
            autocompleteList.innerHTML = "";
            autocompleteList.style.display = "none";
        }
    });

    searchBar.addEventListener("keydown", (event) => {
        const items = autocompleteList.