/* pdf-suite/css/edit.css
 * --------------------------------------------------------------
 * Styles for edit.php — page-thumbnail list, form-fill panel,
 * text-overlay tool indicator.  No inline styles anywhere.
 */

.file-input-hidden {
    display: none;
}

.file-button-secondary {
    background: var(--panel-light);
}

.sidebar-header-secondary {
    margin-top: 8px;
    border-top: 1px solid var(--border);
}

.page-list {

    display: flex;
    flex-direction: column;

    gap: 10px;

    margin: 0;
    padding: 16px;

    list-style: none;
}

.page-list-item {

    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-rows: auto auto;

    gap: 8px 12px;

    padding: 10px;

    border:
        1px solid var(--border);

    border-radius: 8px;

    background: var(--panel-light);
}

.page-list-item.is-dragover {

    outline:
        2px dashed var(--accent);

    outline-offset: -4px;
}

.page-thumb {

    grid-row: 1 / span 2;

    width: 56px;
    height: 72px;

    border:
        1px solid var(--border);

    border-radius: 4px;

    background: #fff;

    object-fit: contain;
}

.page-meta {

    align-self: center;

    color: var(--muted);
    font-size: 13px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-actions {

    display: flex;
    flex-wrap: wrap;

    gap: 6px;
}

.page-actions button {

    padding: 6px 10px;

    font-size: 12px;
}

.page-actions button.page-action-danger {

    background: #7f1d1d;
}

.form-fields-container {

    display: flex;
    flex-direction: column;

    gap: 10px;

    padding: 16px;
}

.form-field {

    display: flex;
    flex-direction: column;

    gap: 4px;
}

.form-field label {

    color: var(--muted);
    font-size: 13px;
}

.form-field input[type="text"],
.form-field select,
.form-field textarea {

    padding: 8px 10px;

    border:
        1px solid var(--border);

    border-radius: 6px;

    background: var(--panel-light);
    color: var(--text);

    font: inherit;
}

.form-field-checkbox {

    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.form-field-checkbox label {

    color: var(--text);
}

/* Row that pairs a form-field control with its Delete button so they
 * sit side-by-side without the button stretching to the input's
 * width.  Used by editPdfForm.js for text / select / radio rows;
 * checkboxes append the button directly to the wrap. */
.form-field-row {

    display: flex;
    align-items: stretch;
    gap: 6px;
}

.form-field-row > input[type="text"],
.form-field-row > select {

    flex: 1 1 auto;
    min-width: 0;
}

/* Multi-select list boxes need vertical room so the user can see and
 * Ctrl/Cmd-click multiple options.  Without this, the browser collapses
 * a <select multiple> down to the height of a single-line dropdown. */
.form-field-row > select[multiple] {

    min-height: 96px;
    padding: 4px 6px;
}

.form-field-delete {

    flex: 0 0 auto;

    width: 28px;
    height: 28px;

    padding: 0;

    border: 1px solid var(--border);
    border-radius: 6px;

    background: var(--panel-light);
    color: #b91c1c;

    font-size: 14px;
    line-height: 1;

    cursor: pointer;
}

.form-field-delete:hover,
.form-field-delete:focus-visible {

    background: #7f1d1d;
    color: #fff;
}

/* Viewer cursor + overlay placement layer */

#viewerContainer.tool-add-text #viewer .page {
    cursor: text;
}

#viewerContainer.tool-add-image #viewer .page {
    cursor: copy;
}

#viewerContainer.tool-select #viewer .page,
#viewerContainer.tool-select .overlay-layer {
    cursor: crosshair;
}

/* Suppress overlay-mark pointer events while the select tool is active
 * so a drag starts a new selection rectangle even if it begins over an
 * existing overlay. */
#viewerContainer.tool-select .overlay-mark {
    pointer-events: none;
}

.overlay-layer {

    position: absolute;
    inset: 0;

    pointer-events: auto;
}

.overlay-mark {

    position: absolute;

    padding: 2px 4px;

    border:
        1px dashed var(--accent);

    background: rgba(59, 130, 246, .12);

    color: #0f172a;

    /* font-size / line-height are applied inline per-overlay by
     * applyTextStyleToElement so the mark visually matches the PDF
     * size — do NOT set a fixed font-size here or it overrides
     * the very first paint before JS catches up. */
    line-height: 1.2;

    cursor: move;
    pointer-events: auto;
    touch-action: none;
    transform-origin: 50% 50%;
    user-select: none;
}

#viewerContainer.tool-add-text  .overlay-mark,
#viewerContainer.tool-add-image .overlay-mark {
    pointer-events: none;
}

