/* ==========================================================================
   Edit PDF tool — editor styles (pe- = "PDF editor")
   Fonts for added/edited text are registered from JS (FontFace) using the
   local files in /Tools/edit_pdf/fonts/, so the preview matches the PDF.
   ========================================================================== */

#edit-pdf .pe-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid rgba(21, 128, 61, 0.15);
    border-top-color: #15803d;
    animation: pe-spin 0.8s linear infinite;
}
@keyframes pe-spin { to { transform: rotate(360deg); } }
/* Download button while the PDF is being prepared, and the toast after saving */
#edit-pdf #pe-download-btn.is-saving { cursor: progress; opacity: 1; }
#edit-pdf #pe-download-btn.is-saving .material-symbols-outlined { animation: pe-spin 1s linear infinite; }
#edit-pdf .pe-toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 90; transform: translateX(-50%);
    display: flex; align-items: center; gap: 10px; max-width: min(92vw, 480px);
    padding: 12px 18px; border-radius: 12px; background: #0b1c30; color: #fff;
    font-size: 15px; font-weight: 600; line-height: 1.35; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
}
#edit-pdf .pe-toast.hidden { display: none; }
#edit-pdf .pe-toast .material-symbols-outlined { color: #4ade80; font-size: 22px; flex-shrink: 0; }
#edit-pdf .pe-toast.is-error { background: #7f1d1d; }
#edit-pdf .pe-toast.is-error .material-symbols-outlined { color: #fecaca; }
#edit-pdf .pe-toast:not(.hidden) { animation: pe-toast-in .2s ease-out; }
@keyframes pe-toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) { #edit-pdf .pe-toast:not(.hidden), #edit-pdf #pe-download-btn.is-saving .material-symbols-outlined { animation: none; } }

/* ---------- How it works ---------- */
#edit-pdf .pe-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #15803d;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 4px;
}

/* ---------- File line ---------- */
#edit-pdf .pe-fileline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 2px 4px 8px;
    font-size: 13px;
    color: #434655;
    min-width: 0;
}
#edit-pdf .pe-fileline > .material-symbols-outlined { font-size: 18px; color: #b91c1c; }
#edit-pdf .pe-filename { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
#edit-pdf .pe-status { margin-left: auto; font-weight: 600; color: #15803d; }
#edit-pdf .pe-status.is-error { color: #b91c1c; }

/* ---------- Sticky toolbar ---------- */
#edit-pdf .pe-sticky {
    position: sticky;
    top: var(--pe-sticky-top, 0px);
    z-index: 40;
    margin: 0 -4px 8px;
    padding: 4px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}
#edit-pdf .pe-toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
}
#edit-pdf .pe-tool {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 64px;
    height: 56px;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: #0b1c30;
    cursor: pointer;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .15s, color .15s, border-color .15s;
}
#edit-pdf .pe-tool .material-symbols-outlined { font-size: 22px; }
#edit-pdf .pe-tool-label { font-size: 11px; font-weight: 600; white-space: nowrap; max-width: none; color: inherit; }
@media (hover: hover) {
    #edit-pdf .pe-tool:hover:not(:disabled):not(.is-active):not(.pe-tool--primary) { background: rgba(21, 128, 61, 0.08); color: #15803d; }
}
#edit-pdf .pe-tool:active:not(:disabled) { transform: scale(0.96); }
#edit-pdf .pe-tool:disabled { opacity: .4; cursor: not-allowed; }
#edit-pdf .pe-tool.is-active { background: #15803d; color: #fff; border-color: #15803d; }
#edit-pdf .pe-tool--primary { background: linear-gradient(135deg, #15803d 0%, #22c55e 100%); color: #fff; }
#edit-pdf .pe-tool--primary:hover:not(:disabled) { color: #fff; filter: brightness(1.05); background: linear-gradient(135deg, #15803d 0%, #22c55e 100%); }
#edit-pdf .pe-sep { flex: 0 0 1px; align-self: center; height: 36px; margin: 0 4px; background: rgba(195, 198, 215, 0.8); }
#edit-pdf .pe-tgroup { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0 4px; color: #434655; }
#edit-pdf .pe-tgroup-row { display: flex; align-items: center; gap: 2px; }

/* ---- Toolbar in 3 groups: LEFT editing tools | CENTRE view | RIGHT Start Over + Download ---- */
#edit-pdf .pe-sticky { container-type: inline-size; container-name: petb; }
#edit-pdf .pe-toolbar { justify-content: space-between; gap: 6px; }
#edit-pdf .pe-tb-group { flex: 0 0 auto; display: flex; align-items: stretch; gap: 2px; }
#edit-pdf .pe-tb-centre { gap: 10px; }
#edit-pdf .pe-sep--group { margin: 0; }
/* Same box for every item: 56px tall, a 32px icon/control row, then the
   label — so "Zoom" and "Page" sit on the same baseline as the tool labels. */
