/* editor.css */
/* Root tokens (reuse from global or override if this file is standalone) */
:root {
  --color-charcoal: #36454f;
  --color-charcoal-light: #576673;
  --color-charcoal-dark: #232e36;
  --color-red: #e63946;

  --color-white: #ffffff;
  --color-off-white: #f8f9fa;
  --color-light-gray: #e9ecef;
  --color-gray: #ced4da;
  --color-dark-gray: #6c757d;
  --color-black: #212529;

  --color-success: #28a745;
  --color-warning: #ffc107;
  --color-error: #dc3545;
  --color-info: #17a2b8;

  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-secondary: 'Georgia', serif;
  --font-mono: 'Courier New', monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.14);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;

  /* Added toolbar sizing so fixed positioning works consistently */
  --app-header-height: 72px;
  --document-toolbar-height: 56px;
}

/* Base editor layout */

.editor-page-body {
  margin: 0;
  font-family: var(--font-primary);
  background: var(--color-off-white);
  color: var(--color-black);
}

.editor-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--color-off-white);
}

.editor-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding-top: var(--document-toolbar-height);
}

/* Main editor layout */

.editor-main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: var(--space-4);
  padding: var(--space-4);
  align-items: stretch;
}

@media (max-width: 1024px) {
  .editor-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Toolbar */

.document-toolbar {
  position: fixed;
  top: var(--app-header-height);
  left: 0;
  right: 0;
  z-index: 2000;
  min-height: var(--document-toolbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-light-gray);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.document-toolbar .toolbar-section {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.toolbar-left,
.toolbar-center,
.recipients-section {
  min-width: 0;
}

.document-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-charcoal);
  margin-inline: var(--space-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.toolbar-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-charcoal);
  background: transparent;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.toolbar-btn:hover {
  background: var(--color-off-white);
  color: var(--color-charcoal-dark);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.toolbar-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Tool buttons */

.toolbar-center {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2);
}

.toolbar-center-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.1rem;
  border-radius: var(--radius-pill);
  background: var(--color-off-white);
  border: 1px solid var(--color-light-gray);
}

.toolbar-tool-btn {
  min-width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  border: none;
  padding: 0 0.65rem;
  font-size: 0.875rem;
  color: var(--color-dark-gray);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    transform var(--transition-fast);
}

.toolbar-tool-btn:hover {
  background: var(--color-light-gray);
  transform: translateY(-1px);
}

.toolbar-tool-btn.is-active {
  background: var(--color-charcoal);
  color: var(--color-white);
}

/* Recipients / action area */

.recipients-section {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

.recipient-selector {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 220px;
}

.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  background: var(--color-red);
  color: var(--color-white);
  font-weight: 600;
  font-size: 0.9rem;
  transition:
    background var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.send-btn:hover:not(:disabled) {
  background: #c72433;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Viewer column */

.editor-viewer-container {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pdf-viewer {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: var(--radius-md);
  background: var(--color-white);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.pdf-controls {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--color-light-gray);
  background: var(--color-off-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.page-navigation,
.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.nav-button,
.zoom-button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-light-gray);
  background: #f9fafb;
  color: var(--color-charcoal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.nav-button:hover,
.zoom-button:hover {
  background: var(--color-off-white);
  border-color: var(--color-gray);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.nav-button:disabled,
.zoom-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.page-info,
.zoom-level {
  font-size: 0.875rem;
  color: var(--color-dark-gray);
  min-width: 64px;
  text-align: center;
}

.pdf-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: var(--space-4);
  position: relative;
  background: #e5e7eb;
  min-height: 480px;
}

.pdf-loading,
.pdf-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: rgba(248, 249, 250, 0.92);
  z-index: 5;
  text-align: center;
  padding: var(--space-4);
}

.pdf-loading[hidden],
.pdf-error[hidden] {
  display: none !important;
}

.pdf-error {
  color: var(--color-error);
}

.progress-container {
  width: min(320px, 100%);
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: #dbe1e6;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.08);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--color-charcoal);
  transition: width var(--transition-normal);
}

.retry-button {
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-charcoal);
  color: var(--color-white);
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

.pdf-pages {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  position: relative;
  min-width: max-content;
}

.pdf-page {
  position: relative;
  background: var(--color-white);
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: var(--space-2);
  cursor: default;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  max-width: 100%;
}

.pdf-page:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.16);
  transform: translateY(-2px);
}

.pdf-page.current-page {
  box-shadow: 0 0 0 3px var(--color-charcoal), 0 4px 12px rgba(0,0,0,0.2);
}

/* Ensure z-order for PDF + overlay */
.page-media-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  width: max-content;
  max-width: none;
  flex: 0 0 auto;
  z-index: 1;
}


.page-media-wrap img,
.page-media-wrap canvas {
  display: block;
  width: auto;
  max-width: none;
  height: auto;
  transform-origin: top center;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.page-number,
.pdf-page-number {
  position: absolute;
  bottom: 10px;
  right: 14px;
  background: rgba(0,0,0,0.72);
  color: #fff;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.2;
}

/* Overlay / annotation layer */

.annotation-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

/* Labels */

.document-label {
  position: absolute;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: flex;
  align-items: stretch;
  justify-content: stretch;

  /* changed from hidden */
  overflow: visible;

  background: transparent;
  pointer-events: auto;
  padding: 0;
  margin: 0;
  outline: none;
  z-index: 21;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-fast),
    transform var(--transition-fast);
}

.document-label:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.16);
}

