/*
 * The PDF page tools (web/pdf/pages.js): merge, split and organise pages
 * on the device. Loaded only on their pages (catalog.js, group "pdf"),
 * after filebender.css, whose tokens and components it builds on. No new
 * hues: brand tokens and tints of them only (design/DESIGN.md).
 */

/* One column that never grows past the card, whatever a long file name wants. */
.fb-pdf,
.fb-pdf-work {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--fb-space-4);
}
.fb-pdf[data-state="files"] .fb-drop {
  padding: 20px 16px;
}
.fb-pdf[data-state="files"] .fb-drop-art {
  display: none;
}

.fb-pdf-device {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--rb-ui-muted);
  font-size: var(--fb-text-sm);
}

.fb-pdf-title {
  font-size: 17px;
}
.fb-pdf-grid-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--fb-space-3);
}
.fb-pdf-grid-hint {
  margin-top: calc(var(--fb-space-3) * -1);
}

.fb-icon-btn--small {
  width: 32px;
  height: 32px;
}
.fb-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}

/* The PDFs ------------------------------------------------------------------ */
.fb-pdf-files,
.fb-pdf-result-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.fb-pdf-file,
.fb-pdf-result {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--rb-ui-line);
  border-radius: var(--rb-radius-md);
  background: var(--rb-ui-surface);
}
.fb-pdf-file {
  grid-template-columns: minmax(0, 1fr);
}
.fb-pdf-file[data-state="failed"] {
  border-color: rgb(194 52 77 / 0.35);
}
.fb-pdf-file-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.fb-pdf-file-n {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--rb-ui-accent-soft);
  color: var(--rb-ui-accent-strong);
  font-size: var(--fb-text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.fb-pdf-file-text {
  flex: 1;
  min-width: 0;
}
.fb-pdf-file-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fb-pdf-file-meta {
  color: var(--rb-ui-muted);
  font-size: var(--fb-text-sm);
  font-variant-numeric: tabular-nums;
}
.fb-pdf-file-actions {
  display: flex;
  flex: none;
  gap: 2px;
}
.fb-pdf-consent {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--rb-radius-md);
  background: var(--rb-ui-accent-soft);
  font-size: 14px;
}
.fb-pdf-consent strong {
  color: var(--rb-ui-accent-strong);
}

/* Split: the ranges; rotate: turn every page; delete: pages by number ------- */
.fb-pdf-split,
.fb-pdf-panel {
  display: grid;
  gap: var(--fb-space-3);
  padding: var(--fb-space-4);
  border: 1px solid var(--rb-ui-line);
  border-radius: var(--rb-radius-md);
  background: var(--rb-ui-canvas);
}
.fb-pdf-split .fb-input[aria-invalid="true"],
.fb-pdf-panel .fb-input[aria-invalid="true"] {
  border-color: var(--fb-danger);
}
.fb-pdf-panel .fb-row--nowrap .fb-input {
  flex: 1;
  min-width: 0;
}
.fb-pdf-panel .fb-btn .fb-icon {
  display: inline-flex;
  vertical-align: -3px;
}

/* Rotate: the turn buttons stand out; delete: so do the ticks and remove buttons. */
.fb-pdf[data-focus="rotate"] .fb-pdf-turn,
.fb-pdf[data-focus="delete"] .fb-pdf-remove {
  background: var(--rb-ui-accent-soft);
  color: var(--rb-ui-accent-strong);
}
.fb-pdf[data-focus="delete"] .fb-pdf-remove {
  color: var(--fb-danger);
  background: var(--fb-danger-soft);
}
.fb-pdf-tick {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  margin: 0;
  color-scheme: light;
  accent-color: var(--fb-danger);
  cursor: pointer;
}
.fb-pdf-tick:focus-visible {
  outline: 2px solid var(--rb-violet-600);
  outline-offset: 2px;
}
.fb-pdf-page[data-selected="true"] {
  border-color: var(--fb-danger);
  background: var(--fb-danger-soft);
}
.fb-pdf-page[data-selected="true"] .fb-pdf-thumb img {
  opacity: 0.45;
}