#edit-pdf .pe-tool,
#edit-pdf .pe-tgroup { height: 56px; padding: 4px 6px; border: 1px solid transparent; gap: 2px; justify-content: center; }
#edit-pdf .pe-tool .material-symbols-outlined { height: 32px; display: flex; align-items: center; justify-content: center; line-height: 1; }
#edit-pdf .pe-tgroup-row { height: 32px; }
#edit-pdf .pe-tool-label { display: block; line-height: 1; height: 11px; }
/* Download: last and most prominent */
#edit-pdf #pe-download-btn { min-width: 88px; box-shadow: 0 4px 12px rgba(21, 128, 61, 0.3); }
#edit-pdf #pe-download-btn .pe-tool-label { font-weight: 700; }

/* Tablet / desktop: when space gets tight the centre group shrinks first
   (its labels hide, controls tighten), then the tools tighten. On narrow
   tablets the view controls move to their own row so every group stays whole. */
@media (min-width: 769px) {
    @container petb (max-width: 1120px) {
        #edit-pdf .pe-tb-centre { gap: 4px; }
        #edit-pdf .pe-tb-centre .pe-tgroup { padding: 4px 2px; }
        #edit-pdf .pe-tb-centre .pe-tgroup > .pe-tool-label { display: none; }
        #edit-pdf .pe-tb-centre .pe-zoom-label { min-width: 42px; }
        #edit-pdf .pe-tb-centre .pe-page-input { width: 36px; }
    }
    @container petb (max-width: 1020px) {
        #edit-pdf .pe-toolbar { gap: 4px; }
        #edit-pdf .pe-tool { min-width: 56px; padding: 4px 3px; }
        #edit-pdf .pe-tool-label { font-size: 10.5px; }
        #edit-pdf #pe-download-btn { min-width: 76px; }
    }
    @container petb (max-width: 920px) {
        #edit-pdf .pe-toolbar { flex-wrap: wrap; row-gap: 4px; }
        #edit-pdf .pe-sep--group { display: none; }
        #edit-pdf .pe-tb-centre {
            order: 3; flex: 1 0 100%; justify-content: center; gap: 16px;
            padding-top: 4px; border-top: 1px solid rgba(195, 198, 215, 0.6);
        }
        #edit-pdf .pe-tb-centre .pe-tgroup { height: 40px; }
    }
}

/* Phones: keep the horizontal scrolling toolbar; Download stays visible at the right edge. */
@media (max-width: 768px) {
    #edit-pdf .pe-toolbar { justify-content: flex-start; }
    #edit-pdf .pe-tb-right { display: contents; }
    #edit-pdf #pe-download-btn {
        position: sticky; right: 0; z-index: 2; margin-left: 4px;
        box-shadow: -12px 0 10px -2px rgba(255, 255, 255, 0.95), 0 4px 12px rgba(21, 128, 61, 0.3);
    }
}

/* Small buttons (zoom, page, options, dialog) */
#edit-pdf .pe-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid rgba(195, 198, 215, 0.7);
    background: #fff;
    color: #0b1c30;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
#edit-pdf .pe-mini .material-symbols-outlined { font-size: 20px; }
#edit-pdf .pe-mini:hover:not(:disabled) { border-color: #15803d; color: #15803d; }
#edit-pdf .pe-mini:disabled { opacity: .4; cursor: not-allowed; }
#edit-pdf .pe-mini[aria-pressed="true"] { background: #15803d; border-color: #15803d; color: #fff; }
#edit-pdf .pe-mini--text { padding: 0 12px; }
#edit-pdf .pe-mini--primary { background: #15803d; border-color: #15803d; color: #fff; }
#edit-pdf .pe-mini--primary:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }
#edit-pdf .pe-mini--danger { color: #b91c1c; padding: 0 10px; }
#edit-pdf .pe-mini--danger:hover:not(:disabled) { border-color: #b91c1c; color: #b91c1c; background: #fef2f2; }
#edit-pdf .pe-zoom-label { min-width: 50px; padding: 0 4px; font-variant-numeric: tabular-nums; }
#edit-pdf .pe-page-label { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; color: #434655; }
#edit-pdf .pe-page-input {
    width: 44px;
    height: 32px;
    padding: 0 4px;
    border-radius: 8px;
    border: 1px solid rgba(195, 198, 215, 0.9);
    text-align: center;
    font-size: 13px;
    -moz-appearance: textfield;
}
#edit-pdf .pe-page-input::-webkit-outer-spin-button,
#edit-pdf .pe-page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#edit-pdf .pe-color { display: inline-flex; width: 32px; height: 32px; border-radius: 8px; overflow: hidden; border: 1px solid rgba(195, 198, 215, 0.9); cursor: pointer; flex-shrink: 0; }
#edit-pdf .pe-color input { width: 150%; height: 150%; margin: -25%; border: 0; padding: 0; cursor: pointer; }

