(function () {
    'use strict';
    document.addEventListener('DOMContentLoaded', function () {
        const params = new URLSearchParams(window.location.search);
        const filterKeys = ['county', 'sector', 'q', 'subcategory', 'rating', 'org', 'sub'];
        const hasFilter = filterKeys.some(k => params.get(k));
        if (!hasFilter) return;

        // Only scroll when navigating from within the same site
        const sameOrigin = document.referrer &&
            new URL(document.referrer).origin === window.location.origin;
        if (!sameOrigin) return;

        const target = document.getElementById('submissions')
            || document.getElementById('all-submissions');
        if (!target) return;
        setTimeout(() => target.scrollIntoView({ behavior: 'smooth', block: 'start' }), 300);
    });
})();
