@font-face { font-family: "PE Sans"; src: url(vendor/fonts/DejaVuSans.ttf); font-weight: 400; }
@font-face { font-family: "PE Sans"; src: url(vendor/fonts/DejaVuSans-Bold.ttf); font-weight: 700; }
@font-face { font-family: "PE Serif"; src: url(vendor/fonts/DejaVuSerif.ttf); font-weight: 400; }
@font-face { font-family: "PE Serif"; src: url(vendor/fonts/DejaVuSerif-Bold.ttf); font-weight: 700; }

:root {
  --bg: #e9eaee; --panel: #ffffff; --line: #d3d6dd; --ink: #1c2230; --muted: #667085;
  --accent: #b3261e; --accent-ink: #ffffff; --sel: #1a73e8; --btn: #f3f4f7; --btn-h: #e6e8ee;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #24262b; --panel: #2f3238; --line: #454952; --ink: #eceef2; --muted: #a2a8b4; --btn: #3a3e46; --btn-h: #4a4f59; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--ink);
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }

button, select, input { font: inherit; color: inherit; }
button { background: var(--btn); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--btn-h); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.on { background: var(--sel); border-color: var(--sel); color: #fff; }
select, input[type=number], input[type=text] { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
input[type=number] { width: 62px; }
input[type=color] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; vertical-align: middle; background: none; }

#bar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.grp { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.grp.right { margin-left: auto; }
#pageInd { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }

#props { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; min-height: 38px; padding: 5px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
#props .pg { display: none; gap: 4px; align-items: center; }
#props .pg.show { display: inline-flex; }
#hint { color: var(--muted); }

main { flex: 1; display: flex; min-height: 0; }
#thumbs { width: 150px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 10px 8px; }
#thumbs:empty { display: none; }
.thumb { position: relative; margin: 0 auto 12px; width: 116px; cursor: pointer; text-align: center; color: var(--muted); font-size: 11px; }
.thumb .tc { border: 2px solid transparent; border-radius: 3px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); overflow: hidden; margin-bottom: 3px; }
.thumb .tc canvas { display: block; width: 100%; height: 100%; }
.thumb.cur .tc { border-color: var(--sel); }
.thumb .ta { position: absolute; top: 4px; right: 4px; display: none; flex-direction: column; gap: 2px; }
.thumb:hover .ta { display: flex; }
.thumb .ta button { padding: 0; width: 22px; height: 22px; font-size: 12px; line-height: 1; background: #fff; color: #222; border-color: #999; }
@media (max-width: 700px) { #thumbs { display: none; } }

#viewer { flex: 1; overflow: auto; position: relative; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px; width: max-content; min-width: 100%; }
#pages:empty { display: none; }
.page { position: relative; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.35); flex: none; }
.page .cv { position: absolute; inset: 0; }
.page .cv canvas { display: block; width: 100%; height: 100%; }
.overlay { position: absolute; left: 0; top: 0; transform-origin: 0 0; touch-action: none; }

.obj { position: absolute; cursor: move; user-select: none; -webkit-user-select: none; }
.obj.sel { outline: calc(1.5px * var(--inv, 1)) solid var(--sel); }
.obj:not(.sel):hover { outline: calc(1px * var(--inv, 1)) dashed var(--sel); }
.obj.text { white-space: pre; line-height: 1.2; }
.obj.text .t { outline: none; min-width: 4px; min-height: 1em; display: block; }
.obj.text.editing { cursor: text; outline: calc(1.5px * var(--inv, 1)) dashed var(--sel); }
.obj.text.editing .t { user-select: text; -webkit-user-select: text; }
.obj.image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.obj.ink svg { width: 100%; height: 100%; display: block; overflow: visible; pointer-events: none; }
.obj .h { position: absolute; right: calc(-6px * var(--inv, 1)); bottom: calc(-6px * var(--inv, 1));
  width: calc(12px * var(--inv, 1)); height: calc(12px * var(--inv, 1)); background: #fff;
  border: calc(1.5px * var(--inv, 1)) solid var(--sel); border-radius: 50%; cursor: nwse-resize; }

body[data-tool=text] .overlay { cursor: text; }
body[data-tool=ink] .overlay, body[data-tool=hl] .overlay, body[data-tool=wo] .overlay,
body[data-tool=check] .overlay, body[data-tool=date] .overlay { cursor: crosshair; }
body[data-tool=ink] .obj, body[data-tool=hl] .obj, body[data-tool=wo] .obj { pointer-events: none; }
.ti { position: absolute; cursor: text; outline: calc(1px * var(--inv, 1)) dashed rgba(26,115,232,.45); border-radius: 2px; }
.ti:hover { background: rgba(26,115,232,.18); outline-style: solid; }

#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 20px; }
#empty h1 { margin: 0 0 6px; font-size: 26px; }
#empty p { margin: 0; font-size: 15px; }
#empty .small { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
#empty button { padding: 9px 18px; font-size: 14px; }
body.has-doc #empty { display: none; }
body.dragover #viewer { outline: 3px dashed var(--sel); outline-offset: -8px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 18px; width: min(620px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 10px; font-size: 17px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.row .grow { flex: 1; }
dialog canvas { width: 100%; height: 200px; background: #fff; border: 1px solid var(--line); border-radius: 8px; display: block; touch-action: none; }
#sigCanvas { cursor: crosshair; }
#sigText { flex: 1; min-width: 180px; font-size: 15px; padding: 6px 8px; }
#sigSaved { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
#sigSaved:empty { display: none; }
.ss { position: relative; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px 8px; cursor: pointer; }
.ss img { height: 44px; max-width: 150px; display: block; object-fit: contain; }
.ss button { position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 1; }

#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: #1c2230; color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.35); z-index: 50; max-width: 90vw; }
