/**
 * PDF Micro Editor Styles
 */

:root {
  /* Apple-ish (macOS) dark vibrancy system */
  color-scheme: dark;

  --bg-primary: #0b0c0f;
  --bg-secondary: rgba(28, 28, 30, 0.78);   /* panel glass */
  --bg-tertiary: rgba(44, 44, 46, 0.70);
  --bg-elevated: rgba(58, 58, 60, 0.75);

  --surface-glass: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.10);
  --surface-active: rgba(255, 255, 255, 0.14);

  --border-subtle: rgba(255, 255, 255, 0.10);
  --border-default: rgba(255, 255, 255, 0.16);

  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(235, 235, 245, 0.70);
  --text-tertiary: rgba(235, 235, 245, 0.45);
  --text-inverse: rgba(0, 0, 0, 0.92);

  /* Red accent to match toolbar icons */
  --accent-blue: #ff453a;
  --accent-blue-hover: #e23b31;
  --accent-green: #30d158;
  --accent-red: #ff453a;

  /* Typography: system font stack */
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --toolbar-height: 52px;
  --sidebar-width: 260px;

  /* Shadows tuned for "Apple" look */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 22px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.45);

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(255, 69, 58, 0.35);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}



/* ==================== APPLE-STYLE OVERRIDES ==================== */
/* Keep class names intact; modernize the look via tokens + a few targeted overrides */

body {
  background:
    radial-gradient(900px 520px at 25% 15%, rgba(255, 69, 58, 0.16) 0%, transparent 55%),
    radial-gradient(780px 520px at 70% 70%, rgba(48, 209, 88, 0.10) 0%, transparent 55%),
    var(--bg-primary);
}

/* Frosted header */
.mode-header {
  background: rgba(20, 20, 22, 0.92);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border-bottom: 1px solid var(--border-subtle);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .mode-header {
    background: rgba(20, 20, 22, 0.62);
  }
}

/* Glass panels */
.left-panel,
.right-panel {
  background: rgba(28, 28, 30, 0.96);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .left-panel,
  .right-panel {
    background: rgba(28, 28, 30, 0.70);
  }
}

/* Clear focus ring */
.header-btn:focus-visible,
.tool-btn:focus-visible,
.toolbar-btn:focus-visible,
.mode-btn:focus-visible,
.mode-switch-btn:focus-visible,
.popover-btn:focus-visible,
.property-btn:focus-visible,
.btn-action:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.zoom-btn:focus-visible,
.nav-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Active state */
.mode-btn.active,
.mode-switch-btn.active,
.left-panel-tools .tool-btn.active,
.toolbar-btn.active,
.property-btn.active,
.popover-btn.active {
  background: rgba(255, 69, 58, 0.22);
  border-color: rgba(255, 69, 58, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 69, 58, 0.35);
  color: var(--text-primary);
}

/* Hover surfaces */
.left-panel-tools .tool-btn:hover,
.mode-switch-btn:hover,
.header-btn:hover:not(:disabled),
.tool-btn:hover,
.toolbar-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-subtle);
}

/* Primary actions */
.toolbar-btn.export-btn,
.btn-save,
.popover-btn.primary,
.btn-primary {
  background: linear-gradient(180deg, rgba(255, 69, 58, 0.95), rgba(255, 69, 58, 0.75));
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 24px rgba(255, 69, 58, 0.22);
}

/* Popovers: macOS sheet */
.edit-popover,
.text-properties-popover,
.comment-popup {
  background: rgba(44, 44, 46, 0.78);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
}

/* Inputs */
.popover-input,
.popover-textarea,
.popover-select,
.property-input,
.property-select,
.toolbar-font-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
}

.popover-input:focus,
.popover-textarea:focus,
.popover-select:focus,
.property-input:focus,
.property-select:focus,
.toolbar-font-select:focus {
  outline: none;
  border-color: rgba(255, 69, 58, 0.55);
  box-shadow: var(--focus-ring);
}

/* Page cards */
.page-wrapper,
.canvas-wrapper {
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}

.page-wrapper.active {
  box-shadow: 0 0 0 2px rgba(255, 69, 58, 0.85), 0 18px 44px rgba(0, 0, 0, 0.45);
}

/* Toast: macOS HUD */
.toast {
  background: rgba(44, 44, 46, 0.82);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
}

/* Scrollbars */
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }
/* ==================== END APPLE-STYLE OVERRIDES ==================== */

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Global mode switch header (ONLY control always visible) */
.mode-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(10, 11, 14, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 250000;
}

.mode-filename {
  font-size: 13px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-zoom,
.header-pages {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.header-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.header-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.header-zoom-level,
.header-page-info {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  min-width: 50px;
  text-align: center;
}


.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding-top: var(--toolbar-height);
  padding-left: 72px; /* space for narrow left panel (48px + margins) */
  padding-right: 230px; /* space for right panel (200px + margins) */
}

.toolbar-tools {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-glass);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

/* Mode switch */
.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.mode-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--accent-blue);
  color: var(--text-inverse);
  border-color: rgba(0, 0, 0, 0.15);
}

/* Mode helpers */
body.mode-edit .edit-tools { display: flex !important; }
body.mode-edit .annotate-tools { display: none !important; }
body.mode-annotate .edit-tools { display: none !important; }
body.mode-annotate .annotate-tools { display: flex !important; }

