
/* oMATIC Minds v0.6.8.82 Image Studio emergency mobile stability.
   CSS-only patch. No MutationObserver/mobile ordering JavaScript.
   Purpose: stop mobile page freezes from the prior JS controller and keep the
   composer/reference/status areas usable with static CSS only.
*/

@media (max-width: 640px) {
  body.om-image-studio-route .om-image-studio-messages,
  body.om-image-studio-route.om-chat-shell-route .om-chat-messages {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain !important;
    padding-bottom: 300px !important;
    scroll-padding-bottom: 300px !important;
  }

  body.om-image-studio-route .om-image-studio-messages > .om-image-generation-grid,
  body.om-image-studio-route.om-chat-shell-route .om-chat-messages > .om-image-generation-grid,
  body.om-image-studio-route .om-image-generation-grid {
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    gap: 18px !important;
    overflow: visible !important;
    touch-action: pan-y !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
  }

  body.om-image-studio-route .om-image-generation-grid > .om-image-generation-card,
  body.om-image-studio-route .om-image-generation-grid > .om-image-generation-card.chatgpt-style {
    order: 0 !important;
    flex: 0 0 auto !important;
  }

  body.om-image-phone-composer-closed.om-image-studio-route .om-image-studio-messages,
  body.om-image-phone-composer-closed.om-image-studio-route.om-chat-shell-route .om-chat-messages {
    padding-bottom: 380px !important;
    scroll-padding-bottom: 380px !important;
  }

  body.om-image-phone-composer-closed.om-image-studio-route .om-image-generation-grid {
    padding-bottom: 250px !important;
  }

  body.om-image-phone-composer-closed.om-image-studio-route .om-image-generation-grid > .om-image-generation-card:last-child,
  body.om-image-phone-composer-closed.om-image-studio-route .om-image-generation-grid > .om-image-generation-card.chatgpt-style:last-child {
    margin-bottom: 190px !important;
  }

  body.om-image-phone-composer-closed.om-image-studio-route .om-image-phone-composer-toggle {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px) !important;
    transform: translateX(-50%) !important;
    width: min(260px, calc(100vw - 110px)) !important;
    max-width: min(260px, calc(100vw - 110px)) !important;
    z-index: 220 !important;
  }

  /* Mobile reference tray: hide the internal stage add button that was clipping/peeking.
     The dedicated "Upload reference image" button below remains the add action. */
  body.om-image-studio-route .om-image-studio-composer-shell.has-image-references #image-reference-stage.om-image-reference-stage-card {
    min-height: 198px !important;
    padding: 12px !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell.has-image-references #image-reference-stage .om-image-reference-stage-actions {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    justify-content: center !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell.has-image-references #image-reference-stage .om-image-reference-stage-actions .status-pill {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    text-align: center !important;
    justify-content: center !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell.has-image-references #image-reference-stage .om-image-reference-stage-actions button,
  body.om-image-studio-route .om-image-studio-composer-shell.has-image-references #image-reference-stage button[data-image-reference-trigger] {
    display: none !important;
  }

  /* Make submit/reply/error notice inline under the admin confirmation row. */
  body.om-image-studio-route .om-image-studio-composer-shell .om-image-live-confirm-row {
    position: static !important;
    order: 2 !important;
    width: 100% !important;
    margin: 2px 0 0 !important;
    z-index: 2 !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell .om-image-generation-submit-status {
    position: static !important;
    order: 3 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 8px 0 0 !important;
    z-index: 1 !important;
    transform: none !important;
    pointer-events: none !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell .om-image-generation-submit-status[hidden] {
    display: none !important;
  }

  body.om-image-studio-route .om-image-studio-composer-shell #om-image-studio-generate-form {
    order: 4 !important;
  }
}
