/* Outil : Modifier les pages d’un PDF */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

@supports (overflow-x: clip) {
  html,
  body {
    overflow-x: clip;
  }
}

body.pdf-pages-mobile-safe .tool-page,
body.pdf-pages-mobile-safe .optimizer-shell,
body.pdf-pages-mobile-safe .summary,
body.pdf-pages-mobile-safe .pdfm-toolbar,
body.pdf-pages-mobile-safe .pdfm-grid,
body.pdf-pages-mobile-safe .pdfm-card,
body.pdf-pages-mobile-safe .toolbar-actions {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.pdfm-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.pdfm-summary .stat strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdfm-toolbar {
  margin-top: 20px;
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid #e8e3da;
  border-radius: 18px;
  background: #fffdf9;
}

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

.pdfm-toolbar-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.pdfm-toolbar-copy strong {
  font-size: .96rem;
}

.pdfm-toolbar-copy span {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
}

.pdfm-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.pdfm-toolbar-actions button {
  padding: 9px 11px;
  font-size: .82rem;
}

.pdfm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.pdfm-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #e8e3da;
  border-radius: 20px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.pdfm-card.selected {
  border-color: rgba(232, 93, 63, .48);
  box-shadow: 0 0 0 3px rgba(232, 93, 63, .08);
}

.pdfm-card-top {
  min-height: 48px;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #eee9e1;
  background: #fffdf9;
}

.pdfm-select {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: #5c6971;
  font-size: .79rem;
  font-weight: 800;
}

.pdfm-select input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--primary);
}

.pdfm-preview-wrap {
  position: relative;
  height: 245px;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
  background: #f3f3f1;
}

.pdfm-preview {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 5px 18px rgba(30, 35, 40, .13);
}

.pdfm-preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .74);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

.pdfm-preview-loading[hidden] {
  display: none !important;
}

.pdfm-page-info {
  padding: 12px 13px 0;
  display: grid;
  gap: 3px;
}

.pdfm-page-info strong {
  font-size: .95rem;
}

.pdfm-page-info span {
  min-height: 1.2em;
  color: var(--muted);
  font-size: .76rem;
}

.pdfm-page-actions {
  padding: 11px 12px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.pdfm-page-actions button {
  min-width: 0;
  padding: 9px 7px;
  font-size: .78rem;
  white-space: normal;
}

.pdfm-page-actions .delete-page {
  grid-column: 1 / -1;
}


.pdfm-bottom-actions {
  align-items: center;
}

.pdfm-progress {
  display: none;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: .84rem;
  text-align: right;
}

.pdfm-progress.visible {
  display: block;
}

@media (max-width: 780px) {
  body.pdf-pages-mobile-safe .tool-page {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  @supports (overflow-x: clip) {
    body.pdf-pages-mobile-safe .tool-page {
      overflow-x: clip;
    }
  }

  .pdfm-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .pdfm-toolbar-actions {
    justify-content: stretch;
  }

  .pdfm-toolbar-actions button {
    flex: 1 1 145px;
  }

  .pdfm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .pdfm-preview-wrap {
    height: 210px;
  }

  .pdfm-bottom-actions button {
    flex: 1 1 210px;
  }
}

@media (max-width: 520px) {
  .pdfm-summary {
    grid-template-columns: 1fr 1fr;
  }

  .pdfm-grid {
    grid-template-columns: 1fr;
  }

  .pdfm-preview-wrap {
    height: min(56vh, 390px);
  }

  .pdfm-toolbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .pdfm-bottom-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .pdfm-bottom-actions button {
    width: 100%;
    min-width: 0;
  }

  .pdfm-progress {
    text-align: left;
  }
}


/* Mode dédié à la réorganisation */
.pdfm-grid[hidden],
.pdfm-bottom-actions[hidden],
.tool-tip[hidden],
.pdfm-reorder-panel[hidden] {
  display: none !important;
}

.pdfm-reorder-panel {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid #e8e3da;
  border-radius: 22px;
  background: #fffdf9;
}

.pdfm-reorder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
}

.pdfm-reorder-head > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.pdfm-reorder-head strong {
  font-size: 1rem;
}

.pdfm-reorder-head span,
.pdfm-reorder-tip {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}

.pdfm-reorder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 11px;
}

