/* =========================
   GLOBAL RESET & BASE
   ========================= */
* {
  box-sizing: border-box;
  font-family: Arial, 'Segoe UI', 'Segoe UI Emoji', 'Apple Color Emoji',
    'Noto Color Emoji', sans-serif;
}

body {
  margin: 0;
  background: #f5f5f5;
}

/* =========================
     TOP SUMMARY BAR
     ========================= */
#top-summary {
  position: fixed;
  top: 0;
  width: 100%;
  height: 50px;
  background: #222;
  color: #fff;
  padding: 0 15px;
  display: flex;
  gap: 20px;
  align-items: center;
  z-index: 1000;
}

#top-summary button {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 14px;
}

/* =========================
     DRAG & DROP AREA
     ========================= */
#drag {
  margin: 80px 20px 20px;
  padding: 40px;
  border: 2px dashed #999;
  text-align: center;
  background: #fff;
  cursor: pointer;
  border-radius: 14px;
  transition: border-color 140ms ease, box-shadow 140ms ease,
    background-color 140ms ease, transform 140ms ease;
}

#drag.border-primary {
  background-color: #f0f8ff;
}

#drag.is-file-hover {
  border-color: #0d6efd;
  background: linear-gradient(180deg, #f7fbff 0%, #eef6ff 100%);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.14);
  transform: translateY(-1px);
}

body.is-file-dragging #frame {
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
  border-color: rgba(13, 110, 253, 0.4);
}

.backend-status {
  margin: 8px 20px 0;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.backend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex: 0 0 9px;
  background: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.backend-status.is-online {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}
.backend-status.is-online .backend-dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.backend-status.is-checking {
  border-color: #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
}
.backend-status.is-checking .backend-dot {
  background: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.backend-status.is-offline {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}
.backend-status.is-offline .backend-dot {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* =========================
     MAIN FRAME / WORKSPACE
     ========================= */
#frame {
  margin: 20px;
  padding: 20px;
  background: #fff;
  border: 1px solid #ccc;
  position: -webkit-sticky; /* Support for Safari */
  position: sticky;
  /* Adjust '56px' to match your actual navbar height */
  top: calc(56px + 8px); 
  z-index: 1020; /* Ensure it stays above other content but below the navbar */
  overflow: visible;
}

/* Workspace is the true render surface */
#workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 100% !important;
}

/* =========================
     PDF CARD (PDF AS A UNIT)
     ========================= */
.pdf-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  overflow: hidden; /* IMPORTANT: prevents spill/overlap */
  position: relative;
  transition: box-shadow 140ms ease, transform 140ms ease,
    border-color 140ms ease, background-color 140ms ease;
}

.pdf-card:hover {
  box-shadow: 0 0 0 1px #ccc;
}

/* =========================
   DRAG DROP HIGHLIGHTS (PHASE 5)
   ========================= */
.pdf-card.drop-target-pages {
  outline: 2px dashed #0d6efd;
  outline-offset: 2px;
  background: #f5f9ff;
}

.pdf-card.drop-target-pdf {
  outline: 2px solid #20c997;
  outline-offset: 2px;
  background: #f4fffb;
}

.pdf-card.drop-target-pdf.drop-before::before {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  top: 0;
  height: 4px;
  background: #20c997;
  border-radius: 6px;
}

.pdf-card.drop-target-pdf.drop-after::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 0;
  height: 4px;
  background: #20c997;
  border-radius: 6px;
}

/* Optional: make placeholder look consistent */
.drop-placeholder {
  box-sizing: border-box;
  background: linear-gradient(135deg, rgba(13, 110, 253, 0.06), rgba(13, 110, 253, 0.14));
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.pdf-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.pdf-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  user-select: none;
}

/* =========================
     PDF THUMBNAIL (FIRST PAGE)
     ========================= */
.pdf-thumb {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f8f9fa;
  padding: 6px;
  border-radius: 4px;
}

/* =========================
     PDF ACTION BUTTONS
     ========================= */