.overlay-mark.is-selected {

    outline: 2px solid var(--accent);
    outline-offset: 1px;

    z-index: 4;
}

.overlay-mark-image {

    padding: 0;
    background: transparent;
}

/* Rect overlay — a solid-color rectangle used to "erase" or fill an
 * area (the white hole left behind when a selection is moved or
 * deleted).  Background colour is applied inline per-overlay. */
.overlay-mark-rect {

    padding: 0;
    border: 1px dashed rgba(15, 23, 42, .25);
    background: #ffffff;
}

/* Active selection rectangle drawn while the user is dragging out a
 * region with the select tool (before mouse-up). */
.selection-rect {

    position: absolute;

    border: 1px dashed var(--accent);
    background: rgba(59, 130, 246, .12);

    pointer-events: none;

    box-sizing: border-box;
}

/* Confirmed selection — drawn after mouse-up, awaiting user action
 * (drag / right-click / Delete).  Same look as .overlay-mark.is-selected
 * but without the inner content. */
.selection-mark {

    position: absolute;

    border: 1px dashed var(--accent);
    outline: 2px solid var(--accent);
    outline-offset: 1px;

    background: rgba(59, 130, 246, .15);

    cursor: move;
    pointer-events: auto;
    touch-action: none;
    box-sizing: border-box;
    user-select: none;

    z-index: 4;
}

/* Move-mode selection (mobile flow) — more opaque fill and thicker
 * border so it's clearly visible on a white PDF page.  The PC default
 * .selection-mark style above is intentionally subtle. */
.selection-mark.selection-mark-move {

    background: rgba(59, 130, 246, .30);
    border: 2px dashed var(--accent);
    outline-offset: 0;
}

/* Resize handles for move-mode selections (touch flow).  Larger than the
 * overlay-mark handles since they have to be reachable with a fingertip. */
.selection-mark-handle {

    position: absolute;

    width: 22px;
    height: 22px;

    background: var(--accent);

    border: 2px solid #ffffff;
    border-radius: 50%;

    box-shadow: 0 1px 3px rgba(0, 0, 0, .35);

    pointer-events: auto;
    touch-action: none;

    z-index: 5;
}

.selection-mark-handle-tl { top: -11px; left: -11px;  cursor: nwse-resize; }
.selection-mark-handle-tr { top: -11px; right: -11px; cursor: nesw-resize; }
.selection-mark-handle-bl { bottom: -11px; left: -11px;  cursor: nesw-resize; }
.selection-mark-handle-br { bottom: -11px; right: -11px; cursor: nwse-resize; }

/* While the user is in the act of dragging the selection to lift it,
 * the floating preview image shows the captured pixels following the
 * cursor.  Fixed positioning keeps it free of any clipping ancestor. */
.selection-drag-preview {

    position: fixed;

    border: 1px dashed var(--accent);

    opacity: .85;
    pointer-events: none;
    user-select: none;

    z-index: 1600;
}

.selection-drag-preview img {

    display: block;

    width: 100%;
    height: 100%;
}

.overlay-mark-image img {

    display: block;

    width: 100%;
    height: auto;

    pointer-events: none;
    user-select: none;
}

.overlay-mark-handle {

    position: absolute;

    width: 14px;
    height: 14px;

    border: 2px solid #fff;
    border-radius: 50%;

    background: var(--accent);
    box-sizing: border-box;

    pointer-events: auto;
    touch-action: none;

    z-index: 5;
}

.overlay-mark-handle-resize-tl { top: -7px;    left: -7px;   cursor: nwse-resize; }
.overlay-mark-handle-resize-tr { top: -7px;    right: -7px;  cursor: nesw-resize; }
.overlay-mark-handle-resize-bl { bottom: -7px; left: -7px;   cursor: nesw-resize; }
.overlay-mark-handle-resize-br { bottom: -7px; right: -7px;  cursor: nwse-resize; }

.overlay-mark-handle-rotate {

    top: -34px;
    left: 50%;

    margin-left: -7px;

    background: #fff;
    border-color: var(--accent);

    cursor: grab;
}

.overlay-mark-handle-rotate::after {

    content: '';

    position: absolute;
    top: 100%;
    left: 50%;

    width: 2px;
    height: 20px;

    margin-left: -1px;

    background: var(--accent);
}

.overlay-mark-handle-rotate:active {
    cursor: grabbing;
}

/* Paste / context menu shown on right-click or long-tap. */
.overlay-context-menu {

    position: fixed;
    z-index: 1500;

    min-width: 140px;
    padding: 4px 0;

    border: 1px solid var(--border);
    border-radius: 6px;

    background: var(--panel);
    box-shadow: var(--shadow);
}

