/* ═══════════════════════════════════════════════════════════════════════════
   PDF Editor — Production-Ready Professional Styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Upload Zone ────────────────────────────────────────────────────────── */
.pdf-upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  background: #f8fafc;
}
.pdf-upload-zone:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
}
.pdf-upload-zone.drag-over {
  border-color: #0ea5e9;
  background: rgba(14,165,233,0.04);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.1);
}
html.dark .pdf-upload-zone { background: #1e293b; border-color: #475569; }
html.dark .pdf-upload-zone:hover { border-color: #64748b; background: #1e293b; }
html.dark .pdf-upload-zone.drag-over { border-color: #0ea5e9; background: rgba(14,165,233,0.06); }

.pdf-upload-zone .upload-icon {
  width: 44px; height: 44px;
  margin: 0 auto 0.75rem;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Editor Workspace ──────────────────────────────────────────────────── */
.pdf-editor-workspace {
  display: none;
  gap: 0;
  height: calc(100vh - 140px);
  min-height: 400px;
}
.pdf-editor-workspace.active { display: flex; }

/* ── Toolbar ───────────────────────────────────────────────────────────── */
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  flex-wrap: wrap;
}
html.dark .pdf-toolbar {
  background: #1e293b;
  border-color: #334155;
}
.toolbar-divider {
  width: 1px; height: 20px;
  background: #e2e8f0;
  margin: 0 3px;
  flex-shrink: 0;
}
html.dark .toolbar-divider { background: #475569; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 1px;
}

.tool-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}
.tool-btn:hover {
  background: #f1f5f9;
  color: #334155;
}
.tool-btn.active {
  background: #0ea5e9;
  color: #fff;
  box-shadow: 0 1px 4px rgba(14,165,233,0.3);
}
html.dark .tool-btn:hover { background: #334155; color: #e2e8f0; }
html.dark .tool-btn.active { background: #0ea5e9; color: #fff; }
.tool-btn svg { width: 14px; height: 14px; pointer-events: none; }

.tool-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: -26px; left: 50%;
  transform: translateX(-50%) translateY(2px);
  background: #1e293b; color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 4px;
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 100;
}
.tool-btn[data-tooltip]:hover::after {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ── Thumbnails Sidebar ───────────────────────────────────────────────── */
.thumbnails-sidebar {
  width: 88px; flex-shrink: 0;
  padding: 6px; overflow-y: auto;
  border-right: 1px solid #e2e8f0;
  background: #f8fafc;
}
html.dark .thumbnails-sidebar { background: #0f172a; border-color: #334155; }

.thumb-item {
  position: relative; cursor: pointer;
  border-radius: 4px; overflow: hidden;
  margin-bottom: 6px;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.thumb-item:hover { border-color: #94a3b8; }
.thumb-item.active {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14,165,233,0.15);
}
.thumb-item canvas { width: 100%; display: block; }
.thumb-page-num {
  position: absolute; bottom: 2px; left: 50%;
  transform: translateX(-50%);
  background: rgba(15,23,42,0.7); color: #fff;
  font-size: 8px; font-weight: 700;
  padding: 1px 6px; border-radius: 8px;
}

/* ── Pages Container ──────────────────────────────────────────────────── */
.pages-container {
  flex: 1; overflow: auto;
  padding: 12px;
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  background: #f1f5f9;
  scroll-behavior: smooth;
}
html.dark .pages-container { background: #0f172a; }

.page-wrapper {
  position: relative; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-radius: 2px;
}
.page-wrapper canvas { display: block; }

/* ── Layer containers ─────────────────────────────────────────────────── */
.text-overlay-layer,
.hit-layer,
.cover-layer,
.overlay-layer,
.selection-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
}

.cover-layer { z-index: 2; pointer-events: none; }
.hit-layer { z-index: 3; pointer-events: none; }
.overlay-layer { z-index: 5; pointer-events: none; }
.selection-layer { z-index: 6; pointer-events: none; }

.overlay-layer .added-text,
.overlay-layer .img-wrap,
.overlay-layer .sticky-note,
.overlay-layer [class^="sh-"] {
  pointer-events: auto;
}

.hit-layer .tw { pointer-events: auto; }

.page-wrapper.cursor-text { cursor: text; }
.page-wrapper.cursor-crosshair { cursor: crosshair; }

.draw-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 4; cursor: crosshair;
  pointer-events: none;
}
.draw-canvas.active { pointer-events: auto; }

/* Cover original PDF glyphs when edited — canvas paints paper-matched fills */
.cover-canvas {
  position: absolute;
  left: 0; top: 0;
  pointer-events: none;
  z-index: 1;
}
.text-cover {
  display: none; /* legacy HTML covers disabled — canvas covers only */
}

/* ── Word hit targets (invisible, hoverable) ──────────────────────────── */
.tw {
  position: absolute; cursor: text;
  pointer-events: auto;
  border: 1px solid transparent;
  border-radius: 1px;
  outline: none;
  background: transparent;
  transition: background 0.1s, border-color 0.1s;
}
.tw:hover {
  background: rgba(14,165,233,0.12);
  border-color: rgba(14,165,233,0.35);
}
.tw.find-hl {
  background: rgba(251,191,36,0.35) !important;
  outline: 2px solid #f59e0b;
}

/* ── Highlight / Whiteout / Shapes / Image overlays ──────────────────── */
.hl-rect {
  position: absolute; pointer-events: none;
  border-radius: 1px; z-index: 1;
  mix-blend-mode: multiply;
}
.hl-underline, .hl-strikethrough {
  position: absolute; pointer-events: none;
  border-radius: 1px;
}
.wo-rect {
  position: absolute; background: #fff;
  z-index: 3; pointer-events: none;
}
html.dark .wo-rect, html.dark .text-cover { background: #fff; }

.added-text {
  position: absolute; z-index: 5; cursor: move;
  padding: 0;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 0;
  outline: none;
  min-width: 4px;
  min-height: 10px;
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  overflow: hidden;
  line-height: 1.15;
  pointer-events: auto;
  caret-color: #0284c7;
  box-sizing: border-box;
}
/* Inline PDF text — looks like real page text when not selected */
.added-text.inline-pdf-text {
  background: transparent !important;
  border-color: transparent;
  box-shadow: none;
  cursor: text;
}
.added-text.inline-pdf-text:hover {
  border-color: rgba(14,165,233,0.35);
  background: rgba(14,165,233,0.04) !important;
}
.added-text.selected {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 1px rgba(14,165,233,0.25);
  background: rgba(255,255,255,0.15) !important;
  cursor: move;
}
.added-text.editing {
  border-color: #0284c7;
  box-shadow: 0 0 0 2px rgba(2,132,199,0.2);
  background: rgba(255,255,255,0.2) !important;
  cursor: text;
  outline: none;
  caret-color: #0284c7;
  overflow: hidden;
}
.added-text.editing::selection,
.added-text.editing *::selection {
  background: rgba(14,165,233,0.35);
  color: inherit;
}
.added-text.exporting {
  border-color: transparent !important;
  box-shadow: none !important;
  background: transparent !important;
}
.added-text.find-hl {
  outline: 2px solid #f59e0b;
  background: rgba(251,191,36,0.2) !important;
}
.find-hl-active {
  outline: 2px solid #ea580c !important;
  background: rgba(251,146,60,0.4) !important;
  z-index: 8;
}

.tw.find-hl-active {
  background: rgba(251,146,60,0.45) !important;
  border-color: #ea580c !important;
}

.tool-btn-danger { color: #ef4444; }
.tool-btn-danger:hover { background: #fef2f2; color: #dc2626; }
html.dark .tool-btn-danger:hover { background: #450a0a; color: #fca5a5; }

.img-wrap {
  position: absolute; z-index: 5; cursor: move;
  pointer-events: auto;
  border: 1px dashed transparent;
  overflow: hidden;
}
.img-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.img-wrap.selected { border-color: #0ea5e9; box-shadow: 0 0 0 2px rgba(14,165,233,0.2); }

.sh-rect, .sh-circle, .sh-line, .sh-arrow {
  position: absolute; pointer-events: auto; cursor: move; z-index: 4;
  box-sizing: border-box;
}
.sh-rect.selected, .sh-circle.selected, .sh-line.selected, .sh-arrow.selected {
  outline: 2px solid #0ea5e9;
}

.sticky-note {
  position: absolute; z-index: 5;
  background: #fef08a;
  border: 1px solid #fde047;
  border-radius: 2px;
  padding: 8px;
  cursor: move;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-family: 'Courier New', monospace;
  overflow: auto;
}
.sticky-note.selected, .sticky-note.editing {
  outline: 2px solid #0ea5e9;
}
html.dark .sticky-note { background: #713f12; border-color: #a16207; color: #fef3c7; }

.drag-ghost {
  position: absolute;
  border: 1.5px dashed #0ea5e9;
  background: rgba(14,165,233,0.08);
  pointer-events: none;
  z-index: 20;
}

/* ── Selection chrome + resize handles ───────────────────────────────── */
.sel-box {
  position: absolute;
  border: 1.5px solid #0ea5e9;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 7;
}
.sel-handle {
  position: absolute;
  width: 8px; height: 8px;
  background: #fff;
  border: 1.5px solid #0ea5e9;
  border-radius: 1px;
  pointer-events: auto;
  z-index: 8;
  box-sizing: border-box;
}
.sel-handle-nw { left: -4px; top: -4px; cursor: nwse-resize; }
.sel-handle-ne { right: -4px; top: -4px; cursor: nesw-resize; }
.sel-handle-sw { left: -4px; bottom: -4px; cursor: nesw-resize; }
.sel-handle-se { right: -4px; bottom: -4px; cursor: nwse-resize; }
.sel-handle-n { left: 50%; top: -4px; margin-left: -4px; cursor: ns-resize; }
.sel-handle-s { left: 50%; bottom: -4px; margin-left: -4px; cursor: ns-resize; }
.sel-handle-e { right: -4px; top: 50%; margin-top: -4px; cursor: ew-resize; }
.sel-handle-w { left: -4px; top: 50%; margin-top: -4px; cursor: ew-resize; }

/* ── Formatting Toolbar ───────────────────────────────────────────────── */
.format-bar {
  position: absolute;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 3px 6px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.06);
  z-index: 9999;
  font-family: inherit;
}
html.dark .format-bar {
  background: #1e293b;
  border-color: #475569;
}
.fb-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 26px;
  border: none; border-radius: 4px;
  background: transparent; color: #475569;
  font-size: 12px; cursor: pointer;
  transition: background 0.1s;
}
.fb-btn:hover { background: #f1f5f9; color: #0f172a; }
html.dark .fb-btn:hover { background: #334155; color: #e2e8f0; }
.fb-del { color: #ef4444; font-size: 11px; }
.fb-del:hover { background: #fef2f2; }
.fb-sep {
  width: 1px; height: 18px;
  background: #e2e8f0; margin: 0 3px;
}
html.dark .fb-sep { background: #475569; }
.fb-sel {
  height: 26px; padding: 0 4px;
  border: 1px solid #e2e8f0; border-radius: 4px;
  font-size: 11px; outline: none; cursor: pointer;
  background: #fff; color: #334155;
  max-width: 110px;
}
html.dark .fb-sel { background: #0f172a; border-color: #475569; color: #e2e8f0; }
.fb-color {
  width: 26px; height: 26px;
  border: 1px solid #e2e8f0; border-radius: 4px;
  padding: 2px; cursor: pointer;
}

/* ── Properties Panel ─────────────────────────────────────────────────── */
.properties-panel {
  width: 180px; flex-shrink: 0;
  padding: 10px; overflow-y: auto;
  border-left: 1px solid #e2e8f0;
  background: #fff;
  font-size: 11px;
}
html.dark .properties-panel { background: #1e293b; border-color: #334155; }

.prop-label {
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: #94a3b8; margin-bottom: 4px;
}
.prop-select, .prop-input {
  width: 100%; padding: 4px 6px;
  border: 1px solid #e2e8f0; border-radius: 5px;
  font-size: 11px; background: #fff; color: #334155;
  outline: none; transition: border-color 0.15s;
}
.prop-select:focus, .prop-input:focus { border-color: #0ea5e9; }
html.dark .prop-select, html.dark .prop-input { background: #0f172a; border-color: #475569; color: #e2e8f0; }

/* ── Color Swatches ───────────────────────────────────────────────────── */
.color-swatch-row { display: flex; gap: 3px; flex-wrap: wrap; }
.color-swatch {
  width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: #334155; }

/* ── Find & Replace Bar ───────────────────────────────────────────────── */
.find-replace-bar {
  display: none; align-items: center;
  gap: 4px; padding: 4px 8px;
  border-radius: 6px; margin-bottom: 4px;
  background: #fff; border: 1px solid #e2e8f0;
  flex-wrap: wrap;
}
.find-replace-bar.active { display: flex; }
html.dark .find-replace-bar { background: #1e293b; border-color: #334155; }

.find-replace-bar input {
  padding: 4px 8px; border: 1px solid #e2e8f0;
  border-radius: 4px; font-size: 11px; outline: none;
  min-width: 100px;
}
.find-replace-bar input:focus { border-color: #0ea5e9; }
html.dark .find-replace-bar input { background: #0f172a; border-color: #475569; color: #e2e8f0; }

.fr-btn {
  padding: 4px 10px; border: none; border-radius: 4px;
  font-size: 10px; font-weight: 700; cursor: pointer;
  transition: opacity 0.15s;
}
.fr-btn-find { background: #0ea5e9; color: #fff; }
.fr-btn-replace { background: #10b981; color: #fff; }
.fr-btn-close { background: #f1f5f9; color: #64748b; }
html.dark .fr-btn-close { background: #334155; color: #94a3b8; }
.fr-btn:hover { opacity: 0.85; }

.find-match-count { font-size: 10px; font-weight: 600; color: #64748b; }

/* ── Status Bar ───────────────────────────────────────────────────────── */
.pdf-status-bar {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 3px 10px;
  font-size: 10px; font-weight: 500; color: #94a3b8;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  border-radius: 0 0 8px 8px;
}
html.dark .pdf-status-bar { background: #0f172a; border-color: #334155; }

/* ── Zoom Controls ────────────────────────────────────────────────────── */
.zoom-controls { display: flex; align-items: center; gap: 2px; }
.zoom-btn {
  width: 24px; height: 24px;
  border: 1px solid #e2e8f0; border-radius: 4px;
  background: #fff; color: #475569;
  font-size: 12px; font-weight: 700;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: all 0.1s;
}
.zoom-btn:hover { background: #f1f5f9; border-color: #94a3b8; }
html.dark .zoom-btn { background: #1e293b; border-color: #475569; color: #94a3b8; }
.zoom-level { font-size: 10px; font-weight: 700; color: #475569; min-width: 32px; text-align: center; }
html.dark .zoom-level { color: #94a3b8; }

/* ── Loading ──────────────────────────────────────────────────────────── */
.pdf-loading { display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 2rem; }
.pdf-loading.active { display: flex; }
.loading-bar {
  width: 160px; height: 3px; border-radius: 3px;
  background: #e2e8f0; overflow: hidden; position: relative;
}
.loading-bar::after {
  content: ''; position: absolute; top: 0; left: -100%;
  width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, #0ea5e9, transparent);
  animation: loadSlide 1.2s ease-in-out infinite;
}
@keyframes loadSlide { 0% { left: -50%; } 100% { left: 100%; } }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .thumbnails-sidebar { display: none; }
  .properties-panel { display: none; }
  .pdf-editor-workspace { height: calc(100vh - 160px); }
}
@media (max-width: 640px) {
  .pdf-toolbar { padding: 3px 4px; gap: 1px; }
  .tool-btn { width: 26px; height: 26px; }
  .tool-btn svg { width: 12px; height: 12px; }
  .pages-container { padding: 8px; }
  .pdf-upload-zone { padding: 1.5rem 1rem; }
}

/* ── Pro extensions ───────────────────────────────────────────────────── */
.pdf-subtoolbar {
  margin-top: -4px;
  margin-bottom: 6px;
  padding: 2px 8px;
  gap: 4px;
}
.sub-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #94a3b8;
  text-transform: uppercase;
  margin-right: 4px;
}
.mode-btn {
  width: 26px !important;
  font-size: 10px;
  font-weight: 800;
}
.edit-mode-group .mode-btn.active {
  background: #0f172a;
  color: #fff;
}

.hl-squiggly {
  position: absolute;
  pointer-events: none;
  height: 3px !important;
  background: repeating-linear-gradient(
    90deg,
    #ef4444 0 4px,
    transparent 4px 7px
  ) !important;
  border-radius: 0;
}

.sh-roundrect, .sh-ellipse, .sh-polygon {
  position: absolute; pointer-events: auto; cursor: move; z-index: 4;
  box-sizing: border-box;
}
.sh-roundrect.selected, .sh-ellipse.selected, .sh-polygon.selected,
.sh-rect.selected, .sh-circle.selected, .sh-line.selected, .sh-arrow.selected {
  outline: 2px solid #0ea5e9;
}

.pdf-link {
  position: absolute;
  z-index: 6;
  border: 1px dashed rgba(59,130,246,0.55);
  background: rgba(59,130,246,0.08);
  cursor: pointer;
  pointer-events: auto;
}
.pdf-link.selected { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }

.form-field {
  position: absolute;
  z-index: 6;
  pointer-events: auto;
  box-sizing: border-box;
}
.form-field.selected { outline: 2px solid #0ea5e9; }
.form-input {
  width: 100%;
  height: 100%;
  border: 1px solid #94a3b8;
  border-radius: 3px;
  background: rgba(255,255,255,0.95);
  font-size: 12px;
  padding: 2px 4px;
  box-sizing: border-box;
}
.form-field input[type="checkbox"],
.form-field input[type="radio"] {
  width: 100%;
  height: 100%;
  margin: 0;
}

.align-guide {
  position: absolute;
  background: #f43f5e;
  pointer-events: none;
  z-index: 30;
  opacity: 0.85;
}
.align-guide-v { width: 1px; height: 100%; top: 0; }
.align-guide-h { height: 1px; width: 100%; left: 0; }

.added-text.locked, .img-wrap.locked, [class^="sh-"].locked {
  outline: 1px dashed #94a3b8 !important;
  cursor: not-allowed !important;
}

.pdf-modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
}
.pdf-modal-card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  width: min(460px, 92vw);
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
html.dark .pdf-modal-card { background: #1e293b; color: #e2e8f0; }

.properties-panel { width: 210px; }
.pdf-toolbar-main { row-gap: 4px; }