.pdf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.pdf-actions .btn {
  flex: 1 1 120px;
  min-width: 0;
}

/* =========================
     PAGE GRID (SPLIT PAGES)
     ========================= */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
  margin-top: 12px;
  align-items: start;
  scroll-margin-top: 120px;
}

/* =========================
     PAGE ITEM (ATOMIC UNIT)
     ========================= */
.page-item {
  width: 100%;
  max-width: 100%;
  padding: 4px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.page-item:hover {
  border-color: #999;
}

.page-item canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.page-mobile-select-wrap {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 8;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.15);
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.page-mobile-select {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #0d6efd;
}

/* =========================
     EDIT BUTTON (E) ON THUMBNAILS
     ========================= */
.page-edit-btn {
  position: absolute;
  bottom: 4%;
  left: 4px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: #d4af37; /* gold */
  color: #ffffff;
  font-weight: 800;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.page-edit-btn:hover {
  filter: brightness(0.95);
}

.page-edit-btn:active {
  transform: translateY(1px);
}

.page-edit-btn:focus {
  outline: 2px solid rgba(13, 110, 253, 0.6);
  outline-offset: 1px;
}

/* Selected page */
.page-item.selected {
  border: 2px solid #0d6efd;
  background-color: #e7f1ff;
}

.page-item {
  position: relative;
  padding: 6px;
}

.page-item canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

@media (hover: none), (pointer: coarse) {
  .page-mobile-select-wrap {
    display: inline-flex;
  }
}

.page-actions {
  position: absolute;
  bottom: 2%;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 5;
}

.page-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  line-height: 24px;
  padding: 0;
  margin: 0%;
}

.page-action-btn:hover {
  background: #fff;
}

.page-action-btn.danger {
  color: #c40000;
}

/* =========================
     THUMBNAIL SIZE LOCK
     ========================= */

/* =========================
     RIGHT ACTION PANEL (FUTURE)
     ========================= */

/* =========================
     GO TO TOP (FUTURE)
     ========================= */
#goTop {
  position: fixed;
  bottom: 20px;
  right: 25%;
  padding: 10px;
  display: none;
}

.page-item:active {
  opacity: 0.6;
}

/* =========================
     GLOBAL DROP OVERLAY
     ========================= */
#globalDrop {
  position: fixed;
  inset: 0;
  background: rgba(13, 110, 253, 0.12);
  border: 4px dashed #0d6efd;
  display: none;
  z-index: 2000;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.global-drop-card {
  min-width: min(560px, 92vw);
  max-width: 92vw;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid rgba(13, 110, 253, 0.22);
  box-shadow: 0 18px 42px rgba(13, 40, 90, 0.2);
  padding: 18px 20px;
  text-align: center;
}

.global-drop-title {
  color: #0d3ea1;
  font-size: clamp(20px, 2.5vw, 30px);
  font-weight: 800;
  line-height: 1.2;
}

.global-drop-sub {
  margin-top: 8px;
  color: #334155;
  font-size: 14px;
}

@media (max-width: 900px) {
  .backend-status {
    margin: 8px 12px 0;
  }

  #frame {
    margin: 12px;
    padding: 12px;
    position: static;
    top: auto;
  }

  #workspace {
    width: 100%;
    max-width: 100% !important;
  }

  .pdf-card {
    padding: 10px;
  }

  .pdf-title-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .pdf-actions .btn {
    flex: 1 1 calc(50% - 8px);
  }

  .page-grid {
    grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
    gap: 8px;
  }

  .page-item {
    width: 100%;
  }

  .page-actions {
    right: 4px;
  }
}

/* =========================
     LOADER OVERLAY
     ========================= */
#loaderBox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  z-index: 3000;
  align-items: center;
  justify-content: center;
}

.loader-card {
  background: #fff;
  padding: 30px 40px;
  border-radius: 10px;
  text-align: center;
  width: 320px;
}

