
/* StudyBuddies 2.10.3 — Mobile Product Surface Lock
   Mobile is treated as an intentional product surface, not compressed desktop.
   Desktop rules are untouched. */

@media(max-width:900px){
  html,body{
    max-width:100%;
    overflow-x:hidden;
  }

  /* Protect application shells from horizontal drift */
  :where(.app,.learnerShell,.adminShell,.pageShell,.main,.mainContent,.content,.workspace,.workspaceMain){
    min-width:0!important;
    max-width:100%!important;
  }

  /* Flexible grids collapse instead of squeezing */
  :where(
    .grid,.cardGrid,.dashboardGrid,.moduleGrid,.studyGrid,.learningGrid,
    .statsGrid,.summaryGrid,.contentGrid,.settingsGrid,.formGrid,.detailGrid,
    .twoCol,.threeCol,.fourCol
  ){
    min-width:0!important;
  }

  /* Toolbars may wrap by group, but compact controls themselves never wrap */
  :where(.toolbar,.filters,.filterBar,.actions,.actionBar,.buttonRow,.controlRow,.topActions,.pageActions){
    min-width:0!important;
    max-width:100%!important;
  }

  /* Prevent wide media/content from breaking the viewport */
  pre,code{
    max-width:100%;
  }
  pre{
    overflow:auto;
  }
}

