/* PDF editor */
.pe-container { max-width: 1480px; }
.pe-shell { display: flex; flex-direction: column; height: min(88vh, 940px); min-height: 600px; overflow: hidden; }
.pe-shell.is-full { height: auto; }
.pe-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex: none; }
.pe-bar .grp { display: flex; gap: 2px; align-items: center; padding-right: 6px; margin-right: 4px; border-right: 1px solid var(--line-strong); }
.pe-bar .grp:last-child { border-right: 0; }
.pe-bar .sp { flex: 1; }
.pt {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 46px; height: 46px; padding: 3px 7px;
  border-radius: 10px; border: 1px solid transparent; background: transparent; font-size: 0.68rem; line-height: 1.1; color: var(--text); white-space: nowrap;
}
.pt svg { width: 19px; height: 19px; flex: none; }
.pt:hover { background: var(--surface-2); border-color: var(--line); }
.pt.on { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.pt[disabled] { opacity: 0.4; pointer-events: none; }
.pt.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pt.sm { min-width: 34px; height: 34px; }
.pe-zoom { font-size: 0.8rem; min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; }

.pe-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 176px 1fr 270px; }
.pe-side { border-right: 1px solid var(--line); background: var(--bg-2); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.pe-side-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.pe-side-tabs button { flex: 1; padding: 9px 4px; font-size: 0.8rem; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); }
.pe-side-tabs button.on { color: var(--text); border-bottom-color: var(--accent-text); font-weight: 600; }
#sidePages { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.pe-side-actions { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); flex: none; }
.pe-side-actions .pt { min-width: 30px; height: 30px; padding: 2px; }
.pe-side-actions .pt svg { width: 16px; height: 16px; }
.pe-thumbs { overflow: auto; padding: 10px 8px 20px; display: grid; gap: 12px; align-content: start; flex: 1; }
.th { position: relative; display: grid; gap: 4px; justify-items: center; cursor: pointer; padding: 4px; border-radius: 8px; border: 2px solid transparent; }
.th.on { border-color: var(--accent-text); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.th.cur { border-color: color-mix(in srgb, var(--accent-text) 50%, transparent); }
.th.drop-before::before, .th.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 3px; background: var(--accent-text); border-radius: 2px; }
.th.drop-before::before { top: -7px; } .th.drop-after::after { bottom: -7px; }
.th .tc { background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); position: relative; line-height: 0; }
.th canvas { display: block; }
.th small { font-size: 0.72rem; color: var(--muted); }
.th .badge-n { position: absolute; top: 6px; right: 6px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 0.66rem; padding: 1px 6px; font-weight: 600; z-index: 2; }
.pe-find { padding: 10px; display: grid; gap: 8px; align-content: start; overflow: auto; }
.pe-find .input { padding: 9px 11px; }
.pe-find-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }

