The old code used complex `if` blocks and strange HTML layouts. <details>  </details> This PR refactors the template code and remove legacy CSS styles. The UI doesn't change much.  