.loader-bar {
  height: 8px;
  background: #e0e0e0;
  border-radius: 6px;
  margin-top: 15px;
  overflow: hidden;
}

.loader-progress {
  height: 100%;
  width: 0%;
  background: #0d6efd;
  transition: width 0.4s ease;
}

/* =========================
     FRAME TOP BAR
     ========================= */
.frame-top-bar {
  position: sticky;
  top: 60px; /* below your fixed top summary (50px) */
  z-index: 1500;
  background: #fff;
  padding: 8px 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
  margin-bottom: -14px;
  margin-top: -14px;
}

.frame-top-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.upload-live-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid #bfdbfe;
  background: linear-gradient(135deg, #f5f9ff 0%, #e8f1ff 100%);
  color: #0f172a;
  font-size: 10px;
  line-height: 1.2;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.05);
}

.upload-live-strip.is-hidden {
  display: none !important;
}

.upload-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.2);
  flex: 0 0 8px;
}

.upload-live-text {
  min-width: 0;
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
}

.upload-live-main {
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
  color: #0f172a;
}

.upload-live-detail {
  white-space: nowrap;
  color: #334155;
  font-size: 10px;
}

.upload-live-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #1e3a8a;
  white-space: nowrap;
  font-size: 10px;
}

.upload-live-chip.is-hidden {
  display: none !important;
}

.upload-live-meter {
  width: 72px;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.25);
  margin-left: 2px;
}

.upload-live-meter-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa 0%, #2563eb 100%);
  transition: width 180ms ease;
}