/* Mode switch container */
.mode-switch-container {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.mode-switch-btn {
  appearance: none;
  flex: 1;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-switch-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.mode-switch-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--text-inverse);
}


.edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.edit-list-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.edit-count {
  color: var(--accent-blue);
  font-weight: 500;
}

.snap-indicator {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 6px 8px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.whiteout-color-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-secondary);
}

.whiteout-color-picker input[type="color"] {
  width: 32px;
  height: 24px;
  border: 1px solid var(--border-default);
  border-radius: 4px;
  cursor: pointer;
}

.pages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
}

/* LEFT panel: Mode switch + Tools (narrow vertical) */
.left-panel {
  position: fixed;
  left: 12px;
  top: calc(var(--toolbar-height) + 12px);
  bottom: 12px;
  width: 48px;
  display: flex;
  flex-direction: column;
  background: rgba(18, 20, 26, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 8px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

/* Mode switch at top of left panel */
.left-panel-mode-switch {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.mode-switch-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-switch-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.mode-switch-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--text-inverse);
}

/* Tools in left panel (vertical) */
.left-panel-tools {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.left-panel-tools .tool-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.left-panel-tools .tool-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.left-panel-tools .tool-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--text-inverse);
}

/* RIGHT panel: History (unified for both modes) */
.right-panel {
  position: fixed;
  right: 12px;
  top: calc(var(--toolbar-height) + 12px);
  bottom: 12px;
  width: 200px;
  background: rgba(18, 20, 26, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.history-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.history-count {
  font-size: 12px;
  color: var(--accent-blue);
  font-weight: 500;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-item:hover {
  background: var(--surface-hover);
  border-color: var(--border-default);
}

.history-item.selected {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-blue);
}

.history-item-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.history-item-text {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-page {
  font-size: 10px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.history-item-delete {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.history-item:hover .history-item-delete {
  opacity: 1;
}

.history-item-delete:hover {
  background: rgba(255, 68, 68, 0.2);
  color: #ff4444;
}

.history-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* Highlight border for selected items on PDF */
.edit-highlight-border {
  animation: highlight-pulse 0.5s ease-out;
}

@keyframes highlight-pulse {
  0% {
    stroke-width: 3;
    opacity: 1;
  }
  100% {
    stroke-width: 1.5;
    opacity: 1;
  }
}

/* REMOVED: Annotation contextual controls */

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  gap: 6px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
}

.toolbar-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.toolbar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-btn.active {
  background: var(--accent-blue);
  color: var(--text-inverse);
}

.toolbar-btn.delete-btn:hover {
  background: var(--accent-red);
  color: var(--text-inverse);
}

.toolbar-btn.export-btn {
  background: linear-gradient(135deg, #68d391, #38a169);
  color: var(--text-inverse);
  padding: 0 16px;
}

.toolbar-btn.export-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.toolbar-btn.export-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
}

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

.whiteout-color-picker {
  display: flex;
  align-items: center;
  margin: 0 4px;
  padding: 0 4px;
}

.whiteout-color-picker input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  padding: 2px;
}

.whiteout-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.whiteout-color-picker input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: var(--radius-sm);
}

.toolbar-font-select {
  display: inline-block;
  height: 36px;
  padding: 0 12px;
  margin: 0 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  min-width: 120px;
}

.toolbar-font-select:hover {
  background: var(--surface-hover);
  border-color: var(--border-default);
}

.toolbar-font-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.toolbar-zoom,
.toolbar-page {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: center;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-section.edits-section {
  flex: 1;
  overflow-y: auto;
  border-bottom: none;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.edit-count {
  color: var(--accent-blue);
}

.pages-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.page-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-item:hover {
  background: var(--surface-hover);
}

.page-item.active {
  background: var(--accent-blue);
  color: var(--text-inverse);
}

.page-item-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: var(--accent-green);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
}

.edits-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.edit-item:hover {
  background: var(--surface-hover);
}

.edit-item.selected {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--accent-blue);
}

.edit-item-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.edit-item-content {
  flex: 1;
  min-width: 0;
}

.edit-item-type {
  display: block;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.edit-item-label {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edit-item-page {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
}

.edit-item-delete {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s ease;
}

.edit-item:hover .edit-item-delete {
  opacity: 1;
}

.edit-item-delete:hover {
  background: var(--accent-red);
  color: var(--text-inverse);
}

.empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-tertiary);
}

.empty-state p {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

/* Edits grouped by page */
.edits-page-group {
  margin-bottom: 16px;
}

.edits-page-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  padding: 0 4px;
}

.edits-page-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edit-item-preview {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edit-item-label[contenteditable="true"] {
  background: var(--bg-tertiary);
  padding: 2px 4px;
  border-radius: 4px;
  outline: 1px solid var(--accent-blue);
}

/* Properties Panel */
.properties-section {
  border-top: 1px solid var(--border-subtle);
  max-height: 400px;
  overflow-y: auto;
}

.properties-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.property-group {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.property-group + .property-group {
  padding-top: 14px;
}

.property-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-tertiary);
  opacity: 0.7;
}

.property-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
}

.property-input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.property-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
  cursor: pointer;
}

