/* ── PDF Workspace page styles ──
   Layout: action bar on top, then pages | options | ad slot, then the
   add/undo/redo bar. Narrower screens stack the columns; the ad slot always
   keeps its 300×250 box so nothing moves when an ad is added later. */

.pw-app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  /* Reserve the tool's height before the script runs (CLS). */
  min-height: 560px;
}
.pw-app [hidden] { display: none !important; }

/* Action bar: tabs and Download */
.pw-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.pw-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
}
.pw-tab {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pw-tab:hover { color: var(--text); background: var(--surface-2); }
.pw-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-2);
}
.pw-app button:focus-visible,
.pw-app input:focus-visible,
.pw-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Status line and error */
.pw-msgs { padding: var(--space-2) 0; }
.pw-note-slot { min-height: 1.45em; margin-bottom: 4px; }  /* reserved, so the note causes no layout shift */
.pw-download-note { margin: 0; font-size: 13px; line-height: 1.45; font-weight: 600; color: var(--text-2); overflow-wrap: anywhere; }
@media (max-width: 559px) {
  .pw-note-slot { min-height: 2.9em; }   /* room for a long translation to wrap to two lines */
}
.pw-status {
  min-height: 1.45em;
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-3);
}
.pw-error {
  margin: var(--space-2) 0 0;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: color-mix(in oklch, var(--color-danger) 12%, var(--surface));
  border: 1px solid color-mix(in oklch, var(--color-danger) 45%, var(--surface));
  border-radius: var(--radius-sm);
}

/* Grid: bar and messages on top, pages | options | ad, bottom bar.
   Narrower: the ad slot moves below the tool; on a phone everything stacks. */
.pw-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px 300px;
  grid-template-areas:
    "bar   bar     bar"
    "msgs  msgs    msgs"
    "pages options ad"
    "foot  foot    foot";
  column-gap: var(--space-4);
  align-items: start;
}
.pw-bar { grid-area: bar; }
.pw-msgs { grid-area: msgs; }
.pw-pages { grid-area: pages; min-width: 0; position: relative; }
.pw-options { grid-area: options; min-width: 0; }
.pw-foot { grid-area: foot; }
.pw-ad-slot {
  grid-area: ad;
  width: 300px;
  height: 250px;
  justify-self: center;
}

@media (max-width: 1099px) {
  .pw-app {
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-areas: "bar bar" "msgs msgs" "pages options" "foot foot" "ad ad";
  }
  .pw-ad-slot { margin-top: var(--space-4); }
}
@media (max-width: 759px) {
  .pw-app {
    padding: var(--space-3);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bar" "msgs" "pages" "options" "foot" "ad";
  }
  .pw-options { margin-top: var(--space-4); }
  .pw-tab { padding: 8px 10px; }
  .pw-download { width: 100%; }
}

.pw-pages-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  min-height: 1.5em;
  margin-bottom: var(--space-2);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
}

/* Drop zone (empty document) */
.pw-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 320px;
  padding: var(--space-5) var(--space-4);
  text-align: center;
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.pw-dropzone p { margin: 0; }
.pw-drop-title { font-size: 17px; font-weight: 500; color: var(--text); }
.pw-drop-sub { font-size: 14px; color: var(--text-3); }
.pw-dropzone .btn { margin-top: var(--space-2); }
.pw-pages.pw-dragover .pw-dropzone,
.pw-pages.pw-dragover .pw-grid {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Page grid */
.pw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
  min-height: 320px;
  align-content: start;
  padding: 2px;
  border: 2px dashed transparent;
  border-radius: var(--radius-md);
}
.pw-page {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 0;
  cursor: grab;
  user-select: none;
}
.pw-page.pw-is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.pw-page.sortable-ghost { opacity: 0.4; }
.pw-page.sortable-chosen { box-shadow: var(--shadow-card-hover); }

/* The thumbnail box is square and sized before the canvas arrives. */
.pw-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 4px;
}
.pw-thumb canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 0 0 1px var(--border);
  transition: transform var(--transition);
}
.pw-page[data-rotation="90"] .pw-thumb canvas { transform: rotate(90deg); }
.pw-page[data-rotation="180"] .pw-thumb canvas { transform: rotate(180deg); }
.pw-page[data-rotation="270"] .pw-thumb canvas { transform: rotate(270deg); }