.upload-live-strip.is-uploading {
  border-color: #93c5fd;
  background: linear-gradient(135deg, #eef6ff 0%, #dbeafe 100%);
}

.upload-live-strip.is-uploading .upload-live-dot {
  background: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.upload-live-strip.is-uploading .upload-live-meter-bar {
  background: linear-gradient(90deg, #60a5fa 0%, #2563eb 100%);
}

.upload-live-strip.is-queued .upload-live-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
}

.upload-live-strip.is-queued .upload-live-meter-bar {
  background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%);
}

.upload-live-strip.is-loading .upload-live-dot {
  background: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

.upload-live-strip.is-loading .upload-live-meter-bar {
  background: linear-gradient(90deg, #22d3ee 0%, #0ea5e9 100%);
}

@media (max-width: 900px) {
  .frame-top-bar {
    top: 56px;
    align-items: stretch;
  }

  .upload-live-strip {
    width: 100%;
    border-radius: 12px;
    font-size: 10px;
    padding: 6px 8px;
    gap: 6px;
  }

  .frame-top-actions {
    width: 100%;
    margin-left: 0;
  }

  .upload-live-meter {
    width: 58px;
  }
}

/* Bluish white panel button */
.panel-btn {
  background: #e7f1ff;
  border: 1px solid #0d6efd;
  color: #0d6efd;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

/* Visual feedback while dragging PDF */
.pdf-card.dragging {
  opacity: 0.4;
  border: 2px dashed #0d6efd;
}

/* Drop target indicator when reordering PDFs */
.pdf-card.drop-before {
  box-shadow: inset 0 4px 0 #0d6efd;
}

.pdf-card.drop-after {
  box-shadow: inset 0 -4px 0 #0d6efd;
}

/* Cursor and drag feedback */
.page-item,
.pdf-card {
  cursor: grab;
}

.page-item:active,
.pdf-card:active {
  cursor: grabbing;
}

/* While dragging */
.dragging {
  opacity: 0.5;
  transform: scale(0.97);
  transition: transform 0.15s ease;
}

/* =========================
     ZOOM MODAL
     ========================= */
.zoom-modal {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0, 0, 0, 0.7);
  z-index: 6000;
  align-items: center; /* ? center */
  justify-content: center; /* ? center */
  padding: 16px;
  overflow: auto;
}

.zoom-content {
  position: relative;
  background: #fff;
  padding: 16px;
  border-radius: 10px;
  max-height: calc(100vh - 32px);
  overflow-y: auto; /* ? vertical scroll */
  overflow-x: hidden; /* ? avoid horizontal */
}

#zoomCanvas {
  display: block;
  max-width: 90vw;
  height: auto;
}

.zoom-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #fff;
  color: #000;
  border: 2px solid #ccc;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-weight: bold;
  text-align: center;
  line-height: 28px;
  cursor: pointer;
  z-index: 10;
}

/* =========================
     UPLOAD QUICK GUIDE MODAL
     ========================= */
body.upload-guide-open {
  overflow: hidden;
}

.upload-guide-modal {
  z-index: 6400;
  background: rgba(10, 18, 34, 0.68);
}

.upload-guide-card {
  position: relative;
  width: min(780px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #dbe4f0;
  box-shadow: 0 22px 56px rgba(12, 21, 38, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.upload-guide-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid #d9e0ec;
  border-radius: 10px;
  background: #ffffff;
  color: #0f172a;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.upload-guide-close:hover {
  background: #f8fafc;
}

.upload-guide-head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid #e5edf8;
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%);
}

.upload-guide-kicker {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.upload-guide-head h3 {
  margin: 10px 0 6px;
  font-size: 22px;
  line-height: 1.25;
  color: #0f172a;
}

.upload-guide-sub {
  margin: 0;
  color: #475569;
  font-size: 14px;
  line-height: 1.45;
}

.upload-guide-steps {
  padding: 14px 20px 10px;
  overflow: auto;
}

.upload-guide-step {
  display: none;
}

.upload-guide-step.is-active {
  display: block;
  animation: uploadGuideFadeIn 180ms ease-out;
}

.upload-guide-step h4 {
  margin: 0 0 8px;
  font-size: 20px;
  color: #0f172a;
}

.upload-guide-step-meta {
  display: inline-flex;
  align-items: center;
  margin-bottom: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  background: #dbeafe;
}

.upload-guide-step-desc {
  margin: 0 0 10px;
  color: #475569;
  font-size: 14px;
  line-height: 1.45;
}

.upload-guide-alert {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #fbbf24;
  background: #fffbeb;
  color: #7c2d12;
  font-size: 13px;
  line-height: 1.45;
}

.upload-guide-alert strong {
  letter-spacing: 0.2px;
}

.upload-guide-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.upload-guide-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #dbeafe;
  background: #f8fbff;
  color: #1e3a8a;
  font-size: 12px;
  font-weight: 600;
}

.upload-guide-step ul {
  margin: 0;
  padding-left: 18px;
}

.upload-guide-step li {
  margin: 0 0 9px;
  color: #334155;
  line-height: 1.45;
  font-size: 14px;
}

.upload-guide-footer {
  border-top: 1px solid #e5edf8;
  background: #f8fbff;
  padding: 12px 20px 14px;
  display: grid;
  gap: 10px;
}

.upload-guide-meter {
  position: relative;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #dce6f6;
  overflow: hidden;
}

.upload-guide-meter span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 16%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #0ea5e9);
  transition: width 220ms ease;
}

.upload-guide-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-guide-dot {
  width: 11px;
  height: 11px;
  border: none;
  border-radius: 999px;
  padding: 0;
  background: #cbd5e1;
  cursor: pointer;
  transition: transform 100ms ease, background-color 120ms ease;
}

.upload-guide-dot.is-active {
  background: #2563eb;
  transform: scale(1.15);
}

.upload-guide-step-count {
  margin-left: 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
}

.upload-guide-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-guide-controls .panel-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

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

.upload-guide-step.is-active .upload-guide-chip {
  animation: uploadGuideChipIn 220ms ease both;
}

.upload-guide-step.is-active li {
  animation: uploadGuideListIn 240ms ease both;
}

.upload-guide-step.is-active li:nth-child(2) {
  animation-delay: 45ms;
}

.upload-guide-step.is-active li:nth-child(3) {
  animation-delay: 90ms;
}

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

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

