/* ALPHATRADE_SITEWIDE_MOBILE_FOUNDATION_V2
   Mobile-only responsive overrides. Desktop remains unchanged. */

@media (max-width: 900px){
  html,body{max-width:100%;overflow-x:hidden}
  body{min-width:0}
  *,*::before,*::after{box-sizing:border-box}

  img,svg,canvas,video{max-width:100%;height:auto}
  pre,code{max-width:100%;overflow-wrap:anywhere}
  input,select,textarea,button{max-width:100%}

  .page,.main,.content,.container,.shell,.app-main,.dashboard-main{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
  }

  .panel,.card,.vizcard,.execcard,.diag,.intelcard,.regcard,
  .controlbox,.scorebox,.expbox,.expvariant,.queuecard,.watchbox,
  .historybox,.shadowbox,.small-stat{
    min-width:0!important;
    max-width:100%!important;
  }

  .cards,.summary,.execgrid,.vizgrid,.controlgrid,.scorecardgrid,
  .expgrid,.expvariants,.shadowgrid,.historygrid,.intelgrid,
  .registrygrid,.queuegrid,.two,.grid,.stats-grid,.kpi-grid{
    min-width:0!important;
  }

  .table-scroll,.tablewrap,.table-wrap,.healthmatrix,.opp-table-wrap{
    width:100%!important;
    max-width:100%!important;
    overflow-x:auto!important;
    overflow-y:auto;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:thin;
  }

  table{max-width:none}
  th,td{white-space:nowrap}

  #tabs,.viewtabs,.filters,.toolbar,.tabbar,.tabs,.nav-tabs{
    max-width:100%!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    flex-wrap:nowrap!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  #tabs::-webkit-scrollbar,.viewtabs::-webkit-scrollbar,.filters::-webkit-scrollbar,
  .toolbar::-webkit-scrollbar,.tabbar::-webkit-scrollbar,.tabs::-webkit-scrollbar,
  .nav-tabs::-webkit-scrollbar{display:none}
  #tabs button,.viewtabs button,.filters button,.tabbar button,.tabs button,.nav-tabs button{
    flex:0 0 auto!important;
    min-height:42px;
    touch-action:manipulation;
  }

  button,.btn,a.back,.sign-in{
    min-height:40px;
    touch-action:manipulation;
  }

  .modal,.dialog,.popover,.dropdown,.v6-notification-panel{
    max-width:calc(100vw - 24px)!important;
    max-height:calc(100vh - 24px)!important;
  }
}

@media (max-width: 768px){
  body{font-size:14px}

  .page{padding:12px!important}
  .panel{padding:12px!important;margin-top:10px!important;border-radius:12px!important}
  .panelhead{gap:8px!important;align-items:flex-start!important}
  .panelhead h2{font-size:15px!important;line-height:1.25}
  .panelhead p{font-size:10px!important;line-height:1.45}

  .hero{padding:15px!important;border-radius:14px!important}
  .hero h1{font-size:25px!important;line-height:1.12!important}

  .cards,.vizgrid,.execgrid,.two,.expvariants{
    grid-template-columns:1fr!important;
  }
  .summary,.controlgrid,.scorecardgrid,.expgrid,.shadowgrid,.historygrid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  .intelgrid,.registrygrid,.queuegrid{
    grid-template-columns:1fr!important;
  }

  .top,.topbar,.header,.page-head{
    gap:8px!important;
  }

  body:not(.v6page) .sidebar{
    max-width:min(86vw,320px)!important;
  }

  body.v6page .sidebar{
    width:100%!important;
    max-width:100%!important;
  }

  .status-rail,.top-meta{
    min-width:0!important;
  }

  .chart-container,.chart-wrap,.chart-card,.chart{
    min-height:220px!important;
    max-height:none!important;
  }

  .alert-item,.reco{
    grid-template-columns:1fr!important;
  }

  .reason,.portfolio-row,.shadowobs{
    grid-template-columns:1fr!important;
  }

  .donutwrap{
    flex-direction:column!important;
    align-items:flex-start!important;
  }
}

