/* GetXtra Tools 2.0 — tool page and the tool workspace rendered by assets/js/engine. */

.tool-hero {
  padding-block: var(--space-8) var(--space-8);
  text-align: center;
}

.tool-hero .breadcrumbs ol {
  justify-content: center;
}

.tool-hero .tool-icon {
  margin: var(--space-8) auto var(--space-5);
}

.tool-hero h1 {
  font-size: var(--text-4xl);
}

.tool-hero .lead {
  max-width: 640px;
  margin: var(--space-3) auto 0;
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--success-soft);
  color: var(--success);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ---------- Workspace ---------- */
.workspace {
  position: relative;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.workspace-loading {
  display: grid;
  place-items: center;
  min-height: 320px;
  color: var(--text-subtle);
}

.workspace-grid {
  display: grid;
}

@media (min-width: 960px) {
  .workspace-grid {
    grid-template-columns: minmax(0, 1fr) 340px;
  }
}

.workspace-main {
  min-width: 0;
  padding: var(--space-5);
}

.workspace-side {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

@media (min-width: 960px) {
  .workspace-side {
    border-top: 0;
    border-left: 1px solid var(--border);
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  }
}

.workspace-side-body {
  flex: 1;
  padding: var(--space-5);
}

.workspace-side h2 {
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
}

.workspace-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

@media (min-width: 960px) {
  .workspace-actions {
    border-radius: 0 0 var(--radius-xl) 0;
  }
}

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

.toolbar-title {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ---------- Dropzone ---------- */
.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: var(--space-4);
  min-height: 300px;
  margin: var(--space-3);
  padding: var(--space-10) var(--space-6);
  border: 2px dashed var(--border-strong);
  border-radius: calc(var(--radius-xl) - 6px);
  background: var(--bg-subtle);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration) var(--ease), background-color var(--duration) var(--ease);
}

.dropzone:hover {
  border-color: var(--brand);
}

.dropzone:focus-within {
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.dropzone.dragging {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--surface);
  color: var(--brand-text);
  box-shadow: var(--shadow-md);
  transition: transform var(--duration) var(--ease);
}

.dropzone.dragging .dropzone-icon {
  transform: translateY(-4px) scale(1.05);
}

.dropzone-icon .icon {
  width: 28px;
  height: 28px;
}

.dropzone h2 {
  font-size: var(--text-xl);
}

.dropzone p {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-5);
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

.dropzone-meta span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* ---------- File list ---------- */
.file-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long file names must not widen the list */
  gap: var(--space-2);
  padding: 0;
  list-style: none;
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  padding-right: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: box-shadow var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}

.file-item.sortable .drag-handle {
  touch-action: none;
}

.file-item.drag-source {
  opacity: 0.4;
}

.file-item.drag-ghost {
  position: fixed;
  z-index: var(--z-modal);
  pointer-events: none;
  box-shadow: var(--shadow-xl);
  transform: rotate(1deg);
}

.drag-handle {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 40px;
  color: var(--text-subtle);
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.file-thumb {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 64px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-subtle);
}

.file-thumb img,
.file-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  color: var(--text-subtle);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.file-actions {
  display: flex;
  flex: none;
  gap: 2px;
}

/* Small phones: sortable rows have a handle, a thumbnail and three buttons — make room for the name. */
@media (max-width: 479px) {
  .file-item {
    gap: var(--space-2);
    padding-right: var(--space-2);
  }

  .file-item .file-thumb {
    width: 40px;
    height: 48px;
  }

  .file-item.sortable .drag-handle {
    width: 18px;
  }
}

.add-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 52px;
  margin-top: var(--space-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.add-more:hover {
  border-color: var(--brand);
  color: var(--brand-text);
}

/* ---------- Page grid (PDF page thumbnails) ---------- */
.page-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  padding: 0;
  list-style: none;
}

.page-tile {
  position: relative;
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  padding: var(--space-2);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  user-select: none;
  transition: border-color var(--duration-fast) var(--ease), background-color var(--duration-fast) var(--ease);
}

