/*
  PDF Tools. Loaded only on the PDF tool pages. Plain CSS, not built by
  Tailwind; colours come from the site's theme tokens so dark mode just works.
  Pages themselves are always drawn as paper (white).
*/

.pdft {
  --pdft-line: var(--color-base-300);
  --pdft-accent: var(--color-primary);
  --pdft-radius: 0.875rem;
  --pdft-sans: PdftSans, var(--font-sans);
  --pdft-serif: PdftSerif, Georgia, serif;
  position: relative;
}

.pdft-icon { display: inline-flex; width: 1.125rem; height: 1.125rem; flex: none; }
.pdft-icon svg { width: 100%; height: 100%; }

/* ---- Drop zone ---- */

.pdft-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 3rem 1.25rem;
  text-align: center;
  border: 2px dashed var(--pdft-line);
  border-radius: var(--pdft-radius);
  background: var(--color-base-100);
  transition: border-color 0.15s, background-color 0.15s;
}
.pdft.is-dragover .pdft-drop,
.pdft.is-dragover .pdft-work {
  border-color: var(--pdft-accent);
  background: color-mix(in oklab, var(--pdft-accent) 7%, var(--color-base-100));
}
.pdft-drop-icon { width: 3rem; height: 3rem; color: var(--pdft-accent); }
.pdft-drop-title { font-size: 1.375rem; font-weight: 600; }
.pdft-private {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}
.pdft-private svg { width: 1rem; height: 1rem; }
.pdft-error { color: var(--color-error); font-size: 0.9375rem; max-width: 60ch; }

/* ---- Workspace ---- */

.pdft-work {
  border: 1px solid var(--pdft-line);
  border-radius: var(--pdft-radius);
  background: var(--color-base-100);
}
.pdft-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--pdft-line);
}
.pdft-title { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.pdft-head-actions { display: flex; gap: 0.5rem; }
.pdft-head-actions .btn { gap: 0.35rem; }

.pdft-body { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 64rem) {
  .pdft-body { grid-template-columns: minmax(0, 1fr) 19rem; }
  .pdft-side { border-left: 1px solid var(--pdft-line); border-top: 0 !important; }
  .pdft-side-inner { position: sticky; top: 5rem; }
}
.pdft-stage {
  min-width: 0;
  min-height: 18rem;
  padding: 1rem;
  background: var(--color-base-200);
  border-radius: 0 0 0 var(--pdft-radius);
}
.pdft-side {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.25rem;
  border-top: 1px solid var(--pdft-line);
}
@media (min-width: 64rem) {
  .pdft-go { position: sticky; bottom: 1rem; background: var(--color-base-100); padding-top: 0.5rem; }
}
.pdft-options { display: flex; flex-direction: column; gap: 1.1rem; }
.pdft-go { display: flex; flex-direction: column; gap: 0.5rem; }
.pdft-hint, .pdft-note { font-size: 0.875rem; color: var(--muted); line-height: 1.45; }
.pdft-status { font-size: 0.875rem; min-height: 1.25rem; }
.pdft-status.is-error, .pdft-field-error { color: var(--color-error); }
.pdft-field-error { font-size: 0.8125rem; }
.pdft-field-error:empty { display: none; }
.pdft-summary { font-weight: 600; }
.pdft-work.is-busy .pdft-stage { opacity: 0.6; pointer-events: none; }
.pdft-work.is-busy .pdft-status::before {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-right: 0.4rem;
  vertical-align: -0.1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: pdft-spin 0.7s linear infinite;
}
@keyframes pdft-spin { to { transform: rotate(360deg); } }

.pdft-field { display: flex; flex-direction: column; gap: 0.45rem; }
.pdft-label { font-size: 0.875rem; font-weight: 600; }
.pdft-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.pdft-row .btn { gap: 0.3rem; }
.pdft-inline { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; font-size: 0.875rem; font-weight: 600; }
.pdft-inline[hidden], .pdft-field[hidden] { display: none; }
.pdft-check { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.9375rem; cursor: pointer; }
.pdft-check input { margin-top: 0.15rem; }

/* Segmented choice */
.pdft-seg {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--pdft-line);
  border-radius: 0.625rem;
  overflow: hidden;
  background: var(--color-base-100);
}
.pdft-seg label { flex: 1 1 auto; position: relative; cursor: pointer; }
.pdft-seg input { position: absolute; opacity: 0; pointer-events: none; }
.pdft-seg span {
  display: block;
  padding: 0.4rem 0.6rem;
  text-align: center;
  font-size: 0.8125rem;
  white-space: nowrap;
}
.pdft-seg label + label span { border-left: 1px solid var(--pdft-line); }
.pdft-seg input:checked + span { background: var(--color-base-content); color: var(--color-base-100); font-weight: 600; }
.pdft-seg input:focus-visible + span { outline: 2px solid var(--pdft-accent); outline-offset: -2px; }

