.editor-hero {
  margin-bottom: 24px;
}

.editor-page-title {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.05;
}

.editor-intro,
.editor-app {
  padding: 28px;
}

.editor-intro {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 24px;
}

.editor-intro h2 {
  margin: 0 0 10px;
}

.editor-intro p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.security-banner {
  min-width: 260px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
  line-height: 1.5;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 20px 0;
  padding: 16px;
  border: 1px solid rgba(21, 38, 58, 0.08);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
}

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

.ghost-button.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: rgba(217, 72, 65, 0.3);
}

.editor-input,
.color-input {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(21, 38, 58, 0.12);
  border-radius: 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

.editor-input {
  min-width: 220px;
}

.editor-input-small {
  min-width: 84px;
}

.color-input {
  width: 52px;
  padding: 4px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 18px;
}

.thumbnail-panel,
.viewer-panel {
  min-height: 540px;
  padding: 18px;
  border: 1px solid rgba(21, 38, 58, 0.08);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.66);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
}

.mini-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thumbnail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.thumbnail-item {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(21, 38, 58, 0.08);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.thumbnail-item:hover,
.thumbnail-item:focus-visible,
.thumbnail-item.is-active {
  border-color: var(--primary);
  transform: translateY(-1px);
  outline: none;
}

.thumbnail-preview {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #f7f9fb;
}

.thumbnail-label {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-weight: 700;
  text-align: center;
}

.viewer-frame {
  position: relative;
  min-height: 460px;
  padding: 18px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 246, 250, 0.96));
  overflow: auto;
}

.viewer-placeholder {
  display: grid;
  place-items: center;
  min-height: 420px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.viewer-stage {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

#pdfCanvas {
  display: block;
  box-shadow: 0 18px 36px rgba(20, 33, 50, 0.14);
}

.text-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.text-overlay .text-block {
  pointer-events: auto;
}

/* Editable original-text layer (the "notepad" experience) */
.pdf-text-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.pdf-text-layer.is-hidden {
  display: none;
}

.pte-word {
  position: absolute;
  transform-origin: 0 0;
  white-space: pre;
  color: transparent;
  caret-color: #2563eb;
  cursor: text;
  border-radius: 2px;
  padding: 0;
  outline: none;
}

.pdf-text-layer:not(.is-hidden) .pte-word:hover {
  box-shadow: inset 0 -0.12em 0 rgba(37, 99, 235, 0.55);
}

.pte-word.is-editing {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.55);
}

.pte-word.is-dirty {
  box-shadow: 0 0 0 2px rgba(217, 72, 65, 0.6);
}

/* Image / signature objects placed on the page */
.object-block {
  position: absolute;
  min-width: 40px;
  min-height: 40px;
  border: 2px solid rgba(37, 99, 235, 0.5);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
  resize: both;
  overflow: hidden;
  cursor: move;
  pointer-events: auto;
}

.object-block.is-selected {
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(20, 33, 50, 0.18);
}

.object-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 22px;
  padding: 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: rgba(37, 99, 235, 0.85);
  cursor: move;
  user-select: none;
}

.object-remove {
  width: 18px;
  height: 18px;
  line-height: 1;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

.object-image {
  display: block;
  width: 100%;
  height: calc(100% - 22px);
  object-fit: contain;
  pointer-events: none;
}

.watermark-preview {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* Modals (signature / watermark) */
.editor-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
}

.editor-modal {
  width: min(520px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 20px;
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
}

.editor-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.editor-modal-head h3 {
  margin: 0;
}

.editor-modal-close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(21, 38, 58, 0.08);
  cursor: pointer;
  font-size: 1.2rem;
}

.editor-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.editor-modal-tab {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(21, 38, 58, 0.12);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.editor-modal-tab.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.signature-pad {
  display: block;
  width: 100%;
  height: auto;
  border: 1px dashed rgba(21, 38, 58, 0.3);
  border-radius: 12px;
  background: #fff;
  touch-action: none;
}

.editor-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-modal-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.editor-modal .hidden {
  display: none;
}

.flatten-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.text-block {
  position: absolute;
  min-width: 48px;
  padding: 4px 6px;
  border: 1px dashed transparent;
  border-radius: 8px;
  cursor: move;
  user-select: none;
  white-space: pre-wrap;
  line-height: 1.3;
  background: rgba(255, 255, 255, 0.18);
}

.text-block.is-selected {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.7);
}

.replace-block {
  position: absolute;
  min-width: 120px;
  min-height: 52px;
  padding: 8px;
  border: 2px solid rgba(21, 38, 58, 0.12);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(20, 33, 50, 0.12);
  resize: both;
  overflow: hidden;
}

.replace-block.is-selected {
  border-color: var(--primary);
  box-shadow: 0 12px 28px rgba(217, 72, 65, 0.16);
}

.replace-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  cursor: move;
  user-select: none;
}

.replace-tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(21, 38, 58, 0.08);
}

.replace-resize-hint {
  font-size: 0.76rem;
}

.replace-textarea {
  width: 100%;
  height: calc(100% - 28px);
  min-height: 24px;
  padding: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  color: inherit;
}

.selection-box {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(217, 72, 65, 0.12);
  pointer-events: none;
}

.replace-help {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-top: 18px;
}

.editor-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 1024px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .thumbnail-panel,
  .viewer-panel {
    min-height: 0;
  }

  .thumbnail-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

@media (max-width: 768px) {
  .editor-intro,
  .editor-app {
    padding: 22px;
  }

  .editor-intro,
  .editor-toolbar,
  .editor-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .security-banner {
    min-width: 0;
  }

  .toolbar-group {
    width: 100%;
  }

  .editor-input {
    min-width: 0;
    width: 100%;
  }
}
