/* Mobile-only header corrections; desktop rules remain unchanged. */
@media screen and (max-width:767px){
  body > header.topbar{
    display:grid !important;grid-template-columns:minmax(0,1fr) !important;
    grid-template-areas:"brand" "session" "admin" "tabs" !important;
    width:100% !important;max-width:100vw !important;min-width:0 !important;
    box-sizing:border-box !important;padding:16px 12px !important;gap:12px !important;
  }
  body > header.topbar > .topbar-brand-block{grid-area:brand !important;width:100% !important;min-width:0 !important;}
  body > header.topbar > .topbar-brand-block > .topbar-logo{
    width:auto !important;height:auto !important;max-width:min(240px,100%) !important;max-height:56px !important;box-sizing:border-box !important;object-fit:contain !important;
  }
  body > header.topbar > .topbar-session{
    grid-area:session !important;display:flex !important;justify-content:space-between !important;align-items:center !important;
    width:100% !important;min-width:0 !important;margin:0 !important;padding:0 !important;border:0 !important;gap:12px !important;
  }
  body > header.topbar .topbar-user{min-width:0 !important;flex:1 1 auto !important;text-align:left !important;}
  body > header.topbar .topbar-user strong{white-space:normal !important;overflow-wrap:anywhere !important;}
  body > header.topbar .topbar-logout{flex:0 0 auto !important;min-height:44px !important;white-space:nowrap !important;}
  body > header.topbar > .admin-mode-toggle{grid-area:admin !important;width:100% !important;margin:0 !important;justify-content:flex-end !important;}
  body > header.topbar > .module-tabs.v165-module-tabs.cenergys-nav-groups{
    grid-area:tabs !important;display:flex !important;flex-wrap:nowrap !important;width:100% !important;min-width:0 !important;
    justify-content:flex-start !important;overflow-x:auto !important;gap:6px !important;padding-bottom:6px !important;
  }
  body > header.topbar > .module-tabs.v165-module-tabs.cenergys-nav-groups > :not(.v312-nav-hidden){
    flex:0 0 auto !important;width:auto !important;min-width:98px !important;max-width:none !important;min-height:44px !important;
  }
  body > header.topbar .cenergys-nav-group > .v165-module-tab{width:100% !important;min-width:98px !important;min-height:44px !important;}
  body > header.topbar #moduleTabDatabase{flex:0 0 118px !important;width:118px !important;min-width:118px !important;max-width:118px !important;min-height:44px !important;}
  body > header.topbar #moduleTabDatabase span:last-child{white-space:normal !important;overflow:visible !important;}
}
/* Mobile menus stay inside the viewport; expanded submenus participate in layout. */
@media screen and (max-width:767px){
  body > header.topbar > .module-tabs.v165-module-tabs.cenergys-nav-groups{
    display:grid !important;grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    flex-wrap:wrap !important;overflow:visible !important;align-items:start !important;
  }
  body > header.topbar > .module-tabs.v165-module-tabs.cenergys-nav-groups > :not(.v312-nav-hidden){
    width:100% !important;min-width:0 !important;max-width:none !important;box-sizing:border-box !important;
  }
  body > header.topbar #moduleTabDatabase{width:100% !important;min-width:0 !important;max-width:none !important;}
  body > header.topbar .cenergys-nav-group{display:flex !important;flex-direction:column !important;min-width:0 !important;}
  body > header.topbar .cenergys-nav-group > .v165-module-tab{min-width:0 !important;}
  body > header.topbar .cenergys-nav-group.open{grid-column:1 / -1 !important;}
  body > header.topbar .cenergys-nav-group .cenergys-nav-menu{
    position:static !important;top:auto !important;left:auto !important;right:auto !important;
    width:100% !important;min-width:0 !important;max-width:100% !important;box-sizing:border-box !important;
    margin-top:6px !important;transform:none !important;
  }
  body > header.topbar .cenergys-nav-group.open .cenergys-nav-menu{display:flex !important;flex-direction:column !important;}
  body > header.topbar .cenergys-nav-menu button{width:100% !important;min-height:44px !important;white-space:normal !important;box-sizing:border-box !important;}
  #crmModule.wrap{width:100% !important;max-width:100% !important;min-width:0 !important;box-sizing:border-box !important;padding-left:12px !important;padding-right:12px !important;}
  #crmModule .crm-topbar{flex-wrap:wrap !important;min-width:0 !important;}
  #crmModule .crm-topbar > div{min-width:0 !important;flex:1 1 180px !important;}
  #crmModule .crm-subnav.v165-crm-subnav{display:grid !important;grid-template-columns:repeat(2,minmax(0,1fr)) !important;min-width:0 !important;}
  #crmModule .crm-subnav .crm-subtab{min-width:0 !important;width:100% !important;white-space:normal !important;box-sizing:border-box !important;justify-content:center !important;}
  #crmModule .crm-metrics{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}
  #crmModule .crm-table-wrap{max-width:100% !important;overflow-x:auto !important;}
}