.pdft-swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pdft-swatch {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid color-mix(in oklab, var(--color-base-content) 25%, transparent);
  cursor: pointer;
}
.pdft-swatch[aria-pressed="true"] { outline: 2px solid var(--color-base-content); outline-offset: 2px; }

/* Result */
.pdft-result {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  border: 1px solid color-mix(in oklab, var(--color-success) 60%, var(--pdft-line));
  border-radius: 0.75rem;
  background: color-mix(in oklab, var(--color-success) 8%, var(--color-base-100));
}
.pdft-result[hidden] { display: none; }
.pdft-result-title { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; }
.pdft-result-title .pdft-icon { color: var(--color-success); }
.pdft-result-name { font-size: 0.875rem; color: var(--muted); overflow-wrap: anywhere; }
.pdft-result-note { font-size: 0.875rem; line-height: 1.45; }

/* Compress: the size box and its unit */
.pdft-options[hidden] { display: none; }
.pdft-num { width: 7rem; }
.pdft-unit { width: 5rem; }
.pdft-next { font-size: 0.875rem; }
.pdft-next ul { margin-top: 0.3rem; display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; }
.pdft-next a { text-decoration: underline; text-underline-offset: 2px; }

/* ---- Tiles (pages and files) ---- */

.pdft-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 1rem;
  user-select: none;
  -webkit-user-select: none;
}
.pdft-tiles.is-files { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
.pdft-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem;
  border: 2px solid transparent;
  border-radius: 0.75rem;
  background: var(--color-base-100);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  cursor: pointer;
  -webkit-touch-callout: none;
  transition: border-color 0.12s, opacity 0.12s;
}
.pdft-tiles.is-sortable .pdft-tile { cursor: grab; }
.pdft-tile:focus-visible { outline: 2px solid var(--pdft-accent); outline-offset: 2px; }
.pdft-tile.is-dragging {
  z-index: 5;
  cursor: grabbing;
  box-shadow: 0 12px 30px rgb(0 0 0 / 0.25);
  border-color: var(--pdft-accent);
}
.pdft-tile.is-selected { border-color: var(--pdft-accent); }
.pdft-tile.is-new { border-color: color-mix(in oklab, var(--color-success) 70%, transparent); }
.pdft-tile.is-dim { opacity: 0.45; }
.pdft-tiles.is-mark .pdft-tile.is-selected { border-color: var(--color-error); }
.pdft-tiles.is-mark .pdft-tile.is-selected .pdft-tile-thumb { opacity: 0.35; }
.pdft-tiles.is-mark .pdft-tile.is-selected::after {
  content: "✕";
  position: absolute;
  inset: 0.5rem 0.5rem 2rem;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-error);
  pointer-events: none;
}
.pdft-tiles:not(.is-mark) .pdft-tile.is-selected::after {
  content: "✓";
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--pdft-accent);
  color: var(--color-primary-content, #fff);
  font-size: 0.85rem;
  font-weight: 700;
}
.pdft-tile-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 0.375rem;
  background: var(--color-base-200);
  transition: opacity 0.12s;
}
.pdft-tile-thumb img {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08);
  background: #fff;
  pointer-events: none;
  transition: transform 0.2s;
}
.pdft-blank {
  width: auto;
  height: 100%;
  max-width: 100%;
  background: #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.12);
}
.pdft-blank.is-error { display: grid; place-items: center; width: 60%; color: #888; }
.pdft-tile-label {
  font-size: 0.8125rem;
  text-align: center;
  white-space: pre-line;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.pdft-tile-badge {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #fff;
  background: #4b5563;
}
.pdft-tile-badge[hidden] { display: none; }
.pdft-tile[data-group="0"] .pdft-tile-badge { background: #2563eb; }
.pdft-tile[data-group="1"] .pdft-tile-badge { background: #16a34a; }
.pdft-tile[data-group="2"] .pdft-tile-badge { background: #d97706; }
.pdft-tile[data-group="3"] .pdft-tile-badge { background: #db2777; }
.pdft-tile[data-group="4"] .pdft-tile-badge { background: #7c3aed; }
.pdft-tile[data-group="5"] .pdft-tile-badge { background: #0891b2; }
.pdft-tile.is-dim .pdft-tile-badge { background: #6b7280; }
.pdft-tile-btns {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
}
.pdft-iconbtn {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  color: var(--color-base-content);
  background: var(--color-base-200);
  cursor: pointer;
}
.pdft-iconbtn:hover { background: var(--color-base-300); }
.pdft-iconbtn:focus-visible { outline: 2px solid var(--pdft-accent); outline-offset: 1px; }

/* ---- Pages view (edit, sign, forms) ---- */

.pdft-editor { display: flex; flex-direction: column; gap: 0.75rem; }
.pdft-toolbar {
  position: sticky;
  top: 4.5rem;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 1px solid var(--pdft-line);
  border-radius: 0.75rem;
  background: var(--color-base-100);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.08);
}
.pdft-toolbar-gap { flex: 1; }
.pdft-toolbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-base-content);
  cursor: pointer;
}
.pdft-toolbtn:hover:not(:disabled) { background: var(--color-base-200); }
.pdft-toolbtn[aria-pressed="true"] { background: var(--color-base-content); color: var(--color-base-100); }
.pdft-toolbtn:disabled { opacity: 0.4; cursor: default; }
.pdft-toolbtn:focus-visible { outline: 2px solid var(--pdft-accent); outline-offset: 1px; }
@media (max-width: 40rem) { .pdft-toolbtn span:not(.pdft-icon) { display: none; } }

.pdft-pages { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.pdft-sheet {
  position: relative;
  flex: none;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15), 0 8px 24px rgb(0 0 0 / 0.08);
}
.pdft-sheet canvas { display: block; width: 100%; height: 100%; }
.pdft-layer { position: absolute; inset: 0; overflow: hidden; }
.pdft-pages[data-tool="text"] .pdft-layer, .pdft-pages[data-tool="date"] .pdft-layer { cursor: text; }
.pdft-pages[data-tool="pen"] .pdft-layer, .pdft-pages[data-tool="marker"] .pdft-layer,
.pdft-pages[data-tool="box"] .pdft-layer, .pdft-pages[data-tool="whiteout"] .pdft-layer,
.pdft-pages[data-tool="line"] .pdft-layer, .pdft-pages[data-tool="arrow"] .pdft-layer,
.pdft-pages[data-tool="highlight"] .pdft-layer { cursor: crosshair; touch-action: none; }
.pdft-editor .pdft-layer { cursor: crosshair; }
.pdft-pages[data-tool="select"] .pdft-layer { cursor: default; }

/* Things added to a page */
.pdft-obj { position: absolute; touch-action: none; }
.pdft-obj:focus { outline: none; }
.pdft-obj.is-selected, .pdft-obj:focus-visible { outline: 1.5px dashed var(--pdft-accent); outline-offset: 2px; }
.pdft-text {
  min-width: 0.5em;
  padding: 0;
  line-height: 1.25;
  white-space: pre;
  cursor: move;
}
.pdft-text:focus { cursor: text; outline: 1.5px solid var(--pdft-accent); outline-offset: 2px; }
.pdft-text:empty::before { content: attr(data-placeholder); opacity: 0.4; }
.pdft-image { cursor: move; }
.pdft-image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.pdft-rect { cursor: move; }
.pdft-rect.is-whiteout { box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08); }
.pdft-rect.is-highlight, .pdft-path.is-marker { mix-blend-mode: multiply; }
.pdft-path { cursor: move; }
.pdft-path svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.pdft-obj.is-selected.pdft-rect.is-box { outline-offset: calc(var(--s) * 3px); }
.pdft-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--pdft-accent);
  cursor: nwse-resize;
  display: none;
}
.pdft-obj.is-selected .pdft-resize { display: block; }

/* Form fields: filling */
.pdft-input {
  position: absolute;
  margin: 0;
  padding: 0 0.2em;
  border: 0;
  border-radius: 0;
  background: rgb(191 219 254 / 0.45);
  color: #000;
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1.2;
  resize: none;
}
.pdft-input:focus { outline: 2px solid #2563eb; background: rgb(191 219 254 / 0.25); }
.pdft-input:disabled { background: transparent; }
.pdft-input.is-check { accent-color: #111; cursor: pointer; }
textarea.pdft-input { padding-top: 0.15em; }

/* Form fields: creating */
.pdft-fieldbox {
  border: 1.5px solid #2563eb;
  background: rgb(191 219 254 / 0.5);
  cursor: move;
  color: #1e3a8a;
  font: 600 calc(var(--s) * 8px) / 1.1 system-ui, sans-serif;
  overflow: visible;
}
.pdft-fieldbox-name {
  position: absolute;
  left: 0;
  bottom: 100%;
  max-width: 20em;
  padding: 0 0.3em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #2563eb;
  color: #fff;
  border-radius: 3px 3px 0 0;
  pointer-events: none;
}
.pdft-fieldbox.is-radio { border-radius: 50%; }
.pdft-fieldbox.is-dropdown::after { content: "▾"; position: absolute; right: 0.3em; top: 50%; transform: translateY(-50%); }

/* Crop */
.pdft-crop { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.pdft-crop-nav { display: flex; align-items: center; gap: 0.75rem; }
.pdft-crop-frame {
  position: relative;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15), 0 8px 24px rgb(0 0 0 / 0.08);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.pdft-crop-frame canvas { display: block; }
.pdft-crop-frame:focus-visible { outline: 2px solid var(--pdft-accent); outline-offset: 3px; }
.pdft-crop-box {
  position: absolute;
  box-shadow: 0 0 0 9999px rgb(15 23 42 / 0.5);
  outline: 2px solid #fff;
  cursor: move;
}
.pdft-crop-box[hidden] { display: none; }
.pdft-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: var(--pdft-accent);
}
.pdft-handle.is-nw { left: 0; top: 0; cursor: nwse-resize; }
.pdft-handle.is-n { left: 50%; top: 0; cursor: ns-resize; }
.pdft-handle.is-ne { left: 100%; top: 0; cursor: nesw-resize; }
.pdft-handle.is-e { left: 100%; top: 50%; cursor: ew-resize; }
.pdft-handle.is-se { left: 100%; top: 100%; cursor: nwse-resize; }
.pdft-handle.is-s { left: 50%; top: 100%; cursor: ns-resize; }
.pdft-handle.is-sw { left: 0; top: 100%; cursor: nesw-resize; }
.pdft-handle.is-w { left: 0; top: 50%; cursor: ew-resize; }

/* Text to PDF */
.pdft-textarea {
  display: block;
  width: 100%;
  min-height: 26rem;
  padding: 1.25rem;
  border: 1px solid var(--pdft-line);
  border-radius: 0.5rem;
  background: #fff;
  color: #111;
  font-size: 0.9375rem;
  line-height: 1.5;
  resize: vertical;
}

/* Signature dialog */
.pdft-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 0;
  border-radius: var(--pdft-radius, 0.875rem);
  background: var(--color-base-100);
  color: var(--color-base-content);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}
.pdft-dialog::backdrop { background: rgb(15 23 42 / 0.55); }
.pdft-dialog-body { display: flex; flex-direction: column; gap: 0.9rem; padding: 1.25rem; }
.pdft-dialog-body [hidden] { display: none; }
.pdft-dialog-body > div:not(.pdft-row):not(.pdft-seg) { display: flex; flex-direction: column; gap: 0.5rem; }
.pdft-dialog-actions { justify-content: flex-end; }
.pdft-pad {
  display: block;
  width: 100%;
  aspect-ratio: 1200 / 380;
  border: 1px dashed var(--color-base-300);
  border-radius: 0.5rem;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}
.pdft-saved {
  display: block;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--pdft-line);
  border-radius: 0.5rem;
  background: #fff;
  cursor: pointer;
}
.pdft-saved img { max-height: 3.5rem; margin-inline: auto; }
.pdft-saved:hover { border-color: var(--pdft-accent); }

/* ---- Page copy ---- */

.pdft-steps { counter-reset: step; display: flex; flex-direction: column; gap: 0.9rem; }
.pdft-steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  gap: 0.75rem;
  line-height: 1.55;
}
.pdft-steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-base-content);
  color: var(--color-base-100);
  font-weight: 700;
  font-size: 0.875rem;
}

.pdft-cards { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.pdft-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0.85rem;
  height: 100%;
  padding: 1rem 1.1rem;
  border: 1px solid var(--pdft-line, var(--color-base-300));
  border-radius: 0.875rem;
  background: var(--color-base-100);
  transition: border-color 0.12s, transform 0.12s;
}
.pdft-card > span:last-child { display: flex; flex-direction: column; gap: 0.15rem; }
.pdft-card-name { font-weight: 600; }
.pdft-card-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.625rem;
  color: var(--cat, var(--t-steel, currentColor));
  background: color-mix(in oklab, var(--cat, var(--t-steel, currentColor)) 13%, var(--color-base-100));
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--cat, var(--t-steel, currentColor)) 22%, transparent);
}
.pdft-card:hover { border-color: var(--color-base-content); transform: translateY(-1px); }
.pdft-card:hover .pdft-card-icon { background: color-mix(in oklab, var(--cat, var(--t-steel, currentColor)) 20%, var(--color-base-100)); }
.pdft-card-name {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.pdft-index {
  display: grid;
  gap: 2rem 2.5rem;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
}
.pdft-index a:hover { text-decoration: underline; text-underline-offset: 2px; }
