/* V6.4.4 — Mobile Polish & Stabilisation. Loaded last on purpose. */
@media (max-width:760px){
  :root{--v644-bottom-nav:calc(70px + env(safe-area-inset-bottom))}

  /* Every scrollable view must be able to clear the fixed bottom navigation. */
  main{padding-bottom:calc(var(--v644-bottom-nav) + 28px)!important}
  .view{padding-bottom:18px}
  .listing-grid,#sellRows,#exportGrid,.stock-visual-grid,#needsRows,#opportunitiesRows{padding-bottom:calc(var(--v644-bottom-nav) + 18px)!important}

  /* Messaging: compact screens always start as a visible inbox; chat owns the remaining viewport. */
  #messages{min-height:0!important;padding-bottom:calc(var(--v644-bottom-nav) + 8px)!important}
  #messages .messages{display:block!important;height:calc(100dvh - 205px - env(safe-area-inset-bottom))!important;min-height:300px!important;max-height:none!important;overflow:hidden!important}
  #messages .thread-list{display:block!important;visibility:visible!important;opacity:1!important;height:100%!important;min-height:0!important;overflow-y:auto!important;-webkit-overflow-scrolling:touch}
  #messages .thread-list .thread{display:block!important}
  #messages.mobile-chat-open .thread-list{display:none!important}
  #messages .chat{height:100%!important;min-height:0!important}
  #messages.mobile-chat-open .chat{display:grid!important;grid-template-rows:auto minmax(0,1fr) auto!important}
  #messages .chat-body{min-height:0!important;overflow-y:auto!important;-webkit-overflow-scrolling:touch}
  #messages .composer{position:relative!important;bottom:auto!important;flex:0 0 auto!important;padding-bottom:max(10px,env(safe-area-inset-bottom))!important}

  /* The real application modal is .modal-box (not .modal-card). Keep its actions reachable. */
  .modal{padding:0!important;align-items:stretch!important;justify-content:center!important;overflow:hidden!important}
  .modal-box{width:100%!important;max-width:none!important;height:100dvh!important;max-height:100dvh!important;border-radius:0!important;display:flex!important;flex-direction:column!important;overflow:hidden!important}
  .modal-head{flex:0 0 auto!important;padding:max(14px,env(safe-area-inset-top)) 16px 14px!important;background:var(--panel)!important;z-index:2}
  .modal-box .form{flex:1 1 auto!important;min-height:0!important;overflow-y:auto!important;-webkit-overflow-scrolling:touch!important;padding:14px 16px calc(var(--v644-bottom-nav) + 34px)!important;scroll-padding-bottom:calc(var(--v644-bottom-nav) + 34px)!important}
  .modal-box .form-actions{position:sticky!important;bottom:0!important;z-index:4!important;margin:12px -16px calc(-1 * (var(--v644-bottom-nav) + 34px))!important;padding:12px 16px calc(var(--v644-bottom-nav) + 12px)!important;background:linear-gradient(to bottom,rgba(255,255,255,.94),#fff 18px)!important;border-top:1px solid var(--line)!important}
  .modal-box .form-actions button{min-height:44px!important}
}

/* Short phones need vertical space more than decorative spacing. */
@media (max-width:760px) and (max-height:700px){
  #messages>.page-head{margin-bottom:8px!important}
  #messages>.page-head h1{font-size:27px!important}
  #messages>.page-head p{margin-bottom:0!important}
  #messages .messages{height:calc(100dvh - 190px - env(safe-area-inset-bottom))!important;min-height:270px!important}
  .modal-head{padding-top:12px!important;padding-bottom:10px!important}
}
