/* Estilos complementarios para Firmafy */

/* Fuente manuscrita para firmas */
@import url('https://fonts.googleapis.com/css2?family=Alex+Brush&family=Caveat:wght@600&family=Dancing+Script:wght@600&family=Great+Vibes&family=Inter:wght@300;400;500;600;700&display=swap');

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.font-signature-1 {
    font-family: 'Dancing Script', cursive;
}

.font-signature-2 {
    font-family: 'Caveat', cursive;
}

.font-signature-3 {
    font-family: 'Great Vibes', cursive;
}

.font-signature-4 {
    font-family: 'Alex Brush', cursive;
}

/* Material Symbols sizing */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

.material-symbols-outlined.fill-icon {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Capa de anotaciones sobre el documento y soporte de Zoom */
.document-page-container {
    position: relative;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    background-color: white;
    user-select: none;
    flex-shrink: 0 !important;
    max-width: none !important;
    box-sizing: content-box;
}

#pdfCanvas, #docImage {
    max-width: none !important;
    display: block;
}

.annotation-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    overflow: hidden;
}

/* Elementos de anotación interactivos */
.annotation-item {
    position: absolute;
    cursor: move;
    border: 1.5px dashed transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    padding: 2px 4px;
    box-sizing: border-box;
    display: flex;
    align-items: flex-start;
    background: transparent;
    touch-action: none; /* Crucial para evitar que el navegador móvil interprete el arrastre como scroll */
    user-select: none;
    -webkit-user-select: none;
}

.annotation-item:hover {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
}

.annotation-item.selected {
    border-color: #4f46e5;
    background: rgba(79, 70, 229, 0.08);
    box-shadow: 0 0 0 1px #4f46e5;
    z-index: 50;
}

/* Controles de elementos seleccionados (borrar, rotar, mover) */
.annotation-item .item-controls {
    display: none;
    position: absolute;
    top: -28px;
    right: 0;
    background: #1e293b;
    border-radius: 6px;
    padding: 2px 4px;
    color: white;
    font-size: 11px;
    gap: 4px;
    z-index: 60;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    touch-action: manipulation;
}

.annotation-item.selected .item-controls {
    display: flex;
}

.annotation-item .delete-btn {
    cursor: pointer;
    color: #f87171;
    display: flex;
    align-items: center;
    touch-action: manipulation;
}

.annotation-item .delete-btn:hover {
    color: #ef4444;
}

/* Caja de texto editable */
.annotation-item .editable-text {
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 40px;
    display: block;
    cursor: text;
    background: transparent;
    box-sizing: border-box;
    line-height: 1.25;
}

.annotation-item .editable-text:empty:before {
    content: 'Escribe aquí...';
    color: #94a3b8;
}

/* Firma en el lienzo */
.annotation-item img.signature-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

/* Handle de redimensionamiento */
.annotation-item .resize-handle {
    display: none;
    position: absolute;
    width: 13px;
    height: 13px;
    background-color: #4f46e5;
    border: 2px solid white;
    border-radius: 50%;
    bottom: -6.5px;
    right: -6.5px;
    cursor: se-resize;
    z-index: 55;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transition: transform 0.15s ease, background-color 0.15s ease;
    touch-action: none; /* Crucial para escalado táctil en pantallas móviles */
}

/* Expansión del área táctil invisible para facilitar agarre con dedos (mínimo 36x36px) */
.annotation-item .resize-handle::after {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    cursor: inherit;
    border-radius: 50%;
}

.annotation-item.selected .resize-handle {
    display: block;
}

.annotation-item .resize-handle:hover,
.annotation-item .resize-handle:active {
    transform: scale(1.3);
    background-color: #3730a3;
}

.annotation-item .resize-handle.text-resize-handle {
    cursor: ew-resize;
    background-color: #6366f1;
}

.annotation-item .resize-handle.text-resize-handle:hover,
.annotation-item .resize-handle.text-resize-handle:active {
    background-color: #4f46e5;
}

/* Optimización para dispositivos táctiles (pantallas móviles / iPads) */
@media (pointer: coarse), (max-width: 768px) {
    .annotation-item .resize-handle {
        width: 18px;
        height: 18px;
        bottom: -9px;
        right: -9px;
        border-width: 2.5px;
    }
    
    .annotation-item .item-controls {
        top: -34px;
        padding: 4px 8px;
        font-size: 13px;
        gap: 6px;
    }
    
    .annotation-item .delete-btn {
        padding: 3px;
    }
}

/* Drag over upload styling */
.drag-over {
    border-color: #4f46e5 !important;
    background-color: #eef2ff !important;
}

/* Animaciones suaves */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.25s ease-out forwards;
}

/* Barra de herramientas fijada al hacer scroll */
.editor-toolbar-fixed {
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
}

/* Scrollbar estilizada para el contenedor del documento */
#editorScrollContainer::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#editorScrollContainer::-webkit-scrollbar-track {
    background: #f1f5f9;
}

#editorScrollContainer::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
    border: 2px solid #f1f5f9;
}

#editorScrollContainer::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Ocultar flechas arriba/abajo en inputs numéricos (Zoom, Páginas, etc.) */
input.no-spinners::-webkit-outer-spin-button,
input.no-spinners::-webkit-inner-spin-button,
#zoomInput::-webkit-outer-spin-button,
#zoomInput::-webkit-inner-spin-button,
#pageNumberInput::-webkit-outer-spin-button,
#pageNumberInput::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

