.edit-pdf-page {
  --edit-yellow: #ffd700;
}

.edit-pdf-dropzone.is-dragging > div {
  border-color: #111827;
  background: #fffef2;
}

.edit-pdf-divider {
  width: 1px;
  height: 2rem;
  background: #e5e7eb;
}

.edit-pdf-icon-button,
.edit-pdf-secondary-button,
.edit-pdf-primary-button {
  min-height: 44px;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 800;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.edit-pdf-icon-button {
  width: 44px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #111827;
}

.edit-pdf-secondary-button {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #111827;
  padding: 0.55rem 0.8rem;
}

.edit-pdf-primary-button {
  border: 1px solid var(--edit-yellow);
  background: var(--edit-yellow);
  color: #000;
  padding: 0.6rem 1rem;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 900;
  text-decoration: none;
}

.edit-pdf-icon-button:hover,
.edit-pdf-secondary-button:hover,
.edit-pdf-icon-button:focus-visible,
.edit-pdf-secondary-button:focus-visible {
  border-color: #111827;
  background: #fffef2;
}

.edit-pdf-primary-button:hover,
.edit-pdf-primary-button:focus-visible {
  background: #f1ca00;
}

.edit-pdf-icon-button:disabled,
.edit-pdf-secondary-button:disabled,
.edit-pdf-primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.edit-pdf-icon-button:focus-visible,
.edit-pdf-secondary-button:focus-visible,
.edit-pdf-primary-button:focus-visible,
.edit-pdf-tool-button:focus-visible,
.edit-pdf-page-card:focus-visible {
  outline: 3px solid #111827;
  outline-offset: 2px;
}

.edit-pdf-zoom-label {
  min-width: 2.5rem;
  text-align: center;
  color: #374151;
  font-size: 0.75rem;
  font-weight: 800;
}

.edit-pdf-tool-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.edit-pdf-tool-button {
  min-height: 44px;
  padding: 0.45rem 0.72rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #fff;
  color: #111827;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.edit-pdf-tool-button .material-symbols-outlined {
  font-size: 1.15rem;
}

.edit-pdf-tool-button:hover {
  border-color: #9ca3af;
}

.edit-pdf-tool-button.is-active,
.edit-pdf-tool-button[aria-pressed="true"] {
  border: 2px solid var(--edit-yellow);
  background: #fff8d6;
  color: #111827;
  box-shadow: none;
}

.edit-pdf-shapes-control {
  position: relative;
  display: inline-flex;
}

.edit-pdf-shapes-control > .edit-pdf-tool-button { gap: 0.25rem; }

.edit-pdf-tool-caret {
  font-size: 1rem !important;
  margin-left: 0.1rem;
}

.edit-pdf-shapes-picker {
  display: none;
  position: absolute;
  z-index: 20;
  left: 0;
  top: calc(100% + 0.35rem);
  min-width: 14rem;
  padding: 0.55rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 12px 30px rgba(17, 24, 39, 0.15);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

#edit-pdf-shapes-toggle[aria-expanded="true"] + .edit-pdf-shapes-picker { display: grid; }

.edit-pdf-shapes-picker .edit-pdf-tool-button {
  justify-content: flex-start;
  white-space: nowrap;
}

.edit-pdf-inspector {
  min-height: 2.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: #fffdf4;
  border: 1px solid #f3e6a3;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
}

.edit-pdf-inspector:empty {
  display: none;
}

.edit-pdf-control {
  min-width: 8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.edit-pdf-control > span,
.edit-pdf-control-label {
  color: #4b5563;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.edit-pdf-control input:not([type="color"]),
.edit-pdf-control select,
.edit-pdf-control textarea {
  min-height: 40px;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  background: #fff;
  padding: 0.5rem 0.65rem;
  color: #111827;
  font-size: 0.875rem;
}

.edit-pdf-control textarea {
  min-width: min(24rem, 70vw);
  min-height: 2.5rem;
  resize: vertical;
}

.edit-pdf-control input[type="color"] {
  width: 3rem;
  height: 2.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  background: #fff;
  padding: 0.2rem;
}

.edit-pdf-control input[type="range"] {
  min-height: 40px;
  accent-color: #111827;
}

.edit-pdf-control-check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.25rem;
  color: #111827;
  font-size: 0.8rem;
  font-weight: 700;
}

.edit-pdf-control-check input {
  width: 1rem;
  height: 1rem;
  accent-color: #ffd700 !important;
}

.edit-pdf-canvas-scroll {
  width: 100%;
  overflow: auto;
  max-height: min(74vh, 980px);
  padding: 0.5rem;
}

.edit-pdf-page-wrap {
  position: relative;
  margin: 0 auto;
  width: fit-content;
  min-width: 0;
  max-width: none;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.16);
  line-height: 0;
  touch-action: manipulation;
}

.edit-pdf-page-wrap canvas {
  display: block;
  max-width: none;
  /* PDF.js sets both dimensions. The canvas, SVG and caret must share them. */
}

.edit-pdf-overlay {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: none;
}

.edit-pdf-overlay.is-drawing {
  cursor: crosshair;
}

.edit-pdf-overlay.is-text {
  cursor: text;
}

.edit-pdf-overlay .edit-pdf-annotation {
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}

.edit-pdf-overlay .edit-pdf-text-region {
  fill: rgba(255, 215, 0, 0.1);
  stroke: rgba(17, 24, 39, 0.2);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: text;
}

.edit-pdf-overlay .edit-pdf-text-region:hover,
.edit-pdf-overlay .edit-pdf-text-region.is-selected {
  fill: rgba(255, 215, 0, 0.28);
  stroke: #111827;
}

.edit-pdf-overlay .edit-pdf-annotation.is-selected {
  stroke: #111827 !important;
  stroke-width: 2.5px !important;
}

.edit-pdf-page-navigation .material-symbols-outlined {
  font-size: 1.15rem;
}

.edit-pdf-workspace {
  display: grid;
  grid-template-columns: minmax(12rem, 14rem) minmax(0, 1fr);
  align-items: start;
  gap: 0.75rem;
}

.edit-pdf-page-sidebar {
  position: sticky;
  top: 0.75rem;
  min-width: 0;
}

.edit-pdf-pages-toggle { display: none; }
.edit-pdf-pages-close { display: none; }

.edit-pdf-pages-panel {
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  background: #fff;
}

.edit-pdf-pages-header { align-items: baseline; }
.edit-pdf-pages-header p { margin: 0; }

.edit-pdf-inspector-actions {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid #e5e7eb;
}

.edit-pdf-inspector-actions .edit-pdf-secondary-button {
  min-height: 36px;
  padding: 0.4rem 0.6rem;
  font-size: 0.72rem;
}

.edit-pdf-geometry-grid {
  display: grid;
  flex: 1 1 100%;
  grid-template-columns: repeat(4, minmax(4.25rem, 1fr));
  gap: 0.5rem;
}

.edit-pdf-geometry-control,
.edit-pdf-fill-control { min-width: 0; }

.edit-pdf-page-input-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #4b5563;
  font-size: 0.8rem;
  font-weight: 800;
}

.edit-pdf-page-input-label input {
  width: 4.25rem;
  min-height: 40px;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  background: #fff;
  padding: 0.4rem;
  text-align: center;
  color: #111827;
}

.edit-pdf-page-rail {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
  max-height: min(72vh, 860px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0.15rem 0.5rem;
  list-style: none;
  scroll-snap-type: y proximity;
}

.edit-pdf-page-card-wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding: 0;
  list-style: none;
}

.edit-pdf-page-select {
  width: 100%;
  min-height: 5.4rem;
  padding: 0.45rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #fff;
  color: #111827;
  text-align: left;
  display: grid;
  grid-template-columns: 3.7rem minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem;
  scroll-snap-align: start;
}

.edit-pdf-page-select.is-current {
  border-color: var(--edit-yellow);
  background: #fffdf0;
  box-shadow: none;
}

.edit-pdf-page-card-wrap[draggable="true"] {
  cursor: grab;
}

.edit-pdf-page-card-wrap.is-dragging {
  opacity: 0.45;
}

.edit-pdf-page-card-wrap.is-drop-target .edit-pdf-page-select {
  border-color: #111827;
  background: #fffef2;
}

.edit-pdf-page-thumb {
  display: block;
  width: 3.7rem;
  aspect-ratio: 0.72;
  height: 4.8rem;
  max-height: 4.8rem;
  object-fit: contain;
  border: 1px solid #f3f4f6;
  background: linear-gradient(180deg, #fff 0 22%, #f3f4f6 22% 24%, #fff 24% 42%, #f3f4f6 42% 44%, #fff 44% 100%);
  margin-bottom: 0.35rem;
}

.edit-pdf-page-select.is-current .edit-pdf-page-thumb {
  border-color: #d1d5db;
}

.edit-pdf-page-number {
  font-size: 0.72rem;
  font-weight: 900;
}

.edit-pdf-page-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.1rem;
  margin-top: 0.15rem;
}

.edit-pdf-page-action {
  min-width: 25px;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0.25rem;
  background: transparent;
  color: #4b5563;
}

.edit-pdf-page-action:hover,
.edit-pdf-page-action:focus-visible {
  background: #fff3a6;
  color: #111827;
}

.edit-pdf-page-action .material-symbols-outlined {
  font-size: 1rem;
}

.edit-pdf-alert {
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  background: #fff;
  padding: 0.75rem 1rem;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.5;
}

.edit-pdf-inspector-help,
.edit-pdf-inspector-note {
  flex: 1 1 100%;
  margin: 0;
  color: #4b5563;
  font-size: 0.75rem;
  line-height: 1.45;
}

.edit-pdf-inspector-note {
  padding: 0.25rem 0;
  border: 0;
  background: transparent;
}

.edit-pdf-text-input {
  flex: 1 1 14rem;
}

.edit-pdf-image-status {
  align-self: center;
  color: #16803c;
  font-size: 0.75rem;
  font-weight: 800;
}

.edit-pdf-export-panel.is-success #edit-pdf-export-indicator {
  color: #16803c;
}

