/* LAW CABIN CRM — COMMERCIAL 2.0 FIX5-R4
 * Final structural desktop topbar contract.
 * R4 changes the DOM layout instead of stacking another positional override:
 *   row 1: [brand] [navigation]
 *   row 2: [spacer under brand] [branch ... right-aligned service cluster]
 * Service cluster: [notifications][online][license][logout].
 * The logout button is a normal flex item inside the service cluster and cannot
 * escape the white topbar vertically or horizontally.
 */
.topbar-primary-row-fix5r4,
.topbar-secondary-row-fix5r4,
.topbar-right-cluster-fix5r4 {
  display: contents;
}

@media (min-width: 901px) {
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar {
    height: auto !important;
    min-height: 94px !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-main {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 4px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 90px !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 8px 14px 9px !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-primary-row-fix5r4,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-secondary-row-fix5r4 {
    display: grid !important;
    grid-template-columns: minmax(210px, 250px) minmax(0, 1fr) !important;
    column-gap: 14px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-primary-row-fix5r4 {
    min-height: 36px !important;
    align-items: center !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-secondary-row-fix5r4 {
    min-height: 38px !important;
    align-items: center !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-brand {
    grid-area: auto !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    align-self: center !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 250px !important;
    margin: 0 !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-menu-toggle {
    display: none !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topNav {
    grid-area: auto !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    align-content: center !important;
    justify-content: flex-start !important;
    gap: 2px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 36px !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  /* Wrapped rows can sit under the accepted sticky Settings item (z-index:24).
     Raise only the currently opened group by one local layer. */
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topNav > .nav-group.hover-open,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topNav > .nav-group.open {
    z-index: 25 !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-tools-fix5 {
    grid-area: auto !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  /* Dynamic CourtFlow counter is inserted as a direct child of .topbar-tools.
     Order keeps it between the branch selector and the right service cluster. */
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-tools-fix5 > #courtEventNotificationsCounterV157 {
    order: 1 !important;
    flex: 0 0 auto !important;
    margin: 0 !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5 {
    order: 0 !important;
    display: flex !important;
    flex: 0 0 190px !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 190px !important;
    min-width: 190px !important;
    max-width: 190px !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 {
    order: 2 !important;
    display: flex !important;
    flex: 0 1 auto !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    margin: 0 0 0 auto !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-status-stack-fix5 {
    display: flex !important;
    flex: 0 1 auto !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-status-row-fix5 {
    display: flex !important;
    flex: 0 1 auto !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #notificationBox.topbar-notification-fix5 {
    display: flex !important;
    flex: 0 0 140px !important;
    width: 140px !important;
    min-width: 140px !important;
    max-width: 140px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topbarOnlineSummaryV153.topbar-online-fix5:not(.hidden) {
    display: flex !important;
    flex: 0 0 160px !important;
    width: 160px !important;
    min-width: 160px !important;
    max-width: 160px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #commercialBannerV160:not(.hidden) {
    display: flex !important;
    flex: 0 1 248px !important;
    width: 248px !important;
    min-width: 190px !important;
    max-width: 248px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #logoutBtn.topbar-logout-fix5 {
    position: static !important;
    inset: auto !important;
    display: inline-flex !important;
    flex: 0 0 78px !important;
    align-self: center !important;
    align-items: center !important;
    justify-content: center !important;
    width: 78px !important;
    min-width: 78px !important;
    max-width: 78px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 8px !important;
    transform: none !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
}

/* Compact desktop / tablet-width desktop: keep the exact same two-row structure,
   only reduce fixed service widths. */
@media (min-width: 901px) and (max-width: 1180px) {
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-main {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-primary-row-fix5r4,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-secondary-row-fix5r4 {
    grid-template-columns: minmax(170px, 190px) minmax(0, 1fr) !important;
    column-gap: 10px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5 {
    flex-basis: 140px !important;
    width: 140px !important;
    min-width: 140px !important;
    max-width: 140px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-status-stack-fix5,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-status-row-fix5 {
    gap: 4px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #notificationBox.topbar-notification-fix5 {
    flex-basis: 100px !important;
    width: 100px !important;
    min-width: 100px !important;
    max-width: 100px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topbarOnlineSummaryV153.topbar-online-fix5:not(.hidden) {
    flex-basis: 124px !important;
    width: 124px !important;
    min-width: 124px !important;
    max-width: 124px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #commercialBannerV160:not(.hidden) {
    flex-basis: 160px !important;
    width: 160px !important;
    min-width: 145px !important;
    max-width: 160px !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #logoutBtn.topbar-logout-fix5 {
    flex-basis: 70px !important;
    width: 70px !important;
    min-width: 70px !important;
    max-width: 70px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
}

/* FIX5-R5 runtime safeguard: license renderer must never restore legacy visual-system offsets. */
@media (min-width: 901px) {
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 #commercialBannerV160:not(.hidden) {
    margin: 0 !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    justify-self: auto !important;
  }
}

/* LAW CABIN CRM — COMMERCIAL 2.0 FIX5-R6
 * Browser-confirmed final service-row contract.
 * Do not nest the service pills on desktop: notifications, online, license and
 * logout participate in one grid row and have exactly the same height.
 */
@media (min-width: 901px) {
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 {
    display: grid !important;
    grid-template-columns: 140px 160px max-content 84px !important;
    grid-auto-flow: column !important;
    align-items: stretch !important;
    justify-content: end !important;
    column-gap: 6px !important;
    flex: 0 0 auto !important;
    width: max-content !important;
    min-width: 0 !important;
    max-width: calc(100% - 8px) !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 0 0 auto !important;
    padding: 0 !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  /* Flatten the old two-level status wrappers. All four service controls now
     become grid items of .topbar-right-cluster-fix5r4. */
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 > .topbar-status-stack-fix5,
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 .topbar-status-row-fix5 {
    display: contents !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #notificationBox.topbar-notification-fix5 {
    grid-column: 1 !important;
    display: flex !important;
    width: 140px !important;
    min-width: 140px !important;
    max-width: 140px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 !important;
    align-self: stretch !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #notificationBox.topbar-notification-fix5 > #enableNotificationsBtn {
    width: 100% !important;
    min-width: 0 !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 9px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topbarOnlineSummaryV153.topbar-online-fix5:not(.hidden) {
    grid-column: 2 !important;
    display: flex !important;
    width: 160px !important;
    min-width: 160px !important;
    max-width: 160px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 !important;
    align-self: stretch !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topbarOnlineSummaryV153.topbar-online-fix5:not(.hidden) > #topbarAllOnlineBtnV2100 {
    width: 100% !important;
    min-width: 0 !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 9px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 #commercialBannerV160:not(.hidden) {
    grid-column: 3 !important;
    display: flex !important;
    flex: none !important;
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 11px !important;
    align-self: stretch !important;
    align-items: center !important;
    justify-content: center !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    font-size: 10px !important;
    letter-spacing: 0 !important;
  }

  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #logoutBtn.topbar-logout-fix5 {
    grid-column: 4 !important;
    position: static !important;
    inset: auto !important;
    display: flex !important;
    width: 84px !important;
    min-width: 84px !important;
    max-width: 84px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 9px !important;
    align-self: stretch !important;
    align-items: center !important;
    justify-content: center !important;
    transform: none !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }
}

/* Narrow desktop: preserve one line; only tighten the two compact status pills.
   The license remains max-content so its legal/status information is never cut. */
@media (min-width: 901px) and (max-width: 1365px) {
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 {
    grid-template-columns: 112px 132px max-content 76px !important;
    column-gap: 4px !important;
  }
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #notificationBox.topbar-notification-fix5 {
    width: 112px !important;
    min-width: 112px !important;
    max-width: 112px !important;
  }
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #topbarOnlineSummaryV153.topbar-online-fix5:not(.hidden) {
    width: 132px !important;
    min-width: 132px !important;
    max-width: 132px !important;
  }
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #logoutBtn.topbar-logout-fix5 {
    width: 76px !important;
    min-width: 76px !important;
    max-width: 76px !important;
  }
  body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) .topbar-right-cluster-fix5r4 #commercialBannerV160:not(.hidden) {
    padding-left: 8px !important;
    padding-right: 8px !important;
    font-size: 9.5px !important;
  }
}

/* FIX19 QA6 — actual desktop branch selector. This sheet loads AFTER styles.css;
   previous QA5 width rules were overridden here. Preserve the accepted two-row
   header and keep the right-side status cluster intact. */
@media (min-width:1366px){
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5{
   flex:0 0 244px!important;width:244px!important;min-width:244px!important;max-width:244px!important;
 }
}
@media (min-width:1181px) and (max-width:1365px){
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5{
   flex:0 0 224px!important;width:224px!important;min-width:224px!important;max-width:224px!important;
 }
}
@media (min-width:901px) and (max-width:1180px){
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5{
   flex:0 1 180px!important;width:180px!important;min-width:150px!important;max-width:180px!important;
 }
}
@media (min-width:901px){
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5 .network-branch-switcher-a8{
   width:100%!important;max-width:none!important;min-width:0!important;
 }
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5 .network-branch-switcher-a8>label{
   width:100%!important;max-width:none!important;min-width:0!important;
 }
 body.crm-edition-commercial-v220:not(.crm-mobile-nav-mode-v1544) #networkBranchSlotFix2.network-branch-slot-fix5 .network-branch-switcher-a8 select{
   min-width:0!important;max-width:none!important;flex:1 1 auto!important;
 }
}
