/* mobilefooter1: geometry only. The native versions identified by workspace-shell
 * already inset their WebView for OS bars; browsers retain their CSS safe area.
 * Keep this stylesheet after tenant-themes.css and outside the color generator.
 */
@media screen and (max-width: 760px), screen and (min-width: 761px) and (max-height: 520px) {
  html[data-crm-workspace="windows"] {
    --crm-workspace-safe-bottom: env(safe-area-inset-bottom, 0px);
    --crm-workspace-taskbar-height: calc(54px + var(--crm-workspace-safe-bottom));
  }

  html[data-crm-workspace="windows"][data-crm-native-insets="handled"] {
    --crm-workspace-safe-bottom: 0px;
  }

  html[data-crm-workspace="windows"] body.workspace-shell-enabled .main > .workspace-taskbar {
    box-sizing: border-box;
    height: var(--crm-workspace-taskbar-height);
    min-height: var(--crm-workspace-taskbar-height);
    max-height: var(--crm-workspace-taskbar-height);
    padding: 5px 6px calc(5px + var(--crm-workspace-safe-bottom));
  }

  html[data-crm-workspace="windows"] body.workspace-shell-enabled .workspace-start-menu {
    bottom: calc(var(--crm-workspace-taskbar-height) + 6px);
    max-height: calc(100dvh - var(--crm-workspace-taskbar-height) - 18px);
  }
}

/* Keep the width-based window profile unchanged on landscape tablet/desktop UI. */
@media screen and (max-width: 760px) {
  html[data-crm-workspace="windows"] body.workspace-shell-enabled .main {
    padding-bottom: calc(var(--crm-workspace-taskbar-height) + 6px);
  }

  /* Match the existing themed/maximized inset specificity, without changing top,
   * horizontal bounds, stacking, hidden state or the classic/desktop layout. */
  html[data-crm-workspace="windows"] body.workspace-shell-enabled .main > .view.workspace-window-open:not(.workspace-window-minimized) {
    bottom: var(--crm-workspace-taskbar-height) !important;
  }

  html[data-crm-workspace="windows"] body.workspace-shell-enabled.workspace-module-layer-open .main::after,
  html[data-crm-workspace="windows"] body.workspace-shell-enabled .workspace-sticky-notes-layer {
    bottom: var(--crm-workspace-taskbar-height);
  }

  /* Settings dialogs retain their original parent/listeners. Reserve the taskbar
   * below their backdrop and scroll long content inside the bounded grid card. */
  html[data-crm-workspace="windows"] body.workspace-shell-enabled #users .settings-tool-modal-backdrop {
    bottom: var(--crm-workspace-taskbar-height);
  }

  html[data-crm-workspace="windows"] body.workspace-shell-enabled #users .settings-tool-modal-backdrop .settings-tool-modal-card {
    max-height: 100%;
  }

}

/* A landscape phone can cross the width breakpoint. Do not let the legacy
 * 520px desktop minimum move its absolute taskbar below the visible viewport. */
@media screen and (min-width: 761px) and (max-height: 520px) {
  html[data-crm-workspace="windows"] body.workspace-shell-enabled .main {
    min-height: 100dvh;
  }
}

/* mobilewindows1: the mobile frame owns system insets, never the scrolling
 * content. Padding above a sticky titlebar lets list rows pass over that bar.
 * The measured bounds probe also supports short landscape phones. */
