/**
 * PDF Editor Styles - Phase 3 Page Editing
 * Comprehensive styling for PDF editing tools and interface
 */

/* Editor Canvas */
.editing-canvas {
  pointer-events: auto;
  touch-action: none; /* Prevent scrolling while drawing */
  user-select: none; /* Allow text selection when not in drawing mode */
}

/* PDF Canvas - Enable text selection */
#pdf-canvas {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
}

/* PDF Viewer Container */
.pdf-viewer-container {
  position: relative;
  width: 100%;
  min-height: 400px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* Allow horizontal scrolling for large PDFs */
  overflow-x: auto;
  overflow-y: auto;
}

/* PDF Canvas Wrapper */
#pdf-canvas-wrapper {
  position: relative;
  display: inline-block;
  /* Remove max-width to allow natural PDF size */
  width: auto;
  min-width: fit-content;
}

/* PDF Canvas Scaling - Fit Container Width */
#pdf-canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

/* Text selection layer */
.textLayer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 0.2;
  line-height: 1.0;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  cursor: text;
}

.textLayer > span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.pdf-text-layer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 0.2;
  line-height: 1.0;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: auto;
}

.pdf-text-layer > span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.pdf-text-layer .highlight {
  margin: -1px;
  padding: 1px;
  background-color: rgba(180, 0, 170, 0.2);
  border-radius: 4px;
}

/* Toolbar Styles */
.pdf-editor-toolbar {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  width: 100%;
  overflow-x: auto;
  position: relative;
  z-index: 20;
}

/* Tool Buttons */
.tool-btn {
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background-color: white;
  transition: colors 0.2s, background-color 0.2s;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn:hover {
  background-color: #f9fafb;
  border-color: #9ca3af;
}

.tool-btn.active {
  background-color: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.tool-btn.active:hover {
  background-color: #2563eb;
}

/* Action Buttons */
.action-btn {
  padding: 0.5rem;
  border-radius: 0.25rem;
  border: 1px solid #e5e7eb;
  background-color: white;
  transition: colors 0.2s, background-color 0.2s;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn:hover {
  background-color: #f9fafb;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Tool Settings */
.tool-settings {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-picker input[type="color"] {
  border: 2px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.color-picker input[type="color"]:hover {
  border-color: #9ca3af;
}

.size-slider input[type="range"] {
  accent-color: #3b82f6;
}

.font-selector select {
  border: 1px solid #e5e7eb;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  background-color: white;
}

/* Annotation Styles */
.annotation-popup {
  position: absolute;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-width: 250px;
  z-index: 1000;
}

.annotation-popup::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #fff;
}

/* Text Input Overlay */
.text-input-overlay {
  position: absolute;
  z-index: 100;
  background: transparent;
  border: 2px dashed #3b82f6;
  border-radius: 4px;
  padding: 4px;
}

.text-input-overlay input {
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  width: 100%;
}

/* Shape Drawing */
.shape-preview {
  position: absolute;
  border: 2px dashed #3b82f6;
  pointer-events: none;
  z-index: 50;
}

/* Image Upload */
.image-upload-zone {
  position: absolute;
  border: 2px dashed #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3b82f6;
  font-size: 14px;
  z-index: 100;
}

/* Signature Pad */
.signature-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.signature-pad {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 90vw;
  max-height: 90vh;
}

.signature-canvas {
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  cursor: crosshair;
}

/* Link Editor */
.link-editor {
  position: absolute;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  min-width: 300px;
}

.link-editor input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  margin-bottom: 0.75rem;
}

.link-editor button {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  margin-right: 0.5rem;
}

.link-editor .save-btn {
  background-color: #3b82f6;
  color: white;
}

.link-editor .save-btn:hover {
  background-color: #2563eb;
}

.link-editor .cancel-btn {
  background-color: #f3f4f6;
  color: #374151;
}

.link-editor .cancel-btn:hover {
  background-color: #e5e7eb;
}

/* Responsive Design */
@media (max-width: 768px) {
  .pdf-editor-toolbar {
    position: relative;
    border-radius: 0.5rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    max-width: 100%;
    padding: 12px;
  }
  
  .pdf-editor-toolbar .flex {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }
  
  .tool-btn {
    min-width: 36px;
    min-height: 36px;
  }
  
  .tool-settings {
    order: 3;
    width: 100%;
    justify-content: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
  }
}

/* Touch-specific styles */
@media (pointer: coarse) {
  .tool-btn {
    min-width: 44px;
    min-height: 44px;
  }
  
  .editing-canvas {
    touch-action: none;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .editing-canvas {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Animation classes */
.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.slide-up {
  animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { 
    opacity: 0;
    transform: translateY(20px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

/* Selection indicators */
.selected-element {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #3b82f6;
  border: 1px solid white;
  border-radius: 50%;
  cursor: pointer;
}

.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; }

/* Brand colors integration */
.tool-btn.active {
  background-color: #77BEF0; /* PDFGo blue */
  border-color: #77BEF0;
}

.tool-btn.active:hover {
  background-color: #5ba8e0;
}

.action-btn.save-btn {
  background-color: #77BEF0;
  color: white;
}

.action-btn.save-btn:hover {
  background-color: #5ba8e0;
}

/* Highlight tool specific */
.highlight-mode .editing-canvas {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><rect x="2" y="8" width="16" height="4" fill="%23FFFF00" opacity="0.7"/></svg>') 10 10, crosshair;
}
