/* Tool pages: the workbench where files are chosen and results appear. */

.workbench {
  width: min(860px, calc(100% - 32px)); margin: 0 auto 40px; padding: 20px; min-height: 260px;
  display: flex; flex-direction: column; gap: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-s);
}
.workbench .drop { width: 100%; margin-top: 0; box-shadow: none; background: var(--paper); }
.workbench .drop.compact { flex-direction: row; justify-content: center; gap: 14px; padding: 14px; }
.workbench .drop.compact strong { font-size: 15px; }
.workbench .drop.compact .as-button { margin-top: 0; height: 36px; }
.noscript { margin: 0; color: var(--ink-soft); text-align: center; }

.msg { margin: 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.msg.error { background: #fdecea; color: #8c1d12; }
.msg.info { background: var(--paper); color: var(--ink-soft); }
.hint { margin: 0; color: var(--ink-soft); font-size: 14px; }
.summary { margin: 0; min-height: 1.4em; color: var(--ink-soft); }
.notes { display: flex; flex-direction: column; gap: 8px; }
.notes:empty { display: none; }

.busy-card { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 56px 12px; color: var(--ink-soft); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }


.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.file { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; cursor: grab; box-shadow: 0 1px 2px rgba(27, 23, 19, .04); }
.file:hover { border-color: rgba(27, 23, 19, .35); }
.file-n { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--yellow); font-size: 12px; font-weight: 700; }
.file-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-main.with-thumb { flex-direction: row; align-items: center; gap: 12px; }
.fc-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 13px; color: var(--ink-soft); }
.file-thumb { flex: none; width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.file-actions { flex: none; display: flex; gap: 2px; }

.actions-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.actions-row.sticky { position: sticky; bottom: 12px; z-index: 5; padding: 12px; background: color-mix(in srgb, var(--card) 94%, transparent); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-m); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
a.primary { text-decoration: none; }
.primary.big { height: 48px; padding: 0 28px; font-size: 16px; }

.options { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.field.inline { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 100%; font-size: 14px; }
.field.inline select { max-width: 100%; min-width: 0; }
.field.inline > span { font-weight: 500; }
.workbench select { height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--card); }
.range-input { width: 220px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 15px; }
.range-input.bad { border-color: var(--danger); }
.range-input:disabled { opacity: .5; }
.num { width: 84px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--ink); background: #fffbe9; }
.choice-body { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px 12px; padding: 16px; background: var(--canvas); border-radius: 14px; }
.cell { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 8px 8px; background: transparent; border: 2px solid transparent; border-radius: 14px; font: inherit; color: inherit; cursor: pointer; transition: background-color .12s; }
.cell:hover { background: rgba(255, 255, 255, .55); }
div.cell { cursor: default; }
.thumb { width: 100%; aspect-ratio: 3 / 4; display: grid; place-items: center; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px rgba(27, 23, 19, .08), 0 2px 4px rgba(27, 23, 19, .08), 0 8px 18px rgba(27, 23, 19, .1); }
.thumb canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; transition: transform .25s; }
.thumb.failed { background: repeating-linear-gradient(45deg, #fff, #fff 6px, #f3f1ec 6px, #f3f1ec 12px); }
.thumb-label { font-size: 12px; font-weight: 500; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.turn { display: flex; gap: 4px; }
.cell.selected { border-color: var(--ink); background: var(--card); }
.cell.selected::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; }
.workbench[data-tool="delete-pages"] .cell.selected { border-color: var(--danger); background: #fff3f1; }
.workbench[data-tool="delete-pages"] .cell.selected::after { content: "✕"; background: var(--danger); }
.workbench[data-tool="delete-pages"] .cell.selected .thumb { opacity: .55; }

.result { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px 8px; text-align: center; }
.result-title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.result-note { margin: 0; color: var(--ink-soft); max-width: 46ch; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.result-next { margin: 8px 0 0; font-size: 14px; color: var(--ink-soft); }
.chip { display: inline-block; margin: 2px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); text-decoration: none; }
.chip:hover { border-color: var(--ink); }

.meta-table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.meta-table caption { padding: 6px 0; font-weight: 700; text-align: left; }
.meta-table th, .meta-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; overflow-wrap: anywhere; }
.meta-table th { width: 36%; font-weight: 500; color: var(--ink-soft); }
.meta-table td.none { color: #a39d93; }

@media (max-width: 640px) {
  .workbench { width: calc(100% - 20px); padding: 14px; border-radius: 16px; }
  .range-input { width: 100%; }
}

/* Redact: pages with boxes drawn on top. */
.rpages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 16px; background: var(--canvas); border-radius: 14px; max-height: 70vh; overflow: auto; }
.rwrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rpage { position: relative; background: #fff; box-shadow: var(--shadow-s); flex: none; }
.rpage img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.rlayer { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.rbox { position: absolute; background: rgba(27, 23, 19, .85); outline: 2px solid var(--ink); }
.rbox.found { background: rgba(229, 56, 79, .35); outline-color: var(--danger); }
.rbox.ghost { background: rgba(27, 23, 19, .35); pointer-events: none; }
.rbox-x { position: absolute; top: -10px; right: -10px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; line-height: 20px; cursor: pointer; display: none; }
.rbox:hover .rbox-x, .rbox-x:focus-visible { display: block; }
.checks-box { padding: 12px 16px; background: var(--paper); border-radius: 12px; text-align: left; font-size: 14px; }
.checks-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- PDFs shown as cards ---------- */
.fc { display: flex; align-items: center; gap: 14px; min-width: 0; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.fc-thumb { position: relative; flex: none; display: grid; place-items: center; width: 56px; aspect-ratio: 3 / 4; overflow: hidden; background: #fff; border-radius: 4px; box-shadow: 0 0 0 1px rgba(27, 23, 19, .1), 0 2px 6px rgba(27, 23, 19, .12); }
.fc-thumb.small { width: 44px; }
.fc-thumb.big { width: 84px; }
.fc-thumb canvas, .fc-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.fc-thumb.zip { background: #fffbe9; }
.fc-ext { font-size: 10px; font-weight: 700; letter-spacing: .08em; color: var(--ink-soft); }
.fc-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.fc-meta { font-size: 13px; color: var(--ink-soft); }
.file-name { font-weight: 600; }

/* ---------- result ---------- */
.result { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 8px 22px; text-align: center; }
.result-check { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: #e3f6ec; color: #17a05a; }
.result-check svg { width: 28px; height: 28px; }
.result-title { margin: 6px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
.result-file { display: flex; align-items: center; gap: 16px; width: min(580px, 100%); margin-top: 12px; padding: 14px 16px; text-align: left; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; }
.result-file .primary { flex: none; }
.primary.big svg { width: 20px; height: 20px; flex: none; }
.result-actions { margin-top: 4px; }
@media (max-width: 640px) { .result-file { flex-wrap: wrap; } .result-file .primary { width: 100%; } }


/* ---------- preview beside the options ---------- */
.split { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; }
.preview { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 0; }
.preview .hint { text-align: center; max-width: 340px; }
.options.col { flex-direction: column; align-items: stretch; gap: 14px; }
.field.inline .unit-mm { color: var(--ink-soft); font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }
.slider { width: 180px; accent-color: var(--ink); }
.range-out { min-width: 52px; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.colorbox { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; }
.choice-body.stack { flex-direction: column; align-items: flex-start; gap: 2px; }
.choice-body.stack .hint { font-size: 13px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } .slider { width: 140px; } }

/* A page with things drawn on top of it. */
.stage { position: relative; overflow: hidden; flex: none; background: #fff; box-shadow: 0 0 0 1px rgba(27, 23, 19, .1), 0 4px 16px rgba(27, 23, 19, .14); user-select: none; }
.pn-mark { position: absolute; color: #1b1713; font-family: Helvetica, Arial, sans-serif; white-space: nowrap; line-height: 1; padding: 2px 4px; background: rgba(246, 201, 69, .45); border-radius: 3px; }
.wm-mark { position: absolute; left: 50%; top: 50%; white-space: nowrap; font: 700 16px Helvetica, Arial, sans-serif; line-height: 1; transform-origin: center; pointer-events: none; }

/* Crop frame with draggable edges. */
.crop-shade { position: absolute; background: rgba(27, 23, 19, .45); pointer-events: none; }
.crop-frame { position: absolute; outline: 2px solid var(--yellow); }
.crop-handle { position: absolute; background: var(--yellow); box-shadow: 0 0 0 1px rgba(27, 23, 19, .5); touch-action: none; }
.crop-handle.top, .crop-handle.bottom { left: 50%; width: 52px; height: 10px; margin-left: -26px; cursor: ns-resize; border-radius: 5px; }
.crop-handle.left, .crop-handle.right { top: 50%; height: 52px; width: 10px; margin-top: -26px; cursor: ew-resize; border-radius: 5px; }
.crop-handle.top { top: 0; } .crop-handle.bottom { bottom: 0; } .crop-handle.left { left: 0; } .crop-handle.right { right: 0; }

/* Signature pad and placement. */
.sig-area { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.sig-pad { display: block; background: #fff; border: 1px dashed var(--ink-soft); border-radius: 12px; touch-action: none; cursor: crosshair; }
.tool[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.sig-img { position: absolute; cursor: grab; touch-action: none; outline: 1.5px dashed rgba(31, 63, 184, .7); outline-offset: 3px; }
.sig-img:active { cursor: grabbing; }
.pager.inline { display: inline-flex; align-items: center; gap: 4px; }

/* Organize: pages you can drag. */
.grid.organize { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); }
.grid.organize .cell { cursor: grab; }
.grid.organize .cell.dragging { opacity: .4; }
.grid.organize .cell.gone { opacity: .45; }
.grid.organize .cell.gone .thumb { outline: 3px solid var(--danger); outline-offset: -3px; }
.grid.organize .turn { justify-content: center; gap: 0; }
.grid.organize .turn .icon { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }

/* Compare. */
.cmp-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cmp-slot { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cmp-title { margin: 0; font-weight: 700; }
.cmp-slot .drop.compact { flex-direction: column; padding: 18px; gap: 8px; }
.cmp-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.cmp-summary strong { font-size: 18px; }
.del-count { color: #b4232f; font-weight: 600; } .add-count { color: #17803f; font-weight: 600; }
.diff { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; max-height: 60vh; overflow-y: auto; font-size: 14px; }
.diff-row { display: grid; grid-template-columns: 24px 36px 1fr; gap: 6px; padding: 5px 10px; border-bottom: 1px solid rgba(27, 23, 19, .06); }
.diff-row.del { background: #fdecea; } .diff-row.add { background: #e6f6ec; } .diff-row.same { color: var(--ink-soft); }
.diff-mark { font-weight: 700; text-align: center; } .diff-page { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.diff-text { overflow-wrap: anywhere; }
@media (max-width: 640px) { .cmp-slots { grid-template-columns: 1fr; } }

.text-preview { width: min(580px, 100%); max-height: 180px; overflow: auto; margin: 6px 0 0; padding: 12px 14px; text-align: left; white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }

/* ---- Wave 3: OCR, form filling, scanning */
.busy-card.stack { flex-direction: column; text-align: center; }
.ocr-bar { width: min(320px, 100%); height: 8px; accent-color: var(--ink); }
.ff-pages { display: flex; flex-direction: column; gap: 18px; align-items: center; margin: 12px 0; }
.ff-page { margin: 0; text-align: center; }
.ff-page .stage { box-shadow: 0 1px 3px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.08); background: #fff; }
.ff-input { position: absolute; box-sizing: border-box; margin: 0; padding: 0 3px; font: inherit; color: #111; background: #fff3c4; border: 1px solid rgba(160, 120, 0, .55); border-radius: 2px; }
.ff-input:focus { outline: 2px solid var(--ink); outline-offset: 0; background: #fffbe6; }
textarea.ff-input { padding: 3px; resize: none; line-height: 1.25; }
.ff-tick { padding: 0; accent-color: var(--ink); background: #fff3c4; cursor: pointer; }
.intake { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.intake .camera { text-align: center; cursor: pointer; }
.scan-thumb { display: block; width: 56px; height: auto; max-height: 76px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
.scan-turn { display: inline-flex; gap: 4px; margin-top: 4px; }

/* ---- Wave 4: pages per sheet */
.nup-sketch { display: grid; gap: 4px; width: min(100%, 240px); max-height: 320px; margin: 0 auto 8px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.nup-sketch span { display: grid; place-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 3px; font-size: 12px; color: var(--ink-soft); }

/* ---- Wave 5: header and footer, text to PDF, annotate */
.hf-mark { position: absolute; white-space: nowrap; line-height: 1; font-family: Helvetica, Arial, sans-serif; pointer-events: none; }
.hf-row { display: grid; grid-template-columns: 5.5rem repeat(3, minmax(0, 1fr)); gap: 6px; align-items: center; }
.hf-cols { display: grid; grid-template-columns: 5.5rem repeat(3, minmax(0, 1fr)); gap: 6px; font-size: 12px; color: var(--ink-soft); }
.hf-label { font-size: 13px; font-weight: 500; }
.hf-row .range-input { width: 100%; min-width: 0; }
@media (max-width: 640px) { .hf-row, .hf-cols { grid-template-columns: 1fr; } .hf-cols { display: none; } }
.ttp-area { width: 100%; box-sizing: border-box; min-height: 260px; padding: 12px; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 12px; resize: vertical; }
.props .range-input.wide { width: min(440px, 100%); }
.as-label { cursor: pointer; display: inline-flex; align-items: center; }
.apages { display: flex; flex-direction: column; gap: 18px; align-items: center; margin: 12px 0; }
.apage { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.08); max-width: 100%; }
.a-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.apages[data-tool="hl"] .a-svg, .apages[data-tool="pen"] .a-svg { touch-action: none; cursor: crosshair; }
.apages[data-tool="text"] .a-svg { cursor: text; }
.apages[data-tool="erase"] .a-svg { cursor: not-allowed; }
.apages[data-tool="erase"] .a-hl, .apages[data-tool="erase"] .a-pen { cursor: pointer; }
.a-hl { mix-blend-mode: multiply; }
.a-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.a-note, .a-edit { position: absolute; margin: 0; padding: 0; font-family: Helvetica, Arial, sans-serif; line-height: 1.25; white-space: pre; }
.apages[data-tool="erase"] .a-note { pointer-events: auto; cursor: pointer; }
.a-edit { pointer-events: auto; min-width: 8em; background: rgba(255, 251, 230, .9); border: 1px dashed var(--ink-soft); outline: none; resize: none; overflow: hidden; }
.swatches { display: inline-flex; gap: 6px; align-items: center; }
.swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }
.sticky-tools { position: sticky; top: 64px; z-index: 5; background: var(--bg, #faf9f6); padding: 8px 0; flex-wrap: wrap; }

/* ---- Wave 6: auto-crop */
.ac-box { position: absolute; box-sizing: border-box; border: 2px dashed #b88700; box-shadow: 0 0 0 999px rgba(20, 20, 20, .38); pointer-events: none; }
.ac-box[hidden] { display: none; }

/* colour pickers: a clear, finger-sized swatch instead of the browser's narrow bar */
input[type="color"].colorbox { width: 48px; height: 34px; padding: 3px; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
input[type="color"].colorbox::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].colorbox::-webkit-color-swatch { border: 0; border-radius: 5px; }
input[type="color"].colorbox::-moz-color-swatch { border: 0; border-radius: 5px; }
input[type="color"].colorbox:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
