/* Annotate tool — menu, overlays, float toolbar accents */

.pedit-annotate-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 28; /* above images (26) so placed marks stay clickable */
    /* Keep none on the full layer so text edit still works; only .pedit-annotation captures. */
    pointer-events: none;
    overflow: visible;
}

.pedit-annotation {
    position: absolute;
    box-sizing: border-box;
    pointer-events: auto;
    cursor: pointer;
    touch-action: none;
    z-index: 1;
}

.pedit-annotation.is-selected {
    outline: 1px dashed rgba(247, 145, 18, 0.95);
    outline-offset: 2px;
    z-index: 2;
}

#pedit-annotate-float-toolbar {
    z-index: 90 !important;
}

.pedit-ann-draft-sel {
    position: absolute;
    pointer-events: none;
    z-index: 3;
    border-radius: 2px;
    box-sizing: border-box;
}

.pedit-ann-draft-sel.is-highlight {
    /* tint set inline */
}

/* Underline / strike: soft text-select wash + solid bar (not parent opacity —
   that would fade the ::after line and make marks look like they vanished). */
.pedit-ann-draft-sel.is-underline::after,
.pedit-ann--underline .pedit-ann-mark::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: max(1px, 10%);
    height: 3px;
    background: currentColor;
    border-radius: 1px;
    pointer-events: none;
}

.pedit-ann-draft-sel.is-strikeout::after,
.pedit-ann--strikeout .pedit-ann-mark::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 3px;
    margin-top: -1.5px;
    background: currentColor;
    border-radius: 1px;
    pointer-events: none;
}

.pedit-ann-mark {
    position: absolute;
    box-sizing: border-box;
    pointer-events: none;
    overflow: visible;
}

.pedit-ann--highlight .pedit-ann-mark {
    background: currentColor;
    opacity: 0.38;
    border-radius: 2px;
}

.pedit-ann--underline .pedit-ann-mark,
.pedit-ann--strikeout .pedit-ann-mark {
    /* Permanent marks: line only (::after). Select wash is draft-only. */
    background: transparent;
}

/* While placing text marks, don't let existing annotations steal the next select-drag */
#pedit-canvas-wrap.annotate-draw-mode .pedit-annotation {
    pointer-events: none !important;
}

#pedit-canvas-wrap.annotate-text-mode {
    cursor: text;
}

.pedit-ann-path {
    display: block;
    pointer-events: none;
}

.pedit-ann-draft {
    position: absolute;
    pointer-events: none;
    z-index: 2;
}

.pedit-ann-draft-text {
    border: 1px dashed currentColor;
    border-radius: 2px;
}

#pedit-canvas-wrap.annotate-draw-mode {
    cursor: crosshair;
}

#pedit-canvas-wrap.annotate-draw-mode.annotate-text-mode {
    cursor: text;
}

/*
 * Mobile: while placing a mark, stop the browser from stealing the finger
 * gesture for page scroll (that cancelled highlight/freehand drags).
 * Only active during annotate place-mode classes — edit/scroll untouched.
 */
#pedit-canvas-wrap.annotate-draw-mode,
#pedit-canvas-wrap.annotate-text-mode,
#pedit-canvas-wrap.annotate-freehand-mode {
    touch-action: none;
    overscroll-behavior: contain;
}

.pdf-viewer-panel:has(#pedit-canvas-wrap.annotate-draw-mode),
.pdf-viewer-panel:has(#pedit-canvas-wrap.annotate-text-mode),
.pdf-viewer-panel:has(#pedit-canvas-wrap.annotate-freehand-mode) {
    touch-action: none;
    overscroll-behavior: contain;
}

#pedit-canvas-wrap.annotate-draw-mode .pedit-text-hit {
    pointer-events: none !important;
}

#pedit-canvas-wrap.annotate-text-mode .pedit-text-hit {
    pointer-events: none !important;
}

/* Dropdown under Annotate toolbar button — fixed to viewport (like Shapes) */
.pedit-annotate-menu {
    position: fixed;
    z-index: 1100;
    width: 300px;
    max-height: min(70vh, 520px);
    overflow: auto;
    background: #fff;
    border: 1px solid rgba(17, 24, 39, 0.1);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(17, 24, 39, 0.14);
    padding: 12px 12px 14px;
    display: none;
}

.pedit-annotate-menu.is-open {
    display: block;
}

.pedit-ann-menu-head {
    margin-bottom: 10px;
}

.pedit-ann-menu-title {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: #111827;
}

.pedit-ann-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    margin-bottom: 12px;
    background: rgba(247, 145, 18, 0.08);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    cursor: pointer;
}

