(function(){
	document.addEventListener('input', function(e) {
		if (e.target.classList.contains('kramar-color-picker')) {
			var hex = e.target.closest('div').querySelector('.kramar-color-hex');
			if (hex) hex.value = e.target.value;
		}
		if (e.target.classList.contains('kramar-color-hex')) {
			var v = e.target.value.trim();
			var picker = e.target.closest('div').querySelector('.kramar-color-picker');
			if (picker && /^#[0-9a-fA-F]{6}$/.test(v)) picker.value = v;
		}
	});
	document.addEventListener('DOMContentLoaded', function() {
		var addForm = document.getElementById('addtag');
		if (addForm) {
			addForm.addEventListener('reset', function() {
				var picker = addForm.querySelector('.kramar-color-picker');
				var hex = addForm.querySelector('.kramar-color-hex');
				if (picker) picker.value = '#ffffff';
				if (hex) hex.value = '#ffffff';
			});
		}
	});
})();