/* ---------- Hint / options bar (fixed height: no layout jump under the finger) ---------- */
#edit-pdf .pe-hintbar {
    display: flex;
    align-items: center;
    height: 44px;
    margin-top: 4px;
    padding: 0 8px;
    border-radius: 10px;
    background: rgba(21, 128, 61, 0.07);
    border: 1px solid rgba(21, 128, 61, 0.18);
    overflow: hidden;
}
#edit-pdf .pe-hint { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; font-weight: 500; color: #14532d; }
#edit-pdf .pe-hint .material-symbols-outlined { font-size: 20px; color: #15803d; flex-shrink: 0; }
#edit-pdf #pe-hint-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#edit-pdf .pe-opts { display: flex; align-items: center; gap: 8px; width: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#edit-pdf .pe-opts::-webkit-scrollbar { display: none; }
#edit-pdf .pe-opt-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
#edit-pdf .pe-opt-label { font-size: 12px; font-weight: 600; color: #434655; white-space: nowrap; flex-shrink: 0; }
#edit-pdf #pe-delete-btn { margin-left: auto; flex-shrink: 0; }
@media (max-width: 640px) {
    #edit-pdf #pe-hint-text { white-space: normal; font-size: 12px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
    #edit-pdf #pe-delete-label, #edit-pdf #pe-opts-name { display: none; }
    #edit-pdf .pe-mini--danger { padding: 0; width: 32px; }
}

/* ---------- Find & Replace ---------- */
/* Part of the sticky block, so Next / Replace stay reachable while scrolling. */
#edit-pdf .pe-find {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    padding: 8px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid rgba(195, 198, 215, 0.6);
}
#edit-pdf .pe-find-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#edit-pdf .pe-field {
    flex: 1 1 200px;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid rgba(195, 198, 215, 0.9);
    background: #f8fafc;
    min-width: 0;
}
#edit-pdf .pe-field:focus-within { border-color: #15803d; background: #fff; box-shadow: 0 0 0 3px rgba(21, 128, 61, 0.12); }
#edit-pdf .pe-field .material-symbols-outlined { font-size: 18px; color: #737686; }
#edit-pdf .pe-field input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 14px; padding: 0; box-shadow: none; }
#edit-pdf .pe-find-count { font-size: 12px; font-weight: 600; color: #434655; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
#edit-pdf .pe-find-opts { gap: 16px; font-size: 13px; color: #434655; }
#edit-pdf .pe-find-opts label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
#edit-pdf .pe-find-opts input { accent-color: #15803d; width: 16px; height: 16px; }
@media (max-width: 640px) {
    #edit-pdf .pe-find-row:first-child { flex-wrap: nowrap; }
    #edit-pdf .pe-find-row:first-child .pe-field { flex: 1 1 auto; }
    #edit-pdf .pe-find-count { min-width: 52px; }
    #edit-pdf .pe-find-row:nth-child(2) .pe-field { flex: 1 1 100%; }
    #edit-pdf .pe-find-row:nth-child(2) .pe-mini { flex: 1 1 0; height: 36px; }
}

/* ---------- Hero: collapses smoothly while a PDF is open (h1 stays in the HTML) ---------- */
#edit-pdf .pe-hero { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .35s ease, opacity .25s ease; }
#edit-pdf .pe-hero-inner { overflow: hidden; min-height: 0; padding-bottom: 24px; }
#edit-pdf.pe-editing .pe-hero { grid-template-rows: 0fr; opacity: 0; }
#edit-pdf.pe-editing .pe-hero-inner { padding-bottom: 0; transition: padding-bottom .35s ease; }
@media (prefers-reduced-motion: reduce) {
    #edit-pdf .pe-hero, #edit-pdf .pe-hero-inner { transition: none; }
}

/* ---------- Page area: all pages in one vertical scroll ---------- */
/* Only the window scrolls vertically (no nested scrollbar). The pages column
   scrolls sideways only when zoomed in past the width. */
#edit-pdf .pe-viewport {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 320px;
    background: #e2e8f0;
    border-radius: 12px;
    padding: 12px;
}
@media (max-width: 640px) {
    #edit-pdf .pe-viewport { padding: 6px; }
}
#edit-pdf .pe-pages {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
/* margin auto centres a page; when it is wider than the column it starts at the
   left edge, so every part stays reachable by scrolling sideways. */
