/* InstaPDF editor. Self-contained: no external fonts or scripts (the page promises that nothing leaves the device). */
:root {
  --blue: #0a6cff; --blue-dark: #0856cc; --ink: #1c1f26; --muted: #667085; --line: #e4e7ec; --bg: #f6f7f9; --stage: #eaecf2;
  --danger: #d92d20;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: #fff; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
svg.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.link { border: 0; background: none; color: var(--blue); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }
.plain { color: var(--ink); font-size: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--blue); background: var(--blue); color: #fff; padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); text-decoration: none; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: #fff; color: var(--blue); border-color: #b9d3ff; }
.btn.ghost:hover { background: #eef5ff; border-color: var(--blue); }
.btn.primary { width: 100%; padding: 11px 16px; }
.btn [data-icon], .btn svg.ic { display: inline-flex; align-items: center; justify-content: center; }
.btn svg.ic { display: block; }
.btn:disabled { opacity: .4; cursor: default; }
.btn:disabled:hover { background: var(--blue); }
.btn.ghost:disabled:hover { background: #fff; border-color: #b9d3ff; }
.ibtn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink); }
.ibtn:hover { background: var(--bg); }
.ibtn:disabled { opacity: .3; cursor: default; }
.only-mobile { display: none; }

/* ---------------------------------------------------------------------------------------------- the whole page is the editor */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: #fff; }
.titlebar { position: relative; z-index: 30; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 12px; border-bottom: 1px solid var(--line); background: #fff; flex: none; }
.brand { display: flex; align-items: center; }
.brand img { border-radius: 7px; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.titleblock { display: flex; flex-direction: column; justify-content: center; min-width: 0; line-height: 1.2; }
.titlebar input.docname { width: 260px; max-width: 100%; margin: 0 0 0 -7px; padding: 1px 6px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 600; text-overflow: ellipsis; }
.titlebar input.docname:hover:not(:disabled) { border-color: var(--line); }
.titlebar input.docname:focus { outline: none; border-color: var(--blue); background: #fff; }
.titlebar input.docname:disabled, .titlebar input.docname::placeholder { color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }
.sublink { width: max-content; padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
.sublink:hover { color: var(--blue); text-decoration: underline; }
.splitbtn { position: relative; display: inline-flex; }
.splitbtn .btn:first-child { border-radius: 9px 0 0 9px; }
.splitbtn .chev { border-radius: 0 9px 9px 0; border-left-color: rgba(255,255,255,.4); padding: 6px 7px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; padding: 4px; background: #fff; border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.22), 0 0 0 1px rgba(16,24,40,.07); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: #eef5ff; }

.body { position: relative; display: flex; flex: 1; min-height: 0; }
.sidebar { position: relative; width: 168px; flex: none; display: flex; flex-direction: column; background: var(--bg); border-right: 1px solid var(--line); }
.thumbs { position: relative; flex: 1; overflow: auto; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.tpage { position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; }
.tpage .tthumb { position: relative; display: block; background: #fff; box-shadow: 0 0 0 1px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.12); }
.tpage canvas { display: block; width: 100%; height: auto; }
.tpage .tnum { text-align: center; font-size: 12px; color: var(--muted); padding-top: 6px; }
.tpage.on .tthumb { box-shadow: 0 0 0 2px var(--blue), 0 2px 8px rgba(16,24,40,.12); }
.tpage.dragging { opacity: .35; }
.tpage.drop-before::before, .tpage.drop-after::after { content: ""; position: absolute; left: -4px; right: -4px; height: 3px; background: var(--blue); border-radius: 2px; }
.tpage.drop-before::before { top: -9px; }
.tpage.drop-after::after { bottom: 12px; }
.files-link { border: 0; background: none; color: var(--blue); font: inherit; font-size: 12px; padding: 8px; cursor: pointer; border-top: 1px solid var(--line); }

.stage { position: relative; flex: 1; min-width: 0; background: var(--stage); }
.viewer { position: absolute; inset: 0; overflow: auto; padding: 84px 24px 40px; -webkit-overflow-scrolling: touch; }
.vpages { display: flex; flex-direction: column; align-items: center; gap: 20px; width: max-content; min-width: 100%; }
.vpage { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(16,24,40,.22); flex: none; }
.vpage .vthumb { position: relative; display: block; width: 100%; background: #fff; }
.vpage canvas { display: block; width: 100%; height: auto; }
.vpage .vnum { position: absolute; left: 0; right: 0; bottom: -20px; text-align: center; font-size: 12px; color: var(--muted); }
.vpage.placing, .vpage.placing .vthumb { cursor: copy; }

.placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; width: 100%; border: 0; background: transparent;
  color: #8a93a6; font: inherit; font-size: 17px; cursor: pointer; transition: color .15s; }
.placeholder:hover, .placeholder.over { color: #5b6477; }


.ftb { position: absolute; z-index: 6; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; padding: 5px; border-radius: 14px; max-width: calc(100% - 24px);
  background: rgba(255,255,255,.82); -webkit-backdrop-filter: blur(14px) saturate(1.5); backdrop-filter: blur(14px) saturate(1.5);
  box-shadow: 0 8px 28px rgba(16,24,40,.2), 0 0 0 1px rgba(16,24,40,.06); }
.tb { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 52px; border: 0; background: transparent; padding: 6px 8px 4px; border-radius: 10px; color: var(--ink); cursor: pointer; font: inherit; font-size: 11px; }
.tb:hover { background: rgba(10,108,255,.1); }
.tb.on { background: rgba(10,108,255,.16); color: var(--blue); }
.tb.danger { color: var(--danger); }
.tb.danger:hover { background: rgba(217,45,32,.1); }
.tb:disabled { opacity: .3; cursor: default; background: transparent; }
.addgroup { display: flex; align-items: stretch; }
.tb.chevtb { min-width: 22px; padding: 4px 4px 4px 0; justify-content: center; }
.tb.chevtb svg.ic { width: 14px; height: 14px; }
.addmenu { z-index: 8; right: auto; min-width: 170px; }
.tsep { width: 1px; height: 30px; align-self: center; background: rgba(16,24,40,.12); margin: 0 3px; }
.toast { position: absolute; z-index: 7; bottom: 20px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); background: #101828; color: #fff; padding: 8px 16px; border-radius: 22px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.3); text-align: center; }

/* sheets: drop down from the toolbar on a computer, slide up from the bottom on a phone */
.sheets { position: absolute; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(16,24,40,.2); }
.sheet-panel { position: absolute; top: 82px; left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 24px)); max-height: calc(100% - 98px); overflow: auto;
  background: #fff; border-radius: 14px; padding: 14px 16px; box-shadow: 0 18px 50px rgba(16,24,40,.35), 0 0 0 1px rgba(16,24,40,.06); animation: sheet-in .16s ease-out; }
.sheet-panel.narrow { width: auto; padding: 10px; }
@keyframes sheet-in { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.hint { color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 18px; font: inherit; font-size: 14px; cursor: pointer; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: #e8f1ff; color: var(--blue); font-weight: 600; }

.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.files .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .meta { color: var(--muted); font-size: 12px; }
.files button { border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; padding: 1px 6px; }
.radio { display: block; margin: 8px 0; font-size: 14px; }
.radio input[type=radio] { margin-right: 6px; }
input.inline { width: 60px; }
input[type=text], input[type=number], input[type=password], select { padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 9px; font: inherit; background: #fff; }
input.wide, select.wide { width: 100%; margin: 4px 0; }
.error { color: var(--danger); margin: 8px 0 0; font-size: 13px; }
.tabs { display: flex; gap: 4px; margin: 0 0 10px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.tab.active { background: #e8f1ff; border-color: var(--blue); color: var(--blue); font-weight: 600; }
.sig { width: 100%; height: auto; border: 1px solid #cfd4dc; border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; display: block; }
.sig.preview { cursor: default; margin: 6px 0; }
.row { display: flex; gap: 8px; margin: 10px 0 0; align-items: center; }
.stamps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stamps button, .library button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px; cursor: pointer; }
.stamps button:hover, .library button:hover { border-color: var(--blue); }
.stamps img { max-width: 100%; height: 38px; object-fit: contain; display: block; margin: 0 auto; }
.library { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.library button { position: relative; background: repeating-conic-gradient(#f2f4f7 0 25%, #fff 0 50%) 0 0 / 12px 12px; }
.library img { max-width: 100%; height: 44px; object-fit: contain; display: block; margin: 0 auto; }
.library .x { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: #98a2b3; color: #fff; border: 0; padding: 0; line-height: 18px; font-size: 11px; }

.overlay { position: absolute; border: 1px dashed transparent; cursor: move; touch-action: none; }
.overlay:hover, .overlay.active { border-color: var(--blue); }
.overlay img { display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
.overlay .handle { position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; cursor: nwse-resize; display: none; touch-action: none; }
.overlay .remove { position: absolute; right: -10px; top: -10px; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid #fff; font-size: 13px; line-height: 15px; cursor: pointer; display: none; padding: 0; }
.overlay:hover .handle, .overlay.active .handle, .overlay:hover .remove, .overlay.active .remove { display: block; }


.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(16,24,40,.45); }
.sheet { position: relative; width: 100%; max-width: 340px; max-height: 92vh; overflow: auto; background: #fff; border-radius: 16px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet-close { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; }
.sheet.auth { max-width: 430px; padding: 0; overflow: hidden; }
.auth-frame { display: block; width: 100%; height: 480px; border: 0; background: #fff; }
.sheet.auth .sheet-close { z-index: 2; }
.linkrow { display: flex; gap: 8px; }
.linkrow input { flex: 1; min-width: 0; }
.spinner { width: 30px; height: 30px; margin: 22px auto; border: 3px solid #e4e7ec; border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .titlebar { gap: 6px; padding: 0 8px; }
  .lbl { display: none; }
  .btn.small { padding: 7px 10px; }
  .titleblock { max-width: 38%; }
  .titlebar input.docname { width: 100%; font-size: 14px; }
  /* the thumbnail browser slides in over the page */
  .sidebar { position: absolute; z-index: 15; top: 0; bottom: 0; left: 0; width: min(260px, 82%); transform: translateX(-102%); transition: transform .22s ease; box-shadow: 6px 0 24px rgba(16,24,40,.25); }
  .shell.side-open .sidebar { transform: none; }
  .side-backdrop { display: none; position: absolute; inset: 0; z-index: 14; background: rgba(16,24,40,.35); }
  .shell.side-open .side-backdrop { display: block; }
  .thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start; }
  .viewer { padding: 14px 8px 96px; }
  .ftb { top: auto; bottom: 0; left: 0; right: 0; transform: none; max-width: none; border-radius: 16px 16px 0 0; overflow-x: auto; justify-content: flex-start; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tb { min-width: 58px; flex: none; }
  .toast { bottom: 84px; }
  .sheet-panel { top: auto; bottom: 0; left: 0; right: 0; transform: none; width: auto; max-height: 84%; border-radius: 18px 18px 0 0; animation: sheet-up .2s ease-out; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* the privacy "certificate" */
.nameline { display: flex; align-items: center; gap: 2px; min-width: 0; }
.sheet-panel h2 { margin: 0 0 8px; font-size: 16px; }
.sheet-panel ol { margin: 0 0 14px; padding-left: 20px; }
.sheet-panel dt { font-weight: 600; margin-top: 10px; }
.sheet-panel dd { margin: 2px 0 0; color: var(--muted); }
.sheet-panel.certificate { text-align: center; width: min(360px, calc(100% - 24px)); padding: 22px 22px 18px; border-top: 4px solid #1a9d50; }
.certificate .seal { display: inline-flex; width: 52px; height: 52px; align-items: center; justify-content: center; border-radius: 50%; background: #e8f6ee; color: #1a9d50; margin-bottom: 8px; }
.certificate .seal svg.ic { width: 28px; height: 28px; }
.certificate p { margin: 0 0 8px; }
.ibtn.lock { color: #1a9d50; }
