:root {
  --bar: #f0f1f3; --line: #c9ccd1; --text: #222; --muted: #666;
  --accent: #2f6fdd; --view: #6b6f75; --side: #e9eaec; --hover: #e3ecf9;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
/* The editor's element styles are limited to the editor (:where keeps their weight),
   so they don't leak into the website around it. */
/* The editor fills the window. On the website it is shown once a PDF is open
   (body.editing); until then the page itself is shown. */
#app, .modal, .modal * { font: 13px "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; color: var(--text); background: var(--bar); }
#app[hidden] { display: none; }
body.editing { overflow: hidden; }
body.editing > :not(#app):not(.modal):not(script):not(iframe):not(input) { display: none; }

#toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; padding: 4px 6px; background: var(--bar); border-bottom: 1px solid var(--line); }
#toolbar .brand { width: 26px; height: 26px; margin-right: 6px; }
.grp { display: flex; align-items: center; gap: 2px; padding: 0 6px; border-right: 1px solid var(--line); }
.grp:last-child { border-right: 0; }
:where(#app, .modal) button { font: inherit; padding: 3px 8px; border: 1px solid #b8bcc3; border-radius: 3px; background: #fdfdfd; cursor: pointer; white-space: nowrap; }
:where(#app, .modal) button:hover:not(:disabled) { background: var(--hover); border-color: #9fb9e6; }
:where(#app, .modal) button:disabled { color: #999; cursor: default; }
:where(#app, .modal) button.tool { border-color: transparent; background: transparent; }
:where(#app, .modal) button.tool.on { background: #dbe6fa; border-color: #9fb9e6; }
#pageBox { width: 38px; text-align: center; }
#zoomLabel { min-width: 42px; text-align: center; }
:where(#app, .modal) select, :where(#app, .modal) input[type=number], :where(#app, .modal) input[type=text] { font: inherit; padding: 2px 4px; }
#fontSize { width: 56px; }
#toolbar label { display: flex; align-items: center; gap: 2px; margin: 0 4px; }
:where(#app, .modal) input[type=color] { width: 32px; height: 24px; padding: 0 2px; border: 1px solid #b8bcc3; background: #fff; }

.menu { position: relative; }
.menu-list { display: none; position: absolute; top: 100%; left: 0; z-index: 20; background: #fff; border: 1px solid var(--line); box-shadow: 0 4px 12px rgba(0,0,0,.15); padding: 4px; }
.menu-list.open { display: block; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 12px; }
.menu-list button:hover { background: var(--hover); }
.menu-list button:disabled { color: #999; background: none; }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-list .menu-hint { color: #777; font-size: 12px; padding: 4px 12px; max-width: 240px; white-space: normal; }
#picList { min-width: 230px; }
#picList.at-mouse { position: fixed; top: auto; }
.hit.img.cropping { cursor: crosshair; }
.pick-picture .hit.img { cursor: pointer; outline: 2px dashed var(--accent); }
.crop-box { position: absolute; border: 2px dashed #d93025; background: rgba(217,48,37,.08); pointer-events: none; }

#tabs { display: flex; align-items: flex-end; padding: 4px 6px 0; background: #dfe1e5; border-bottom: 1px solid var(--line); min-height: 30px; }
#tabStrip { flex: 0 1 auto; min-width: 0; display: flex; align-items: flex-end; gap: 2px; overflow: hidden; }
.tab-ctl { flex: none; border: 0; background: none; padding: 3px 7px 5px; color: #3a3f46; }
.tab-ctl:hover:not(:disabled) { background: #cfd2d7; }
.tab-ctl:disabled { color: #b0b4ba; }
#tabs .menu[hidden], #tabs .tab-ctl[hidden] { display: none; }
#tabList { left: auto; right: 0; max-height: 60vh; overflow-y: auto; min-width: 240px; }
#tabList button { white-space: nowrap; }
.tab { flex: 0 1 auto; display: flex; align-items: center; max-width: 230px; min-width: 120px; padding: 4px 4px 4px 10px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; background: #eceef1; color: #4a4f57; cursor: pointer; user-select: none; }
.tab:hover { background: #f5f6f8; }
.tab.on { background: #fff; color: #1f2329; font-weight: 600; border-color: #c4c7cc; margin-bottom: -1px; padding-bottom: 5px; }
.tab.drop { outline: 2px solid var(--accent); }
.tab .name { flex: 1; min-width: 0; display: flex; white-space: nowrap; }
.tab .name .h { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tab .name .t { flex: none; }
.tab .x { border: 0; background: none; padding: 0 5px; margin-left: 4px; color: #6b7078; font-size: 15px; line-height: 1; }
.tab .x:hover { color: #c0392b; background: none; }
.tab-plus { border: 0; background: none; font-size: 18px; line-height: 1; padding: 2px 9px 4px; color: #3a3f46; }
.tab-plus:hover:not(:disabled) { background: #cfd2d7; }
#app > main { flex: 1; display: flex; min-height: 0; }
#side { width: 190px; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); }
.side-head { padding: 6px 8px; font-weight: 600; }
#thumbs { flex: 1; overflow-y: auto; padding: 4px 0 10px; outline: none; }
.thumb { margin: 6px auto 2px; width: 130px; text-align: center; cursor: pointer; position: relative; }
.thumb img { display: block; margin: 0 auto; max-width: 120px; box-shadow: 0 1px 3px rgba(0,0,0,.3); background: #fff; border: 3px solid transparent; }
.thumb.sel img { border-color: var(--accent); }
.thumb .num { font-size: 12px; color: var(--muted); }
.thumb.drop-before::before, .thumb.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 4px; background: var(--accent); }
.thumb.drop-before::before { top: -6px; }
.thumb.drop-after::after { bottom: -4px; }
.side-btns { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px; border-top: 1px solid var(--line); }
.side-btns button { flex: 1 0 auto; padding: 3px 5px; }

#view { flex: 1; overflow: auto; background: var(--view); position: relative; outline: none; }
#view.welcome { background: #fff; }
#pages { padding: 16px 0 40px; }
.page { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.page > img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.page > img.tile { inset: auto; }
.layer { position: absolute; inset: 0; }
.mode-edit .layer, .mode-add .layer, .mode-sign .layer { cursor: crosshair; }
.mode-edit .layer, .mode-text .layer { cursor: text; }
.mode-hand .page { cursor: grab; }
#view.panning, #view.panning * { cursor: grabbing !important; }
.tsel { position: absolute; background: rgba(61,123,253,.32); pointer-events: none; }
.hl-sel { position: absolute; border: 2px dashed var(--accent); pointer-events: none; }
.hit { position: absolute; border: 1px solid transparent; }
.mode-edit .hit.line:hover { background: rgba(47,111,221,.12); border-color: rgba(47,111,221,.6); }
.hit.img, .hit.tline { cursor: move; }
.mode-select .hit.tline:hover { border: 1px dashed var(--accent); }
.hit.tline.sel { border: 2px solid var(--accent); }
.mode-select .hit.img:hover { border: 1px dashed var(--accent); }
.hit.img.sel { border: 2px solid var(--accent); }
.hit.img.sel .grip { display: block; }
.hit.img .grip { display: none; position: absolute; right: -6px; bottom: -6px; width: 11px; height: 11px; background: #fff; border: 2px solid var(--accent); cursor: nwse-resize; }
.typing { position: absolute; z-index: 5; margin: 0; padding: 0 1px; border: 1px dashed var(--accent); background: rgba(255,255,255,.96); outline: none; resize: none; line-height: 1.25; white-space: pre; overflow: hidden; }

#home { padding: 36px 48px; }
#home .home-logo { width: 260px; display: block; margin-bottom: 30px; }
#tiles { display: flex; flex-wrap: wrap; }
.tile { width: 160px; height: 140px; margin: 0 8px 10px 0; border: 1px solid transparent; border-radius: 8px; background: none; display: flex; flex-direction: column; align-items: center; padding-top: 14px; font-size: 14px; color: #333a44; }
.tile img { width: 72px; height: 72px; margin-bottom: 12px; }
.tile:hover { background: var(--hover); border-color: #b9cff0; }

#status { padding: 4px 10px; border-top: 1px solid var(--line); background: var(--bar); min-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status.err { color: #b3261e; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal .box { background: #fff; border-radius: 8px; padding: 18px 20px; min-width: 340px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h2 { font-size: 16px; margin: 0 0 12px; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-btns button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.choice { display: block; width: 100%; margin: 6px 0; padding: 8px 12px; text-align: left; }
#sigPad { border: 1px solid var(--line); background: #fff; touch-action: none; cursor: crosshair; display: block; }
.busy * { cursor: progress !important; }
.gap-sel { position: absolute; left: 4px; right: 4px; background: rgba(217, 48, 37, .12); border: 2px dashed #d93025; pointer-events: none; }
.hit.insel { border: 2px solid var(--accent); background: rgba(47,111,221,.08); }
.marquee { position: absolute; border: 1px dashed var(--accent); background: rgba(47,111,221,.12); pointer-events: none; }
