<x-layouts.app :title="__('Show document')">
    <div class="grid grid-cols-2 gap-x-0 h-screen bg-gray-100">
        <!-- Zona izquierda - Visualizador de documentos -->
        <div class="bg-gray-500 relative">
            <div id="outerContainer">
                <div id="sidebarContainer">
                    <div id="toolbarSidebar" class="toolbarHorizontalGroup">
                        <div id="toolbarSidebarLeft">
                            <div id="sidebarViewButtons" class="toolbarHorizontalGroup toggled" role="radiogroup">
                                <button id="viewThumbnail" class="toolbarButton toggled" type="button" tabindex="0" data-l10n-id="pdfjs-thumbs-button" role="radio" aria-checked="true" aria-controls="thumbnailView">
                                    <span data-l10n-id="pdfjs-thumbs-button-label"></span>
                                </button>
                                <button id="viewOutline" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-document-outline-button" role="radio" aria-checked="false" aria-controls="outlineView">
                                    <span data-l10n-id="pdfjs-document-outline-button-label"></span>
                                </button>
                                <button id="viewAttachments" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-attachments-button" role="radio" aria-checked="false" aria-controls="attachmentsView">
                                    <span data-l10n-id="pdfjs-attachments-button-label"></span>
                                </button>2
                                <button id="viewLayers" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-layers-button" role="radio" aria-checked="false" aria-controls="layersView">
                                    <span data-l10n-id="pdfjs-layers-button-label"></span>
                                </button>
                            </div>
                        </div>

                        <div id="toolbarSidebarRight">
                            <div id="outlineOptionsContainer" class="toolbarHorizontalGroup">
                                <div class="verticalToolbarSeparator"></div>

                                <button id="currentOutlineItem" class="toolbarButton" type="button" disabled="disabled" tabindex="0" data-l10n-id="pdfjs-current-outline-item-button">
                                    <span data-l10n-id="pdfjs-current-outline-item-button-label"></span>
                                </button>
                            </div>
                        </div>
                    </div>
                    <div id="sidebarContent">
                        <div id="thumbnailView">
                        </div>
                        <div id="outlineView" class="hidden">
                        </div>
                        <div id="attachmentsView" class="hidden">
                        </div>
                        <div id="layersView" class="hidden">
                        </div>
                    </div>
                    <div id="sidebarResizer"></div>
                </div>  <!-- sidebarContainer -->

                

                <div id="mainContainer">
                    <div class="toolbar">
                        <div id="toolbarContainer">
                            <div id="toolbarViewer" class="toolbarHorizontalGroup">
                                <div id="toolbarViewerLeft" class="toolbarHorizontalGroup">
                                    <button id="sidebarToggleButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-toggle-sidebar-button" aria-expanded="false" aria-haspopup="true" aria-controls="sidebarContainer">
                                        <span data-l10n-id="pdfjs-toggle-sidebar-button-label"></span>
                                    </button>
                                    <div class="toolbarButtonSpacer"></div>
                                    <div class="toolbarButtonWithContainer">
                                        <button id="viewFindButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-findbar-button" aria-expanded="false" aria-controls="findbar">
                                            <span data-l10n-id="pdfjs-findbar-button-label"></span>
                                        </button>
                                        <div class="hidden doorHanger toolbarHorizontalGroup" id="findbar">
                                            <div id="findInputContainer" class="toolbarHorizontalGroup">
                                                <span class="loadingInput end toolbarHorizontalGroup">
                                                    <input id="findInput" class="toolbarField" tabindex="0" data-l10n-id="pdfjs-find-input" aria-invalid="false">
                                                </span>
                                                <div class="toolbarHorizontalGroup">
                                                    <button id="findPreviousButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-find-previous-button">
                                                    <span data-l10n-id="pdfjs-find-previous-button-label"></span>
                                                    </button>
                                                    <div class="splitToolbarButtonSeparator"></div>
                                                    <button id="findNextButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-find-next-button">
                                                    <span data-l10n-id="pdfjs-find-next-button-label"></span>
                                                    </button>
                                                </div>
                                            </div>

                                            <div id="findbarOptionsOneContainer" class="toolbarHorizontalGroup">
                                            <div class="toggleButton toolbarLabel">
                                                <input type="checkbox" id="findHighlightAll" tabindex="0" />
                                                <label for="findHighlightAll" data-l10n-id="pdfjs-find-highlight-checkbox"></label>
                                            </div>
                                            <div class="toggleButton toolbarLabel">
                                                <input type="checkbox" id="findMatchCase" tabindex="0" />
                                                <label for="findMatchCase" data-l10n-id="pdfjs-find-match-case-checkbox-label"></label>
                                            </div>
                                            </div>
                                            <div id="findbarOptionsTwoContainer" class="toolbarHorizontalGroup">
                                            <div class="toggleButton toolbarLabel">
                                                <input type="checkbox" id="findMatchDiacritics" tabindex="0" />
                                                <label for="findMatchDiacritics" data-l10n-id="pdfjs-find-match-diacritics-checkbox-label"></label>
                                            </div>
                                            <div class="toggleButton toolbarLabel">
                                                <input type="checkbox" id="findEntireWord" tabindex="0" />
                                                <label for="findEntireWord" data-l10n-id="pdfjs-find-entire-word-checkbox-label"></label>
                                            </div>
                                            </div>

                                            <div id="findbarMessageContainer" class="toolbarHorizontalGroup" aria-live="polite">
                                            <span id="findResultsCount" class="toolbarLabel"></span>
                                            <span id="findMsg" class="toolbarLabel"></span>
                                            </div>
                                        </div>  <!-- findbar -->
                                    </div>
                                    <div class="toolbarHorizontalGroup hiddenSmallView">
                                        <button class="toolbarButton" type="button" id="previous" tabindex="0" data-l10n-id="pdfjs-previous-button">
                                            <span data-l10n-id="pdfjs-previous-button-label"></span>
                                        </button>
                                        <div class="splitToolbarButtonSeparator"></div>
                                        <button class="toolbarButton" type="button" id="next" tabindex="0" data-l10n-id="pdfjs-next-button">
                                            <span data-l10n-id="pdfjs-next-button-label"></span>
                                        </button>
                                    </div>
                                    <div class="toolbarHorizontalGroup">
                                        <span class="loadingInput start toolbarHorizontalGroup">
                                            <input type="number" id="pageNumber" class="toolbarField" value="1" min="1" tabindex="0" data-l10n-id="pdfjs-page-input" autocomplete="off">
                                        </span>
                                        <span id="numPages" class="toolbarLabel"></span>
                                    </div>
                                </div>
                                <div id="toolbarViewerMiddle" class="toolbarHorizontalGroup">
                                    <div class="toolbarHorizontalGroup">
                                        <button id="zoomOutButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-zoom-out-button">
                                            <span data-l10n-id="pdfjs-zoom-out-button-label"></span>
                                        </button>
                                        <div class="splitToolbarButtonSeparator"></div>
                                        <button id="zoomInButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-zoom-in-button">
                                            <span data-l10n-id="pdfjs-zoom-in-button-label"></span>
                                        </button>
                                    </div>
                                    <span id="scaleSelectContainer" class="dropdownToolbarButton">
                                        <select id="scaleSelect" tabindex="0" data-l10n-id="pdfjs-zoom-select">
                                            <option id="pageAutoOption" value="auto" selected="selected" data-l10n-id="pdfjs-page-scale-auto"></option>
                                            <option id="pageActualOption" value="page-actual" data-l10n-id="pdfjs-page-scale-actual"></option>
                                            <option id="pageFitOption" value="page-fit" data-l10n-id="pdfjs-page-scale-fit"></option>
                                            <option id="pageWidthOption" value="page-width" data-l10n-id="pdfjs-page-scale-width"></option>
                                            <option id="customScaleOption" value="custom" disabled="disabled" hidden="true" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 0 }'></option>
                                            <option value="0.5" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 50 }'></option>
                                            <option value="0.75" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 75 }'></option>
                                            <option value="1" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 100 }'></option>
                                            <option value="1.25" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 125 }'></option>
                                            <option value="1.5" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 150 }'></option>
                                            <option value="2" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 200 }'></option>
                                            <option value="3" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 300 }'></option>
                                            <option value="4" data-l10n-id="pdfjs-page-scale-percent" data-l10n-args='{ "scale": 400 }'></option>
                                        </select>
                                    </span>
                                </div>
                                <div id="toolbarViewerRight" class="toolbarHorizontalGroup">
                                    <div id="editorModeButtons" class="toolbarHorizontalGroup" role="radiogroup">
                                    <div id="editorSignature" class="toolbarButtonWithContainer" hidden="true">
                                        <button id="editorSignatureButton" class="toolbarButton" type="button" tabindex="0" disabled="disabled" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorSignatureParamsToolbar" data-l10n-id="pdfjs-editor-signature-button">
                                        <span data-l10n-id="pdfjs-editor-signature-button-label"></span>
                                        </button>
                                        <div class="editorParamsToolbar hidden doorHangerRight menu" id="editorSignatureParamsToolbar">
                                        <div id="addSignatureDoorHanger" class="menuContainer" role="region" data-l10n-id="pdfjs-editor-add-signature-container">
                                            <button id="editorSignatureAddSignature" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-editor-signature-add-signature-button">
                                            <span data-l10n-id="pdfjs-editor-signature-add-signature-button-label" class="editorParamsLabel"></span>
                                            </button>
                                        </div>
                                        </div>
                                    </div>
                                    <div id="editorHighlight" class="toolbarButtonWithContainer">
                                        <button id="editorHighlightButton" class="toolbarButton" type="button" disabled="disabled" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorHighlightParamsToolbar" tabindex="0" data-l10n-id="pdfjs-editor-highlight-button">
                                        <span data-l10n-id="pdfjs-editor-highlight-button-label"></span>
                                        </button>
                                        <div class="editorParamsToolbar hidden doorHangerRight" id="editorHighlightParamsToolbar">
                                        <div id="highlightParamsToolbarContainer" class="editorParamsToolbarContainer">
                                            <div id="editorHighlightColorPicker" class="colorPicker">
                                            <span id="highlightColorPickerLabel" class="editorParamsLabel" data-l10n-id="pdfjs-editor-highlight-colorpicker-label"></span>
                                            </div>
                                            <div id="editorHighlightThickness">
                                            <label for="editorFreeHighlightThickness" class="editorParamsLabel" data-l10n-id="pdfjs-editor-free-highlight-thickness-input"></label>
                                            <div class="thicknessPicker">
                                                <input type="range" id="editorFreeHighlightThickness" class="editorParamsSlider" data-l10n-id="pdfjs-editor-free-highlight-thickness-title" value="12" min="8" max="24" step="1" tabindex="0">
                                            </div>
                                            </div>
                                            <div id="editorHighlightVisibility">
                                            <div class="divider"></div>
                                            <div class="toggler">
                                                <label for="editorHighlightShowAll" class="editorParamsLabel" data-l10n-id="pdfjs-editor-highlight-show-all-button-label"></label>
                                                <button id="editorHighlightShowAll" class="toggle-button" type="button" data-l10n-id="pdfjs-editor-highlight-show-all-button" aria-pressed="true" tabindex="0"></button>
                                            </div>
                                            </div>
                                        </div>
                                        </div>
                                    </div>
                                    <div id="editorFreeText" class="toolbarButtonWithContainer">
                                        <button id="editorFreeTextButton" class="toolbarButton" type="button" disabled="disabled" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorFreeTextParamsToolbar" tabindex="0" data-l10n-id="pdfjs-editor-free-text-button">
                                        <span data-l10n-id="pdfjs-editor-free-text-button-label"></span>
                                        </button>
                                        <div class="editorParamsToolbar hidden doorHangerRight" id="editorFreeTextParamsToolbar">
                                        <div class="editorParamsToolbarContainer">
                                            <div class="editorParamsSetter">
                                            <label for="editorFreeTextColor" class="editorParamsLabel" data-l10n-id="pdfjs-editor-free-text-color-input"></label>
                                            <input type="color" id="editorFreeTextColor" class="editorParamsColor" tabindex="0">
                                            </div>
                                            <div class="editorParamsSetter">
                                            <label for="editorFreeTextFontSize" class="editorParamsLabel" data-l10n-id="pdfjs-editor-free-text-size-input"></label>
                                            <input type="range" id="editorFreeTextFontSize" class="editorParamsSlider" value="10" min="5" max="100" step="1" tabindex="0">
                                            </div>
                                        </div>
                                        </div>
                                    </div>
                                    <div id="editorInk" class="toolbarButtonWithContainer">
                                        <button id="editorInkButton" class="toolbarButton" type="button" disabled="disabled" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorInkParamsToolbar" tabindex="0" data-l10n-id="pdfjs-editor-ink-button">
                                        <span data-l10n-id="pdfjs-editor-ink-button-label"></span>
                                        </button>
                                        <div class="editorParamsToolbar hidden doorHangerRight" id="editorInkParamsToolbar">
                                        <div class="editorParamsToolbarContainer">
                                            <div class="editorParamsSetter">
                                            <label for="editorInkColor" class="editorParamsLabel" data-l10n-id="pdfjs-editor-ink-color-input"></label>
                                            <input type="color" id="editorInkColor" class="editorParamsColor" tabindex="0">
                                            </div>
                                            <div class="editorParamsSetter">
                                            <label for="editorInkThickness" class="editorParamsLabel" data-l10n-id="pdfjs-editor-ink-thickness-input"></label>
                                            <input type="range" id="editorInkThickness" class="editorParamsSlider" value="1" min="1" max="20" step="1" tabindex="0">
                                            </div>
                                            <div class="editorParamsSetter">
                                            <label for="editorInkOpacity" class="editorParamsLabel" data-l10n-id="pdfjs-editor-ink-opacity-input"></label>
                                            <input type="range" id="editorInkOpacity" class="editorParamsSlider" value="1" min="0.05" max="1" step="0.05" tabindex="0">
                                            </div>
                                        </div>
                                        </div>
                                    </div>
                                    <div id="editorStamp" class="toolbarButtonWithContainer">
                                        <button id="editorStampButton" class="toolbarButton" type="button" disabled="disabled" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorStampParamsToolbar" tabindex="0" data-l10n-id="pdfjs-editor-stamp-button">
                                        <span data-l10n-id="pdfjs-editor-stamp-button-label"></span>
                                        </button>
                                        <div class="editorParamsToolbar hidden doorHangerRight menu" id="editorStampParamsToolbar">
                                        <div class="menuContainer">
                                            <button id="editorStampAddImage" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-editor-stamp-add-image-button">
                                            <span class="editorParamsLabel" data-l10n-id="pdfjs-editor-stamp-add-image-button-label"></span>
                                            </button>
                                        </div>
                                        </div>
                                    </div>
                                    </div>

                                    <div id="editorModeSeparator" class="verticalToolbarSeparator"></div>

                                    <div class="toolbarHorizontalGroup hiddenMediumView">
                                    <button id="printButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-print-button">
                                        <span data-l10n-id="pdfjs-print-button-label"></span>
                                    </button>

                                    <button id="downloadButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-save-button">
                                        <span data-l10n-id="pdfjs-save-button-label"></span>
                                    </button>
                                    </div>

                                    <div class="verticalToolbarSeparator hiddenMediumView"></div>

                                    <div id="secondaryToolbarToggle" class="toolbarButtonWithContainer">
                                    <button id="secondaryToolbarToggleButton" class="toolbarButton" type="button" tabindex="0" data-l10n-id="pdfjs-tools-button" aria-expanded="false" aria-haspopup="true" aria-controls="secondaryToolbar">
                                        <span data-l10n-id="pdfjs-tools-button-label"></span>
                                    </button>
                                    <div id="secondaryToolbar" class="hidden doorHangerRight menu">
                                        <div id="secondaryToolbarButtonContainer" class="menuContainer">
                                        <button id="secondaryOpenFile" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-open-file-button">
                                            <span data-l10n-id="pdfjs-open-file-button-label"></span>
                                        </button>

                                        <div class="visibleMediumView">
                                            <button id="secondaryPrint" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-print-button">
                                            <span data-l10n-id="pdfjs-print-button-label"></span>
                                            </button>

                                            <button id="secondaryDownload" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-save-button">
                                            <span data-l10n-id="pdfjs-save-button-label"></span>
                                            </button>

                                        </div>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <button id="presentationMode" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-presentation-mode-button">
                                            <span data-l10n-id="pdfjs-presentation-mode-button-label"></span>
                                        </button>

                                        <a href="#" id="viewBookmark" class="toolbarButton labeled" tabindex="0" data-l10n-id="pdfjs-bookmark-button">
                                            <span data-l10n-id="pdfjs-bookmark-button-label"></span>
                                        </a>

                                        <div id="viewBookmarkSeparator" class="horizontalToolbarSeparator"></div>

                                        <button id="firstPage" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-first-page-button">
                                            <span data-l10n-id="pdfjs-first-page-button-label"></span>
                                        </button>
                                        <button id="lastPage" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-last-page-button">
                                            <span data-l10n-id="pdfjs-last-page-button-label"></span>
                                        </button>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <button id="pageRotateCw" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-page-rotate-cw-button">
                                            <span data-l10n-id="pdfjs-page-rotate-cw-button-label"></span>
                                        </button>
                                        <button id="pageRotateCcw" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-page-rotate-ccw-button">
                                            <span data-l10n-id="pdfjs-page-rotate-ccw-button-label"></span>
                                        </button>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <div id="cursorToolButtons" role="radiogroup">
                                            <button id="cursorSelectTool" class="toolbarButton labeled toggled" type="button" tabindex="0" data-l10n-id="pdfjs-cursor-text-select-tool-button" role="radio" aria-checked="true">
                                            <span data-l10n-id="pdfjs-cursor-text-select-tool-button-label"></span>
                                            </button>
                                            <button id="cursorHandTool" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-cursor-hand-tool-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-cursor-hand-tool-button-label"></span>
                                            </button>
                                        </div>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <div id="scrollModeButtons" role="radiogroup">
                                            <button id="scrollPage" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-scroll-page-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-scroll-page-button-label"></span>
                                            </button>
                                            <button id="scrollVertical" class="toolbarButton labeled toggled" type="button" tabindex="0" data-l10n-id="pdfjs-scroll-vertical-button" role="radio" aria-checked="true">
                                            <span data-l10n-id="pdfjs-scroll-vertical-button-label"></span>
                                            </button>
                                            <button id="scrollHorizontal" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-scroll-horizontal-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-scroll-horizontal-button-label"></span>
                                            </button>
                                            <button id="scrollWrapped" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-scroll-wrapped-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-scroll-wrapped-button-label"></span>
                                            </button>
                                        </div>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <div id="spreadModeButtons" role="radiogroup">
                                            <button id="spreadNone" class="toolbarButton labeled toggled" type="button" tabindex="0" data-l10n-id="pdfjs-spread-none-button" role="radio" aria-checked="true">
                                            <span data-l10n-id="pdfjs-spread-none-button-label"></span>
                                            </button>
                                            <button id="spreadOdd" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-spread-odd-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-spread-odd-button-label"></span>
                                            </button>
                                            <button id="spreadEven" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-spread-even-button" role="radio" aria-checked="false">
                                            <span data-l10n-id="pdfjs-spread-even-button-label"></span>
                                            </button>
                                        </div>

                                        <div id="imageAltTextSettingsSeparator" class="horizontalToolbarSeparator hidden"></div>
                                        <button id="imageAltTextSettings" type="button" class="toolbarButton labeled hidden" tabindex="0" data-l10n-id="pdfjs-image-alt-text-settings-button" aria-controls="altTextSettingsDialog">
                                            <span data-l10n-id="pdfjs-image-alt-text-settings-button-label"></span>
                                        </button>

                                        <div class="horizontalToolbarSeparator"></div>

                                        <button id="documentProperties" class="toolbarButton labeled" type="button" tabindex="0" data-l10n-id="pdfjs-document-properties-button" aria-controls="documentPropertiesDialog">
                                            <span data-l10n-id="pdfjs-document-properties-button-label"></span>
                                        </button>
                                        </div>
                                    </div>  <!-- secondaryToolbar -->
                                    </div>
                                </div>
                            </div>
                            <div id="loadingBar">
                            <div class="progress">
                                <div class="glimmer">
                                </div>
                            </div>
                            </div>
                        </div>
                    </div>                    
                    <div id="viewerContainer" tabindex="0">
                        <div id="viewer" class="pdfViewer"></div>
                    </div> 

                </div> <!-- mainContainer -->

                <div id="dialogContainer">
                    <dialog id="passwordDialog">
                    <div class="row">
                        <label for="password" id="passwordText" data-l10n-id="pdfjs-password-label"></label>
                    </div>
                    <div class="row">
                        <input type="password" id="password" class="toolbarField">
                    </div>
                    <div class="buttonRow">
                        <button id="passwordCancel" class="dialogButton" type="button"><span data-l10n-id="pdfjs-password-cancel-button"></span></button>
                        <button id="passwordSubmit" class="dialogButton" type="button"><span data-l10n-id="pdfjs-password-ok-button"></span></button>
                    </div>
                    </dialog>
                    <dialog id="documentPropertiesDialog">
                    <div class="row">
                        <span id="fileNameLabel" data-l10n-id="pdfjs-document-properties-file-name"></span>
                        <p id="fileNameField" aria-labelledby="fileNameLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="fileSizeLabel" data-l10n-id="pdfjs-document-properties-file-size"></span>
                        <p id="fileSizeField" aria-labelledby="fileSizeLabel">-</p>
                    </div>
                    <div class="separator"></div>
                    <div class="row">
                        <span id="titleLabel" data-l10n-id="pdfjs-document-properties-title"></span>
                        <p id="titleField" aria-labelledby="titleLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="authorLabel" data-l10n-id="pdfjs-document-properties-author"></span>
                        <p id="authorField" aria-labelledby="authorLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="subjectLabel" data-l10n-id="pdfjs-document-properties-subject"></span>
                        <p id="subjectField" aria-labelledby="subjectLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="keywordsLabel" data-l10n-id="pdfjs-document-properties-keywords"></span>
                        <p id="keywordsField" aria-labelledby="keywordsLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="creationDateLabel" data-l10n-id="pdfjs-document-properties-creation-date"></span>
                        <p id="creationDateField" aria-labelledby="creationDateLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="modificationDateLabel" data-l10n-id="pdfjs-document-properties-modification-date"></span>
                        <p id="modificationDateField" aria-labelledby="modificationDateLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="creatorLabel" data-l10n-id="pdfjs-document-properties-creator"></span>
                        <p id="creatorField" aria-labelledby="creatorLabel">-</p>
                    </div>
                    <div class="separator"></div>
                    <div class="row">
                        <span id="producerLabel" data-l10n-id="pdfjs-document-properties-producer"></span>
                        <p id="producerField" aria-labelledby="producerLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="versionLabel" data-l10n-id="pdfjs-document-properties-version"></span>
                        <p id="versionField" aria-labelledby="versionLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="pageCountLabel" data-l10n-id="pdfjs-document-properties-page-count"></span>
                        <p id="pageCountField" aria-labelledby="pageCountLabel">-</p>
                    </div>
                    <div class="row">
                        <span id="pageSizeLabel" data-l10n-id="pdfjs-document-properties-page-size"></span>
                        <p id="pageSizeField" aria-labelledby="pageSizeLabel">-</p>
                    </div>
                    <div class="separator"></div>
                    <div class="row">
                        <span id="linearizedLabel" data-l10n-id="pdfjs-document-properties-linearized"></span>
                        <p id="linearizedField" aria-labelledby="linearizedLabel">-</p>
                    </div>
                    <div class="buttonRow">
                        <button id="documentPropertiesClose" class="dialogButton" type="button"><span data-l10n-id="pdfjs-document-properties-close-button"></span></button>
                    </div>
                    </dialog>
                    <dialog class="dialog altText" id="altTextDialog" aria-labelledby="dialogLabel" aria-describedby="dialogDescription">
                    <div id="altTextContainer" class="mainContainer">
                        <div id="overallDescription">
                        <span id="dialogLabel" data-l10n-id="pdfjs-editor-alt-text-dialog-label" class="title"></span>
                        <span id="dialogDescription" data-l10n-id="pdfjs-editor-alt-text-dialog-description"></span>
                        </div>
                        <div id="addDescription">
                        <div class="radio">
                            <div class="radioButton">
                            <input type="radio" id="descriptionButton" name="altTextOption" tabindex="0" aria-describedby="descriptionAreaLabel" checked>
                            <label for="descriptionButton" data-l10n-id="pdfjs-editor-alt-text-add-description-label"></label>
                            </div>
                            <div class="radioLabel">
                            <span id="descriptionAreaLabel" data-l10n-id="pdfjs-editor-alt-text-add-description-description"></span>
                            </div>
                        </div>
                        <div class="descriptionArea">
                            <textarea id="descriptionTextarea" aria-labelledby="descriptionAreaLabel" data-l10n-id="pdfjs-editor-alt-text-textarea" tabindex="0"></textarea>
                        </div>
                        </div>
                        <div id="markAsDecorative">
                        <div class="radio">
                            <div class="radioButton">
                            <input type="radio" id="decorativeButton" name="altTextOption" aria-describedby="decorativeLabel">
                            <label for="decorativeButton" data-l10n-id="pdfjs-editor-alt-text-mark-decorative-label"></label>
                            </div>
                            <div class="radioLabel">
                            <span id="decorativeLabel" data-l10n-id="pdfjs-editor-alt-text-mark-decorative-description"></span>
                            </div>
                        </div>
                        </div>
                        <div id="buttons">
                        <button id="altTextCancel" class="secondaryButton" type="button" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-cancel-button"></span></button>
                        <button id="altTextSave" class="primaryButton" type="button" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-save-button"></span></button>
                        </div>
                    </div>
                    </dialog>
                    <dialog class="dialog newAltText" id="newAltTextDialog" aria-labelledby="newAltTextTitle" aria-describedby="newAltTextDescription" tabindex="0">
                    <div id="newAltTextContainer" class="mainContainer">
                        <div class="title">
                        <span id="newAltTextTitle" data-l10n-id="pdfjs-editor-new-alt-text-dialog-edit-label" role="sectionhead" tabindex="0"></span>
                        </div>
                        <div id="mainContent">
                        <div id="descriptionAndSettings">
                            <div id="descriptionInstruction">
                            <div id="newAltTextDescriptionContainer">
                                <div class="altTextSpinner" role="status" aria-live="polite"></div>
                                <textarea id="newAltTextDescriptionTextarea" aria-labelledby="descriptionAreaLabel" data-l10n-id="pdfjs-editor-new-alt-text-textarea" tabindex="0"></textarea>
                            </div>
                            <span id="newAltTextDescription" role="note" data-l10n-id="pdfjs-editor-new-alt-text-description"></span>
                            <div id="newAltTextDisclaimer" role="note"><div><span data-l10n-id="pdfjs-editor-new-alt-text-disclaimer1"></span> <a href="https://support.mozilla.org/en-US/kb/pdf-alt-text" target="_blank" rel="noopener noreferrer" id="newAltTextLearnMore" data-l10n-id="pdfjs-editor-new-alt-text-disclaimer-learn-more-url" tabindex="0"></a></div></div>
                            </div>
                            <div id="newAltTextCreateAutomatically" class="toggler">
                            <button id="newAltTextCreateAutomaticallyButton" class="toggle-button" type="button" aria-pressed="true" tabindex="0"></button>
                            <label for="newAltTextCreateAutomaticallyButton" class="togglerLabel" data-l10n-id="pdfjs-editor-new-alt-text-create-automatically-button-label"></label>
                            </div>
                            <div id="newAltTextDownloadModel" class="hidden">
                            <span id="newAltTextDownloadModelDescription" data-l10n-id="pdfjs-editor-new-alt-text-ai-model-downloading-progress" aria-valuemin="0" data-l10n-args='{ "totalSize": 0, "downloadedSize": 0 }'></span>
                            </div>
                        </div>
                        <div id="newAltTextImagePreview"></div>
                        </div>
                        <div id="newAltTextError" class="messageBar">
                        <div>
                            <div>
                            <span class="title" data-l10n-id="pdfjs-editor-new-alt-text-error-title"></span>
                            <span  class="description" data-l10n-id="pdfjs-editor-new-alt-text-error-description"></span>
                            </div>
                            <button id="newAltTextCloseButton" class="closeButton" type="button" tabindex="0"><span data-l10n-id="pdfjs-editor-new-alt-text-error-close-button"></span></button>
                        </div>
                        </div>
                        <div id="newAltTextButtons" class="dialogButtonsGroup">
                        <button id="newAltTextCancel" type="button" class="secondaryButton hidden" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-cancel-button"></span></button>
                        <button id="newAltTextNotNow" type="button" class="secondaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-new-alt-text-not-now-button"></span></button>
                        <button id="newAltTextSave" type="button" class="primaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-save-button"></span></button>
                        </div>
                    </div>
                    </dialog>

                    <dialog class="dialog" id="altTextSettingsDialog" aria-labelledby="altTextSettingsTitle">
                    <div id="altTextSettingsContainer" class="mainContainer">
                        <div class="title">
                        <span id="altTextSettingsTitle" data-l10n-id="pdfjs-editor-alt-text-settings-dialog-label" role="sectionhead" tabindex="0" class="title"></span>
                        </div>
                        <div id="automaticAltText">
                        <span data-l10n-id="pdfjs-editor-alt-text-settings-automatic-title"></span>
                        <div id="automaticSettings">
                            <div id="createModelSetting">
                            <div class="toggler">
                                <button id="createModelButton" type="button" class="toggle-button" aria-pressed="true" tabindex="0"></button>
                                <label for="createModelButton" class="togglerLabel" data-l10n-id="pdfjs-editor-alt-text-settings-create-model-button-label"></label>
                            </div>
                            <div id="createModelDescription" class="description">
                                <span data-l10n-id="pdfjs-editor-alt-text-settings-create-model-description"></span> <a href="https://support.mozilla.org/en-US/kb/pdf-alt-text" target="_blank" rel="noopener noreferrer" id="altTextSettingsLearnMore" data-l10n-id="pdfjs-editor-new-alt-text-disclaimer-learn-more-url" tabindex="0"></a>
                            </div>
                            </div>
                            <div id="aiModelSettings">
                            <div>
                                <span data-l10n-id="pdfjs-editor-alt-text-settings-download-model-label" data-l10n-args='{ "totalSize": 180 }'></span>
                                <div id="aiModelDescription" class="description">
                                <span data-l10n-id="pdfjs-editor-alt-text-settings-ai-model-description"></span>
                                </div>
                            </div>
                            <button id="deleteModelButton" type="button" class="secondaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-settings-delete-model-button"></span></button>
                            <button id="downloadModelButton" type="button" class="secondaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-settings-download-model-button"></span></button>
                            </div>
                        </div>
                        </div>
                        <div class="dialogSeparator"></div>
                        <div id="altTextEditor">
                        <span data-l10n-id="pdfjs-editor-alt-text-settings-editor-title"></span>
                        <div id="showAltTextEditor">
                            <div class="toggler">
                            <button id="showAltTextDialogButton" type="button" class="toggle-button" aria-pressed="true" tabindex="0"></button>
                            <label for="showAltTextDialogButton" class="togglerLabel" data-l10n-id="pdfjs-editor-alt-text-settings-show-dialog-button-label"></label>
                            </div>
                            <div id="showAltTextDialogDescription" class="description">
                            <span data-l10n-id="pdfjs-editor-alt-text-settings-show-dialog-description"></span>
                            </div>
                        </div>
                        </div>
                        <div id="buttons" class="dialogButtonsGroup">
                        <button id="altTextSettingsCloseButton" type="button" class="primaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-alt-text-settings-close-button"></span></button>
                        </div>
                    </div>
                    </dialog>

                    <dialog class="dialog signatureDialog" id="addSignatureDialog" aria-labelledby="addSignatureDialogLabel">
                    <span id="addSignatureDialogLabel" data-l10n-id="pdfjs-editor-add-signature-dialog-label"></span>
                    <div id="addSignatureContainer" class="mainContainer">
                        <div class="title">
                        <span role="sectionhead" data-l10n-id="pdfjs-editor-add-signature-dialog-title" tabindex="0"></span>
                        </div>
                        <div role="tablist" id="addSignatureOptions">
                        <button id="addSignatureTypeButton" type="button" role="tab" aria-selected="true" aria-controls="addSignatureTypeContainer" data-l10n-id="pdfjs-editor-add-signature-type-button" tabindex="0"></button>
                        <button id="addSignatureDrawButton" type="button" role="tab" aria-selected="false" aria-controls="addSignatureDrawContainer" data-l10n-id="pdfjs-editor-add-signature-draw-button" tabindex="0"></button>
                        <button id="addSignatureImageButton" type="button" role="tab" aria-selected="false" aria-controls="addSignatureImageContainer" data-l10n-id="pdfjs-editor-add-signature-image-button" tabindex="-1"></button>
                        </div>
                        <div id="addSignatureActionContainer" data-selected="type">
                        <div id="addSignatureTypeContainer" role="tabpanel" aria-labelledby="addSignatureTypeContainer">
                            <input id="addSignatureTypeInput" type="text" data-l10n-id="pdfjs-editor-add-signature-type-input" tabindex="0"></input>
                        </div>
                        <div id="addSignatureDrawContainer" role="tabpanel" aria-labelledby="addSignatureDrawButton" tabindex="-1">
                            <svg id="addSignatureDraw" xmlns="http://www.w3.org/2000/svg" aria-labelledby="addSignatureDrawPlaceholder"></svg>
                            <span id="addSignatureDrawPlaceholder" data-l10n-id="pdfjs-editor-add-signature-draw-placeholder"></span>
                            <div id="thickness">
                            <div>
                                <label for="addSignatureDrawThickness" data-l10n-id="pdfjs-editor-add-signature-draw-thickness-range-label"></label>
                                <input type="range" id="addSignatureDrawThickness" min="1" max="5" step="1" value="1" data-l10n-id="pdfjs-editor-add-signature-draw-thickness-range" data-l10n-args='{ "thickness": 1 }' tabindex="0">
                            </div>
                            </div>
                        </div>
                        <div id="addSignatureImageContainer" role="tabpanel" aria-labelledby="addSignatureImageButton" tabindex="-1">
                            <svg id="addSignatureImage" xmlns="http://www.w3.org/2000/svg" aria-labelledby="addSignatureImagePlaceholder"></svg>
                            <div id="addSignatureImagePlaceholder">
                            <span data-l10n-id="pdfjs-editor-add-signature-image-placeholder"></span>
                            <label id="addSignatureImageBrowse" for="addSignatureFilePicker" tabindex="0">
                                <a data-l10n-id="pdfjs-editor-add-signature-image-browse-link"></a>
                            </label>
                            <input id="addSignatureFilePicker" type="file"></input>
                            </div>
                        </div>
                        <div id="addSignatureControls">
                            <div id="horizontalContainer">
                            <div id="addSignatureDescriptionContainer">
                                <label for="addSignatureDescInput" data-l10n-id="pdfjs-editor-add-signature-description-label"></label>
                                <span id="addSignatureDescription" class="inputWithClearButton">
                                <input id="addSignatureDescInput" type="text" data-l10n-id="pdfjs-editor-add-signature-description-input" tabindex="0"></input>
                                <button class="clearInputButton" type="button" tabindex="0" aria-hidden="true"></button>
                                </span>
                            </div>
                            <button id="clearSignatureButton" type="button" data-l10n-id="pdfjs-editor-add-signature-clear-button" tabindex="0"><span data-l10n-id="pdfjs-editor-add-signature-clear-button-label"></span></button>
                            </div>
                            <div id="addSignatureSaveContainer">
                            <input type="checkbox" id="addSignatureSaveCheckbox" checked="true"></input>
                            <label for="addSignatureSaveCheckbox" data-l10n-id="pdfjs-editor-add-signature-save-checkbox"></label>
                            <span></span>
                            <span id="addSignatureSaveWarning" data-l10n-id="pdfjs-editor-add-signature-save-warning-message"></span>
                            </div>
                        </div>
                        <div id="addSignatureError" hidden="true" class="messageBar">
                            <div>
                            <div>
                                <span class="title" data-l10n-id="pdfjs-editor-add-signature-image-upload-error-title"></span>
                                <span class="description" data-l10n-id="pdfjs-editor-add-signature-image-upload-error-description"></span>
                            </div>
                            <button id="addSignatureErrorCloseButton" class="closeButton" type="button" tabindex="0"><span data-l10n-id="pdfjs-editor-add-signature-error-close-button"></span></button>
                            </div>
                        </div>
                        <div class="dialogButtonsGroup">
                            <button id="addSignatureCancelButton" type="button" class="secondaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-add-signature-cancel-button"></span></button>
                            <button id="addSignatureAddButton" type="button" class="primaryButton" disabled tabindex="0"><span data-l10n-id="pdfjs-editor-add-signature-add-button"></span></button>
                        </div>
                        </div>
                    </div>
                    </dialog>

                    <dialog class="dialog signatureDialog" id="editSignatureDescriptionDialog" aria-labelledby="editSignatureDescriptionTitle">
                        <div id="editSignatureDescriptionContainer" class="mainContainer">
                        <div class="title">
                            <span id="editSignatureDescriptionTitle" role="sectionhead" data-l10n-id="pdfjs-editor-edit-signature-dialog-title" tabindex="0"></span>
                        </div>
                        <div id="editSignatureDescriptionAndView">
                            <div id="editSignatureDescriptionContainer">
                            <label for="editSignatureDescInput" data-l10n-id="pdfjs-editor-add-signature-description-label"></label>
                            <span id="editSignatureDescription" class="inputWithClearButton">
                                <input id="editSignatureDescInput" type="text" data-l10n-id="pdfjs-editor-add-signature-description-input" tabindex="0"></input>
                                <button class="clearInputButton" type="button" tabindex="0" aria-hidden="true"></button>
                            </span>
                            </div>
                            <svg id="editSignatureView" xmlns="http://www.w3.org/2000/svg"></svg>
                        </div>
                        <div class="dialogButtonsGroup">
                            <button id="editSignatureCancelButton" type="button" class="secondaryButton" tabindex="0"><span data-l10n-id="pdfjs-editor-add-signature-cancel-button"></span></button>
                            <button id="editSignatureUpdateButton" type="button" class="primaryButton" disabled tabindex="0"><span data-l10n-id="pdfjs-editor-edit-signature-update-button"></span></button>
                        </div>
                        </div>
                    </dialog>

                    <dialog id="printServiceDialog" style="min-width: 200px;">
                    <div class="row">
                        <span data-l10n-id="pdfjs-print-progress-message"></span>
                    </div>
                    <div class="row">
                        <progress value="0" max="100"></progress>
                        <span data-l10n-id="pdfjs-print-progress-percent" data-l10n-args='{ "progress": 0 }' class="relative-progress">0%</span>
                    </div>
                    <div class="buttonRow">
                        <button id="printCancel" class="dialogButton" type="button"><span data-l10n-id="pdfjs-print-progress-close-button"></span></button>
                    </div>
                    </dialog>
                </div>  <!-- dialogContainer -->

                <div id="editorUndoBar" class="messageBar" role="status" aria-labelledby="editorUndoBarMessage" tabindex="-1" hidden>
                    <div>
                    <div>
                        <span id="editorUndoBarMessage" class="description"></span>
                    </div>
                    <button id="editorUndoBarUndoButton" class="undoButton" type="button" tabindex="0" data-l10n-id="pdfjs-editor-undo-bar-undo-button">
                        <span data-l10n-id="pdfjs-editor-undo-bar-undo-button-label"></span>
                    </button>
                    <button id="editorUndoBarCloseButton" class="closeButton" type="button" tabindex="0" data-l10n-id="pdfjs-editor-undo-bar-close-button">
                        <span data-l10n-id="pdfjs-editor-undo-bar-close-button-label"></span>
                    </button>
                    </div>
                </div> <!-- editorUndoBar -->

            </div> <!-- outerContainer -->
            <div id="printContainer"></div>
        </div>

        <!-- Zona derecha - Tabs de información -->
        <div x-data="{
            activeTab: 'properties',
            // Estado para el treeview de versiones y revisiones
            openVersion: null,
            openRevision: {},
            
            toggleVersion(versionNumber) {
                this.openVersion = this.openVersion === versionNumber ? null : versionNumber;
            },
            
            toggleRevision(versionNumber, revisionNumber) {
                const key = `v${versionNumber}r${revisionNumber}`;
                this.openRevision[key] = !this.openRevision[key];
                // Para asegurar la reactividad
                this.openRevision = {...this.openRevision};
            },

            // Función para cargar PDF en el visor
            loadPdfInViewer(pdfUrl) {
                if (pdfUrl) {
                    // Usar PDFViewerApplication para cargar el nuevo PDF
                    PDFViewerApplication.open(pdfUrl).then(() => {
                        console.log('PDF cargado en el visor:', pdfUrl);
                        
                        // Opcional: Mostrar un mensaje de éxito
                        this.showNotification('PDF cargado en el visor', 'success');
                    }).catch(error => {
                        console.error('Error al cargar el PDF:', error);
                        this.showNotification('Error al cargar el PDF', 'error');
                    });
                }
            },

            // Función auxiliar para mostrar notificaciones
            showNotification(message, type = 'info') {
                // Puedes implementar un sistema de notificaciones toast aquí
                // Por ahora usamos alert para simplificar
                alert(message);
            }
        }" class="flex flex-col bg-white">
            <!-- Tabs de navegación -->
            <div class="border-b border-gray-200">
                <nav class="flex space-x-4 px-4 pt-2">
                    <button @click="activeTab = 'properties'" 
                        :class="activeTab === 'properties' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'" 
                        class="py-1 px-1 border-b-2 font-medium">
                        Propiedades
                    </button>
                    <button @click="activeTab = 'security'" 
                        :class="activeTab === 'security' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'" 
                        class="py-1 px-1 border-b-2 font-medium">
                        Seguridad
                    </button>
                    <button @click="activeTab = 'comments'" 
                        :class="activeTab === 'comments'  ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'" 
                        class="py-1 px-1 border-b-2 font-medium">
                        Comentarios
                    </button>
                    <button @click="activeTab = 'history'" 
                        :class="activeTab === 'history' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'" 
                        class="py-1 px-1 border-b-2 font-medium">
                        Historial
                    </button>
                    <button @click="activeTab = 'relations'" 
                        :class="activeTab === 'relations' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'" 
                        class="py-1 px-1 border-b-2 font-medium">
                        Relaciones
                    </button>
                </nav>
            </div>

            <!-- Contenido de los tabs -->
            <div class="flex-1 overflow-y-auto p-4 space-y-6">
                <!-- Propiedades -->
                <div x-show="activeTab === 'properties'">
                    <div class="space-y-4">
                        <x-property-item label="Nombre" :value="$document->name" />
                        <x-property-item label="Tipo" :value="$document->type" />
                        <x-property-item label="Tamaño" :value="$document->size_for_humans" />
                        <x-property-item label="Creado por" :value="Storage::url($document->file_path)" />
                        <x-property-item label="Fecha creación" :value="$document->created_at->format('d/m/Y H:i')" />
                        <x-property-item label="Última modificación" :value="$document->updated_at->format('d/m/Y H:i')" />
                    </div>
                </div>

                <!-- Seguridad -->
                <div x-show="activeTab === 'security'" x-cloak>
                    Implementar
                </div>

                <!-- Comentarios -->
                <div x-show="activeTab === 'comments'" x-cloak>
                    Implementar 
                </div>

                <!-- Historial -->
                <div x-show="activeTab === 'history'" x-cloak>
                    <div class="space-y-2">
                        @php
                            // Agrupar las versiones por número de versión
                            $groupedVersions = $document->versions->groupBy('version');
                        @endphp
                        
                        @foreach($groupedVersions as $versionNumber => $versions)
                            <div class="border rounded-lg">
                                <!-- Cabecera de la Versión (Rama principal) -->
                                <div class="flex items-center justify-between p-4 bg-gray-50 cursor-pointer"
                                    @click="toggleVersion({{ $versionNumber }})">
                                    <div class="flex items-center space-x-3">
                                        <svg :class="{'rotate-90': openVersion === {{ $versionNumber }}}"
                                            class="w-4 h-4 transition-transform duration-200"
                                            fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                                        </svg>
                                        <div class="flex items-center space-x-2">
                                            <svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
                                            </svg>
                                            <span class="font-medium text-gray-800">
                                                Versión {{ $versionNumber }}
                                            </span>
                                        </div>
                                        <span class="text-sm text-gray-500 bg-gray-200 px-2 py-1 rounded-full">
                                            {{ $versions->count() }} revisión{{ $versions->count() > 1 ? 'es' : '' }}
                                        </span>
                                    </div>
                                    <div class="flex items-center space-x-4">
                                        <span class="text-sm text-gray-500">
                                            {{ $versions->sortBy('created_at')->first()->created_at_formatted }}
                                        </span>
                                    </div>
                                </div>

                                <!-- Contenido de la Versión - Revisiones como ramas hijas -->
                                <div x-show="openVersion === {{ $versionNumber }}" class="border-t bg-white">
                                    <div class="space-y-0">
                                        @foreach($versions->sortByDesc('review') as $revisionIndex => $revision)
                                            <div class="border-b last:border-b-0">
                                                <!-- Cabecera de la Revisión (Rama hija) -->
                                                <div class="flex items-center justify-between p-4 pl-8 cursor-pointer hover:bg-gray-50"
                                                    @click="toggleRevision({{ $versionNumber }}, {{ $revision->review }})">
                                                    <div class="flex items-center space-x-3">
                                                        <svg :class="{'rotate-90': openRevision['v{{ $versionNumber }}r{{ $revision->review }}']}"
                                                            class="w-4 h-4 transition-transform duration-200"
                                                            fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                                                        </svg>
                                                        <div class="flex items-center space-x-2">
                                                            <svg class="w-4 h-4 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                                                            </svg>
                                                            <span class="font-medium text-gray-700">
                                                                Revisión {{ $revision->review }}
                                                            </span>
                                                            @if($revision->review == 0)
                                                                <span class="px-2 py-1 text-xs bg-blue-100 text-blue-800 rounded-full">Original</span>
                                                            @endif
                                                        </div>
                                                    </div>
                                                    <div class="flex items-center space-x-4">
                                                        <button @click.stop="loadPdfInViewer('{{ $revision->file_url }}')" 
                                                                class="inline-flex items-center px-3 py-1 text-sm bg-green-600 text-white rounded hover:bg-green-700"
                                                                title="Cargar en visor PDF">
                                                            <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                                                            </svg>
                                                            Cargar en Visor
                                                        </button>
                                                        <span class="text-sm text-gray-500">{{ $revision->created_at_formatted }}</span>
                                                        <span class="text-sm text-gray-400">{{ $revision->file_size_formatted }}</span>
                                                    </div>
                                                </div>

                                                <!-- Detalles de la Revisión (Contenido expandible) -->
                                                <div x-show="openRevision['v{{ $versionNumber }}r{{ $revision->review }}']" 
                                                    class="bg-gray-50 border-t">
                                                    <div class="p-4 pl-12 space-y-4">
                                                        <!-- Información básica -->
                                                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                                            <x-property-item label="ID" :value="$revision->id" />
                                                            <x-property-item label="Document ID" :value="$revision->document_id" />
                                                            <x-property-item label="Usuario" :value="$revision->user->name ?? 'Usuario no disponible'" />
                                                        </div>

                                                        <!-- Archivo -->
                                                        <div>
                                                            <div class="mb-2">
                                                                <span class="block text-sm font-medium text-gray-700">Archivo</span>
                                                                <div class="mt-1 flex items-center space-x-2">
                                                                    <x-property-item label="Ruta" :value="$revision->file_path" />
                                                                    <button @click="loadPdfInViewer('{{ $revision->file_url }}')" 
                                                                            class="inline-flex items-center px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700">
                                                                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                                                                        </svg>
                                                                        Cargar en Visor
                                                                    </button>
                                                                    <a href="{{ $revision->file_url }}" target="_blank" 
                                                                    class="inline-flex items-center px-3 py-1 text-sm bg-gray-600 text-white rounded hover:bg-gray-700">
                                                                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
                                                                        </svg>
                                                                        Descargar
                                                                    </a>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <!-- Cambios -->
                                                        <div>
                                                            <span class="block text-sm font-medium text-gray-700 mb-2">Cambios realizados</span>
                                                            @if(!empty($revision->changes) && count($revision->changes) > 0)
                                                                <div class="bg-white rounded border p-3">
                                                                    <ul class="list-disc list-inside text-sm text-gray-600 space-y-1">
                                                                        @foreach($revision->changes as $change)
                                                                            <li class="hover:text-gray-800">{{ $change }}</li>
                                                                        @endforeach
                                                                    </ul>
                                                                </div>
                                                            @else
                                                                <div class="bg-white rounded border p-3 text-sm text-gray-500">
                                                                    No hay cambios registrados en esta revisión
                                                                </div>
                                                            @endif
                                                        </div>

                                                        <!-- Fechas -->
                                                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-2 border-t">
                                                            <x-property-item label="Fecha de creación" :value="$revision->created_at_formatted" />
                                                            <x-property-item label="Última actualización" 
                                                                        :value="$revision->updated_at ? \Carbon\Carbon::parse($revision->updated_at)->format('d/m/Y H:i') : 'N/A'" />
                                                        </div>

                                                        <!-- Información adicional del usuario -->
                                                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-2 border-t">
                                                            <div>
                                                                <span class="block text-sm font-medium text-gray-700">Creado por</span>
                                                                <div class="flex items-center space-x-2 mt-1">
                                                                    @if(isset($revision->user->avatar))
                                                                        <img src="{{ $revision->user->avatar }}" alt="{{ $revision->user->name }}" class="w-6 h-6 rounded-full">
                                                                    @else
                                                                        <div class="w-6 h-6 bg-gray-300 rounded-full flex items-center justify-center">
                                                                            <span class="text-xs text-gray-600">{{ substr($revision->user->name ?? 'U', 0, 1) }}</span>
                                                                        </div>
                                                                    @endif
                                                                    <span class="text-sm text-gray-600">{{ $revision->user->name ?? 'Usuario no disponible' }}</span>
                                                                </div>
                                                            </div>
                                                            <div>
                                                                <span class="block text-sm font-medium text-gray-700">Email</span>
                                                                <span class="text-sm text-gray-600">{{ $revision->user->email ?? 'No disponible' }}</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        @endforeach

                        @if($groupedVersions->isEmpty())
                            <div class="text-center py-8 text-gray-500">
                                <svg class="w-12 h-12 mx-auto text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                                </svg>
                                <p class="mt-2">No hay historial de versiones disponible</p>
                            </div>
                        @endif
                    </div>
                </div>

                <!-- Relaciones -->
                <div x-show="activeTab === 'relations'" x-cloak>
                    implementar
                </div>
            </div>
        </div>
    </div>
    
    @push('scripts')
        <script>
            var ae_post_url = "{{ route('documents.update-pdf', $document) }}";
            
            window.OptionKind = window.OptionKind || { VIEWER: 0, API: 1 };

            const PDF_URL = @json(Storage::url($document->file_path));
            const SAVE_URL = "{{ route('documents.update-pdf', $document) }}";
            const CSRF_TOKEN = "{{ csrf_token() }}";

            console.log("PDF URL:", PDF_URL); 

            window.PDFViewerApplicationOptions = {
                defaultUrl: {
                    value: encodeURI(PDF_URL),  
                    kind: OptionKind.VIEWER   
                },
                cMapUrl: '/js/pdfjs-5.2.133-dist/web/cmaps/',
                cMapPacked: true
            };
        </script>

        @vite([
            'resources/js/pdfjs-5.2.133-dist/build/pdf.mjs',
            'resources/js/pdfjs-5.2.133-dist/web/viewer.mjs',
            'resources/js/pdfjs-5.2.133-dist/web/viewer.css',
            'resources/js/pdfjs-5.2.133-dist/pdfjs-annotation-extension.js'    
        ])

        <script>
            document.addEventListener('DOMContentLoaded', () => {
                PDFViewerApplication.initializedPromise.then(() => {
                    // Pasar un OBJETO con { url: TU_URL } 
                    PDFViewerApplication.open({ 
                        url: encodeURI(PDF_URL),
                        originalUrl: PDF_URL
                    }).then(() => {
                        // Una vez cargado el PDF, configurar los event listeners para guardar
                        setupSaveFunctionality();
                    }).catch(error => {
                        console.error('Error cargando PDF:', error);
                    });
                });

                function setupSaveFunctionality() {
                    // Interceptar el botón de descarga para guardar con anotaciones
                    const downloadButton = document.getElementById('downloadButton');
                    if (downloadButton) {
                        downloadButton.addEventListener('click', function(e) {
                            e.preventDefault();
                            savePdfWithAnnotations();
                        });
                    }

                    // También puedes agregar un botón personalizado para guardar
                    addCustomSaveButton();
                }

                function addCustomSaveButton() {
                    // Agregar botón de guardar personalizado en la toolbar
                    const toolbarRight = document.getElementById('toolbarViewerRight');
                    if (toolbarRight) {
                        const saveButton = document.createElement('button');
                        saveButton.id = 'saveWithAnnotations';
                        saveButton.className = 'toolbarButton';
                        saveButton.innerHTML = '<span>Guardar con anotaciones</span>';
                        saveButton.title = 'Guardar PDF con anotaciones, firmas y stamps';
                        saveButton.addEventListener('click', savePdfWithAnnotations);
                        
                        // Insertar antes del botón de descarga
                        const downloadBtn = document.getElementById('downloadButton');
                        if (downloadBtn) {
                            toolbarRight.insertBefore(saveButton, downloadBtn);
                        } else {
                            toolbarRight.appendChild(saveButton);
                        }
                    }
                }

                async function savePdfWithAnnotations() {
                    try {
                        // Mostrar indicador de carga
                        showLoading('Guardando PDF con anotaciones...');

                        // Obtener el PDF modificado con anotaciones
                        const pdfDocument = PDFViewerApplication.pdfDocument;
                        const data = await pdfDocument.saveDocument();
                        const pdfData = await data.arrayBuffer();
                        
                        // Convertir a base64
                        const base64Pdf = arrayBufferToBase64(pdfData);

                        // Enviar al servidor
                        const response = await fetch('{{ route("documents.update-pdf", $document) }}', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json',
                                'X-CSRF-TOKEN': '{{ csrf_token() }}'
                            },
                            body: JSON.stringify({
                                pdf_data: 'data:application/pdf;base64,' + base64Pdf,
                                annotations: getCurrentAnnotations(), // Si quieres guardar metadatos
                                signatures: getCurrentSignatures(),
                                stamps: getCurrentStamps()
                            })
                        });

                        const result = await response.json();
                        
                        hideLoading();
                        
                        if (result.success) {
                            showSuccess('PDF guardado correctamente con todas las anotaciones');
                        } else {
                            showError('Error al guardar: ' + result.message);
                        }

                    } catch (error) {
                        hideLoading();
                        console.error('Error saving PDF:', error);
                        showError('Error al guardar el PDF');
                    }
                }

                function arrayBufferToBase64(buffer) {
                    let binary = '';
                    const bytes = new Uint8Array(buffer);
                    const len = bytes.byteLength;
                    for (let i = 0; i < len; i++) {
                        binary += String.fromCharCode(bytes[i]);
                    }
                    return window.btoa(binary);
                }

                function getCurrentAnnotations() {
                    // Obtener anotaciones actuales del visor
                    // Esto depende de cómo la extensión almacena las anotaciones
                    if (window.pdfAnnotationExtension) {
                        return window.pdfAnnotationExtension.getAnnotations();
                    }
                    return [];
                }

                function getCurrentSignatures() {
                    // Obtener firmas actuales
                    if (window.pdfAnnotationExtension) {
                        return window.pdfAnnotationExtension.getSignatures();
                    }
                    return [];
                }

                function getCurrentStamps() {
                    // Obtener stamps actuales
                    if (window.pdfAnnotationExtension) {
                        return window.pdfAnnotationExtension.getStamps();
                    }
                    return [];
                }

                function showLoading(message) {
                    // Implementar un spinner o mensaje de carga
                    console.log('Loading:', message);
                }

                function hideLoading() {
                    // Ocultar spinner
                    console.log('Loading complete');
                }

                function showSuccess(message) {
                    alert(message); // Puedes usar un toast mejor
                }

                function showError(message) {
                    alert('Error: ' + message); // Puedes usar un toast mejor
                }
            });
        </script>
        <!-- ELIMINA EL SCRIPT versionTree() DE AQUÍ -->
    @endpush
</x-layouts.app>