/* ==========================================================================
   WorldByYou — Edit PDF Stylesheet
   Clean, light, professional vector PDF editing studio matching WorldByYou Tools.
   ========================================================================== */

:root {
  --ep-bg: #f1f5f9;              /* Light slate workspace canvas viewport */
  --ep-surface: #ffffff;         /* Pure white for panels, header, toolbar */
  --ep-surface-2: #f8fafc;       /* Slate-50 for inputs & subtle surfaces */
  --ep-surface-3: #f1f5f9;       /* Slate-100 for hover & borders */
  --ep-border: #e2e8f0;          /* Slate-200 */
  --ep-border-strong: #cbd5e1;   /* Slate-300 */
  --ep-border-focus: #2563eb;    /* Blue-600 */
  --ep-accent: #2563eb;          /* WorldByYou Blue Accent */
  --ep-accent-hover: #1d4ed8;    /* Blue-700 */
  --ep-accent-glow: rgba(37, 99, 235, 0.15);
  --ep-text: #0f172a;            /* Slate-900 */
  --ep-text-muted: #64748b;      /* Slate-500 */
  --ep-danger: #ef4444;          /* Red-500 */
  --ep-primary-btn: #0f172a;     /* Dark Charcoal header CTA */
  --ep-primary-btn-hover: #1e293b;
  --ep-header-h: 56px;
  --ep-toolbar-h: 50px;
  --ep-sidebar-w: 210px;
  --ep-props-w: 288px;
}

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

html {
  overflow-x: hidden;
  max-width: 100vw;
}

body.edit-pdf-body {
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overflow-x: hidden;
  background-color: var(--ep-bg);
  color: var(--ep-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Header
   ========================================================================== */
.ep-header {
  height: var(--ep-header-h);
  background: var(--ep-surface);
  border-bottom: 1px solid var(--ep-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  position: relative;
}

.ep-header-left, .ep-header-center, .ep-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Undo / Redo tight pill group */
.ep-history-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--ep-surface-2);
  border: 1px solid var(--ep-border);
  border-radius: 8px;
  padding: 2px;
}

.ep-history-group .ep-icon-btn {
  border-radius: 6px;
  border: none;
  background: transparent;
}


.ep-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--ep-surface-2);
  color: var(--ep-text);
  text-decoration: none;
  border: 1px solid var(--ep-border);
  transition: all 0.15s ease;
}

.ep-back-btn:hover {
  background: var(--ep-surface-3);
  color: var(--ep-accent);
  border-color: var(--ep-border-strong);
}

.ep-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
  padding: 3px 6px;
  margin: -3px -6px;
  transition: background 0.15s ease, transform 0.1s ease;
  cursor: pointer;
}

.ep-brand:hover {
  background: var(--ep-surface-2);
}

.ep-brand:active {
  transform: scale(0.96);
}

.ep-brand:focus-visible {
  outline: 2px solid var(--ep-accent);
  outline-offset: 2px;
}

.ep-logo {
  width: 26px;
  height: 26px;
}

.ep-titles {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.ep-app-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--ep-text);
}

.ep-tool-title {
  font-size: 0.85rem;
  color: var(--ep-accent);
  font-weight: 600;
}

.ep-btn-label-desktop {
  display: inline;
}

.ep-btn-label-mobile {
  display: none;
}

.ep-doc-name-wrap {
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--ep-border);
  max-width: 280px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ep-doc-name {
  font-size: 0.82rem;
  color: var(--ep-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Close Document Button - Prominent & Highlighted on Desktop & Mobile */
.ep-close-doc-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  user-select: none;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.08);
}

.ep-close-doc-btn:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.16);
}

.ep-close-doc-btn:active {
  transform: translateY(0);
  background: #fecaca;
}

.ep-close-doc-btn svg {
  stroke-width: 2.5;
  flex-shrink: 0;
}

/* Shown whenever a document is open */
.ep-has-document .ep-close-doc-btn,
.ep-has-session .ep-close-doc-btn {
  display: inline-flex !important;
}

.ep-divider-v {
  width: 1px;
  height: 20px;
  background: var(--ep-border);
}

.ep-page-indicator {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ep-text-muted);
  background: var(--ep-surface-2);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--ep-border);
}

/* Common Buttons */
.ep-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  font-family: inherit;
}

.ep-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.ep-btn-primary {
  background: var(--ep-primary-btn);
  color: #ffffff;
}

.ep-btn-primary:hover:not(:disabled) {
  background: var(--ep-primary-btn-hover);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
  transform: translateY(-1px);
}

.ep-btn-secondary {
  background: var(--ep-surface-2);
  color: var(--ep-text);
  border: 1px solid var(--ep-border);
}

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

.ep-btn-ghost {
  background: transparent;
  color: var(--ep-text-muted);
}

.ep-btn-ghost:hover {
  background: var(--ep-surface-3);
  color: var(--ep-text);
}

.ep-btn-danger {
  background: #fef2f2;
  color: var(--ep-danger);
  border: 1px solid #fecaca;
}

.ep-btn-danger:hover {
  background: #fee2e2;
}

.ep-btn-success {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
  font-weight: 600;
}

.ep-btn-success:hover {
  background: #dcfce7;
  border-color: #86efac;
}

.ep-btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.ep-btn-lg {
  padding: 10px 22px;
  font-size: 0.95rem;
}

.ep-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ep-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.ep-icon-btn:hover:not(:disabled) {
  background: var(--ep-surface-3);
  border-color: var(--ep-border);
}

.ep-icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ==========================================================================
   Toolbar
   ========================================================================== */
.ep-toolbar {
  height: var(--ep-toolbar-h);
  background: var(--ep-surface);
  border-bottom: 1px solid var(--ep-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 120;
  position: relative;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.ep-toolbar::-webkit-scrollbar {
  display: none;
}

.ep-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  position: relative;
  box-sizing: border-box;
}

.ep-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: #475569;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: inherit;
}

.ep-tool-btn:hover {
  background: var(--ep-surface-3);
  color: var(--ep-text);
}

.ep-tool-btn.active {
  background: #eff6ff;
  color: var(--ep-accent);
  border-color: #bfdbfe;
  font-weight: 600;
}

.ep-tool-btn.ep-btn-feature {
  color: var(--ep-text);
  border: 1px solid transparent;
  background: transparent;
  font-weight: 500;
}

.ep-tool-btn.ep-btn-feature:hover {
  background: var(--ep-surface-3);
  color: var(--ep-text);
  border-color: var(--ep-border);
}

.ep-tool-btn.ep-btn-feature.active {
  background: #eff6ff !important;
  color: var(--ep-accent, #2563eb) !important;
  border-color: #bfdbfe !important;
  font-weight: 600;
}

.ep-tool-sep {
  width: 1px;
  height: 20px;
  background: var(--ep-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.ep-dropdown-wrap {
  position: relative;
  display: inline-block;
  overflow: visible !important;
}

.ep-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #ffffff;
  border: 1px solid var(--ep-border);
  border-radius: 8px;
  padding: 6px;
  min-width: 175px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16), 0 4px 10px rgba(15, 23, 42, 0.08);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ep-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--ep-text);
  font-size: 0.82rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all 0.15s;
}

.ep-dropdown-item:hover {
  background: var(--ep-surface-3);
  color: var(--ep-accent);
}

.ep-zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.ep-zoom-val {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ep-text-muted);
  min-width: 44px;
  text-align: center;
}

.ep-mobile-only {
  display: none;
}

/* ==========================================================================
   Main Layout (Sidebar + Workspace + Properties)
   ========================================================================== */
.ep-main-layout {
  display: flex;
  height: calc(100vh - var(--ep-header-h) - var(--ep-toolbar-h));
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 100vw;
}