.property-select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.property-select:hover {
  border-color: var(--border-default);
  background: var(--bg-elevated);
}

.property-input-small {
  width: 80px;
}

/* ── Stamp panel (Presets | Custom) — minimal dark UI ───────────────── */
.stamp-panel {
  --stamp-radius: 8px;
  --stamp-h: 34px;
}

.stamp-panel__head {
  margin-bottom: 12px;
}

.stamp-panel__title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.stamp-seg {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--stamp-radius);
  border: 1px solid var(--border-subtle);
}

.stamp-seg__btn {
  flex: 1;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.stamp-seg__btn:hover {
  color: var(--text-primary);
}

.stamp-seg__btn.is-active {
  color: var(--text-primary);
  background: var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.stamp-tab[hidden] {
  display: none !important;
}

.stamp-sec-label {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.stamp-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Unified pill — system + user use same shape; color is soft tint */
.stamp-chip {
  min-height: var(--stamp-h);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--stamp-tone, #888) 35%, var(--border-subtle));
  background: color-mix(in srgb, var(--stamp-tone, #888) 16%, var(--bg-elevated));
  color: var(--stamp-tone, var(--text-primary));
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.stamp-chip:hover {
  background: color-mix(in srgb, var(--stamp-tone, #888) 24%, var(--bg-elevated));
  border-color: color-mix(in srgb, var(--stamp-tone, #888) 45%, var(--border-subtle));
}

.stamp-chip:active {
  transform: scale(0.98);
}

.stamp-chip.is-selected {
  border-color: color-mix(in srgb, var(--stamp-tone, #ccc) 55%, var(--border-default));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--stamp-tone, #fff) 12%, transparent);
  background: color-mix(in srgb, var(--stamp-tone, #888) 22%, var(--bg-elevated));
}

.stamp-user-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stamp-user-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stamp-user-row .stamp-chip {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.stamp-btn-icon {
  flex-shrink: 0;
  width: 32px;
  height: var(--stamp-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--stamp-radius);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.stamp-btn-icon:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.stamp-btn-icon--danger:hover {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.35);
}

.stamp-ico {
  display: block;
}

.stamp-empty-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.stamp-preview {
  min-height: 56px;
  padding: 12px;
  border-radius: var(--stamp-radius);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stamp-preview__inner {
  display: block;
  transform: scale(var(--p, 1));
  transform-origin: center center;
}

.stamp-preview__box {
  display: inline-block;
  padding: 6px 12px;
  border: 2px solid;
  border-radius: 2px;
  background: transparent;
}

.stamp-preview__txt {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.stamp-actions {
  margin-top: 12px;
}

.stamp-actions--split {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stamp-btn {
  width: 100%;
  min-height: 38px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--stamp-radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.stamp-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stamp-btn--primary {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent-blue) 22%, var(--bg-tertiary));
  border-color: color-mix(in srgb, var(--accent-blue) 35%, var(--border-subtle));
}

.stamp-btn--primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-blue) 30%, var(--bg-elevated));
}

.stamp-btn--secondary {
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-color: var(--border-subtle);
}

.stamp-btn--secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-default);
}

.stamp-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: center;
}

.stamp-field {
  margin-bottom: 12px;
}

.stamp-field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
}

.stamp-input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--stamp-radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stamp-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

.stamp-input:focus {
  border-color: color-mix(in srgb, var(--accent-blue) 45%, var(--border-subtle));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 18%, transparent);
}

.stamp-input--num {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  text-align: center;
}

.stamp-color-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.stamp-hex {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  font-family: ui-monospace, monospace;
}

.stamp-color-wrap .color-picker-container {
  gap: 8px;
}

.stamp-color-wrap .color-preview-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  box-shadow: none;
}

.stamp-color-wrap .color-preview-swatch:hover {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--text-tertiary) 25%, transparent);
}

.stamp-color-wrap .color-picker-grid {
  gap: 5px;
}

.stamp-color-wrap .color-picker-grid .color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

.stamp-color-wrap .color-picker-grid .color-swatch.active {
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 3px color-mix(in srgb, var(--text-primary) 35%, transparent);
}

.stamp-stepper {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.stamp-stepper__btn {
  width: 36px;
  min-height: 34px;
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--stamp-radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.stamp-stepper__btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.stamp-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stamp-slider {
  flex: 1;
}

.stamp-slider::-webkit-slider-thumb {
  background: color-mix(in srgb, var(--text-secondary) 85%, var(--bg-primary));
  border: 2px solid var(--bg-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.stamp-slider::-moz-range-thumb {
  background: color-mix(in srgb, var(--text-secondary) 85%, var(--bg-primary));
  border: 2px solid var(--bg-primary);
}

.stamp-slider-val {
  min-width: 44px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

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

.property-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}

.property-checkbox-label input[type="checkbox"] {
  cursor: pointer;
}

.property-buttons {
  display: flex;
  gap: 4px;
}

.property-btn {
  flex: 1;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s ease;
}

.property-btn:hover {
  background: var(--surface-hover);
}

.property-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--text-inverse);
}

/* Help hint */
.help-hint {
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.help-hint strong {
  color: var(--text-primary);
}

.empty-state span {
  font-size: 12px;
  opacity: 0.7;
}

/* Viewer */
.viewer-container {
  flex: 1;
  overflow: auto;
  background: 
    radial-gradient(circle at 30% 20%, rgba(239, 68, 68, 0.03) 0%, transparent 40%),
    var(--bg-primary);
  display: flex;
  justify-content: center;
  padding: 32px;
}

/* Old .pages-container moved to Canvas Area section below */

/* Old page styles - moved to canvas-area section */

/* Text layer for text selection */
.pdf-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  pointer-events: auto !important; /* Always enable for text selection */
  z-index: 10; /* Higher z-index to ensure it's accessible */
  overflow: hidden;
  /* Ensure text layer is always on top when highlight tool is active */
}

/* REMOVED: Annotate mode text layer styles */

.pdf-text-layer span {
  position: absolute;
  color: transparent; /* Invisible but selectable */
  white-space: pre;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  pointer-events: auto !important;
  /* Add small padding to make selection easier, especially for last letters */
  padding: 1px 2px;
  margin: -1px -2px;
}

.overlay-svg {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: var(--radius-md);
  z-index: 2; /* Above text layer for editing */
}

.annotation-canvas {
  z-index: 3 !important; /* Above SVG but below panels (panels are z-index: 100) */
  position: absolute;
  top: 0;
  left: 0;
}

/* In annotate mode, disable pointer events on text layer */
body.mode-annotate .pdf-text-layer {
  pointer-events: none !important;
  z-index: 1 !important;
}

/* In annotate mode, ensure annotation canvas is on top of page content only */
body.mode-annotate .annotation-canvas {
  z-index: 3 !important; /* Keep below panels (z-index: 100) */
  pointer-events: auto !important;
  display: block !important;
}

/* Ensure annotation canvas wrapper doesn't overflow page-wrapper */
body.mode-annotate .page-wrapper .canvas-container {
  z-index: 3 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  pointer-events: auto !important;
  overflow: visible !important;
}

/* REMOVED: Annotate mode overlay SVG styles */

/* Welcome */
.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.welcome-content {
  text-align: center;
  padding: 48px;
  background: var(--surface-glass);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  max-width: 420px;
}

.welcome-icon {
  margin-bottom: 24px;
  color: var(--accent-blue);
  opacity: 0.8;
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #63b3ed, #4c9aed);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.welcome-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  background: linear-gradient(135deg, #63b3ed, #4c9aed);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-inverse);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.welcome-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.4);
}

.welcome-hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-tertiary);
}

/* Popover */
.edit-popover {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  min-width: 280px;
  z-index: 1000;
  animation: popover-in 0.15s ease;
}

@keyframes popover-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.popover-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.popover-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
}

.popover-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.popover-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popover-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.popover-row label {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 50px;
}

.popover-input,
.popover-textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
}

.popover-textarea {
  resize: vertical;
  min-height: 80px;
}

.popover-input:focus,
.popover-textarea:focus {
  border-color: var(--accent-blue);
}

.popover-select {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.popover-color {
  width: 40px;
  height: 32px;
  padding: 2px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.popover-button-group {
  display: flex;
  gap: 4px;
}

.popover-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.popover-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.popover-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--text-inverse);
}

.popover-btn.mark-btn {
  font-size: 18px;
  width: 40px;
}

.popover-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

.popover-btn.secondary {
  background: transparent;
}

.popover-btn.primary {
  background: linear-gradient(135deg, #63b3ed, #4c9aed);
  border-color: transparent;
  color: var(--text-inverse);
}

.popover-btn.primary:hover {
  filter: brightness(1.1);
}

.popover-btn.primary:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
}

/* SVG Edit Styles */
.edit-rect {
  cursor: pointer;
  transition: opacity 0.15s;
}

.edit-rect:hover {
  opacity: 0.8;
}

.edit-rect.selected {
  /* Selection border is rendered as separate element, not via CSS */
  outline: none;
}

.edit-selection-border {
  stroke: #ff0000;
  stroke-width: 1;
  stroke-dasharray: 4,4;
  fill: none;
  pointer-events: none;
}

/* TextEditorOverlay - completely transparent, ZERO visible controls */
.text-editor-overlay {
  pointer-events: auto;
}

.text-editor-input {
  font-family: var(--font-mono, 'Courier New', monospace);
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Text properties button (appears only when selected, not editing) */
.text-properties-btn {
  transition: all 0.15s ease;
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, sans-serif);
}

/* Text properties popover */
.text-properties-popover {
  animation: popover-in 0.15s ease;
}

/* Inline font select dropdown */
.inline-font-select {
  transition: all 0.15s ease;
  user-select: none;
}

.inline-font-select:hover {
  background: rgba(59, 130, 246, 0.1) !important;
  border-color: #3b82f6;
}

.inline-font-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Font size buttons */
.font-size-btn {
  transition: all 0.2s ease;
  user-select: none;
}

.font-size-btn:hover {
  transform: scale(1.1);
}

.font-size-btn:active {
  transform: scale(0.95);
}

/* Font family select dropdown */
.font-family-select {
  transition: all 0.2s ease;
}

.font-family-select:hover {
  background: rgba(59, 130, 246, 0.1) !important;
}

.font-family-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Text edit cursor */
.edit-rect[data-edit-type="fill_text"] {
  cursor: text;
}

/* Removed select-tool specific styles */

.drawing-rect {
  fill: rgba(239, 68, 68, 0.2);
  stroke: #3b82f6;
  stroke-width: 2;
  stroke-dasharray: 5,5;
}

/* Snap Zones (Blank Line Detection) */
.snap-zone {
  cursor: pointer !important;
  transition: all 0.15s ease;
  fill: rgba(16, 185, 129, 0.1);
  stroke: #10b981;
  stroke-width: 2;
  stroke-dasharray: 6,3;
  rx: 3;
  ry: 3;
}

.snap-zone:hover,
.snap-zone-highlight {
  fill: rgba(16, 185, 129, 0.25) !important;
  stroke: #059669 !important;
  stroke-width: 3 !important;
  stroke-dasharray: none !important;
  filter: drop-shadow(0 0 4px rgba(16, 185, 129, 0.5));
}

.snap-zones-group {
  transition: opacity 0.2s ease;
}

.snap-zones-group .snap-zone {
  pointer-events: auto !important;
}

/* Snap zone indicator in toolbar */
.snap-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: #10b981;
}

.snap-indicator::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  animation: pulse-snap 1.5s infinite;
}

@keyframes pulse-snap {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 1001;
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Comment Popup (matching reference implementation) */
.comment-popup {
  position: fixed;
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  overflow: hidden;
}

.comment-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-default);
}

.comment-popup-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.comment-popup-actions {
  display: flex;
  gap: 4px;
}

.comment-popup-delete,
.comment-popup-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.comment-popup-delete:hover {
  background: var(--accent-red);
  color: white;
}

.comment-popup-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.comment-popup-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.comment-popup-textarea::placeholder {
  color: var(--text-tertiary);
}

/* Color Picker Component - специфичные стили для Fill PDF */
.color-picker-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Pill preview — full width, click to open full picker */
.color-preview-swatch {
  width: 100%;
  height: 30px;
  border-radius: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

.color-preview-swatch:hover {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 2.5px rgba(239, 68, 68, 0.35);
}

/* Color Picker Modal */
.color-picker-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent; /* No dark overlay - just for click detection */
  z-index: 10000;
  pointer-events: auto;
}

.color-picker-modal {
  position: fixed;
  z-index: 10001;
  animation: slideIn 0.2s ease;
}

.color-picker-modal-header {
  background: #333333;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  height: 24px;
}

.color-picker-minimize-btn,
.color-picker-close-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  opacity: 0.8;
  transition: opacity 0.15s ease;
}