.overlay-context-menu button {

    display: block;

    width: 100%;
    padding: 8px 14px;

    border: 0;

    background: transparent;
    color: var(--text);

    text-align: left;

    cursor: pointer;
    font: inherit;
}

.overlay-context-menu button:hover,
.overlay-context-menu button:focus {

    background: var(--panel-light);
}

.overlay-context-menu button:disabled {

    color: var(--muted);
    cursor: default;
}

/* Bigger touch targets and wider menu on touch devices so Copy / Cut /
 * Delete are reachable with a fingertip without misfires. */
@media (pointer: coarse) {

    .overlay-context-menu {
        min-width: 200px;
    }

    .overlay-context-menu button {
        padding: 14px 18px;
        font-size: 15px;
    }
}

.edit-text-prompt {

    display: flex;
    flex-direction: column;

    gap: 6px;

    padding: 12px 16px;

    border-top:
        1px solid var(--border);

    background: var(--panel-light);
}

.edit-text-prompt label {

    color: var(--muted);
    font-size: 13px;
}

.edit-text-prompt input,
.edit-text-prompt select {

    padding: 8px 10px;

    border:
        1px solid var(--border);

    border-radius: 6px;

    background: var(--panel);
    color: var(--text);

    font: inherit;
}

.edit-text-prompt-row {

    display: flex;
    align-items: center;
    gap: 8px;
}

.edit-text-prompt-row > * {

    flex: 1;
}

/* Placement markers — drawn at the user's click point until the overlay
 * is confirmed (replaced with the real overlay) or cancelled (removed).
 * Image marker is centred on the click (per spec); text caret aligns
 * its left edge with the click so the inserted text starts where the
 * caret blinked. */
.placement-marker {

    position: absolute;

    pointer-events: none;
}

.placement-marker-text {

    width: 2px;
    height: 1.4em;

    transform: translate(0, -50%);

    background: var(--accent);

    box-shadow: 0 0 0 1px rgba(255, 255, 255, .55);

    animation: editPlacementCaret 1s steps(2, end) infinite;
}

@keyframes editPlacementCaret {
    0%, 49%   { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.placement-marker-image {

    width: 64px;
    height: 64px;

    transform: translate(-50%, -50%);

    border: 2px solid var(--accent);
    background: rgba(59, 130, 246, .12);

    box-sizing: border-box;
}

.placement-marker-image::after {

    content: '';

    display: block;

    width: 100%;
    height: 100%;

    border: 2px solid var(--accent);
    border-radius: 50%;

    box-sizing: border-box;
}

/* Wide variant of the .pdf-modal-dialog for the rich text-overlay form. */
.pdf-modal-dialog-wide {

    max-width: 640px;
}

.edit-text-form {

    display: flex;
    flex-direction: column;

    gap: 14px;
}

.edit-text-form-row {

    display: flex;
    flex-direction: column;

    gap: 4px;
}

.edit-text-form-row > span {

    color: var(--muted);
    font-size: 13px;
}

.edit-text-form-row textarea {

    padding: 8px 10px;

    border: 1px solid var(--border);
    border-radius: 6px;

    background: var(--panel-light);
    color: var(--text);

    font: inherit;
    resize: vertical;
}

.edit-text-form-grid {

    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));

    gap: 10px 12px;
}

.edit-text-form-grid label,
.edit-text-form-grid .edit-text-form-field {

    display: flex;
    flex-direction: column;

    gap: 4px;

    color: var(--muted);
    font-size: 13px;
}

.edit-text-form-grid select,
.edit-text-form-grid input[type="number"] {

    padding: 8px 10px;

    border: 1px solid var(--border);
    border-radius: 6px;

    background: var(--panel-light);
    color: var(--text);

    font: inherit;
}

.edit-text-form-toggles {

    display: flex;
    flex-wrap: wrap;
    gap: 14px;

    padding-top: 4px;
}