.pw-page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.pw-num {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.pw-select {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.pw-page-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.pw-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pw-icon:hover { color: var(--text); background: var(--surface-2); }
.pw-icon:disabled { opacity: 0.35; cursor: default; }
.pw-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Options panel */
.pw-panel {
  padding: var(--space-4);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.pw-h2 {
  margin: 0 0 var(--space-2);
  font-size: 17px;
  font-weight: 600;
}
.pw-h3 {
  margin: var(--space-5) 0 var(--space-2);
  padding-top: var(--space-4);
  font-size: 15px;
  font-weight: 600;
  border-top: 1px solid var(--border);
}
.pw-hint {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-3);
}
.pw-panel > .pw-hint:last-child { margin-bottom: 0; }
.pw-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.pw-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-2);
}
.pw-app .pw-split-n {
  max-width: 120px;
  min-height: 40px;
  margin-bottom: var(--space-2);
  font-family: var(--mono);
}
.pw-panel .btn { max-width: 100%; white-space: normal; text-align: center; }

/* Stamp tab: fields */
.pw-h3-first { margin-top: var(--space-3); padding-top: 0; border-top: 0; }
.pw-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin-bottom: var(--space-3);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.pw-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.pw-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.pw-field { min-width: 0; margin-bottom: var(--space-2); }
.pw-fields .pw-field { margin-bottom: 0; }
.pw-app .pw-input { min-height: 40px; max-width: 100%; }
.pw-app .pw-input:disabled { opacity: 0.5; cursor: default; }
.pw-range { display: block; width: 100%; margin: 6px 0; accent-color: var(--accent); }
.pw-hint-tight { margin-top: 6px; }
.pw-label output { font-family: var(--mono); color: var(--text); }

/* Live stamp preview on a thumbnail. The layer has the shape of the page as
   shown (aspect ratio set from the canvas) and is its own size container, so
   every length inside is in cqw (percent of the page width). It is drawn over
   the canvas and never touches it. */
.pw-thumb { container-type: size; }
.pw-stamp-layer,
.pw-sign-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100cqw, calc(100cqh * var(--pw-ar, 0.77)));
  aspect-ratio: var(--pw-ar, 0.77);
  transform: translate(-50%, -50%);
  container-type: inline-size;
  overflow: hidden;
  pointer-events: none;
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1;
}
/* Signatures sit under the stamps, as in the export. */
.pw-stamp-layer { z-index: 2; }
.pw-sign-layer { z-index: 1; }
.pw-sign-item { position: absolute; display: block; }
.pw-stamp-num {
  position: absolute;
  color: #000;
  white-space: nowrap;
}
.pw-stamp-bottom { bottom: 3.9cqw; }
.pw-stamp-top { top: 3.9cqw; }
.pw-stamp-left { left: 3.9cqw; }
.pw-stamp-right { right: 3.9cqw; }
.pw-stamp-center { left: 50%; transform: translateX(-50%); }
.pw-stamp-wm {
  position: absolute;
  left: 50%;
  top: 50%;
  color: #808080;
  white-space: nowrap;
}