.page-tile:focus-visible {
  outline: none;
  border-color: var(--brand);
}

.page-tile .page-canvas {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
}

.page-tile canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 3px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration) var(--ease);
}

.page-tile .page-number {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-tile .page-tools {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: flex;
  gap: 2px;
}

.page-tile .page-tools .btn {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.page-grid[data-mode="select"] .page-tile {
  cursor: pointer;
}

.page-tile[aria-pressed="true"] {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.page-tile[aria-pressed="true"] canvas {
  opacity: 0.45;
}

.page-tile .page-mark {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: none;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
}

.page-tile[aria-pressed="true"] .page-mark {
  display: grid;
}

.page-grid[data-mode="pick"] .page-tile {
  cursor: pointer;
}

.page-grid[data-mode="pick"] .page-tile[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.page-grid[data-mode="pick"] .page-tile[aria-pressed="true"] canvas {
  opacity: 1;
}

.page-grid[data-mode="pick"] .page-mark {
  background: var(--brand);
  color: var(--brand-fg);
}

.page-grid[data-mode="reorder"] .page-tile {
  cursor: grab;
  touch-action: none;
}

.page-tile.drag-source {
  opacity: 0.35;
}

.page-tile.drop-before {
  box-shadow: -6px 0 0 -2px var(--brand);
}

.page-tile.drop-after {
  box-shadow: 6px 0 0 -2px var(--brand);
}

/* ---------- Options ---------- */
.file-option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.file-option-name {
  flex: 1 1 8rem;
  min-width: 0;
  overflow: hidden;
  color: var(--text-subtle);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.options {
  display: grid;
  gap: var(--space-5);
}

.options .field + .field {
  margin-top: 0;
}

.option-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.option-row .input {
  min-width: 0;
}

.option-link {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
}

.option-link[aria-pressed="true"] {
  background: var(--brand-soft);
  color: var(--brand-text);
}

/* ---------- Processing ---------- */
.processing {
  display: grid;
  place-items: center;
  gap: var(--space-5);
  min-height: 320px;
  padding: var(--space-10) var(--space-6);
  text-align: center;
}

.processing .progress {
  width: min(360px, 100%);
}

.processing h2 {
  font-size: var(--text-xl);
}

.processing p {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* ---------- Result ---------- */
.result {
  padding: var(--space-6) var(--space-5);
}

.result-head {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  text-align: center;
}

.result-check {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  animation: pop-in var(--duration-slow) var(--ease);
}

.result-check .icon {
  width: 28px;
  height: 28px;
}

.result-head h2 {
  font-size: var(--text-2xl);
}

.result-head p {
  color: var(--text-muted);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.saving {
  color: var(--success);
  font-weight: 700;
}

.result-list {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  max-width: 980px;
  margin: var(--space-8) auto 0;
  padding: 0;
  list-style: none;
}

.result-item {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.result-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  padding: var(--space-3);
  background:
    repeating-conic-gradient(var(--bg-muted) 0% 25%, var(--surface) 0% 50%) 0 0 / 16px 16px;
  border-bottom: 1px solid var(--border);
}

.result-preview img {
  max-height: 100%;
  object-fit: contain;
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
}

.result-preview .icon {
  width: 40px;
  height: 40px;
  color: var(--text-subtle);
}

.result-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
}

.result-meta > div {
  flex: 1;
  min-width: 0;
}

.compare {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

/* ---------- Single preview (crop, QR) ---------- */
.preview-stage {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background:
    repeating-conic-gradient(var(--bg-muted) 0% 25%, var(--surface) 0% 50%) 0 0 / 18px 18px;
}

.crop-stage {
  width: 100%;
  height: min(60vh, 520px);
  min-height: 280px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-muted);
}

.crop-stage img {
  display: block;
  max-width: 100%;
}

.qr-preview {
  width: min(320px, 100%);
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-md);
  image-rendering: pixelated;
}

.tool-error {
  margin: var(--space-4) var(--space-5) 0;
}

/* ---------- Content below the workspace ---------- */
.tool-content {
  display: grid;
  gap: var(--space-16);
  padding-block: var(--space-16);
}

.tool-aside {
  display: grid;
  justify-items: center;
}

.tool-content h2 {
  margin-bottom: var(--space-6);
  font-size: var(--text-2xl);
}

.howto {
  display: grid;
  gap: var(--space-4);
  counter-reset: step;
  padding: 0;
  list-style: none;
}

@media (min-width: 768px) {
  .howto {
    grid-template-columns: repeat(3, 1fr);
  }
}

.howto li {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-muted);
}

.howto li::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: var(--text-sm);
  font-weight: 700;
}

/* The result heading receives focus for screen readers; no ring needed for that programmatic focus. */
.result-head h2:focus {
  outline: none;
}

/* ---------- Phase 2 stages: PDF form fields, page crop, image editors, palette ---------- */
.form-stage {
  display: grid;
  gap: var(--space-4);
}

.form-fields {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  align-items: start;
}

.form-fields .field + .field {
  margin-top: 0;
}

.radio-list {
  display: grid;
  gap: var(--space-2);
}

.crop-stage-page {
  background: var(--bg-muted);
}

.crop-note {
  margin-top: var(--space-3);
}

.image-preview {
  min-height: 260px;
}

.preview-canvas {
  display: block;
  max-width: 100%;
  max-height: min(56vh, 480px);
  height: auto;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}

.preview-files {
  margin-top: var(--space-4);
}

/* Add text to image: canvas editor with a layer list */
.text-editor {
  display: grid;
  gap: var(--space-3);
}

.text-stage {
  padding: var(--space-3);
}

.text-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-sm);
  cursor: move;
  touch-action: none;
}

.text-canvas:focus-visible {
  outline: none;
  box-shadow: var(--ring-offset), var(--ring);
}

.text-canvas.dragging {
  cursor: grabbing;
}

.layer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.layer-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-width: 0;
  padding: 0;
  list-style: none;
}