#edit-pdf .pe-page {
    position: relative;
    flex: 0 0 auto;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.18);
    contain: layout; /* not "paint": handles may stick out of the page */
}
#edit-pdf .pe-page > canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
#edit-pdf .pe-page-num {
    position: absolute; right: 8px; bottom: 8px; z-index: 3;
    padding: 2px 8px; border-radius: 999px;
    background: rgba(15, 23, 42, 0.55); color: #fff;
    font-size: 11px; font-weight: 600; line-height: 1.5;
    pointer-events: none;
}
#edit-pdf .pe-layer { position: absolute; inset: 0; z-index: 2; }
#edit-pdf .pe-layer.tool-text { cursor: text; }
/* Erase: one finger draws; two fingers scroll / pinch (browser handles them). */
#edit-pdf .pe-layer.tool-erase { cursor: crosshair; touch-action: pinch-zoom; }
/* Brush mode paints over everything; select strokes with Edit text or Box mode. */
#edit-pdf .pe-layer.erase-brush .pe-obj,
#edit-pdf .pe-layer.erase-brush .pe-obj * { pointer-events: none !important; }
#edit-pdf .pe-layer.erase-brush { cursor: none; }
@media (pointer: coarse) { #edit-pdf .pe-layer.erase-brush { cursor: default; } }

/* ---------- Page thumbnails (desktop only) ---------- */
#edit-pdf .pe-thumbs { display: none; }
@media (min-width: 1024px) {
    #edit-pdf .pe-viewport.has-thumbs .pe-thumbs {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        flex: 0 0 132px;
        position: sticky;
        top: calc(var(--pe-sticky-top, 0px) + var(--pe-toolbar-h, 120px) + 8px);
        max-height: calc(100vh - var(--pe-sticky-top, 0px) - var(--pe-toolbar-h, 120px) - 24px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 16px 6px;
        scrollbar-width: thin;
    }
}
#edit-pdf .pe-thumb {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 4px; border: 2px solid transparent; border-radius: 8px;
    background: transparent; cursor: pointer; flex-shrink: 0;
    color: #434655; font-size: 12px; font-weight: 600;
}
#edit-pdf .pe-thumb:hover { border-color: rgba(21, 128, 61, 0.35); }
#edit-pdf .pe-thumb.is-current { border-color: #15803d; color: #15803d; background: rgba(21, 128, 61, 0.08); }
#edit-pdf .pe-thumb:focus-visible { outline: 3px solid #15803d; outline-offset: 1px; }
#edit-pdf .pe-thumb-box { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2); }
#edit-pdf .pe-thumb-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Erase options: Box | Brush ---------- */
#edit-pdf .pe-seg { display: inline-flex; padding: 2px; border-radius: 9px; background: #fff; border: 1px solid rgba(195, 198, 215, 0.8); flex-shrink: 0; }
#edit-pdf .pe-seg-btn {
    display: inline-flex; align-items: center; gap: 4px;
    height: 28px; padding: 0 10px; border: 0; border-radius: 7px;
    background: transparent; color: #434655; font-size: 13px; font-weight: 600; cursor: pointer;
}
#edit-pdf .pe-seg-btn .material-symbols-outlined { font-size: 18px; }
#edit-pdf .pe-seg-btn.is-active { background: #15803d; color: #fff; }
@media (pointer: coarse) { #edit-pdf .pe-seg-btn { height: 34px; } }
#edit-pdf .pe-brush-size { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
#edit-pdf .pe-brush-size input { width: 110px; accent-color: #15803d; }
#edit-pdf .pe-brush-size.is-off { display: none; }
#edit-pdf .pe-brush-dot { display: inline-block; flex-shrink: 0; width: 16px; height: 16px; border-radius: 50%; background: #0b1c30; opacity: .7; }
#edit-pdf #pe-erase-auto[aria-pressed="true"] { background: rgba(21, 128, 61, 0.12); border-color: #15803d; color: #15803d; }
#edit-pdf .pe-erase-hint { color: #5b6070; font-weight: 500; }
@media (max-width: 640px) {
    #edit-pdf .pe-erase-hint { display: none; }
    #edit-pdf .pe-brush-size input { width: 90px; }
    #edit-pdf #pe-erase-auto { padding: 0 8px; }
}
/* Brush strokes */
#edit-pdf .pe-obj--brush { pointer-events: none; cursor: pointer; }
#edit-pdf .pe-obj--brush svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#edit-pdf .pe-obj--brush path { pointer-events: stroke; }
#edit-pdf .pe-obj--brush .pe-handle { pointer-events: auto; }
#edit-pdf .pe-obj--brush.is-selected { outline: 2px dashed #15803d; }
#edit-pdf .pe-brush-draft { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 8; }
#edit-pdf .pe-busy {
    position: absolute;
    inset: 0;
    background: rgba(226, 232, 240, 0.75);
    color: #0b1c30;
    font-size: 14px;
    font-weight: 600;
    z-index: 30;
}
/* Stays in view on a tall page */
#edit-pdf .pe-busy-inner {
    position: sticky;
    top: calc(var(--pe-sticky-top, 0px) + 160px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px 0;
}