.edit-pdf-export-panel.is-failure #edit-pdf-export-indicator {
  color: #ba1a1a;
}

@media (max-width: 767px) {
  .edit-pdf-workspace { grid-template-columns: minmax(0, 1fr); }

  .edit-pdf-page-sidebar {
    position: relative;
    top: auto;
    z-index: 25;
  }

  .edit-pdf-pages-toggle {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #fff;
    color: #111827;
    font-size: 0.8rem;
    font-weight: 800;
  }

  .edit-pdf-pages-panel {
    position: fixed;
    z-index: 60;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 21rem);
    padding: 1rem 0.8rem;
    border-radius: 0;
    border-left: 0;
    border-top: 0;
    border-bottom: 0;
    box-shadow: 0.8rem 0 2rem rgba(17, 24, 39, 0.16);
    overflow: auto;
    visibility: hidden;
    transform: translateX(-105%);
    transition: transform 0.18s ease, visibility 0.18s ease;
  }

  .edit-pdf-pages-close {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 0.45rem 0.7rem;
    border: 1px solid #d1d5db;
    border-radius: 0.45rem;
    background: #fff;
    color: #111827;
    font-size: 0.75rem;
    font-weight: 800;
  }

  #edit-pdf-pages-toggle[aria-expanded="true"] + .edit-pdf-pages-panel {
    visibility: visible;
    transform: translateX(0);
  }

  .edit-pdf-page-rail { max-height: calc(100vh - 10rem); }
}

