How a phone app and a database served up Imran Khan’s Pakistan poll win