/* Page loading spinner / error message, shown on the page itself */
#edit-pdf .pe-page-status { position: absolute; left: 0; right: 0; top: 0; z-index: 12; display: flex; justify-content: center; pointer-events: none; }
#edit-pdf .pe-page-status:empty { display: none; }
#edit-pdf .pe-page-loading {
    margin-top: 24px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.15);
    font-size: 13px;
    font-weight: 600;
    color: #434655;
}
#edit-pdf .pe-page-loading .pe-spinner { width: 18px; height: 18px; border-width: 3px; }
#edit-pdf .pe-page-error {
    pointer-events: auto;
    margin: 32px 16px 0;
    max-width: 420px;
    padding: 16px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid #fecaca;
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.15);
    text-align: center;
    font-size: 14px;
    color: #7f1d1d;
}
#edit-pdf .pe-page-error .material-symbols-outlined { font-size: 32px; color: #dc2626; display: block; margin: 0 auto 6px; }
#edit-pdf .pe-page-error b { display: block; font-size: 15px; margin-bottom: 4px; color: #991b1b; }
#edit-pdf .pe-page-error p { color: #6b7280; font-size: 13px; margin: 0 0 12px; }
#edit-pdf .pe-page-error button {
    height: 36px;
    padding: 0 16px;
    border-radius: 10px;
    border: 0;
    background: #15803d;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

/* ---------- Existing text lines (tap to edit, Edit text tool only) ---------- */
#edit-pdf .pe-line {
    position: absolute;
    cursor: text;
    border-radius: 2px;
    outline: 1px dashed transparent;
    transition: background-color .12s, outline-color .12s;
}
#edit-pdf .pe-layer:not(.tool-edit) .pe-line { pointer-events: none; }
#edit-pdf .pe-layer.tool-edit.pe-show-lines .pe-line { outline-color: rgba(21, 128, 61, 0.25); }
@media (hover: hover) {
    #edit-pdf .pe-layer.tool-edit .pe-line:hover { background: rgba(21, 128, 61, 0.10); outline-color: rgba(21, 128, 61, 0.7); }
}

/* Find matches */
/* Plain translucent colour + outline: visible on light and dark pages. */
#edit-pdf .pe-hit { position: absolute; background: rgba(250, 204, 21, 0.4); outline: 1px solid rgba(202, 138, 4, 0.9); border-radius: 2px; pointer-events: none; }
#edit-pdf .pe-hit.is-current { background: rgba(249, 115, 22, 0.45); outline: 2px solid #f97316; }

/* Erase rectangle being drawn */
#edit-pdf .pe-erase-draft { position: absolute; border: 2px dashed #15803d; background: rgba(21, 128, 61, 0.08); pointer-events: none; }

/* ---------- Editable objects (text, edited line, image, erase) ---------- */
#edit-pdf .pe-obj {
    position: absolute;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: move;
}
#edit-pdf .pe-obj.pe-edit { cursor: text; }
#edit-pdf .pe-obj.is-selected { outline: 2px solid #15803d; outline-offset: 2px; z-index: 5; }
#edit-pdf .pe-obj:not(.is-selected):hover { outline: 1px dashed rgba(21, 128, 61, 0.7); outline-offset: 2px; }
#edit-pdf .pe-cover { position: absolute; background: #ffffff; pointer-events: none; }
#edit-pdf .pe-erase-fill { width: 100%; height: 100%; }
#edit-pdf .pe-text {
    position: relative;
    font-family: 'XF Noto Sans', 'XF Noto Deva', sans-serif;
    white-space: pre;
    max-width: none;
    font-kerning: normal;
    font-synthesis: none;
}
#edit-pdf .pe-text .pe-tl { display: block; overflow: visible; white-space: pre; max-width: none; }
#edit-pdf .pe-text .pe-tl:empty::before { content: "\200b"; }
#edit-pdf .pe-obj img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    pointer-events: none;
    -webkit-user-drag: none;
}
#edit-pdf textarea.pe-textarea {
    position: absolute;
    left: 0;
    top: 0;
    margin: 0;
    padding: 0;
    border: 0;
    outline: none;
    resize: none;
    overflow: hidden;
    white-space: pre;
    overflow-wrap: normal;
    background: rgba(255, 255, 255, 0.85);
    font-family: 'XF Noto Sans', 'XF Noto Deva', sans-serif;
    font-kerning: normal;
    font-synthesis: none;
    box-shadow: none;
    min-width: 1em;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    touch-action: auto;
}
#edit-pdf .pe-obj.pe-edit textarea.pe-textarea { background: transparent; }
#edit-pdf .pe-obj.is-editing .pe-text { visibility: hidden; }
#edit-pdf .pe-obj.is-editing { outline: 2px solid #2563eb; outline-offset: 2px; cursor: text; }

