/* DOCSIGN-00C - customer Prep Studio (cps- prefix). Full-screen "Prepare" workspace opened from a Forms Hub document row.
 * Styles the shared neutral core (frontend/js/core/prepStudioCore.js): signing fields, document markup and generic signer slots.
 *
 * Theme-aware: every colour derives from the active theme's tokens (base.css) with a dark fallback, so it reads in the dark and
 * light themes. Preparation only - no recipient / send / sign UI exists in this surface. */

body.cps-lock { overflow: hidden; }

.cps-modal {
    --cps-surface: var(--bg-card, #1c1f26);
    --cps-text: var(--text-primary, #e5e7eb);
    --cps-muted: rgba(var(--text-primary-rgb, 229, 231, 235), 0.68);
    --cps-border: rgba(var(--text-primary-rgb, 229, 231, 235), 0.16);
    --cps-fill: rgba(var(--text-primary-rgb, 229, 231, 235), 0.07);
    --cps-fill-strong: rgba(var(--text-primary-rgb, 229, 231, 235), 0.14);
    --cps-accent: var(--accent-primary, #6366f1);
    --cps-accent-strong: var(--accent-strong, #4f46e5);
    --cps-accent-tint: rgba(var(--accent-primary-rgb, 99, 102, 241), 0.18);
    --cps-danger: #ef4444;
    position: fixed; inset: 0; z-index: 100000; display: flex; background: var(--cps-surface); color: var(--cps-text); overflow: hidden;
}
.cps-modal [hidden] { display: none !important; }
.cps-modal:focus { outline: none; }
.cps-modal-body { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; }
.cps-root { position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; min-height: 0; }

/* header + toolbar */
.cps-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 12px 16px; border-bottom: 1px solid var(--cps-border); }
.cps-heading { min-width: 0; flex: 1 1 220px; }
.cps-title { margin: 0; font-size: 1.15rem; line-height: 1.3; text-align: left; color: var(--cps-text); }
.cps-subtitle { margin: 2px 0 0; font-size: 0.85rem; color: var(--cps-muted); overflow-wrap: anywhere; }
.cps-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cps-zoom-label { min-width: 3.2em; text-align: center; font-size: 0.85rem; color: var(--cps-muted); }
.cps-status { font-size: 0.82rem; color: var(--cps-muted); min-width: 7.5em; }

.cps-btn { min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--cps-border); background: var(--cps-fill); color: var(--cps-text); font: inherit; font-size: 0.9rem; cursor: pointer; transition: background 0.15s ease; }
.cps-btn:hover:not(:disabled) { background: var(--cps-fill-strong); }
.cps-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cps-btn--primary { background: var(--cps-accent-strong); border-color: var(--cps-accent-strong); color: #fff; font-weight: 700; }
.cps-btn--primary:hover:not(:disabled) { background: var(--cps-accent-strong); filter: brightness(1.12); }
.cps-btn--danger { border-color: var(--cps-danger); color: var(--cps-danger); background: transparent; }
.cps-btn--icon { min-width: 40px; padding: 8px 10px; font-size: 1.1rem; line-height: 1; }
.cps-btn:focus-visible, .cps-field:focus-visible, .cps-markup-text:focus-visible, .cps-select:focus-visible, .cps-input:focus-visible, .cps-pages:focus-visible, .cps-notice-close:focus-visible { outline: 3px solid var(--cps-accent); outline-offset: 2px; }

/* notices + banners */
.cps-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 16px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--cps-border); font-size: 0.9rem; }
.cps-notice--success { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.5); }
.cps-notice--error { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.55); }
.cps-notice-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.cps-notice-close { flex: 0 0 auto; min-width: 32px; min-height: 32px; background: none; border: 0; color: var(--cps-muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.cps-banner { margin: 10px 16px 0; padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; }
.cps-banner--readonly { background: rgba(245, 183, 66, 0.2); border: 1px solid rgba(245, 183, 66, 0.6); }

/* workspace */
.cps-body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr) 260px; gap: 0; }
.cps-tools, .cps-inspector { padding: 14px; overflow-y: auto; min-height: 0; border-color: var(--cps-border); border-style: solid; border-width: 0; }
.cps-tools { border-right-width: 1px; display: flex; flex-direction: column; gap: 10px; }
.cps-inspector { border-left-width: 1px; display: flex; flex-direction: column; gap: 10px; }
.cps-tools-title { margin: 0; font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cps-muted); }
.cps-palette { display: flex; flex-direction: column; gap: 6px; }
.cps-type { text-align: left; }
.cps-type--armed { background: var(--cps-accent-tint); border-color: var(--cps-accent); font-weight: 700; }
.cps-plugin-toolbar { display: contents; }