@media(max-width:760px){
  :root{
    --sb-mobile-page-pad:14px;
    --sb-mobile-gap:12px;
    --sb-mobile-control:46px;
    --sb-mobile-radius:14px;
  }

  html,body{
    width:100%;
    min-width:0;
    overflow-x:hidden!important;
  }

  body{
    padding:0!important;
  }

  /* ---------- Global mobile canvas ---------- */
  :where(
    .main,.mainContent,.content,.pageContent,.workspaceMain,.learnerMain,
    .adminMain,.adminContent,.screen,.page,.routePage
  ){
    min-width:0!important;
    max-width:100%!important;
  }

  :where(.mainContent,.pageContent,.learnerMain,.adminMain,.adminContent){
    padding-left:var(--sb-mobile-page-pad)!important;
    padding-right:var(--sb-mobile-page-pad)!important;
  }

  /* Avoid large desktop whitespace on phones */
  :where(.panel,.card,.sectionCard,.moduleCard){
    min-width:0!important;
    max-width:100%!important;
    padding:14px!important;
    border-radius:var(--sb-mobile-radius)!important;
  }

  /* Hero sections become content-first, not oversized banners */
  :where([class*="hero"],[class*="Hero"]){
    min-height:0!important;
    height:auto!important;
    padding:16px!important;
    border-radius:16px!important;
  }

  :where([class*="hero"],[class*="Hero"]) h1,
  :where([class*="hero"],[class*="Hero"]) h2{
    max-width:100%!important;
  }

  /* ---------- Typography containment ---------- */
  h1,h2,h3,h4,p,label,small,strong,span{
    overflow-wrap:anywhere;
  }

  /* Compact UI labels remain single-line */
  :where(
    .mobileNav button,.navBtn,.tab,[role="tab"],.pill,.chip,.tag,.badge,
    .filterPill,.sortPill,.statusPill,.tableAction,.actionButton,.toolbar button,
    .button,.btn
  ){
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  /* ---------- Controls / forms ---------- */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  button,
  .btn,
  .button{
    max-width:100%;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select{
    min-height:var(--sb-mobile-control)!important;
  }

  textarea{
    min-height:104px!important;
    resize:vertical;
  }

  :where(.formGrid,.fields,.fieldGrid,.filtersGrid,.searchFilters,.profileFields,.settingsFields){
    display:grid!important;
    grid-template-columns:1fr!important;
    gap:12px!important;
  }

  :where(.field,.formField,.inputGroup,.filterField){
    min-width:0!important;
    width:100%!important;
  }

  /* Buttons: task-first and touch-safe */
  :where(.btn,.button,.primaryButton,.secondaryButton,.navBtn,.toolbar button,.actions button){
    min-height:44px!important;
  }

  /* Long desktop action rails become scroll-safe or wrap by item */
  :where(.tabs,.tabBar,.filterTabs,.qualificationSwitch,.revisionViewSwitch,.topicNavStrip){
    max-width:100%!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  :where(.tabs,.tabBar,.filterTabs,.qualificationSwitch,.revisionViewSwitch,.topicNavStrip)::-webkit-scrollbar{
    display:none;
  }
  :where(.tabs,.tabBar,.filterTabs,.qualificationSwitch,.revisionViewSwitch,.topicNavStrip)>*{
    flex:0 0 auto!important;
  }

  /* ---------- Mobile navigation ---------- */
  body.learner-app .sideNav{
    display:none!important;
  }

  body.learner-app .mobileNav{
    position:fixed!important;
    left:8px!important;
    right:8px!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
    z-index:1200!important;
    display:grid!important;
    grid-template-columns:repeat(5,minmax(0,1fr))!important;
    gap:2px!important;
    min-height:68px!important;
    padding:6px!important;
    border:1px solid rgba(212,219,230,.9)!important;
    border-radius:18px!important;
    background:rgba(255,255,255,.96)!important;
    box-shadow:0 12px 34px rgba(21,33,59,.16)!important;
    backdrop-filter:blur(16px);
  }

  body.learner-app .mobileNav button{
    min-width:0!important;
    min-height:56px!important;
    padding:5px 3px!important;
    border-radius:12px!important;
  }

  body.learner-app .mobileNav button span:not(.sbIcon){
    display:block!important;
    max-width:100%!important;
    font-size:10.5px!important;
    line-height:1!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  /* Keep content clear of fixed bottom navigation */
  body.learner-app :where(.main,.mainContent,.content,.learnerMain,.pageContent){
    padding-bottom:calc(92px + env(safe-area-inset-bottom))!important;
  }

  /* Exactly one mobile navigation trigger: hide redundant desktop hamburger/menu affordances */
  body.learner-app :where(.desktopMenuToggle,.sideNavToggle,.sidebarToggle){
    display:none!important;
  }

  /* ---------- Dashboard / module grids ---------- */
  :where(
    .dashboardGrid,.cardGrid,.moduleGrid,.studyGrid,.learningGrid,
    .summaryGrid,.statsGrid,.contentGrid,.settingsGrid,.detailGrid
  ){
    display:grid!important;
    grid-template-columns:1fr!important;
    gap:var(--sb-mobile-gap)!important;
  }

  /* Very small metric groups may remain 2-up if they are genuinely compact */
  :where(.metricGrid,.compactStats,.quickStats){
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }

  /* ---------- Tables become card-like mobile rows ---------- */
  :where(.tableWrap,.tableContainer,.dataTableWrap,.adminTableWrap){
    max-width:100%!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  /* If table rows already expose data-label, turn them into stacked cards */
  table[data-mobile-cards] thead{
    display:none!important;
  }
  table[data-mobile-cards],
  table[data-mobile-cards] tbody,
  table[data-mobile-cards] tr,
  table[data-mobile-cards] td{
    display:block!important;
    width:100%!important;
  }
  table[data-mobile-cards] tr{
    margin-bottom:10px!important;
    padding:12px!important;
    border:1px solid var(--sb-border)!important;
    border-radius:14px!important;
    background:#fff!important;
  }
  table[data-mobile-cards] td{
    display:grid!important;
    grid-template-columns:minmax(92px,.42fr) 1fr!important;
    gap:10px!important;
    padding:7px 0!important;
    border:0!important;
  }
  table[data-mobile-cards] td::before{
    content:attr(data-label);
    color:var(--sb-muted);
    font-size:12px;
    font-weight:850;
  }

  /* ---------- Dialogs / modals ---------- */
  :where(.modal,.dialog,.sheet,.drawer,.modalCard,.dialogCard){
    max-width:calc(100vw - 24px)!important;
    max-height:calc(100dvh - 24px)!important;
  }

  :where(.modal,.dialog,.modalCard,.dialogCard){
    overflow:auto!important;
  }

  /* ---------- Social / feed surfaces ---------- */
  :where(.feedCard,.postCard,.sbWallPost,.slhPost,.communityPost){
    padding:13px!important;
    border-radius:14px!important;
  }

  :where(.postActions,.sbWallActions,.slhPostActions){
    display:flex!important;
    flex-wrap:wrap!important;
    gap:6px!important;
  }

  /* ---------- Revision / Study Set surfaces ---------- */
  :where(.rc2Filters,.practiceFilters,.studySetFilters,.primaryRcClearHeader,.primaryRcStepBlock){
    max-width:100%!important;
  }

  :where(.rc2FilterPrimary,.practiceFilterGrid){
    grid-template-columns:1fr!important;
  }

  :where(.rc2Ratings,.ratingGrid){
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }

  /* ---------- Admin / content studio ---------- */
  body.admin-app :where(.adminGrid,.dashboardGrid,.summaryGrid,.formGrid,.settingsGrid),
  body.content-studio :where(.adminGrid,.dashboardGrid,.summaryGrid,.formGrid,.settingsGrid){
    grid-template-columns:1fr!important;
  }

  body.admin-app :where(.toolbar,.filters,.actionBar,.pageActions),
  body.content-studio :where(.toolbar,.filters,.actionBar,.pageActions){
    display:flex!important;
    flex-wrap:wrap!important;
    gap:8px!important;
  }

  body.admin-app :where(.toolbar button,.filters button,.actionBar button,.pageActions button),
  body.content-studio :where(.toolbar button,.filters button,.actionBar button,.pageActions button){
    flex:0 1 auto!important;
  }

  /* ---------- Safe-area handling ---------- */
  .topbar,.mobileHeader{
    padding-top:max(8px,env(safe-area-inset-top))!important;
  }
}

@media(max-width:430px){
  :root{
    --sb-mobile-page-pad:12px;
  }

  body.learner-app .mobileNav{
    left:6px!important;
    right:6px!important;
    padding:5px!important;
  }

  body.learner-app .mobileNav button span:not(.sbIcon){
    font-size:10px!important;
  }

  :where(.panel,.card,.sectionCard,.moduleCard){
    padding:13px!important;
  }

  :where(.rc2Ratings,.ratingGrid){
    grid-template-columns:1fr 1fr!important;
  }

  :where(.primaryRcSupportRow,.compactStats,.quickStats){
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
}

@media(max-width:390px){
  body.learner-app .mobileNav{
    min-height:66px!important;
  }

  body.learner-app .mobileNav button{
    min-height:54px!important;
    padding-inline:2px!important;
  }

  body.learner-app .mobileNav button span:not(.sbIcon){
    font-size:9.6px!important;
  }

  h1{font-size:25px!important}
  h2{font-size:21px!important}
}

@media(max-width:360px){
  :root{
    --sb-mobile-page-pad:10px;
  }

  body.learner-app .mobileNav{
    left:4px!important;
    right:4px!important;
    gap:1px!important;
  }

  body.learner-app .mobileNav button span:not(.sbIcon){
    font-size:9.2px!important;
  }

  :where(.panel,.card,.sectionCard,.moduleCard){
    padding:12px!important;
    border-radius:12px!important;
  }

  :where(.primaryRcStartActions,.buttonRow,.actionRow){
    grid-template-columns:1fr!important;
  }
}

@media(min-width:761px) and (max-width:1024px){
  /* Tablet: two-column workspace where useful, without desktop squeeze. */
  :where(.dashboardGrid,.cardGrid,.moduleGrid,.studyGrid,.learningGrid,.contentGrid){
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  :where(.formGrid,.settingsGrid){
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .sideNav{
    max-width:240px;
  }
}