/* Handles (larger touch targets on coarse pointers) */
#edit-pdf .pe-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #15803d;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    touch-action: none;
    z-index: 6;
    padding: 0;
}
#edit-pdf .pe-obj.is-selected:not(.is-editing) .pe-handle { display: flex; }
#edit-pdf .pe-handle .material-symbols-outlined { font-size: 14px; pointer-events: none; }
#edit-pdf .pe-handle--resize { right: -14px; bottom: -14px; cursor: nwse-resize; }
#edit-pdf .pe-handle--delete { right: -14px; top: -14px; background: #dc2626; cursor: pointer; }
@media (pointer: coarse) {
    #edit-pdf .pe-handle { width: 30px; height: 30px; }
    #edit-pdf .pe-handle--resize { right: -18px; bottom: -18px; }
    #edit-pdf .pe-handle--delete { right: -18px; top: -18px; }
    #edit-pdf .pe-handle .material-symbols-outlined { font-size: 18px; }
}

/* ---------- Signature dialog ---------- */
#edit-pdf .pe-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(11, 28, 48, 0.55);
}
#edit-pdf .pe-modal-card {
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    background: #fff;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#edit-pdf .pe-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#edit-pdf .pe-modal-head h3 { font-family: 'Inter', sans-serif; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
#edit-pdf .pe-modal-foot { display: flex; justify-content: flex-end; gap: 8px; }
#edit-pdf .pe-modal-foot .pe-mini { height: 40px; }
#edit-pdf .pe-sig-last {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px dashed rgba(21, 128, 61, 0.5);
    background: rgba(21, 128, 61, 0.05);
    font-size: 13px;
    font-weight: 600;
    color: #15803d;
    cursor: pointer;
}
#edit-pdf .pe-sig-last img { height: 40px; max-width: 160px; object-fit: contain; display: block; }
#edit-pdf .pe-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: #f1f5f9; }
#edit-pdf .pe-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    border-radius: 9px;
    border: 0;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #434655;
    cursor: pointer;
}
#edit-pdf .pe-tab .material-symbols-outlined { font-size: 20px; }
#edit-pdf .pe-tab.is-active { background: #fff; color: #15803d; box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12); }
#edit-pdf .pe-pane { display: flex; flex-direction: column; gap: 10px; }
#edit-pdf .pe-pane[hidden] { display: none; }
#edit-pdf .pe-sig-pad {
    position: relative;
    height: 200px;
    border-radius: 12px;
    border: 1px solid rgba(195, 198, 215, 0.9);
    background: #fff;
    overflow: hidden;
}
#edit-pdf .pe-sig-pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 1; }
#edit-pdf .pe-sig-line { position: absolute; left: 24px; right: 24px; bottom: 48px; border-bottom: 1px solid #cbd5e1; pointer-events: none; }
#edit-pdf .pe-sig-ph { position: absolute; left: 0; right: 0; bottom: 20px; text-align: center; font-size: 13px; color: #94a3b8; pointer-events: none; }
#edit-pdf .pe-sig-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#edit-pdf .pe-swatches { display: flex; gap: 6px; }
#edit-pdf .pe-swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #cbd5e1; cursor: pointer; padding: 0; }
#edit-pdf .pe-swatch.is-active { box-shadow: 0 0 0 2px #15803d; }
#edit-pdf .pe-range { display: inline-flex; align-items: center; gap: 6px; flex: 1 1 120px; color: #434655; }
#edit-pdf .pe-range input { flex: 1; accent-color: #15803d; }
#edit-pdf .pe-sig-name {
    height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(195, 198, 215, 0.9);
    font-size: 16px;
}
#edit-pdf .pe-sig-fonts { display: flex; flex-direction: column; gap: 6px; }
#edit-pdf .pe-sig-font {
    display: flex;
    align-items: center;
    min-height: 64px;
    padding: 4px 14px;
    border-radius: 12px;
    border: 1px solid rgba(195, 198, 215, 0.9);
    background: #fff;
    font-size: 34px;
    line-height: 1.2;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    cursor: pointer;
}
#edit-pdf .pe-sig-font.is-active { border-color: #15803d; box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.25); }
#edit-pdf .pe-sig-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    border-radius: 12px;
    border: 1px dashed rgba(195, 198, 215, 1);
    background-color: #fff;
    background-image: linear-gradient(45deg, #f1f5f9 25%, transparent 25%), linear-gradient(-45deg, #f1f5f9 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f1f5f9 75%), linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
}
#edit-pdf .pe-sig-upload img { max-height: 120px; max-width: 100%; object-fit: contain; display: block; }
#edit-pdf .pe-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: #434655; cursor: pointer; }
#edit-pdf .pe-check input { accent-color: #15803d; width: 16px; height: 16px; }

