/*
 * Virii8 Workspace Shell CSS module: viewport/safe-area bus guards.
 * JS measures the active shell chrome and publishes the variables below.
 */
:root {
  --v8-viewport-width: 100vw;
  --v8-viewport-height: 100dvh;
  --v8-shell-container-width: 100vw;
  --v8-shell-container-height: 100dvh;
  --v8-shell-top-reserve: 0px;
  --v8-shell-bottom-reserve: 74px;
  --v8e-admin-tools-anchor-bottom: 74px;
  --v8-shell-usable-top: var(--v8-shell-top-reserve, 0px);
  --v8-shell-usable-bottom: calc(var(--v8-shell-container-height, 100dvh) - var(--v8-shell-bottom-reserve, 74px));
  --v8-shell-usable-height: calc(var(--v8-shell-container-height, 100dvh) - var(--v8-shell-top-reserve, 0px) - var(--v8-shell-bottom-reserve, 74px));
}

#v8-os-container.v8-os-environment,
.v8-os-environment {
  --v8-shell-bottom-reserve: 74px;
  --v8e-admin-tools-anchor-bottom: 74px;
  --v8-shell-top-reserve: 0px;
}

#v8-os-container.v8-platform-mac:not(.v8-device-phone),
#v8-os-container.v8-platform-ios:not(.v8-device-phone),
.v8-os-environment.v8-platform-mac:not(.v8-device-phone),
.v8-os-environment.v8-platform-ios:not(.v8-device-phone) {
  --v8-shell-bottom-reserve: 112px;
  --v8e-admin-tools-anchor-bottom: 112px;
  --v8-shell-top-reserve: var(--v8-macos-menubar-height, 36px);
}

#v8-os-container.v8-platform-win:not(.v8-device-phone),
#v8-os-container.v8-platform-android:not(.v8-device-phone),
.v8-os-environment.v8-platform-win:not(.v8-device-phone),
.v8-os-environment.v8-platform-android:not(.v8-device-phone) {
  --v8-shell-bottom-reserve: 62px;
  --v8e-admin-tools-anchor-bottom: 62px;
}

#v8-os-container.v8-device-phone.v8-selected-mac,
#v8-os-container.v8-device-phone.v8-platform-ios,
.v8-os-environment.v8-device-phone.v8-selected-mac,
.v8-os-environment.v8-device-phone.v8-platform-ios {
  --v8-shell-bottom-reserve: 104px;
  --v8e-admin-tools-anchor-bottom: 104px;
}

#v8-os-container.v8-device-phone.v8-selected-win,
#v8-os-container.v8-device-phone.v8-platform-android,
.v8-os-environment.v8-device-phone.v8-selected-win,
.v8-os-environment.v8-device-phone.v8-platform-android {
  --v8-shell-bottom-reserve: 78px;
  --v8e-admin-tools-anchor-bottom: 78px;
}

#v8-os-container:not(.v8-device-phone) .v8-desktop,
.v8-os-environment:not(.v8-device-phone) .v8-desktop {
  bottom: max(72px, calc(var(--v8-shell-bottom-reserve, 74px) + 8px)) !important;
}

#v8-os-container.v8-platform-mac:not(.v8-device-phone) .v8-desktop,
#v8-os-container.v8-platform-ios:not(.v8-device-phone) .v8-desktop,
.v8-os-environment.v8-platform-mac:not(.v8-device-phone) .v8-desktop,
.v8-os-environment.v8-platform-ios:not(.v8-device-phone) .v8-desktop {
  top: max(44px, calc(var(--v8-shell-top-reserve, var(--v8-macos-menubar-height, 36px)) + 8px)) !important;
  bottom: max(102px, calc(var(--v8-shell-bottom-reserve, 112px) + 6px)) !important;
}

#v8-os-container.v8-platform-win:not(.v8-device-phone) .v8-desktop,
#v8-os-container.v8-platform-android:not(.v8-device-phone) .v8-desktop,
.v8-os-environment.v8-platform-win:not(.v8-device-phone) .v8-desktop,
.v8-os-environment.v8-platform-android:not(.v8-device-phone) .v8-desktop {
  bottom: max(68px, calc(var(--v8-shell-bottom-reserve, 62px) + 10px)) !important;
}

#v8-os-container.v8-device-phone .v8-desktop,
.v8-os-environment.v8-device-phone .v8-desktop {
  bottom: max(98px, calc(var(--v8-shell-bottom-reserve, 78px) + 12px)) !important;
}