.layer-item {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
}

.layer-select {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  max-width: 14rem;
  min-height: 34px;
  padding: 0 var(--space-2) 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.layer-select span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-select[aria-pressed="true"] {
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 600;
}

.layer-select:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Colour palette */
.palette-stage {
  display: grid;
  gap: var(--space-5);
}

@media (min-width: 1100px) {
  .palette-stage {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: start;
  }
}

.palette-image {
  min-height: 220px;
}

.swatches {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
}

.swatches[aria-busy="true"] {
  opacity: 0.6;
}

.swatch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.swatch-chip {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
}

.swatch-info {
  display: grid;
  flex: 1 1 7rem;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.swatch-copy {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* PDF bookmarks editor */
.bm-stage {
  display: grid;
  gap: var(--space-3);
}

.bm-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.bm-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.bm-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-left: min(calc(var(--bm-level, 0) * 1.25rem), 6rem);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  background: var(--surface);
}

.bm-fields {
  display: flex;
  flex: 1 1 14rem;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.bm-title {
  flex: 1 1 auto;
  min-width: 0;
}

.bm-page-label {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
}

.bm-page {
  width: 5rem;
}

.bm-actions {
  display: flex;
  flex: none;
  gap: 2px;
  margin-left: auto;
}

/* Compare PDF */
.cmp-stage {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.cmp-summary {
  display: grid;
  gap: var(--space-2);
}

.cmp-summary-text {
  margin: 0;
  font-weight: 600;
}

.cmp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.cmp-chip {
  border-color: var(--danger);
  color: var(--danger);
}

.cmp-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

.cmp-panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-2);
  min-width: 0;
}

.cmp-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-muted);
  overflow: hidden;
}

.cmp-pane-diff {
  grid-column: 1 / -1;
}

.cmp-pane-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-sm);
}

