(function(){
  'use strict';
  var b = document.body;
  if(!b || !b.classList.contains('ua-shell-chrome') || b.classList.contains('ua-page-dashboard')) return;
  if(b.classList.contains('ua-p-subscribers') || b.classList.contains('ua-p-subscribers-add')) return;

  b.classList.add('ua-v11-normalized');

  document.querySelectorAll('.content-header').forEach(function(h){
    h.classList.add('ua-v11-title-strip');
    var actions = h.querySelectorAll('.btn');
    if(actions.length) h.classList.add('has-actions');
  });

  document.querySelectorAll('.box,.card,.panel,.well,.callout,.ua-card,.sa-card').forEach(function(card){
    card.classList.add('ua-v11-card');
    if(!card.querySelector('.box-header,.card-header,.panel-heading')) card.classList.add('ua-v11-card-plain');
  });

  document.querySelectorAll('section.content .row, .container-fluid > .row').forEach(function(row){
    var children = Array.prototype.slice.call(row.children || []);
    if(!children.length) return;
    var actionCols = 0;
    children.forEach(function(col){
      if(col.matches('[class*="col-"]') && col.querySelector(':scope > a.btn, :scope > button.btn')) actionCols++;
    });
    if(actionCols >= Math.max(2, Math.floor(children.length * .66))){
      row.classList.add('ua-v11-action-grid');
      children.forEach(function(col){
        var btn = col.querySelector(':scope > a.btn, :scope > button.btn');
        if(btn) btn.classList.add('ua-v11-action-tile');
      });
    }
  });

  // Keep accidental help bubbles fully disabled in this phase.
  document.querySelectorAll('.ua-help-btn,.ua-help-popover').forEach(function(x){ x.remove(); });
  document.querySelectorAll('.ua-help-source-hidden').forEach(function(x){ x.classList.remove('ua-help-source-hidden'); });
})();
