/**
 * UI/UX Pro Max - Standalone PDF Editor Stylesheet
 * Integrates with existing design tokens, dual dark/light mode,
 * and handles pixel-perfect overlays, floating property palettes, and toolbars.
 */

/* Main Editor Layout */
.editor-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg-app);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* Apply Changes Button inside .nav-actions */
.btn-apply-changes {
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px var(--color-primary-glow);
  transition: all 0.18s ease;
  white-space: nowrap;
}

.btn-apply-changes:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--color-primary-glow);
}

.btn-apply-changes:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Secondary Tool Ribbon */
.editor-ribbon {
  position: sticky;
  top: 67px;
  z-index: 900;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 20px;
  box-shadow: var(--shadow-sm);
}

.ribbon-inner {
  max-width: 1380px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.tools-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.tool-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.tool-btn.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.ribbon-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
  margin: 0 6px;
}

.zoom-controls {
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.zoom-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.zoom-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

/* Workspace Canvas Viewport */
.editor-workspace {
  flex: 1;
  padding: 36px 20px 80px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  background-color: var(--bg-app);
  position: relative;
}

/* Initial Dropzone Landing (when no PDF loaded) */
.editor-landing {
  max-width: 680px;
  width: 100%;
  margin: 60px auto;
  text-align: center;
}

.editor-dropzone {
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 56px 36px;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.editor-dropzone:hover,
.editor-dropzone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.landing-icon-wrap {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 16px var(--color-primary-glow);
}

.landing-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.landing-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  max-width: 440px;
}

.landing-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Individual PDF Page Stack */
.pdf-page-container {
  position: relative;
  background: #ffffff;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border-subtle);
  border-radius: 4px;
  transition: transform 0.2s ease;
  user-select: none;
}

.pdf-canvas {
  display: block;
  border-radius: 4px;
}

/* Interactive Synchronized Overlay Layer */
.page-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  overflow: visible !important;
  border-radius: 4px;
}

.page-overlay.tool-active-crosshair {
  cursor: crosshair !important;
}

.page-overlay.tool-active-text {
  cursor: text !important;
}

/* Overlay Annotation Objects */
.overlay-item {
  position: absolute;
  box-sizing: border-box;
  cursor: move;
  z-index: 10;
  user-select: none;
}

.overlay-item.selected {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Existing Text Layer (Extracted from PDF) */
.existing-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

/* Individual Existing Text Block */
.existing-text-block {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none; /* Disabled by default so other tools work cleanly */
  cursor: text;
  border-radius: 3px;
  border: 1px dashed transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  color: transparent !important;
  white-space: nowrap;
  overflow: visible;
  padding: 1px 3px;
  display: inline-flex;
  align-items: center;
}

.existing-text-block .text-content {
  color: transparent !important;
  white-space: nowrap;
  user-select: none;
}

/* Enabled when Text or Select tool is active */
.page-overlay.tool-active-text .existing-text-block,
.page-overlay.tool-active-select .existing-text-block {
  pointer-events: auto;
}

.page-overlay.tool-active-text .existing-text-block:hover:not(.active-editing),
.page-overlay.tool-active-select .existing-text-block:hover:not(.active-editing) {
  border-color: rgba(59, 130, 246, 0.6);
  background-color: rgba(59, 130, 246, 0.08);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.text-edit-badge {
  display: none;
  position: absolute;
  top: -24px;
  left: 0;
  background: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  z-index: 100;
  align-items: center;
  gap: 4px;
}

.page-overlay.tool-active-text .existing-text-block:hover:not(.active-editing) .text-edit-badge,
.page-overlay.tool-active-select .existing-text-block:hover:not(.active-editing) .text-edit-badge {
  display: inline-flex;
}

/* While editing, hide the original block so only the white active-text-editor-container shows */
.existing-text-block.active-editing {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Altered state (only after user explicitly confirms edit via tick mark) */
.existing-text-block.altered {
  background-color: #ffffff;
  color: inherit !important;
  z-index: 15;
  border: 1px solid transparent !important;
  box-shadow: none !important;
  outline: none !important;
  white-space: nowrap !important;
  width: auto !important;
  min-width: fit-content !important;
  height: auto !important;
  min-height: 16px;
  padding: 1px 3px;
  display: inline-flex;
  align-items: center;
}

/* Do not show box or shadow around altered text after confirmation */
.page-overlay.tool-active-text .existing-text-block.altered:hover:not(.active-editing),
.page-overlay.tool-active-select .existing-text-block.altered:hover:not(.active-editing) {
  border-color: transparent !important;
  box-shadow: none !important;
  outline: none !important;
}

/* Hide edit badge on confirmed altered text */
.existing-text-block.altered .text-edit-badge {
  display: none !important;
}

.existing-text-block.altered .text-content {
  color: inherit !important;
  white-space: nowrap !important;
  display: inline-block;
}

.existing-text-block.erased {
  border: 1px dashed rgba(239, 68, 68, 0.6) !important;
  background-color: #ffffff !important;
}

.existing-text-block.erased::after {
  content: "Erased";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: rgba(239, 68, 68, 0.7);
  font-family: var(--font-sans);
  font-weight: 600;
  pointer-events: none;
}

/* Active Text Inline Editor Container */
.active-text-editor-container {
  position: absolute;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16), 0 0 0 2px var(--color-primary);
  border-radius: var(--radius-sm);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  pointer-events: auto !important;
  overflow: visible;
}

.active-text-editor-input {
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  padding: 2px 6px;
  margin: 0;
  white-space: pre; /* Keep on single line without auto-wrapping */
  word-break: normal;
  line-height: 1.15;
  box-sizing: border-box;
  color: inherit;
  pointer-events: auto !important;
}

/* Floating Confirmation Pill (Tick & Close) */
.inline-action-dock {
  position: absolute;
  right: 0;
  top: -34px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-subtle);
  z-index: 60;
  animation: fadeInDown 0.15s ease-out;
  pointer-events: auto !important;
}

.inline-action-dock.dock-bottom {
  top: auto;
  bottom: -34px;
}

.btn-inline-action {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto !important;
}

/* Interactive PDF Page Toolbar */
.pdf-page-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.pdf-page-toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  color: var(--text-secondary);
  box-sizing: border-box;
}