.color-picker-minimize-btn:hover,
.color-picker-close-btn:hover {
  opacity: 1;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.color-picker-modal-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.color-picker-controls-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0;
}

.eyedropper-btn {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  color: #000000;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.eyedropper-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.25);
}

.eyedropper-btn svg {
  stroke: #000000;
}

.color-preview-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(100, 150, 200, 0.4);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

.color-picker-rgb-inputs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.rgb-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.rgb-input-group label {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}

.rgb-input {
  width: 100%;
  height: 32px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  color: #000000;
  font-size: 13px;
  padding: 0 8px;
  text-align: center;
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.rgb-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.rgb-input-group label {
  font-size: 11px;
  color: #666666;
  text-align: center;
  font-weight: 500;
}

.rgb-input::-webkit-inner-spin-button,
.rgb-input::-webkit-outer-spin-button {
  opacity: 1;
}

/* Old styles removed - using .picker__ styles below */

.native-color-input {
  width: 100%;
  height: 36px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  background: #ffffff;
  cursor: pointer;
  padding: 2px;
  transition: all 0.15s ease;
}

.native-color-input:hover {
  border-color: rgba(0, 0, 0, 0.25);
}

.native-color-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.native-color-input:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.native-color-input:focus {
  outline: none;
  border-color: #63b3ed;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* New Picker Styles */
.picker {
  width: 300px;
  max-width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0,0,0,.10);
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: #1d1d1f;
}

.picker__preview {
  height: 220px;
  position: relative;
  background: #f5f5f5;
}

.picker__previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.picker__panel {
  padding: 14px 16px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  background: #fff;
}

.picker__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Eyedropper button — dark icon on white bg */
.picker__tool {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 9px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  color: #1d1d1f;
  transition: background 0.13s, border-color 0.13s;
}

.picker__tool:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.22);
}