.edit-text-form-preview {

    min-height: 56px;
    padding: 10px 12px;

    border: 1px dashed var(--border);
    border-radius: 6px;

    /* White background so the chosen text colour is always readable —
     * the surrounding panel is dark in the default theme and any black
     * preview text would otherwise vanish. */
    background: #ffffff;
    color: #0f172a;

    overflow: auto;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Draggable text-overlay modal — h2 acts as the drag handle.  Modal
 * remains centered on open (via the flex parent) and only switches to
 * fixed-position once the user grabs the title bar. */
.pdf-modal-drag-handle {

    cursor: move;
    user-select: none;
    touch-action: none;
}

.pdf-modal-dialog.pdf-modal-dialog-dragging {

    position: fixed;
    margin: 0;
}

/* ──────────────────────────────────────────────────────────────
 * Custom color picker — replaces <input type="color"> which has
 * an unusable popover on mobile (16 colours, no manual entry on
 * some Android browsers).  Touch targets are sized for fingers.
 * ──────────────────────────────────────────────────────────── */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.color-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-picker-swatch {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #000000;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.color-picker-swatch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.color-picker-hex {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-light);
    color: var(--text);
    font: inherit;
    font-family: "Courier New", Consolas, monospace;
    text-transform: lowercase;
}

.color-picker-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 1000;
    display: none;
    width: 280px;
    max-width: calc(100vw - 24px);
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.color-picker-popover.is-open {
    display: block;
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    margin-bottom: 12px;
}

.color-picker-preset {
    aspect-ratio: 1;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    cursor: pointer;
}

.color-picker-preset:hover,
.color-picker-preset:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.color-picker-sliders {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.color-picker-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker-slider-row > span[aria-hidden="true"] {
    flex: 0 0 14px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.color-picker-slider {
    flex: 1 1 auto;
    height: 28px;
    margin: 0;
    padding: 0;
    border-radius: 14px;
    background: var(--panel-light);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    touch-action: none;
}

.color-picker-slider::-webkit-slider-runnable-track {
    height: 28px;
    border-radius: 14px;
    background: transparent;
}

.color-picker-slider::-moz-range-track {
    height: 28px;
    border-radius: 14px;
    background: transparent;
}

.color-picker-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    margin-top: 3px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    cursor: grab;
}

.color-picker-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    cursor: grab;
}

.color-picker-slider:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.color-picker-hue {
    background: linear-gradient(
        to right,
        hsl(0,   100%, 50%),
        hsl(60,  100%, 50%),
        hsl(120, 100%, 50%),
        hsl(180, 100%, 50%),
        hsl(240, 100%, 50%),
        hsl(300, 100%, 50%),
        hsl(360, 100%, 50%)
    );
}

.color-picker-popover-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.color-picker-current {
    display: inline-block;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #000000;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.color-picker-close {
    padding: 8px 16px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.color-picker-close:focus-visible {
    outline: 2px solid var(--accent-soft);
    outline-offset: 2px;
}

/* Touch-first layout: larger swatches/thumbs and a fixed-to-screen
 * popover so it never gets clipped by the modal on narrow viewports. */
@media (max-width: 600px), (pointer: coarse) {

    .color-picker-swatch {
        width: 44px;
        height: 44px;
    }

    .color-picker-hex {
        padding: 10px 12px;
        font-size: 16px;
    }

    .color-picker-popover {
        position: fixed;
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 12px;
        width: auto;
        max-width: none;
        max-height: 72vh;
        overflow: auto;
        padding: 14px;
    }

    .color-picker-grid {
        grid-template-columns: repeat(8, 1fr);
        gap: 6px;
        margin-bottom: 14px;
    }

    .color-picker-preset {
        min-width: 36px;
        min-height: 36px;
        border-radius: 6px;
    }

    .color-picker-slider {
        height: 36px;
        border-radius: 18px;
    }

    .color-picker-slider::-webkit-slider-runnable-track {
        height: 36px;
        border-radius: 18px;
    }

    .color-picker-slider::-moz-range-track {
        height: 36px;
        border-radius: 18px;
    }

    .color-picker-slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
        margin-top: 4px;
    }

    .color-picker-slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }

    .color-picker-current {
        width: 40px;
        height: 40px;
    }

    .color-picker-close {
        padding: 12px 20px;
        font-size: 16px;
    }
}

/* ──────────────────────────────────────────────────────────────
 * Save-format chooser modal (Original vs Printed)
 * ──────────────────────────────────────────────────────────── */

.save-format-intro {
    margin: 0 0 12px 0;
    color: var(--muted);
    font-size: 13px;
}

.save-format-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
}

.save-format-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;

    padding: 12px 14px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--panel-light);
    color: var(--text);

    text-align: left;
    cursor: pointer;

    font: inherit;
    transition: border-color 120ms ease, background 120ms ease;
}

.save-format-choice:hover,
.save-format-choice:focus-visible {
    border-color: var(--accent);
    background: var(--panel);
    outline: none;
}

.save-format-choice-title {
    font-weight: 600;
    font-size: 15px;
}

.save-format-choice-desc {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}