/* generic signer slots (no recipients): colour dot + label chips, the SimpleSign palette */
.cps-slots { display: flex; flex-wrap: wrap; gap: 6px; }
.cps-slot { --slot-color: #6366f1; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--cps-border); background: var(--cps-fill); color: var(--cps-text); font: inherit; font-size: 0.82rem; cursor: pointer; }
.cps-slot:hover:not(:disabled) { background: var(--cps-fill-strong); }
.cps-slot:disabled { opacity: 0.5; cursor: not-allowed; }
.cps-slot:focus-visible { outline: 3px solid var(--cps-accent); outline-offset: 2px; }
.cps-slot-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--slot-color); flex: 0 0 auto; }
.cps-slot--active { border-color: var(--slot-color); background: var(--cps-fill-strong); font-weight: 700; box-shadow: 0 0 0 2px var(--slot-color); }
.cps-hint { margin: 0; font-size: 0.8rem; color: var(--cps-muted); }
.cps-page-indicator { font-size: 0.82rem; color: var(--cps-muted); }
.cps-slot-label, .cps-row { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--cps-muted); margin: 0; }
.cps-row--inline { flex-direction: row; align-items: center; gap: 8px; }
.cps-input--area { min-height: 84px; resize: vertical; }
.cps-select, .cps-input { min-height: 40px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--cps-border); background: var(--cps-fill); color: var(--cps-text); font: inherit; font-size: 0.9rem; width: 100%; box-sizing: border-box; }
/* login.css styles every bare input (width 100%, padding); reset it for the checkbox */
.cps-check { width: 18px; height: 18px; padding: 0; margin: 0; flex: 0 0 auto; }
.cps-field-meta { margin: 0; font-size: 0.82rem; color: var(--cps-muted); }
.cps-fields-list { display: flex; flex-direction: column; gap: 10px; }

.cps-stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: rgba(0, 0, 0, 0.22); }
.cps-loading, .cps-error { margin: 24px; text-align: center; color: var(--cps-muted); }
.cps-error { color: var(--cps-text); }
.cps-pages { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 16px; scroll-behavior: auto; }

/* pages */
.cps-page { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.35); max-width: none; }
.cps-canvas { display: block; width: 100%; height: 100%; }
.cps-overlay { position: absolute; inset: 0; }
.cps-root--armed .cps-overlay { cursor: crosshair; touch-action: none; }
.cps-ghost { position: absolute; border: 2px dashed var(--cps-accent); background: var(--cps-accent-tint); pointer-events: none; }