/* Left Sidebar (Thumbnails) */
.ep-sidebar {
  width: var(--ep-sidebar-w);
  background: var(--ep-surface);
  border-right: 1px solid var(--ep-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 50;
}

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

.ep-sidebar-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ep-text);
}

.ep-sidebar-count {
  font-size: 0.75rem;
  color: var(--ep-text-muted);
  background: var(--ep-surface-2);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--ep-border);
}

.ep-sidebar-close {
  display: none;
}

.ep-sidebar-actions {
  padding: 8px 12px;
  border-bottom: 1px solid var(--ep-border);
}

.ep-sidebar-open-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: 8px;
}

.ep-thumbnails-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ep-thumbnail-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  border: none;
  background: transparent;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ep-thumbnail-card:hover .ep-thumbnail-preview-wrap {
  border-color: var(--ep-border-strong);
}

.ep-thumbnail-card.active .ep-thumbnail-preview-wrap {
  border-color: var(--ep-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25), 0 4px 12px rgba(37, 99, 235, 0.16);
}

.ep-thumbnail-preview-wrap {
  width: 100%;
  background: #ffffff;
  border: 2px solid var(--ep-border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ep-thumbnail-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.ep-thumbnail-label {
  font-size: 0.75rem;
  color: var(--ep-text-muted);
  font-weight: 500;
  margin-top: 2px;
  line-height: 1.2;
}

.ep-thumbnail-card.active .ep-thumbnail-label {
  color: var(--ep-accent);
  font-weight: 700;
}

/* Center Workspace */
.ep-workspace {
  flex: 1;
  min-width: 0;
  background: var(--ep-bg);
  position: relative;
  overflow: auto;
  display: flex;
  padding: 0;
  box-sizing: border-box;
  touch-action: pan-x pan-y; /* allow single-finger scroll in all directions */
}

/* Immediate Session States (Zero-Flash on Refresh) */
html.ep-has-session #epDropzoneContainer,
body.ep-has-session #epDropzoneContainer,
.ep-has-document #epDropzoneContainer {
  display: none !important;
}

html.ep-has-session #epViewport,
body.ep-has-session #epViewport,
.ep-has-document #epViewport {
  display: flex !important;
}

/* Landing Dropzone */
.ep-dropzone-container {
  width: 100%;
  max-width: 580px;
  margin: auto;
  padding: 32px 16px;
  box-sizing: border-box;
  flex-shrink: 0;
}

.ep-dropzone-card {
  background: var(--ep-surface);
  border: 2px dashed var(--ep-border-strong);
  border-radius: 16px;
  padding: 48px 32px;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
}

.ep-dropzone-card.drag-over {
  border-color: var(--ep-accent);
  background: #eff6ff;
}

.ep-dropzone-icon {
  color: var(--ep-accent);
  margin-bottom: 16px;
}

.ep-dropzone-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--ep-text);
  font-family: 'Space Grotesk', sans-serif;
}

.ep-dropzone-subtitle {
  font-size: 0.9rem;
  color: var(--ep-text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.ep-dropzone-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.ep-dropzone-actions .ep-btn-primary {
  padding: 12px 28px;
  font-size: 0.95rem;
  border-radius: 10px;
}

.ep-dropzone-hint {
  font-size: 0.78rem;
  color: var(--ep-text-muted);
}

/* Viewport & Canvas Stack (Hidden until PDF is loaded) */
.ep-viewport {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  height: max-content;
  padding: 32px;
  box-sizing: border-box;
  margin: auto;
}

.ep-page-wrapper {
  position: relative;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.06);
  border-radius: 4px;
  background: #ffffff;
  user-select: none;
  border: 1px solid var(--ep-border);
  flex-shrink: 0;
  margin: auto;
}

.ep-pdf-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  z-index: 1;
}

.ep-fabric-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}

.canvas-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 2 !important;
}

.canvas-container,
.canvas-container .upper-canvas,
.canvas-container .lower-canvas {
  touch-action: pan-x pan-y !important;
}

body.ep-tool-draw .canvas-container .upper-canvas,
body.ep-tool-erase .canvas-container .upper-canvas,
body.ep-tool-move .canvas-container .upper-canvas,
body.ep-tool-shape .canvas-container .upper-canvas,
body.ep-tool-highlight .canvas-container .upper-canvas {
  touch-action: none !important;
}

body.ep-tool-move .canvas-container .upper-canvas,
body.ep-tool-move .canvas-container canvas {
  cursor: crosshair;
}

/* Hitbox Overlay for Detected Text */
.ep-hitbox-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: auto;
  touch-action: pan-x pan-y; /* don't block scroll when not tapping a hitbox */
}

.ep-hitbox {
  position: absolute;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.04);
  border-radius: 2px;
  outline: 1px dashed rgba(15, 23, 42, 0.28);
  transition: background 0.12s ease, outline 0.12s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Hitbox boundary: strict vertical bounds so adjacent lines never overlap */
.ep-hitbox::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -2px;
  right: -2px;
  pointer-events: auto;
}

/* Active & touch feedback: blue highlight on tap or hover matching desktop */
.ep-hitbox:hover,
.ep-hitbox:active,
.ep-hitbox:focus-visible {
  background: rgba(37, 99, 235, 0.10) !important;
  outline: 1.5px solid #2563eb !important;
  box-shadow: 0 0 6px rgba(37, 99, 235, 0.2);
}

.ep-hitbox.selected {
  background: rgba(37, 99, 235, 0.16);
  outline: 2px solid #2563eb;
  box-shadow: 0 0 6px rgba(37, 99, 235, 0.25);
}

/* Animated Hand Tap Gesture for Edit Text Mode */
.ep-edit-text-gesture {
  position: absolute;
  z-index: 120;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translate(-10px, -10px);
  animation: epGestureFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.ep-edit-text-gesture.fading-out {
  opacity: 0;
  transform: translate(-10px, -20px) scale(0.95);
}

.ep-gesture-ripple {
  position: absolute;
  top: 6px;
  left: 19px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.25);
  border: 1.5px solid #2563eb;
  transform: translate(-50%, -50%);
  animation: epTapRipple 1.6s cubic-bezier(0.2, 0.8, 0.4, 1) infinite;
}

@keyframes epTapRipple {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 1;
  }
  70% {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0.15;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.6);
    opacity: 0;
  }
}

.ep-gesture-hand {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff;
  color: #2563eb;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18), 0 0 0 1.5px rgba(37, 99, 235, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: epHandTap 1.5s cubic-bezier(0.25, 1, 0.5, 1) infinite;
  position: relative;
  z-index: 2;
}

@keyframes epHandTap {
  0%, 100% {
    transform: scale(1) translateY(0);
  }
  35% {
    transform: scale(0.92) translateY(-5px);
  }
  65% {
    transform: scale(1.03) translateY(-1px);
  }
}

.ep-gesture-pill {
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  animation: epPillFloat 1.5s ease-in-out infinite;
}

@keyframes epPillFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes epGestureFadeIn {
  0% { opacity: 0; transform: translate(-10px, 5px) scale(0.9); }
  100% { opacity: 1; transform: translate(-10px, -10px) scale(1); }
}

/* Non-editable text click feedback */
.ep-non-editable-hint {
  position: absolute;
  z-index: 130;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 5px 8px 5px 12px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(245, 158, 11, 0.4);
  pointer-events: auto;
  animation: epHintPop 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.ep-hint-ocr-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #2563eb;
  color: #ffffff !important;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  text-decoration: none;
  pointer-events: auto;
  cursor: pointer;
  margin-left: 2px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4);
  transition: all 0.15s ease;
}

.ep-hint-ocr-btn:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.5);
}

.ep-hint-ocr-btn svg {
  color: #ffffff !important;
}