.cmp-pane-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmp-scroll {
  position: relative; /* offsetTop of the pages is measured from the scroll box */
  display: grid;
  gap: var(--space-3);
  align-content: start;
  height: min(70vh, 760px);
  padding: var(--space-2);
  overflow: auto;
  overscroll-behavior: contain;
}

.cmp-scroll:focus-visible {
  outline: none;
  box-shadow: inset var(--ring);
}

.cmp-pane-diff .cmp-scroll {
  justify-items: center;
}

.cmp-pane-diff .cmp-block {
  width: min(100%, 720px);
}

.cmp-block {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.cmp-page-label {
  color: var(--text-muted);
  font-size: var(--text-xs, 0.75rem);
  font-weight: 600;
}

.cmp-block.is-changed .cmp-page-label {
  color: var(--danger);
}

.cmp-page {
  position: relative;
  width: 100%;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.cmp-block.is-changed .cmp-page {
  outline: 2px solid var(--danger);
  outline-offset: 1px;
}

.cmp-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.cmp-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cmp-mark {
  position: absolute;
  border-radius: 2px;
  mix-blend-mode: multiply;
}

.cmp-del {
  background: rgb(230 57 70 / 0.38);
  box-shadow: 0 0 0 1px rgb(200 38 27 / 0.7);
}

.cmp-ins {
  background: rgb(42 157 143 / 0.4);
  box-shadow: 0 0 0 1px rgb(15 123 85 / 0.7);
}

.cmp-no-marks .cmp-marks {
  display: none;
}

.cmp-missing {
  display: grid;
  place-items: center;
  background: var(--surface);
  outline: 1px dashed var(--border-strong);
}

.cmp-missing-note {
  padding: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

@media (max-width: 559px) {
  .cmp-scroll {
    height: 52vh;
    padding: var(--space-1);
  }

  .cmp-pane-head .badge + .cmp-pane-name {
    display: none;
  }
}

/* ---------- Page editor (sign, annotate, redact, edit PDF) ---------- */
.pe {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.pe-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.pe-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  padding-right: var(--space-2);
  border-right: 1px solid var(--border);
}

.pe-group:last-child {
  border-right: 0;
  padding-right: 0;
}

.pe-mode[aria-pressed="true"] {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-text);
}

@media (max-width: 640px) {
  .pe-mode-label {
    display: none;
  }
}

.pe-zoom {
  min-width: 3.2em;
  text-align: center;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.pe-nav .select {
  width: auto;
  min-height: 2rem;
  padding-block: 0;
  font-size: var(--text-sm);
}

.pe-body {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}

@media (min-width: 1200px) {
  .pe-body {
    grid-template-columns: minmax(0, 1fr) 260px;
    align-items: start;
  }
}

.pe-viewport {
  overflow: auto;
  max-height: min(78vh, 1100px);
  min-height: 320px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-muted);
}

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

.pe-page {
  position: relative;
  margin-inline: auto;
  background: #fff;
  box-shadow: var(--shadow-md);
}

.pe-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.pe-canvas {
  position: absolute;
  inset: 0;
}

.pe-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pe-viewport:not([data-mode="select"]) .pe-overlay {
  cursor: crosshair;
  touch-action: none;
}

.pe-viewport[data-mode="highlight"] .pe-overlay,
.pe-viewport[data-mode="underline"] .pe-overlay,
.pe-viewport[data-mode="strike"] .pe-overlay {
  cursor: text;
}

.pe-viewport[data-mode="select"] .pe-obj {
  cursor: move;
  touch-action: none;
}

.pe-selection {
  stroke: var(--brand);
  pointer-events: none;
}

.pe-handle {
  fill: #fff;
  stroke: var(--brand);
  cursor: nwse-resize;
  touch-action: none;
}

.pe-handle[data-handle="ne"],
.pe-handle[data-handle="sw"] {
  cursor: nesw-resize;
}

.pe-preview {
  pointer-events: none;
}

.pe-side,
.pe-panels {
  display: grid;
  gap: var(--space-3);
  align-content: start;
  min-width: 0;
}

.pe-panel {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.pe-panel h3,
.pe-items h3 {
  margin: 0;
  font-size: var(--text-sm);
}

.pe-panel .field {
  margin: 0;
}

.pe-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.pe-swatch {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.pe-swatch input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.pe-swatch-dot {
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid var(--surface);
  border-radius: var(--radius-full);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.pe-swatch input:checked + .pe-swatch-dot {
  box-shadow: 0 0 0 2px var(--brand);
}

.pe-swatch input:focus-visible + .pe-swatch-dot {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
}

.pe-items {
  display: grid;
  gap: var(--space-2);
}

.pe-list {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pe-item {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.pe-item:hover,
.pe-item.is-selected {
  border-color: var(--border);
  background: var(--bg-subtle);
}

.pe-note {
  margin: 0;
}

/* Signature panel */
.sign-body {
  display: grid;
  gap: var(--space-3);
}

.sign-pad-wrap {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}

.sign-pad {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 1;
  touch-action: none;
  cursor: crosshair;
}

.sign-fonts {
  display: grid;
  gap: var(--space-2);
}

.sign-font {
  position: relative;
  display: block;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: #111827;
  cursor: pointer;
}

.sign-font input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.sign-font:has(input:checked) {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}

.sign-font:has(input:focus-visible) {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.sign-font-sample {
  display: block;
  overflow: hidden;
  font-size: 1.9rem;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .pe-panel {
    padding: var(--space-3);
  }

  .pe-viewport {
    padding: var(--space-2);
  }

  .sign-pad {
    aspect-ratio: 5 / 2;
  }
}

/* ---------- Text results (OCR, AI summaries and descriptions) ---------- */
.text-results {
  display: grid;
  gap: var(--space-4);
  max-width: 860px;
  margin: 0 auto;
}

.text-result-card {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.text-result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.text-result-head label,
.text-result-head h3 {
  flex: 1 1 12rem;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: var(--text-sm);
  font-weight: 600;
}

.text-result {
  width: 100%;
  min-height: 10rem;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: var(--text-sm);
  line-height: 1.6;
  resize: vertical;
}

.text-result-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
}

/* Before/after comparison of an AI image result */
.compare-view {
  position: relative;
  max-width: 860px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    repeating-conic-gradient(var(--bg-muted) 0% 25%, var(--surface) 0% 50%) 0 0 / 16px 16px;
}

.compare-view img {
  display: block;
  width: 100%;
  height: auto;
}

.compare-view .compare-after {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* transparent results (background removal) must not show the original underneath */
  background:
    repeating-conic-gradient(var(--bg-muted) 0% 25%, var(--surface) 0% 50%) 0 0 / 16px 16px;
}

.compare-view .compare-after img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.compare-slider {
  display: block;
  width: min(100%, 860px);
  margin: var(--space-3) auto 0;
}

.compare-labels {
  display: flex;
  justify-content: space-between;
  max-width: 860px;
  margin: var(--space-1) auto 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* AI image generator: the prompt is the stage */
.ai-prompt-stage {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
}

.ai-prompt {
  min-height: 9rem;
  font-size: var(--text-base);
  line-height: 1.6;
  resize: vertical;
}

.prompt-examples {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.prompt-chip {
  min-height: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

/* AI object remover: brush on the photo */
.brush-stage {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
}

@media (max-width: 480px) {
  .brush-stage {
    padding: var(--space-2);
  }
}

.brush-canvas-wrap {
  position: relative;
  justify-self: center;
  max-width: 100%;
  touch-action: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.brush-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.brush-canvas-wrap .brush-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.brush-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

/* Favourite + privacy note under the tool heading */
.tool-hero-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-3);
  margin-top: var(--space-4);
}

.tool-hero-actions .privacy-pill {
  margin: 0;
}
