/* FIX2801 mobile PDF.js canvas reader. Desktop iframe styling is unchanged. */
@media(max-width:850px){
 .resource-topic-reader .document-viewer.nga-pdf-mobile-ready{min-height:400px;height:min(75vh,810px);overflow:hidden}
 .nga-mobile-pdf{display:flex;flex-direction:column;height:100%;width:100%;min-width:0;background:#e9eef5}
 .nga-mobile-pdf-toolbar{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:6px;padding:9px 5px;background:#fff;border-bottom:1px solid #d5dfeb}
 .nga-mobile-pdf-btn{padding:8px 9px;border:1px solid #bfcee0;border-radius:6px;background:#fff;color:#153c6d;font-size:13px;font-weight:600;line-height:1.2;cursor:pointer}
 .nga-mobile-pdf-btn:disabled{opacity:.4;cursor:default}
 .nga-mobile-pdf-status{font-size:13px;font-weight:600;min-width:44px;text-align:center;color:#24364d}
 .nga-mobile-pdf-scroll{flex:1;overflow:auto;overscroll-behavior:contain;display:flex;align-items:flex-start;justify-content:flex-start;padding:9px}
 .nga-mobile-pdf-scroll canvas{display:block;margin:0 auto;background:#fff;box-shadow:0 2px 9px #20364b33;max-width:none}
 .nga-mobile-pdf-error{padding:24px;color:#6f2330;background:#fff7f7;font-size:14px;line-height:1.5}
 .nga-preview-expanded .document-viewer.nga-pdf-mobile-ready{flex:1;height:auto;min-height:0}
}


/* FIX2809 — Mobile PDF preview: full-width paper, auto-height canvas, no empty fixed-height box.
   Only resource PDF previews on <=850px viewports. Desktop and other viewers are unchanged. */
@media (max-width:850px) {
  body.resource-topic-page .resource-topic-reader .resource-paid-preview:has([data-nga-preview-reader]) {
    padding-left:8px!important;
    padding-right:8px!important;
  }
  body.resource-topic-page .resource-topic-reader [data-nga-preview-reader] {
    width:100%;max-width:none;min-width:0;
  }
  body.resource-topic-page .resource-topic-reader .document-viewer.nga-pdf-mobile-ready {
    width:100%!important;max-width:none!important;
    height:auto!important;min-height:0!important;
    margin:8px 0 0!important;overflow:hidden!important;
    border-radius:10px!important;
  }
  body.resource-topic-page .nga-mobile-pdf {
    width:100%;height:auto;min-height:0;
  }
  body.resource-topic-page .nga-mobile-pdf-toolbar {
    display:flex;flex-wrap:nowrap;justify-content:space-between;
    gap:4px;padding:8px 5px;
  }
  body.resource-topic-page .nga-mobile-pdf-btn {
    flex:0 0 auto;min-width:0;white-space:nowrap;
    font-size:clamp(11px,2.8vw,13px);padding:8px 7px;
    touch-action:manipulation;
  }
  body.resource-topic-page .nga-mobile-pdf-status {
    flex:0 0 auto;min-width:34px;font-size:clamp(11px,2.8vw,13px);
  }
  body.resource-topic-page .nga-mobile-pdf-scroll {
    display:block;flex:0 0 auto;height:auto;min-height:0;
    max-height:calc(100dvh - 175px);
    width:100%;box-sizing:border-box;
    padding:5px;overflow:auto;
    background:#fff;
  }
  body.resource-topic-page .nga-mobile-pdf-scroll canvas {
    display:block;margin-left:auto;margin-right:auto;
    max-width:none; /* zoom must scroll rather than distort the PDF */
  }
  /* Maximize remains within the mobile browser viewport: page keeps A4 ratio and scrolls. */
  body.resource-topic-page .nga-preview-reader.nga-preview-expanded {
    inset:0!important;padding:8px!important;
    width:100vw!important;height:100dvh!important;
    max-width:none!important;box-sizing:border-box;
  }
  body.resource-topic-page .nga-preview-expanded .nga-preview-reader-actions {
    flex:0 0 auto;gap:8px;min-width:0;
  }
  body.resource-topic-page .resource-topic-reader .nga-preview-expanded .resource-paid-pdf-preview.nga-pdf-mobile-ready,
  body.resource-topic-page .nga-preview-expanded .resource-paid-pdf-preview.nga-pdf-mobile-ready {
    display:flex;flex:1 1 auto;
    height:auto!important;max-height:none!important;min-height:0!important;
    margin:0!important;overflow:hidden!important;
  }
  body.resource-topic-page .nga-preview-expanded .nga-mobile-pdf {
    height:100%;min-height:0;flex:1 1 auto;
  }
  body.resource-topic-page .nga-preview-expanded .nga-mobile-pdf-scroll {
    flex:1 1 auto;min-height:0;max-height:none;
    overflow:auto;background:#f5f8fd;
  }
}

/* FIX2811 — Viewport-safe mobile resource reader.
   Keep desktop, PDF content, resource access, and the site header untouched. */
@media (max-width:850px) {
  /* Use full available mobile width for BOTH the description and its preview. */
  body.resource-topic-page .resource-topic-pagehead .wrap,
  body.resource-topic-page .resource-topic-reader > .wrap.resource-topic-layout {
    box-sizing:border-box!important;
    width:calc(100% - 16px)!important;
    max-width:none!important;
    margin-left:8px!important;
    margin-right:8px!important;
    min-width:0!important;
  }
  body.resource-topic-page .resource-topic-reader .resource-topic-layout {
    grid-template-columns:minmax(0,1fr)!important;
    min-width:0!important;
  }
  body.resource-topic-page .resource-topic-reader .resource-topic-main {
    box-sizing:border-box!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }
  body.resource-topic-page .resource-topic-reader .resource-public-description,
  body.resource-topic-page .resource-topic-reader .resource-paid-preview,
  body.resource-topic-page .resource-topic-reader .resource-topic-body {
    box-sizing:border-box!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    margin-left:0!important;
    margin-right:0!important;
    padding:12px!important;
    overflow-wrap:anywhere;
  }
  body.resource-topic-page .resource-topic-reader .resource-preview-copy,
  body.resource-topic-page .resource-topic-reader .resource-public-description .reader-content,
  body.resource-topic-page .resource-topic-reader .resource-paid-preview-head,
  body.resource-topic-page .resource-topic-reader .resource-written-sample {
    box-sizing:border-box!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    overflow-wrap:anywhere!important;
  }
  body.resource-topic-page .resource-topic-reader .resource-paid-preview .resource-written-sample {
    margin-left:0!important;
    margin-right:0!important;
    padding:10px 0!important;
  }
  /* Show PDF up to the inner border of the preview card; never go beyond viewport. */
  body.resource-topic-page .resource-topic-reader .resource-paid-preview > .nga-preview-reader:not(.nga-preview-expanded) {
    box-sizing:border-box!important;
    position:static!important;
    left:auto!important;
    transform:none!important;
    width:calc(100% + 24px)!important;
    max-width:none!important;
    min-width:0!important;
    margin:10px -12px 0!important;
    overflow:hidden!important;
  }
  body.resource-topic-page .nga-preview-reader:not(.nga-preview-expanded) .nga-preview-reader-actions {
    box-sizing:border-box!important;
    width:100%!important;
    display:flex!important;
    align-items:center!important;
    justify-content:space-between!important;
    flex-wrap:wrap!important;
    gap:8px!important;
    padding:0 12px!important;
    margin:8px 0 12px!important;
  }
  body.resource-topic-page .nga-preview-reader-title {
    min-width:0;
    font-size:clamp(13px,3.5vw,15px)!important;
  }
  body.resource-topic-page .nga-preview-maximize {
    flex:0 0 auto;
    padding:7px 10px!important;
    font-size:13px!important;
  }
  body.resource-topic-page .resource-topic-reader .document-viewer.nga-pdf-mobile-ready {
    box-sizing:border-box!important;
    display:block!important;
    width:100%!important;
    max-width:100%!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    margin:0!important;
    padding:0!important;
    border:1px solid #dce5f0!important;
    border-radius:8px!important;
    overflow:hidden!important;
    background:#fff!important;
  }
  body.resource-topic-page .resource-topic-reader .document-viewer.resource-a4-reader.nga-pdf-mobile-ready:not(.resource-paid-pdf-preview) {
    position:static!important;
    left:auto!important;
    transform:none!important;
    width:100%!important;
    max-width:100%!important;
    margin:8px 0!important;
  }
  body.resource-topic-page .nga-mobile-pdf {
    box-sizing:border-box!important;
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    max-width:100%!important;
    height:auto!important;
    min-height:0!important;
    background:#fff!important;
  }
  body.resource-topic-page .nga-mobile-pdf-toolbar {
    box-sizing:border-box!important;
    display:flex!important;
    align-items:center!important;
    justify-content:space-between!important;
    flex-wrap:nowrap!important;
    gap:3px!important;
    width:100%!important;
    max-width:100%!important;
    padding:6px 4px!important;
    margin:0!important;
    overflow:hidden!important;
    background:#fff!important;
    border-bottom:1px solid #d9e3ed!important;
  }
  body.resource-topic-page .nga-mobile-pdf-btn {
    box-sizing:border-box!important;
    flex:0 1 auto!important;
    min-width:0!important;
    min-height:34px!important;
    padding:6px clamp(3px,1.5vw,7px)!important;
    white-space:nowrap!important;
    font-size:clamp(11px,2.8vw,13px)!important;
    border-radius:6px!important;
  }
  body.resource-topic-page .nga-mobile-pdf-status {
    flex:0 0 auto!important;
    min-width:38px!important;
    font-size:clamp(11px,2.8vw,13px)!important;
    text-align:center!important;
  }
  /* Fit always stays inside the viewport. Only explicit zoom enables panning. */
  body.resource-topic-page .nga-mobile-pdf-scroll,
  body.resource-topic-page .nga-preview-reader:not(.nga-preview-expanded) .nga-mobile-pdf-scroll,
  body.resource-topic-page .resource-a4-reader.nga-pdf-mobile-ready .nga-mobile-pdf-scroll {
    box-sizing:border-box!important;
    display:block!important;
    flex:0 0 auto!important;
    width:100%!important;
    max-width:100%!important;
    min-height:0!important;
    height:auto!important;
    max-height:none!important;
    margin:0!important;
    padding:0!important;
    overflow:hidden!important;
    background:#fff!important;
  }
  body.resource-topic-page .nga-mobile-pdf-scroll canvas {
    box-sizing:content-box!important;
    display:block!important;
    max-width:100%!important;
    height:auto!important;
    margin:0 auto!important;
    box-shadow:none!important;
    background:#fff;
  }
  body.resource-topic-page .nga-mobile-pdf.nga-mobile-pdf-zoomed .nga-mobile-pdf-scroll {
    max-height:76dvh!important;
    overflow:auto!important;
    overscroll-behavior:contain;
  }
  body.resource-topic-page .nga-mobile-pdf.nga-mobile-pdf-zoomed .nga-mobile-pdf-scroll canvas {
    max-width:none!important;
  }
  /* Preserve the existing fullscreen toggle, with bounded zoom/panning. */
  body.resource-topic-page .resource-topic-reader .nga-preview-reader.nga-preview-expanded {
    box-sizing:border-box!important;
    position:fixed!important;
    inset:0!important;
    left:0!important;
    top:0!important;
    transform:none!important;
    width:100%!important;
    max-width:100%!important;
    height:100dvh!important;
    margin:0!important;
    padding:8px!important;
    overflow:hidden!important;
    display:flex!important;
    flex-direction:column!important;
    background:#f5f8fd!important;
    z-index:2147483000!important;
  }
  body.resource-topic-page .nga-preview-expanded .document-viewer.nga-pdf-mobile-ready {
    display:flex!important;
    flex:1 1 auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:hidden!important;
  }
  body.resource-topic-page .nga-preview-expanded .nga-mobile-pdf {
    flex:1 1 auto!important;
    height:100%!important;
    min-height:0!important;
  }
  body.resource-topic-page .nga-preview-expanded .nga-mobile-pdf-scroll {
    flex:1 1 auto!important;
    max-height:none!important;
    min-height:0!important;
    overflow:auto!important;
    background:#f6f8fd!important;
  }
}