.ep-non-editable-hint svg {
  color: #fbbf24;
  flex-shrink: 0;
}

.ep-non-editable-hint.fading-out {
  opacity: 0;
  transform: translateY(-6px) scale(0.95);
}

@keyframes epHintPop {
  0% { opacity: 0; transform: translateY(5px) scale(0.92); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.ep-non-editable-ripple {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #f59e0b;
  background: rgba(245, 158, 11, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: epNonEditablePulse 0.55s ease-out forwards;
}

@keyframes epNonEditablePulse {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.4); opacity: 0; }
}

/* Floating Banner for active mode (deprecated / replaced by interactive hand gesture) */
.ep-mode-banner {
  display: none !important;
}

@keyframes epBannerFadeIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.ep-banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ep-accent);
  box-shadow: 0 0 8px var(--ep-accent);
  animation: epDotPulse 1.5s infinite;
}

@keyframes epDotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.ep-banner-close {
  background: transparent;
  border: none;
  color: var(--ep-text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
}

.ep-banner-close:hover {
  color: var(--ep-text);
}

/* Right Sidebar (Properties Panel) */
.ep-props-panel {
  width: var(--ep-props-w);
  background: var(--ep-surface);
  border-left: 1px solid var(--ep-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 50;
}

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

.ep-props-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ep-text);
}

.ep-props-close {
  background: transparent;
  border: none;
  color: var(--ep-text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
}

.ep-props-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.ep-props-body::-webkit-scrollbar {
  width: 4px;
}

.ep-props-body::-webkit-scrollbar-track {
  background: transparent;
}

.ep-props-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

.ep-empty-props {
  text-align: center;
  padding: 40px 10px;
  color: var(--ep-text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ep-prop-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 4px;
}

.ep-prop-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ep-text-muted);
  margin-bottom: 2px;
}

.ep-prop-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ep-prop-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ep-text-placement {
  border-top: 1px solid var(--ep-border);
  padding-top: 12px;
}

.ep-text-placement-heading {
  color: var(--ep-text);
  font-size: 0.84rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.ep-text-placement-hint {
  color: var(--ep-text-muted);
  font-size: 0.76rem;
  line-height: 1.4;
  margin: 0 0 10px;
}

.ep-text-placement .ep-prop-col {
  min-width: 74px;
}

.ep-input, .ep-select {
  width: 100%;
  padding: 7px 10px;
  background: var(--ep-surface);
  border: 1px solid var(--ep-border-strong);
  border-radius: 6px;
  color: var(--ep-text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Custom styled select — remove browser default */
.ep-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  cursor: pointer;
}

.ep-select:hover {
  border-color: var(--ep-border-focus);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.ep-input:focus, .ep-select:focus {
  border-color: var(--ep-border-focus);
  box-shadow: 0 0 0 2px var(--ep-accent-glow);
}

/* ── Custom Select Dropdown (Matches Compress PDF Dropdown) ── */
.ep-custom-select {
  position: relative;
  width: 100%;
}

.ep-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  min-height: 42px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1.5px solid var(--ft-border-strong, #cbd5e1);
  border-radius: var(--ft-radius-sm, 8px);
  background-color: var(--ft-bg-surface, #ffffff);
  color: var(--ft-text-primary, #0f172a);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  text-align: left;
  user-select: none;
}

.ep-select-trigger:hover {
  border-color: var(--ft-text-muted, #94a3b8);
  background-color: var(--ft-bg-subtle, #f8fafc);
}

.ep-custom-select.is-open .ep-select-trigger,
.ep-select-trigger:focus-visible {
  outline: none;
  border-color: var(--ft-accent-blue, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  background-color: #ffffff;
}

.ep-select-value {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.875rem;
  color: var(--ft-text-primary, #0f172a);
}

.ep-select-chevron {
  flex-shrink: 0;
  color: var(--ft-text-secondary, #475569);
  transition: transform 0.2s ease, color 0.15s ease;
}

.ep-custom-select.is-open .ep-select-chevron {
  transform: rotate(180deg);
  color: var(--ft-accent-blue, #2563eb);
}

.ep-select-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background-color: #ffffff;
  border: 1.5px solid var(--ft-border-strong, #cbd5e1);
  border-radius: var(--ft-radius-sm, 8px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.14), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  max-height: 230px;
  overflow-y: auto;
  z-index: 1050;
  padding: 0.35rem;
  animation: epDropdownDown 140ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

.ep-custom-select.is-open .ep-select-dropdown {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ep-select-option {
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  color: var(--ft-text-primary, #0f172a);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ep-select-option:hover {
  background-color: #f1f5f9;
  color: #0f172a;
}

.ep-select-option.selected {
  background-color: #eff6ff;
  color: var(--ft-accent-blue, #2563eb);
  font-weight: 600;
}

.ep-number-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.ep-number-input-wrap .ep-input {
  padding-right: 28px;
}

.ep-unit {
  position: absolute;
  right: 8px;
  font-size: 0.75rem;
  color: var(--ep-text-muted);
  pointer-events: none;
}

.ep-color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ep-surface);
  border: 1px solid var(--ep-border-strong);
  border-radius: 6px;
  padding: 4px 8px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.ep-color-picker-wrap:hover {
  border-color: var(--ep-primary);
}

.ep-color-picker-wrap:has(.ep-color-preview-box) .ep-color-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
  padding: 0;
  border: none;
}

.ep-color-preview-box {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--ep-border);
  background-color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  position: relative;
  overflow: hidden;
}

.ep-color-preview-box.is-transparent {
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #ffffff !important;
}

.ep-color-preview-box.is-transparent::after {
  content: '';
  position: absolute;
  top: 50%;
  left: -2px;
  right: -2px;
  height: 2px;
  background: #ef4444;
  transform: rotate(-45deg);
}

.ep-btn-xs.active {
  background: var(--ep-primary) !important;
  color: #ffffff !important;
  border-color: var(--ep-primary) !important;
}

.ep-color-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--ep-border);
  background: none;
  cursor: pointer;
  padding: 0;
}

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

.ep-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.ep-color-hex {
  font-size: 0.78rem;
  font-family: monospace;
  color: var(--ep-text-muted);
}

.ep-btn-group {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--ep-surface-2);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--ep-border);
}

.ep-btn-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  min-width: 30px;
  padding: 0 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ep-text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1;
}

/* B / I / U specific letter styling & icons */
.ep-btn-toggle b,
.ep-btn-toggle i,
.ep-btn-toggle u,
.ep-btn-toggle svg {
  font-style: normal;
  font-size: 0.9rem;
  line-height: 1;
  pointer-events: none;
}
.ep-btn-toggle b {
  font-weight: 800;
  letter-spacing: -0.02em;
}
.ep-btn-toggle i {
  font-style: italic;
  font-weight: 600;
}
.ep-btn-toggle u {
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.ep-btn-toggle:hover {
  background: rgba(0,0,0,0.06);
  color: var(--ep-text);
}

.ep-btn-toggle.active {
  background: #ffffff;
  color: var(--ep-accent);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.18), 0 1px 2px rgba(0,0,0,0.08);
  font-weight: 700;
}

.ep-range-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ep-range {
  flex: 1;
  accent-color: var(--ep-accent);
}

.ep-range-val {
  font-size: 0.8rem;
  color: var(--ep-text-muted);
  min-width: 38px;
  text-align: right;
}

.ep-props-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ep-border);
  flex-shrink: 0;
}

.ep-props-actions[hidden] {
  display: none;
}

.ep-props-actions .ep-btn {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
}

.ep-manage-finalize {
  width: 100%;
  justify-content: center;
  padding: 8px 12px;
}

.ep-manage-delete {
  width: 100%;
  justify-content: center;
  padding: 8px 12px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.ep-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.ep-modal-card {
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: epModalSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.ep-modal-card-sm {
  max-width: 400px;
  padding: 32px 24px;
}

@keyframes epModalSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.ep-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ep-text);
  font-family: 'Space Grotesk', sans-serif;
}

.ep-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--ep-surface-2);
  border: 1px solid var(--ep-border);
  color: var(--ep-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.ep-modal-close:hover {
  background: var(--ep-surface-3);
  color: var(--ep-text);
  border-color: var(--ep-border-strong);
}

.ep-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-height: 0;
}

.ep-modal-desc {
  font-size: 0.85rem;
  color: var(--ep-text-muted);
  line-height: 1.5;
}

.ep-original-text-box {
  padding: 10px 14px;
  background: var(--ep-surface-2);
  border: 1px solid var(--ep-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ep-text);
  font-weight: 400;
  min-height: 40px;
  word-break: break-word;
}

.ep-replace-preview-container {
  padding: 14px 18px;
  background: #ffffff;
  border: 1px solid var(--ep-border-strong);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: all 0.15s ease;
}

#epReplaceModal .ep-modal-card {
  max-height: calc(100dvh - 32px);
}

#epReplaceModal .ep-modal-body {
  min-height: 0;
  overflow-y: auto;
}

#epReplaceModal .ep-input {
  border: 1.5px solid var(--ft-border-strong, #cbd5e1);
  border-radius: var(--ft-radius-sm, 8px);
  padding: 0.65rem 0.85rem;
  font-size: 0.875rem;
  min-height: 42px;
  background-color: var(--ft-bg-surface, #ffffff);
  color: var(--ft-text-primary, #0f172a);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#epReplaceModal .ep-input:hover {
  border-color: var(--ft-text-muted, #94a3b8);
}

#epReplaceModal .ep-input:focus {
  outline: none;
  border-color: var(--ft-accent-blue, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

#epReplaceModal .ep-number-input-wrap .ep-input {
  padding-right: 32px;
}

#epReplaceModal .ep-unit {
  right: 12px;
  color: var(--ft-text-secondary, #475569);
  font-weight: 500;
  font-size: 0.82rem;
}

.ep-replace-style-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ep-replace-style-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ep-replace-style-btn {
  gap: 8px;
  height: 38px;
  border: 1px solid var(--ep-border-strong);
  background: var(--ep-surface-2);
  font-size: 0.82rem;
}

.ep-replace-style-btn.active {
  border-color: var(--ep-accent);
  background: var(--ep-accent-glow);
}

.ep-modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--ep-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--ep-surface-2);
  flex-shrink: 0;
}

#epSignatureModal .ep-modal-card {
  max-width: 480px;
}

/* Modal Tabs */
.ep-tabs, .ep-modal-tabs {
  display: flex;
  gap: 6px;
  background: var(--ep-surface-2);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--ep-border);
}

.ep-tab, .ep-modal-tab {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ep-text-muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  font-family: inherit;
}

.ep-tab:hover, .ep-modal-tab:hover {
  color: var(--ep-text);
}

.ep-tab.active, .ep-modal-tab.active {
  background: #ffffff;
  border-color: var(--ep-border);
  color: var(--ep-accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ep-sig-canvas-wrap {
  position: relative;
  border: 1px solid var(--ep-border-strong);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  height: 180px;
  max-height: 180px;
}

.ep-sig-canvas,
#epSigPadCanvas {
  width: 100% !important;
  height: 180px !important;
  max-height: 180px !important;
  display: block;
  cursor: crosshair;
  background: #ffffff;
  touch-action: none;
}

.ep-sig-clear-btn {
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 5px 14px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--ep-border-strong);
  color: var(--ep-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.15s ease;
  z-index: 10;
  font-family: inherit;
}

.ep-sig-clear-btn:hover {
  background: #fee2e2;
  color: #ef4444;
  border-color: #fca5a5;
}

.ep-sig-tools {
  padding: 8px 12px;
  background: var(--ep-surface);
  border-top: 1px solid var(--ep-border);
  display: flex;
  justify-content: flex-end;
}

.ep-sig-upload-box {
  border: 2px dashed var(--ep-border-strong);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  background: var(--ep-surface-2);
  transition: all 0.15s;
}

.ep-sig-upload-box:hover {
  background: #eff6ff;
  border-color: var(--ep-accent);
}

.ep-sig-type-preview {
  padding: 32px 24px;
  margin-top: 16px;
  border: 1.5px solid var(--ep-border);
  border-radius: 10px;
  text-align: center;
  font-size: 2.4rem;
  line-height: 1.4;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #0f172a;
  font-family: 'Dancing Script', cursive;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.06);
  word-break: break-word;
  overflow-wrap: break-word;
}

.ep-sig-font-dancing {
  font-family: 'Dancing Script', cursive;
}

/* Spinner */
.ft-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--ep-accent);
  border-radius: 50%;
  animation: epSpin 0.75s linear infinite;
}

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

