    (function() {
        var pillsWrap = document.getElementById('followupTypePills');
        var hiddenType = document.getElementById('followupVisitType');
        var billableBox = document.getElementById('followupBillable');
        var priceRow = document.getElementById('followupPriceRow');
        function paintopsSyncPriceRow() {
            if (priceRow && billableBox) { priceRow.style.display = billableBox.checked ? '' : 'none'; }
        }
        if (billableBox) { billableBox.addEventListener('change', paintopsSyncPriceRow); }
        if (pillsWrap && hiddenType) {
            pillsWrap.addEventListener('click', function(e) {
                var pill = e.target.closest('.paintops-status-pill');
                if (!pill) return;
                pillsWrap.querySelectorAll('.paintops-status-pill').forEach(function(p) { p.classList.remove('active'); });
                pill.classList.add('active');
                hiddenType.value = pill.getAttribute('data-value');
                // Add-On Work is normally billable: pre-check it (still
                // uncheckable for a freebie add-on) and reveal the price.
                if (pill.getAttribute('data-value') === 'addon' && billableBox && !billableBox.checked) {
                    billableBox.checked = true;
                    paintopsSyncPriceRow();
                }
            });
        }

        var dateField = document.getElementById('followupDate');
        if (dateField) {
            dateField.addEventListener('change', function() {
                var parts = this.value.split('-');
                if (parts.length !== 3) return;
                document.getElementById('fpyear').value = parseInt(parts[0], 10);
                document.getElementById('fpmonth').value = parseInt(parts[1], 10);
                document.getElementById('fpday').value = parseInt(parts[2], 10);
            });
        }
    })();