.document-label.is-selected {
  z-index: 22;
  box-shadow: 0 0 0 3px rgba(54, 69, 79, 0.28), 0 4px 10px rgba(0,0,0,0.16);
}

.document-label.is-dragging {
  z-index: 23;
  transform: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
}

.document-label.is-required::after {
  content: "*";
  position: absolute;
  top: 2px;
  right: 4px;
  color: var(--color-error);
  font-size: 0.9rem;
  font-weight: 700;
  pointer-events: none;
}

.document-label .label-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  overflow: hidden;
  border: 1px dashed currentColor;
  background: transparent;
  padding: 0.25rem 0.5rem;
}

.document-label .field-display {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
  line-height: 1.2;
}

.label-type-text {
  min-width: 120px;
  min-height: 32px;
}

.label-type-signature {
  min-width: 160px;
  min-height: 50px;
}

.label-type-checkbox {
  min-width: 40px;
  min-height: 40px;
}

.label-type-datefield {
  min-width: 140px;
  min-height: 38px;
}

/* Sidebar */

.editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-4);
  min-height: 0;
  min-width: 0;
}

.editor-sidebar-section {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-off-white);
}

.editor-sidebar-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--color-dark-gray);
  margin-bottom: var(--space-2);
}

/* Dialog */

.editor-dialog {
  max-width: 640px;
  width: min(640px, calc(100vw - 2rem));
  border: none;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  color: var(--color-black);
}

.editor-dialog::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.editor-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.editor-dialog-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-charcoal);
}

.editor-dialog-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.editor-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* Panels / misc UI */

.editor-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
}

.editor-banner-warning {
  background: rgba(255, 193, 7, 0.12);
  color: #8a6d1f;
}

.editor-banner-error {
  background: rgba(220, 53, 69, 0.1);
  color: #842029;
}

.editor-banner-info {
  background: rgba(23, 162, 184, 0.1);
  color: #0c5460;
}

.editor-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--color-white);
  border: 1px solid var(--color-light-gray);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-dark-gray);
}

.editor-chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.editor-muted {
  font-size: 0.8rem;
  color: var(--color-dark-gray);
}

.editor-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: var(--space-3);
}

.editor-field-group:last-child {
  margin-bottom: 0;
}

.editor-field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-charcoal);
}

.editor-field-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-gray);
  background: var(--color-white);
  color: var(--color-black);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.editor-field-input:focus {
  border-color: var(--color-charcoal);
  box-shadow: 0 0 0 0.1rem rgba(54, 69, 79, 0.25);
  outline: 0;
}

select.editor-field-input {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-dark-gray) 50%),
    linear-gradient(135deg, var(--color-dark-gray) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.25rem;
}

/* Optional page mode styling */

.private-editor-page .send-btn {
  background: var(--color-red);
}

.public-editor-page .send-btn {
  background: var(--color-charcoal);
}

/* Responsive */