@media (max-width: 900px) {
  .upload-guide-card {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .upload-guide-head {
    padding: 14px 14px 12px;
  }

  .upload-guide-head h3 {
    font-size: 19px;
    margin-top: 8px;
  }

  .upload-guide-steps {
    padding: 12px 14px 6px;
  }

  .upload-guide-step h4 {
    font-size: 17px;
  }

  .upload-guide-step li {
    font-size: 13px;
  }

  .upload-guide-footer {
    padding: 10px 14px 12px;
  }

  .upload-guide-controls {
    justify-content: stretch;
  }

  .upload-guide-controls .panel-btn {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
}

/* Mini loader spinner */
.mini-loader {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top: 4px solid #0d6efd;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 10;
}

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

/* =========================
     EDIT MODAL (PART 2)
     ========================= */

.edit-content {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: 95vw;
  height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e5e5;
}

.edit-title {
  font-weight: 700;
  font-size: 16px;
}

.edit-under-construction {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #f59e0b;
  background: linear-gradient(180deg, #fff8db 0%, #fff1c2 100%);
}

.edit-under-construction-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
  flex: 0 0 34px;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.edit-under-construction-text {
  display: block;
  color: #7c2d12;
  font-weight: 900;
  font-size: clamp(12px, 1.25vw, 16px);
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.edit-close {
  border: none;
  background: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.edit-close:hover {
  background: #f2f2f2;
}

.edit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #eaeaea;
  background: #fafafa;
}

.edit-select {
  height: 32px;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
}

.edit-tool-btn {
  height: 32px;
  min-width: 32px;
  border: 1px solid #dcdcdc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.edit-tool-btn:hover {
  background: #f2f2f2;
}

.edit-color {
  height: 32px;
  width: 38px;
  padding: 0;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.edit-spacer {
  flex: 1;
}

.edit-body {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.edit-preview {
  flex: 1;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  background: #fff;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
}

#editCanvas {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 8px;
  max-width: 100%;
}

.edit-side {
  width: 320px;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  overflow: auto;
}

.edit-help {
  background: #fff8d6;
  border: 1px solid #f1e1a6;
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
}

.edit-text-span.selected {
  border-color: red;
  background: rgba(255, 0, 0, 0.06);
}

/* =========================
     RIGHT SLIDE PANEL
     ========================= */
/* =========================
     SLIDING RIGHT PANEL
     ========================= */
#panel {
  position: fixed;
  top: 50px;
  right: -100%;
  width: 20%;
  min-width: 280px;
  height: calc(100% - 50px);
  background: #ffffff;
  border-left: 1px solid #ddd;
  padding: 16px;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.12);
  transition: right 0.35s ease;
  z-index: 2000;
  overflow-y: auto;
}

#panel.open {
  right: 0%;
}

/* Warning text */
.panel-warning {
  background: #fff3cd;
  color: #664d03;
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}

/* Action buttons */
.panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-btn {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #0d6efd;
  background: #e7f1ff;
  color: #0d6efd;
  font-weight: 600;
  cursor: pointer;
}

.panel-btn.danger {
  background: #fdecea;
  border-color: #dc3545;
  color: #dc3545;
}

.panel-btn:hover {
  opacity: 0.9;
}

.panel-btn.is-busy {
  opacity: 0.72;
  cursor: wait;
  pointer-events: none;
}

/* Stats */
.panel-stats p {
  margin: 6px 0;
  font-size: 14px;
}

/* Panel header */
.panel-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

/* Close button */
.panel-close {
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  margin-right: 10px;
  color: #555;
}

.panel-close:hover {
  color: #000;
}

/* Panel title */
.panel-title {
  font-weight: 600;
  font-size: 14px;
}

/* =========================
     PAGE NUMBER MODAL
     ========================= */

/* =========================================================
     COMPLETE MODAL CSS (REPLACE OLD MODAL STYLES WITH THIS)
     Works for:
     - Page Numbers (Live Preview) designer modal
     - Signature/Watermark designer modal
     ========================================================= */

/* Overlay */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(0, 0, 0, 0.45);
  padding: 12px;

  /* IMPORTANT: stop page behind from scrolling */
  overflow: hidden;
}

/* Hidden state (your HTML uses .hidden) */
.hidden {
  display: none !important;
}

/* Modal card */
.modal .modal-card {
  width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);

  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);

  display: flex;
  flex-direction: column;
  overflow: hidden; /* keeps header/footer fixed while body scrolls */
}