/* fields */
.cps-field { position: absolute; box-sizing: border-box; border: 2px solid var(--cps-accent); border-radius: 4px; cursor: move; touch-action: none; user-select: none; color: #111827; }
.cps-field--readonly { cursor: default; }
.cps-field--optional { border-style: dashed; }
.cps-field--selected { outline: 3px solid var(--cps-accent); outline-offset: 1px; z-index: 2; }
.cps-field-tag { display: block; max-width: 100%; padding: 0 3px; font-size: 11px; line-height: 1.3; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(255, 255, 255, 0.75); border-bottom-right-radius: 4px; }
.cps-handle { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid var(--cps-accent); border-radius: 50%; touch-action: none; box-sizing: border-box; }
.cps-handle::after { content: ''; position: absolute; inset: -12px; }
.cps-handle--nw { left: -7px; top: -7px; cursor: nwse-resize; }
.cps-handle--ne { right: -7px; top: -7px; cursor: nesw-resize; }
.cps-handle--sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.cps-handle--se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.cps-field:not(.cps-field--selected) .cps-handle, .cps-field--readonly .cps-handle { display: none; }

/* document markup: the preparer's visual edits to the PDF itself (text box, highlight, line, strikethrough, ellipse) */
.cps-field--markup { border: 1px dashed rgba(var(--text-primary-rgb, 229, 231, 235), 0.0); background: transparent; border-radius: 2px; }
.cps-field--markup.cps-field--selected { border-color: var(--cps-accent); }
.cps-field--markup:hover { border-color: rgba(100, 116, 139, 0.7); }
.cps-field--markup .cps-field-tag { display: none; }
.cps-markup-mark { position: absolute; inset: 0; pointer-events: none; }
.cps-field--markup_highlight .cps-markup-mark { background: rgba(250, 204, 21, 0.42); }
.cps-field--markup_ellipse .cps-markup-mark { border: 2px solid #1f2937; border-radius: 50%; }
.cps-field--markup_line .cps-markup-mark, .cps-field--markup_strikethrough .cps-markup-mark { top: 50%; bottom: auto; height: 0; border-top: 2px solid #111827; transform: translateY(-1px); }
.cps-field--markup_strikethrough .cps-markup-mark { border-top-color: #dc2626; }
.cps-field--markup_text_box { background: rgba(255, 255, 255, 0.9); border-color: rgba(100, 116, 139, 0.6); }
.cps-markup-text { display: block; position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); margin: 0; padding: 2px 4px; box-sizing: border-box; border: 0; border-radius: 0; background: transparent; color: #111827; font: inherit; font-size: 12px; line-height: 1.25; resize: none; overflow: hidden; cursor: text; }
.cps-field--markup_text_box:not(.cps-field--selected) .cps-markup-text { pointer-events: none; }
.cps-field--unknown { border-style: dotted; }
.cps-undo { min-width: 64px; }
.cps-duplicate { min-width: 96px; }

/* touch targets are independent of the percentage geometry: every field gets an invisible hit area of at least 24px
   (44px on touch screens), so a 0.3%-tall line or a tiny checkbox is still easy to grab; hidden while drawing */
.cps-field::before { content: ''; position: absolute; left: 50%; top: 50%; min-width: 24px; min-height: 24px; width: 100%; height: 100%; transform: translate(-50%, -50%); }
.cps-root--armed .cps-field::before { display: none; }
.cps-field--markup_text_box::before { display: none; }

/* unsaved-changes guard */
.cps-guard { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.55); }
.cps-guard-card { width: min(420px, 100%); padding: 20px; border-radius: 14px; border: 1px solid var(--cps-border); background: var(--cps-surface); display: flex; flex-direction: column; gap: 12px; }
.cps-guard-title { margin: 0; font-size: 1.05rem; text-align: left; color: var(--cps-text); }
.cps-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* tablet / mobile: tools become a strip above the pages, field settings a bottom sheet */
@media (max-width: 900px) {
    .cps-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
    .cps-tools { border-right-width: 0; border-bottom-width: 1px; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; gap: 8px; }
    .cps-tools-title, .cps-tools > .cps-hint { display: none; }
    .cps-palette { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; gap: 6px; -webkit-overflow-scrolling: touch; }
    .cps-palette .cps-btn { flex: 0 0 auto; white-space: nowrap; }
    .cps-slots { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
    .cps-slot { flex: 0 0 auto; white-space: nowrap; }
    .cps-inspector { border-left-width: 0; border-top-width: 1px; max-height: 30vh; padding: 8px 12px; gap: 6px; }
    /* compact two-column sheet so the page stays visible while a field is selected */
    .cps-fields-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; align-items: end; }
    .cps-fields-list > .cps-field-meta, .cps-fields-list > .cps-btn, .cps-row--wide { grid-column: 1 / -1; }
}
@media (pointer: coarse) {
    .cps-field::before { min-width: 44px; min-height: 44px; }
    .cps-handle { width: 16px; height: 16px; }
    .cps-handle::after { inset: -14px; }
    .cps-slot { min-height: 44px; }
    .cps-btn, .cps-select, .cps-input { min-height: 44px; }
    /* the app-wide custom select renderer replaces native selects with .csr-btn: keep its touch target at 44px too */
    .cps-modal .csr-btn { min-height: 44px; }
}
@media (max-width: 600px) {
    .cps-header { padding: 8px 12px; gap: 4px 12px; }
    .cps-subtitle { margin: 0; }
    .cps-toolbar { width: 100%; gap: 4px; }
    .cps-toolbar .cps-btn { padding-left: 8px; padding-right: 8px; }
    .cps-zoom-label { min-width: 2.6em; }
    /* one scrolling tool row (fields, markup, slots, place) so the page keeps most of the screen */
    .cps-tools { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; align-items: center; padding: 6px 12px; -webkit-overflow-scrolling: touch; }
    .cps-tools > * { flex: 0 0 auto; }
    .cps-palette, .cps-slots { display: contents; }
    .cps-tools .cps-btn, .cps-slot { white-space: nowrap; }
    .cps-page-indicator { display: none; }
    /* the selected item's settings: actions first so Duplicate / Delete are never scrolled away */
    .cps-inspector { max-height: 24vh; }
    .cps-fields-list > .cps-actions { order: -1; }
    .cps-fields-list > .cps-field-meta { order: -2; }
    .cps-status { flex: 1 1 100%; order: 5; }
    .cps-btn { min-height: 44px; }
    .cps-select, .cps-input { min-height: 44px; }
    .cps-pages { padding: 8px; }
    .cps-notice, .cps-banner { margin: 8px 12px 0; }
}
@media (prefers-reduced-motion: reduce) { .cps-btn { transition: none; } .cps-pages { scroll-behavior: auto; } }
