/* ============ PDFForge layout ============ */
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.ptoolbar {
  touch-action: pan-x;           /* scrolls sideways; never starts page-zoom */
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  color: var(--muted); font-size: 12px;
}
.ptoolbar .tool {
  min-width: 32px; height: 30px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  padding: 0 10px;
  display: inline-flex; align-items: center; gap: 6px;
}
.ptoolbar .tool:hover { background: var(--panel-3); }
.ptoolbar .tool.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.ptoolbar .sep { width: 1px; height: 22px; background: var(--border); }

.pdf-main { flex: 1; display: flex; min-height: 0; }

.page-list {
  width: 168px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 10px 8px;
}
.page-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 8px;
  padding: 7px 9px;
  cursor: pointer;
  font-size: 12px;
}
.page-item.active { border-color: var(--accent); background: var(--panel-3); }
.page-item .pnum { font-weight: 600; margin-bottom: 5px; display: block; }
.page-item .pops { display: flex; gap: 3px; }
.page-item .pops button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--muted);
  border-radius: 4px;
  height: 21px;
  cursor: pointer;
  font-size: 11px;
}
.page-item .pops button:hover { color: var(--text); border-color: var(--border-lt); }

.pdf-scroll {
  flex: 1;
  overflow: auto;
  background: var(--bg-deep);
  padding: 24px 16px 60px;
  text-align: center;
  /* one/two-finger panning stays native; two-finger pinch is ours (browser
     page-zoom is suppressed here so the document itself can zoom) */
  touch-action: pan-x pan-y;
}
.pdf-page {
  position: relative;
  display: inline-block;
  margin: 0 auto 22px;
  box-shadow: 0 8px 30px rgba(0,0,0,.55);
  background: #fff;
  text-align: left;
}
.pdf-page canvas.render { display: block; }
.pdf-page canvas.ink {
  position: absolute; inset: 0;
  pointer-events: none;
}

/* selectable text layer (pdf.js) — transparent glyphs over the render */
.pdf-page .textLayer {
  position: absolute; inset: 0;
  overflow: hidden;
  line-height: 1;
  pointer-events: none;
}
.textLayer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  transform-origin: 0 0;
  cursor: text;
}
.textLayer ::selection { background: rgba(91,140,255,.35); }
.tool-select .textLayer { pointer-events: auto; }
/* every line is editable in Select mode — show it on hover (desktop) */
.tool-select .textLayer span:hover {
  outline: 1.5px dashed rgba(91,140,255,.55);
  background: rgba(91,140,255,.12);
}

.pdf-page .annot-layer { position: absolute; inset: 0; pointer-events: none; }
.pdf-page .annot-layer .annot { pointer-events: auto; }

/* alignment crosshairs shown while a drawing tool is active */
.pdf-page .guide-v, .pdf-page .guide-h {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  display: none;
}
.pdf-page .guide-v { top: 0; bottom: 0; width: 0; border-left: 1px dashed rgba(91,140,255,.65); }
.pdf-page .guide-h { left: 0; right: 0; height: 0; border-top: 1px dashed rgba(91,140,255,.65); }