/* Header */
.modal .modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 12px 14px;
  border-bottom: 1px solid #e9e9e9;
}

.modal .modal-title {
  font-size: 16px;
  font-weight: 700;
}

/* Close button */
.modal .modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

/* Footer */
.modal .modal-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 10px;

  padding: 12px 14px;
  border-top: 1px solid #e9e9e9;
  background: #fff;
}

/* =========================
     DESIGNER LAYOUT
     ========================= */

.modal .designer-body {
  flex: 1 1 auto;
  min-height: 0; /* IMPORTANT: enables internal scrolling */

  display: grid;
  grid-template-columns: minmax(520px, 1fr) 360px;
  gap: 14px;

  padding: 14px;
  overflow: hidden; /* prevent body itself from scrolling */
}

/* Left preview area */
.modal .designer-left {
  min-height: 0;
  overflow: auto; /* if preview becomes tall, left side scrolls */
}

/* Preview frame */
.modal .designer-preview-wrap {
  position: relative;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fafafa;

  padding: 10px;
  min-height: 520px;

  display: flex;
  justify-content: center;
  align-items: center;
}

/* Preview canvas */
.modal .designer-preview-wrap canvas {
  width: 100%;
  max-width: 520px;
  height: auto;
  display: block;

  background: #fff;
  border-radius: 10px;
}

/* Drag element */
.modal .designer-drag {
  position: absolute;
  left: 50%;
  top: 88%;
  transform: translate(-50%, -100%);

  padding: 6px 10px;
  border: 1px dashed #1e73ff;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  cursor: move;
  user-select: none;
  z-index: 5;
}

/* Hint text */
.modal .designer-hint {
  margin-top: 8px;
  font-size: 13px;
  opacity: 0.8;
}

/* Right controls (scrollable) */
.modal .designer-right {
  min-height: 0;
  overflow: auto; /* RIGHT SIDE SCROLLBAR */
  padding-right: 6px;
}

/* Small checkbox rows */
.modal .designer-check {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  user-select: none;
}

/* Note text */
.modal .designer-note {
  margin-top: 12px;
  font-size: 13px;
  opacity: 0.8;
}

/* Responsive: stack for smaller screens */
@media (max-width: 900px) {
  .modal .modal-card {
    width: calc(100vw - 24px);
  }

  .modal .designer-body {
    grid-template-columns: 1fr;
  }

  .modal .designer-preview-wrap {
    min-height: 420px;
  }
}

/* Keep right panel scroll always usable */
.designer-right {
  overflow: auto;
  max-height: 100%;
}

.row {
  margin-bottom: 10px;
}
.lbl {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  color: #333;
}
.inp {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid #eee;
  justify-content: flex-end;
}

#signatureModal .modal-body {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.panel-btn.small {
  padding: 8px 10px;
  font-size: 13px;
}
.panel-btn.primary {
  background: #1e73ff;
  color: white;
  border: none;
}

.hint {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
}

#signatureModal .form-control {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
}
#signatureModal label {
  display: block;
  margin-top: 8px;
}

#sigEnabled {
  display: none;
}
#sigEnabled + * {
  display: none;
}

/* =========================
     EDIT TEXT LAYER (PART 3)
     ========================= */

.edit-canvas-wrap {
  position: relative;
  display: inline-block;
}

/* Layer sits above canvas */
.edit-text-layer {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none; /* IMPORTANT: only spans catch clicks */
}