@media (max-width: 768px) {
  :root {
    --app-header-height: 72px;
    --document-toolbar-height: 108px;
  }

  .editor-shell {
    padding-top: var(--document-toolbar-height);
  }

  .document-toolbar {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-center,
  .recipients-section {
    width: 100%;
    justify-content: flex-start;
  }

  .recipient-selector {
    min-width: 0;
    flex: 1;
  }

  .document-title {
    max-width: 100%;
  }

  .pdf-controls {
    flex-wrap: wrap;
  }

  .page-navigation,
  .zoom-controls {
    width: 100%;
    justify-content: space-between;
  }
}

/* Dark mode */

@media (prefers-color-scheme: dark) {
  .editor-page-body {
    background: #2d2d2d;
    color: #eeeeee;
  }

  .editor-page {
    background: #2d2d2d;
  }

  .document-toolbar {
    background: #1e1e1e;
    border-bottom-color: #3a3a3a;
  }

  .document-title,
  .toolbar-btn,
  .editor-field-label,
  .editor-dialog-title {
    color: #eeeeee;
  }

  .toolbar-btn:hover {
    background: #2a2a2a;
    color: #ffffff;
  }

  .toolbar-center-group {
    background: #252525;
    border-color: #3a3a3a;
  }

  .toolbar-tool-btn {
    color: #c9c9c9;
  }

  .toolbar-tool-btn:hover {
    background: #333333;
  }

  .toolbar-tool-btn.is-active {
    background: #f3f4f6;
    color: #111827;
  }

  .pdf-viewer,
  .editor-sidebar,
  .editor-dialog {
    background: #1e1e1e;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  }

  .pdf-controls,
  .editor-sidebar-section {
    background: #252525;
    border-color: #3a3a3a;
  }

  .nav-button,
  .zoom-button,
  .editor-chip {
    background: #2a2a2a;
    border-color: #444;
    color: #eee;
  }

  .nav-button:hover,
  .zoom-button:hover {
    background: #343434;
    border-color: #5a5a5a;
  }

  .page-info,
  .zoom-level,
  .editor-muted {
    color: #c4c4c4;
  }

  .pdf-container {
    background: #3a3a3a;
  }

  .pdf-loading,
  .pdf-error {
    background: rgba(30, 30, 30, 0.92);
  }

  .progress-bar {
    background: #4a4a4a;
  }

  .progress-fill {
    background: #d1d5db;
  }

  .retry-button {
    background: #e5e7eb;
    color: #111827;
  }

  .pdf-page {
    background: #111111;
  }

  .document-label {
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  }

  .document-label .label-content {
    background: transparent;
  }

  .editor-field-input {
    background: #1e1e1e;
    border-color: #555555;
    color: #eeeeee;
  }

  .editor-field-input:focus {
    border-color: #d1d5db;
    box-shadow: 0 0 0 0.1rem rgba(209, 213, 219, 0.22);
  }

  select.editor-field-input {
    background-image:
      linear-gradient(45deg, transparent 50%, #d1d5db 50%),
      linear-gradient(135deg, #d1d5db 50%, transparent 50%);
  }
}

/* Signing page layout */
/* Signing layout root */
.editor-shell.signing-shell {
  height: 100vh;
  padding-top: var(--document-toolbar-height);
}

/* Main area: two columns */
.editor-shell.signing-shell .editor-main {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  height: calc(100vh - var(--document-toolbar-height));
  overflow: hidden; /* prevent body scroll; only viewer scrolls */
}


.send-recipient-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.send-recipient-card {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-light-gray);
  background: #f9fafb;
}

.send-recipient-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.send-recipient-card-meta {
  flex: 1;
  min-width: 0;
}

.editor-dialog__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.editor-dialog__panel--public-link {
  width: 100%;
}

.editor-dialog__panel--success {
  align-items: center;
  text-align: center;
  padding: var(--space-5);
  max-width: 520px;
  margin: 0 auto;
}

.editor-dialog__close {
  position: absolute;
  top: 0;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-charcoal);
  background: transparent;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.editor-dialog__close:hover {
  background: var(--color-off-white);
  color: var(--color-charcoal-dark);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.editor-dialog__icon-wrap {
  display: flex;
  justify-content: center;
  margin-top: var(--space-2);
}

.editor-dialog__success-icon {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 167, 69, 0.12);
  color: var(--color-success);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.editor-dialog__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-charcoal);
}

.editor-dialog__message,
.editor-dialog__quota {
  margin: 0;
  color: var(--color-dark-gray);
}

.editor-dialog__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-2);
}

.editor-dialog__actions--center {
  justify-content: center;
}

.editor-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  min-height: 40px;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.editor-btn--primary {
  background: var(--color-red);
  color: var(--color-white);
}

.editor-btn--primary:hover:not(:disabled) {
  background: #c72433;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.editor-btn--primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (prefers-color-scheme: dark) {
  .editor-dialog__close {
    color: #eeeeee;
  }

  .editor-dialog__close:hover {
    background: #2a2a2a;
    color: #ffffff;
  }

  .editor-dialog__title {
    color: #eeeeee;
  }

  .editor-dialog__message,
  .editor-dialog__quota {
    color: #c4c4c4;
  }

  .editor-dialog__success-icon {
    background: rgba(109, 170, 69, 0.16);
    color: #9fe870;
  }
}

