:root {
  --toolbar-height: 45px;
  --secondary-toolbar-height: 40px;
}

html,
body {
  height: 100%;
}

body:has(#pdfEditorApp) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body:has(#pdfEditorApp) footer {
  display: none;
}

body:has(#pdfEditorApp) main.container-fullwidth {
  flex: 1;
  min-height: 0;
  height: auto;
}

/* Scoped reset for editor so global site styles don't leak in */
.pdf-editor-page,
.pdf-editor-page * {
  /* Reset previous style to apply only editor one */
  box-sizing: border-box;
}

.pdf-editor-page {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  color: #2b2b2b;
  /* Match secondary toolbar strip so no background flash when it fades in */
  background: linear-gradient(
    180deg,
    #f8f8f8 0,
    #f8f8f8 calc(var(--toolbar-height) + var(--secondary-toolbar-height)),
    #f5f5f5 calc(var(--toolbar-height) + var(--secondary-toolbar-height))
  );
  overflow-y: hidden; /* Keep vertical overflow hidden */
  overflow-x: hidden; /* Prevent horizontal scrollbar from sidebar toggle */
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: #f5f5f5;
}

/* Editor page only: full-width main so editor fills the viewport */
body:has(#pdfEditorApp) main.container-fullwidth {
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: none;
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
  background: #e5e5e5;
}

.pdf-editor-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  height: 100%;
}

.pdf-editor-page
  :where(h1, h2, h3, h4, h5, h6, p, ul, ol, li, figure, blockquote) {
  margin: 0;
  padding: 0;
}

.pdf-editor-page :where(ul, ol) {
  list-style: none;
}

.pdf-editor-page :where(a) {
  color: inherit;
  text-decoration: none;
}

.pdf-editor-page :where(button, input, select, textarea) {
  font: inherit;
  color: inherit;
  margin: 0;
  border-radius: 0;
  outline: none;
}

.pdf-editor-page :where(button) {
  background: none;
  border: none;
}

.pdf-editor-page
  :where(.fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands) {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  line-height: 1;
}

.pdf-editor-page :where(.fa, .fas, .fa-solid) {
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
}

.pdf-editor-page :where(.far, .fa-regular) {
  font-family: 'Font Awesome 6 Free';
  font-weight: 400;
}

.pdf-editor-page :where(.fab, .fa-brands) {
  font-family: 'Font Awesome 6 Brands';
  font-weight: 400;
}

/* Word-like Toolbar */
.editor-toolbar {
  background: #f3f3f3;
  border-bottom: 1px solid #d0d0d0;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  flex-shrink: 0; /* Prevent toolbar from shrinking */
}

.toolbar-group {
  display: flex;
  gap: 4px;
  padding: 0 8px;
  align-items: center;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: #d0d0d0;
  flex-shrink: 0;
  margin: 0 2px;
}

.toolbar-control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-control-group input {
  height: 32px;
}

.toolbar-label-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: #555;
  cursor: default;
  border-radius: 4px;
  transition: background-color 0.2s;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  pointer-events: none;
}

.toolbar-label-icon:hover {
  background-color: #f0f0f0;
}

.toolbar-label-icon i {
  font-size: 14px;
}

.toolbar-select,
.toolbar-input {
  padding: 6px 8px;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  min-width: 120px;
  height: 32px;
  font-family: inherit;
}

.toolbar-select:focus,
.toolbar-input:focus {
  outline: none;
  border-color: #0078d4;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.1);
}

.toolbar-input {
  width: 44px;
  min-width: 44px;
}

.toolbar-input-narrow {
  width: 38px;
  min-width: 38px;
  text-align: center;
}

.toolbar-color-input {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  cursor: pointer;
  background: #fff;
}

.toolbar-color-input:hover {
  border-color: #0078d4;
}

.toolbar-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.toolbar-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.toolbar-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 13px;
  color: #333;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

/* Disable transition on mode buttons for instant updates */
.toolbar-btn.mode-btn {
  transition: none;
  transform: none;
}

.toolbar-btn:hover:not(:disabled) {
  background: #e8e8e8;
  border-color: #d0d0d0;
  transform: none;
}

.toolbar-btn.mode-btn:hover:not(:disabled) {
  transform: none;
}

.toolbar-btn {
  transform: none;
}

.toolbar-btn:hover:not(:disabled) {
  transform: none;
}

.toolbar-btn:disabled,
.toolbar-btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.toolbar-group.mode-group .toolbar-btn.mode-btn:disabled,
.toolbar-group.mode-group .toolbar-btn.mode-btn[aria-disabled='true'] {
  opacity: 1;
  background: var(--item-bg) !important;
  color: var(--muted-text) !important;
  border-color: var(--border-color) !important;
  box-shadow: none !important;
  transform: none !important;
  font-weight: 500;
  opacity: 0.6;
}

.toolbar-btn.active {
  background: var(--primary-blue-hover) !important;
  border-color: var(--primary-blue) !important;
  color: var(--text-color) !important;
}

.toolbar-caret {
  margin-left: 6px;
  font-size: 10px;
}

.toolbar-dropdown {
  position: relative;
}

.toolbar-btn.icon-only {
  min-width: 36px;
  padding: 6px;
  gap: 4px;
  justify-content: center;
}

.format-group {
  gap: 4px;
  position: relative;
}

.toolbar-group.add-tools-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toolbar-btn.add-tool-btn.icon-only {
  min-width: 40px;
  min-height: 40px;
  padding: 8px;
  justify-content: center;
  align-items: center;
}

.toolbar-btn.add-tool-btn.icon-only .fa,
.toolbar-btn.add-tool-btn.icon-only .fas,
.toolbar-btn.add-tool-btn.icon-only .far {
  margin: 0;
  font-size: 1.1em;
}

.toolbar-btn.add-tool-btn.active {
  background: var(--primary-blue-hover) !important;
  border-color: var(--primary-blue) !important;
  color: var(--text-color) !important;
}