/* Each text item becomes a span (click target) */
.edit-text-span {
  position: absolute;
  white-space: pre;
  transform-origin: 0 0;
  pointer-events: auto; /* allow click */
  cursor: text;
  user-select: none;

  /* invisible by default, but hover outline shows */
  color: transparent;
  border: 1px dotted transparent;
  padding: 1px 2px;
}

.edit-text-span:hover {
  border-color: red; /* red dotted border */
}

/* After editing, show the edited text so user sees result immediately */
.edit-text-span.edited {
  color: #000;
  background: #ffffff; /* solid cover (no double text showing) */
  border-color: rgba(255, 0, 0, 0.25);
  padding: 1px 3px; /* slightly larger to cover original edges */
}
/* Inline editor that appears when user clicks text */
.edit-inline-editor {
  position: absolute;
  transform-origin: 0 0;
  pointer-events: auto;
  background: #ffffff;
  border: 1px dashed #0d6efd;
  border-radius: 4px;
  padding: 0;

  outline: none;
  white-space: pre;
  line-height: 1;
  cursor: text;
}

/* Hide old "Replace with" box (we edit by clicking text now) */
#editReplaceBox {
  display: none;
}

/* =========================
     DESIGNER MODALS (PHASE 2)
     ========================= */
/* Designer should always fit screen */
.designer-card {
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  width: min(1100px, 96vw);
}

.designer-body {
  display: grid;
  gap: 14px;
  padding: 14px;
  flex: 1 1 auto;
  min-height: 0; /* IMPORTANT: allows inner scrolling */
  overflow: hidden;
  grid-template-columns: minmax(520px, 1fr) 360px;
}

.designer-left {
  max-height: 100%;
}

.designer-right {
  max-height: 100%;
  overflow: auto;
  padding-right: 6px;
}

.designer-preview-wrap {
  position: relative;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fafafa;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
}

.designer-preview-wrap canvas {
  width: 100%;
  max-width: 520px;
  height: auto;
  display: block;
  background: #fff;
  border-radius: 8px;
}

.designer-drag {
  position: absolute;
  left: 50%;
  top: 88%;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border: 1px dashed #1e73ff;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  cursor: move;
  user-select: none;
  z-index: 5;
}

.designer-hint {
  margin-top: 8px;
  font-size: 13px;
  opacity: 0.8;
}

.designer-check {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.designer-note {
  margin-top: 12px;
  font-size: 13px;
  opacity: 0.8;
}

/* On small screens, stack vertically */
@media (max-width: 900px) {
  .designer-body {
    grid-template-columns: 1fr;
  }
}

/* =========================
   PHASE 5: LOADER + EDITOR UX
   ========================= */
#loaderBox {
  position: fixed;
  inset: 0;
  background: rgba(6, 16, 34, 0.48);
  backdrop-filter: blur(2px);
  display: none;
  z-index: 3000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.loader-card {
  width: min(540px, 96vw);
  background: linear-gradient(135deg, #ffffff, #f5f9ff);
  border: 1px solid rgba(13, 110, 253, 0.2);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(10, 25, 55, 0.2);
}

.loader-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.loader-orb {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, #7db0ff, #1e73ff);
  display: grid;
  place-items: center;
  animation: loaderPulse 1.4s ease-in-out infinite;
}

.loader-orb-core {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #ffffff;
}

.loader-copy {
  min-width: 0;
}

.loader-text {
  color: #0f172a;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loader-stage {
  margin-top: 3px;
  color: #475569;
  font-size: 12px;
}

.loader-percent {
  min-width: 54px;
  text-align: right;
  font-size: 18px;
  font-weight: 800;
  color: #1d4ed8;
}

.loader-bar {
  margin-top: 12px;
  height: 10px;
  border-radius: 999px;
  background: #dce8ff;
  overflow: hidden;
}

.loader-progress {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1e73ff, #33a3ff);
  transition: width 220ms linear;
}

.loader-dots {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  justify-content: center;
}

.loader-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #1e73ff;
  opacity: 0.35;
  animation: loaderDot 1s ease-in-out infinite;
}

.loader-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.loader-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes loaderPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes loaderDot {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 0.95;
    transform: translateY(-2px);
  }
}