.edit-pdf-spinner {
  animation: edit-pdf-spin 1s linear infinite;
}

@keyframes edit-pdf-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .edit-pdf-shapes-picker {
    left: auto;
    right: 0;
  }

  .edit-pdf-heading {
    margin-bottom: 1rem;
  }

  .edit-pdf-topbar {
    gap: 0.5rem;
  }

  .edit-pdf-topbar .edit-pdf-file-summary {
    flex: 1 0 100%;
    width: 100%;
  }

  .edit-pdf-divider {
    display: none;
  }

  .edit-pdf-tool-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .edit-pdf-tool-button {
    min-width: 0;
    padding-inline: 0.35rem;
    white-space: normal;
    flex-direction: column;
    gap: 0.1rem;
    text-align: center;
    font-size: 0.66rem;
  }

  .edit-pdf-inspector {
    align-items: stretch;
    gap: 0.55rem;
  }

  .edit-pdf-control {
    flex: 1 1 8rem;
  }

  .edit-pdf-canvas-scroll {
    max-height: 68vh;
    padding: 0.25rem;
  }

  .edit-pdf-page-wrap {
    min-width: 0;
    max-width: none;
  }

  .edit-pdf-page-wrap canvas {
    max-width: none;
  }

  .edit-pdf-page-navigation { gap: 0.25rem; }
  .edit-pdf-page-navigation .edit-pdf-secondary-button { padding-inline: 0.45rem; }
  .edit-pdf-geometry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .edit-pdf-spinner {
    animation-duration: 2.5s;
  }
  .edit-pdf-icon-button,
  .edit-pdf-secondary-button,
  .edit-pdf-primary-button {
    transition: none;
  }
}

/* The live text surface uses document points; its matrix follows the PDF viewport. */
.edit-pdf-inline-editor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  box-sizing: border-box;
  transform-origin: 0 0;
  border: 0;
  outline: 1px solid #d9af00;
  outline-offset: 1px;
  padding: 0;
  margin: 0;
  min-width: 1px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  overflow: visible;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
}
.edit-pdf-inline-editor.is-overflowing,
.edit-pdf-inline-editor.has-save-error { outline-color: #b91c1c; }
.edit-pdf-overlay text { stroke: none !important; stroke-width: 0 !important; }

.edit-pdf-inline-mask {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  transform-origin: 0 0;
  pointer-events: none;
}

.edit-pdf-text-formatting {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.65rem;
  width: 100%;
}
.edit-pdf-text-formatting .edit-pdf-control { flex: 0 1 6rem; min-width: 4.5rem; }
.edit-pdf-source-font {
  align-self: center;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: #374151;
}
.edit-pdf-text-formatting .is-active {
  background: #fff8cc;
  border-color: #ffd700;
  box-shadow: inset 0 0 0 1px #ffd700;
}
.edit-pdf-text-formatting button[aria-label="Bold"] { font-weight: 800; }
.edit-pdf-text-formatting button[aria-label="Italic"] { font-style: italic; }
.edit-pdf-text-formatting button[aria-label="Underline"] { text-decoration: underline; }