/* ---------- Font picker (text options + Find & Replace) ---------- */
#edit-pdf .pe-font-btn { gap: 2px; padding: 0 4px 0 10px; max-width: 190px; }
#edit-pdf .pe-font-btn .material-symbols-outlined { font-size: 18px; flex-shrink: 0; }
#edit-pdf .pe-font-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 500; }
#edit-pdf .pe-font-btn.is-loading { opacity: .6; cursor: progress; }
#edit-pdf .pe-mini#pe-bold-btn:disabled { opacity: .35; }
#edit-pdf .pe-find-font { display: inline-flex; align-items: center; gap: 8px; }
#edit-pdf .pe-find-font .pe-font-btn { height: 32px; }
#edit-pdf .pe-font-menu {
    position: fixed;
    z-index: 80;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid rgba(195, 198, 215, 0.8);
    background: #fff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    outline: none;
}
#edit-pdf .pe-font-group {
    padding: 8px 10px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #6b7280;
}
#edit-pdf .pe-font-opt {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name check" "note check";
    align-items: center;
    column-gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #0b1c30;
    text-align: left;
    cursor: pointer;
    font-synthesis: none;
}
#edit-pdf .pe-font-opt:hover:not([aria-disabled]),
#edit-pdf .pe-font-opt:focus-visible { background: rgba(21, 128, 61, 0.08); outline: none; }
#edit-pdf .pe-font-opt[aria-selected="true"] { background: rgba(21, 128, 61, 0.12); color: #15803d; }
#edit-pdf .pe-font-opt[aria-disabled] { opacity: .4; cursor: not-allowed; }
#edit-pdf .pe-font-opt-name { grid-area: name; font-size: 17px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#edit-pdf .pe-font-opt-sample { grid-area: name; justify-self: end; margin-left: 12px; font-size: 16px; line-height: 1.3; color: #434655; }
#edit-pdf .pe-font-opt[aria-selected="true"] .pe-font-opt-sample { color: inherit; }
#edit-pdf .pe-font-opt-note { grid-area: note; font-size: 11.5px; line-height: 1.3; color: #6b7280; font-family: 'Inter', sans-serif; }
#edit-pdf .pe-font-opt-check { grid-area: check; font-size: 20px; color: #15803d; }
#edit-pdf .pe-font-foot { margin: 6px 10px 4px; font-size: 12px; line-height: 1.4; color: #6b7280; }

/* ---------- PDF Scanner app promo (start screen only) ---------- */
#pdf-scanner-promo { --psp-main: #06caad; --psp-deep: #0b7d6c; --psp-soft: #dff7f2; --psp-dark: #12253a; }
#pdf-scanner-promo.hidden { display: none; }
#pdf-scanner-promo .psp-card {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: center;
    padding: 28px 20px 24px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(6, 202, 173, 0.22) 0%, rgba(6, 202, 173, 0) 60%),
        radial-gradient(90% 80% at 0% 100%, rgba(11, 125, 108, 0.12) 0%, rgba(11, 125, 108, 0) 60%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.92) 0%, rgba(223, 247, 242, 0.85) 100%);
    box-shadow: 0 18px 48px rgba(11, 125, 108, 0.14), 0 2px 8px rgba(15, 23, 42, 0.05);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}