.picker__tool svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.picker__swatch {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid rgba(0, 0, 0, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
}

.picker__hue {
  position: relative;
  flex: 1;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    #ff0000 0%,
    #ff00ff 16%,
    #0000ff 33%,
    #00ffff 50%,
    #00ff00 66%,
    #ffff00 83%,
    #ff0000 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.picker__hueInput {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

.picker__hueThumb {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgb(0, 255, 230);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(0,0,0,.08);
  pointer-events: none;
  transition: left 0.08s ease;
}

/* Alpha/Opacity slider */
.picker__alpha-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
}

.picker__alpha-label {
  font-size: 11px;
  font-weight: 500;
  color: #6e6e73;
  margin-right: 10px;
  min-width: 46px;
}

.picker__alpha {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.picker__alphaInput {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, 
    rgba(255,255,255,0) 0%, 
    rgba(255,255,255,1) 100%),
    repeating-linear-gradient(45deg, #ccc 0px, #ccc 5px, #fff 5px, #fff 10px);
  border-radius: 3px;
  cursor: pointer;
}

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

.picker__alphaInput::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  cursor: pointer;
}

.picker__alphaValue {
  font-size: 12px;
  color: #6e6e73;
  min-width: 36px;
  text-align: right;
}


/* Small screens */
@media (max-width: 620px) {
  .picker__preview {
    height: 240px;
  }
  .picker__row {
    gap: 10px;
  }
  .picker__swatch {
    width: 32px;
    height: 32px;
  }
  .picker__tool {
    width: 36px;
    height: 36px;
  }
}

/* Properties Panel additional styles */
.slider-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
}

