/* Touch tablets + phones (iPad Safari first). Classes come from /touch-ui.js: html.ts-touch / ts-ipad / ts-ios / ts-nogdm / ts-kb.
   Linked AFTER the app's own CSS so equal-specificity rules here win. Nothing here applies to a mouse-only desktop:
   rules sit under html.ts-touch or @media (hover:none) and (pointer:coarse), except the narrow-window rail block (801-960px),
   which fixes an overflow every 820px-wide window had (iPad portrait, small desktop windows). Audit: docs/audit/IPAD-AUDIT-2026-10-16.md */

/* ---------- 801-960px wide (iPad 10/11" portrait): icons-only rail so the chat keeps ~480px and the composer's Send button fits ---------- */
@media(min-width:801px) and (max-width:960px){
  html:not(.rs-m-e) #rail{width:64px!important;min-width:0;flex:none;padding-left:8px;padding-right:8px;align-items:stretch}
  html:not(.rs-m-e) #rail .rt select,html:not(.rs-m-e) #rail .rt>*:not(#acb),html:not(.rs-m-e) #rail .qwrap,html:not(.rs-m-e) #mxst,html:not(.rs-m-e) .mechip .mcn,html:not(.rs-m-e) .mechip i,html:not(.rs-m-e) #gab{display:none!important}
  html:not(.rs-m-e) #rail .rt{justify-content:center;padding:0 0 12px}html:not(.rs-m-e) #acb{margin:0}
  html:not(.rs-m-e) .ni{font-size:0;gap:0;justify-content:center;padding:0;position:relative}
  html:not(.rs-m-e) .ni em,html:not(.rs-m-e) .ni em.dot{position:absolute;top:6px;right:10px;width:9px;height:9px;min-width:0;padding:0;font-size:0;margin:0;box-shadow:0 0 0 2px var(--wash)}
  html:not(.rs-m-e) #pwa-row{justify-content:center;padding:0}html:not(.rs-m-e) #pwa-row span,html:not(.rs-m-e) #pwa-row em{display:none}
  html:not(.rs-m-e) .mechip{justify-content:center;padding:6px 0}
  html:not(.rs-m-e) #pwa-hint{display:none!important}
  #side{width:260px}
  #comp .ctool{min-width:0;flex-wrap:nowrap}
}

/* ---------- whole-app touch behaviour ---------- */
html.ts-touch{-webkit-text-size-adjust:100%;text-size-adjust:100%;touch-action:manipulation}
html.ts-touch body{overscroll-behavior:none}
html.ts-touch button,html.ts-touch a,html.ts-touch [role=button],html.ts-touch .ni,html.ts-touch .cv,html.ts-touch .ibtn,html.ts-touch .mi{-webkit-tap-highlight-color:transparent;touch-action:manipulation}
/* scrolling panels keep their own momentum and never drag the whole page (rubber-banding the app shell) */
html.ts-touch #msgs,html.ts-touch #convs,html.ts-touch #nav,html.ts-touch #rail,html.ts-touch #appview,html.ts-touch #tpbody,html.ts-touch #gsb,html.ts-touch #cside,html.ts-touch .lkm,html.ts-touch .cmenu,html.ts-touch #mbox,html.ts-touch #modal .box{overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
/* long-press opens our menu: no iOS callout / text-selection loupe on the rows that have one */
html.ts-touch #msgs .m,html.ts-touch #tpbody .m,html.ts-touch .cv,html.ts-touch .ni,html.ts-touch #nav,html.ts-touch .dr-r,html.ts-touch .tools,html.ts-touch .lkm,html.ts-touch .cmenu{-webkit-touch-callout:none}
html.ts-touch #msgs .m,html.ts-touch #tpbody .m,html.ts-touch .cv,html.ts-touch .ni,html.ts-touch .dr-r{-webkit-user-select:none;user-select:none}
html.ts-touch body.msel #msgs .m{-webkit-user-select:none}

/* ---------- pinch-zoom is always allowed (no maximum-scale anywhere). iOS zooms the page into a focused field whose text is under 16px
   and leaves it zoomed, so every field is 16px on a touch screen: inputs, textareas, selects and the rich editors (contenteditable:
   mail compose, mail reply; Docs is 16px already). Slides text keeps its own size (it is drawn to the slide's scale). ---------- */