/* The page grid -------------------------------------------------------------- */
.fb-pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (min-width: 640px) {
  .fb-pdf-grid {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 22px;
  }
}
.fb-pdf-page {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--rb-ui-line);
  border-radius: var(--rb-radius-md);
  background: var(--rb-ui-surface);
  user-select: none;
  -webkit-user-select: none;
}
.fb-pdf-grid[data-mode="merge"] .fb-pdf-page,
.fb-pdf-grid[data-mode="organise"] .fb-pdf-page {
  cursor: grab;
}
.fb-pdf-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--rb-radius-sm);
  background: var(--rb-ui-surface-muted);
}
.fb-pdf-thumb img {
  max-width: 92%;
  max-height: 92%;
  box-shadow: 0 1px 4px rgb(var(--rb-shadow-rgb) / 0.25);
  background: #fff;
  transform: rotate(var(--turn, 0deg));
  transition: transform 0.2s;
}
.fb-pdf-thumb img:not([src]) {
  width: 64%;
  aspect-ratio: 0.72;
  box-shadow: none;
  background: var(--rb-ui-canvas);
}
.fb-pdf-thumb--none img {
  display: none;
}
.fb-pdf-thumb--none::after {
  content: "No preview";
  color: var(--rb-ui-muted);
  font-size: var(--fb-text-xs);
}
.fb-pdf-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  min-width: 0;
  font-size: var(--fb-text-sm);
}
.fb-pdf-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.fb-pdf-from {
  overflow: hidden;
  min-width: 0;
  flex: 1;
  color: var(--rb-ui-muted);
  font-size: var(--fb-text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fb-pdf-part:empty {
  display: none;
}
.fb-pdf-part {
  padding: 1px 7px;
  border-radius: var(--rb-radius-pill);
  background: var(--rb-ui-accent-soft);
  color: var(--rb-ui-accent-strong);
  font-size: var(--fb-text-xs);
  font-weight: 700;
}
.fb-pdf-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
}
.fb-pdf-grid[data-mode="split"] .fb-pdf-tools {
  justify-content: flex-end;
}
/* The grip, beside the page's number and off the picture: where a finger
   drags from, and a button the arrow keys move the page with. */
.fb-pdf-grip {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--rb-ui-line);
  border-radius: var(--rb-radius-sm);
  background: var(--rb-ui-surface);
  color: var(--rb-ui-muted);
  cursor: grab;
  touch-action: none;
}
.fb-pdf-grip:hover {
  background: var(--rb-ui-surface-muted);
  color: var(--rb-ui-accent-strong);
}
.fb-pdf-grip:focus-visible {
  outline: none;
  box-shadow: var(--fb-focus);
}
@media (max-width: 639px) {
  .fb-pdf-tools .fb-icon-btn--small {
    width: 28px;
    height: 28px;
  }
}

/* Which PDF each page goes into, when splitting */
.fb-pdf-page[data-part="odd"] {
  border-color: var(--rb-violet-300);
  background: var(--rb-violet-50);
}
.fb-pdf-page[data-part="even"] {
  border-color: var(--rb-ui-line);
  background: var(--rb-ui-surface-muted);
}
.fb-pdf-page[data-part="none"] .fb-pdf-thumb {
  opacity: 0.4;
}
.fb-pdf-page[data-part="none"] .fb-pdf-part {
  background: var(--rb-ui-surface-muted);
  color: var(--rb-ui-muted);
}

/* The scissors between two pages: in the gap after each page but the last */
.fb-pdf-cut {
  position: absolute;
  top: 20%;
  right: -15px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 16px;
  height: 60%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--rb-ui-muted);
  cursor: pointer;
}
@media (min-width: 640px) {
  .fb-pdf-cut {
    right: -19px;
  }
}
.fb-pdf-cut::before {
  content: "";
  position: absolute;
  inset: 0 7px;
  border-left: 2px dashed var(--rb-ui-line);
}
.fb-pdf-cut .fb-icon {
  position: relative;
  padding: 2px 0;
  border-radius: 50%;
  background: var(--rb-ui-surface);
}
.fb-pdf-cut:hover,
.fb-pdf-cut[aria-pressed="true"] {
  color: var(--rb-violet-600);
}
.fb-pdf-cut:hover::before {
  border-left-color: var(--rb-violet-300);
}
.fb-pdf-cut[aria-pressed="true"]::before {
  border-left: 2px solid var(--rb-violet-600);
}
.fb-pdf-cut:focus-visible {
  outline: none;
  box-shadow: var(--fb-focus);
}

/* Dragging a page */
.fb-pdf-page.is-dragging {
  z-index: 5;
  box-shadow: 0 18px 40px rgb(var(--rb-shadow-rgb) / 0.25);
  opacity: 0.92;
  pointer-events: none;
  cursor: grabbing;
}
.fb-pdf-grid.is-sorting .fb-pdf-page:not(.is-dragging) .fb-pdf-thumb img {
  transition: none;
}
.fb-pdf-page[data-drop]::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 4px;
  border-radius: 2px;
  background: var(--rb-violet-600);
}
.fb-pdf-page[data-drop="before"]::before {
  left: -10px;
}
.fb-pdf-page[data-drop="after"]::before {
  right: -10px;
}

/* Making the PDF ------------------------------------------------------------- */
.fb-pdf-foot-text {
  display: grid;
  gap: 2px;
  text-align: right;
}
.fb-pdf-summary {
  color: var(--rb-ui-accent-strong);
  font-size: var(--fb-text-sm);
  font-weight: 600;
}
@media (max-width: 560px) {
  .fb-pdf-foot > .fb-convert {
    width: 100%;
  }
  .fb-pdf-foot-text {
    text-align: left;
  }
}

.fb-pdf-done {
  display: grid;
  gap: var(--fb-space-3);
  padding: var(--fb-space-4);
  border: 1px solid var(--rb-violet-300);
  border-radius: var(--rb-radius-lg);
  background: var(--rb-violet-50);
}
.fb-pdf-done .fb-pdf-title:focus {
  outline: none;
}
.fb-pdf-result {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
@media (max-width: 480px) {
  .fb-pdf-result {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fb-pdf-thumb img {
    transition: none;
  }
}