/* Toast Notifications — Minimal & Professional Tool Page Design */
.ep-toast:not(.error):not(.success) {
  display: none !important;
}

.ep-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #ffffff;
  color: #1e293b;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #0f172a;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.05);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: epToastIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 540px;
}

.ep-toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.ep-toast-text {
  line-height: 1.45;
  color: #1e293b;
  font-size: 0.84rem;
}

.ep-toast-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #ffffff !important;
  font-size: 0.80rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 7px;
  text-decoration: none;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ep-toast-action-btn:hover {
  background: linear-gradient(135deg, #ea580c, #c2410c);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.4);
  color: #ffffff !important;
}

.ep-toast-action-btn svg {
  color: #ffffff !important;
}

.ep-toast.error {
  background: #ffffff;
  border-color: #fed7aa;
  border-left: 4px solid #f97316;
  color: #1e293b;
}

.ep-toast.error svg:first-child {
  color: #ea580c;
}

.ep-toast.success {
  background: #ffffff;
  border-color: #bbf7d0;
  border-left: 4px solid #10b981;
  color: #1e293b;
}

.ep-toast.success svg:first-child {
  color: #10b981;
}

@keyframes epToastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Z-INDEX LAYER SCHEME (canonical)
   1   PDF canvas
   2   Fabric overlay + canvas-container
   3   Hitbox overlay
   4   Highlight preview layer
   50  Sidebars (desktop)
   80  Mode banner
   100 Floating highlight toolbar
   120 Toolbar / header
   150 Mobile slide-over panels
   200 Modals / backdrops
   250 Mobile full-width props panel
   300 Toasts
   ========================================================================== */

/* ==========================================================================
   CSS Custom Properties — Responsive Tokens
   ========================================================================== */
:root {
  --ep-header-h: 56px;
  --ep-toolbar-h: 50px;
  --ep-sidebar-w: 210px;
  --ep-props-w: 288px;
  /* Safe areas — fall back to 0 on devices without notches */
  --ep-safe-top: env(safe-area-inset-top, 0px);
  --ep-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ep-safe-left: env(safe-area-inset-left, 0px);
  --ep-safe-right: env(safe-area-inset-right, 0px);
}

/* ==========================================================================
   Base — Use dvh where available for better mobile viewport handling
   ========================================================================== */
body.edit-pdf-body {
  height: 100vh;
  height: 100dvh; /* modern browsers — handles address bar / keyboard */
  /* Prevent accidental body scroll on touch devices */
  overscroll-behavior: none;
}

/* Full-height main layout */
.ep-main-layout {
  height: calc(100vh - var(--ep-header-h) - var(--ep-toolbar-h));
  height: calc(100dvh - var(--ep-header-h) - var(--ep-toolbar-h));
}

/* ==========================================================================
   High-DPI Canvas Hint (applied via renderPage in JS — CSS only does layout)
   The JS already caps DPR correctly; no CSS transform hacks needed.
   ========================================================================== */

/* ==========================================================================
   BREAKPOINT: ≤ 1280px — Compact Desktop / Laptop Scaling
   ========================================================================== */
@media (max-width: 1280px) {
  :root {
    --ep-sidebar-w: 185px;
    --ep-props-w: 272px;
  }

  .ep-toolbar {
    padding: 0 8px;
  }

  .ep-toolbar-inner {
    gap: 3px;
  }

  .ep-tool-btn {
    padding: 5px 8px;
    font-size: 0.8rem;
    gap: 4px;
  }

  .ep-tool-sep {
    margin: 0 2px;
  }

  .ep-zoom-group {
    gap: 2px;
  }

  .ep-zoom-val {
    padding: 2px 5px;
    font-size: 0.78rem;
  }
}

/* ==========================================================================
   BREAKPOINT: ≤ 1024px  — Small Desktop / Large Tablet Landscape
   ========================================================================== */
@media (max-width: 1024px) {
  :root {
    --ep-sidebar-w: 160px;
    --ep-props-w: 260px;
  }

  .ep-doc-name-wrap {
    max-width: 180px;
  }

  .ep-app-title {
    font-size: 0.95rem;
  }
}

/* ==========================================================================
   BREAKPOINT: ≤ 1100px  — Tablets (iPad Pro, iPad Air, Galaxy Tab) & Phablets
   Sidebars become slide-over drawers; toolbar scrolls horizontally.
   Full 100% canvas workspace space for PDF.
   ========================================================================== */
@media (max-width: 1100px) {
  /* Hide file name on narrow viewports to avoid header overflow */
  .ep-doc-name-wrap {
    max-width: 130px;
  }

  /* Toolbar: horizontal scroll strip with touch momentum */
  .ep-toolbar {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
    width: 100%;
    max-width: 100vw;
  }

  .ep-toolbar::-webkit-scrollbar {
    display: none;
  }

  .ep-toolbar-inner {
    width: max-content;
    min-width: 100%;
    padding-right: 12px;
    gap: 4px;
  }

  /* Slide-over LEFT sidebar (Page Thumbnails) */
  .ep-sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 250px;
    max-width: 80vw;
    transform: translateX(-100%);
    box-shadow: 12px 0 35px rgba(0, 0, 0, 0.2);
    z-index: 150;
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .ep-sidebar.open {
    transform: translateX(0);
  }

  /* Bottom Sheet properties panel on Tablet & Mobile (slides up from down side) */
  .ep-props-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 680px;
    margin: 0 auto;
    height: auto;
    max-height: 65dvh;
    border-radius: 20px 20px 0 0;
    border-left: 1px solid var(--ep-border);
    border-right: 1px solid var(--ep-border);
    border-top: 1px solid var(--ep-border);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.22);
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 250;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--ep-safe-bottom, 8px);
    background: var(--ep-surface);
  }

  .ep-props-panel.open {
    transform: translateY(0);
  }

  .ep-props-header {
    padding: 10px 16px;
    position: relative;
  }

  .ep-props-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--ep-border-strong);
    border-radius: 2px;
  }

  .ep-props-body {
    padding: 8px 16px 18px;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ep-props-close {
    display: flex !important;
  }

  /* Show tablet/mobile toggle buttons in toolbar */
  .ep-mobile-only {
    display: inline-flex !important;
  }

  /* Pages button positioned first on mobile/tablet — prominent & highlighted */
  .ep-pages-nav-btn {
    font-weight: 600;
  }
  .ep-pages-nav-btn.active {
    background: var(--ep-accent-light) !important;
    color: var(--ep-accent) !important;
    border-color: var(--ep-accent) !important;
  }
  .ep-page-indicator {
    cursor: pointer;
  }

  /* Workspace fills all available space on tablet */
  .ep-workspace {
    padding: 0;
    width: 100%;
    max-width: 100vw;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }
  .ep-viewport {
    padding: 16px;
    margin: 0 auto;
    min-height: 100%;
  }

  /* Make touch targets comfortable (min 44px) */
  .ep-tool-btn {
    padding: 8px 10px;
    min-height: 44px;
  }

  .ep-icon-btn {
    width: 40px;
    height: 40px;
  }

  /* Undo/Redo stay compact in pill — don't blow up with the generic icon-btn size */
  .ep-history-group .ep-icon-btn {
    width: 40px;
    height: 40px;
  }

  /* Tighten header-center gap on tablet so pill sits flush */
  .ep-header-center {
    gap: 8px;
  }

  /* Panel overlay scrim — close panels when tapping workspace */
  .ep-panel-scrim {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 140;
    background: rgba(15, 23, 42, 0.3);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .ep-panel-scrim.visible {
    display: block;
  }
}

/* ==========================================================================
   BREAKPOINT: ≤ 600px  — Phone / Small Mobile (iPhone, Galaxy, Pixel)
   Full redesign: bottom-sheet properties, ultra-compact header, touch toolbar.
   ========================================================================== */
@media (max-width: 600px) {
  /* Use smaller base height tokens */
  :root {
    --ep-header-h: 52px;
    --ep-toolbar-h: 48px;
  }

  /* --- HEADER --- */
  .ep-header {
    height: var(--ep-header-h);
    padding: 0 8px;
    padding-left: max(8px, var(--ep-safe-left));
    padding-right: max(8px, var(--ep-safe-right));
    width: 100%;
    max-width: 100vw;
  }

  .ep-header-left,
  .ep-header-right {
    gap: 6px;
  }

  /* Mobile brand: compact logo icon links directly back to tools/home */
  .ep-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 3px;
    margin: 0;
    border-radius: 8px;
  }

  .ep-logo {
    width: 22px;
    height: 22px;
  }

  /* Hide brand text, document filename & legacy back btn on mobile */
  .ep-titles,
  .ep-doc-name-wrap,
  .ep-back-btn {
    display: none !important;
  }

  /* Close doc button on mobile: prominent, compact, easy to tap */
  .ep-close-doc-btn {
    height: 30px;
    padding: 0 8px;
    font-size: 0.74rem;
    gap: 3px;
    border-radius: 7px;
  }

  @media (max-width: 400px) {
    .ep-close-doc-btn {
      width: 30px;
      padding: 0;
      justify-content: center;
    }
    .ep-close-doc-text {
      display: none !important;
    }
  }

  /* Keep Undo/Redo & Page indicator visible and compact on mobile */
  .ep-header-center {
    display: flex !important;
    align-items: center;
    gap: 4px;
  }

  .ep-header-center .ep-icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 4px;
  }

  .ep-page-indicator {
    padding: 2px 6px;
    font-size: 0.72rem;
    font-weight: 600;
  }

  .ep-divider-v {
    display: none !important;
  }

  /* "Open PDF" upload btn on phone: "Open" label with plenty of free breathing room */
  .ep-btn-label-desktop {
    display: none !important;
  }

  .ep-btn-label-mobile {
    display: inline !important;
  }

  #epChangePdfBtn {
    display: inline-flex !important;
    padding: 5px 8px;
    font-size: 0.78rem;
    gap: 3px;
    border-radius: 7px;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    height: 32px;
  }

  @media (max-width: 340px) {
    .ep-btn-label-mobile {
      display: none !important;
    }
    #epChangePdfBtn {
      padding: 5px;
      width: 32px;
      min-width: 32px;
    }
  }

  /* Export btn on mobile: download icon button only */
  #epExportBtn {
    padding: 5px 8px;
    font-size: 0.8rem;
    gap: 0;
    border-radius: 7px;
    min-width: 32px;
    width: 32px;
    height: 32px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  #epExportBtn span {
    display: none !important;
  }

  #epExportBtn svg {
    width: 16px;
    height: 16px;
    margin: 0;
  }

  /* --- TOOLBAR --- */
  .ep-toolbar {
    height: var(--ep-toolbar-h);
    padding: 0 6px;
    padding-left: max(6px, var(--ep-safe-left));
  }

  .ep-toolbar-inner {
    gap: 2px;
  }

  /* Compact tool buttons — icon + tiny label, min 44px tall */
  .ep-tool-btn {
    padding: 6px 9px;
    font-size: 0.78rem;
    gap: 4px;
    min-height: 44px;
    border-radius: 6px;
  }

  /* Hide separator dots on very narrow screens */
  .ep-tool-sep {
    margin: 0 2px;
  }

  /* Zoom group — compact */
  .ep-zoom-group {
    gap: 2px;
  }

  .ep-zoom-val {
    min-width: 34px;
    font-size: 0.75rem;
  }

  .ep-icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  /* --- WORKSPACE --- */
  .ep-workspace {
    padding: 0;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    touch-action: pan-x pan-y;
  }
  .ep-viewport {
    padding: 8px 6px;
    padding-bottom: calc(16px + var(--ep-safe-bottom));
    min-height: 100%;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .ep-page-wrapper {
    margin: 4px auto;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
    box-sizing: content-box;
  }

  /* --- MAIN LAYOUT --- */
  .ep-main-layout {
    /* Reserve space for bottom sheet handle when panel is open */
    height: calc(100dvh - var(--ep-header-h) - var(--ep-toolbar-h));
  }

  /* --- SIDEBARS → Full-width bottom-positioned drawers on mobile --- */

  /* Left sidebar (Pages): transforms into a modern BOTTOM SHEET with SIDEWAYS scrolling */
  .ep-sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: auto;
    max-height: 330px;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--ep-border);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.2);
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 245;
    display: flex;
    flex-direction: column;
    padding-bottom: max(12px, var(--ep-safe-bottom));
  }

  .ep-sidebar.open {
    transform: translateY(0);
  }

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

  .ep-sidebar-close {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--ep-surface-2);
    color: var(--ep-text-muted);
    cursor: pointer;
  }

  .ep-sidebar-actions {
    padding: 6px 16px 2px 16px;
    border-bottom: none;
  }

  .ep-sidebar-open-btn {
    padding: 6px 12px;
    font-size: 0.78rem;
  }

  /* Horizontal sideways scroll strip for page previews */
  .ep-thumbnails-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 16px 16px 16px;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .ep-thumbnail-card {
    flex-shrink: 0;
    width: 96px;
    padding: 2px 2px 6px 2px;
    scroll-snap-align: center;
    border-radius: 8px;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .ep-thumbnail-card.active {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .ep-thumbnail-preview-wrap {
    min-height: 110px;
    border-radius: 8px;
    border: 2px solid var(--ep-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }

  .ep-thumbnail-card.active .ep-thumbnail-preview-wrap {
    border: 2.5px solid var(--ep-accent) !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25), 0 4px 12px rgba(37, 99, 235, 0.2) !important;
  }

  .ep-thumbnail-label {
    font-size: 0.75rem;
    margin-top: 6px;
    line-height: 1.2;
    display: inline-block;
    text-align: center;
  }

  .ep-thumbnail-card.active .ep-thumbnail-label {
    color: var(--ep-accent) !important;
    font-weight: 700 !important;
  }

  /* Right properties panel: transform into BOTTOM SHEET on mobile */
  .ep-props-panel {
    /* Position: stick to bottom, slide up */
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: auto;
    max-height: 65dvh;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--ep-border);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.2);
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 250;
    /* Allow internal scroll */
    display: flex;
    flex-direction: column;
    /* Safe area */
    padding-bottom: var(--ep-safe-bottom);
  }

  .ep-props-panel.open {
    transform: translateY(0);
  }

  /* Pull handle above bottom sheet */
  .ep-props-header {
    padding: 10px 16px;
    /* Show drag handle */
    position: relative;
  }

  .ep-props-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--ep-border-strong);
    border-radius: 2px;
  }

  .ep-props-body {
    padding: 8px 14px 16px;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Always show close button */
  .ep-props-close {
    display: block;
    width: 32px;
    height: 32px;
    background: var(--ep-surface-2);
    border-radius: 50%;
    border: 1px solid var(--ep-border);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* --- MODALS --- */
  .ep-modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .ep-modal-card {
    width: 100vw;
    max-width: 100vw;
    border-radius: 18px 18px 0 0;
    max-height: 92dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Safe area */
    padding-bottom: var(--ep-safe-bottom);
    animation: epModalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .ep-modal-card-sm {
    max-width: 100vw;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(24px + var(--ep-safe-bottom));
  }

  /* Signature drawing canvas — larger on mobile for finger signing */
  .ep-sig-canvas {
    height: 200px;
    touch-action: none; /* Prevent page scroll while drawing */
  }

  /* --- INPUTS — prevent iOS auto-zoom (font-size >= 16px) --- */
  .ep-input,
  .ep-select,
  input[type="text"],
  input[type="number"],
  textarea {
    font-size: max(16px, 0.85rem) !important;
  }

  /* --- TOASTS --- */
  .ep-toast {
    bottom: calc(16px + var(--ep-safe-bottom));
    right: 10px;
    left: 10px;
    padding: 8px 12px;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    max-width: calc(100vw - 20px);
    border-radius: 10px;
  }

  .ep-toast-action-btn {
    padding: 4px 9px;
    font-size: 0.74rem;
  }

  /* --- HIGHLIGHT TOAST --- */
  .ep-highlight-toast {
    bottom: calc(20px + var(--ep-safe-bottom));
    font-size: 0.78rem;
    padding: 7px 12px;
    max-width: calc(100vw - 24px);
  }

  /* --- MODE BANNER --- */
  .ep-mode-banner {
    bottom: calc(16px + var(--ep-safe-bottom));
    font-size: 0.8rem;
    padding: 7px 14px;
  }

  /* --- FLOATING HIGHLIGHT TOOLBAR --- */
  .ep-floating-hl-toolbar {
    padding: 6px 8px;
    gap: 6px;
    border-radius: 24px;
    /* On mobile, position near bottom to avoid keyboard conflicts */
    max-width: calc(100vw - 24px);
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  /* Larger touch targets for float dots */
  .ep-float-dot {
    width: 22px;
    height: 22px;
  }

  /* --- THUMBNAIL CARDS — more compact in drawer --- */
  .ep-thumbnail-card {
    padding: 5px;
  }

  /* --- DROPZONE CARD — fill screen nicely --- */
  .ep-dropzone-container {
    width: 100%;
    max-width: 100%;
    padding: 16px 12px;
  }

  .ep-dropzone-card {
    padding: 32px 16px;
    border-radius: 12px;
  }

  .ep-dropzone-title {
    font-size: 1.15rem;
  }

  .ep-dropzone-subtitle {
    font-size: 0.84rem;
  }

  /* --- PROPERTY INPUTS — single column on narrow screens --- */
  .ep-prop-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .ep-prop-col {
    min-width: 120px;
  }

  /* Color dot swatches — larger tap target */
  .ep-hl-color-dot,
  .ep-hl-color-custom-btn {
    width: 28px;
    height: 28px;
  }
}

/* ==========================================================================
   BREAKPOINT: ≤ 380px  — Very Small Phones (320px–380px)
   ========================================================================== */
@media (max-width: 380px) {
  .ep-tool-btn {
    padding: 5px 7px;
    font-size: 0.74rem;
  }

  .ep-tool-btn span {
    display: none; /* Icon only at this width */
  }

  /* Re-show icons — keep icon-only mode */
  .ep-tool-btn svg {
    flex-shrink: 0;
  }

  /* Pages + Props toggles — keep visible in icon-only mode */
  #epToggleThumbnailsBtn span,
  #epTogglePropsBtn span {
    display: none;
  }

  .ep-props-panel {
    max-height: 72dvh;
  }

  .ep-props-body {
    max-height: none;
  }
}

/* ==========================================================================
   BREAKPOINT: ≥ 1101px Desktop — Permanent Sidebars & Full Workspace
   ========================================================================== */
@media (min-width: 1101px) {
  /* Scrim not used on desktop */
  .ep-panel-scrim {
    display: none !important;
  }

  /* Props panel always visible on desktop — never a bottom sheet */
  .ep-props-panel {
    position: static;
    width: var(--ep-props-w);
    max-width: var(--ep-props-w);
    max-height: none;
    transform: none !important;
    border-radius: 0;
    border-left: 1px solid var(--ep-border);
    border-top: none;
    box-shadow: none;
    padding-bottom: 0;
  }

  .ep-props-header::before {
    display: none;
  }

  .ep-props-close {
    display: none !important;
  }

  /* Mobile only hidden on desktop */
  .ep-mobile-only {
    display: none !important;
  }

  /* Sidebar always visible on desktop */
  .ep-sidebar {
    position: static;
    width: var(--ep-sidebar-w);
    max-width: none;
    transform: none !important;
    box-shadow: none;
  }
}

/* ==========================================================================
   BREAKPOINT: ≥ 1400px — Large Monitors: constrain panel widths
   ========================================================================== */
@media (min-width: 1400px) {
  :root {
    --ep-sidebar-w: 220px;
    --ep-props-w: 300px;
  }
}

@media (min-width: 1920px) {
  :root {
    --ep-sidebar-w: 240px;
    --ep-props-w: 316px;
  }

  /* On very large screens, center the main area */
  .ep-workspace {
    padding: 0;
  }
  .ep-viewport {
    padding: 40px;
  }
}

/* ==========================================================================
   ORIENTATION: Landscape phones — ensure toolbar + workspace fit
   ========================================================================== */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --ep-header-h: 44px;
    --ep-toolbar-h: 42px;
  }

  .ep-header {
    height: var(--ep-header-h);
  }

  .ep-toolbar {
    height: var(--ep-toolbar-h);
  }

  .ep-tool-btn {
    padding: 4px 9px;
    min-height: 40px;
  }

  /* Properties bottom sheet shorter in landscape */
  .ep-props-panel {
    max-height: 55dvh !important;
  }

  .ep-props-body {
    max-height: none !important;
  }

  /* Sig canvas taller in landscape — good for drawing */
  .ep-sig-canvas {
    height: 140px;
  }

  .ep-workspace {
    padding: 0;
  }
  .ep-viewport {
    padding: 8px 6px;
  }
}

