/* ==========================================================================
   Responsive layer - loaded after every other stylesheet.
   Goal: no screen scrolls sideways at any width. Wide content (tables, code)
   scrolls inside its own box; grids and toolbars fold as the screen narrows.
   Breakpoints: 1100 (small laptop / tablet landscape), 820 (tablet portrait,
   the sidebar becomes a top bar), 560 (phone).
   ========================================================================== */

/* ---------- everywhere ---------- */
img, video, canvas{max-width:100%;height:auto;}
.card, article, section, .board > *, .row-a > *, .row-b > *{min-width:0;}
pre, code{overflow-wrap:anywhere;}
pre{max-width:100%;overflow-x:auto;}

/* tables get their own horizontal scroller (see the wrapper script in base.html) */
.tablescroll{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;}
.tablescroll > table{min-width:100%;}
.tablescroll > table th, .tablescroll > table td{white-space:nowrap;}
.tablescroll > table td.mpmsg, .tablescroll > table td:last-child small{white-space:normal;}

/* toolbars and card headers wrap instead of pushing past the edge */
.cardhead, .cardhead.tight, .toolbar, .tools, .tfoot, .pager, .range, .head > .range{flex-wrap:wrap;}
.tsearch{max-width:100%;}

/* ---------- small laptop / tablet landscape ---------- */
@media (max-width:1100px){
  .frame{gap:16px;}
  .umpanel{max-width:calc(100vw - 32px);}
}

/* ---------- tablet portrait: sidebar becomes a top bar ---------- */
@media (max-width:820px){
  .frame{gap:10px;}
  .side{min-height:0;}                                 /* was full-screen tall as a sidebar */
  .menu{flex:0 0 auto;
    -webkit-mask-image:linear-gradient(90deg,#000 85%,transparent);mask-image:linear-gradient(90deg,#000 85%,transparent);}
  .brand{padding:2px 4px 10px;}
  .sidefoot{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding-top:8px;}
  .sidefoot .buildstamp{display:none;}
  .menulabel{display:none;}
  .brand img{max-height:34px;width:auto;}
  .menu{gap:4px;scrollbar-width:thin;}
  .mitem{padding:8px 10px;}
  .board{padding:0;}
  .head{gap:10px;margin-bottom:16px;}
  .head h1{font-size:20px;}
  .head > div:first-child{flex-basis:100%;}
  .tsearch, .tsearch input, .tsearch .sicon + input{width:100%;}
  .tiles{gap:10px;}
  .card{padding:16px;}
  .umdialog{padding:10px;align-items:flex-start;}
  .umpanel{width:100%;max-height:calc(100vh - 20px);}
  .umgrid{grid-template-columns:1fr;}
  .umwide{grid-column:auto;}
  .umfoot{flex-wrap:wrap;}
}

/* Marketplace sandbox on narrow screens: one column, cards and buttons wrap */
@media (max-width:820px){
  .mpsandbox > *, .mpsandin, .mpsandout{min-width:0;}
  .mpsamplefile, .mpslot{flex-wrap:wrap;}
  .mpsamplefile .mpuse, .mpslotbtns{margin-left:auto;}
  .mpslothead{flex-wrap:wrap;}
  .mpouttabs, .mpdtabs{overflow-x:auto;flex-wrap:nowrap;scrollbar-width:thin;}
  .mpouttab, .mpdtab{white-space:nowrap;flex:none;}
  .mpsandout .mpoutpane{height:auto;max-height:70vh;}
  .mpchat{height:70vh;}
  .mpchecks li, .mpagentchecks li{grid-template-columns:18px 1fr !important;}
  .mpchecks li small{grid-column:2;}
  .mpagenttop{flex-wrap:wrap;}
  .mpagentms{margin-left:0;}
  .mpagcond, .mpagcond:last-child{grid-template-columns:1fr;}
  .mpdecision small{margin-left:0;flex-basis:100%;}
  .mpcheckout, .mpdetail, .mpadrow{grid-template-columns:1fr;}
  .mpfieldrow{grid-template-columns:1fr 1fr;}
  .mponprem{flex-direction:column;align-items:stretch;}
  .mpwhygrid, .mpprivgrid, .mpkept, .mpedgrid{grid-template-columns:1fr;}
  .mpstats{grid-template-columns:repeat(2,1fr);gap:10px;}
  .mpfoot{flex-wrap:wrap;gap:10px;}
  .mpdiscount{flex-direction:column;align-items:stretch;}
}

/* ---------- phone ---------- */
@media (max-width:560px){
  body{padding:6px;}
  .frame{padding:10px;border-radius:12px;}
  .head h1{font-size:18px;}
  .head p{font-size:12px;}
  .tiles, .ministrip, .statrow{grid-template-columns:1fr 1fr;}
  .tile{padding:12px;gap:9px;}
  .tval{font-size:19px;}
  .tico{width:30px;height:30px;flex-basis:30px;}
  .card{padding:13px;border-radius:10px;}
  .range, .range form, .rangebtn{width:100%;}
  .range > *{flex:1 1 auto;}
  .rangedrop{left:0;right:0;width:auto;}
  .fagrid{grid-template-columns:1fr;}
  .tile .tlab{font-size:11px;}
  .mpsamplebody{flex:1 1 calc(100% - 60px);}         /* buttons drop under the text */
  .mpsamplefile .mpuse, .mpslotbtns{margin-left:50px;}
}
@media (max-width:340px){
  .tiles, .ministrip, .statrow{grid-template-columns:1fr;}
}
