/* ===== Sign Documents V2 (DocuSign-style) ===== */

.sv2-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 2500;
    align-items: stretch;
    justify-content: stretch;
}
.sv2-overlay.show { display: flex; }

.sv2-modal {
    background: #f8fafc;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sv2-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 22px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    flex-shrink: 0;
}
.sv2-header h2 {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    gap: 9px;
    align-items: center;
    white-space: nowrap;
}
.sv2-header .sv2-title-input {
    margin-left: 14px;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    min-width: 340px;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.sv2-header .sv2-title-input:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.sv2-header .sv2-actions { display: flex; gap: 8px; align-items: center; }
.sv2-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}
.sv2-btn:hover { background: #f1f5f9; border-color: #94a3b8; }
.sv2-btn.primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.sv2-btn.primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.38);
}
.sv2-btn.danger {
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.22);
}
.sv2-btn.danger:hover:not(:disabled) { box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35); }
.sv2-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }

.sv2-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sv2-sidebar {
    width: 290px;
    min-width: 290px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sv2-sidebar-section {
    padding: 14px;
    border-bottom: 1px solid #f1f5f9;
}
.sv2-sidebar-section h3 {
    margin: 0 0 10px 0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sv2-sidebar-section h3 .sv2-add-btn {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #dbeafe;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 0.66rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: none;
    letter-spacing: normal;
    transition: all 0.15s;
}
.sv2-sidebar-section h3 .sv2-add-btn:hover { background: #dbeafe; border-color: #93c5fd; }

.sv2-signers { display: flex; flex-direction: column; gap: 6px; }
.sv2-signer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    background: #fff;
    border-left-width: 4px;
}
.sv2-signer:hover { background: #f8fafc; }
.sv2-signer.active {
    background: #eff6ff;
    box-shadow: 0 0 0 2px #93c5fd inset;
}
.sv2-signer-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}
.sv2-signer-info { flex: 1; min-width: 0; overflow: hidden; }
.sv2-signer-name { font-size: 0.82rem; font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sv2-signer-email { font-size: 0.7rem; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sv2-signer-remove {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px;
    font-size: 0.75rem;
}
.sv2-signer-remove:hover { color: #ef4444; }
.sv2-signers-empty {
    color: #94a3b8;
    font-size: 0.75rem;
    text-align: center;
    padding: 12px 0;
}

.sv2-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sv2-palette-item {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 6px;
    text-align: center;
    cursor: grab;
    user-select: none;
    transition: all 0.15s ease;
    font-size: 0.72rem;
    color: #475569;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.sv2-palette-item:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.15);
}
.sv2-palette-item:active { cursor: grabbing; transform: scale(0.97); }
.sv2-palette-item.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.sv2-palette-item i { display: block; font-size: 1.2rem; margin-bottom: 6px; color: #3b82f6; }

.sv2-palette-hint {
    margin-top: 10px;
    padding: 10px 12px;
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border: 1px solid #fde68a;
    border-radius: 8px;
    font-size: 0.7rem;
    color: #92400e;
    line-height: 1.5;
}

.sv2-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #e5e7eb;
}

.sv2-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 9px 16px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.82rem;
    flex-shrink: 0;
}
.sv2-toolbar .sv2-tb-group { display: flex; align-items: center; gap: 8px; }
.sv2-toolbar button {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 11px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #475569;
    transition: all 0.15s;
}
.sv2-toolbar button:hover { background: #eff6ff; border-color: #93c5fd; color: #2563eb; }
.sv2-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }

.sv2-viewer {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.sv2-canvas-wrap {
    position: relative;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    margin: 0 auto;
}
.sv2-canvas-wrap canvas { display: block; }
.sv2-overlay-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.sv2-drop-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #64748b;
    background: radial-gradient(circle at 50% 38%, #ffffff 0%, #f8fafc 100%);
    margin: 24px;
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.18s ease;
}
.sv2-drop-screen:hover {
    border-color: #93c5fd;
    background: radial-gradient(circle at 50% 38%, #ffffff 0%, #eff6ff 100%);
}
.sv2-drop-screen.drag-over {
    border-color: #2563eb;
    background: #eff6ff;
    color: #2563eb;
    transform: scale(1.005);
}
.sv2-drop-screen i {
    font-size: 2.6rem;
    margin-bottom: 16px;
    color: #3b82f6;
    background: #eff6ff;
    width: 88px;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.18);
}
.sv2-drop-screen h3 { margin: 0 0 6px 0; font-size: 1.1rem; font-weight: 700; color: #1e293b; }
.sv2-drop-screen p { margin: 0; font-size: 0.86rem; }

.sv2-field {
    position: absolute;
    pointer-events: auto;
    border: 2px dashed #2563eb;
    background: rgba(37, 99, 235, 0.08);
    border-radius: 4px;
    cursor: move;
    user-select: none;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #2563eb;
    font-size: 11px;
    font-family: Arial, sans-serif;
    padding: 4px;
    text-align: center;
    overflow: hidden;
}
.sv2-field:hover { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3); }
.sv2-field.selected { box-shadow: 0 0 0 2px #2563eb; }
.sv2-field i { font-size: 14px; margin-bottom: 2px; }
.sv2-field .sv2-field-label { font-weight: 600; line-height: 1.1; }
.sv2-field .sv2-field-sub { font-size: 9px; opacity: 0.8; }
.sv2-field .sv2-field-delete {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.sv2-field:hover .sv2-field-delete,
.sv2-field.selected .sv2-field-delete { display: flex; }
.sv2-field .sv2-field-resize {
    position: absolute;
    right: -4px;
    bottom: -4px;
    width: 10px;
    height: 10px;
    background: #2563eb;
    cursor: nwse-resize;
    border-radius: 2px;
    display: none;
}
.sv2-field:hover .sv2-field-resize,
.sv2-field.selected .sv2-field-resize { display: block; }

.sv2-ghost {
    position: absolute;
    pointer-events: none;
    opacity: 0.7;
    z-index: 10;
}

/* Reuse for picker sub-modal */
.sv2-picker {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2600;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.sv2-picker.show { display: flex; }
.sv2-picker-content {
    background: #fff;
    width: 560px;
    max-width: 95%;
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sv2-picker-header {
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sv2-picker-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #1e293b;
    display: flex;
    gap: 8px;
    align-items: center;
}
.sv2-picker-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
}
.sv2-picker-tab {
    flex: 1;
    padding: 10px;
    background: #f8fafc;
    border: none;
    cursor: pointer;
    font-size: 0.82rem;
    color: #64748b;
    border-bottom: 2px solid transparent;
}
.sv2-picker-tab.active {
    background: #fff;
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}
.sv2-picker-body {
    padding: 16px;
    overflow: auto;
    flex: 1;
}
.sv2-picker-body input,
.sv2-picker-body select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 10px;
    box-sizing: border-box;
}
.sv2-picker-list {
    max-height: 280px;
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}
.sv2-picker-user {
    padding: 10px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
}
.sv2-picker-user:hover { background: #f8fafc; }
.sv2-picker-user.selected { background: #eff6ff; }
.sv2-picker-user img,
.sv2-picker-user .sv2-avatar-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #cbd5e1;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}
.sv2-picker-user-info { flex: 1; min-width: 0; }
.sv2-picker-user-name { font-size: 0.85rem; font-weight: 600; color: #1e293b; }
.sv2-picker-user-meta { font-size: 0.7rem; color: #64748b; }
.sv2-picker-footer {
    padding: 12px 18px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===== Mobile optimization for the Sign page (clicked from a document row) ===== */
@media (max-width: 768px) {
    /* Header: let the title and action buttons wrap and stay tappable */
    #sv2SignModal .sv2-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
        position: relative;
    }
    #sv2SignModal .sv2-header > div:first-child {
        flex: 1 1 100%;
        gap: 8px !important;
        flex-wrap: wrap;
        padding-right: 44px; /* leave room for the corner close button */
    }
    #sv2SignModal .sv2-header h2 { font-size: 0.92rem; }
    #sv2SignModal #sv2SignerLabel { font-size: 0.74rem; flex-basis: 100%; }
    #sv2SignModal .sv2-actions {
        width: 100%;
        gap: 6px;
    }
    #sv2SignModal .sv2-actions .sv2-btn {
        flex: 1;
        justify-content: center;
        padding: 9px 8px;
        font-size: 0.78rem;
    }
    /* Move the Close button to the top-right corner */
    #sv2SignModal #sv2SignCloseBtn {
        position: absolute;
        top: 8px;
        right: 10px;
        flex: 0 0 auto;
        width: 34px;
        height: 34px;
        padding: 0;
        border-radius: 50%;
        font-size: 0; /* hide the "Close" text label */
        z-index: 2;
    }
    #sv2SignModal #sv2SignCloseBtn i { margin: 0; font-size: 0.95rem; }

    /* Body: stack the fields/signature panel on top of the document */
    #sv2SignModal .sv2-body { flex-direction: column; }
    #sv2SignModal .sv2-sidebar {
        width: 100%;
        min-width: 0;
        max-height: 30vh;
        overflow-y: auto;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
        flex-direction: row;
        flex-wrap: wrap;
    }
    #sv2SignModal .sv2-sidebar-section {
        flex: 1 1 48%;
        min-width: 150px;
        border-bottom: none;
    }
    /* Hide the "Your Fields" heading on mobile to save space */
    #sv2SignModal .sv2-sidebar-section h3 { display: none; }
    /* Align signer name and sign history (status · date) on the same row */
    #sv2SignModal .sv2-signer-status {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 4px 8px;
    }
    #sv2SignModal .sv2-main { width: 100%; }

    /* Toolbar + viewer: tighten spacing so the PDF gets maximum room */
    #sv2SignModal .sv2-toolbar {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 8px 10px;
        justify-content: flex-end; /* zoom controls sit on the right above the document */
        align-items: center;
    }
    /* Hide the document/file title shown above the page (kept in the header) */
    #sv2SignModal .sv2-toolbar .sv2-tb-group:first-child { display: none; }
    #sv2SignModal .sv2-viewer { padding: 12px 6px; }
    #sv2SignModal .sv2-canvas-wrap { max-width: 100%; }
}

/* Signature pad / picker popup — fit small screens */
@media (max-width: 768px) {
    .sv2-picker { padding: 10px; }
    .sv2-picker-content { width: 100%; max-width: 100%; max-height: 92vh; }
    .sv2-picker-footer { flex-direction: column-reverse; }
    .sv2-picker-footer .sv2-btn { width: 100%; justify-content: center; }
}
