;
                }
            }

            // Close search history dropdown when clicking outside
            document.addEventListener('click', (event) => {
                if (!searchHistoryDropdown.contains(event.target) &&
                    event.target !== historyToggle &&
                    !historyToggle.contains(event.target)) {
                    searchHistoryDropdown.style.display = 'none';
                }
            });

            // Check for cached data
            const cachedMain