As you've suggested, John, '12am' should technically be '12 midnight'
However using '12am' for midnight is the logical extension of the (perfectly sensible) convention which results in 12pm being used to indicate noon.
Noon is (by definition) neither 'ante meridiem', nor 'post meridiem'. If anything, it should be '12m'. ('12 meridiem'). But it seems more convenient to choose either 'am' or 'pm' to be used at noon. Since 12:00:01, 12:00:02, etc (in the middle of the day) are clearly 'post meridiem' (if only by a second or two!) it makes sense to designate 12:00:00 (at noon) as also being 'pm'. Following on from that convention, 12am is then used to designate midnight.