body { font-family: 'Outfit', sans-serif; }
        .drag-active { border-color: #00c07a !important; background-color: #f0fdf4 !important; }

        /* PDF Canvas & Overlays */
        #main-scroll-area {
            user-select: none;
            -webkit-user-select: none;
        }

        /* Hover box for existing text lines in PDF (Sejda-clean subtle hover) */
        .static-text-item {
            position: absolute;
            border: 1px dashed transparent;
            cursor: text;
            z-index: 40 !important;
            transition: border-color 0.14s ease, background-color 0.14s ease;
            border-radius: 2px;
            box-sizing: border-box;
            touch-action: manipulation;
        }
        .static-text-item:hover {
            border-color: rgba(37, 99, 235, 0.55) !important;
            background-color: rgba(37, 99, 235, 0.05) !important;
        }
        .embedded-image-item, .canvas-element-item, #editor-container button {
            touch-action: manipulation;
        }
        #pdf-zoom-stage {
            transition: width 0.15s ease, height 0.15s ease;
        }
        #pdf-render-container,
        .canvas-element-item,
        .content-edit {
            -webkit-text-size-adjust: none;
            text-size-adjust: none;
        }
        #pdf-render-container {
            transition: transform 0.15s ease;
        }

        /* Editable text box inside PDF (Sejda-style crisp single border, zero text jump) */
        .content-edit {
            outline: 1px dashed rgba(37, 99, 235, 0.48);
            border-radius: 2px;
            background: transparent;
            cursor: text;
            user-select: text;
            -webkit-user-select: text;
            display: inline-block;
            vertical-align: top;
            white-space: pre;
            line-height: 1;
            box-sizing: border-box;
        }
        .content-edit:focus {
            outline: 1.5px solid rgba(37, 99, 235, 0.78);
            outline-offset: 2px;
            border-radius: 3px;
            box-shadow: 0 2px 10px rgba(37, 99, 235, 0.12);
        }

        /* Move handle now lives cleanly in floating #text-toolbar (Sejda-style, zero overlap on lines above) */
        .text-drag-handle {
            display: none !important;
        }

        /* Resizers for shapes/images/whiteouts */
        .tool-resizer {
            position: absolute;
            width: 12px;
            height: 12px;
            background-color: #ffffff;
            border: 2px solid #2563eb;
            border-radius: 2px;
            box-shadow: 0 1px 4px rgba(0,0,0,0.25);
            z-index: 99999;
            display: none;
            touch-action: none;
        }
        .tool-resizer-se { bottom: -6px; right: -6px; cursor: se-resize; }
        .tool-resizer-sw { bottom: -6px; left: -6px; cursor: sw-resize; }
        .tool-resizer-ne { top: -6px; right: -6px; cursor: ne-resize; }
        .tool-resizer-nw { top: -6px; left: -6px; cursor: nw-resize; }
        .group.is-active .tool-resizer,
        .group:hover .tool-resizer {
            display: block !important;
        }
        .group.is-active {
            outline: 2px dashed #2563eb !important;
            outline-offset: 1px;
        }
        /* Sejda-style clean text focus: no outer dashed double box and no protruding red badge on text lines */
        .canvas-element-item[data-type="text"].group.is-active,
        .group[data-type="text"].is-active {
            outline: none !important;
        }
        .canvas-element-item[data-type="text"] .element-delete-badge,
        .group[data-type="text"] .element-delete-badge {
            display: none !important;
        }
        .canvas-element-item.is-active:not([data-type="whiteout"]),
        .group.is-active:not([data-type="whiteout"]) {
            z-index: 80 !important;
        }

        /* Strict Stacking Layer Hierarchy: Whiteout (20) -> Shapes (28) -> Images (30) -> Text (50) */
        .group[data-type="whiteout"],
        .canvas-element-item[data-type="whiteout"],
        div[data-type="whiteout"],
        div[data-is-embedded-mask="true"] {
            background-color: #ffffff !important;
            border: none !important;
            box-shadow: none !important;
            z-index: 20 !important;
        }
        .group[data-type="whiteout"]:not(.is-active) {
            border: none !important;
            box-shadow: none !important;
            outline: none !important;
        }
        .group[data-type="whiteout"].is-active,
        .canvas-element-item[data-type="whiteout"].is-active {
            outline: 1.5px dashed #2563eb !important;
            outline-offset: 0px !important;
            z-index: 22 !important;
        }

        .group[data-type="rect"],
        .group[data-type="ellipse"],
        .canvas-element-item[data-type="rect"],
        .canvas-element-item[data-type="ellipse"] {
            z-index: 28 !important;
        }

        .group[data-type="text"],
        .canvas-element-item[data-type="text"],
        div[data-type="text"] {
            z-index: 50 !important;
        }
        .group[data-type="text"].is-active,
        .canvas-element-item[data-type="text"].is-active,
        div[data-type="text"].is-active {
            z-index: 60 !important;
        }
        .content-edit {
            position: relative;
            z-index: 65 !important;
        }

        /* Embedded Image / Signature detection overlays (PDFescape mode) */
        .embedded-image-item {
            position: absolute;
            z-index: 42;
            border: 1.5px dashed transparent;
            border-radius: 4px;
            cursor: move !important;
            pointer-events: auto;
            user-select: none;
            transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
        }
        .embedded-image-item:hover {
            border: 2px dashed #2563eb !important;
            background-color: rgba(37, 99, 235, 0.08) !important;
            box-shadow: 0 2px 10px rgba(37, 99, 235, 0.18);
        }
        .embedded-image-item.is-active {
            z-index: 36 !important;
            border: 2px dashed #2563eb !important;
            outline: none !important;
            background-color: rgba(37, 99, 235, 0.04) !important;
            box-shadow: 0 4px 16px rgba(37, 99, 235, 0.2);
        }

        /* Delete badge (shapes/images/stamps/whiteout — never protrude over text boxes) */
        .group:not([data-type="text"]).is-active .element-delete-badge,
        .group:not([data-type="text"]):hover .element-delete-badge {
            display: flex !important;
        }
        .canvas-element-item[data-type="text"] .element-delete-badge,
        .group[data-type="text"].is-active .element-delete-badge,
        .group[data-type="text"]:hover .element-delete-badge {
            display: none !important;
        }
        .element-delete-badge {
            position: absolute;
            top: -12px;
            right: -12px;
            width: 24px;
            height: 24px;
            background: #ef4444;
            color: #ffffff;
            border: 2px solid #ffffff;
            border-radius: 50%;
            cursor: pointer;
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 100000;
            box-shadow: 0 2px 8px rgba(0,0,0,0.35);
            pointer-events: all;
            padding: 0;
            user-select: none;
            transition: transform 0.15s ease, background 0.15s ease;
        }
        .element-delete-badge:hover {
            background: #dc2626;
            transform: scale(1.12);
        }

        /* Dropdown menus */
        .editor-dropdown-menu {
            display: none;
        }
        .group:hover .editor-dropdown-menu,
        .editor-dropdown-menu.show {
            display: block !important;
        }