.annot {
  position: absolute;
  cursor: grab;
  /* touching an annotation always drags the annotation, not the page —
     without this iOS claims the gesture for scrolling and cancels the move */
  touch-action: none;
}
.annot.text {
  font-family: Helvetica, Arial, sans-serif;
  white-space: pre;
  line-height: 1.15;
}
.annot.hl { mix-blend-mode: multiply; }
.annot.rect { background: transparent; }
.annot.wipe { background: #fff; }             /* actual color set inline, sampled from the page */
.annot.penbox { background: transparent; }    /* invisible hit area over a pen stroke */
.annot.penbox:hover { outline: 1px dashed rgba(91,140,255,.55); }
.annot.field {
  border: 1.5px dashed #1c7ed6;
  background: rgba(28,126,214,.07);
  color: #1c7ed6;
  font: 10px -apple-system, Arial, sans-serif;
  padding: 1px 4px;
  overflow: hidden;
  white-space: nowrap;
}
.annot.check {
  border: 1.5px solid #1c7ed6;
  background: rgba(255,255,255,.6);
}

/* live form controls inside field annotations — inert while designing,
   interactive in the Fill tool and in view mode */
.annot .fieldctl {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  box-sizing: border-box;
  margin: 0; padding: 0 4px;
  border: none; outline: none;
  background: rgba(255,255,255,.88);
  color: #111;
  font-family: Helvetica, Arial, sans-serif;
  pointer-events: none;
  color-scheme: light;
}
.annot.check .fieldctl { padding: 0; accent-color: #1c7ed6; }
.tool-fill .annot .fieldctl, body.forge-view .annot .fieldctl { pointer-events: auto; }
/* fill mode: fields look live, not like draggable design objects */
.tool-fill .annot.field, .tool-fill .annot.check,
body.forge-view .annot.field, body.forge-view .annot.check {
  cursor: default;
  border-style: solid;
}
.annot.selected { outline: 2px dashed var(--accent); outline-offset: 2px; }
.annot .del {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px; line-height: 1;
  cursor: pointer;
  display: none;
}
.annot.selected .del { display: block; }
/* selection controls always paint above everything else in the layer */
.annot .del, .annot .cog, .annot .rz, .annot .mv { z-index: 40; }
/* move indicator — a small ✥ under the selected object */
.annot .mv {
  position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(91,140,255,.9);
  color: #fff;
  font-size: 11px; line-height: 18px;
  text-align: center;
  pointer-events: none;          /* purely an indicator — the object itself drags */
  display: none;
}
.annot.selected .mv { display: block; }

/* phones: finger-sized selection controls */
@media (pointer: coarse) {
  .annot .del, .annot .cog {
    width: 26px; height: 26px;
    font-size: 14px;
    top: -30px;
  }
  .annot .del { left: calc(50% - 16px); }
  .annot .cog { left: calc(50% + 16px); }
  .annot .mv { width: 22px; height: 22px; line-height: 22px; font-size: 13px; bottom: -26px; }
  .annot .rz { width: 20px; height: 20px; border-radius: 4px; }
  .annot .rz.nw { left: -11px; top: -11px; }
  .annot .rz.ne { right: -11px; top: -11px; }
  .annot .rz.sw { left: -11px; bottom: -11px; }
  .annot .rz.se { right: -11px; bottom: -11px; }
}
/* ⚙ on a selected field — sits beside the ✕ */
.annot .cog {
  position: absolute; top: -12px; left: calc(50% + 14px);
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 11px; line-height: 1;
  padding: 0;
  cursor: pointer;
  display: none;
}
.annot.selected .cog { display: block; }

/* resize grips — shown on the selected annotation (not on locked covers) */
.annot .rz {
  position: absolute; width: 11px; height: 11px; box-sizing: border-box;
  background: #fff; border: 1.5px solid var(--accent); border-radius: 2px;
  display: none; z-index: 6; touch-action: none;
}
.annot.selected .rz { display: block; }
.annot .rz.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.annot .rz.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.annot .rz.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.annot .rz.se { right: -6px; bottom: -6px; cursor: nwse-resize; }

.tool-text .annot-layer, .tool-hl .annot-layer, .tool-rect .annot-layer, .tool-pen .annot-layer,
.tool-table .annot-layer { cursor: crosshair; }
/* while a drawing tool is active the finger draws — it must not pan the page
   (switch to Select to pan, or pinch with two fingers to zoom) */
.pdf-scroll.tool-pen, .pdf-scroll.tool-hl, .pdf-scroll.tool-rect, .pdf-scroll.tool-field,
.pdf-scroll.tool-table, .pdf-scroll.tool-area { touch-action: none; }

/* area-select rubber band */
.marquee {
  position: absolute;
  border: 1.5px dashed var(--accent);
  background: rgba(91,140,255,.12);
  z-index: 26;
  pointer-events: none;
}

/* preview mode: the document as a viewer sees it — no design chrome */
body.forge-preview .ptoolbar { display: none; }
body.forge-preview .page-list { display: none; }

/* floating zoom control — bottom center, clear of the drawer toggle (left)
   and the version badge (right) */
.zoombar {
  position: fixed;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  display: none;                 /* shown once a document is open */
  align-items: center; gap: 2px;
  background: rgba(22,22,30,.88);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px;
  z-index: 65;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
  touch-action: manipulation;    /* taps only — no double-tap page-zoom */
}
.zoombar button {
  background: transparent;
  border: none;
  color: var(--text);
  min-width: 32px; height: 28px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 16px; line-height: 1;
}
.zoombar button:hover { background: var(--panel-3); }
.zoombar #zoomFit { font-size: 11px; color: var(--muted); padding: 0 10px; }
.zoombar #zoomPct {
  color: var(--muted);
  font-size: 11px;
  min-width: 40px;
  height: 28px;
  text-align: center;
  cursor: pointer;
}
/* the slider tray is hidden until the % tag is tapped */
.zoombar .zoomtray { display: none; align-items: center; gap: 2px; }
.zoombar.open .zoomtray { display: flex; }
.zoombar.open #zoomPct { color: var(--text); }
#zoomSlider {
  width: min(44vw, 200px);
  margin: 0 6px;
  accent-color: var(--accent);
  cursor: pointer;
  /* the thumb-drag belongs to the slider — never to page scrolling */
  touch-action: none;
}

