/* 5.9.2 — small-screen safety net. Loaded last on every public and admin page, so it wins over kit styles
   without !important where possible. Fixes: course sidebar sitting on top of the content, header buttons
   overlapping, wide tables and two-column forms pushing the page sideways, cards not stacking. */

img,video,iframe,embed,object{max-width:100%}
img,video{height:auto}

/* ---------- course page: the buy card goes under the intro instead of on top of it ---------- */
@media (max-width:900px){
  .course-hero{grid-template-columns:minmax(0,1fr)!important}
  .course-hero>aside{position:static!important;top:auto}
  .course-hero>*{min-width:0}
}

/* ---------- generic stacking ---------- */
@media (max-width:760px){
  .form-grid,.form-grid>*,.grid>*,.course-hero>*,.doc-card,.card{min-width:0}
  .form-grid{grid-template-columns:minmax(0,1fr)!important}
  .form-cols{grid-template-columns:minmax(0,1fr)!important}
  .g2,.g3,.g4{grid-template-columns:minmax(0,1fr)}
  .grid[style*="grid-template-columns"]{grid-template-columns:minmax(0,1fr)!important}
  .row>*{min-width:0;max-width:100%}
  input,select,textarea{max-width:100%;min-width:0}
  .card,.prose,.lead,h1,h2,h3{overflow-wrap:anywhere}
  pre,code{white-space:pre-wrap;word-break:break-word}
  /* wide tables scroll inside themselves instead of widening the whole page */
  table.tbl,table.table,.prose table,.adm-main table,main table{display:block;max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
  table.tbl td,table.tbl th{white-space:nowrap}
  table.tbl td.wrap,table.tbl td .small{white-space:normal}
  .toolbar>*{max-width:100%}
  .builder-sec{max-width:100%;overflow-x:auto}
  /* landing-page side lists (home) */
  .lxs .lx-card,.lxs [class*="lx-"]{min-width:0;max-width:100%}
  .lxs .lx-topics a{overflow-wrap:anywhere}
}

/* ---------- public header: everything fits in one row ---------- */
@media (max-width:480px){
  html.mnav-on .mnav-row{gap:4px!important}
  html.mnav-on .mnav-head [class*="actions"],html.mnav-on .mnav-head .bbox.lay-row{gap:4px!important;flex:0 1 auto!important;min-width:0}
  html.mnav-on .mnav-head :is(.icon-btn,.xs-trigger,.head-search-m){width:36px!important;height:36px!important;flex:none}
  html.mnav-on .mnav-burger{width:40px;height:40px;margin-left:2px}
  /* the account menu is in the drawer too (Account, Admin, sign out) */
  html.mnav-on .mnav-head .user-menu{display:none!important}
  html.mnav-on .mnav-head .brand>span:last-child{max-width:34vw}
}
@media (max-width:360px){
  html.mnav-on .mnav-head .brand>span:last-child{display:none}
}

/* ---------- admin top bar ---------- */
@media (max-width:760px){
  .adm-top{gap:8px!important;padding:0 12px!important}
  .adm-top .adm-crumbs{display:none!important}
  .adm-top .adm-burger{flex:none;width:40px;height:40px}
  .adm-top .adm-search{flex:1 1 auto!important;min-width:0!important;margin-left:0}
  .adm-top .adm-actions{flex:none;gap:6px}
  .adm-main,.adm-content{min-width:0;max-width:100vw}
  .adm-head,.page-head{flex-wrap:wrap;gap:10px}
}

/* ---------- tablets ---------- */
@media (max-width:1100px){
  table.tbl,table.table,.prose table{display:block;max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
  .pp-viewer,.grid>*,[class*="-grid"]>*{min-width:0;max-width:100%}
}

/* helpline: the "Report" pop-up stays inside the screen */
@media (max-width:760px){
  .hl-report{position:relative}
  .hl-report>form.card{position:absolute;right:0;left:auto;width:min(300px,calc(100vw - 32px));max-width:calc(100vw - 32px);z-index:20}
}