.slider-value {
  min-width: 50px;
  text-align: right;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Loading Screen */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  z-index: 10000;
  gap: 1.5rem;
}

.loading.hidden {
  display: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(239, 68, 68, 0.2);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Editor Container */
.editor-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ==================== UNIFIED TOOLBAR ==================== */

.toolbar-unified {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 12px;
  background: #1E1F23;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  z-index: 100;
}

.toolbar-tools-left,
.toolbar-tools-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 20px;
}

.toolbar-info {
  font-size: 12px;
  color: #9CA3AF;
  font-weight: 500;
}

/* Tool Groups */
.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Tool Dividers */
.tool-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 8px;
}

/* Tool Buttons */
.tool-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #E6E6E6;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.tool-btn.active {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px #4C8DFF;
}

.tool-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #4C8DFF;
}

/* Danger button (delete) */
.tool-btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Shape Tool Wrapper with Dropdown */
.tool-btn-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.tool-btn-wrapper .tool-btn {
  border-radius: 8px 0 0 8px;
}

.tool-btn-dropdown-arrow {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 0 8px 8px 0;
  background: transparent;
  color: #9CA3AF;
  cursor: pointer;
  transition: all 0.15s ease;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.tool-btn-dropdown-arrow:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #E6E6E6;
}

.tool-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: row;
  gap: 4px;
  padding: 6px;
  background: #2A2B30;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

.tool-dropdown-menu.active {
  display: flex;
}

.tool-dropdown-item {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #E6E6E6;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tool-dropdown-item.active {
  background: rgba(76, 141, 255, 0.2);
  color: #4C8DFF;
}

/* Zoom Controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 2px;
}

.zoom-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #9CA3AF;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #E6E6E6;
}

#zoomInfo {
  font-size: 12px;
  font-weight: 500;
  color: #E6E6E6;
  min-width: 44px;
  text-align: center;
  font-family: var(--font-mono);
}

/* Action Buttons (Save/Export) */
.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-action {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-save {
  background: #4C8DFF;
  color: white;
}

.btn-save:hover {
  background: #3B7AE8;
}

.btn-export {
  background: rgba(255, 255, 255, 0.08);
  color: #E6E6E6;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-export:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ==================== SIGNATURE TOOL STYLES ==================== */

.signature-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.signature-modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  width: 540px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
}

.signature-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.signature-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.signature-modal-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.signature-modal-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* Tabs */
.signature-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
}

.signature-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.signature-tab:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.signature-tab.active {
  background: var(--accent-blue);
  color: white;
}

/* Tab content */
.signature-tab-content {
  padding: 20px;
}

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

/* Signature pad */
.signature-pad-container {
  position: relative;
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-subtle);
  overflow: hidden;
}

.signature-pad {
  display: block;
  width: 100%;
  height: 200px;
  cursor: crosshair;
}

.signature-pad-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 14px;
  pointer-events: none;
}

/* Signature options */
.signature-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

.signature-color-options,
.signature-width-options {
  display: flex;
  align-items: center;
  gap: 10px;
}

.signature-color-options label,
.signature-width-options label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Ink color picker inside signature modal — compact dot */
#signatureInkColorPicker {
  display: flex;
  align-items: center;
}
#signatureInkColorPicker .color-picker-container {
  flex-direction: row;
  align-items: center;
  gap: 0;
}
#signatureInkColorPicker .color-preview-swatch {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
#signatureInkColorPicker .color-picker-grid {
  display: none;
}

.signature-width-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-subtle);
  border-radius: 2px;
  cursor: pointer;
}

.signature-width-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
}

