/* dam.DMS PWA/mobile layer.
   All layout changes are intentionally limited to small viewports or standalone mode. */

.pwa-install-btn{display:none!important}
.mobile-pdf-viewer{display:none}

@media (max-width: 980px){
  .pwa-install-btn.is-visible:not([hidden]){
    display:inline-flex!important;
    width:38px;height:38px;padding:0;margin:0;
    align-items:center;justify-content:center;
    border:1px solid var(--dms-border,#dfe6ef);
    border-radius:10px;background:#eef5fb;color:var(--dms-primary,#146bb8);
    box-shadow:none;font-size:1rem;
  }
  .pwa-install-btn.is-visible:hover{transform:none;box-shadow:none;background:#e4f0fa}

  .viewer-card.has-mobile-pdf-viewer .desktop-pdf-frame{display:none!important}
  .viewer-card.has-mobile-pdf-viewer .mobile-pdf-viewer{
    display:flex;flex-direction:column;
    height:calc(100dvh - 150px);min-height:440px;
    background:#e9eef4;color:#26364d;
  }
  .mobile-pdf-toolbar{
    flex:0 0 auto;display:flex;align-items:center;gap:5px;
    min-height:48px;padding:5px 7px;
    background:rgba(255,255,255,.97);border-bottom:1px solid #d8e0e9;
    box-shadow:0 3px 12px rgba(28,45,75,.06);z-index:2;
  }
  .mobile-pdf-tool,.mobile-pdf-page{
    min-width:38px;height:38px;min-height:38px;padding:0 9px;margin:0;
    display:inline-flex;align-items:center;justify-content:center;gap:4px;
    border:1px solid #d7e0e9;border-radius:9px;background:#fff;color:#42526a;
    box-shadow:none;font-size:.88rem;font-weight:750;
  }
  .mobile-pdf-tool:hover,.mobile-pdf-page:hover{transform:none;box-shadow:none;background:#f1f6fa}
  .mobile-pdf-tool:disabled{opacity:.35;cursor:default}
  .mobile-pdf-tool.is-primary{color:#146bb8;background:#edf6fd;border-color:#c7dff3}
  .mobile-pdf-page{min-width:68px;font-variant-numeric:tabular-nums}
  .mobile-pdf-page-sep{color:#98a2b3}
  .mobile-pdf-spacer{flex:1 1 auto}
  .mobile-pdf-stage{
    flex:1 1 auto;min-height:0;overflow:auto;
    padding:10px;box-sizing:border-box;
    display:flex;align-items:flex-start;justify-content:flex-start;
    overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
    background:linear-gradient(180deg,#e9eef4,#e2e8ef);
  }
  .mobile-pdf-canvas{
    display:block;flex:0 0 auto;margin:0 auto;
    background:#fff;box-shadow:0 4px 20px rgba(31,48,73,.18);
  }
  .mobile-pdf-loading,.mobile-pdf-error{
    width:100%;min-height:180px;display:flex;flex-direction:column;
    align-items:center;justify-content:center;gap:8px;text-align:center;
    padding:24px;box-sizing:border-box;color:#64748b;
  }
  .mobile-pdf-loading i{font-size:1.35rem;color:#146bb8}
  .mobile-pdf-error i{font-size:1.35rem;color:#b45309}
  .mobile-pdf-error strong{color:#344054}
  .mobile-pdf-error a{margin-top:4px}
  .mobile-pdf-loading[hidden],.mobile-pdf-error[hidden],.mobile-pdf-canvas[hidden]{display:none!important}

  /* Document workspace: app-like use of the available height. */
  body.no-sidebar .document-page{padding-bottom:env(safe-area-inset-bottom,0px)}
  body.no-sidebar .doc-mobile-switch{top:calc(58px + env(safe-area-inset-top,0px))!important}
  body.no-sidebar .document-editable .meta-panel .meta-header{top:calc(108px + env(safe-area-inset-top,0px))!important}
  body.no-sidebar .meta-wizard-footer{padding-bottom:max(7px,env(safe-area-inset-bottom,0px))!important}
}

@media (max-width: 768px){
  html,body{min-height:100%;min-height:100dvh}
  body{font-size:15px;-webkit-tap-highlight-color:rgba(20,107,184,.12)}
  .top-bar{
    min-height:calc(58px + env(safe-area-inset-top,0px));
    padding-top:env(safe-area-inset-top,0px)!important;
  }
  .top-bar .logo{font-size:1.08rem;white-space:nowrap}
  .sidebar-toggle{width:40px;height:40px;min-height:40px;margin-right:7px;padding:0}
  .top-nav{margin-top:0!important;gap:2px}
  .top-nav a,.top-user{width:38px;height:38px;margin:0!important}
  .content{padding-bottom:max(18px,calc(12px + env(safe-area-inset-bottom,0px)))!important}
  .footer{padding-bottom:max(14px,env(safe-area-inset-bottom,0px))}

  /* Keep mobile forms touch-friendly without changing desktop density. */
  input[type="text"],input[type="password"],input[type="email"],input[type="tel"],input[type="url"],input[type="date"],input[type="number"],select,textarea{
    font-size:16px; /* prevents involuntary browser zoom on focus */
  }
  .btn,button,input[type="submit"]{min-height:42px}
  .admin-tabs{scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch}
  .admin-tab{scroll-snap-align:start;min-height:42px}
  .table-wrap{max-width:100%;-webkit-overflow-scrolling:touch}

  /* Explorer: more usable tap targets while preserving existing desktop layout. */
  .explorer-commandbar{border-radius:11px}
  .xp-btn{min-width:40px!important;min-height:40px!important}
  .grid .card{touch-action:manipulation}
  .grid .card .info h3{-webkit-line-clamp:3!important;min-height:0!important}
}

@media (max-width: 480px){
  .top-bar{padding-left:7px!important;padding-right:7px!important}
  .top-nav a,.top-user,.pwa-install-btn.is-visible:not([hidden]){width:36px;height:36px;min-height:36px}
  .viewer-card.has-mobile-pdf-viewer .mobile-pdf-viewer{height:calc(100dvh - 142px);min-height:380px}
  .mobile-pdf-toolbar{gap:3px;padding-left:5px;padding-right:5px}
  .mobile-pdf-tool{min-width:36px;width:36px;padding:0}
  .mobile-pdf-page{min-width:62px;padding-left:6px;padding-right:6px}
  .mobile-pdf-stage{padding:7px}
}

@media (display-mode: standalone){
  html{background:#f3f6fa}
  body{overscroll-behavior-y:none}
  .top-bar{padding-top:env(safe-area-inset-top,0px)}
  .footer{padding-bottom:max(12px,env(safe-area-inset-bottom,0px))}
}

/* ============================================================
   V13.6 Fold / narrow viewport hardening
   Final mobile overrides intentionally use !important because
   doc.php contains later desktop/wizard layout rules.
   ============================================================ */
@media (max-width:980px){
  html,body{
    width:100%;max-width:100%;overflow-x:hidden;
  }
  body.no-sidebar .content{
    width:100%!important;max-width:100%!important;min-width:0!important;
    box-sizing:border-box!important;overflow-x:clip!important;
  }
  body.no-sidebar .document-page,
  body.no-sidebar .document-editable,
  body.no-sidebar .document-editable .doc-layout,
  body.no-sidebar .document-editable .doc-left,
  body.no-sidebar .document-editable .doc-right,
  body.no-sidebar .document-editable .viewer-sticky,
  body.no-sidebar .document-editable .viewer-card,
  body.no-sidebar .document-editable .meta-panel,
  body.no-sidebar .document-editable .meta-scroll,
  body.no-sidebar .document-editable .meta-edit-form,
  body.no-sidebar .document-editable .meta-sections,
  body.no-sidebar .document-editable [data-meta-panel],
  body.no-sidebar .document-editable .m-body,
  body.no-sidebar .document-editable .form-grid,
  body.no-sidebar .document-editable .form-group{
    min-width:0!important;width:100%!important;max-width:100%!important;
    box-sizing:border-box!important;
  }
  body.no-sidebar .document-editable .doc-layout{
    display:grid!important;
    grid-template-columns:minmax(0,1fr)!important;
    gap:8px!important;
  }
  body.no-sidebar .document-editable .doc-left,
  body.no-sidebar .document-editable .doc-right{overflow-x:clip!important}

  /* A fitted PDF can never exceed the visible viewer width. Zoomed pages may pan. */
  .viewer-card.has-mobile-pdf-viewer,
  .viewer-card.has-mobile-pdf-viewer .mobile-pdf-viewer,
  .viewer-card.has-mobile-pdf-viewer .mobile-pdf-stage{
    width:100%!important;max-width:100%!important;min-width:0!important;
    box-sizing:border-box!important;
  }
  .mobile-pdf-canvas:not(.is-zoomed){max-width:100%!important;height:auto!important}
  .mobile-pdf-viewer:not(.is-zoomed) .mobile-pdf-stage{overflow-x:hidden!important}

  /* Meta header/actions must wrap instead of widening the Fold viewport. */
  body.no-sidebar .document-editable .meta-panel .meta-header{
    width:100%!important;max-width:100%!important;min-width:0!important;
    box-sizing:border-box!important;
  }
  body.no-sidebar .document-editable .meta-header-actions{
    min-width:0!important;max-width:100%!important;flex-wrap:wrap!important;
  }

  /* All controls are bounded by their field, including address autocomplete. */
  body.no-sidebar .document-editable input,
  body.no-sidebar .document-editable select,
  body.no-sidebar .document-editable textarea,
  body.no-sidebar .document-editable .address-autocomplete,
  body.no-sidebar .document-editable .address-suggestions,
  body.no-sidebar .document-editable .address-master-card,
  body.no-sidebar .document-editable .address-master-state,
  body.no-sidebar .document-editable .address-master-actions,
  body.no-sidebar .document-editable .wizard-profile-choice,
  body.no-sidebar .document-editable .wizard-profile-empty,
  body.no-sidebar .document-editable .wizard-ocr-summary,
  body.no-sidebar .document-editable .wizard-qr-strip,
  body.no-sidebar .document-editable .ocr-learning-box,
  body.no-sidebar .document-editable .ocr-learning-fields,
  body.no-sidebar .document-editable .action-menu{
    min-width:0!important;max-width:100%!important;box-sizing:border-box!important;
  }
  body.no-sidebar .document-editable .ocr-profile-chooser{
    width:100%!important;max-width:100%!important;min-width:0!important;margin-left:0!important;
  }
  body.no-sidebar .document-editable .address-master-state{flex:1 1 100%!important}
  body.no-sidebar .document-editable .address-master-actions{width:100%!important;justify-content:flex-start!important}
  body.no-sidebar .document-editable .address-master-state>div,
  body.no-sidebar .document-editable .wizard-qr-copy,
  body.no-sidebar .document-editable .ocr-learning-summary-copy{min-width:0!important;max-width:100%!important}

  /* Wizard navigation is allowed to shrink below the old 31px column minimum. */
  body.no-sidebar .document-editable .meta-workspace-tabs.meta-wizard-steps{
    width:100%!important;max-width:100%!important;min-width:0!important;
    grid-template-columns:repeat(var(--wizard-count,7),minmax(0,1fr))!important;
    overflow:hidden!important;box-sizing:border-box!important;
  }
  body.no-sidebar .document-editable .meta-wizard-steps .meta-step{
    min-width:0!important;max-width:100%!important;padding-left:2px!important;padding-right:2px!important;
  }
}

@media (max-width:560px){
  /* On a narrow Fold cover display metadata is deliberately one column everywhere. */
  body.no-sidebar .document-editable .meta-panel.meta-tabs-ready .form-grid,
  body.no-sidebar .document-editable .meta-panel.meta-tabs-ready .meta-sections,
  body.no-sidebar .document-editable details[data-meta-panel="details"] .form-grid,
  body.no-sidebar .document-editable .ocr-learning-fields,
  body.no-sidebar .document-editable .action-menu[data-meta-panel="actions"].is-meta-active{
    grid-template-columns:minmax(0,1fr)!important;
  }
  body.no-sidebar .document-editable .form-group,
  body.no-sidebar .document-editable details[data-meta-panel="details"].is-meta-active{
    grid-column:1/-1!important;
  }
  body.no-sidebar .document-editable .meta-panel .meta-header{
    display:grid!important;grid-template-columns:minmax(0,1fr)!important;align-items:start!important;gap:7px!important;
  }
  body.no-sidebar .document-editable .meta-header-actions{
    width:100%!important;justify-content:flex-start!important;
  }
  body.no-sidebar .document-editable .meta-save-state{flex:1 1 auto!important}
  body.no-sidebar .document-editable .meta-save-btn{flex:1 1 112px!important}
  body.no-sidebar .document-editable .address-master-actions .btn-small{flex:1 1 100%!important;width:100%!important}
  body.no-sidebar .document-editable .wizard-profile-choice{grid-template-columns:minmax(0,1fr)!important}
  body.no-sidebar .document-editable .wizard-profile-apply{width:100%!important}
  body.no-sidebar .document-editable .wizard-ocr-facts{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}

@media (max-width:390px){
  body.no-sidebar .content{padding-left:6px!important;padding-right:6px!important}
  body.no-sidebar .document-editable .meta-scroll{padding-left:7px!important;padding-right:7px!important}
  body.no-sidebar .document-editable .wizard-ocr-facts{grid-template-columns:minmax(0,1fr)!important}
  body.no-sidebar .document-editable .wizard-qr-strip{flex-wrap:wrap!important}
  body.no-sidebar .document-editable .wizard-qr-strip .btn{width:100%!important;flex:1 1 100%!important}
  .mobile-pdf-toolbar{flex-wrap:wrap!important}
  .mobile-pdf-spacer{display:none!important}
  .mobile-pdf-toolbar .mobile-pdf-page{flex:1 1 auto!important;min-width:54px!important}
}
