/*
 * Admin impersonation must consume part of the viewport, not add a second
 * full-height application below it. Keep all overrides in one late-loaded
 * stylesheet so page-specific CSS cannot restore a 100dvh shell afterwards.
 */

:root {
  --admin-impersonation-height: 0px;
  --admin-impersonation-available-height: 100dvh;
}

body.has-admin-impersonation {
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 0 !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
}

body.has-admin-impersonation > .admin-impersonation-banner {
  position: relative !important;
  top: auto !important;
  flex: 0 0 auto !important;
  width: 100%;
  z-index: 2100;
}

/* Desktop trainer CRM and client CRM: the shell is exactly the viewport remainder. */
body.has-admin-impersonation > .app-shell--trainer-crm,
body.has-admin-impersonation > .app-shell--client-crm {
  box-sizing: border-box !important;
  width: 100% !important;
  height: var(--admin-impersonation-available-height) !important;
  min-height: 0 !important;
  max-height: var(--admin-impersonation-available-height) !important;
  flex: 0 0 var(--admin-impersonation-available-height) !important;
  overflow: hidden !important;
}

/* Trainer desktop has its own nested scrollport. Keep every flex ancestor shrinkable. */
body.has-admin-impersonation > .app-shell--trainer-crm > .gym-crm,
body.has-admin-impersonation > .app-shell--trainer-crm .gym-crm__inset {
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

body.has-admin-impersonation > .app-shell--trainer-crm .gym-crm__main {
  min-height: 0 !important;
  max-height: 100% !important;
  overflow-y: auto !important;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

/* Client shell is also constrained to the remaining viewport. */
body.has-admin-impersonation > .app-shell--client-crm:not(:has(.client-crm--embed)) > .client-crm {
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

body.has-admin-impersonation > .app-shell--client-crm:not(:has(.client-crm--embed)) .client-crm__workspace {
  min-height: 0 !important;
}

body.has-admin-impersonation > .app-shell--client-crm:not(:has(.client-crm--embed)) .client-crm__main {
  min-height: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior-y: contain;
}

/* Client/trainer-mobile headers are fixed to the viewport, not to their shell. */
body.has-admin-impersonation .client-crm:not(.client-crm--embed):not(.client-crm--workout-focus) .client-crm__header,
body.has-admin-impersonation.trainer-mobile-body .tm-header {
  top: var(--admin-impersonation-height) !important;
}

/* Mobile trainer shell uses the client shell primitive and needs the same hard bound. */
body.has-admin-impersonation.trainer-mobile-body > .app-shell--client-crm.trainer-mobile-app,
body.has-admin-impersonation.trainer-mobile-body > .app-shell--client-crm.trainer-mobile-app > .tm-shell {
  height: var(--admin-impersonation-available-height) !important;
  min-height: 0 !important;
  max-height: var(--admin-impersonation-available-height) !important;
  overflow: hidden !important;
}

body.has-admin-impersonation.trainer-mobile-body > .app-shell--client-crm.trainer-mobile-app > .tm-shell {
  height: 100% !important;
  max-height: 100% !important;
}

body.has-admin-impersonation.trainer-mobile-body .tm-main {
  min-height: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior-y: contain;
}