#pdf-scanner-promo .psp-text { min-width: 0; }
#pdf-scanner-promo .psp-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 999px;
    background: rgba(6, 202, 173, 0.14); color: var(--psp-deep);
    font-size: 13px; font-weight: 700; letter-spacing: .02em;
}
#pdf-scanner-promo .psp-badge .material-symbols-outlined { font-size: 18px; }
#pdf-scanner-promo .psp-title {
    margin: 12px 0 8px; color: var(--psp-dark);
    font-size: 26px; line-height: 1.2; font-weight: 800; letter-spacing: -0.02em;
}
#pdf-scanner-promo .psp-lead { margin: 0 0 16px; color: #434655; font-size: 16px; line-height: 1.6; max-width: none; }
#pdf-scanner-promo .psp-lead strong { color: var(--psp-dark); }
#pdf-scanner-promo .psp-ticks { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }
#pdf-scanner-promo .psp-ticks li { display: flex; align-items: flex-start; gap: 10px; color: #1f2937; font-size: 16px; line-height: 1.45; font-weight: 500; }
#pdf-scanner-promo .psp-ticks .material-symbols-outlined { color: var(--psp-deep); font-size: 22px; flex-shrink: 0; font-variation-settings: "FILL" 1; }
#pdf-scanner-promo .psp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
#pdf-scanner-promo .psp-play { display: inline-block; border-radius: 12px; line-height: 0; transition: transform .2s ease; }
#pdf-scanner-promo .psp-play img { width: auto; height: 60px; max-width: 100%; }
#pdf-scanner-promo .psp-play:hover { transform: translateY(-2px); }
#pdf-scanner-promo .psp-play:focus-visible, #pdf-scanner-promo .psp-more:focus-visible { outline: 3px solid var(--psp-main); outline-offset: 3px; }
#pdf-scanner-promo .psp-more {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
    color: var(--psp-deep); font-size: 16px; font-weight: 700; text-decoration: none;
}
#pdf-scanner-promo .psp-more:hover { text-decoration: underline; text-underline-offset: 3px; }
#pdf-scanner-promo .psp-more span { transition: transform .2s ease; }
#pdf-scanner-promo .psp-more:hover span { transform: translateX(3px); }

/* Phone mockup with the app screens (cross-fade) */
#pdf-scanner-promo .psp-phone-wrap { order: -1; display: flex; justify-content: center; }
#pdf-scanner-promo .psp-phone {
    position: relative;
    width: 168px;
    aspect-ratio: 608 / 1080;
    box-sizing: content-box;
    padding: 8px;
    border-radius: 30px;
    background: var(--psp-dark);
    box-shadow: 0 22px 44px rgba(18, 37, 58, 0.28), inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}
#pdf-scanner-promo .psp-shot {
    position: absolute; top: 8px; left: 8px;
    width: calc(100% - 16px); height: calc(100% - 16px);
    max-width: none; object-fit: cover; border-radius: 23px;
    background: var(--psp-soft);
    opacity: 0; transition: opacity .9s ease;
}
#pdf-scanner-promo .psp-shot.is-active { opacity: 1; }

/* Entrance animation (only when the script has armed it) */
#pdf-scanner-promo.psp-anim .psp-text,
#pdf-scanner-promo.psp-anim .psp-phone-wrap { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
#pdf-scanner-promo.psp-anim .psp-phone-wrap { transition-delay: .12s; }
#pdf-scanner-promo.psp-anim.is-in .psp-text,
#pdf-scanner-promo.psp-anim.is-in .psp-phone-wrap { opacity: 1; transform: none; }

@media (max-width: 380px) {
    #pdf-scanner-promo .psp-card { padding: 24px 16px 20px; }
    #pdf-scanner-promo .psp-phone { width: 150px; }
    #pdf-scanner-promo .psp-title { font-size: 24px; }
}
@media (max-width: 639px) {
    #pdf-scanner-promo .psp-actions { flex-direction: column; align-items: stretch; text-align: center; }
    #pdf-scanner-promo .psp-play { align-self: center; }
    #pdf-scanner-promo .psp-play img { height: 64px; }
    #pdf-scanner-promo .psp-more { justify-content: center; }
}
@media (min-width: 768px) {
    #pdf-scanner-promo .psp-card { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 32px; padding: 40px 48px; border-radius: 28px; }
    #pdf-scanner-promo .psp-phone-wrap { order: 0; }
    #pdf-scanner-promo .psp-phone { width: 200px; padding: 10px; border-radius: 36px; }
    #pdf-scanner-promo .psp-shot { top: 10px; left: 10px; width: calc(100% - 20px); height: calc(100% - 20px); border-radius: 27px; }
    #pdf-scanner-promo .psp-title { font-size: 32px; }
    #pdf-scanner-promo .psp-lead { font-size: 17px; }
}
@media (min-width: 1024px) {
    #pdf-scanner-promo .psp-card { padding: 48px 64px; }
    #pdf-scanner-promo .psp-phone { width: 230px; transform: rotate(-3deg); }
    #pdf-scanner-promo .psp-title { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) {
    #pdf-scanner-promo.psp-anim .psp-text,
    #pdf-scanner-promo.psp-anim .psp-phone-wrap { opacity: 1; transform: none; transition: none; }
    #pdf-scanner-promo .psp-shot, #pdf-scanner-promo .psp-play, #pdf-scanner-promo .psp-more span { transition: none; }
}

/* Cancel buttons for long jobs (Find, Replace all, building the PDF) */
#edit-pdf #pe-find-cancel.hidden, #edit-pdf #pe-busy-cancel.hidden { display: none; }
#edit-pdf #pe-busy-cancel { min-height: 40px; padding: 0 18px; }
#edit-pdf #pe-busy-text { text-align: center; padding: 0 16px; max-width: 520px; }
