/* ==========================================================================
   PDF Tools workspace — assets/pdf-tools.css
   Scoped under #pdfWorkspace. Reuses site tokens from style.css/home.css.
   ========================================================================== */

#pdfWorkspace{
  scroll-margin-top: 88px;
  margin: 8px auto 48px;
  max-width: 980px;
}

.pw-panel{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 24px);
  box-shadow: var(--shadow-md);
  padding: 26px 24px 24px;
}

.pw-head{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.pw-head-text h3{
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 4px;
}
.pw-head-text p{
  margin: 0;
  font-size: .88rem;
  color: var(--ink-soft);
  max-width: 560px;
  line-height: 1.5;
}
.pw-close{
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-soft);
  width: 34px; height: 34px;
  border-radius: 10px;
  display: inline-grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s ease, border-color .15s ease, transform .15s ease;
}
.pw-close:hover{ color: var(--ink); border-color: var(--ink-faint); transform: rotate(90deg); }
.pw-close svg{ width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.2; }

/* ---- dropzone ---- */
.pw-dropzone{
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  background: var(--surface-2);
}
.pw-dropzone:hover, .pw-dropzone.pw-drag-over{
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-2));
}
.pw-dropzone svg{ width: 32px; height: 32px; stroke: var(--accent); fill: none; stroke-width: 1.7; margin-bottom: 10px; }
.pw-dropzone strong{ display: block; color: var(--ink); font-size: .95rem; margin-bottom: 4px; }
.pw-dropzone span{ font-size: .8rem; color: var(--ink-faint); }
.pw-dropzone input[type="file"]{ display: none; }

/* ---- toolbar ---- */
.pw-toolbar{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.pw-toolbar .pw-spacer{ flex: 1 1 auto; }
.pw-count{
  font-size: .82rem;
  color: var(--ink-faint);
  font-weight: 600;
}
.pw-status{
  font-size: .82rem;
  color: var(--accent-3);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
}
.pw-status.pw-status-error{ color: #d3453f; }

/* ---- busy/processing indicator — spinning ring shown next to the
   status text while an AI Summarizer / Translate PDF / AI OCR request
   is in flight, so a slow response reads as "working" instead of
   "frozen". Removed as soon as the request resolves or fails. ---- */
.pw-spinner{
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent-3) 30%, transparent);
  border-top-color: var(--accent-3);
  animation: pw-spin .8s linear infinite;
}
.pw-status-error .pw-spinner{ display: none; }
@keyframes pw-spin{
  to{ transform: rotate(360deg); }
}
.pw-status-elapsed{
  color: var(--ink-faint);
  font-weight: 500;
}

