/* Morpheus PD Central V135.3 — mobile workspace and loader stability
   Presentation only. No form, permission, Supabase, task-audience or workflow changes. */

/* --------------------------------------------------------------------------
   Stable portal entry viewport
   The older loader inherited 24px padding from .booting while its child also
   requested 100dvh. Mobile browser chrome changes then made the page jump.
   -------------------------------------------------------------------------- */
html:has(#app.booting),
body:has(#app.booting){
  width:100%;
  height:100%;
  min-height:100%;
  margin:0;
  overflow:hidden!important;
  overscroll-behavior:none;
  background:#06111f!important;
}
#app.booting{
  position:fixed!important;
  inset:0!important;
  width:100vw!important;
  height:100vh!important;
  height:100svh!important;
  min-height:0!important;
  max-height:100svh!important;
  margin:0!important;
  padding:0!important;
  display:block!important;
  overflow:hidden!important;
  background:#06111f!important;
}
#app.booting .portal-entry{
  width:100%!important;
  height:100%!important;
  min-height:0!important;
  max-height:100%!important;
  overflow:hidden!important;
}
#app.booting .portal-entry-panel>p{
  min-height:2.8em!important;
  max-height:2.8em!important;
  overflow:hidden!important;
}
#app.booting .portal-entry-readout{
  min-width:0!important;
}
#app.booting .portal-entry-readout>span{
  min-width:0!important;
  max-width:100%!important;
  white-space:nowrap!important;
  overflow:hidden!important;
  text-overflow:ellipsis!important;
}
#app.booting .portal-entry-readout>strong{
  flex:0 0 auto!important;
  white-space:nowrap!important;
}

/* --------------------------------------------------------------------------
   Admin portal-view selector
   Never allow the label or selected option to collapse into vertical letters.
   -------------------------------------------------------------------------- */
.admin-preview-select,
.admin-preview-select>span,
.admin-preview-select>select{
  writing-mode:horizontal-tb!important;
  text-orientation:mixed!important;
  word-break:keep-all!important;
  overflow-wrap:normal!important;
  white-space:nowrap!important;
}

@media(max-width:900px){
  .top-actions{min-width:0!important;overflow-x:auto!important;overflow-y:hidden!important;scrollbar-width:none;}
  .top-actions::-webkit-scrollbar{display:none;}
  .top-actions>*{flex:0 0 auto!important;}
  .admin-preview-select{
    width:auto!important;
    min-width:0!important;
    max-width:none!important;
    flex:0 0 auto!important;
    padding:5px 7px!important;
    gap:0!important;
    overflow:visible!important;
  }
  .admin-preview-select>span{display:none!important;}
  .admin-preview-select>select{
    width:auto!important;
    min-width:136px!important;
    max-width:156px!important;
    padding:7px 28px 7px 9px!important;
    font-size:14px!important;
    line-height:1.2!important;
  }
}

/* --------------------------------------------------------------------------
   Company / project command windows on phones
   These workspaces are appended directly to body, outside #app. Older mobile
   rules scoped under #app therefore missed them and left the desktop rail in a
   narrow column. This final layer deliberately targets the body-level modal.
   -------------------------------------------------------------------------- */