.pdfm-reorder-card {
  position: relative;
  min-width: 0;
  padding: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(30, 35, 40, .07);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}

.pdfm-reorder-card:hover {
  border-color: rgba(232, 93, 63, .24);
  transform: translateY(-1px);
}

.pdfm-reorder-card:active {
  cursor: grabbing;
}

.pdfm-reorder-preview-wrap {
  position: relative;
  height: 175px;
  display: grid;
  place-items: center;
  padding: 7px;
  overflow: hidden;
  border-radius: 11px;
  background: #f1f2f1;
}

.pdfm-reorder-preview {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  background: #fff;
  box-shadow: 0 3px 10px rgba(30, 35, 40, .12);
}

.pdfm-reorder-position {
  position: absolute;
  top: 7px;
  left: 7px;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .16);
  font-size: .78rem;
  font-weight: 900;
  pointer-events: none;
}

.pdfm-reorder-label {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: .8rem;
  text-align: center;
  pointer-events: none;
}

.pdfm-reorder-tip {
  margin: 12px 2px 0;
  text-align: center;
}

/* Retour visuel très marqué pendant/après le déplacement. */
.pdfm-reorder-ghost {
  opacity: .18 !important;
  border: 2px dashed var(--primary) !important;
  background: var(--primary-soft) !important;
}

.pdfm-reorder-chosen {
  border-color: var(--primary) !important;
  box-shadow: 0 10px 28px rgba(30, 35, 40, .16);
}

.pdfm-reorder-dragging {
  opacity: .92;
  box-shadow: 0 18px 40px rgba(30, 35, 40, .22);
  cursor: grabbing;
}

.pdfm-reorder-moved {
  animation: pdfmMovedFlash .52s ease;
}

@keyframes pdfmMovedFlash {
  0% { box-shadow: 0 0 0 0 rgba(232, 93, 63, .46); }
  45% { box-shadow: 0 0 0 7px rgba(232, 93, 63, .18); }
  100% { box-shadow: 0 3px 12px rgba(30, 35, 40, .07); }
}

@media (max-width: 780px) {
  .pdfm-reorder-head {
    align-items: stretch;
    flex-direction: column;
  }

  .pdfm-reorder-head button {
    width: 100%;
  }

  .pdfm-reorder-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .pdfm-reorder-card {
    padding: 6px;
    border-radius: 13px;
  }

  .pdfm-reorder-preview-wrap {
    height: 135px;
    padding: 5px;
    border-radius: 9px;
  }

  .pdfm-reorder-position {
    top: 5px;
    left: 5px;
    min-width: 25px;
    height: 25px;
    font-size: .72rem;
  }

  .pdfm-reorder-label {
    margin-top: 5px;
    font-size: .74rem;
  }
}

@media (max-width: 480px) {
  .pdfm-reorder-panel {
    padding: 11px;
    border-radius: 18px;
  }

  .pdfm-reorder-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .pdfm-reorder-preview-wrap {
    height: 145px;
  }
}


/* Déplacement tactile dédié : la copie est positionnée manuellement
   en position fixed et centrée sous le doigt. */
.pdfm-touch-drag-clone {
  position: fixed !important;
  z-index: 100000 !important;
  margin: 0 !important;
  pointer-events: none !important;
  opacity: .94 !important;
  transition: none !important;
  transform: none !important;
  cursor: grabbing !important;
  box-shadow: 0 20px 46px rgba(30, 35, 40, .28) !important;
  border-color: var(--primary) !important;
  will-change: left, top;
}

.pdfm-touch-source {
  opacity: .22 !important;
  border: 2px dashed var(--primary) !important;
  background: var(--primary-soft) !important;
}

body.pdfm-touch-reordering {
  -webkit-user-select: none;
  user-select: none;
}

@media (pointer: coarse), (hover: none) {
  .pdfm-reorder-card {
    -webkit-touch-callout: none;
  }
}


/* Bouton d’ajout d’un autre PDF */
.pdfm-add-pdf {
  background: var(--mint);
  color: var(--mint-ink);
}

.pdfm-add-pdf:hover {
  background: #dff1e9;
}

#addPdfInput[hidden] {
  display: none !important;
}

/* Les noms de PDF ajoutés peuvent être longs dans les vignettes. */
.pdfm-reorder-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
