/* The wallpaper fills the viewport; foreground UI respects each system edge.
   WebKit updates these insets when rotating, folding or resizing the window. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  --safe-width: calc(100vw - var(--safe-left) - var(--safe-right));
}
#root { padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); }
.hub-page, .login-page, .startup-error, .workspace-choice-page { min-height: var(--safe-height); }
.workspace-choice { max-height: calc(var(--safe-height) - 48px); }
/* Fixed hosts and top-layer dialogs do not inherit the root's padding. */
.app-host { padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); }
/* Android Teams places this detail view below its toolbar and inside the side cutout. */
.app-host[data-android-teams-app-link] { padding: 0 0 var(--safe-bottom); }
.dialog, .session-expired {
  inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  max-width: calc(var(--safe-width) - 32px);
  max-height: calc(var(--safe-height) - 32px);
}
.spotlight { max-height: min(76vh, calc(var(--safe-height) - var(--launcher-dialog-top) - 16px)); }
.appearance-dialog { max-height: calc(var(--safe-height) - var(--launcher-dialog-top) - 24px); }
.hub-toasts {
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, var(--safe-right));
  max-width: calc(var(--safe-width) - 32px);
}

@media (max-width:480px) {
  .hub-toasts { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* Ordinary pages scroll as a document. Only the first header uses space beside
   corner system regions; dialogs and bounded panes retain complete clearance. */
:root[data-native-viewport] #root:has(.hub-page) {
  padding-bottom: var(--device-bottom);
}
:root[data-native-viewport] .hub-page { min-height: calc(100dvh - var(--safe-top) - var(--device-bottom)); }
:root[data-native-regions] #root:has(.hub-page) { padding-top: var(--native-top); }
:root[data-native-regions] .hub-page {
  min-height: calc(100dvh - var(--native-top) - var(--device-bottom));
}
/* Safe rectangle for authentication and error screens. */
:root[data-native-viewport] #root:has(.login-page, .startup-error) {
  --safe-top: var(--device-top);
  --safe-right: var(--device-right);
  --safe-bottom: var(--device-bottom);
  --safe-left: var(--device-left);
  --safe-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  --safe-width: calc(100vw - var(--safe-left) - var(--safe-right));
}
/* A centered sign-in card can use the whole viewport when it clears the cutout. */
:root[data-native-viewport] #root:has(.login-page[data-centered-card]) {
  padding: 0;
  --safe-height: 100dvh;
}
:root[data-native-viewport] .hub-footer[data-safe-edge="bottom"] {
  min-height: var(--region-safe-height, 0px);
  padding-left: max(16px, var(--region-safe-left, 0px));
  padding-right: max(16px, var(--region-safe-right, 0px));
  padding-bottom: max(8px, var(--region-safe-block, 0px));
}
body:has(dialog[open]) { overflow: hidden; }

/* Opted-in apps own the remaining regions inside their frame. */
:root[data-native-viewport] .app-host[data-app-viewport] { padding-bottom: 0; }
:root[data-native-viewport][data-native-regions] .app-host[data-app-viewport] { padding: 0; }
:root[data-native-viewport][data-native-regions] .app-host[data-app-viewport] .app-host-header {
  min-height: 56px;
}
:root[data-native-viewport][data-native-regions] .app-host[data-app-viewport] .app-host-header,
:root[data-native-regions] .nh-inbox-layout .app-host-header {
  padding-top: max(8px, var(--region-safe-block, 0px));
  padding-left: calc(16px + var(--region-safe-left, 0px));
  padding-right: calc(16px + var(--region-safe-right, 0px));
}