/* Re-draw button in signature properties panel */
.sig-redraw-btn {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-secondary, #2a2a2e);
  color: var(--text-primary, #e8e8e8);
  border: 1px solid var(--border-subtle, #3a3a3e);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.sig-redraw-btn:hover {
  background: var(--bg-hover, #3a3a3e);
  border-color: var(--accent-blue, #4a9eff);
}

/* Signature actions */
.signature-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.signature-btn {
  flex: 1;
  appearance: none;
  border: none;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.signature-btn-primary {
  background: var(--accent-blue);
  color: white;
}

.signature-btn-primary:hover {
  background: var(--accent-blue-hover);
}

.signature-btn-secondary {
  background: var(--surface-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.signature-btn-secondary:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* Saved signatures */
.saved-signatures-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.saved-signature-item {
  position: relative;
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.saved-signature-item:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.saved-signature-item img {
  width: 100%;
  height: 80px;
  object-fit: contain;
}

.saved-signature-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 1;
  visibility: visible;
}

.saved-signature-use {
  flex: 1;
  appearance: none;
  border: none;
  background: var(--accent-blue);
  color: white;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  opacity: 1 !important;
}

.saved-signature-use:hover {
  background: var(--accent-blue-hover, #3a8eef);
  opacity: 1 !important;
}

.saved-signature-delete {
  appearance: none;
  border: none;
  background: #e53e3e;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.saved-signature-delete:hover {
  background: #c53030;
  color: white;
}

.no-saved-signatures {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.no-saved-signatures p {
  margin: 0;
}

.no-saved-signatures .hint {
  font-size: 12px;
  margin-top: 8px;
  opacity: 0.7;
}

.no-saved-signatures.hidden {
  display: none;
}

/* Placement hint */
.signature-placement-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
}

.signature-placement-hint.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Old .tool-btn styles moved to UNIFIED TOOLBAR section above */

.nav-btn,
.zoom-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  font-size: 16px;
}

.nav-btn:hover:not(:disabled),
.zoom-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.nav-btn:disabled,
.zoom-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  color: var(--text-tertiary);
}

#pageInfo,
#zoomInfo {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  min-width: 80px;
  text-align: center;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #4c9aed);
  color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-default);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Editor Main */
.editor-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Sidebar (Properties Panel) */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.close-sidebar {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.close-sidebar:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sidebar.hidden {
  display: none;
}

/* Canvas Area */
.canvas-area {
  flex: 1;
  overflow: auto;
  background: var(--bg-primary);
  display: flex;
  justify-content: center;
  padding: 32px;
  /* Smooth scrolling for keyboard/programmatic navigation */
  scroll-behavior: smooth;
  /* Prevent width jumping when scrollbar appears */
  scrollbar-gutter: stable;
}

.pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Gap accommodates page-number-badge (18px) + divider spacing */
  gap: 32px;
  padding-bottom: 48px;
}

/* Page divider line between pages */
.page-divider {
  width: 100%;
  max-width: var(--page-divider-width, 100%);
  height: 1px;
  background: rgba(128, 128, 128, 0.15);
  flex-shrink: 0;
}

.page-wrapper {
  position: relative;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  /* Prevent flex shrink - pages must keep their full height */
  flex-shrink: 0;
}

.page-wrapper.active {
  box-shadow: 0 0 0 2px var(--accent-blue), 0 4px 16px rgba(0, 0, 0, 0.4);
}

.page-number-badge {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  padding: 2px 10px;
  border-radius: 10px;
}

.canvas-wrapper {
  position: relative !important;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  /* Ensure wrapper has explicit dimensions set by JS */
  min-width: 0;
  min-height: 0;
}

#pdfCanvas {
  display: block;
  border-radius: var(--radius-md);
  pointer-events: none !important;
  position: relative;
  z-index: 1;
}

.text-layer {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100%;
  height: 100%;
  opacity: 1;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none !important;
  z-index: 10 !important;
  overflow: hidden;
  touch-action: none;
}

/* Enable text selection only when text tool is active */
.text-layer.selectable {
  pointer-events: auto !important;
}

.text-layer.selectable span {
  pointer-events: auto !important;
}


.text-layer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none !important;
  transform-origin: 0% 0%;
  touch-action: none;
}

.overlay-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: auto;
}

/* Fabric.js container and canvases - critical for mouse events */
.canvas-wrapper .canvas-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

.canvas-container canvas {
  position: absolute;
  left: 0;
  top: 0;
}

.canvas-container .upper-canvas {
  z-index: 15 !important;
  pointer-events: auto !important;
}

.canvas-container .lower-canvas {
  z-index: 14;
  pointer-events: none;
}

.annotation-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* Color swatch grid — used by all tools */
.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.color-picker-grid .color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, 0.10);
  transition: transform 0.12s ease, border-color 0.12s, box-shadow 0.12s;
  background-clip: padding-box;
  box-shadow: 0 1px 2px rgba(0,0,0,.20);
}

.color-picker-grid .color-swatch:hover {
  transform: scale(1.12);
  border-color: rgba(255, 255, 255, 0.40);
}

.color-picker-grid .color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px #4C8DFF, 0 1px 4px rgba(0,0,0,.25);
  transform: scale(1.08);
}

/* ─── Text Properties Panel (tp-*) ────────────────────────────────── */
.tp-font-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 2px;
}

.tp-font-pill {
  width: 100%;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  height: 36px;
  overflow: hidden;
}

.tp-font-select {
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary); /* Windows/Chrome: avoid invisible text */
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  cursor: pointer;
  -webkit-appearance: menulist;
  appearance: auto;
}

.tp-font-select option {
  color: #1a1a1a;
  background: #ffffff;
}

.tp-divider-v {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

.tp-size-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px 0 4px;
  flex-shrink: 0;
}

.tp-size-input {
  width: 28px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  text-align: left;
  -moz-appearance: textfield;
  appearance: textfield;
}

.tp-size-input::-webkit-outer-spin-button,
.tp-size-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tp-size-unit {
  font-size: 12px;
  color: var(--text-tertiary);
}