.pe-view { position: relative; overflow: auto; background: #4a4f57; outline: none; min-width: 0; }
:root[data-theme="light"] .pe-view { background: #c9ced6; }
.pe-pages { padding: 14px 0 60px; min-width: max-content; }
.pg { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); overflow: hidden; touch-action: pan-x pan-y; }
.pg canvas.base { display: block; position: absolute; left: 0; top: 0; }
.pg .tl { position: absolute; inset: 0; overflow: hidden; line-height: 1; z-index: 1; }
.pg .tl span { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.pg .tl ::selection { background: rgba(47, 128, 255, 0.35); }
.pg .ol { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.pg .fl { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.pg .fl > * { pointer-events: auto; position: absolute; box-sizing: border-box; }
.pg .fl input[type="text"], .pg .fl select, .pg .fl textarea { background: rgba(190, 215, 255, 0.55); border: 1px solid #5b8def; color: #111; padding: 0 3px; font: inherit; width: 100%; height: 100%; }
.pg .fl input:focus, .pg .fl select:focus { background: #fff; outline: 2px solid #2f80ff; }
.pg .fl input[type="checkbox"], .pg .fl input[type="radio"] { width: 100%; height: 100%; margin: 0; accent-color: #2f80ff; }
.pg .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa; font-size: 0.8rem; }
.pe-view.tool-text .pg, .pe-view.tool-shape .pg, .pe-view.tool-cover .pg, .pe-view.tool-draw .pg, .pe-view.tool-place .pg { cursor: crosshair; }
.pe-view.tool-edit .pg { cursor: text; }
.pe-view.tool-select .tl, .pe-view.tool-mark .tl { pointer-events: auto; }
.pe-view:not(.tool-select):not(.tool-mark) .tl { pointer-events: none; }
.pe-view.tool-mark .tl span { cursor: text; }
.pg .ol .po { pointer-events: auto; }
.pe-view.tool-draw .po, .pe-view.tool-shape .po, .pe-view.tool-cover .po, .pe-view.tool-text .po:not(.t), .pe-view.tool-place .po { pointer-events: none; }
.pg .tlines { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.pg .tline { pointer-events: auto; position: absolute; border-radius: 2px; cursor: text; box-sizing: border-box; }
.pg .tline:hover { background: rgba(47, 128, 255, 0.16); outline: 1px solid rgba(47, 128, 255, 0.8); }
.fhit { position: absolute; background: rgba(255, 190, 0, 0.45); mix-blend-mode: multiply; z-index: 2; pointer-events: none; border-radius: 2px; }
.fhit.cur { background: rgba(255, 120, 0, 0.6); outline: 2px solid #ff7a00; }

/* objects */
.po { position: absolute; box-sizing: border-box; transform-origin: 50% 50%; user-select: none; -webkit-user-select: none; touch-action: none; }
.po.sel { outline: 1.5px solid #2f80ff; cursor: move; }
.po.locked.sel { outline-style: dashed; cursor: default; }
.po.t { white-space: pre-wrap; word-break: break-word; line-height: 1.2; overflow: visible; }
.po.t.editing { user-select: text; -webkit-user-select: text; cursor: text; outline: 1.5px solid #2f80ff; background-clip: padding-box; }
.po .c { position: absolute; inset: 0; pointer-events: none; }
.po img, .po svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.po svg { overflow: visible; }
.hd { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid #2f80ff; border-radius: 2px; z-index: 6; touch-action: none; }
.hd.rot { border-radius: 50%; cursor: grab; }
.hd.p1 { left: -6px; top: -6px; cursor: nwse-resize; } .hd.p2 { left: 50%; top: -6px; margin-left: -5px; cursor: ns-resize; } .hd.p3 { right: -6px; top: -6px; cursor: nesw-resize; }
.hd.p4 { right: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; } .hd.p5 { right: -6px; bottom: -6px; cursor: nwse-resize; } .hd.p6 { left: 50%; bottom: -6px; margin-left: -5px; cursor: ns-resize; }
.hd.p7 { left: -6px; bottom: -6px; cursor: nesw-resize; } .hd.p8 { left: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.hd.rot { left: 50%; top: -28px; margin-left: -5px; }
.po.line .hd.p2, .po.line .hd.p4, .po.line .hd.p6, .po.line .hd.p8, .po.line .hd.rot { display: none; }
.rubber { position: absolute; border: 1.5px dashed #2f80ff; background: rgba(47, 128, 255, 0.12); pointer-events: none; z-index: 7; }
.rubber.cover { border-color: #111; background: rgba(255, 255, 255, 0.6); }
.rubber.redact { border-color: #e11; background: rgba(0, 0, 0, 0.55); }

/* properties */
.pe-props { border-left: 1px solid var(--line); background: var(--bg-2); overflow: auto; padding: 12px; font-size: 0.84rem; min-height: 0; }
.pe-props h3 { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; font-family: var(--font-body); font-weight: 600; }
.pe-props h3:first-child { margin-top: 0; }
.pe-props .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.pe-props .row > label { color: var(--muted); font-size: 0.78rem; min-width: 52px; }
.pe-props .input, .pe-props select { padding: 6px 8px; font-size: 0.82rem; border-radius: 8px; min-width: 0; }
.pe-props input[type="number"] { width: 70px; }
.pe-props input[type="color"] { width: 38px; height: 30px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.pe-props .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.pe-props .seg button { padding: 5px 9px; background: transparent; border: 0; font-size: 0.8rem; min-width: 30px; border-right: 1px solid var(--line); }
.pe-props .seg button:last-child { border-right: 0; }
.pe-props .seg button.on { background: color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 600; }
.pe-props .btn { padding: 8px 12px; font-size: 0.8rem; }
.pe-props .wide { width: 100%; justify-content: center; }
.pe-props .hint { color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.pe-props input[type="range"] { flex: 1; min-width: 80px; }
.pe-props .chk { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; }
.pe-props .swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.pe-props .swatches button { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(128, 128, 128, 0.5); padding: 0; }

/* menus / dialogs */
.pe-menu { position: fixed; z-index: 400; min-width: 190px; max-height: 70vh; overflow: auto; background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; }
.pe-menu button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; padding: 8px 10px; border-radius: 8px; border: 0; background: transparent; font-size: 0.86rem; color: var(--text); }
.pe-menu button:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.pe-menu button svg { width: 17px; height: 17px; flex: none; color: var(--accent-text); }
.pe-menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.pe-menu .lbl { padding: 6px 10px 2px; font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
dialog.dlg { background: var(--bg-2); color: var(--text); border: 1px solid var(--line-strong); border-radius: 20px; padding: 22px; width: min(640px, 96vw); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(3px); }
dialog.dlg h3 { margin: 0 0 14px; }
dialog.dlg .dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
dialog.dlg label.f { display: grid; gap: 5px; font-size: 0.82rem; color: var(--muted); }
dialog.dlg .input, dialog.dlg select { padding: 9px 11px; }
dialog.dlg fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 12px; margin: 0 0 12px; }
dialog.dlg legend { padding: 0 8px; font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
dialog.dlg .chk { display: flex; gap: 8px; align-items: center; margin: 6px 0; font-size: 0.9rem; }
dialog.dlg .acts { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
dialog.dlg .tabs { display: flex; gap: 6px; margin-bottom: 12px; }
dialog.dlg .tabs button { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 0.84rem; }
dialog.dlg .tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
dialog.dlg .anchor9 { display: grid; grid-template-columns: repeat(3, 26px); gap: 4px; }
dialog.dlg .anchor9 button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 0; }
dialog.dlg .anchor9 button.on { background: var(--accent); border-color: var(--accent-text); }
dialog.dlg .sigpad { border: 1px dashed var(--line-strong); border-radius: 12px; background: #fff; touch-action: none; width: 100%; height: 190px; display: block; cursor: crosshair; }
dialog.dlg .sigsaved { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
dialog.dlg .sigsaved .s { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 4px; cursor: pointer; }
dialog.dlg .sigsaved .s:hover { outline: 2px solid var(--accent-text); }
dialog.dlg .sigsaved .s img { height: 44px; display: block; }
dialog.dlg .sigsaved .s button { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: #e11; color: #fff; font-size: 11px; line-height: 1; padding: 0; }
dialog.dlg .sigtype { display: grid; gap: 8px; }
dialog.dlg .sigtype button { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 2rem; text-align: left; color: #111; cursor: pointer; }
dialog.dlg .sigtype button.on { outline: 2px solid var(--accent-text); }
dialog.dlg progress { width: 100%; height: 10px; }

.pe-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; gap: 10px; padding: 20px; color: var(--text); }
.pe-empty .ico { margin: 0 auto 4px; width: 64px; height: 64px; border-radius: 18px; }
.pe-empty .ico svg { width: 30px; height: 30px; }
.pe-empty h2 { font-size: 1.5rem; }
.pe-empty p { color: var(--muted); max-width: 40ch; }
.pe-empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.pe-view.dragover { outline: 3px dashed var(--accent-text); outline-offset: -6px; }
.pe-view.has-doc .pe-empty { display: none; }
.pe-hide-side .pe-side { display: none; }
.pe-hide-props .pe-props { display: none; }
.pe-hide-side .pe-body { grid-template-columns: 0 1fr 270px; }
.pe-hide-props .pe-body { grid-template-columns: 176px 1fr 0; }
.pe-hide-side.pe-hide-props .pe-body { grid-template-columns: 1fr; }
.editor-shell.pe-shell.is-full { display: flex; }
.editor-shell.pe-shell.is-full .pe-body { flex: 1; }

@media (max-width: 1000px) {
  .pe-body { grid-template-columns: 120px 1fr; }
  .pe-props { position: absolute; right: 0; bottom: 0; top: auto; width: 100%; max-height: 46%; border-left: 0; border-top: 1px solid var(--line-strong); z-index: 20; box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4); }
  .pe-props:empty { display: none; }
  .pe-shell { position: relative; }
  .pt { min-width: 40px; }
}
@media (max-width: 640px) {
  .pe-body { grid-template-columns: 1fr; }
  .pe-side { display: none; }
  .pe-show-side .pe-side { display: flex; position: absolute; left: 0; top: 0; bottom: 0; width: 150px; z-index: 25; }
  .pe-bar .grp { border-right: 0; }
  .pt span { display: none; }
  .pt { min-width: 38px; height: 38px; }
}
@media print { .pe-bar, .pe-side, .pe-props { display: none !important; } }

/* OCR */
.ocr-bar { position: sticky; top: 0; left: 0; z-index: 8; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; background: #2b2f1a; color: #f3f6d8; border-bottom: 1px solid rgba(214, 255, 63, 0.35); font-size: 0.85rem; }
.ocr-bar[hidden] { display: none; }
.ocr-bar span { flex: 1 1 240px; }
.ocr-x { background: none; border: 0; color: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 2px 8px; opacity: 0.8; }
.pg .tl .ocr-s { color: transparent; white-space: pre; transform-origin: 0 0; position: absolute; }
:root[data-theme="light"] .ocr-bar { background: #fff8d6; color: #4a4210; }

/* find and replace */
.pe-find .chk { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.pe-sep { border: 0; border-top: 1px solid var(--line, rgba(255, 255, 255, 0.12)); margin: 4px 0; width: 100%; }
.pe-find-note { margin: 0; font-size: 0.74rem; color: var(--muted); line-height: 1.4; }
