/* Gematrixx V74 — sitewide mobile audit hardening, 2026-08-08
   Loaded AFTER every feature stylesheet. Purpose: keep dense content readable
   without page-wide horizontal overflow or squashed table columns. */

html,body{max-width:100%;overflow-x:clip}

@media(max-width:820px){
  /* Global shell safety. Only containment here; page-specific layouts remain intact. */
  .page-view,[id^="page"]{max-width:100%!important;min-width:0!important;overflow-x:clip!important}
  .page-view :where(.body,.hdr,.panel,.section,.card,.wrap,.container,section,article,form,fieldset){min-width:0;max-width:100%}
  .page-view :where(img,video,iframe){max-width:100%!important;height:auto}
  .page-view :where(input,select,textarea,button){max-width:100%;min-width:0}

  /* Local table scroller — never let a data table widen the whole page. */
  .gmx74-local-scroll{width:100%!important;max-width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch;overscroll-behavior-inline:contain}
  .gmx74-local-scroll>table{max-width:none!important}
  .gmx74-local-scroll table :where(th,td){word-break:normal!important;overflow-wrap:normal!important}

  /* Generic record/card mode for selected dense data tables. */
  table.gmx74-card-table{display:block!important;width:100%!important;min-width:0!important;max-width:100%!important;table-layout:auto!important;border-collapse:separate!important}
  table.gmx74-card-table>thead{display:none!important}
  table.gmx74-card-table>tbody{display:grid!important;grid-template-columns:minmax(0,1fr)!important;gap:.7rem!important;width:100%!important}
  table.gmx74-card-table>tbody>tr{display:block!important;width:100%!important;min-width:0!important;border:1px solid var(--bdr,var(--border))!important;border-radius:12px!important;background:var(--bg2,var(--bg-card))!important;overflow:hidden!important}
  table.gmx74-card-table>tbody>tr>:is(td,th){
    display:grid!important;grid-template-columns:minmax(96px,38%) minmax(0,1fr)!important;gap:.65rem!important;
    align-items:center!important;width:100%!important;min-width:0!important;box-sizing:border-box!important;
    padding:.56rem .7rem!important;border:0!important;border-bottom:1px solid var(--bdr,var(--border))!important;
    white-space:normal!important;overflow:visible!important;text-overflow:clip!important;word-break:normal!important;overflow-wrap:normal!important;
    position:static!important;text-align:right!important;background:transparent!important
  }
  table.gmx74-card-table>tbody>tr>:is(td,th):last-child{border-bottom:0!important}
  table.gmx74-card-table>tbody>tr>:is(td,th)::before{content:attr(data-label);color:var(--gold2,var(--gold));font-size:.7rem;font-weight:800;line-height:1.5;text-align:right;direction:rtl}
  table.gmx74-card-table>tbody>tr>:is(td,th)[colspan]{display:block!important;text-align:center!important}
  table.gmx74-card-table>tbody>tr>:is(td,th)[colspan]::before{content:none!important}
  .gmx74-card-wrap{overflow:visible!important;border:0!important;background:transparent!important;max-width:100%!important}

  /* Keep footer totals readable instead of losing them when a table becomes cards. */
  table.gmx74-card-table>tfoot{display:block!important;margin-top:.55rem!important;width:100%!important}
  table.gmx74-card-table>tfoot>tr{display:flex!important;flex-wrap:wrap!important;gap:.25rem!important;justify-content:center!important;border:1px solid var(--bdr,var(--border))!important;border-radius:10px!important;padding:.45rem!important;background:rgba(201,168,76,.05)!important}
  table.gmx74-card-table>tfoot>tr>:is(th,td){display:block!important;position:static!important;min-width:0!important;width:auto!important;padding:.25rem .45rem!important;border:0!important;white-space:normal!important;text-align:center!important}

  /* Quran exploration — protected namespace. Never squeeze its 12 columns. */
  #pageQuran #pg-explore>.tw{overflow:visible!important;border:0!important;background:transparent!important;width:100%!important;max-width:100%!important}
  #pageQuran #pg-explore>.tw>table{display:block!important;width:100%!important;min-width:0!important;max-width:100%!important;table-layout:auto!important}
  #pageQuran #pg-explore>.tw>table>thead{display:none!important}
  #pageQuran #pg-explore #srchBody{display:grid!important;grid-template-columns:minmax(0,1fr)!important;gap:.8rem!important;width:100%!important;max-width:100%!important}
  #pageQuran #pg-explore #srchBody>tr{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;width:100%!important;min-width:0!important;border:1px solid var(--bdr)!important;border-radius:12px!important;overflow:hidden!important;background:var(--bg2)!important}
  #pageQuran #pg-explore #srchBody>tr>td{display:flex!important;align-items:center!important;justify-content:space-between!important;gap:.55rem!important;width:auto!important;min-width:0!important;max-width:none!important;padding:.58rem .7rem!important;border:0!important;border-bottom:1px solid var(--bdr)!important;white-space:normal!important;overflow:visible!important;text-overflow:clip!important;word-break:normal!important;overflow-wrap:normal!important;position:static!important;text-align:left!important;font-size:.88rem!important;line-height:1.55!important;background:transparent!important}
  #pageQuran #pg-explore #srchBody>tr>td::before{color:var(--txt3);font-size:.7rem;font-weight:700;white-space:nowrap;flex:0 0 auto;text-align:right}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(1)::before{content:"#"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(2)::before{content:"ترتيب السورة"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(3)::before{content:"السورة"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(4)::before{content:"الآية"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(6)::before{content:"جمل كبير"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(7)::before{content:"جمل صغير"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(8)::before{content:"ألفبائي ترتيبي"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(9)::before{content:"ألفبائي تخفيضي"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(10)::before{content:"كلمات"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(11)::before{content:"حروف"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(12)::before{content:"جزء"}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(5){grid-column:1/-1!important;display:block!important;direction:rtl!important;text-align:right!important;font-family:'Amiri',var(--font-main),serif!important;font-size:1.12rem!important;line-height:2!important;padding:.8rem!important;background:var(--bg3)!important}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(5)::before{content:"نص الآية";display:block;margin-bottom:.22rem;color:var(--gold2);font-family:var(--font-main);font-size:.72rem}
  #pageQuran #pg-explore #srchBody>tr>td[colspan]{grid-column:1/-1!important;display:block!important;text-align:center!important;padding:1.5rem!important;border:0!important}
  #pageQuran #pg-explore #srchBody>tr>td[colspan]::before{content:none!important}

  /* Quran controls remain readable and do not force a horizontal row. */
  #pageQuran #pg-explore>.bar{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:.55rem!important;align-items:stretch!important}
  #pageQuran #pg-explore :is(#srchTxt,#srchSur,#srchOrd,.srch-mode){grid-column:1/-1!important;width:100%!important;min-width:0!important;max-width:none!important;margin:0!important}
  #pageQuran #pg-explore .srch-mode{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:.35rem!important}
  #pageQuran #pg-explore>.bar>.btn{width:100%!important;min-height:42px!important;margin:0!important}

  /* Surah statistics: safe fallback is a local readable table; JS then upgrades it to cards. */
  #pageQuran #pg-surastats #ssWrap{width:100%!important;max-width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch}
  #pageQuran #pg-surastats #ssTable{min-width:760px!important;width:max-content!important;table-layout:auto!important}
  #pageQuran #pg-surastats #ssWrap.gmx74-card-wrap{overflow:visible!important}
  #pageQuran #pg-surastats #ssTable.gmx74-card-table{min-width:0!important;width:100%!important;max-width:100%!important;table-layout:auto!important}
  #pageQuran #pg-surastats .ssbar{display:grid!important;grid-template-columns:minmax(0,1fr)!important;gap:.5rem!important}
  #pageQuran #pg-surastats .ssbar input{width:100%!important;min-width:0!important}

  /* Scripture statistics/lexicon — seven-column data becomes records on phones. */
  #pageGenesis :is(.gns-stats-table,.gns-dict-table).gmx74-card-table{min-width:0!important}
  #pageGenesis :is(.gns-stats-table-wrap,.gns-dict-table-wrap).gmx74-card-wrap{overflow:visible!important}

  /* Astrology tables — preserve names/values instead of squeezed columns. */
  #pageAstro .az-tbl.gmx74-card-table{min-width:0!important}
  #pageAstro .az-tbl-wrap.gmx74-card-wrap{overflow:visible!important}

  /* Calendar month comparison: one month = one mobile record; no sideways table. */
  #pageDatecalc .dc-months-table.gmx74-card-table{min-width:0!important;direction:rtl!important}
  #pageDatecalc .dc-months-table-wrap.gmx74-card-wrap{overflow:visible!important;border:0!important;box-shadow:none!important;background:transparent!important}

  /* Macrocosm 5-column comparison table becomes readable records. */
  #pageMacrocosm .mc-expanded-table.gmx74-card-table{min-width:0!important}
  #pageMacrocosm .mc-table-wrap.gmx74-card-wrap{overflow:visible!important}

  /* Matrix-like content must keep its geometry and scroll only inside its own box. */
  #pageQuran :is(.mq2-heat-wrap,.qoc-matrix-wrap),
  #pagePeriodic .pt-grid-wrap,
  #pageBirthcard .bc109-table-wrap,
  #pageDateMatrix .table-wrap,
  #pageTreeOfLife [class*="matrix"]{max-width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch;overscroll-behavior-inline:contain}

  /* Reflow recurring wide grids/panels rather than shrinking text. */
  #pageQuran :where(.cg2,.qwr-points,.qvo-grid){grid-template-columns:minmax(0,1fr)!important}
  #pageQuran :where(.qcvs-row,.qwr-selects){display:grid!important;grid-template-columns:minmax(0,1fr)!important;gap:.45rem!important}
  #pageQuran :where(.qcvs-row,.qwr-selects)>*{width:100%!important;min-width:0!important}
  #pageMacrocosm :where(.mc-two-col,.mc-type-grid,.mc-cosmic-cards){grid-template-columns:minmax(0,1fr)!important}
  #pageGenesis .gns-dict-controls{grid-template-columns:minmax(0,1fr)!important}

  /* Keep button/tab labels intact; wrap the group, not letters inside a button. */
  .page-view :where(.toolbar,.controls,.filter-row,.search-row,.button-row){max-width:100%!important;flex-wrap:wrap!important}
  .page-view :where(button,.tab){word-break:normal!important;overflow-wrap:normal!important}
}