@media (max-width: 520px){
  .page{padding:9px!important}
  .panel{padding:10px!important}

  .summary,.controlgrid,.scorecardgrid,.expgrid,.shadowgrid,.historygrid{
    grid-template-columns:1fr!important;
  }

  .hero{align-items:flex-start!important;flex-direction:column!important}
  .hero h1{font-size:22px!important}
  .hero p{font-size:11px!important}

  .top{
    align-items:flex-start!important;
    flex-wrap:wrap!important;
  }
  .top .back{margin-left:auto}

  .cards{gap:8px!important}
  .card,.execcard,.controlbox,.scorebox,.expbox,.historybox,.shadowbox{
    padding:11px!important;
  }

  table{font-size:10px!important}
  th,td{padding:8px 7px!important}

  input,select,textarea{
    font-size:16px!important; /* prevents iOS zoom */
  }

  .modal-actions{
    display:grid!important;
    grid-template-columns:1fr!important;
  }

  .toast{
    left:10px!important;
    right:10px!important;
    bottom:10px!important;
    width:auto!important;
    max-width:none!important;
  }
}

/* Page-specific mobile fixes */
@media (max-width: 768px){
  /* V6 + Stocks professional consoles */
  .safe{
    flex-wrap:wrap!important;
    gap:6px!important;
    padding:8px 10px!important;
  }
  #tabs{
    padding-bottom:4px!important;
    gap:5px!important;
  }
  #tabs button{
    padding:9px 11px!important;
    font-size:11px!important;
  }

  /* Research & Stability */
  .viewtabs{width:100%!important}
  .viewtabs button{flex:1 0 auto!important}
  .barrow{
    grid-template-columns:90px minmax(90px,1fr) 38px!important;
  }
  .healthmatrix table{min-width:900px!important}

  /* Platform hub */
  .platform-grid,.platforms,.hub-grid{
    grid-template-columns:1fr!important;
  }

  /* Dashboard */
  .app{min-width:0!important}
  .main{margin-left:0!important}
  .topbar{padding-left:10px!important;padding-right:10px!important}
  .top-meta{display:none!important}
}

@media (max-width: 420px){
  .barrow{grid-template-columns:78px minmax(70px,1fr) 34px!important;font-size:8px!important}
  .paper-badge{font-size:9px!important;padding:5px 7px!important}
}


/* V6 / STOCKS MOBILE PATCH V2.1 — screenshot fixes */
@media (max-width: 760px){
  html{
    -webkit-text-size-adjust:100%!important;
    text-size-adjust:100%!important;
  }

  body.v6page,
  body.v6page .layout,
  body.v6page .sidebar,
  body.v6page .main{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
  }

  body.v6page .sidebar{
    margin:0!important;
    left:0!important;
    right:0!important;
  }

  body.v6page #tabs{
    width:100vw!important;
    max-width:100vw!important;
    margin-left:0!important;
    margin-right:0!important;
    padding-right:10px!important;
  }

  body.v6page #tab-overview > .grid2:has(#overview-open) > .panel > .panelhead{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:start!important;
    gap:10px!important;
    padding:12px!important;
  }

  body.v6page #tab-overview > .grid2:has(#overview-open) .panelhead h2{
    font-size:17px!important;
    line-height:1.2!important;
    white-space:nowrap!important;
  }

  body.v6page #tab-overview .overview-count{
    font-size:17px!important;
    white-space:nowrap!important;
  }

  body.v6page #tab-overview > .grid2:has(#overview-open) .panelhead p{
    margin-top:4px!important;
    font-size:10px!important;
    line-height:1.4!important;
    max-width:220px!important;
  }

  body.v6page #tab-overview .overview-total-pnl{
    min-width:0!important;
    width:auto!important;
    align-items:flex-end!important;
  }

  body.v6page #tab-overview .overview-total-pnl strong{
    font-size:19px!important;
    line-height:1.1!important;
  }

  body.v6page #tab-overview .overview-total-pnl small{
    max-width:145px!important;
    text-align:right!important;
    font-size:9px!important;
    line-height:1.3!important;
    white-space:normal!important;
  }

  body.v6page #tab-overview .overview-source-filter{
    width:145px!important;
    min-width:145px!important;
    max-width:145px!important;
    height:38px!important;
    padding:0 30px 0 10px!important;
    font-size:10px!important;
  }

  body.v6page .overview-expanded-table{
    width:100%!important;
    max-width:100%!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch!important;
  }

  body.v6page .overview-expanded-footer{
    gap:8px!important;
    flex-wrap:wrap!important;
  }
}