.tp-size-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-left: 2px;
}

.tp-size-arrow {
  width: 18px;
  height: 14px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 7px;
  line-height: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, color 0.1s ease;
}

.tp-size-arrow:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.tp-size-arrow:active {
  background: var(--surface-active);
}

.tp-fmt-row {
  display: flex;
  gap: 7px;
  width: 100%;
}

.tp-fmt-btn {
  flex: 1;
  height: 40px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 15px;
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.tp-fmt-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.tp-fmt-btn.active {
  color: var(--text-primary);
  background: var(--surface-active);
  border-color: var(--border-default);
}

.tp-fmt-btn.tp-bold        { font-weight: 700; }
.tp-fmt-btn.tp-italic      { font-style: italic; }
.tp-fmt-btn.tp-bolditalic  { font-weight: 700; font-style: italic; }
.tp-fmt-btn.tp-bolditalic em { font-style: italic; pointer-events: none; }
.tp-fmt-btn.tp-underline   { text-decoration: underline; }
.tp-fmt-btn.tp-linethrough { text-decoration: line-through; }

.tp-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  text-transform: uppercase;
  margin: 14px 0 8px;
}

.tp-swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}

.tp-swatch {
  aspect-ratio: 1;
  border-radius: 7px;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease, border-color 0.12s ease;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.tp-swatch:hover {
  transform: scale(1.10);
  border-color: rgba(255, 255, 255, 0.30);
}

.tp-swatch.active::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1.5px var(--accent-blue);
  pointer-events: none;
}

.tp-transparent {
  background: repeating-conic-gradient(#9a9a9a 0% 25%, #e0e0e0 0% 50%) 0 / 10px 10px !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

/* Pill-only color picker: hide preset swatches, keep just the preview pill */
.tp-picker-pill-wrap {
  margin-top: 8px;
}

.tp-picker-pill-wrap .color-picker-grid {
  display: none !important;
}

.tp-picker-pill-wrap .color-preview-swatch {
  border-radius: 8px;
  height: 32px;
}

/* ══════════════════════════════════════════
   IMAGE TOOL — properties panel
═══════════════════════════════════════════ */
.img-btn-row {
  display: flex;
  gap: 6px;
}

.img-tool-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  background: var(--bg-secondary, #2a2a2e);
  color: var(--text-primary, #e8e8e8);
  border: 1px solid var(--border-subtle, #3a3a3e);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.img-tool-btn:hover {
  background: var(--bg-hover, #3a3a3e);
  border-color: var(--accent-blue, #4a9eff);
}

.img-crop-trigger-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-secondary, #2a2a2e);
  color: var(--text-primary, #e8e8e8);
  border: 1px solid var(--border-subtle, #3a3a3e);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.img-crop-trigger-btn:hover {
  background: var(--bg-hover, #3a3a3e);
  border-color: var(--accent-blue, #4a9eff);
}

/* ══════════════════════════════════════════
   IMAGE TOOL — crop modal
═══════════════════════════════════════════ */
.imgcrop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.imgcrop-modal {
  background: var(--bg-primary, #1c1c1e);
  border: 1px solid var(--border-subtle, #3a3a3e);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.imgcrop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle, #3a3a3e);
}

.imgcrop-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #e8e8e8);
}

.imgcrop-header-actions {
  display: flex;
  gap: 8px;
}

.imgcrop-btn-secondary {
  padding: 6px 14px;
  background: transparent;
  color: var(--text-secondary, #aaa);
  border: 1px solid var(--border-subtle, #3a3a3e);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.imgcrop-btn-secondary:hover { background: var(--bg-secondary, #2a2a2e); }

.imgcrop-btn-primary {
  padding: 6px 16px;
  background: var(--accent-blue, #4a9eff);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.imgcrop-btn-primary:hover { background: #3a8eef; }

.imgcrop-workspace {
  padding: 20px;
  overflow: auto;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.imgcrop-imgwrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  cursor: crosshair;
}

.imgcrop-imgwrap img {
  max-width: 70vw;
  max-height: 60vh;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Semi-transparent shades outside the crop box */
.imgcrop-shade {
  position: absolute;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* Crop box */
.imgcrop-box {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
  cursor: move;
  box-sizing: border-box;
}

/* Rule-of-thirds grid */
.imgcrop-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}
.imgcrop-grid span {
  border: 0.5px solid rgba(255, 255, 255, 0.25);
}

/* Corner & edge handles */
.imgcrop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 1.5px solid rgba(0,0,0,0.3);
  border-radius: 2px;
}
.imgcrop-nw { top: -6px; left: -6px; cursor: nw-resize; }
.imgcrop-n  { top: -6px; left: calc(50% - 6px); cursor: n-resize; }
.imgcrop-ne { top: -6px; right: -6px; cursor: ne-resize; }
.imgcrop-e  { top: calc(50% - 6px); right: -6px; cursor: e-resize; }
.imgcrop-se { bottom: -6px; right: -6px; cursor: se-resize; }
.imgcrop-s  { bottom: -6px; left: calc(50% - 6px); cursor: s-resize; }
.imgcrop-sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.imgcrop-w  { top: calc(50% - 6px); left: -6px; cursor: w-resize; }