/* ==========================================================================
   TOUCH DEVICE ENHANCEMENTS
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
  /* Touch: increase handle size for Fabric controls via larger padding */
  .ep-tool-btn {
    min-height: 44px;
  }

  .ep-icon-btn {
    min-width: 40px;
    min-height: 40px;
  }

  .ep-btn {
    min-height: 40px;
  }

  .ep-tab, .ep-modal-tab {
    min-height: 40px;
    padding: 10px 14px;
  }

  /* Slightly larger color dots */
  .ep-hl-color-dot,
  .ep-float-dot {
    width: 26px;
    height: 26px;
  }

  .ep-hl-color-custom-btn,
  .ep-float-custom {
    width: 26px;
    height: 26px;
  }

  /* Disable hover effects that don't work on touch */
  .ep-btn-primary:hover:not(:disabled) {
    transform: none;
  }

  /* Signature canvas: prevent scroll during draw */
  .ep-sig-canvas-wrap {
    touch-action: none;
  }
}

/* ==========================================================================
   iOS Safari — Prevent common quirks
   ========================================================================== */
@supports (-webkit-touch-callout: none) {
  /* Prevent callout on long-press */
  .ep-page-wrapper,
  .ep-fabric-canvas,
  .ep-pdf-canvas {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Fix fixed-position bottom sheet clipping behind Safari toolbar */
  .ep-props-panel {
    padding-bottom: max(var(--ep-safe-bottom), 8px);
  }

  /* Fix 100vh on iOS — already handled by dvh, but Safari compat */
  body.edit-pdf-body {
    min-height: -webkit-fill-available;
  }
}

/* ==========================================================================
   Accessibility — Respect reduced-motion preference
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ep-sidebar,
  .ep-props-panel,
  .ep-modal-card {
    transition: none !important;
    animation: none !important;
  }

  .ep-mode-banner,
  .ep-toast,
  .ep-floating-hl-toolbar {
    animation: none !important;
  }
}

/* ==========================================================================
   Print — Hide editor chrome
   ========================================================================== */
@media print {
  .ep-header,
  .ep-toolbar,
  .ep-sidebar,
  .ep-props-panel,
  .ep-mode-banner,
  .ep-toast {
    display: none !important;
  }

  .ep-workspace {
    padding: 0 !important;
  }
}


/* ==========================================================================
   Highlight Feature Upgrade (Smart Text Snapping, Floating Bar & Live Preview)
   ========================================================================== */

/* Active Color Badge on Toolbar Button */
.ep-hl-swatch-badge {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-left: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.ep-dropdown-arrow-icon {
  display: inline-flex;
  align-items: center;
  margin-left: 1px;
  opacity: 0.65;
  transition: transform 0.15s ease;
}

.ep-dropdown-wrap.open .ep-dropdown-arrow-icon {
  transform: rotate(180deg);
}

/* Highlight Dropdown Menu */
.ep-highlight-menu {
  min-width: 220px;
  padding: 8px;
}

.ep-hl-menu-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ep-hl-menu-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ep-text-muted);
  padding: 2px 6px;
}

