document.addEventListener('click', function (event) {
    var toggle = event.target.closest('.bwdk-collapsible-toggle');
    if (!toggle) {
        return;
    }

    var wrapper = toggle.closest('.bwdk-collapsible-field');
    if (!wrapper) {
        return;
    }

    var content = wrapper.querySelector('.bwdk-collapsible-content');
    if (!content) {
        return;
    }

    var isExpanded = toggle.getAttribute('aria-expanded') === 'true';

    toggle.setAttribute('aria-expanded', String(!isExpanded));
    content.hidden = isExpanded;
    wrapper.classList.toggle('is-open', !isExpanded);
});