.pedit-ann-toggle input {
    width: 16px;
    height: 16px;
    accent-color: #f79112;
    cursor: pointer;
}

.pedit-ann-section {
    margin-bottom: 12px;
}

.pedit-ann-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7280;
    margin: 0 2px 8px;
}

.pedit-ann-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.pedit-ann-kind-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 1px solid rgba(17, 24, 39, 0.1);
    background: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    cursor: pointer;
    text-align: left;
}

.pedit-ann-kind-btn i {
    color: #f79112;
    width: 16px;
    text-align: center;
}

.pedit-ann-kind-btn:hover,
.pedit-ann-kind-btn.is-active {
    border-color: #f79112;
    background: rgba(247, 145, 18, 0.1);
}

.pedit-ann-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-left: 2px;
}

.pedit-ann-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(17, 24, 39, 0.2);
    cursor: pointer;
    padding: 0;
}

.pedit-ann-swatch.is-active {
    box-shadow: 0 0 0 2px #f79112;
}

/* Float toolbar — Shapes-like structure; keep brand orange border */
#pedit-annotate-float-toolbar {
    z-index: 90 !important;
    border-color: #f79112;
    box-shadow: 0 6px 20px rgba(17, 24, 39, 0.14);
}

#pedit-annotate-float-toolbar::after {
    border-right-color: #f79112;
    border-bottom-color: #f79112;
}

#pedit-annotate-float-toolbar .sft-sep {
    background: rgba(247, 145, 18, 0.45);
}

#pedit-annotate-float-toolbar .sft-seg {
    color: #374151;
}

#pedit-annotate-float-toolbar .sft-seg:hover,
#pedit-annotate-float-toolbar .sft-seg.is-open {
    background: rgba(247, 145, 18, 0.1);
    color: #111827;
}

#pedit-annotate-float-toolbar .sft-seg.sft-danger:hover {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

#pedit-annotate-float-toolbar .sft-seg.is-dimmed {
    opacity: 0.55;
}

#pedit-annotate-float-toolbar .sft-group {
    position: relative;
}

#pedit-annotate-float-toolbar .sft-menu {
    top: calc(100% + 10px);
    left: 0;
    border-color: #f79112;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 10px 28px rgba(17, 24, 39, 0.16);
    min-width: 188px;
}

/* When toolbar sits below the mark, open color menu upward */
#pedit-annotate-float-toolbar.sft-below .sft-menu {
    top: auto;
    bottom: calc(100% + 10px);
}

#pedit-annotate-float-toolbar .sft-swatch-row {
    gap: 8px;
    padding: 2px;
    justify-content: flex-start;
}

#pedit-annotate-float-toolbar .sft-swatch {
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(17, 24, 39, 0.18);
}

#pedit-annotate-float-toolbar .sft-swatch.is-active {
    box-shadow: 0 0 0 2px #f79112;
    border-color: #fff;
}

#pedit-annotate-float-toolbar .sft-custom-color {
    margin-top: 8px;
    padding: 8px 6px 2px;
    border-top: 1px solid rgba(17, 24, 39, 0.08);
    color: #6b7280;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

#pedit-annotate-float-toolbar .sft-custom-color input[type="color"] {
    width: 28px;
    height: 28px;
}

#pedit-annotate-float-toolbar .sft-icon-fill .sft-color-dot {
    width: 9px;
    height: 9px;
    border: 1px solid rgba(17, 24, 39, 0.2);
}

/* Fat-finger taps — coarsen menu / float targets without changing desktop layout. */
@media (pointer: coarse), (max-width: 768px) {
    .pedit-ann-kind-btn {
        min-height: 44px;
        padding: 12px 14px;
        font-size: 14px;
    }

    .pedit-ann-kind-btn i {
        width: 20px;
        font-size: 16px;
    }

    .pedit-ann-swatch {
        width: 28px;
        height: 28px;
    }

    .pedit-ann-toggle {
        min-height: 44px;
        padding: 12px 12px;
        font-size: 14px;
    }

    .pedit-ann-toggle input {
        width: 20px;
        height: 20px;
    }

    #pedit-annotate-float-toolbar .sft-seg {
        min-width: 40px;
        min-height: 40px;
    }

    #pedit-annotate-float-toolbar .sft-swatch {
        width: 28px;
        height: 28px;
    }

    #pedit-annotate-float-toolbar .sft-custom-color input[type="color"] {
        width: 36px;
        height: 36px;
    }

    .pedit-annotate-menu {
        width: min(320px, calc(100vw - 24px));
        max-height: min(75vh, 560px);
    }
}