@media(hover:none) and (pointer:coarse){
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]),textarea,select{font-size:16px!important}
  [contenteditable]:not([contenteditable=false]):not(.sd-sbox *):not(.ProseMirror *){font-size:max(16px,1em)!important}
}
/* zoomed in (html.ts-zoomed, touch-ui.js): one finger pans the zoomed page in every direction. overscroll-behavior:none on the page (pwa-ui.css,
   touch-ui.css above) or contain on a panel kept a move from ever reaching the zoomed page (Chrome does not pan the zoomed view past either:
   pinch-zoom-ui.check.js). The touch-action line is for WebKit, which drops "pan-y pinch-zoom" and keeps plain pan-y (phone-shell.css), so a
   zoomed page could only move up / down there; Chrome's pan-y pinch-zoom already lets the zoomed view pan sideways (not testable headless) */
html.ts-zoomed #side,html.ts-zoomed #main,html.ts-zoomed #side #convs .cv,html.ts-zoomed body:not(.appmode) #main,html.ts-zoomed body:not(.appmode).tp-on #tpanel{touch-action:manipulation!important}
html.ts-zoomed,html.ts-zoomed body,html.ts-zoomed #msgs,html.ts-zoomed #side,html.ts-zoomed #convs,html.ts-zoomed #nav,html.ts-zoomed #rail,html.ts-zoomed #appview,html.ts-zoomed #tpbody,html.ts-zoomed #gsb,html.ts-zoomed #cside,html.ts-zoomed #mbox,html.ts-zoomed #modal .box,html.ts-zoomed .msh-box{overscroll-behavior:auto!important}

/* ---------- hover-only controls: always visible on touch (no :hover on a finger) ---------- */
html.ts-touch #msgs .m.tap-on .tools,html.ts-touch #tpbody .m.tap-on .tools{display:flex}
html.ts-touch .m.tap-on{background:var(--hov,rgba(0,0,0,.03))}
@media(hover:none) and (pointer:coarse){
  .cal-li .gear,.gs-mrow .mo,.dr-r .dr-act,.mt-r .mt-act.hov,.wp-app .pn,.sd-card .sd-cdel,.bc-day .bc-plus,.bg-h .bg-hm,
  .dx-cover .cv-act,.dx-scroll .dx-cover .cv-add,.dx-callout .dx-callout-bar,#fbar .fb-sec .fb-add,#fb-chip svg,#rl-pop .rl-t .rl-st,
  .ad-fc .ac,.fl-n .x,.mn-node>.mn-col.open,#rmode{opacity:1}
  .wk-node .ops,.wa-b .wa-hv,.sh-chart .sh-chart-btns{display:flex}
  .lpc .lx,.cf-fi .un{display:block}
  .sd-si .sd-sm,#fbar .fb-i[data-lid] .fb-ed{display:inline-flex}
  .cal-ev .rs:after{opacity:.6}
}

/* ---------- touch targets (Apple HIG 44pt) on tablets; phones already get 44px from pwa-ui.css ---------- */
@media(min-width:801px){
  html.ts-touch .ibtn{min-width:40px;min-height:40px}
  html.ts-touch #head .hr .ibtn{width:44px;height:44px}
  html.ts-touch .ctool .ibtn{width:40px;height:40px}
  html.ts-touch .tools button,html.ts-touch .tools.lk button{width:38px;height:38px;padding:0;display:flex;align-items:center;justify-content:center}
  html.ts-touch .lkm .mi{height:44px}
  html.ts-touch .cmenu .mi,html.ts-touch .mxmenu .mi{min-height:44px;display:flex;align-items:center}
  html.ts-touch #rail .ni{min-height:44px}
  html.ts-touch #convs .cvacts button{width:32px}/* wider targets; height stays inside the row's line 1 (chatlist.css .cvacts) */
  html.ts-touch #tx{font-size:16px}
  html.ts-touch #qs{font-size:16px}
  html.ts-touch .btn{min-height:36px}
  html.ts-touch #rmode{width:36px;height:36px;opacity:1}
  html.ts-touch #qs-flt{min-width:36px;min-height:36px;display:inline-flex;align-items:center;justify-content:center}
  html.ts-touch #cf-rail button,html.ts-touch #fbar button,html.ts-touch .cl-lbl{min-height:34px}
  html.ts-touch .cal-side button[aria-label^=Previous],html.ts-touch .cal-side button[aria-label^=Next],html.ts-touch .cal-side [title^=Previous],html.ts-touch .cal-side [title^=Next]{min-width:36px;min-height:36px}
  html.ts-touch .cal-li .gear{min-width:32px;min-height:32px}
}

