/* =====================================================
   Create Fillable PDF Form (create-pdf-form) – tool styles
   ===================================================== */


.tool-wrapper.cpf-wrapper {
    --cpf-accent: #2563eb;
    --cpf-accent-d: #1d4ed8;
    --cpf-border: #d7dde5;
    --cpf-muted: #64748b;
    --cpf-bg: #f7f8fa;
    max-width: 1280px;
    margin: 0 auto;
    color: #1f2937;
}
.cpf-wrapper .hidden { display: none !important; }

/* ---- upload ---- */
.cpf-wrapper .upload-area {
    border: 2px dashed #cbd5e0;
    border-radius: 0.9rem;
    padding: 2.4rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: #fafbfc;
    transition: border-color 0.15s, background 0.15s;
    margin-bottom: 1rem;
}
.cpf-wrapper .upload-area:hover,
.cpf-wrapper .upload-area:focus-visible,
.cpf-wrapper .upload-area.dragover { border-color: var(--cpf-accent); background: #eff6ff; outline: none; }
.cpf-wrapper .upload-icon { font-size: 2.6rem; color: #94a3b8; margin-bottom: 0.6rem; }
.cpf-wrapper .upload-text { font-weight: 600; font-size: 1.1rem; margin-bottom: 0.3rem; }
.cpf-wrapper .upload-hint { color: var(--cpf-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.cpf-wrapper .upload-btn {
    background: var(--cpf-accent); color: #fff; border: none; padding: 0.65rem 1.5rem;
    border-radius: 2rem; font-weight: 600; cursor: pointer; display: inline-flex;
    align-items: center; gap: 0.45rem; font-size: 1rem;
}
.cpf-wrapper .upload-btn:hover { background: var(--cpf-accent-d); }
.cpf-privacy { margin: 1rem 0 0; color: var(--cpf-muted); font-size: 0.85rem; }
.cpf-loading { margin: 0.8rem 0 0; font-weight: 600; color: var(--cpf-accent-d); }
.cpf-msg {
    margin: 0 0 1rem; padding: 0.8rem 1rem; border-radius: 0.6rem;
    background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; font-size: 0.95rem;
}
.cpf-msg a { color: #991b1b; font-weight: 700; text-decoration: underline; }

/* ---- app shell ---- */
.cpf-app {
    position: relative;
    border: 1px solid var(--cpf-border);
    border-radius: 0.7rem;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.cpf-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem;
    padding: 0.55rem 0.7rem; background: var(--cpf-bg); border-bottom: 1px solid #e2e8f0;
}
.cpf-tgroup { display: flex; align-items: center; gap: 0.25rem; }
.cpf-tend { margin-left: auto; gap: 0.5rem; }
.cpf-tbtn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 1px solid #cfd8e3; background: #fff; color: #1f2937; border-radius: 0.5rem;
    padding: 0.45rem 0.7rem; font-size: 0.9rem; font-weight: 600; cursor: pointer; min-height: 38px;
}
.cpf-tbtn:hover { border-color: var(--cpf-accent); color: var(--cpf-accent-d); }
.cpf-tbtn-main { background: #eff6ff; border-color: #bfdbfe; color: var(--cpf-accent-d); }
.cpf-ibtn {
    width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; background: transparent; color: #334155; border-radius: 0.45rem; cursor: pointer;
}
.cpf-ibtn:hover:not(:disabled) { background: #e2e8f0; }
.cpf-ibtn:disabled { opacity: 0.35; cursor: default; }
.cpf-pageind { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.9rem; color: #334155; }
.cpf-pagein { width: 3.4rem; padding: 0.25rem 0.3rem; border: 1px solid #cbd5e1; border-radius: 0.35rem; text-align: center; font-size: 0.9rem; }
.cpf-zoomval { min-width: 3.2rem; text-align: center; font-size: 0.85rem; color: #334155; }
.cpf-download {
    display: inline-flex; align-items: center; gap: 0.45rem; border: none; cursor: pointer;
    background: #16a34a; color: #fff; font-weight: 700; padding: 0.55rem 1rem; border-radius: 0.5rem; font-size: 0.95rem; min-height: 38px;
}
.cpf-download:hover:not(:disabled) { background: #15803d; }
.cpf-download:disabled { opacity: 0.6; cursor: progress; }
.cpf-download:not(.is-ready) { background: #86c99b; }

.cpf-body { display: flex; height: min(78vh, 900px); min-height: 460px; }
.cpf-thumbs {
    flex: 0 0 128px; overflow-y: auto; background: #f1f4f8; border-right: 1px solid #e2e8f0;
    padding: 10px 12px; display: flex; flex-direction: column; gap: 10px;
}
.cpf-thumb {
    position: relative; display: block; width: 100%; padding: 0; border: 2px solid transparent; border-radius: 4px;
    background: transparent; cursor: pointer; flex: 0 0 auto;
}
.cpf-thumb .cpf-tcanvas {
    display: block; width: 100%; aspect-ratio: 1 / var(--cpf-tr, 1.414); height: auto;
    background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.cpf-thumb.is-cur { border-color: var(--cpf-accent); }
.cpf-tnum { display: block; text-align: center; font-size: 0.75rem; color: #475569; padding-top: 2px; }
.cpf-tbadge {
    position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
    background: var(--cpf-accent); color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center; font-weight: 700;
}
.cpf-viewer { flex: 1 1 auto; overflow: auto; background: #d5dbe3; position: relative; -webkit-overflow-scrolling: touch; }
.cpf-pages { position: relative; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: min-content; }
.cpf-pagebox { display: flex; flex-direction: column; align-items: center; }
.cpf-page { position: relative; background: #fff; box-shadow: 0 2px 8px rgba(15,23,42,0.22); }
.cpf-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cpf-layer { position: absolute; inset: 0; }
.cpf-pnum { font-size: 0.75rem; color: #475569; padding: 4px 0 8px; }

/* ---- side panel ---- */
.cpf-side { flex: 0 0 290px; overflow-y: auto; border-left: 1px solid #e2e8f0; padding: 12px 14px; background: #fff; }
.cpf-panel { margin-bottom: 1.1rem; }
.cpf-ph { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.5rem; color: #0f172a; }
.cpf-muted { color: var(--cpf-muted); font-size: 0.85rem; margin: 0; line-height: 1.45; }
.cpf-small { font-size: 0.8rem; }
.cpf-props-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.6rem; }
.cpf-field { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.6rem; flex: 1 1 auto; min-width: 0; }
.cpf-field-l { font-size: 0.78rem; font-weight: 600; color: #475569; }
.cpf-input {
    width: 100%; box-sizing: border-box; padding: 0.42rem 0.55rem; border: 1px solid #cbd5e1; border-radius: 0.4rem;
    font-size: 0.92rem; background: #fff; color: #111827; font-family: inherit;
}
.cpf-input:focus { outline: 2px solid #93c5fd; border-color: var(--cpf-accent); }
.cpf-ta { resize: vertical; min-height: 4.2rem; }
.cpf-num { width: 4.8rem; }
.cpf-color { width: 44px; height: 34px; padding: 2px; border: 1px solid #cbd5e1; border-radius: 0.4rem; background: #fff; cursor: pointer; }
.cpf-row { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.cpf-row > .cpf-field:nth-child(2), .cpf-row > .cpf-field:nth-child(3) { flex: 0 0 auto; }
.cpf-row-tight { flex-wrap: nowrap; align-items: stretch; }
.cpf-row-end { justify-content: flex-end; }
.cpf-acts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.2rem 0 0.7rem; }
.cpf-btn {
    display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.42rem 0.7rem; border-radius: 0.45rem;
    border: 1px solid #cbd5e1; background: #fff; color: #1f2937; font-size: 0.86rem; cursor: pointer; font-weight: 600;
}
.cpf-btn:hover:not(:disabled) { border-color: var(--cpf-accent); color: var(--cpf-accent-d); }
.cpf-btn:disabled { opacity: 0.45; cursor: default; }
.cpf-btn-danger { color: #b91c1c; }
.cpf-btn-danger:hover:not(:disabled) { border-color: #b91c1c; color: #991b1b; }
.cpf-btn-primary { background: var(--cpf-accent); border-color: var(--cpf-accent); color: #fff; }
.cpf-btn-primary:hover:not(:disabled) { background: var(--cpf-accent-d); color: #fff; }
.cpf-copyto { border-top: 1px solid #eef2f7; padding-top: 0.6rem; }
.cpf-copyto .cpf-field-l { display: block; margin-bottom: 0.25rem; }
.cpf-note-box { font-size: 0.8rem; color: #475569; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 0.5rem; padding: 0.6rem 0.7rem; margin: 0; line-height: 1.45; }
.cpf-status { padding: 0.55rem 0.9rem; font-size: 0.88rem; color: #334155; border-top: 1px solid #e2e8f0; background: var(--cpf-bg); min-height: 1.2em; overflow-wrap: anywhere; }
.cpf-toast {
    position: absolute; left: 50%; bottom: 56px; transform: translate(-50%, 10px); background: rgba(15,23,42,0.92); color: #fff;
    padding: 0.55rem 1rem; border-radius: 0.5rem; font-size: 0.88rem; max-width: 88%; text-align: center; opacity: 0;
    pointer-events: none; z-index: 30; transition: opacity 0.2s, transform 0.2s;
}
.cpf-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- responsive ---- */
@media (max-width: 1000px) {
    .cpf-side { flex-basis: 250px; }
    .cpf-thumbs { flex-basis: 104px; }
}
@media (max-width: 820px) {
    .cpf-body { flex-direction: column; height: auto; min-height: 0; }
    .cpf-thumbs { display: none; }
    .cpf-viewer { height: 68vh; min-height: 360px; flex: 0 0 auto; }
    .cpf-side { border-left: none; border-top: 1px solid #e2e8f0; flex: 0 0 auto; }
    .cpf-toolbar { gap: 0.4rem 0.5rem; }
    .cpf-tend { margin-left: 0; width: 100%; justify-content: space-between; }
    .cpf-download { flex: 1 1 auto; justify-content: center; }
    .cpf-pages { padding: 10px; }
}
@media (max-width: 520px) {
    .cpf-tbtn { padding: 0.4rem 0.55rem; font-size: 0.85rem; }
    .cpf-toolbar { gap: 0.35rem 0.4rem; }
    .cpf-zoomval { display: none; }
    .cpf-ibtn { width: 34px; height: 34px; }
}

/* ---- start choices ---- */
.cpf-or { margin: 1.1rem 0 0.2rem; color: var(--cpf-muted); font-size: 0.9rem; }
.cpf-blank-btn {
    display: inline-flex; align-items: center; gap: 0.45rem; border: 1px solid #bfdbfe; background: #eff6ff; color: var(--cpf-accent-d);
    padding: 0.55rem 1.2rem; border-radius: 2rem; font-weight: 600; cursor: pointer; font-size: 0.95rem;
}
.cpf-blank-btn:hover { border-color: var(--cpf-accent); }
.cpf-blank {
    margin: 0.9rem auto 0; max-width: 560px; text-align: left; background: #fff; border: 1px solid var(--cpf-border);
    border-radius: 0.7rem; padding: 0.9rem 1rem; cursor: default;
}
[dir="rtl"] .cpf-blank { text-align: right; }
.cpf-blank .cpf-row { margin-bottom: 0.2rem; }
.cpf-blank .cpf-field { min-width: 120px; }

/* ---- toolbar extras ---- */
.cpf-add { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.cpf-tbtn.is-on, .cpf-ibtn.is-on { background: #dbeafe; border-color: var(--cpf-accent); color: var(--cpf-accent-d); }
.cpf-ibtn.is-on { border-color: #93c5fd; }
.cpf-tbtn-detect { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.cpf-tbtn-detect:hover:not(:disabled) { border-color: #d97706; color: #78350f; }
.cpf-tbtn:disabled { opacity: 0.5; cursor: progress; }
.cpf-hint { padding: 0.45rem 0.9rem; font-size: 0.86rem; color: #334155; background: #f1f5f9; border-bottom: 1px solid #e2e8f0; }
.cpf-note { padding: 0.5rem 0.9rem; font-size: 0.85rem; color: #92400e; background: #fffbeb; border-bottom: 1px solid #fde68a; }
.cpf-app.is-armed .cpf-layer { cursor: crosshair; touch-action: none; }
.cpf-app.is-armed .cpf-f { cursor: crosshair; }
.cpf-layer { touch-action: pan-x pan-y pinch-zoom; }

/* ---- fields on the page ---- */
.cpf-f {
    position: absolute; cursor: move; touch-action: none; user-select: none; -webkit-user-select: none;
    outline: 1px dashed rgba(37, 99, 235, 0); outline-offset: 2px; box-sizing: border-box; line-height: 1.15;
}
.cpf-f:hover { outline-color: rgba(37, 99, 235, 0.6); }
.cpf-f.is-sel { outline: 2px solid var(--cpf-accent); z-index: 5; }
.cpf-f:focus-visible { outline: 2px solid var(--cpf-accent); }
.cpf-face {
    position: absolute; inset: 0; box-sizing: border-box; overflow: hidden; display: flex; align-items: center;
    pointer-events: none; padding: 0 0.25em;
}
.cpf-face-multiline, .cpf-face-list { align-items: flex-start; padding-top: 0.15em; }
.cpf-face-checkbox, .cpf-face-radio { justify-content: center; padding: 0; }
.cpf-face-checkbox i { font-size: 0.85em; }
.cpf-dot { width: 52%; height: 52%; border-radius: 50%; background: currentColor; display: block; }
.cpf-phd { opacity: 0.55; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cpf-phd-ml { white-space: pre-wrap; }
.cpf-caret { margin-left: auto; opacity: 0.7; font-size: 0.9em; }
[dir="rtl"] .cpf-caret { margin-left: 0; margin-right: auto; }
.cpf-lines { width: 100%; }
.cpf-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.75; }
.cpf-line.is-v { background: rgba(37, 99, 235, 0.25); opacity: 1; }
.cpf-tag {
    display: none; position: absolute; left: -2px; top: calc(100% + 5px); max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: #1e3a8a; color: #fff; font: 600 11px/1.3 system-ui, sans-serif; padding: 1px 6px; border-radius: 3px; pointer-events: none; z-index: 6;
}
.cpf-f.is-sel .cpf-tag, .cpf-f:hover .cpf-tag { display: block; }
.cpf-app.is-preview .cpf-tag { display: none !important; }
.cpf-h-del, .cpf-hd { display: none; position: absolute; }
.cpf-f.is-sel .cpf-hd { display: block; }
.cpf-f.is-sel .cpf-h-del { display: flex; }
.cpf-h-del {
    top: -24px; right: -2px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff;
    background: #dc2626; color: #fff; align-items: center; justify-content: center; cursor: pointer; font-size: 0.7rem; padding: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3); z-index: 7;
}
.cpf-hd {
    width: 10px; height: 10px; background: #fff; border: 2px solid var(--cpf-accent); border-radius: 2px; z-index: 6; box-sizing: border-box;
}
.cpf-hd-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.cpf-hd-n { left: calc(50% - 5px); top: -6px; cursor: ns-resize; }
.cpf-hd-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.cpf-hd-e { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.cpf-hd-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.cpf-hd-s { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
.cpf-hd-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.cpf-hd-w { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }
@media (pointer: coarse) {
    .cpf-hd { width: 18px; height: 18px; }
    .cpf-hd-nw { left: -10px; top: -10px; } .cpf-hd-ne { right: -10px; top: -10px; }
    .cpf-hd-se { right: -10px; bottom: -10px; } .cpf-hd-sw { left: -10px; bottom: -10px; }
    .cpf-hd-n { left: calc(50% - 9px); top: -10px; } .cpf-hd-s { left: calc(50% - 9px); bottom: -10px; }
    .cpf-hd-e { right: -10px; top: calc(50% - 9px); } .cpf-hd-w { left: -10px; top: calc(50% - 9px); }
    .cpf-h-del { width: 30px; height: 30px; top: -36px; }
}
.cpf-band { position: absolute; border: 1px solid var(--cpf-accent); background: rgba(37, 99, 235, 0.12); pointer-events: none; z-index: 8; }
.cpf-ghost { position: absolute; border: 2px dashed var(--cpf-accent); background: rgba(37, 99, 235, 0.1); pointer-events: none; z-index: 8; }

/* preview (test filling) */
.cpf-app.is-preview .cpf-f { cursor: auto; outline: none !important; user-select: auto; -webkit-user-select: auto; touch-action: auto; }
.cpf-app.is-preview .cpf-face { pointer-events: auto; padding: 0; }
.cpf-app.is-preview .cpf-hd, .cpf-app.is-preview .cpf-h-del { display: none !important; }
.cpf-in { width: 100%; height: 100%; box-sizing: border-box; border: 0; background: transparent; font-family: Helvetica, Arial, sans-serif; margin: 0; padding: 0 0.25em; resize: none; outline: none; }
textarea.cpf-in { padding-top: 0.15em; }
.cpf-in:focus { background: rgba(255, 255, 255, 0.7); box-shadow: inset 0 0 0 2px var(--cpf-accent); }
.cpf-in-box { padding: 0; width: 100%; height: 100%; accent-color: var(--cpf-accent); }
select.cpf-in { padding: 0 0.1em; }

/* ---- side panel extras ---- */
.cpf-props-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.6rem; }
.cpf-sub { font-size: 0.82rem; font-weight: 700; margin: 0.9rem 0 0.4rem; color: #0f172a; text-transform: none; border-top: 1px solid #eef2f7; padding-top: 0.6rem; }
.cpf-ta { resize: vertical; min-height: 3.6rem; }
.cpf-num { width: 5.4rem; }
.cpf-field-c { flex: 0 0 auto; }
.cpf-check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.86rem; margin: 0.35rem 0; cursor: pointer; line-height: 1.3; }
.cpf-aligns { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-bottom: 0.4rem; }
.cpf-aligns .cpf-ibtn { border-color: #d7dde5; background: #fff; width: 34px; height: 34px; }
.cpf-list { max-height: 240px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 0.45rem; padding: 0.2rem; background: #fff; }
.cpf-list-page { font-size: 0.72rem; font-weight: 700; color: #64748b; text-transform: uppercase; padding: 0.35rem 0.4rem 0.15rem; letter-spacing: 0.03em; }
.cpf-list-row {
    display: flex; align-items: center; gap: 0.45rem; width: 100%; text-align: start; border: 0; background: transparent; padding: 0.3rem 0.4rem;
    border-radius: 0.35rem; cursor: pointer; font-size: 0.85rem; color: #1f2937;
}
.cpf-list-row:hover { background: #f1f5f9; }
.cpf-list-row.is-sel { background: #dbeafe; }
.cpf-list-row i { color: #64748b; width: 1.1em; text-align: center; }
.cpf-list-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cpf-list-req { color: #dc2626; font-weight: 700; }
.cpf-ph-h { display: flex; justify-content: space-between; align-items: center; }
.cpf-count { background: #e2e8f0; border-radius: 9px; padding: 0 0.5rem; font-size: 0.75rem; font-weight: 700; color: #334155; }
.cpf-ad { display: block; }
.cpf-help { margin: 0.6rem 0 0; }
[dir="rtl"] .cpf-side { border-left: 0; border-right: 1px solid #e2e8f0; }
[dir="rtl"] .cpf-thumbs { border-right: 0; border-left: 1px solid #e2e8f0; }
@media (max-width: 820px) {
    [dir="rtl"] .cpf-side { border-right: 0; border-top: 1px solid #e2e8f0; }
    .cpf-list { max-height: 180px; }
}
@media (max-width: 520px) {
    .cpf-add { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
    .cpf-add .cpf-tbtn { justify-content: center; flex-direction: column; gap: 0.15rem; font-size: 0.74rem; text-align: center; }
}

.cpf-app.is-multi .cpf-hd { display: none !important; }
.cpf-app.is-multi .cpf-h-del { display: none !important; }
.cpf-app.is-multi .cpf-f.is-sel .cpf-tag { display: none; }
.cpf-hint.is-warn { background: #fef3c7; color: #92400e; font-weight: 600; }
