/* Phone / tablet layout. Everything here only applies when mobile.js adds class "mobile" to <html>. */
html.mobile{--safe-top:max(env(safe-area-inset-top,0px),var(--safe-area-inset-top,0px));--safe-bottom:max(env(safe-area-inset-bottom,0px),var(--safe-area-inset-bottom,0px));--safe-left:max(env(safe-area-inset-left,0px),var(--safe-area-inset-left,0px));--safe-right:max(env(safe-area-inset-right,0px),var(--safe-area-inset-right,0px))}
html.mobile body{height:100dvh;padding-top:var(--safe-top);padding-left:var(--safe-left);padding-right:var(--safe-right);-webkit-tap-highlight-color:transparent;overscroll-behavior:none}
html.mobile button,html.mobile select{min-height:40px}
html.mobile header .top{flex-wrap:nowrap;overflow-x:auto;gap:4px;padding:6px 8px;scrollbar-width:none}
html.mobile header .top>*{flex:none}
html.mobile header .top::-webkit-scrollbar{display:none}
html.mobile .logo,html.mobile header .sep,html.mobile #handBtn,html.mobile #planBtn,html.mobile #printBtn,
html.mobile #darkBtn,html.mobile #verBtn,html.mobile .tip,html.mobile #zoomInfo{display:none}
html.mobile .spacer{display:none}
html.mobile #pageNum{width:40px;min-height:36px;font-size:15px}
html.mobile #pageInfo{white-space:nowrap}

/* tools (the old ribbon) stay out of the way until "Tools" is tapped */
html.mobile nav.tabs,html.mobile .ribbon{display:none}
html.mobile.tools nav.tabs{display:flex;overflow-x:auto;padding:4px 8px 0;scrollbar-width:none}
html.mobile.tools .ribbon{display:block;max-height:34vh;overflow-y:auto;padding:8px}
html.mobile .tab{white-space:nowrap;padding:9px 12px;flex:none}
html.mobile #toolsBtn.on{background:#dfe8ff;border-color:#2956e8;color:#1f47c9}

html.mobile #viewer{padding:8px 4px}
html.mobile .page{margin-bottom:10px}
html.mobile #thumbs{position:fixed;left:0;top:0;bottom:0;z-index:45;width:132px;box-shadow:4px 0 16px rgba(0,0,0,.3);padding-top:calc(56px + var(--safe-top));padding-bottom:70px}
html.mobile #searchBar input{width:auto;flex:1;min-width:0}

/* bottom action bar: the signing buttons live here */
#mbar{display:none}
html.mobile #mbar{display:flex;gap:6px;padding:8px 8px calc(8px + var(--safe-bottom));background:#fff;border-top:1px solid #d5d8de;flex:none;z-index:30}
html.mobile #mbar button{flex:1;min-width:0;min-height:50px;padding:6px 4px;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
html.mobile #mbar #signBtn{flex:1.5;font-weight:600;background:#e9efff;border-color:#2956e8;color:#1f47c9}
html.mobile #mbar #saveBtn{flex:1.4;background:#2956e8;border-color:#2956e8;color:#fff}
html.mobile #mbar button:disabled{opacity:.4}