/* Sign tab: controls */
.pw-note {
  margin: 0 0 var(--space-3);
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-2);
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.pw-seg {
  position: relative;
  display: flex;
  margin-bottom: var(--space-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.pw-seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.pw-seg label {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 40px;
  padding: 6px;
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  cursor: pointer;
}
.pw-seg label + input + label { border-left: 1px solid var(--border-2); }
.pw-seg label:hover { color: var(--text); background: var(--surface-2); }
.pw-seg input:checked + label { color: var(--text); font-weight: 600; background: var(--accent-soft); }
.pw-seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.pw-sign-block { margin-bottom: var(--space-3); }
.pw-sign-pad {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 280;
  margin-bottom: var(--space-2);
  background: #fff;
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-sm);
  touch-action: none;
  cursor: crosshair;
}
.pw-app .pw-sign-name { width: 100%; margin-bottom: var(--space-3); }
.pw-fieldset { min-width: 0; margin: 0 0 var(--space-2); padding: 0; border: 0; }
.pw-fieldset .pw-check { margin-bottom: 4px; }
.pw-fieldset .pw-row { column-gap: var(--space-4); }
.pw-style-script span { font-family: "Segoe Script", "Brush Script MT", "Snell Roundhand", "Apple Chancery", "URW Chancery L", "Z003", cursive; font-style: italic; font-size: 17px; }
.pw-style-classic span { font-family: "Instrument Serif", Georgia, "Times New Roman", serif; font-style: italic; font-size: 18px; }
.pw-style-bold span { font-family: Georgia, "DejaVu Serif", "Times New Roman", serif; font-style: italic; font-weight: 700; }
.pw-sign-preview canvas,
.pw-sign-current img {
  display: block;
  max-width: 100%;
  max-height: 72px;
  width: auto;
  height: auto;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.pw-sign-preview canvas[width="10"] { display: none; }
.pw-sign-file { display: block; max-width: 100%; margin-bottom: var(--space-2); font-size: 13px; }
.pw-sign-current { margin-top: var(--space-3); }

/* Sign tab: large page view with movable signature boxes */
.pw-view { margin-bottom: var(--space-4); }
.pw-view-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.pw-app .pw-view-step { width: 40px; min-height: 40px; }
.pw-view-label {
  min-width: 8em;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
}
.pw-page-view {
  display: flex;
  justify-content: center;
  padding: var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius-md);
}
.pw-page-view:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pw-view-sheet {
  position: relative;
  width: min(100%, calc(72vh * var(--pw-ar, 0.77)));
  aspect-ratio: var(--pw-ar, 0.77);
  background: #fff;
  box-shadow: 0 0 0 1px var(--border), 0 2px 10px rgb(0 0 0 / 0.12);
}
.pw-view-sheet canvas { display: block; width: 100%; height: 100%; }
.pw-overlay {
  position: absolute;
  box-sizing: border-box;
  outline: 1px dashed var(--accent);
  cursor: move;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
/* The image fills its box, turned by the overlay's rotation (data-rot). For a
   quarter turn it is laid out with the box's sides swapped (cq units of the
   box), then turned into place. */
.pw-overlay,
.pw-sign-item { container-type: size; }
.pw-overlay img,
.pw-sign-item img {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 100cqw;
  height: 100cqh;
  max-width: none;                /* the site's img rule would cap a turned image at the box width */
  max-height: none;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.pw-overlay[data-rot="90"] img,
.pw-sign-item[data-rot="90"] img { width: 100cqh; height: 100cqw; transform: translate(-50%, -50%) rotate(90deg); }
.pw-overlay[data-rot="180"] img,
.pw-sign-item[data-rot="180"] img { transform: translate(-50%, -50%) rotate(180deg); }
.pw-overlay[data-rot="270"] img,
.pw-sign-item[data-rot="270"] img { width: 100cqh; height: 100cqw; transform: translate(-50%, -50%) rotate(270deg); }
.pw-overlay:hover,
.pw-overlay:focus,
.pw-overlay.pw-is-dragging {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: color-mix(in oklch, var(--accent) 8%, transparent);
}
.pw-overlay-resize {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
}
.pw-overlay-resize::before { content: ""; position: absolute; inset: -10px; }   /* bigger touch target */
.pw-app .pw-overlay-remove {
  position: absolute;
  top: -14px;
  right: -14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 50%;
  cursor: pointer;
}
.pw-overlay-remove svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pw-overlay-remove:hover { color: var(--color-danger); }
.pw-view-hint { margin: var(--space-2) 0 0; }

/* Bottom bar */
.pw-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
/* Offline status (pdf/offline.js): its own line under the buttons, with the
   space reserved even while it is hidden or empty, so it never moves the
   layout when it appears or changes. One line on wide screens, up to two
   below 760px and three below 480px (the longest translation fits). */
.pw-offline {
  flex: 1 0 100%;
  margin: 0;
  min-height: calc(13px * 1.45);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-3);
}
.pw-app .pw-offline[hidden] { display: block !important; visibility: hidden; }

@media (max-width: 759px) {
  .pw-offline { min-height: calc(2 * 13px * 1.45); }
  .pw-page-view { padding: var(--space-3); }
  .pw-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-2);
  }
  .pw-page { padding: 6px; }
}

/* Convert tab */
.pw-text-label { margin-top: var(--space-3); }
.pw-app .pw-text-output {
  display: block;
  width: 100%;
  min-height: 160px;
  margin-bottom: var(--space-2);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}
.pw-text-empty { margin-top: var(--space-3); }
.pw-text-empty a { color: var(--accent); }

/* Compress tab */
.pw-compress-quality { max-width: 260px; margin-bottom: var(--space-3); }
.pw-size-line { margin: 0 0 var(--space-2); font-size: 14px; color: var(--text-2); }
.pw-size-line strong, #pw-size-after { color: var(--text); }
#pw-size-after { font-weight: 600; }
#pw-compress-download { margin-top: var(--space-2); }

@media (max-width: 479px) {
  .pw-offline { min-height: calc(3 * 13px * 1.45); }
}