@media(max-width:520px){
  #pageQuran #pg-explore #srchBody>tr{grid-template-columns:minmax(0,1fr)!important}
  #pageQuran #pg-explore #srchBody>tr>td:nth-child(5){grid-column:auto!important}
  #pageQuran #pg-explore .srch-mode{grid-template-columns:minmax(0,1fr)!important}
  table.gmx74-card-table>tbody>tr>:is(td,th){grid-template-columns:minmax(88px,36%) minmax(0,1fr)!important;padding:.52rem .6rem!important}
}


/* v174.0 mobile audit safety net — conservative, no horizontal page overflow */
@media(max-width:700px){
  html,body{max-width:100%!important;overflow-x:hidden!important}
  .page-view{max-width:100%!important;min-width:0!important;box-sizing:border-box!important}
  .page-view :where(img,video,canvas,svg){max-width:100%;height:auto}
  .page-view :where(input,select,textarea,button){max-width:100%;box-sizing:border-box}
  .page-view :where(.card,.panel,.section,.content,.container){min-width:0;max-width:100%;box-sizing:border-box}
  .page-view :where(pre,code){max-width:100%;overflow-wrap:anywhere}
  .page-view :where(.tw,.table-wrap,[class*="table-wrap"],[class*="matrix-wrap"]){max-width:100%;overscroll-behavior-inline:contain;-webkit-overflow-scrolling:touch}
}