/* ---------- on-screen keyboard: the app shrinks to the visible area (visualViewport) so the composer stays above the keyboard ---------- */
html.ts-shell.ts-kb,html.ts-shell.ts-kb body{min-height:0!important;overflow:hidden}   /* + height = the visible area, set inline by touch-ui.js (was var(--vvh) on <html>: a whole-page restyle per keyboard step) */
html.ts-shell.ts-kb #app{height:100%!important}
/* the keyboard covers the home indicator: no bottom safe-area padding above it. The iOS app's overlay keyboard leaves WKWebView (and so
   env(safe-area-inset-bottom) = 34px) unchanged, so the composer floated 34 px over the keyboard on a white band (Kenny 2026-10-25). Android:
   the app already hands --dock-inset-bottom 0 while the keyboard is up (dock-mobile SystemInsets.forPage). */
html.ts-kb{--sa-b:0px}
html.ts-shell.ts-kb #login{min-height:0;height:100%}html.ts-kb #login .la-mslot{display:none}   /* the sign-in page fits the shrunk <body> (pwa-ui.css gives it min-height:100dvh) and scrolls in .lleft; <html> stays full height (touch-ui.js); the art strip makes room for the form (and pauses, login-anim.js sync) */
html.ts-touch.ts-kb #pwa-tabs{display:none!important}
html.ts-touch.ts-kb #pwa-upd{display:none!important}

/* ---------- popups sized with 100vh: Safari's 100vh is the LARGEST viewport (toolbars hidden), so their bottom was cut off ---------- */
html.ts-touch .cal-quick,html.ts-touch .bs-pop,html.ts-touch #rl-pop{max-height:calc(100dvh - 16px)}
html.ts-touch .cb-modal,html.ts-touch .sd-modal,html.ts-touch .sh-modal{max-height:calc(100dvh - 40px)}
html.ts-touch .mc{height:min(640px,calc(100dvh - 60px))}
html.ts-touch .mc-body{max-height:calc(100dvh - 9dvh - 118px)}
html.ts-touch.ts-kb .cal-quick,html.ts-touch.ts-kb .bs-pop,html.ts-touch.ts-kb #rl-pop,html.ts-touch.ts-kb #mbox,html.ts-touch.ts-kb #modal .box{max-height:calc(var(--vvh,100dvh) - 16px)}

/* ---------- standalone (Add to Home Screen) on iPad: content clears the status bar and the home indicator ---------- */
@media(min-width:801px){
  html.ts-standalone #rail,html.ts-standalone #side,html.ts-standalone #main,html.ts-standalone #appview{padding-top:var(--sa-t,env(safe-area-inset-top))}
  html.ts-standalone #comp,html.ts-standalone #rail{padding-bottom:max(8px,var(--sa-b,env(safe-area-inset-bottom)))}
  html.ts-standalone #rail{padding-left:max(10px,var(--sa-l,env(safe-area-inset-left)))}
}

/* ---------- meetings: Safari on iPad / iPhone has no screen capture (getDisplayMedia). The Share button keeps "Share Docs";
   the Desktop / window / tab choices (they failed silently) are replaced by a note. ---------- */
html.ts-nogdm #sharepop .sp-l,html.ts-nogdm #sharepop #spgo,html.ts-nogdm #sharepop .sp-foot label{display:none!important}
html.ts-nogdm #sharepop .sp-body{grid-template-columns:1fr}
html.ts-nogdm #sharepop .sp-r::before{content:"Screen sharing is not available in this browser (Safari on iPad and iPhone cannot share the screen). You can share a document with the meeting instead.";display:block;margin:0 0 12px;padding:10px 12px;border-radius:10px;background:var(--blue-wash);color:var(--ink);font:13px/1.45 var(--f-b)}

/* ---------- editors on touch ---------- */
/* (each pan rule is written twice: WebKit drops a touch-action that names pinch-zoom, so it keeps the plain pan-x / pan-y one; Chrome takes the
   second, which also leaves two-finger zoom to the page) */
/* Calendar day/week grid: a finger scrolls it (it was touch-action:none, so the grid could not scroll); cal-ui.js turns a tap into create / open */
html.ts-touch .cal-col{touch-action:pan-x pan-y;touch-action:pan-x pan-y pinch-zoom}
/* Sheets: a finger pans the grid; sheets-grid.js selects on tap and edits on a second tap */
html.ts-touch .sh-cv{touch-action:pan-x pan-y;touch-action:pan-x pan-y pinch-zoom}
/* Slides: the slide itself is a drawing surface (move / resize / marquee with finger or Pencil, no page pan underneath) */
html.ts-touch .sd-sbox{touch-action:none}
/* Docs: the image resize grip and per-block controls need a finger-sized hit area */
html.ts-touch .dx-img-grip{width:24px;height:24px;right:-12px;bottom:-12px}
