Now, when referencing a section, it works just fine and puts something like Sec. 2.5. When referencing an appendix, however, it puts Sec. Appendix A.

How does LaTeX decide whether it puts just the number (in the case of sections), or whether it puts Appendixand the "number" A? How can I influence this? How can I achieve a reference macro that automatically puts Sec./App./Chap. as appropriate?