/* ---- thumbnail grid ---- */
.pw-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.pw-tile{
  position: relative;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 8px 8px 26px;
  cursor: grab;
  user-select: none;
  transition: border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.pw-tile:active{ cursor: grabbing; }
.pw-tile.pw-dragging{ opacity: .35; }
.pw-tile.pw-drag-target{ border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.pw-tile img{
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  transition: transform .15s ease;
  pointer-events: none;
}
.pw-tile-num{
  position: absolute;
  bottom: 6px; left: 0; right: 0;
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
  color: var(--ink-faint);
}
.pw-tile-badge{
  position: absolute;
  top: 4px; left: 4px;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 2px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  color: var(--accent);
}
.pw-tile-del{
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 7px;
  border: none;
  background: var(--surface);
  color: var(--ink-faint);
  display: inline-grid; place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.pw-tile-del:hover{ color: #d3453f; }
.pw-tile-del svg{ width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.4; }

/* selectable states */
.pw-tile.pw-selectable{ cursor: pointer; }
.pw-tile.pw-selectable .pw-tile-num{ pointer-events: none; }
.pw-tile.pw-included{ border-color: var(--accent-3); }
.pw-tile.pw-included::after{
  content: "✓";
  position: absolute; top: 4px; left: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-3);
  color: #fff;
  font-size: .68rem;
  font-weight: 800;
  display: inline-grid; place-items: center;
}
.pw-tile.pw-excluded{ opacity: .4; }
.pw-tile.pw-excluded::after{
  content: "✕";
  position: absolute; top: 4px; left: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #d3453f;
  color: #fff;
  font-size: .68rem;
  font-weight: 800;
  display: inline-grid; place-items: center;
}
.pw-tile.pw-rotate-selected{ border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

.pw-tile.pw-rot-90 img{ transform: rotate(90deg); }
.pw-tile.pw-rot-180 img{ transform: rotate(180deg); }
.pw-tile.pw-rot-270 img{ transform: rotate(270deg); }

.pw-empty{
  text-align: center;
  padding: 30px 10px;
  color: var(--ink-faint);
  font-size: .88rem;
}

/* ---- split tool ---- */
.pw-split-field{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.pw-split-field input[type="text"]{
  flex: 1 1 240px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: .88rem;
  font-family: var(--font-body);
}
.pw-split-field input[type="text"]:focus{ outline: 2px solid var(--accent-2); outline-offset: 1px; }
.pw-hint{ font-size: .78rem; color: var(--ink-faint); margin: -8px 0 16px; }
.pw-pdf-warn{ color: #d3453f; margin: 4px 0 16px; }
.pw-btn-row{ display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

/* ---- generic option row (page size / format / quality / language selects) ---- */
.pw-field-row{
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  margin: 16px 0 4px;
}
.pw-field-row label{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.pw-field-row select{
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: .85rem;
  font-family: var(--font-body);
}
.pw-field-row select:focus{ outline: 2px solid var(--accent-2); outline-offset: 1px; }
.pw-field-row input[type="text"],
.pw-field-row input[type="password"],
.pw-field-row input[type="number"]{
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: .85rem;
  font-family: var(--font-body);
}
.pw-field-row input[type="text"]:focus,
.pw-field-row input[type="password"]:focus,
.pw-field-row input[type="number"]:focus{ outline: 2px solid var(--accent-2); outline-offset: 1px; }
.pw-field-row input[type="range"]{ width: 120px; accent-color: var(--accent); }
.pw-field-row input[type="color"]{
  width: 34px; height: 30px; padding: 2px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer;
}

/* ---- sign pad ---- */
.pw-sign-panel{ margin: 14px 0 4px; }
.pw-sign-panel-label{ font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.pw-sign-pad-wrap{
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fff;
  display: inline-block;
  max-width: 100%;
}
.pw-sign-pad{
  display: block;
  width: 100%;
  max-width: 520px;
  height: auto;
  aspect-ratio: 520 / 170;
  touch-action: none;
  cursor: crosshair;
  border-radius: 12px;
}
.pw-sign-actions{ display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.pw-sign-upload{ cursor: pointer; }

/* ---- progress bar (Word conversion / OCR) ---- */
.pw-progress{
  height: 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 4px 0 14px;
}
.pw-progress-bar{
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .25s ease;
}

/* ---- crop / edit preview (shared) ---- */
.pw-crop-wrap{
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 14px;
  background: #fff;
}
.pw-crop-img{ display: block; max-width: 100%; height: auto; }
.pw-crop-box{
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(255, 90, 90, .12);
  pointer-events: none;
}

/* ---- edit pdf: click-to-place text notes ---- */
.pw-edit-layer{ position: absolute; inset: 0; cursor: crosshair; }
.pw-edit-note{
  position: absolute;
  transform: translate(-2px, -50%);
  background: rgba(255,255,255,.85);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  border: 1px dashed rgba(0,0,0,.25);
}

/* ---- redact pdf ---- */
.pw-redact-canvas{
  display: block;
  width: 100%;
  max-width: 700px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}

/* ---- pdf forms ---- */
.pw-forms-list{ display: flex; flex-direction: column; gap: 10px; margin: 6px 0 14px; }
.pw-forms-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.pw-forms-row label{ font-size: .85rem; color: var(--ink-soft); flex-shrink: 0; }
.pw-forms-row input[type="text"],
.pw-forms-row select{
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}
.pw-forms-flatten{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

/* ---- compare pdf ---- */
.pw-compare-row{ display: flex; gap: 14px; flex-wrap: wrap; }
.pw-compare-row .pw-dropzone{ flex: 1; min-width: 220px; }
.pw-compare-output{ display: flex; flex-direction: column; gap: 16px; margin-top: 10px; }
.pw-compare-page h4{ margin: 0 0 6px; font-size: .95rem; color: var(--ink); }
.pw-compare-lines{
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.pw-diff-add{ background: rgba(52, 168, 83, .14); color: #1e7a34; padding: 3px 10px; }
.pw-diff-remove{ background: rgba(217, 48, 37, .12); color: #b3261e; padding: 3px 10px; }

/* ---- pdf to markdown ---- */
.pw-md-output{
  width: 100%;
  min-height: 260px;
  margin-top: 10px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
  line-height: 1.55;
  resize: vertical;
}

/* ---- scan to pdf (camera) ---- */
.pw-cam-wrap{
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0d0d0d;
  max-width: 480px;
  aspect-ratio: 4 / 3;
  display: none;
  align-items: center;
  justify-content: center;
}
.pw-cam-wrap.pw-cam-active{ display: flex; }
.pw-cam-video{ width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 560px){
  .pw-grid{ grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
  .pw-panel{ padding: 20px 16px 18px; }
  .pw-compare-row{ flex-direction: column; }
}