.ep-highlight-menu .ep-dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}

.ep-highlight-menu .ep-dropdown-item.active {
  background: var(--ep-accent-subtle);
  border-color: rgba(37, 99, 235, 0.2);
  color: var(--ep-accent);
}

.ep-hl-item-info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.ep-hl-item-info strong {
  font-size: 0.82rem;
  font-weight: 600;
}

.ep-hl-item-info small {
  font-size: 0.72rem;
  color: var(--ep-text-muted);
}

/* Color Swatches Grid */
.ep-hl-quick-colors {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  flex-wrap: wrap;
}

.ep-hl-color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1, 0 1px 2px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
}

.ep-hl-color-dot:hover {
  transform: scale(1.18);
  box-shadow: 0 0 0 1.5px var(--ep-accent), 0 2px 5px rgba(0, 0, 0, 0.2);
}

.ep-hl-color-dot.active {
  transform: scale(1.18);
  box-shadow: 0 0 0 2px var(--ep-accent), 0 2px 6px rgba(37, 99, 235, 0.3);
}

.ep-hl-color-custom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px dashed #94a3b8;
  background: #f8fafc;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  color: #64748b;
  transition: all 0.12s ease;
}

.ep-hl-color-custom-btn:hover {
  border-color: var(--ep-accent);
  color: var(--ep-accent);
  background: #eff6ff;
}