/* Mobile editor responsive layout helpers & touch targets */
.ep-engine-badge { display: none; }
#main-scroll-area { padding: 0.75rem; -webkit-overflow-scrolling: touch; }
#editor-save { padding: 0.65rem 1.35rem; }
#sign-canvas, canvas.touch-draw-active { touch-action: none; }
@media (min-width: 640px) {
    .ep-engine-badge { display: inline-block; }
    #main-scroll-area { padding: 1.5rem; }
    #editor-save { padding: 0.75rem 2rem; }
}
@media (pointer: coarse), (max-width: 767px) {
    .static-text-item {
        border-color: transparent;
        margin-top: -2px;
        padding: 2px 1px;
        box-sizing: content-box;
    }
    #text-toolbar {
        max-width: calc(100vw - 16px) !important;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #text-toolbar::-webkit-scrollbar {
        display: none;
    }
    .tool-resizer {
        width: 20px !important;
        height: 20px !important;
    }
    .tool-resizer-se { bottom: -10px !important; right: -10px !important; }
    .tool-resizer-sw { bottom: -10px !important; left: -10px !important; }
    .tool-resizer-ne { top: -10px !important; right: -10px !important; }
    .tool-resizer-nw { top: -10px !important; left: -10px !important; }
    .element-delete-badge {
        width: 28px !important;
        height: 28px !important;
        top: -14px !important;
        right: -14px !important;
    }
}

/* Modal z-index & mobile bottom-sheet styles (independent of unused Tailwind classes) */
#link-modal { z-index: 1000010 !important; }
#signature-modal { z-index: 1000010 !important; }
#mobile-text-modal {
    z-index: 1000015 !important;
    align-items: flex-end;
}
#mobile-text-modal > div {
    border-radius: 1.5rem 1.5rem 0 0;
    padding: 1.25rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    max-height: 92dvh;
    overflow-y: auto;
}
@media (min-width: 640px) {
    #mobile-text-modal {
        align-items: center;
        padding: 1rem;
    }
    #mobile-text-modal > div {
        border-radius: 1rem;
        padding: 1.5rem;
    }
}
#mte-text {
    padding: 0.625rem 0.875rem;
    font-size: 16px !important;
    line-height: 1.45;
}
#mte-size { background-color: transparent; }
#mte-color { padding: 2px; }
#mte-bold, #mte-italic, #mobile-text-modal button[onclick="deleteMobileEditedText()"] {
    padding: 0.375rem 0.75rem;
}
#mobile-text-modal button[onclick="closeMobileTextSheet(true)"] {
    padding: 0.25rem 0.625rem;
}
#mobile-text-modal label[for="mte-text"] {
    margin-bottom: 0.375rem;
}
.mte-style-active {
    background: #ecfdf5 !important;
    border-color: #10b981 !important;
    color: #047857 !important;
}

/* Responsive floating text toolbar on narrow screens */
#text-toolbar {
    max-width: calc(100vw - 16px);
    flex-wrap: wrap;
    row-gap: 4px;
}
@media (pointer: coarse), (max-width: 767px) {
    #text-toolbar button,
    #text-toolbar select {
        min-height: 36px;
    }
}

/* Dropdown menu open state (avoids overflow-x clipping when fixed-positioned via JS) */
.editor-dropdown-menu.dropdown-open {
    display: block !important;
    position: fixed !important;
    z-index: 999990 !important;
}

/* Form field widgets inside overlay */
.form-field-item {
    pointer-events: auto;
    user-select: none;
}
.form-field-control {
    width: 100%;
    height: 100%;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 12px;
    color: #0f172a;
    background: rgba(239, 246, 255, 0.85);
    border: 1.5px solid #2563eb;
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    box-sizing: border-box;
}
.form-field-control:focus {
    background: #ffffff;
    border-color: #059669;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.22);
}

/* Annotation highlight / underline / strikeout items */
.pdf-shape-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
    pointer-events: none;
}