.edit-content {
  width: min(1700px, 98vw);
  height: min(95vh, 980px);
}

.edit-subtitle {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}

.edit-status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.edit-badge {
  border: 1px solid #d6deea;
  background: #f8fbff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  color: #0f172a;
}

.edit-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
}

.edit-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.edit-toolbar-controls {
  border-top: 1px dashed #dbe3f2;
  padding-top: 8px;
}

.edit-tool-btn {
  border-color: #c7d7f4;
}

.edit-tool-btn.active {
  background: #1e73ff;
  border-color: #1e73ff;
  color: #ffffff;
}

.edit-inline-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #334155;
}

.edit-range-wrap {
  min-width: 150px;
}

.edit-input-sm {
  width: 70px;
  height: 32px;
  border: 1px solid #d0d7e2;
  border-radius: 6px;
  padding: 0 8px;
}

.edit-range {
  width: 120px;
}

.edit-preview {
  align-items: flex-start;
  justify-content: center;
}

.edit-canvas-wrap {
  position: relative;
  display: inline-block;
  width: fit-content;
  max-width: 100%;
}

#editCanvas {
  position: relative;
  z-index: 1;
  display: block;
}

#editOverlayCanvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 40;
}

#editModal .canvas-container {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  z-index: 40 !important;
  pointer-events: auto !important;
}

#editModal .canvas-container canvas {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  pointer-events: auto !important;
}

.edit-text-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 12;
  pointer-events: none;
}

.edit-text-span {
  position: absolute;
  white-space: pre;
  transform-origin: 0 0;
  pointer-events: auto;
  cursor: text;
  user-select: none;
  line-height: 1;
  padding: 0;
  margin: 0;
  color: transparent;
  border: 1px dashed transparent;
  background: transparent;
}

.edit-text-span:hover {
  border-color: rgba(220, 53, 69, 0.75);
  background: rgba(220, 53, 69, 0.06);
}

.edit-text-span.selected {
  border-color: rgba(220, 53, 69, 0.95);
  background: rgba(220, 53, 69, 0.1);
}

.edit-text-layer.hitbox-off .edit-text-span {
  pointer-events: none !important;
}

.edit-side {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.edit-side-section {
  border: 1px solid #e5eaf4;
  border-radius: 10px;
  padding: 10px;
  background: #fbfdff;
}

.edit-side-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: #475569;
  margin-bottom: 6px;
}

.edit-detect-status {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}

.edit-detect-note {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
  color: #475569;
}

@media (max-width: 1100px) {
  .edit-body {
    flex-direction: column;
    overflow: auto;
  }

  .edit-side {
    width: 100%;
  }

  .edit-content {
    height: 96vh;
  }

  .edit-under-construction {
    margin: 8px 10px 0;
    padding: 9px 10px;
  }

  .edit-under-construction-icon {
    width: 30px;
    height: 30px;
    font-size: 17px;
    flex-basis: 30px;
  }
}

/* =========================
   STANDALONE IFRAME EDITOR
   ========================= */
.edit-frame-shell {
  width: min(1880px, 99vw);
  height: min(98vh, 1080px);
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #dfe7f4;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.edit-frame-header {
  height: 54px;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef5ff 100%);
  border-bottom: 1px solid #dbe5f4;
}

.edit-frame-title {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-frame-close {
  border: 1px solid #d5def0;
  background: #ffffff;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 22px;
  line-height: 1;
  color: #334155;
  cursor: pointer;
}

.edit-frame-close:hover {
  background: #f6f9ff;
}

#editFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f8fafc;
}

@media (max-width: 900px) {
  .edit-frame-shell {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    border: 0;
  }
}