@media(max-width:760px){
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329){
    inset:0!important;
    width:100vw!important;
    height:100vh!important;
    height:100dvh!important;
    min-height:0!important;
    margin:0!important;
    padding:0!important;
    display:block!important;
    overflow:hidden!important;
    background:rgba(2,6,23,.72)!important;
    backdrop-filter:none!important;
    -webkit-backdrop-filter:none!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329)>.o2-modal.modal-workspace-command{
    position:absolute!important;
    inset:0!important;
    width:100vw!important;
    max-width:100vw!important;
    height:100vh!important;
    height:100dvh!important;
    max-height:100dvh!important;
    min-width:0!important;
    min-height:0!important;
    margin:0!important;
    border:0!important;
    border-radius:0!important;
    box-shadow:none!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329)>.o2-modal.modal-workspace-command>header{
    position:relative!important;
    inset:auto!important;
    flex:0 0 auto!important;
    width:100%!important;
    min-width:0!important;
    min-height:66px!important;
    height:auto!important;
    padding:10px 14px!important;
    gap:10px!important;
    border-radius:0!important;
    z-index:12!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .modal-title-stack{
    min-width:0!important;
    max-width:calc(100% - 58px)!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .modal-title-stack>span,
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .modal-title-stack>h2{
    display:block!important;
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    writing-mode:horizontal-tb!important;
    text-orientation:mixed!important;
    word-break:normal!important;
    overflow-wrap:break-word!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .modal-title-stack>h2{
    margin:2px 0 0!important;
    font-size:clamp(20px,6.4vw,28px)!important;
    line-height:1.05!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) button[data-action="closeModal"]{
    flex:0 0 48px!important;
    width:48px!important;
    height:48px!important;
    min-width:48px!important;
    min-height:48px!important;
    margin:0!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329)>.o2-modal.modal-workspace-command>.modal-body{
    position:relative!important;
    flex:1 1 auto!important;
    width:100%!important;
    height:auto!important;
    min-width:0!important;
    min-height:0!important;
    max-width:100%!important;
    max-height:none!important;
    padding:0!important;
    overflow:hidden!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-room-v13329{
    display:block!important;
    grid-template-columns:minmax(0,1fr)!important;
    width:100%!important;
    height:100%!important;
    min-width:0!important;
    min-height:0!important;
    max-width:100%!important;
    max-height:100%!important;
    overflow:hidden!important;
  }

  /* The desktop context rail is the direct cause of one-letter columns. */
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-rail{
    display:none!important;
    visibility:hidden!important;
    width:0!important;
    min-width:0!important;
    max-width:0!important;
    height:0!important;
    min-height:0!important;
    margin:0!important;
    padding:0!important;
    border:0!important;
    overflow:hidden!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-main{
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    height:100%!important;
    min-width:0!important;
    min-height:0!important;
    max-width:100%!important;
    overflow:hidden!important;
  }

  /* Keep admin controls usable without taking a large block of phone height. */
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-strip{
    flex:0 0 auto!important;
    width:100%!important;
    min-width:0!important;
    margin:0!important;
    padding:8px 10px!important;
    border-width:0 0 1px!important;
    border-radius:0!important;
    overflow:hidden!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-strip>div:first-child{
    display:none!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-buttons{
    display:flex!important;
    flex-wrap:nowrap!important;
    align-items:center!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    gap:8px!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    padding:1px 0 4px!important;
    scrollbar-width:none;
    -webkit-overflow-scrolling:touch;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-buttons::-webkit-scrollbar{display:none!important;}
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-buttons>:where(button,.btn,a){
    flex:0 0 auto!important;
    min-width:max-content!important;
    width:auto!important;
    min-height:44px!important;
    padding:0 15px!important;
    white-space:nowrap!important;
    writing-mode:horizontal-tb!important;
    word-break:keep-all!important;
    overflow-wrap:normal!important;
  }

  /* Fixed horizontal tab rail, then one independent vertical content scroller. */
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-toolbar{
    flex:0 0 auto!important;
    display:flex!important;
    flex-wrap:nowrap!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    min-height:58px!important;
    margin:0!important;
    padding:7px 8px!important;
    gap:7px!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    border-radius:0!important;
    scrollbar-width:none;
    -webkit-overflow-scrolling:touch;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-toolbar::-webkit-scrollbar{display:none!important;}
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-tab{
    flex:0 0 auto!important;
    width:auto!important;
    min-width:max-content!important;
    max-width:none!important;
    min-height:42px!important;
    padding:0 14px!important;
    white-space:nowrap!important;
    writing-mode:horizontal-tb!important;
    word-break:keep-all!important;
    overflow-wrap:normal!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-content{
    flex:1 1 auto!important;
    width:100%!important;
    min-width:0!important;
    min-height:0!important;
    max-width:100%!important;
    max-height:none!important;
    margin:0!important;
    padding:10px 10px calc(24px + env(safe-area-inset-bottom))!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-content>*{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }

  /* All main company/project workspace layouts become a true single column. */
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) :where(
    .command-overview-hero,
    .command-overview-layout,
    .command-overview-primary,
    .command-overview-side,
    .command-work-grid,
    .workspace-live-grid,
    .workspace-closed-grid,
    .project-room-record-grid,
    .company-project-grid,
    .company-assets-grid,
    .company-finance-adapted,
    .project-finance-adapted-v11033,
    .finance-split,
    .workspace-files-split,
    .company-tab-smart-shell,
    .project-tab-smart-shell
  ){
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    grid-template-columns:minmax(0,1fr)!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-overview-side{
    display:grid!important;
    gap:12px!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-side-card.movement{
    grid-column:auto!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .project-context-strip{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-overview-kpis{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }

  /* Stop any remaining title, card or record label becoming a vertical word. */
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-room-v13329 :where(
    h1,h2,h3,h4,h5,h6,p,label,legend,span,strong,b,small,em,dt,dd,button,a
  ){
    min-width:0!important;
    max-width:100%!important;
    writing-mode:horizontal-tb!important;
    text-orientation:mixed!important;
    word-break:normal!important;
    overflow-wrap:break-word!important;
    hyphens:none!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .command-room-v13329 :where(
    .workspace-tab,.btn,.chip,.pill,.tag,.badge,.status-pill
  ){
    white-space:nowrap!important;
    word-break:keep-all!important;
    overflow-wrap:normal!important;
  }

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) :where(
    .command-work-lane,.command-side-card,.command-media-section,.command-archive,
    .workspace-live-closed-shell,.workspace-closed-accordion,.finance-bucket,
    .project-room-panel,.company-tab-smart-shell,.project-tab-smart-shell
  ){
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    overflow:hidden!important;
  }
}

@media(max-width:420px){
  #app.booting .portal-entry{
    padding:10px!important;
    gap:10px!important;
  }
  #app.booting .portal-gate{
    width:min(54vw,188px)!important;
  }
  #app.booting .portal-entry-panel{
    padding:18px 15px!important;
    border-radius:23px!important;
  }
  #app.booting .portal-entry-panel h1{
    font-size:clamp(31px,9.5vw,37px)!important;
  }
  #app.booting .portal-entry-kicker{margin-bottom:14px!important;}
  #app.booting .portal-entry-readout{margin-top:15px!important;}
  #app.booting .portal-entry-stages{margin-top:13px!important;gap:6px!important;}

  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329)>.o2-modal.modal-workspace-command>header{
    min-height:62px!important;
    padding:8px 10px!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .modal-title-stack>h2{
    font-size:clamp(19px,6vw,24px)!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) button[data-action="closeModal"]{
    flex-basis:44px!important;
    width:44px!important;
    height:44px!important;
    min-width:44px!important;
    min-height:44px!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .admin-action-buttons>:where(button,.btn,a){
    min-height:42px!important;
    padding:0 13px!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-tab{
    min-height:40px!important;
    padding:0 12px!important;
  }
  body>.modal-wrap.o2-modal-wrap:has(.command-room-v13329) .workspace-page-content{
    padding-left:8px!important;
    padding-right:8px!important;
  }
}

@media(max-height:620px) and (orientation:landscape){
  #app.booting .portal-entry{
    grid-template-columns:minmax(180px,240px) minmax(320px,560px)!important;
    gap:18px!important;
    padding:10px 18px!important;
  }
  #app.booting .portal-gate{width:min(38vh,220px)!important;}
  #app.booting .portal-entry-panel{padding:18px!important;}
  #app.booting .portal-entry-panel h1{font-size:34px!important;}
  #app.booting .portal-entry-kicker{margin-bottom:12px!important;}
  #app.booting .portal-entry-readout{margin-top:14px!important;}
  #app.booting .portal-entry-stages{margin-top:12px!important;}
  #app.booting .portal-entry-panel small{margin-top:12px!important;}
}
