/* ==========================================================================
   PDF Studio — page-level merge editor
   Loaded only on /tools/pdf-merger.

   Same workspace principle as the other rebuilt tools: no outer panel, no
   frame. Elevation belongs to the page cards and the controls you press.
   ========================================================================== */

/* ------------------------------------------------------------------- hero */

.tool-hero {
  padding-block: var(--space-7) var(--space-4);
  text-align: center;
  max-width: 48rem;
  margin-inline: auto;
}

.tool-hero__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.tool-hero h1 {
  margin: 0;
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem);
}

/* Compact trust chip beside the title, replacing the full-width banner. */
.trust-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--success-soft);
  color: var(--success-soft-fg);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.trust-chip svg { flex: 0 0 auto; }

.tool-hero__sub { margin: 0; font-size: var(--text-lg); color: var(--fg-muted); }

/* -------------------------------------------------------------- workspace */

.studio { margin-bottom: var(--space-8); }

.studio[data-dragover="true"] {
  outline: 2px dashed var(--primary);
  outline-offset: var(--space-4);
  border-radius: var(--radius-xl);
}

/* ------------------------------------------------------ state A: upload */

.studio__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

.drop-illus {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-lg);
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
}

.studio__empty h2 { margin: 0; font-size: var(--text-xl); }
.studio__hint { margin: 0; font-size: var(--text-sm); color: var(--fg-muted); }

/* ------------------------------------------------------ state B: toolbar */

.studio__bar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding-block: var(--space-3);
  margin-bottom: var(--space-4);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(1px)) {
  .studio__bar { background: var(--bg); }
}

.studio__bar-left,
.studio__bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.studio__bar-right { margin-inline-start: auto; }

.page-count {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.page-count b { color: var(--fg); }

/* Zoom control */
.zoom {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-2);
}
.zoom label { font-size: var(--text-xs); color: var(--fg-muted); white-space: nowrap; }
.zoom input[type="range"] {
  width: 110px;
  height: 44px;
  accent-color: var(--primary);
  cursor: pointer;
  background: transparent;
}

/* ------------------------------------------------------------- page grid */

.page-grid {
  --thumb: 190px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--thumb), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}
.page-card:hover { box-shadow: var(--shadow-md); }
.page-card:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 35%, transparent), var(--shadow-md);
}

/* Sortable state classes */
.page-card.is-ghost { opacity: 0.35; }
.page-card.is-chosen { box-shadow: var(--shadow-lg); }
.page-card.is-drag { transform: rotate(2deg); }

.page-card__canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  /* Reserved box: thumbnails render asynchronously and must not shift the grid. */
  aspect-ratio: 1 / 1.32;
  background: var(--surface-2);
  overflow: hidden;
}

.page-card__canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 1px 4px rgba(11, 18, 32, 0.18);
  background: #fff;
}

.page-card__spinner {
  width: 22px;
  height: 22px;
  border: 2px solid color-mix(in srgb, var(--primary) 25%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.page-card__foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.page-card__origin {
  min-width: 0;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-card__origin b { color: var(--fg); font-weight: 700; }

.page-card__index {
  margin-inline-start: auto;
  flex: 0 0 auto;
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Rotation marker so the state is visible without reading the canvas. */
.page-card__rotated {
  flex: 0 0 auto;
  color: var(--primary);
  display: none;
}
.page-card[data-rotated="true"] .page-card__rotated { display: inline-flex; }

/* --------------------------------------------------------- hover actions */

.page-card__actions {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2);
  background: linear-gradient(to top, rgba(6, 11, 22, 0.82), rgba(6, 11, 22, 0));
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.page-card:hover .page-card__actions,
.page-card:focus-within .page-card__actions {
  opacity: 1;
  transform: none;
}

/* Touch has no hover — keep the controls permanently visible there. */
@media (pointer: coarse) {
  .page-card__actions { opacity: 1; transform: none; }
}

.page-action {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: #0b1220;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.page-action:hover { background: #fff; }
.page-action--danger:hover { background: var(--danger); color: #fff; }
.page-action:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

@media (pointer: coarse) {
  .page-action { width: 44px; height: 44px; }
}

/* Drag handle sits top-left, always available (including on touch). */
.page-card__handle {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.9);
  color: #0b1220;
  cursor: grab;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.page-card:hover .page-card__handle,
.page-card:focus-within .page-card__handle { opacity: 1; }
.page-card__handle:active { cursor: grabbing; }

@media (pointer: coarse) {
  .page-card__handle { opacity: 1; width: 44px; height: 44px; }
}

/* ---------------------------------------------------------------- footer */

.studio__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}
.studio__foot .spacer { flex: 1; }

.studio__status {
  min-height: 22px;
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.filename-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.filename-field label { font-size: var(--text-sm); color: var(--fg-muted); white-space: nowrap; }
.filename-field input {
  width: 190px;
  min-height: 44px;
  padding: 0 var(--space-3);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--text-sm);
}
.filename-field input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent);
}

/* --------------------------------------------------------------- mobile */

@media (max-width: 599px) {
  .page-grid { --thumb: 140px; gap: var(--space-3); }

  .studio__bar {
    /* Stack the toolbar rather than letting it crowd on one line. */
    flex-direction: column;
    align-items: stretch;
  }
  .studio__bar-right { margin-inline-start: 0; }
  .studio__bar-left,
  .studio__bar-right { justify-content: space-between; }
  .zoom { flex: 1; }
  .zoom input[type="range"] { flex: 1; width: auto; }
  .filename-field { width: 100%; }
  .filename-field input { flex: 1; width: auto; }
}