@media (max-width: 430px){
  body.v6page #tab-overview > .grid2:has(#overview-open) > .panel > .panelhead{
    grid-template-columns:1fr!important;
  }

  body.v6page #tab-overview .overview-total-pnl{
    align-items:flex-start!important;
  }

  body.v6page #tab-overview .overview-total-pnl small{
    max-width:none!important;
    text-align:left!important;
  }

  body.v6page #tab-overview .overview-source-filter{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }
}


/* MOBILE KPI + PLATFORM HUB UNIFICATION V2.2 */
@media (max-width:760px){
  body.v6page .sidebar .back,
  body.v6page a.back,
  .page a.back{
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:7px!important;
    min-height:38px!important;
    padding:0 11px!important;
    border:1px solid rgba(111,140,180,.18)!important;
    border-radius:10px!important;
    background:rgba(255,255,255,.025)!important;
    color:#c9d7e8!important;
    text-decoration:none!important;
    font-size:10px!important;
    font-weight:750!important;
    white-space:nowrap!important;
  }

  body.v6page .sidebar .back{
    width:max-content!important;
    max-width:100%!important;
    margin:0!important;
  }

  body.v6page #tab-overview > #summary.cards{
    display:block!important;
    width:100%!important;
    max-width:100%!important;
    overflow:visible!important;
  }

  body.v6page .kpi-strip-v3{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    width:100%!important;
    min-height:0!important;
    gap:0!important;
    overflow:hidden!important;
  }

  body.v6page .kpi-strip-item{
    grid-template-columns:30px minmax(0,1fr)!important;
    grid-template-rows:auto auto!important;
    column-gap:8px!important;
    row-gap:6px!important;
    min-width:0!important;
    min-height:108px!important;
    padding:11px 10px 9px!important;
    align-items:start!important;
  }

  body.v6page .kpi-strip-item:nth-child(odd){
    border-right:1px solid rgba(111,140,180,.10)!important;
  }

  body.v6page .kpi-strip-item:nth-child(n+3){
    border-top:1px solid rgba(111,140,180,.10)!important;
  }

  body.v6page .kpi-strip-icon{
    width:30px!important;
    height:30px!important;
    min-width:30px!important;
    border-radius:8px!important;
    font-size:13px!important;
  }

  body.v6page .kpi-strip-copy{
    min-width:0!important;
  }

  body.v6page .kpi-strip-label{
    font-size:9px!important;
    line-height:1.2!important;
    white-space:normal!important;
    overflow:visible!important;
    text-overflow:clip!important;
  }

  body.v6page .kpi-strip-value{
    margin-top:4px!important;
    font-size:17px!important;
    line-height:1.08!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  body.v6page .kpi-strip-sub{
    margin-top:4px!important;
    font-size:8.5px!important;
    line-height:1.25!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  body.v6page .kpi-strip-chart{
    grid-column:1/-1!important;
    width:100%!important;
    height:18px!important;
    min-width:0!important;
    padding:0!important;
    margin-top:2px!important;
  }

  body.v6page .kpi-strip-chart svg{
    width:100%!important;
    height:18px!important;
  }
}

@media (max-width:390px){
  body.v6page .kpi-strip-v3{
    grid-template-columns:1fr!important;
  }
  body.v6page .kpi-strip-item:nth-child(odd){
    border-right:0!important;
  }
  body.v6page .kpi-strip-item:nth-child(n+2){
    border-top:1px solid rgba(111,140,180,.10)!important;
  }
}
