/* Rex Ultra owner-requested phone polish, 2026-10-29.
   Self-contained mobile override. Desktop/tablet layouts above 700px are untouched. */
@media (max-width:700px){
  html,body{max-width:100%;overflow-x:hidden!important}

  /* Workspace shell: replace desktop wrapping with three calm phone rows. */
  #workspace:not(.rex-window-active)>.workspace-head{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) minmax(108px,145px) 40px!important;
    grid-template-rows:auto auto!important;
    align-items:center!important;
    gap:6px!important;
    width:100%!important;
    min-height:0!important;
    height:auto!important;
    padding:7px 6px 8px!important;
    margin:0!important;
    overflow:visible!important;
    background:#071321!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head>div:first-child{
    grid-column:1!important;
    grid-row:1!important;
    min-width:0!important;
    overflow:hidden!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head .workspace-kicker{display:none!important}
  #workspace:not(.rex-window-active)>.workspace-head #workspaceTitle{
    margin:0!important;
    font-size:13px!important;
    line-height:1.2!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  /* Desktop-size duplicates do not belong in the phone header. */
  #workspace:not(.rex-window-active)>.workspace-head>#rexWorkspaceHome,
  #workspace:not(.rex-window-active)>.workspace-head>#workspaceExpand,
  #workspace:not(.rex-window-active)>.workspace-head>#desktopConnectWorkspace,
  #workspace:not(.rex-window-active)>.workspace-head>#openConnectDirect,
  #workspace:not(.rex-window-active)>.workspace-head>#runtimeConnectionStatus{
    display:none!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head>#runtimeConnectionStatus:not([hidden]){
    display:none!important;
  }

  /* BigRex is the obvious owner control, directly beneath the title. */
  #workspace #bigRexWorkspaceSwitch:not([hidden]),
  #workspace .rex-bigrex-switch:not([hidden]){
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    border:1px solid #e0c26d!important;
    border-radius:11px!important;
    background:linear-gradient(135deg,#705414,#bd9635)!important;
    color:#fff7d6!important;
    box-shadow:0 0 18px #d8ad3a26!important;
    font-weight:900!important;
    letter-spacing:.035em!important;
    text-align:center!important;
    visibility:visible!important;
    opacity:1!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head>#bigRexWorkspaceSwitch:not([hidden]){
    grid-column:1/-1!important;
    grid-row:2!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    min-height:42px!important;
    margin:0!important;
    padding:8px 10px!important;
    font-size:11px!important;
    line-height:1.15!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head>#closeWorkspace{
    grid-column:3!important;
    grid-row:1!important;
    width:40px!important;
    height:40px!important;
    min-width:40px!important;
    min-height:40px!important;
    padding:0!important;
    border-radius:11px!important;
    font-size:0!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head>#closeWorkspace:after{
    content:"×";
    font-size:22px;
    line-height:1;
  }

  /* Keep mobile desktop authorization available, but stop it dominating the screen. */
  #workspace:not(.rex-window-active)>.workspace-head #rexPhoneApprovals{
    grid-column:2!important;
    grid-row:1!important;
    display:flex!important;
    align-items:center!important;
    width:100%!important;
    min-width:0!important;
    max-width:145px!important;
    margin:0!important;
    gap:0!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head #rexPhoneControlToggle{
    width:100%!important;
    min-width:0!important;
    min-height:38px!important;
    padding:5px 7px!important;
    border-radius:10px!important;
    font-size:8px!important;
    line-height:1.05!important;
    white-space:normal!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head #rexPhoneApprovalMessage{
    display:none!important;
  }
  #rexPhoneApprovals + details{display:none!important}
  #workspace:not(.rex-window-active)>.workspace-head>#rexDesktopControlLiveStatus,
  #workspace:not(.rex-window-active)>.workspace-head>#rexNavV7{
    display:none!important;
  }

  /* Tool modes become a swipe rail instead of a wall of pills. */
  #workspace:not(.rex-window-active)>.workspace-modes{
    display:flex!important;
    flex-wrap:nowrap!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    gap:7px!important;
    margin:7px -2px 3px!important;
    padding:3px 2px 7px!important;
    scrollbar-width:none;
    -webkit-overflow-scrolling:touch;
    scroll-snap-type:x proximity;
  }
  #workspace:not(.rex-window-active)>.workspace-modes::-webkit-scrollbar{display:none}
  #workspace:not(.rex-window-active)>.workspace-modes>button,
  #workspace:not(.rex-window-active)>.workspace-modes>a{
    flex:0 0 auto!important;
    min-height:38px!important;
    padding:8px 11px!important;
    font-size:9px!important;
    scroll-snap-align:start;
  }

  /* Chat: BigRex owns the primary row. Rex, Browser and Workspace remain below it. */
  #chatWorkspace.rex-chat-v8 .rex-v8-main{
    grid-template-rows:auto minmax(0,1fr) auto!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header{
    display:grid!important;
    grid-template-columns:40px minmax(0,1fr)!important;
    align-items:start!important;
    gap:6px!important;
    padding:6px 8px!important;
    min-width:0!important;
    min-height:0!important;
    overflow:hidden!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-left{
    grid-column:1!important;
    grid-row:1!important;
    display:flex!important;
    width:40px!important;
    min-width:40px!important;
    align-items:center!important;
    align-self:start!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-menu-button{
    width:40px!important;
    height:40px!important;
    min-width:40px!important;
    min-height:40px!important;
    padding:0!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right{
    grid-column:2!important;
    grid-row:1!important;
    display:grid!important;
    grid-template-columns:minmax(68px,1fr) auto auto!important;
    align-items:stretch!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    gap:5px!important;
    padding:0!important;
    overflow:hidden!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-bigrex-switch:not([hidden]){
    grid-column:1/-1!important;
    grid-row:1!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    min-height:40px!important;
    margin:0!important;
    padding:7px 9px!important;
    font-size:10px!important;
    line-height:1.15!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v9-agent-select{
    grid-column:1!important;
    grid-row:2!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    min-height:36px!important;
    font-size:10px!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-browser-button{
    grid-column:2!important;
    grid-row:2!important;
    display:flex!important;
    min-height:36px!important;
    padding:6px 8px!important;
    font-size:9px!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-workspace-return{
    grid-column:3!important;
    grid-row:2!important;
    display:flex!important;
    min-height:36px!important;
    padding:6px 8px!important;
    font-size:9px!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v9-watch-button,
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-job-button,
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-desktop-button{
    display:none!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-compose{
    padding:8px 8px max(9px,env(safe-area-inset-bottom))!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-compose-inner{border-radius:16px!important}
  #chatWorkspace.rex-chat-v8 #workspaceChatInput{
    min-height:50px!important;
    height:58px!important;
  }

  /* Google Home: one control and one card per row. */
  #workspace #rexHomeV7{
    width:100%!important;
    max-width:100%!important;
    padding:12px!important;
    border-radius:15px!important;
    gap:12px!important;
    overflow-x:hidden!important;
  }
  #workspace #rexHomeV7 h3,
  #workspace .rex-v7-phone h3{
    font-size:22px!important;
    line-height:1.2!important;
    margin:4px 0 6px!important;
  }
  #workspace .rex-v7-hero p,
  #workspace .rex-v7-hint{
    font-size:12px!important;
    line-height:1.5!important;
  }
  #workspace #rexHomeV7 .rex-v7-controls,
  #workspace #rexHomeV7 .rex-v7-fields,
  #workspace #rexHomeV7 .rex-v7-tiles,
  #workspace .rex-v7-controls,
  #workspace .rex-v7-fields,
  #workspace .rex-v7-tiles{
    display:grid!important;
    grid-template-columns:minmax(0,1fr)!important;
    gap:8px!important;
    width:100%!important;
  }
  #workspace #rexHomeV7 .rex-v7-controls>button,
  #workspace #rexHomeV7 .rex-v7-controls>button:nth-child(1),
  #workspace #rexHomeV7 .rex-v7-controls>button:nth-child(2),
  #workspace #rexHomeV7 .rex-v7-controls>button:last-child,
  #workspace .rex-v7-controls button,
  #workspace .rex-v7-controls button:last-child,
  #workspace .rex-v7-phone button,
  #workspace #rexHomeV7>button{
    grid-column:auto!important;
    grid-row:auto!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    min-height:46px!important;
    padding:10px 12px!important;
    font-size:11px!important;
    line-height:1.25!important;
    white-space:normal!important;
  }
  #workspace #rexHomeV7 .rex-v7-tile,
  #workspace .rex-v7-tile{
    width:100%!important;
    min-height:0!important;
    padding:12px!important;
    border-radius:12px!important;
  }
  #workspace .rex-v7-status,
  #workspace .rex-v7-readiness{
    padding:10px!important;
    font-size:11px!important;
    line-height:1.5!important;
  }
  #workspace .rex-v7-phone{
    padding:12px!important;
    border-radius:14px!important;
  }

  /* Full-screen mode: side rail overlays rather than stealing phone width. */
  #workspace.rex-window-active[data-rex-window-mode]{
    --rex-window-header:54px;
    --rex-window-rail:0px!important;
  }
  #workspace.rex-window-active[data-rex-window-mode]>.workspace-head{
    padding:0 8px!important;
    gap:5px!important;
  }
  #workspace.rex-window-active.rex-sidebar-open[data-rex-window-mode]>.workspace-modes{
    width:min(238px,84vw)!important;
    z-index:8!important;
    box-shadow:16px 0 42px #000a!important;
  }
  #rexWindowControls{gap:4px!important;min-width:0!important}
  #rexWindowControls button{
    min-height:36px!important;
    padding:6px 7px!important;
    font-size:9px!important;
  }
}

@media (max-width:380px){
  #workspace:not(.rex-window-active)>.workspace-head{
    grid-template-columns:minmax(0,1fr) minmax(96px,128px) 38px!important;
    gap:5px!important;
  }
  #workspace:not(.rex-window-active)>.workspace-head #workspaceTitle{font-size:12px!important}
  #chatWorkspace.rex-chat-v8 .rex-v8-header{
    grid-template-columns:38px minmax(0,1fr)!important;
    padding-left:6px!important;
    padding-right:6px!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-left,
  #chatWorkspace.rex-chat-v8 .rex-v8-menu-button{
    width:38px!important;
    min-width:38px!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right{
    grid-template-columns:minmax(62px,1fr) auto!important;
  }
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-browser-button{display:none!important}
  #chatWorkspace.rex-chat-v8 .rex-v8-header-right>.rex-v10-workspace-return{grid-column:2!important}
}