.pdf-page-badge {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.pdf-page-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-page-ctrl {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 3px 8px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-page-ctrl:hover {
  background: var(--bg-card-subtle);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn-page-ctrl.btn-page-del:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.btn-inline-action.btn-confirm {
  background: var(--color-success);
  color: #ffffff;
}

.btn-inline-action.btn-confirm:hover {
  background: #059669;
  transform: scale(1.08);
}

.btn-inline-action.btn-cancel {
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

.btn-inline-action.btn-cancel:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--color-danger);
  border-color: var(--color-danger);
  transform: scale(1.08);
}

/* Text Element */
.overlay-text {
  min-width: 32px;
  min-height: 20px;
  padding: 2px 4px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.25;
  background: transparent;
}

.overlay-text:focus {
  outline: 2px dashed var(--color-primary) !important;
}

/* Whiteout Element */
.overlay-whiteout {
  background: #ffffff;
  border: 1px dashed rgba(0, 0, 0, 0.15);
}

.overlay-whiteout.selected {
  border-color: var(--color-primary);
}

/* Highlight Element */
.overlay-highlight {
  background: rgba(254, 240, 138, 0.4);
  pointer-events: auto;
}

/* Vector Shapes (Rect, Ellipse) */
.overlay-shape {
  box-sizing: border-box;
}

/* Form Mark (Check, Cross) */
.overlay-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: move;
}

/* Image / Signature Element */
.overlay-image {
  object-fit: contain;
  pointer-events: auto;
}

.overlay-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

/* Resize & Control Handles */
.handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid var(--color-primary);
  border-radius: 2px;
  z-index: 20;
}

.handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }

.handle-del {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 20px;
  height: 20px;
  background: var(--color-danger);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 30;
  border: none;
}

.handle-del:hover {
  transform: scale(1.15);
}

/* Floating Contextual Property Bar */
.floating-palette {
  position: absolute;
  z-index: 2000;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateY(-100%);
  margin-top: -8px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-90%); }
  to { opacity: 1; transform: translateY(-100%); }
}

.palette-select {
  height: 30px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 0 8px;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-card);
  cursor: pointer;
}

.palette-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: all 0.15s ease;
}

.palette-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.palette-btn.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.palette-color-input {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 2px;
  cursor: pointer;
  background: var(--bg-card);
}

/* Signature Creation Modal */
.sig-modal-card {
  max-width: 580px;
  width: 100%;
}

.sig-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 20px;
  gap: 8px;
}

.sig-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.sig-tab-btn:hover {
  color: var(--text-primary);
}

.sig-tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.sig-canvas-wrap {
  position: relative;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04);
  touch-action: none;
}

.sig-draw-canvas {
  width: 100%;
  height: 180px;
  display: block;
  border-radius: var(--radius-md);
  cursor: crosshair;
}

.sig-canvas-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.sig-font-previews {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.sig-font-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  font-size: 26px;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.sig-font-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

.sig-font-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.sig-upload-box {
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-dropzone);
}

.sig-preview-img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
}

/* Export Notification / Success Bar */
.editor-export-banner {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  color: var(--color-success);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Responsive tweaks */
@media (max-width: 1024px) {
  .ribbon-inner {
    justify-content: flex-start;
    overflow-x: auto;
  }
  .zoom-controls {
    position: static;
    margin-left: auto;
  }
}

@media (max-width: 768px) {
  .editor-nav-inner {
    flex-wrap: wrap;
  }
  .tools-group {
    overflow-x: auto;
  }
  .tool-btn span {
    display: none;
  }
  .tool-btn {
    padding: 6px 8px;
  }
  .sig-font-previews {
    grid-template-columns: 1fr;
  }
}