#v8-os-container.v8-device-phone.v8-selected-mac .v8-desktop,
#v8-os-container.v8-device-phone.v8-platform-ios .v8-desktop,
.v8-os-environment.v8-device-phone.v8-selected-mac .v8-desktop,
.v8-os-environment.v8-device-phone.v8-platform-ios .v8-desktop {
  bottom: max(126px, calc(var(--v8-shell-bottom-reserve, 104px) + 14px)) !important;
}

/*
 * Admin/debug floating buttons use a stable platform anchor, not the live
 * measured reserve. This prevents jitter when the viewport bus re-measures
 * taskbar/dock chrome during browser UI, adminbar, or orientation changes.
 */
#v8-os-container .v8-start-menu,
#v8-os-container .v8-status-panel,
#v8-os-container .v8-shell-tools-popout,
#v8-os-container .v8-context-menu,
#v8-os-container .v8e-context-menu,
.v8-os-environment .v8-start-menu,
.v8-os-environment .v8-status-panel,
.v8-os-environment .v8-shell-tools-popout,
.v8-os-environment .v8-context-menu,
.v8-os-environment .v8e-context-menu {
  max-height: max(160px, calc(var(--v8-shell-usable-height, 70dvh) - 12px));
}

#v8-os-container .v8-window.maximized,
.v8-os-environment .v8-window.maximized {
  top: var(--v8-shell-usable-top, 0px) !important;
  height: var(--v8-shell-usable-height, calc(100% - var(--v8-shell-bottom-reserve, 74px))) !important;
}

#v8-os-container.v8-device-phone .v8-window,
#v8-os-container.v8-device-phone .v8-window.maximized,
.v8-os-environment.v8-device-phone .v8-window,
.v8-os-environment.v8-device-phone .v8-window.maximized {
  top: max(34px, var(--v8-shell-usable-top, 34px)) !important;
  height: max(220px, calc(var(--v8-shell-usable-height, 100dvh) - 34px)) !important;
}


/* v1.6.704: viewport-bounded snapped windows and floating panels. */
#v8-os-container .v8-window.v8-snapped-left,
#v8-os-container .v8-window.v8-snapped-right,
.v8-os-environment .v8-window.v8-snapped-left,
.v8-os-environment .v8-window.v8-snapped-right {
  top: var(--v8-shell-usable-top, 0px) !important;
  height: var(--v8-shell-usable-height, calc(100% - var(--v8-shell-bottom-reserve, 74px))) !important;
  max-height: var(--v8-shell-usable-height, calc(100% - var(--v8-shell-bottom-reserve, 74px))) !important;
  bottom: auto !important;
}

#v8-os-container .v8-window.v8-snapped-left,
.v8-os-environment .v8-window.v8-snapped-left {
  left: 0 !important;
  width: calc(var(--v8-shell-container-width, 100vw) / 2) !important;
}

#v8-os-container .v8-window.v8-snapped-right,
.v8-os-environment .v8-window.v8-snapped-right {
  left: calc(var(--v8-shell-container-width, 100vw) / 2) !important;
  width: calc(var(--v8-shell-container-width, 100vw) / 2) !important;
}

#v8-os-container .v8-window:not(.maximized):not(.minimized),
.v8-os-environment .v8-window:not(.maximized):not(.minimized) {
  max-width: calc(var(--v8-shell-container-width, 100vw) - 16px);
  max-height: var(--v8-shell-usable-height, calc(100dvh - var(--v8-shell-bottom-reserve, 74px)));
}

#v8-os-container .v8-start-menu.active,
#v8-os-container .v8-status-panel.active,
#v8-os-container .v8-shell-tools-popout.active,
.v8-os-environment .v8-start-menu.active,
.v8-os-environment .v8-status-panel.active,
.v8-os-environment .v8-shell-tools-popout.active {
  max-height: max(180px, calc(var(--v8-shell-usable-height, 70dvh) - 16px));
  overflow: auto;
  overscroll-behavior: contain;
}

/* v1.6.704: admin/debug overlays use their own stable overlay anchor;
 * do not make them ride the live viewport bottom-reserve measurement. */
#v8e-debug-panel[data-v8-no-surface-autoclamp="1"],
#v8e-admin-panel[data-v8-no-surface-autoclamp="1"] {
  will-change: auto;
}