/* field properties sheet */
.fieldprops-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.fieldprops-backdrop[hidden] { display: none; }
.fieldprops {
  width: min(92vw, 340px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.fieldprops h3 { margin: 0 0 12px; font-size: 14px; }
.fieldprops label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.fieldprops input[type="text"], .fieldprops input[type="date"], .fieldprops input[type="time"],
.fieldprops input[type="datetime-local"], .fieldprops input[type="number"],
.fieldprops select, .fieldprops textarea {
  display: block; width: 100%; margin-top: 4px; box-sizing: border-box;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 8px; font-size: 13px;
  color-scheme: dark;              /* native date/time pickers match the theme */
}
.fieldprops input[type="checkbox"] { margin-top: 6px; width: 18px; height: 18px; }
.fieldprops .fp-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.fieldprops #fpDelete { margin-right: auto; color: var(--danger); }

#pdfEmpty {
  color: var(--muted);
  padding: 80px 20px;
  font-size: 14px;
}
#pdfEmpty .big { font-size: 40px; margin-bottom: 12px; }

/* the in-place editor is a contenteditable span, NOT an input: it auto-grows
   with its content and renders with the same text metrics as .annot.text on
   every engine (iOS inputs force their own line metrics — that was the
   1–2px shift), so opening it moves nothing. */
#textEntry {
  position: absolute;
  border: none;                     /* seamless in-place editing, no box */
  background: rgba(255,255,255,.9); /* overridden inline with the sampled page color */
  color: #111;
  font-family: Helvetica, Arial, sans-serif;
  padding: 0;
  margin: 0;
  line-height: 1.15;
  white-space: pre;
  outline: none;
  min-width: 40px;
  z-index: 30;
  display: none;
  -webkit-user-select: text;
  user-select: text;
}
/* delete-this-line button, floats above the open editor */
#entryDel {
  position: absolute;
  z-index: 31;
  display: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 15px; line-height: 1;
  align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(0,0,0,.45);
  touch-action: manipulation;
}

/* lift-region confirm chip — offered after an empty Area sweep */
#liftChip {
  position: absolute;
  z-index: 45;
  transform: translateX(-50%);
}
#liftChip[hidden] { display: none; }
#liftChip button {
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 10px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
  cursor: pointer;
  touch-action: manipulation;
}

/* drop-to-delete target — appears while dragging an object */
#dragTrash {
  position: fixed; left: 50%; bottom: 22px;
  transform: translateX(-50%) scale(.92);
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(28, 28, 38, .92);
  border: 2px dashed var(--danger);
  color: var(--danger);
  font-size: 26px;
  display: none;
  align-items: center; justify-content: center;
  z-index: 70;
  pointer-events: none;              /* hit-tested manually during the drag */
  transition: transform .12s, background .12s;
}
#dragTrash.show { display: flex; }
#dragTrash.hot {
  transform: translateX(-50%) scale(1.18);
  background: rgba(224, 49, 49, .3);
  color: #fff;
}

/* phones: long-press on a text line picks it up to MOVE — the OS text-selection
   loupe must not fight that gesture */
@media (pointer: coarse) {
  .textLayer span { -webkit-user-select: none; user-select: none; }
}

/* ---- mobile (≤720px): toolbar scrolls, page list becomes a left drawer ---- */
@media (max-width: 720px) {
  .ptoolbar { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .ptoolbar::-webkit-scrollbar { display: none; }
  .ptoolbar > * { flex-shrink: 0; }
  .page-list {
    position: fixed; top: 52px; left: 0; bottom: 0; width: min(72vw, 240px);
    z-index: 62; transform: translateX(-100%); transition: transform .22s;
  }
  body.drawer-open .page-list { transform: translateX(0); box-shadow: var(--shadow); }
  /* phones zoom by pinching — the zoom pill is a desktop/web control */
  .zoombar { display: none !important; }
  .pdf-scroll { padding: 10px 6px; }

  /* the radial owns tools + undo/redo/preview on phones — drop the bars */
  body.has-radial .ptoolbar { display: none; }
  body.has-radial .appbar #btnPreview,
  body.has-radial .appbar #btnUndo,
  body.has-radial .appbar #btnRedo { display: none; }
}