html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] {
  --crm-workspace-safe-top: env(safe-area-inset-top, 0px);
  --crm-workspace-safe-right: env(safe-area-inset-right, 0px);
  --crm-workspace-safe-bottom: env(safe-area-inset-bottom, 0px);
  --crm-workspace-safe-left: env(safe-area-inset-left, 0px);
  --crm-workspace-taskbar-height: calc(54px + var(--crm-workspace-safe-bottom));
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"][data-crm-native-insets="handled"] {
  --crm-workspace-safe-top: 0px;
  --crm-workspace-safe-right: 0px;
  --crm-workspace-safe-bottom: 0px;
  --crm-workspace-safe-left: 0px;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled {
  overflow: hidden;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.workspace-mobile-bounds,
.workspace-mobile-resize-handle,
.workspace-mobile-split {
  display: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-mobile-bounds {
  display: block;
  position: fixed;
  inset: var(--crm-workspace-safe-top) var(--crm-workspace-safe-right) var(--crm-workspace-taskbar-height) var(--crm-workspace-safe-left);
  visibility: hidden;
  pointer-events: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > .view.workspace-window-open {
  position: fixed !important;
  inset: auto !important;
  left: var(--crm-mobile-window-left, 0px) !important;
  top: var(--crm-mobile-window-top, 0px) !important;
  width: var(--crm-mobile-window-width, 100%) !important;
  height: var(--crm-mobile-window-height, calc(100dvh - var(--crm-workspace-taskbar-height))) !important;
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  box-sizing: border-box;
  padding: 0 8px 52px;
  overflow: auto;
  overscroll-behavior: contain;
  resize: none;
  border: 1px solid var(--color-border, var(--line));
  border-radius: 12px;
  box-shadow: var(--crm-ui-shadow, var(--shadow));
  display: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > .view.workspace-window-open.workspace-mobile-visible:not(.workspace-window-minimized) {
  display: block;
}

/* Module-specific grid/flex rules must never reveal a minimized/denied third
 * window. This is a visibility guard, not a theme or layout override. */
html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > .view.workspace-window-open:is(:not(.workspace-mobile-visible), .workspace-window-minimized) {
  display: none !important;
}

/* Prospects owns its own central scroller; keep that established flex layout. */
html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > #prospects.workspace-window-open.workspace-mobile-visible:not(.workspace-window-minimized) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 8px 52px;
}

/* Email also owns its list/message scroll area and alternate compose workspace. */
html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > #email.workspace-window-open.workspace-mobile-visible:not(.workspace-window-minimized) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  padding: 0 8px 52px;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > :is(#prospects, #email).workspace-window-open.workspace-mobile-visible[data-workspace-mobile-maximized="true"] {
  padding-bottom: 8px;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .main > .view.workspace-window-open[data-workspace-mobile-maximized="true"] {
  border-radius: 0;
  padding-bottom: 8px;
  box-shadow: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-window-titlebar {
  position: sticky;
  top: 0;
  margin: 0 -8px 8px;
  min-height: 44px;
  padding: 0 4px 0 9px;
  border-radius: 11px 11px 0 0;
  touch-action: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled [data-workspace-mobile-maximized="true"] > .workspace-window-titlebar {
  border-radius: 0;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-window-controls button {
  display: grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  min-height: 38px;
  margin-block: 3px;
  border-radius: var(--app-radius, 7px);
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-mobile-resize-handle {
  display: grid;
  place-items: center;
  position: fixed;
  left: var(--crm-mobile-handle-left);
  top: var(--crm-mobile-handle-top);
  z-index: var(--crm-mobile-handle-z);
  box-sizing: border-box;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-accent-border, var(--line));
  border-radius: 10px 0 10px 0;
  background: var(--crm-ui-raised, var(--panel));
  color: var(--crm-ui-text, var(--ink));
  box-shadow: none;
  font-size: 22px;
  touch-action: none;
  cursor: nwse-resize;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-mobile-split {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--color-border, var(--line));
  border-radius: var(--app-radius, 7px);
  background: var(--crm-ui-raised, var(--panel));
  color: var(--crm-ui-text, var(--ink));
  font-size: 22px;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-taskbar {
  position: fixed;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  inset: auto 0 0;
  box-sizing: border-box;
  height: var(--crm-workspace-taskbar-height);
  min-height: var(--crm-workspace-taskbar-height);
  max-height: var(--crm-workspace-taskbar-height);
  padding: 5px 6px calc(5px + var(--crm-workspace-safe-bottom));
}

/* Dock the existing calculator control without changing its action or access.
 * The former floating button covered the split button and window actions. */
html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-taskbar > .price-calculator-fab {
  position: static;
  inset: auto;
  z-index: auto;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  margin: 0;
  padding: 0;
  transform: none;
  border-radius: var(--app-radius, 7px);
  box-shadow: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-taskbar > .price-calculator-fab:hover {
  transform: none;
  box-shadow: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled .workspace-taskbar-status {
  display: none;
}

html[data-crm-workspace="windows"][data-crm-mobile-windows="true"] body.workspace-shell-enabled.workspace-module-layer-open .main::after {
  pointer-events: none;
}

.workspace-mobile-resize-handle[hidden],
.workspace-mobile-split[hidden] {
  display: none !important;
}