.ep-hl-color-custom-btn input[type="color"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Live Preview Overlay */
.ep-highlight-preview-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.ep-hl-preview-box {
  position: absolute;
  border-radius: 2px;
  pointer-events: none;
  transition: all 0.05s ease-out;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
}

/* Contextual Floating Toolbar */
.ep-floating-hl-toolbar {
  position: absolute;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid var(--ep-border);
  border-radius: 30px;
  box-shadow: 0 10px 25px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -2px rgba(15, 23, 42, 0.05);
  transform: translate(-50%, -100%);
  animation: epPopIn 0.14s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  user-select: none;
}

@keyframes epPopIn {
  0% { opacity: 0; transform: translate(-50%, -85%) scale(0.95); }
  100% { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}

.ep-float-hl-colors {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ep-float-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.ep-float-dot:hover,
.ep-float-dot.active {
  transform: scale(1.22);
  box-shadow: 0 0 0 2px var(--ep-accent);
}

.ep-float-custom {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px dashed #94a3b8;
  cursor: pointer;
  overflow: hidden;
  color: #64748b;
}

.ep-float-custom input[type="color"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.ep-float-sep {
  width: 1px;
  height: 18px;
  background: var(--ep-border);
}

.ep-float-opacity-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ep-float-opacity-slider {
  width: 60px;
  height: 4px;
  accent-color: var(--ep-accent);
  cursor: pointer;
}

.ep-float-opacity-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ep-text-muted);
  min-width: 26px;
}

.ep-float-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--ep-border);
  background: transparent;
  color: var(--ep-text);
  cursor: pointer;
  transition: all 0.12s;
}

