@media (max-width: 767px) {
  header:has([data-sidebar="trigger"]) {
    height: auto; min-height: calc(3.5rem + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(.5rem, env(safe-area-inset-right)) 0 max(.5rem, env(safe-area-inset-left));
  }
  header:has([data-sidebar="trigger"]) > div { gap: .25rem; min-width: 0; }
  header [data-sidebar="trigger"] { width: 44px; height: 44px; flex: 0 0 44px; margin: 0; touch-action: manipulation; }
  header:has([data-sidebar="trigger"]) button:has(kbd) { width: 44px; height: 44px; padding: 0; justify-content: center; flex-shrink: 0; }
  header:has([data-sidebar="trigger"]) button:has(kbd) > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  header:has([data-sidebar="trigger"]) button:has(kbd) svg { margin: 0; }
  [data-sidebar="sidebar"][data-mobile="true"] { max-width: calc(100vw - 1rem); height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  [data-sidebar="sidebar"][data-mobile="true"] > button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; top: env(safe-area-inset-top); right: 0; background: var(--sidebar); }
  [data-sidebar="sidebar"][data-mobile="true"] [data-sidebar="header"] { padding-right: 44px; }
  body:has([data-mobile="true"][data-state="open"]) :is(#nd-v14-launch, #nd-v14-panel, .nd-pwa-install) { visibility: hidden; pointer-events: none; }
  html #nd-v14-panel {
    bottom: calc(78px + env(safe-area-inset-bottom));
    max-height: calc(100dvh - 78px - 3.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-width: calc(100% - 14px - env(safe-area-inset-left) - env(safe-area-inset-right));
  }
}

/* Keep the team dashboard and its phone control in separate layout areas. */
@media (min-width: 768px) {
  #app:has(> button.fixed.rounded-full) main > div:has(> .ndtp) {
    padding-inline-end: max(6rem, env(safe-area-inset-right, 0px));
  }
  #app:has(> button.fixed.rounded-full span) main > div:has(> .ndtp) {
    padding-inline-end: max(10rem, env(safe-area-inset-right, 0px));
  }
  body:has(.ndtp) .nd-pwa-install { position: static; margin: 12px 18px 18px auto; }
}
@media (max-width: 767px) {
  body:has(#app .ndtp) {
    display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
    padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #app:has(.ndtp) { display: flex; flex-direction: column; flex: 1 1 0%; min-height: 0; min-width: 0; }
  #app:has(.ndtp) > [data-slot="sidebar-wrapper"] { min-height: 0; min-width: 0; flex: 1 1 0%; overflow: hidden; }
  main[data-slot="sidebar-inset"]:has(.ndtp) {
    min-height: 0; min-width: 0; overflow-y: auto; overscroll-behavior-y: contain;
    scroll-padding-block: 10px; -webkit-overflow-scrolling: touch;
  }
  main:has(.ndtp) > div:has(> .ndtp) { height: auto; flex: 1 0 auto; min-width: 0; }
  main:has(.ndtp) > [role="alert"] { flex-shrink: 0; grid-template-columns: auto minmax(0, 1fr); margin-bottom: 4px; }
  main:has(.ndtp) > [role="alert"] [data-slot="alert-description"],
  main:has(.ndtp) > [role="alert"] [data-slot="alert-description"] > div { flex-wrap: wrap; min-width: 0; gap: 6px; }
  main:has(.ndtp) > [role="alert"] [data-slot="alert-description"] span { overflow-wrap: anywhere; }
  main:has(.ndtp) > div:has(> .ndtp) > div:first-child { flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  main:has(.ndtp) > div:has(> .ndtp) > div:first-child > div { margin-bottom: 0; min-width: 0; }
  #app:has(.ndtp) > button.fixed.rounded-full {
    position: relative; inset: auto !important; align-self: flex-end; flex: 0 0 auto;
    width: auto !important; height: 44px !important; min-width: 44px; padding-inline: 16px;
    margin: 5px 12px; gap: 8px; box-shadow: none; transform: none; scale: 1;
  }
  #app:has(.ndtp) > button.fixed.rounded-full:not(:has(span))::after { content: 'Softphone'; font-size: .8125rem; font-weight: 600; }
  #app:has(.ndtp) > [data-slot="card"].fixed {
    inset: auto max(8px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) auto !important;
    width: min(380px, calc(100% - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-height: calc(100vh - 16px); max-height: min(600px, calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
    display: flex; flex-direction: column; overflow: hidden;
  }
  #app:has(.ndtp) > [data-slot="card"].fixed > :first-child { flex-shrink: 0; }
  #app:has(.ndtp) > [data-slot="card"].fixed [data-slot="scroll-area"] { min-height: 0; flex: 1 1 auto; }
  body:has(.ndtp) .nd-pwa-install { position: static; flex-shrink: 0; margin: 0 8px 4px; max-width: none; }
  body:has(.ndtp):has([data-slot="card"].fixed) .nd-pwa-install,
  body:has(.ndtp):has([role="dialog"][data-state="open"]) .nd-pwa-install { display: none; }
  body:has([role="dialog"][data-state="open"]) #app:has(.ndtp) > :is(button.fixed.rounded-full, [data-slot="card"].fixed) { visibility: hidden; pointer-events: none; }
  .ndtp :is(.ndtp-switch button,select) { min-height: 44px; }
}

/* Installed windows can give the page space behind a notch or the desktop title bar. */
@media (max-width: 767px) and (display-mode: standalone) {
  body:has(.ndtp) { padding-top: env(safe-area-inset-top, 0px); }
  main:has(.ndtp) header:has([data-sidebar="trigger"]) { min-height: 3.5rem; padding-top: 0; }
}
@media (min-width: 768px) and (display-mode: window-controls-overlay) {
  body:has(.ndtp) { padding-top: env(titlebar-area-height, 0px); }
  #app:has(.ndtp) [data-slot="sidebar-container"] {
    top: env(titlebar-area-height, 0px); height: calc(100dvh - env(titlebar-area-height, 0px));
  }
}