input.no-spinners,
#zoomInput,
#pageNumberInput {
    -moz-appearance: textfield !important;
    appearance: textfield !important;
}

/* Scrollbar ultra-delgada y estética para la barra de herramientas del editor si hay desbordamiento en pantallas pequeñas */
.toolbar-scrollable::-webkit-scrollbar {
    height: 4px;
}
.toolbar-scrollable::-webkit-scrollbar-track {
    background: transparent;
}
.toolbar-scrollable::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.25);
    border-radius: 9999px;
}
.toolbar-scrollable::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* Patrón de cuadrícula transparente para previsualización de firmas e imágenes */
.bg-checkerboard {
    background-color: #f8fafc;
    background-image: 
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.dark .bg-checkerboard {
    background-color: #0f172a;
    background-image: 
        linear-gradient(45deg, #1e293b 25%, transparent 25%), 
        linear-gradient(-45deg, #1e293b 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #1e293b 75%), 
        linear-gradient(-45deg, transparent 75%, #1e293b 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* Scrollbars estilizadas para el contenedor del Editor */
#editorScrollContainer::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}
#editorScrollContainer::-webkit-scrollbar-track {
    background: rgba(148, 163, 184, 0.08);
}
#editorScrollContainer::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 9999px;
}
#editorScrollContainer::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}

.dark #editorScrollContainer::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.4);
}
.dark #editorScrollContainer::-webkit-scrollbar-thumb {
    background: rgba(71, 85, 105, 0.45);
}
.dark #editorScrollContainer::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.7);
}

/* Estilos de espacios publicitarios Firmafy */
.firmafy-ad-wrapper {
    position: relative;
    user-select: none;
}
.firmafy-ad-box {
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.05);
}

/* Contenedor del Editor: scroll 2D garantizado en cualquier nivel de zoom */
#editorScrollContainer {
    overflow: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    -webkit-overflow-scrolling: touch;
}

/* Barra lateral del anuncio: estática, anclada e inmune al zoom del documento */
#editorAdSidebar {
    flex-shrink: 0 !important;
    min-width: 180px !important;
    max-width: 180px !important;
    width: 180px !important;
    align-self: stretch !important;
}

/* ==========================================================================
   Efecto de Destello / Resalte para la Zona de Subida ("Arrastra tu archivo aquí")
   ========================================================================== */
@keyframes uploadGlowPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0), 0 10px 25px -5px rgba(0, 0, 0, 0.08);
        border-color: rgba(99, 102, 241, 0.4);
        transform: scale(1);
    }
    18% {
        box-shadow: 0 0 0 12px rgba(99, 102, 241, 0.35), 0 0 45px rgba(99, 102, 241, 0.4), 0 20px 35px -5px rgba(99, 102, 241, 0.25);
        border-color: #4f46e5;
        background-color: rgba(99, 102, 241, 0.08);
        transform: scale(1.02);
    }
    45% {
        box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.2), 0 0 20px rgba(99, 102, 241, 0.2);
        border-color: #6366f1;
        background-color: rgba(99, 102, 241, 0.04);
        transform: scale(1.006);
    }
    68% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0.3), 0 0 35px rgba(99, 102, 241, 0.3), 0 15px 30px -5px rgba(99, 102, 241, 0.18);
        border-color: #4f46e5;
        background-color: rgba(99, 102, 241, 0.06);
        transform: scale(1.015);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0), 0 10px 25px -5px rgba(0, 0, 0, 0.08);
        border-color: rgba(99, 102, 241, 0.3);
        background-color: transparent;
        transform: scale(1);
    }
}

@keyframes uploadGlowPulseDark {
    0% {
        box-shadow: 0 0 0 0 rgba(129, 140, 248, 0);
        border-color: rgba(129, 140, 248, 0.4);
        transform: scale(1);
    }
    18% {
        box-shadow: 0 0 0 12px rgba(129, 140, 248, 0.4), 0 0 50px rgba(129, 140, 248, 0.45);
        border-color: #818cf8;
        background-color: rgba(99, 102, 241, 0.16);
        transform: scale(1.02);
    }
    45% {
        box-shadow: 0 0 0 5px rgba(129, 140, 248, 0.22), 0 0 25px rgba(129, 140, 248, 0.25);
        border-color: #6366f1;
        background-color: rgba(99, 102, 241, 0.08);
        transform: scale(1.006);
    }
    68% {
        box-shadow: 0 0 0 10px rgba(129, 140, 248, 0.35), 0 0 40px rgba(129, 140, 248, 0.35);
        border-color: #818cf8;
        background-color: rgba(99, 102, 241, 0.12);
        transform: scale(1.015);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(129, 140, 248, 0);
        border-color: rgba(129, 140, 248, 0.3);
        background-color: transparent;
        transform: scale(1);
    }
}

.upload-destello-active {
    animation: uploadGlowPulse 2.1s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
    position: relative !important;
    z-index: 25 !important;
    will-change: transform, box-shadow, border-color;
}

.dark .upload-destello-active {
    animation-name: uploadGlowPulseDark !important;
}

.upload-destello-active .material-symbols-outlined {
    animation: iconDestelloPulse 2.1s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

@keyframes iconDestelloPulse {
    0%, 100% { transform: scale(1); }
    18% { transform: scale(1.22); color: #4f46e5; }
    45% { transform: scale(1.06); }
    68% { transform: scale(1.18); color: #4f46e5; }
}