.toolbar-group.mode-group {
  padding: 2px;
  overflow: visible;
  margin: 0 6px;
  display: flex;
  gap: 0;
  flex: 0 0 auto;
  background: var(--container-bg) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.toolbar-group.mode-group:first-child {
  border-radius: 999px;
}

.toolbar-group.mode-group:last-child {
  border-radius: 999px;
}

.toolbar-btn.mode-btn {
  border: none !important;
  box-shadow: none !important;
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  white-space: nowrap;
  justify-content: center;
  margin: 1px 0 0 0;
  padding: 6px 12px;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.toolbar-btn.mode-btn:first-child {
  border-radius: 999px 6px 6px 999px;
}

.toolbar-btn.mode-btn:last-child {
  border-radius: 6px 999px 999px 6px;
}

/* Use CSS attribute selector for real-time updates - CSS responds immediately to aria-pressed */
/* Higher specificity to ensure these rules apply */
.toolbar-group.mode-group .toolbar-btn.mode-btn[aria-pressed='true'],
.toolbar-group.mode-group .toolbar-btn.mode-btn.active {
  background: var(--primary-blue) !important;
  color: #ffffff !important;
  z-index: 1;
  font-weight: 600;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    0 2px 6px rgba(0, 0, 0, 0.12);
  transform: translateY(-1px);
  pointer-events: none;
  cursor: default;
}

.toolbar-group.mode-group .toolbar-btn.mode-btn[aria-pressed='true'] i,
.toolbar-group.mode-group .toolbar-btn.mode-btn.active i {
  color: inherit;
}

.toolbar-group.mode-group .toolbar-btn.mode-btn {
  background: var(--container-bg) !important;
  color: var(--text-color) !important;
}

.toolbar-group.mode-group
  .toolbar-btn.mode-btn[aria-pressed='false']:not(.active),
.toolbar-group.mode-group
  .toolbar-btn.mode-btn:not([aria-pressed='true']):not(.active) {
  background: var(--container-bg) !important;
  color: var(--text-color) !important;
}

.toolbar-group.mode-group .toolbar-btn.mode-btn[aria-pressed='true']:hover,
.toolbar-group.mode-group .toolbar-btn.mode-btn.active:hover {
  background: var(--primary-blue-hover) !important;
}

/* Keep hover simple for mode tabs */
.toolbar-group.mode-group
  .toolbar-btn.mode-btn[aria-pressed='false']:hover:not(.active),
.toolbar-group.mode-group
  .toolbar-btn.mode-btn:not(.active):hover:not([aria-pressed='true']) {
  background: var(--item-hover-bg) !important;
  color: var(--text-color) !important;
  transform: none;
}

/* Edit mode text blocks */
.text-block-edit {
  position: absolute;
  border: 1px dashed transparent;
  background: transparent;
  cursor: move;
  pointer-events: all;
  z-index: 10;
  opacity: 0;
  transition:
    opacity 0.15s ease,
    border-color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}

/* Disable pointer events for edited blocks - they use pdf-element instead */
.text-block-edit--edited {
  pointer-events: none !important;
}

.text-block-edit--visible,
.text-block-edit--edited {
  opacity: 1;
}

.text-block-edit--visible,
.text-block-edit--selected {
  border-color: #0078d4;
  background: rgba(0, 120, 212, 0.1);
}

.text-block-edit--selected {
  border-style: dashed;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
}

.text-block-edit--edited:not(.text-block-edit--selected):not(
    .text-block-edit--hover
  ) {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.text-block-edit__content {
  width: 100%;
  height: 100%;
  padding: 2px;
  white-space: pre-wrap;
  word-break: break-word;
  color: inherit;
  font: inherit;
  pointer-events: none;
  opacity: 0;
}

/* When overlay is visible (hover/selected), receive clicks on content so one click selects the block */
.text-block-edit--visible .text-block-edit__content,
.text-block-edit--selected .text-block-edit__content,
.text-block-edit--hover .text-block-edit__content {
  pointer-events: auto;
}

.text-block-edit--edited .text-block-edit__content {
  opacity: 1;
}

.text-block-edit__controls {
  position: absolute;
  top: -32px;
  right: 0;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #ffffff;
  border: 1px solid #0078d4;
  border-radius: 6px 6px 0 0;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.15s ease;
  transform: translateY(4px);
  z-index: 12;
  user-select: none;
}

.text-block-edit--selected .text-block-edit__controls,
.text-block-edit--hover .text-block-edit__controls {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.text-block-edit__btn {
  border: 1px solid transparent !important;
  background: #ffffff !important;
  color: #333 !important;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
  user-select: none;
  font-size: 12px;
  padding: 12px 12px;
}

.text-block-edit__btn:hover:not(:disabled) {
  background: #eef5ff !important;
  border-color: #0078d4 !important;
  color: #0078d4 !important;
}

.text-block-edit__btn:disabled,
.text-block-edit__btn[aria-disabled='true'] {
  opacity: 0.4;
  cursor: not-allowed;
}

.text-block-edit__handle {
  position: absolute;
  width: 12px;
  height: 12px;
  right: -6px;
  bottom: -6px;
  border-radius: 3px;
  border: 2px solid #0078d4;
  background: #fff;
  cursor: nwse-resize;
  display: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 5;
}

.text-block-edit--selected .text-block-edit__handle {
  display: block;
}

.text-block-edit--visible:hover,
.text-block-edit--hover {
  background: rgba(0, 120, 212, 0.05);
  border-color: #0078d4;
}

/* Inline editor - appears directly in place of text; size matches element box exactly */
.inline-editor {
  position: absolute;
  z-index: 1000;
  background-color: transparent;
  border: 1px solid #0078d4;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}

.inline-editor-content {
  outline: none;
  border: none;
  width: 100%;
  min-height: 1em;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  resize: none;
  overflow: visible;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Element text box editor: content must not be constrained so line-height and height apply correctly */
.inline-editor[data-element-id] .inline-editor-content {
  min-height: 0;
  white-space: pre-line;
}

.inline-editor-confirm {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid #0078d4;
  background: #fff;
  color: #0078d4;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.inline-editor-confirm:hover {
  background: #e6f2fb;
}

.element-controls .confirm-btn {
  background: #fff;
  color: #0078d4;
  border: 1px solid #0078d4;
}

.element-controls .confirm-btn:hover {
  background: #e6f2fb;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.panel-section:last-child {
  margin-bottom: 0;
}

.panel-section label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
}

.panel-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-section select,
.panel-section input[type='number'],
.panel-section input[type='color'] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  font-size: 13px;
}

.panel-section input[type='color'] {
  padding: 0;
  height: 34px;
}

.unit-label {
  font-size: 12px;
  color: #666;
}

.toolbar-btn i {
  font-size: 14px;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-slider-inline {
  width: 120px;
  height: 6px;
  margin: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 999px;
  background: linear-gradient(90deg, #0078d4, #33a0ff);
  outline: none;
}

.zoom-slider-inline::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0078d4;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.zoom-slider-inline::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0078d4;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.zoom-percentage-inline {
  min-width: 45px;
  text-align: center;
  font-size: 13px;
  color: #333;
  font-weight: 500;
}

.zoom-dropdown {
  position: relative;
}

.zoom-toggle {
  padding: 6px;
  justify-content: center;
}

.zoom-panel,
.more-panel,
.toolbar-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 12px;
  min-width: 260px;
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.12),
    0 2px 6px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  pointer-events: none;
  background-clip: padding-box;
  z-index: 1100;
}

.zoom-panel {
  right: 0;
}

.more-panel {
  left: 0;
}

.toolbar-dropdown-panel {
  left: 0;
  min-width: 200px;
}

.dropdown-item {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border-radius: 4px;
  color: #333;
  transition: background 0.15s ease;
  margin-bottom: 4px;
}

.dropdown-item:last-child {
  margin-bottom: 0;
}

.dropdown-item + .dropdown-item {
  margin-top: 4px;
}

.dropdown-item i {
  width: 14px;
  text-align: center;
}

.dropdown-item:hover:not(:disabled) {
  background: #eef5fb;
}

.dropdown-item:disabled,
.dropdown-item[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}

.dropdown-separator {
  height: 1px;
  background: #e0e0e0;
  margin: 6px 0;
}

.file-menu input[type='file'] {
  display: none;
}

.zoom-dropdown.open .zoom-panel,
.format-group.open .more-panel,
.toolbar-dropdown.open .toolbar-dropdown-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.zoom-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-step-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #c7c7c7;
  border-radius: 4px;
  background: #fff;
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.zoom-step-btn:hover {
  background: #e8f4ff;
  border-color: #7ab6ff;
}

#zoomSlider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #0078d4, #33a0ff);
  outline: none;
}

#zoomSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0078d4;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

#zoomSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0078d4;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.zoom-panel-footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.zoom-percentage {
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.zoom-reset-btn {
  border: none;
  background: #0078d4;
  color: #fff;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.zoom-reset-btn:hover {
  background: #106ebe;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: #d0d0d0;
  margin: 0 4px;
}

/* Secondary Toolbar - transition matches show/hide animation so page resizing is smooth */
.editor-secondary-toolbar {
  background: #f8f8f8;
  border-bottom: 1px solid #d0d0d0;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  z-index: 999;
  position: relative;
  flex-shrink: 0;
  max-height: 80px;
  overflow: hidden;
  transition:
    max-height 0.28s cubic-bezier(0.33, 1, 0.68, 1),
    padding 0.28s cubic-bezier(0.33, 1, 0.68, 1),
    border-bottom-width 0.28s ease,
    box-shadow 0.28s ease;
  contain: layout style;
}

@keyframes secondary-toolbar-fade-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes secondary-toolbar-fade-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.editor-secondary-toolbar.secondary-toolbar-visible {
  animation: secondary-toolbar-fade-in 0.28s cubic-bezier(0.33, 1, 0.68, 1)
    forwards;
}

.editor-secondary-toolbar.secondary-toolbar-hiding {
  animation: secondary-toolbar-fade-out 0.26s cubic-bezier(0.32, 0.72, 0.46, 1)
    forwards;
}

/* Collapsed state: smooth height transition so page resizing matches toolbar show/hide */
.editor-secondary-toolbar.secondary-toolbar-collapsed {
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-bottom-width: 0 !important;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
  transition:
    max-height 0.26s cubic-bezier(0.32, 0.72, 0.46, 1),
    padding 0.26s cubic-bezier(0.32, 0.72, 0.46, 1),
    border-bottom-width 0.26s ease,
    box-shadow 0.26s ease;
}

/* When using [hidden] (e.g. initial load), keep same collapsed appearance */
.editor-secondary-toolbar[hidden] {
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-bottom-width: 0 !important;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
}

.secondary-toolbar-panel[hidden] {
  display: none !important;
}

.secondary-toolbar-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-text-input-group {
  min-width: 140px;
}

.toolbar-text-input-group .toolbar-label-text {
  white-space: nowrap;
  margin-right: 4px;
  font-size: 13px;
  color: #555;
}

.toolbar-text-input {
  min-width: 120px;
  max-width: 200px;
}

.toolbar-signature-draw-group[hidden] {
  display: none !important;
}

/* Draw Signature Modal */
.draw-signature-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  padding: 16px;
}

.draw-signature-modal[hidden] {
  display: none !important;
}

.draw-signature-modal-content {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 560px;
  width: 100%;
  overflow: hidden;
}

.draw-signature-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
}

.draw-signature-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.draw-signature-modal-close {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #666;
  border-radius: 4px;
}

.draw-signature-modal-close:hover {
  background: #f0f0f0;
  color: #333;
}

.draw-signature-modal-body {
  padding: 16px;
}

.draw-signature-canvas-wrapper {
  border: 1px solid var(--border-color, #d0d0d0);
  border-radius: var(--radius-medium, 6px);
  background-color: var(--input-bg, #fff);
  background-image:
    linear-gradient(45deg, var(--card-bg, #f5f5f5) 25%, transparent 25%),
    linear-gradient(-45deg, var(--card-bg, #f5f5f5) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--card-bg, #f5f5f5) 75%),
    linear-gradient(-45deg, transparent 75%, var(--card-bg, #f5f5f5) 75%);
  background-size: 12px 12px;
  background-position:
    0 0,
    0 6px,
    6px -6px,
    -6px 0px;
  margin-bottom: 12px;
  overflow: hidden;
}

.draw-signature-canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
  background: transparent;
}

.draw-signature-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.draw-signature-stroke-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.draw-signature-stroke-label {
  font-size: 13px;
  font-weight: 500;
}

.draw-signature-stroke-row-with-clear {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.draw-signature-stroke-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.draw-signature-stroke-slider {
  width: 180px;
  height: 24px;
  accent-color: var(--primary-blue, #0078d4);
}

.draw-signature-stroke-preview {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color, #d0d0d0);
  border-radius: 50%;
  background: var(--input-bg, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.draw-signature-stroke-preview canvas {
  display: block;
  width: 32px;
  height: 32px;
}

.draw-signature-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, #f8f8f8);
}

.editor-secondary-toolbar .toolbar-group {
  padding-right: 8px;
  margin-right: 4px;
}

.toolbar-btn-add-another {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-left: 4px;
  color: #106ebe !important;
  background: rgba(16, 110, 190, 0.08) !important;
  border: 1px solid rgba(16, 110, 190, 0.35);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.toolbar-btn-add-another:hover {
  background: rgba(16, 110, 190, 0.14) !important;
  color: #0d5da3 !important;
  border-color: rgba(16, 110, 190, 0.5);
}

.toolbar-btn-add-another .toolbar-btn-add-another-label {
  white-space: nowrap;
}

.editor-secondary-toolbar .toolbar-separator {
  height: 20px;
  margin: 0 4px;
}

.draw-settings-inline,
.draw-settings {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
}

.draw-settings[hidden] {
  display: none !important;
}

.draw-settings-inline label,
.draw-settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.draw-settings-inline input,
.draw-settings input {
  pointer-events: auto;
}

.draw-settings-inline i,
.draw-settings i {
  color: #4a4a4a;
  pointer-events: none;
}

.toolbar-checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary-blue, #0078d4);
}

.secondary-toolbar-shapes .shapes-settings,
.secondary-toolbar-panel.secondary-toolbar-shapes {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.shape-type-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.shape-type-buttons .shape-type-btn {
  flex: 1 1 auto;
  min-width: 2em;
  max-width: 2.5em;
  height: 2em;
  font-size: 18px;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.shape-type-buttons .shape-type-btn:hover {
  border-radius: 999px;
}

.shape-type-buttons .shape-type-btn.active {
  border-radius: 999px;
  background: #e8e8e8 !important;
}

.shape-type-buttons .shape-type-btn.active:hover {
  background: #e0e0e0 !important;
}

.secondary-toolbar-emoji .emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  align-content: flex-start;
}

.emoji-btn {
  flex: 1 1 auto;
  min-width: 2em;
  max-width: 2.5em;
  height: 2em;
  font-size: 18px;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.emoji-btn:hover {
  border-radius: 999px;
}

.text-box-controls .text-box-btn.rotate {
  display: inline-flex;
}

.draw-item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
}

.draw-item-controls input[type='range'] {
  width: 100px;
}

/* Main Editor Area */
.editor-container {
  display: flex;
  min-height: 0;
  flex: 1;
  height: auto;
  overflow: hidden; /* Prevent horizontal scrollbar from sidebar toggle */
  position: relative; /* Ensure absolute children are positioned relative to this */
  max-height: none;
  flex-shrink: 0; /* Prevent container from shrinking */
  background: #e5e5e5;
}

/* Dark theme support */
body.theme-dark .pdf-editor-page {
  background: var(--bg-dark);
  color: var(--text-color);
}

body.theme-dark .editor-container {
  background: var(--bg-dark);
}

body.theme-dark .editor-toolbar,
body.theme-dark .editor-secondary-toolbar {
  background: var(--container-bg);
  border-color: var(--border-color);
  box-shadow: none;
}

body.theme-dark .toolbar-btn-add-another {
  color: #5ba3e8 !important;
  background: rgba(91, 163, 232, 0.12) !important;
  border-color: rgba(91, 163, 232, 0.4);
}

body.theme-dark .toolbar-btn-add-another:hover {
  background: rgba(91, 163, 232, 0.2) !important;
  color: #7ab5f0 !important;
  border-color: rgba(91, 163, 232, 0.55);
}

body.theme-dark .pdf-editor-page {
  background: linear-gradient(
    180deg,
    var(--container-bg) 0,
    var(--container-bg)
      calc(var(--toolbar-height) + var(--secondary-toolbar-height)),
    var(--bg-dark) calc(var(--toolbar-height) + var(--secondary-toolbar-height))
  );
}

body.theme-dark .editor-main {
  background: var(--bg-dark);
}

body.theme-dark .editor-sidebar {
  background: var(--container-bg);
  border-color: var(--border-color);
}

body.theme-dark .toolbar-btn {
  color: var(--text-color);
}

body.theme-dark .toolbar-btn:hover:not(:disabled) {
  background: var(--item-hover-bg);
  border-color: var(--border-color);
}

body.theme-dark .toolbar-label-icon {
  color: var(--muted-text);
}

body.theme-dark .toolbar-label-icon:hover {
  background: var(--item-hover-bg);
}

body.theme-dark .toolbar-select,
body.theme-dark .toolbar-input {
  background: var(--input-bg);
  color: var(--text-color);
  border-color: var(--border-color);
}

body.theme-dark .toolbar-color-input {
  background: var(--input-bg);
  border-color: var(--border-color);
}

body.theme-dark .toolbar-color-input:hover {
  border-color: var(--primary-blue);
}

body.theme-dark .toolbar-select:focus,
body.theme-dark .toolbar-input:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px rgba(165, 180, 252, 0.2);
}

body.theme-dark .toolbar-group.mode-group {
  border-color: var(--primary-blue);
}

body.theme-dark
  .toolbar-group.mode-group
  .toolbar-btn.mode-btn[aria-pressed='true'],
body.theme-dark .toolbar-group.mode-group .toolbar-btn.mode-btn.active {
  background: var(--primary-blue);
  color: #fff;
}

body.theme-dark
  .toolbar-group.mode-group
  .toolbar-btn.mode-btn[aria-pressed='false']:not(.active),
body.theme-dark
  .toolbar-group.mode-group
  .toolbar-btn.mode-btn:not([aria-pressed='true']):not(.active) {
  background: var(--container-bg);
  color: var(--muted-text);
}

body.theme-dark .toolbar-dropdown-panel {
  background: var(--container-bg);
  border-color: var(--border-color);
}

body.theme-dark .dropdown-item {
  color: var(--text-color);
}

body.theme-dark .dropdown-item:hover:not(:disabled) {
  background: var(--item-hover-bg);
}

body.theme-dark .sidebar-section h4 {
  color: var(--muted-text);
}

body.theme-dark .sidebar-toggle {
  background: var(--container-bg) !important;
  color: var(--text-color) !important;
  border-color: var(--border-color) !important;
  box-shadow: var(--shadow-medium);
}

body.theme-dark .sidebar-toggle:hover {
  border-color: var(--primary-blue) !important;
}

body.theme-dark .text-box-item {
  background: var(--item-bg);
  border-color: var(--border-color);
  color: var(--text-color);
}

body.theme-dark .text-box-item:hover {
  background: var(--item-hover-bg);
  border-color: var(--primary-blue);
}

body.theme-dark .text-box-item.active {
  background: rgba(165, 180, 252, 0.18);
  border-color: var(--primary-blue);
}

body.theme-dark .text-box-type {
  background: rgba(165, 180, 252, 0.12);
  color: var(--text-color);
}

body.theme-dark .text-box-thumbnail,
body.theme-dark .text-box-item .text-box-thumbnail {
  color: #ffffff !important;
}

body.theme-dark .text-boxes-empty {
  color: var(--muted-text);
}

body.theme-dark .text-box-controls {
  background: var(--container-bg);
  border-color: var(--border-color);
}

body.theme-dark .text-box-btn {
  background: var(--container-bg) !important;
  color: var(--text-color) !important;
}

body.theme-dark .text-box-btn:hover {
  background: rgba(165, 180, 252, 0.2);
  border-color: var(--primary-blue);
  color: var(--primary-blue);
}

body.theme-dark .text-box-btn.remove:hover {
  background: rgba(229, 57, 53, 0.2);
  border-color: #e53935;
  color: #ff8a80;
}

.editor-sidebar {
  width: 320px; /* Increased base width */
  min-width: 320px; /* Increased minimum width */
  background: #fafafa;
  border-right: 1px solid #d0d0d0;
  padding: 16px;
  position: relative;
  transition: width 0.3s ease;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: visible; /* Allow toggle button to be visible outside sidebar */
  z-index: 10; /* Ensure sidebar is above editor-main but toggle button can overflow */
}

.editor-sidebar.collapsed {
  width: 0 !important; /* Force width to 0 when collapsed, override any dynamic width */
  min-width: 0 !important; /* Remove min-width when collapsed */
  padding: 0;
  overflow: visible; /* Allow toggle button to be visible */
}

/* Only the content section should scroll, not the sidebar itself */
.editor-sidebar .sidebar-section {
  overflow-x: hidden; /* Allow rotated content to extend horizontally */
  overflow-y: auto; /* Only the content section should scroll vertically */
  flex: 1;
  min-height: 0;
  /* Ensure section doesn't clip toggle button */
  clip-path: none;
  -webkit-clip-path: none;
}

.editor-sidebar.collapsed .sidebar-section {
  display: none;
}

.sidebar-toggle {
  position: absolute;
  right: -15px; /* Position 15px to the right of sidebar edge - half button extends outside */
  top: 8px;
  transform: none;
  width: 30px;
  height: 30px;
  background: #f5f5f5 !important;
  color: #4a4a4a !important;
  border: 1px solid #b0b0b0 !important;
  border-radius: 50%;
  cursor: pointer;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  z-index: 1001; /* Higher z-index to ensure visibility */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition:
    border-color 0.2s ease,
    background 0.2s ease;
  pointer-events: auto; /* Ensure it's clickable */
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: visible; /* Ensure button is fully visible */
  min-width: 30px; /* Prevent clipping */
  min-height: 30px;
}

.sidebar-toggle.visible {
  display: flex; /* Show when visible class is added */
}

.sidebar-toggle:hover {
  background: #f5f5f5 !important;
  border-color: #0078d4 !important;
}

.editor-sidebar.collapsed .sidebar-toggle {
  right: -15px; /* When collapsed, position outside the zero-width sidebar */
  /* Keep button visible when sidebar is collapsed */
}

/* When sidebar is not collapsed, ensure toggle button is fully visible */
.editor-sidebar:not(.collapsed) .sidebar-toggle {
  right: -15px;
  /* Button should extend 15px to the right of sidebar */
}

.sidebar-toggle i {
  font-size: 12px;
  transition: none;
  pointer-events: none; /* Prevent icon from blocking clicks */
}

.editor-sidebar.collapsed .sidebar-toggle i {
  transform: rotate(180deg);
}

/* Right Sidebar (Text Boxes) */
.editor-sidebar-right {
  border-right: none;
  border-left: 1px solid #d0d0d0;
  order: 3;
  overflow: visible;
}

.sidebar-toggle-right {
  left: -15px;
  right: auto;
}

.editor-sidebar-right.collapsed .sidebar-toggle-right {
  left: -15px;
}

/* Text Boxes Sidebar Content */
.text-box-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.text-box-item:hover {
  background: #f5f5f5;
  border-color: #0078d4;
}

.text-box-item.active {
  background: #e8f4f8;
  border-color: #0078d4;
}

.text-box-type {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #6b6f76;
  flex-shrink: 0;
}

.text-box-thumbnail {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px;
  max-width: 180px;
}

.text-box-controls {
  display: flex;
  gap: 1px;
  margin-left: auto;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #cfd8e3;
  padding: 1px;
}

.text-box-btn {
  width: 18px;
  height: 18px;
  border: 1px solid transparent !important;
  background: #ffffff !important;
  color: #4a4a4a !important;
  cursor: pointer;
  border-radius: 3px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
  font-size: 11px;
  padding: 14px 12px;
}

.text-box-btn:hover {
  background: #eef5ff;
  border-color: #0078d4;
  color: #0078d4;
}

.text-box-btn.remove:hover {
  background: #ffecec;
  border-color: #e53935;
  color: #c62828;
}

.text-boxes-empty {
  padding: 16px;
  text-align: center;
  color: #999;
  font-size: 13px;
}

/* Page thumbnail loading state */
.page-thumbnail.loading {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}

.page-thumbnail.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid #0078d4;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* No document: main area fills space and centers empty state. Has document: fills remaining space and scrolls. */
.editor-main {
  flex: 0 0 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  background: #e5e5e5;
  padding: 20px;
  padding-right: 12px; /* Add space for scrollbar */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  min-width: 0;
  position: relative;
  box-sizing: border-box;
  overflow-anchor: none;
  z-index: 1;
  width: 100%;
  align-self: stretch;
}

/* No document: grow to fill space and center the "No PDF loaded" zone */
.pdf-editor-page:not(.has-document) .editor-main {
  flex: 1;
  min-height: 0;
  justify-content: center;
  align-items: center;
}

.pdf-editor-page.has-document .editor-main {
  flex: 1;
  min-height: 0;
  max-height: 100%;
}

/* Ensure scrollbar is accessible and visible */
.editor-main::-webkit-scrollbar {
  width: 12px;
}

.editor-main::-webkit-scrollbar-track {
  background: #f1f1f1;
  margin-right: 0;
}

.editor-main::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 6px;
  border: 2px solid #e5e5e5; /* Add border to make it more visible */
}

.editor-main::-webkit-scrollbar-thumb:hover {
  background: #555;
}

#editorPages {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: auto; /* Don't force 100% height */
  flex: 1;
}

.editor-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(100%, 840px);
  max-width: 840px;
  min-height: 180px;
  padding: 40px 24px;
  color: #666;
  text-align: center;
  border: 2px dashed rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  transition:
    border-color 0.2s,
    background-color 0.2s;
}

.editor-empty--drag-over {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.06);
}

body.theme-dark .editor-empty--drag-over {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}

.editor-empty i {
  font-size: 64px;
  color: #ccc;
  margin-bottom: 16px;
}

.editor-empty h2 {
  margin-bottom: 8px;
  color: #333;
}

body.theme-dark .editor-empty {
  color: var(--muted-text);
  border-color: rgba(255, 255, 255, 0.2);
}

body.theme-dark .editor-empty h2 {
  color: #ffffff;
}

body.theme-dark .editor-empty i {
  color: var(--muted-text);
}

/* Debug PDF picker (only when app.settings.app.debug) */
.editor-debug-picker {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 480px;
}

body.theme-dark .editor-debug-picker {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.editor-debug-picker-label {
  font-size: 12px;
  color: #888;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

body.theme-dark .editor-debug-picker-label {
  color: var(--muted-text);
}

.editor-debug-picker-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.editor-debug-picker-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  min-width: 120px;
}

.editor-debug-picker-card:hover {
  border-color: #0078d4;
  box-shadow: 0 2px 8px rgba(0, 120, 212, 0.2);
}

body.theme-dark .editor-debug-picker-card {
  background: var(--panel-bg, #2d2d2d);
  border-color: rgba(255, 255, 255, 0.2);
}

body.theme-dark .editor-debug-picker-card:hover {
  border-color: #4da3ff;
  box-shadow: 0 2px 8px rgba(77, 163, 255, 0.25);
}

.editor-debug-picker-preview {
  display: block;
  width: 120px;
  height: auto;
  max-height: 155px;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
  margin-bottom: 8px;
}

body.theme-dark .editor-debug-picker-preview {
  background: #1e1e1e;
}

.editor-debug-picker-name {
  font-size: 12px;
  color: #333;
  word-break: break-all;
  text-align: center;
}

body.theme-dark .editor-debug-picker-name {
  color: var(--text-primary, #fff);
}

.editor-debug-picker-load {
  margin-top: 0;
}

.btn-primary {
  background: #0078d4;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  margin-top: 16px;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #106ebe;
}

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* PDF Page */
.pdf-page {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin: 0 auto 20px;
  position: relative;
  border: 1px solid #ddd;
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
}

.pdf-analysis-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.pdf-analysis-overlay--active {
  opacity: 1;
  pointer-events: auto;
}

.pdf-analysis-overlay__card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px rgba(15, 15, 15, 0.12);
  font-size: 14px;
  font-weight: 600;
  color: #1f2933;
}

.pdf-analysis-overlay__spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(31, 41, 51, 0.2);
  border-top-color: rgba(31, 41, 51, 0.8);
  border-radius: 50%;
  animation: pdf-analysis-spin 0.9s linear infinite;
}

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

/* Preparation progress: centered on current pdf-page, pill style */
.editor-prepare-progress {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 999px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
}

.editor-prepare-progress[hidden] {
  display: none;
}

.editor-prepare-progress__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.editor-prepare-progress__spinner {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  animation: pdf-analysis-spin 0.9s linear infinite;
}

.editor-prepare-progress__label {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  min-width: 0;
}

.editor-prepare-progress__bar {
  flex-shrink: 0;
  width: 100px;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.editor-prepare-progress__fill {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Editable Elements */
.pdf-element {
  position: absolute;
  cursor: move;
  border: 1px dashed rgba(0, 0, 0, 0.15);
  transition:
    border-color 0.15s,
    background-color 0.15s,
    box-shadow 0.15s;
  user-select: none;
  min-width: 24px;
  min-height: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4px;
  text-align: left;
  /* Disable transitions for position changes - instant movement */
  will-change: left, top;
  z-index: 15; /* Higher than text-block-edit (z-index: 10) to ensure controls are clickable */
}

/* Annotate-mode added text: above original PDF text (Edit mode layer text) */
.pdf-element.pdf-element-annotation-added {
  z-index: 25;
}

/* Image mask (white cover for erased image): match page background; below overlays; capture hover for default cursor */
.pdf-element.pdf-image-mask {
  z-index: 5;
  pointer-events: auto;
  cursor: default;
  background: #ffffff !important;
}

.pdf-element.pdf-emoji {
  min-width: 20px;
  min-height: 20px;
  padding: 0;
}

.pdf-element.dragging {
  transition: none;
}

.pdf-element.pdf-image {
  padding: 2px;
  box-sizing: border-box;
}

.pdf-element.pdf-element-original-image {
  background: transparent !important;
}

.pdf-element.pdf-image img,
.pdf-dragging-element.pdf-image-element img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  display: block;
}

.pdf-element:hover {
  background: rgba(0, 120, 212, 0.05);
  border: 1px dashed #0078d4;
}

.pdf-element.selected {
  background: rgba(0, 120, 212, 0.1);
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
  border: 1px dashed #0078d4;
  z-index: 500; /* Above other .pdf-elements so the control bar is clickable when another box is behind it */
}

/* When inline editor is open: raise element so resize handle and controls render on top; hide element text/box so only edit zone + handle + controls show (no double text) */
.pdf-element.inline-editing-active {
  z-index: 1001;
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  visibility: hidden;
}
.pdf-element.inline-editing-active .resize-handle,
.pdf-element.inline-editing-active .element-controls {
  visibility: visible;
  opacity: 1;
}

/* View/Annotate mode: hide original PDF editing only; added elements keep borders/hover/controls */
.pdf-view-mode .text-block-edit {
  border: none;
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.pdf-view-mode .text-block-edit__controls {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.pdf-element.dragging {
  opacity: 0.7;
  z-index: 1000;
}

.pdf-element.resizing {
  cursor: nwse-resize;
  user-select: none;
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  bottom: -6px;
  right: -6px;
  border: 2px solid #0078d4;
  background: #fff;
  border-radius: 3px;
  cursor: nwse-resize;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 1100;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none; /* Only active when element is selected */
}

.pdf-element.selected .resize-handle {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* Controls appear above the selected element only (not on hover) */
.element-controls {
  position: absolute;
  top: -29px;
  right: 0;
  background: #ffffff;
  border: 1px solid #0078d4;
  border-radius: 6px 6px 0 0;
  padding: 2px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 20;
  pointer-events: none;
}

.pdf-element.selected .element-controls {
  opacity: 1;
}

.element-controls button {
  pointer-events: auto;
  background: #ffffff !important;
  border: 1px solid transparent !important;
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #333 !important;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
  padding: 0;
}

.element-controls button:hover {
  background: #eef5ff !important;
  border-color: #0078d4 !important;
  color: #0078d4 !important;
}

/* Signature/Initials Styles */
.pdf-signature,
.pdf-initials {
  font-family: 'Dancing Script', 'Pacifico', 'Satisfy', cursive;
  white-space: nowrap;
}

.pdf-text {
  font-family: Arial, sans-serif;
  word-wrap: break-word;
  white-space: pre-wrap;
  pointer-events: auto;
}

/* Text wrapper so content wraps and respects box width (flex item needs min-width: 0 to shrink) */
.pdf-element.pdf-text .pdf-element-text {
  display: block;
  min-width: 0;
  width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  white-space: pre-wrap;
  overflow: hidden;
  box-sizing: border-box;
}

/* Layer text from PDF: distinctive style (original/unmodified) */
/* Layer text in Edit mode: use exact bbox size, no large min */
.pdf-element.pdf-element-layer {
  min-width: 0 !important;
  min-height: 0 !important;
}

.pdf-element.pdf-element-layer.pdf-element-original {
  border: 1px dashed rgba(0, 120, 212, 0.4);
  background: rgba(248, 249, 250, 0.6);
}
body.theme-dark .pdf-element.pdf-element-layer.pdf-element-original {
  border-color: rgba(100, 180, 255, 0.35);
  background: rgba(30, 35, 45, 0.5);
}

/* Original layer text/image in annotate mode: no visible box, plain text look */
.pdf-element.pdf-element-readonly-annotate {
  cursor: default;
  pointer-events: auto;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
}
.pdf-element.pdf-element-readonly-annotate:hover {
  background: transparent !important;
  border: none !important;
}

/* User-added elements in Edit mode: read-only (only original texts/images are editable) */
.pdf-element.pdf-element-readonly-edit {
  cursor: default;
  pointer-events: auto;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
}
.pdf-element.pdf-element-readonly-edit:hover {
  background: transparent !important;
  border: none !important;
}

/* Dragging element (follows mouse) */
.pdf-dragging-element {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  opacity: 0.85;
  transform: translate(-50%, -50%);
  border: 1px dashed #0078d4;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: crosshair;
  max-width: 300px;
  word-wrap: break-word;
  /* Disable transitions for instant movement */
  transition: none;
  will-change: left, top;
}

.pdf-dragging-element.pdf-image-element {
  padding: 4px;
  border-style: solid;
  background: rgba(255, 255, 255, 0.95);
  max-width: none;
}

/* Right-Click Context Menu */
.context-menu {
  position: fixed;
  background: white;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 10001;
  min-width: 180px;
  padding: 4px 0;
}

.context-menu-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #333;
  transition: background 0.15s;
}

.context-menu-item:hover {
  background: #f0f0f0;
}

.context-menu-item i {
  width: 18px;
  text-align: center;
  color: #666;
}

/* Configuration Modal */
.config-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.config-modal.active {
  display: flex;
}

.config-content {
  background: var(--container-bg, #fff);
  border-radius: var(--radius-medium, 4px);
  box-shadow: var(--shadow-strong, 0 4px 20px rgba(0, 0, 0, 0.3));
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.config-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.config-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--heading-color, #333);
}

.config-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted-text, #666);
  padding: 4px 8px;
}

.config-close:hover {
  color: var(--text-color, #333);
}

.config-body {
  padding: 20px;
  flex: 1;
}

/* Config Tabs */
.config-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color, #e0e0e0);
}

.config-tab {
  background: transparent;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted-text, #666);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  flex: 1 1 0;
  justify-content: center;
}

.config-tab:hover {
  color: var(--text-color, #333);
  background: var(--item-hover-bg, #f5f5f5);
}

.config-tab.active {
  color: var(--primary-blue, #0078d4);
  border-bottom-color: var(--primary-blue, #0078d4);
  font-weight: 500;
}

.config-tab-content {
  display: none;
}

.config-tab-content.active {
  display: block;
}

.config-preview {
  background: var(--card-bg, #f9f9f9);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: var(--radius-small, 4px);
  padding: 16px;
  margin-bottom: 20px;
}

.config-preview-label {
  font-size: 12px;
  color: var(--muted-text, #666);
  margin-bottom: 8px;
}

.config-preview-box {
  background: var(--input-bg, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: var(--radius-small, 4px);
  padding: 20px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-color, #333);
}

body.theme-dark .config-preview-label {
  color: var(--muted-text, #b8b8b8) !important;
}

body.theme-dark .config-preview-box {
  background: #f0f0f0 !important;
  color: #333 !important;
}

/* Add Signature / Add Initials modal tabs */
.add-signature-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color, #e0e0e0);
}

.add-signature-tab {
  background: transparent;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted-text, #666);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  flex: 1 1 0;
  justify-content: center;
}

.add-signature-tab:hover {
  color: var(--text-color, #333) !important;
  background: var(--item-hover-bg, #f0f0f0) !important;
}

.add-signature-tab.active {
  color: var(--primary-blue, #006cbd) !important;
  background: var(--accent-blue-light, #e8f4fc) !important;
  border-bottom-color: var(--primary-blue, #006cbd) !important;
  font-weight: 600 !important;
}

body.theme-dark .add-signature-tab.active {
  color: var(--primary-blue, #a1acf1) !important;
  background: rgba(161, 172, 241, 0.35) !important;
  border-bottom-color: var(--primary-blue, #a1acf1) !important;
  font-weight: 600 !important;
}

.add-signature-tab-content {
  display: none;
}

.add-signature-tab-content.active {
  display: block;
}

.add-signature-modal .config-content,
.add-initials-modal .config-content {
  max-width: 420px;
}

.signature-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.signature-mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}

.signature-mode-btn.active {
  background: #0078d4;
  color: white;
  border-color: #0078d4;
}

.signature-draw-options {
  border: 1px dashed #c7d3e3;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 16px;
  background: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.signature-draw-options[hidden] {
  display: none;
}

.signature-canvas-wrapper {
  border: 1px solid #d0dcea;
  border-radius: 6px;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
  background-size: 20px 20px;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
}

#signatureCanvas {
  width: 100%;
  height: 220px;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: transparent;
}

.signature-draw-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: space-between;
}

.signature-draw-toolbar label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: #333;
}

#signatureStrokeWidth {
  width: 180px;
}

.signature-clear-btn {
  border-color: #d93025;
  color: #d93025;
}

.signature-clear-btn:hover {
  background: rgba(217, 48, 37, 0.1);
}

.signature-help {
  font-size: 12px;
  color: var(--muted-text, #666);
}

.config-option {
  margin-bottom: 16px;
}

.config-option label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--heading-color, #333);
  margin-bottom: 6px;
}

.config-option input,
.config-option select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-color, #d0d0d0);
  border-radius: var(--radius-small, 3px);
  font-size: 14px;
  background: var(--input-bg, #fff);
  color: var(--text-color, #333);
}

.config-option input[type='color'] {
  height: 40px;
  cursor: pointer;
}

.config-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, transparent);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.config-footer-actions {
  display: flex;
  gap: 8px;
}

/* Editor confirm modal (reusable confirm/alert style) */
.editor-confirm-modal .editor-confirm-content {
  max-width: 400px;
}
.editor-confirm-message {
  margin: 0;
  font-size: 15px;
  color: var(--text-color, #333);
  line-height: 1.5;
}

/* Editor password modal (password-protected PDFs) */
.editor-password-modal .editor-password-content {
  max-width: 400px;
}
.editor-password-message {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--text-color, #333);
  line-height: 1.5;
}
.editor-password-error {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--error-color, #c00);
  line-height: 1.4;
}

/* Editor Download & Protect modal */
.editor-download-protect-modal .editor-download-protect-content {
  max-width: 420px;
}
.editor-download-protect-message {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--text-color, #333);
  line-height: 1.5;
}
.editor-protect-permissions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
}
.editor-protect-permission {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.editor-protect-spoiler {
  margin-top: 12px;
}
.editor-protect-spoiler-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 0;
  border: none;
  background: none;
  font-size: 14px;
  color: var(--text-color, #333);
  cursor: pointer;
  text-align: left;
}
.editor-protect-spoiler-toggle:hover {
  color: var(--link-color, #0066cc);
}
.editor-protect-spoiler-icon {
  transition: transform 0.2s ease;
  opacity: 0.7;
}
.editor-protect-spoiler-toggle[aria-expanded='true']
  .editor-protect-spoiler-icon {
  transform: rotate(180deg);
}
.editor-protect-spoiler-content {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color, #e0e0e0);
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color, #d0d0d0);
  border-radius: var(--radius-small, 3px);
  cursor: pointer;
  font-size: 14px;
  background: var(--container-bg, #fff);
  color: var(--text-color, #333);
  transition: all 0.2s;
}

.btn:hover {
  background: var(--item-hover-bg, #f5f5f5);
}

.btn-primary-modal {
  background: var(--primary-blue, #0078d4) !important;
  color: #fff !important;
  border: 1px solid var(--primary-blue-hover, #106ebe) !important;
}

.btn-primary-modal:hover {
  background: var(--primary-blue-hover, #106ebe) !important;
  color: #fff !important;
  border-color: var(--primary-blue-hover, #106ebe) !important;
}

.btn-clear-signature {
  background: var(--container-bg, #fff) !important;
  color: #c62828 !important;
  border: 1px solid var(--border-color, #d0d0d0) !important;
}

.btn-clear-signature:hover {
  background: var(--item-hover-bg, #f5f5f5) !important;
  color: #b71c1c !important;
  border-color: var(--border-color, #b0b0b0) !important;
}

.signature-mode-footer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100%;
  color: #666;
}

.loading-title {
  margin-top: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  text-align: center;
}

.loading-subtext {
  margin-top: 6px;
  font-size: 12px;
  color: #555;
  text-align: center;
}

.editor-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(229, 229, 229, 0.92);
  z-index: 20;
  padding: 24px;
}

.editor-loading[hidden] {
  display: none;
}

.loading-progress {
  width: 240px;
  height: 10px;
  background: #dfe6ef;
  border-radius: 999px;
  margin-top: 12px;
  overflow: hidden;
  position: relative;
  border: 1px solid #c5d0df;
}

.loading-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #0078d4, #33a0ff);
  transition: width 0.2s ease;
}

.loading-progress.loading-progress--indeterminate .loading-progress-fill {
  width: 40%;
  animation: loading-progress-indeterminate 1.2s linear infinite;
}

@keyframes loading-progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(250%);
  }
}

.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #0078d4;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Sidebar - Page Selector */
.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  overflow-x: hidden;
  position: relative; /* Ensure proper stacking context */
}

.sidebar-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 8px;
  padding: 0 4px;
}

.page-thumbnail {
  margin-bottom: 8px; /* Base margin, will increase when active */
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 0;
  transition: margin-bottom 0.2s ease;
  background: transparent;
  position: relative;
  display: flex;
  flex-direction: column; /* Stack page box and buttons vertically */
  align-items: center; /* Center page boxes horizontally */
  gap: 6px; /* Space between page box and buttons (always present but buttons hidden) */
  user-select: none; /* Prevent text selection during drag */
  /* Ensure rotated wrapper doesn't overflow */
  overflow: visible;
  /* Ensure thumbnail container doesn't clip rotated content */
  min-width: 0; /* Allow shrinking but don't clip */
}

/* When page is active, increase bottom margin to accommodate visible buttons */
.page-thumbnail.active {
  margin-bottom: 16px; /* More space when buttons are visible */
}

/* Buttons should have normal cursor */
.page-thumbnail-buttons {
  cursor: default; /* Normal cursor for buttons */
}

/* Hover and active states are now on the wrapper */

.page-thumbnail.dragging .page-thumbnail-wrapper {
  opacity: 0.5;
}

.page-thumbnail.drag-over .page-thumbnail-wrapper {
  border-color: #0078d4;
  border-style: dashed;
}

.page-thumbnail-wrapper {
  position: relative;
  width: auto; /* Size to fit canvas, not 100% */
  height: auto; /* Size to fit canvas */
  overflow: visible; /* Allow content to be visible */
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: move; /* Indicate draggable/clickable */
  background: white;
  border: 2px solid transparent;
  padding: 4px;
  transition:
    width 0.3s ease,
    height 0.3s ease,
    border-color 0.2s,
    background 0.2s; /* Smooth size transition */
  box-sizing: border-box;
  /* No transform - wrapper doesn't rotate, only canvas content is rotated */
  /* Wrapper contains only: canvas (preview) and label (page number) */
}

.page-thumbnail:hover .page-thumbnail-wrapper {
  border-color: #c7c7c7;
}

.page-thumbnail.active .page-thumbnail-wrapper {
  border-color: #0078d4;
}

.page-thumbnail.active .page-thumbnail-label {
  color: #0078d4;
  border-color: #cce9ff;
  font-weight: 600;
}

.page-thumbnail-wrapper canvas {
  width: auto; /* Use actual canvas width */
  height: auto; /* Use actual canvas height */
  display: block;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  flex-shrink: 0; /* Don't shrink the canvas */
  /* Canvas is rendered with rotation via viewport, so content is rotated but canvas itself is not */
  /* Canvas dimensions are set via width/height attributes and style, wrapper sizes to fit */
  /* Wrapper contains only: canvas (preview) and label (page number) */
}

/* Fallback selector for canvas */
.page-thumbnail canvas {
  width: auto;
  height: auto;
  display: block;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

/* Adjust wrapper for rotated pages (90 or 270 degrees) */
.page-thumbnail.rotated-landscape .page-thumbnail-wrapper {
  /* When rotated 90/270, the canvas dimensions are swapped */
  /* The viewport already accounts for rotation, so canvas will fit */
}

.page-thumbnail-buttons {
  display: flex;
  flex-direction: row; /* Buttons in a row below the page box */
  gap: 6px;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition:
    opacity 0.2s ease,
    max-height 0.2s ease;
  flex-shrink: 0; /* Don't shrink */
  justify-content: center; /* Center the buttons */
  align-items: center;
  padding: 0;
  margin: 0;
  transform: none;
}

/* Show buttons only when page is active/selected */
.page-thumbnail.active .page-thumbnail-buttons {
  opacity: 1;
  max-height: 48px; /* Enough height for 38px button + padding */
  padding: 0 6px;
}

.page-thumbnail-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: rgba(0, 0, 0, 0.75);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
  padding: 0;
  flex-shrink: 0;
  transform: none;
}

.page-thumbnail-btn:hover {
  background: rgba(0, 0, 0, 0.85);
  transform: none;
}

.pdf-editor-page button {
  transform: none;
}

.pdf-editor-page button:hover {
  transform: none;
}

.page-thumbnail-btn i {
  pointer-events: none;
}

/* Context menu button is now in the buttons container, no special styling needed */

.page-thumbnail-label {
  text-align: center;
  font-size: 15px; /* Increased from 13px to 15px */
  color: #666;
  margin-top: 8px;
  font-weight: 600;
  border-top: 1px solid #f5f5f5;
  padding-top: 2px;
  width: 100%; /* Full width of wrapper */
  background: transparent;
}

#pageThumbnailsContainer {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  margin-right: -4px;
}

/* Page Context Menu - visible by default, animate only on hide */
.page-context-menu {
  position: fixed;
  background: white;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  min-width: 200px;
  padding: 4px 0;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.page-context-menu.is-hidden {
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  pointer-events: none;
}

.page-context-menu-item {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #333;
  transition: background 0.15s;
}

.page-context-menu-item:hover {
  background: #f0f0f0;
}

.page-context-menu-item.danger {
  color: #c00;
}

.page-context-menu-item.danger:hover {
  background: #fee;
}

.page-context-menu-item i {
  width: 16px;
  text-align: center;
}

.page-context-menu-separator {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}

input[type='file'] {
  display: none;
}