.ep-float-btn:hover {
  background: var(--ep-surface-3);
}

.ep-float-btn-delete {
  color: var(--ep-danger);
  border-color: #fee2e2;
  background: #fef2f2;
}

.ep-float-btn-delete:hover {
  background: #fee2e2;
}

.ep-float-btn-find {
  color: var(--ep-accent);
  border-color: #dbeafe;
  background: #eff6ff;
}

.ep-float-btn-find:hover {
  background: #dbeafe;
}

/* Toast Hint for Non-Selectable Text & First Use */
.ep-highlight-toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 0.82rem;
  border-radius: 24px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 120;
  animation: epToastSlide 0.2s ease-out;
  pointer-events: auto;
}

@keyframes epToastSlide {
  0% { opacity: 0; transform: translate(-50%, 12px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

.ep-highlight-toast-action {
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.ep-highlight-toast-action:hover {
  background: #1d4ed8;
}

/* Cursor when highlight mode is active */
.ep-highlight-active-canvas {
  cursor: text !important;
}

.ep-highlight-active-canvas.ep-hl-mode-area {
  cursor: crosshair !important;
}

/* ==========================================================================
   Zoom Controls:
   - On Desktop/Laptop (≥ 1101px): Top toolbar beside shapes (#epTopZoomGroup)
   - On Mobile/Tablet (≤ 1100px): Bottom floating pill (.ep-floating-zoom)
   ========================================================================== */
.ep-desktop-only {
  display: inline-flex;
}

#epTopZoomGroup,
.ep-zoom-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 0;
  flex-shrink: 0;
}

@media (max-width: 1100px) {
  .ep-desktop-only,
  #epTopZoomGroup,
  .ep-zoom-group {
    display: none !important;
  }
}

.ep-floating-zoom {
  display: none;
  position: fixed;
  bottom: calc(18px + var(--ep-safe-bottom));
  right: max(16px, var(--ep-safe-right));
  z-index: 125;
  align-items: center;
  gap: 2px;
  background: var(--ep-surface, #ffffff);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--ep-border, #e2e8f0);
  border-radius: 9999px;
  padding: 3px 6px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
  transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}

/* Floating zoom ONLY for touch / mobile / tablet devices (width <= 1100px) */
@media (max-width: 1100px) {
  body.ep-has-document .ep-floating-zoom,
  html.ep-has-session .ep-floating-zoom {
    display: flex;
  }
}

/* Strictly hide floating zoom on desktop / laptop so it NEVER overlaps properties sidebar */
@media (min-width: 1101px) {
  .ep-floating-zoom {
    display: none !important;
  }
}

/* Hide or tuck away when bottom drawer or modal is open */
body.ep-panel-open .ep-floating-zoom,
body.modal-open .ep-floating-zoom,
.ep-sidebar.open ~ .ep-floating-zoom,
.ep-props-panel.open ~ .ep-floating-zoom {
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px) scale(0.95);
}

.ep-float-zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--ep-text, #334155);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
  touch-action: manipulation;
}

.ep-float-zoom-btn:hover {
  background: var(--ep-hover, rgba(0, 0, 0, 0.06));
  color: var(--ep-text, #0f172a);
}

.ep-float-zoom-btn:active {
  background: rgba(0, 0, 0, 0.1);
}

.ep-float-zoom-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: transparent;
}

.ep-float-zoom-val-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  height: 32px;
  min-width: 44px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--ep-text, #1e293b);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.15s ease;
  touch-action: manipulation;
}

.ep-float-zoom-val-btn:hover {
  background: var(--ep-hover, rgba(0, 0, 0, 0.06));
}

.ep-float-zoom-sep {
  width: 1px;
  height: 18px;
  background: var(--ep-border, #e2e8f0);
  margin: 0 2px;
}

/* OCR Scanning Progress Bar */
.ep-ocr-scan-banner {
  position: fixed;
  top: calc(var(--ep-header-h) + var(--ep-toolbar-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ep-border, #e2e8f0);
  border-radius: 24px;
  padding: 8px 18px 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
  color: var(--ep-text, #0f172a);
  font-size: 0.84rem;
  font-weight: 600;
  pointer-events: none;
  animation: epOcrSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.ep-ocr-scan-banner.ep-fading {
  opacity: 0;
  transform: translate(-50%, -8px);
}

.ep-ocr-scan-icon {
  width: 18px;
  height: 18px;
  color: #2563eb;
  animation: epOcrSpin 1.4s linear infinite;
  flex-shrink: 0;
}

.ep-ocr-scan-banner.ep-complete .ep-ocr-scan-icon {
  animation: none;
  color: #16a34a;
}

.ep-ocr-scan-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  max-width: 240px;
}

.ep-ocr-scan-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ep-ocr-scan-banner.ep-complete .ep-ocr-scan-text {
  color: #16a34a;
}

.ep-ocr-progress-track {
  width: 100%;
  height: 4px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.ep-ocr-progress-fill {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, #2563eb, #38bdf8, #60a5fa, #2563eb);
  background-size: 200% 100%;
  border-radius: 99px;
  transition: width 0.2s cubic-bezier(0.2, 0.8, 0.4, 1);
  animation: epOcrShimmer 1.8s linear infinite;
}

.ep-ocr-scan-banner.ep-complete .ep-ocr-progress-fill {
  width: 100% !important;
  background: #16a34a;
  animation: none;
}

.ep-ocr-scan-laser {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.35), #38bdf8, #2563eb, #38bdf8, rgba(56, 189, 248, 0.35), transparent);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.8), 0 0 3px rgba(37, 99, 235, 0.9);
  pointer-events: none;
  z-index: 25;
  top: 0;
  animation: epOcrLaserSweep 2.2s ease-in-out infinite alternate;
  border-radius: 99px;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.ep-ocr-scan-laser.ep-fading {
  opacity: 0;
}

@media (max-width: 768px) {
  .ep-ocr-scan-banner {
    top: calc(var(--ep-header-h) + var(--ep-toolbar-h) + 8px);
    padding: 6px 14px 6px 10px;
    font-size: 0.78rem;
    gap: 8px;
    max-width: calc(100vw - 24px);
  }
  .ep-ocr-scan-icon {
    width: 15px;
    height: 15px;
  }
  .ep-ocr-scan-info {
    min-width: 130px;
    max-width: 190px;
  }
  .ep-ocr-scan-text {
    font-size: 0.74rem;
  }
}

@keyframes epOcrSlideDown {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes epOcrSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes epOcrShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@keyframes epOcrLaserSweep {
  0% { top: 2%; opacity: 0.85; }
  50% { opacity: 1; }
  100% { top: 96%; opacity: 0.85; }
}