/* big, finger-sized handles on the selected signature / text */
html.mobile .item .h{width:30px;height:30px;right:-15px;bottom:-15px}
html.mobile .item .x{width:30px;height:30px;right:-15px;top:-38px;line-height:24px;font-size:20px}
html.mobile .item.sel{border:2px solid #2956e8}

/* saved-signature picker becomes a bottom sheet */
html.mobile #sigMenu{left:8px!important;right:8px;top:auto!important;bottom:calc(76px + var(--safe-bottom));max-height:55vh;min-width:0;padding:8px}
html.mobile .menu .opt{padding:10px;font-size:16px}
html.mobile .menu .opt img{height:60px;max-width:70vw}

html.mobile dialog{width:96vw;max-width:96vw;padding:14px}
html.mobile #askDialog{min-width:0}
html.mobile #sigPad{width:100%;height:auto}
html.mobile #saved img{height:56px}
html.mobile dialog .row{flex-wrap:wrap}
html.mobile .wmBody{flex-direction:column}
html.mobile .wmForm{width:100%}
html.mobile .wmPreview{min-width:0}
html.mobile #printPreview img{width:46%}
html.mobile #toast{bottom:calc(84px + var(--safe-bottom));max-width:92vw;text-align:center}
html.mobile #empty{margin-top:8vh;padding:0 16px}
html.mobile #empty p{font-size:16px}

/* top bar order: Open, Tools, page controls, zoom first; the rest scrolls sideways */
html.mobile #openBtn,html.mobile #toolsBtn{order:0}
html.mobile #prevBtn,html.mobile #pageInfo,html.mobile #nextBtn{order:1}
html.mobile #zoomOut,html.mobile #zoomIn,html.mobile #undoBtn,html.mobile #redoBtn{order:2}
html.mobile #thumbBtn,html.mobile #findBtn,html.mobile #accountBtn{order:3}
html.mobile header .top button{padding:6px 9px}
html.mobile .item .x{min-height:0;padding:0;border-radius:50%}
html.mobile #mbar button{font-size:14px;padding:6px 2px}


/* home screen (Android): open button + recent files */
#home{max-width:520px;margin:0 auto;padding:14px 8px;text-align:left}
#home #homeOpen{width:100%;min-height:60px;font-size:18px;font-weight:600;margin-bottom:18px}
#home h3{margin:0 0 6px;font-size:14px;color:#666;text-transform:uppercase;letter-spacing:.04em}
#home .recent{display:flex;gap:6px;margin-bottom:6px}
#home .rname{flex:1;min-width:0;display:flex;justify-content:space-between;align-items:center;gap:8px;text-align:left;min-height:52px;background:#fff;font-size:15px}
#home .rname .n{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#home .rname small{color:#888;flex:none}
#home .rx{flex:none;width:44px;color:#888;font-size:20px;background:#fff}
html.mobile #saveAsBtn,html.mobile #shareBtn{order:3}
#home #homeVer{margin-top:24px;text-align:center}

/* v12: signature window fills the screen on a phone; no page shadows (they slow scrolling) */
html.mobile #sigDialog[open]{display:flex;flex-direction:column;width:100vw;height:100dvh;max-width:none;max-height:none;margin:0;border-radius:0;
  padding:calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left))}
