/* ========================================
   PDForge — Editor & Field Overlay
   ======================================== */

/* ---- Editor toolbar ---- */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tool-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.tool-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 6px;
}

/* ---- PDF Viewport ---- */
.pdf-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  position: relative;
}

.pdf-page-container {
  position: relative;
  box-shadow: var(--shadow-lg);
  background: #fff;
  line-height: 0;
}

#pdfCanvas {
  display: block;
}

/* ---- Field Overlay ---- */
.field-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  touch-action: none;
}

.form-field {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  border: 2px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 2px;
  transition: box-shadow var(--transition);
  user-select: none;
}

.form-field:hover {
  box-shadow: 0 0 0 1px var(--accent);
}

.form-field.selected {
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 2px var(--accent-dim), 0 0 12px rgba(79, 143, 247, 0.2);
  z-index: 10;
}

.form-field[data-type="signature"] {
  border-color: var(--sig-accent);
  background: var(--sig-dim);
}

.form-field[data-type="signature"]:hover {
  box-shadow: 0 0 0 1px var(--sig-accent);
}

.form-field[data-type="signature"].selected {
  border-color: var(--sig-accent);
  box-shadow: 0 0 0 2px var(--sig-dim), 0 0 12px rgba(229, 168, 66, 0.2);
}

.form-field[data-type="checkbox"],
.form-field[data-type="radio"] {
  border-radius: 2px;
}

.form-field[data-type="radio"] {
  border-radius: 50%;
}

/* Field label */
.field-label {
  position: absolute;
  top: -18px;
  left: 0;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  pointer-events: none;
  line-height: 1;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-field[data-type="signature"] .field-label {
  color: var(--sig-accent);
}

/* Field type icon */
.field-type-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 2px;
  font-size: 8px;
  font-weight: 700;
  pointer-events: none;
}

.form-field[data-type="signature"] .field-type-badge {
  background: var(--sig-accent);
}

/* Resize handles */
.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity var(--transition);
}

.form-field.selected .resize-handle {
  opacity: 1;
}

.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }
.resize-handle.n  { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle.s  { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle.w  { top: 50%; left: -4px; transform: translateY(-50%); cursor: w-resize; }
.resize-handle.e  { top: 50%; right: -4px; transform: translateY(-50%); cursor: e-resize; }

.form-field[data-type="signature"] .resize-handle {
  background: var(--sig-accent);
}

/* Signature preview in field */
.sig-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Tab order indicator */
.tab-order-badge {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 0 4px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
}

.show-tab-order .tab-order-badge {
  opacity: 1;
}

/* Selection box for multi-select */
.selection-box {
  position: absolute;
  border: 1px dashed var(--accent);
  background: rgba(79, 143, 247, 0.05);
  pointer-events: none;
  z-index: 20;
}

/* Placement preview */
.placement-preview {
  position: absolute;
  border: 2px dashed var(--accent);
  background: var(--accent-dim);
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.6;
}

.placement-preview[data-type="signature"] {
  border-color: var(--sig-accent);
  background: var(--sig-dim);
}

/* Required indicator */
.field-required {
  position: absolute;
  top: -18px;
  right: 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* Field group highlight */
.field-group-highlight {
  position: absolute;
  border: 1px dashed var(--text-muted);
  border-radius: 4px;
  pointer-events: none;
  padding: 4px;
}

/* Dropdown options overlay */
.field-options-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 120px;
  overflow-y: auto;
  z-index: 30;
  font-size: 11px;
}

.field-options-list div {
  padding: 4px 8px;
  cursor: pointer;
}

.field-options-list div:hover {
  background: var(--bg-hover);
}