html.mobile #sigDialog h3{margin:4px 0 6px}
html.mobile #sigPad{flex:1 1 auto;height:auto;min-height:180px;border-radius:12px}
html.mobile #sigDialog .importRow .chk{font-size:13px}
html.mobile #sigDialog #saved{margin-bottom:8px;min-height:0}
html.mobile .page{box-shadow:none;border:1px solid #cfd3db}
html.mobile #home{padding:12px 8px}
html.mobile #home #homeOpen{min-height:30vh}
html.mobile button{height:auto}

/* ---- v13: Figma tuning (appearance only; phone layout) ---- */
/* touch targets: 44 px everywhere, 50 px in the bottom bar */
html.mobile button,html.mobile select{min-height:44px}
html.mobile #mbar button{min-height:50px}
html.mobile header .top{padding:6px 8px}
html.mobile #prevBtn,html.mobile #nextBtn,html.mobile #zoomOut,html.mobile #zoomIn,html.mobile #thumbBtn{min-width:44px;padding:0}
html.mobile #pageNum{width:44px;height:44px;min-height:44px;padding:0;font-size:15px;font-weight:500;border-radius:8px}

/* document tabs: 44 px tab on an 8 px padded strip */
html.mobile #docTabs{padding:8px 8px 0}
html.mobile .docTab{min-height:44px;padding:0 0 0 12px;border-radius:8px 8px 0 0;font-weight:500}
html.mobile .docClose{min-width:44px;min-height:44px;font-size:16px}

/* selected signature handles: 44 px targets */
html.mobile .item .h{width:44px;height:44px;right:-22px;bottom:-22px}
html.mobile .item .x{width:44px;height:44px;right:-22px;top:-45px;border-radius:15px;line-height:1;font-size:22px}

/* start screen: even 16 px rhythm */
html.mobile #home{gap:16px;padding:16px}
html.mobile #home #homeOpen{min-height:220px;gap:12px;margin:0}
html.mobile #home h3,html.mobile #home .recent,html.mobile #home .hint,html.mobile #home #homeVer{margin:0}

/* tools: tab strip and ribbon */
html.mobile .tab{height:44px;padding:10px 12px 8px}
html.mobile.tools nav.tabs{padding:0 0 0 8px;background:#fff}
html.mobile.tools .ribbon{padding:8px}
html.mobile .panel{gap:8px}
html.mobile .lbl{min-height:44px}
html.mobile input[type=color]{width:44px;height:44px}

/* signature window */
html.mobile #sigDialog[open]{background:#eef0f4}
html.mobile #sigDialog #saved img{height:44px;width:128px;object-fit:contain;padding:4px;border-radius:8px;background:#fff;border:1px solid #d7dbe3}
html.mobile #sigDialog .importRow .chk{height:44px;padding:0 10px;border:1px solid #d7dbe3;border-radius:8px;background:#fff;font-size:12px}
html.mobile #sigDialog input[type=text],html.mobile #sigDialog select{height:44px}

/* saved-signature sheet */
html.mobile #sigMenu{border-radius:12px;padding:8px}
html.mobile .menu .opt{padding:10px;gap:10px;min-height:44px;font-size:15px;font-weight:500}
html.mobile .menu .opt img{height:46px;width:130px;max-width:none;object-fit:contain;padding:5px;box-sizing:border-box;border-radius:8px;background:#fff;border:1px solid #d7dbe3}

/* sign-in dialog: Forgot / Create on one line, Sign in + Cancel side by side */
html.mobile #authDialog{width:min(358px,92vw);padding:20px;border-radius:18px}
html.mobile #authForm{display:flex;flex-direction:column;gap:16px}
html.mobile #authDialog h3{margin:0}
html.mobile #authDialog label.stack{margin:0;gap:6px;font-size:12px}
html.mobile #authDialog input{height:48px}
html.mobile #authMsg{min-height:0;margin:0}
html.mobile #authDialog .row{margin:0;gap:8px;flex-wrap:wrap}
html.mobile #authReset{order:1}
html.mobile #authUp{order:2;margin-left:auto}
html.mobile #authIn{order:3;flex:1 1 calc(50% - 4px)}
html.mobile #authCancel{order:4;flex:1 1 calc(50% - 4px)}
html.mobile #sigDialog .row label{display:flex;align-items:center;gap:6px}
html.mobile #authMsg:empty{display:none}
html.mobile #sigDialog .importRow{flex-wrap:nowrap}
html.mobile #sigDialog .importRow .chk{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;gap:6px}
html.mobile #sigDialog .importRow .chk input{margin:0}


/* system status bar area is painted like the header, so the clock / signal icons sit on white */
html.mobile body::before{content:'';position:fixed;top:0;left:0;right:0;height:var(--safe-top);background:#fff;z-index:200;pointer-events:none}

/* v15: small round / icon buttons keep their own size (the 44 px minimum made them ovals) */
html.mobile #wmSwatches button,html.mobile #wmSwatches input[type=color]{min-height:0;min-width:0;width:36px;height:36px;border-radius:50%;padding:0}
html.mobile #saved .sg button{min-height:0;min-width:0;width:26px;height:26px;right:-8px;top:-10px;border-radius:50%;padding:0}
html.mobile .wmNav button,html.mobile .wmForm .pad button{min-height:40px;min-width:40px}
html.mobile #thumbMenu button{min-height:44px}
/* watermark: the preview stays at the top while you change the options */
html.mobile .wmPreview{position:sticky;top:0;z-index:2;background:#fff;order:-1;padding-bottom:6px;min-width:0}
html.mobile #wmScroll{max-height:36vh}
html.mobile .wmNav{flex-wrap:wrap}

/* v16: icons instead of words, top bar order, account colour, themes */
html.mobile #openBtn{display:none}
html.mobile #toolsBtn{order:0}
html.mobile #prevBtn,html.mobile #pageInfo,html.mobile #nextBtn{order:1}
html.mobile #zoomOut,html.mobile #zoomIn,html.mobile #undoBtn,html.mobile #redoBtn{order:2}
html.mobile #thumbBtn,html.mobile #findBtn,html.mobile #accountBtn,html.mobile #aboutBtn{order:3}
html.mobile #saveAsBtn,html.mobile #shareBtn{order:4}
html.mobile button.ico{width:44px;min-width:44px;padding:0;position:relative}
html.mobile #mbar button.ico.withlabel{width:auto;padding:0 8px;gap:6px}
html.mobile #mbar button.ico svg{flex:none}
html.mobile .ribbon button.ico{width:48px;min-width:48px;height:48px}
html.mobile .panel .sep{display:block;width:1px;height:30px;margin:0 2px}
html.mobile button.ico.locked::after{content:"🔒";position:absolute;right:1px;top:1px;font-size:9px}
html.mobile #accountBtn.ico{color:#9aa1b2}
html.mobile #accountBtn.ico.in{background:#2956e8;border-color:#2956e8;color:#fff}
html.mobile #annTool,html.mobile #annWidth,html.mobile #hlColor{-webkit-appearance:none;appearance:none;width:48px;min-width:48px;height:48px;padding:0;color:transparent;background-repeat:no-repeat;background-position:center;background-size:22px;border-radius:8px}
html.mobile #hlColor{background-size:auto;border-radius:50%;width:36px;min-width:36px;height:36px;min-height:36px;border:2px solid #d7dbe3}

/* About: appearance buttons */
#aboutTheme{align-items:center}
#aboutTheme .seg{display:inline-flex;gap:6px}
#aboutTheme .seg button{height:36px;padding:0 10px;gap:6px}
#aboutTheme .seg button.on{background:#e6edff;border-color:#2956e8;color:#1f47c9}
html.mobile #aboutTheme .seg button{min-height:44px}

/* dark theme for the phone-only parts */
html.dark.mobile #mbar,html.dark.mobile #home,html.dark.mobile #sigMenu{filter:invert(1) hue-rotate(180deg)}
html.dark.mobile body::before{background:#000}

/* watermark: preview (stays put) and options (scrolls) in slightly different tones */
html.mobile .wmPreview{background:#e3e9f5;box-shadow:0 6px 8px -6px rgba(20,30,60,.35);border-radius:0 0 12px 12px;padding:8px 8px 6px;margin:0 -4px}
html.mobile #wmScroll{background:#d3dbec}
html.mobile .wmForm{background:#fff;padding-top:6px}
html.dark.mobile #docTabs{filter:none}

/* v18: Undo / Redo in the top bar, thumbnails that fit the drawer, in-app pickers, dialogs inside the safe area, watermark preview at full width */
html.mobile header .top{gap:2px;padding:6px}
html.mobile header .top button.ico{width:40px;min-width:40px}
html.mobile header .top #pageNum{width:38px}
html.mobile header .top #pageInfo{font-size:13px}
html.mobile .thumb{width:auto;margin:0 0 10px;padding:2px}
html.mobile .thumb canvas{width:100%;height:auto}

html.mobile dialog[open]:not(#sigDialog):not(#mSheet){top:calc(var(--safe-top) + 8px);bottom:calc(var(--safe-bottom) + 8px);max-height:calc(100dvh - var(--safe-top) - var(--safe-bottom) - 16px);overflow:auto}

/* bottom sheet used for drop-down lists, colours and yes / no questions */
dialog#mSheet{position:fixed;left:0;right:0;bottom:0;top:auto;margin:0;width:100%;max-width:none;max-height:70dvh;overflow:auto;border-radius:16px 16px 0 0;padding:16px 12px calc(16px + var(--safe-bottom,0px));background:#fff;color:var(--ink)}
#mSheet h3{margin:0 4px 8px}
#mSheet .opts{display:flex;flex-direction:column;gap:4px}
#mSheet .opt{justify-content:flex-start;gap:12px;min-height:48px;height:auto;border:0;background:transparent;font-size:16px;text-align:left;padding:0 12px}
#mSheet .opt.cur{background:#e6edff;color:var(--blue-d);font-weight:600}
#mSheet .opt i{width:22px;height:22px;border-radius:50%;box-shadow:0 0 0 1px #b8bdc9;flex:none}
#mSheet .swatches{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;padding:4px}
#mSheet .sw{height:52px;min-height:52px;border-radius:12px;padding:0;box-shadow:0 0 0 1px #b8bdc9 inset}
#mSheet .sw.cur{outline:3px solid var(--blue);outline-offset:2px}
#mSheet .msg{margin:4px 4px 16px;font-size:16px;white-space:pre-line}
#mSheet .row{margin-top:0}
#mSheet .row button{flex:1}

/* watermark: preview uses the whole width, page buttons and zoom share one row */
html.mobile #wmDialog[open]{width:100vw;max-width:100vw;padding:12px 8px;border-radius:0}
html.mobile .wmBody{align-items:stretch;gap:10px}
html.mobile .wmPreview{flex:none;width:100%;margin:0;padding:8px 6px 6px}
html.mobile #wmScroll{max-width:none}
html.mobile .wmNav{flex-wrap:nowrap;gap:4px;white-space:nowrap}
html.mobile .wmNav button{min-width:38px;padding:0 6px}
html.mobile .wmZoom{margin-left:6px;gap:2px}
html.mobile .wmZoom #wmZoomInfo{min-width:38px}

/* v19: "+" at the right end of the document tabs opens another PDF */
html.mobile #tabAdd{position:sticky;right:0;flex:none;margin-left:auto;width:44px;min-width:44px;height:44px;padding:0;border-radius:8px 8px 0 0;border:0;background:#e3e6ec;box-shadow:-8px 0 8px -4px #e3e6ec;color:var(--blue-d)}
