/* Reset y configuración base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: row;
    height: 100vh;
}

/* Contenedor principal con header y contenido */
.main-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100vh;
    overflow: hidden;
}
.app-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    z-index: 1000;
    min-height: 56px;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}


.header-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Controles de zoom en el header */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.zoom-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.zoom-info {
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    min-width: 45px;
    text-align: center;
}

/* Botones - Estilo moderno */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 36px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: #10b981;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #059669;
}

.btn-success {
    background: #3b82f6;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #2563eb;
}

.btn-secondary {
    background: #f59e0b;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #d97706;
}

.btn-info {
    background: #6366f1;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #138496;
}

.btn-home {
    background: #8b5cf6;
    color: white;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-home:hover:not(:disabled) {
    background: #7c3aed;
    color: white;
    text-decoration: none;
}

/* Toolbar - Estilo WYSIWYG moderno */
.toolbar {
    background: #ffffff;
    border-bottom: 1px solid #e1e5e9;
    padding: 0.5rem 1rem;
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    z-index: 999;
    align-items: center;
    min-height: 48px;
}

/* Esta regla se aplica solo al toolbar horizontal, no al sidebar */
.toolbar:not(.sidebar) .toolbar-section {
    display: block;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.5rem;
    border-right: 1px solid #e1e5e9;
}

.toolbar:not(.sidebar) .toolbar-section:last-child {
    border-right: none;
}

.toolbar-section h3 {
    display: none; /* Ocultar títulos para hacer más compacto */
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: stretch;
    width: 100%;
}

.tool-btn {
    padding: 0.25rem 0.4rem;
    border: 1px solid #d1d5db;
    background: #ffffff;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-width: 28px;
    min-height: 28px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #374151;
    gap: 0.4rem;
    margin-bottom: 0.2rem;
}

.tool-btn:hover {
    border-color: #3b82f6;
    background: #f3f4f6;
    color: #1f2937;
}

.tool-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
    box-shadow: 0 1px 2px rgba(59, 130, 246, 0.3);
}

.tool-btn:active {
    transform: translateY(1px);
}

/* Sidebar lateral - Estilo expandido con etiquetas */
.toolbar {
    background: #ffffff;
    border-right: 1px solid #e1e5e9;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    z-index: 1100; /* Por encima del header (1000) */
    width: 200px;

    min-width: 200px;
    align-items: stretch;
    transition: width 0.3s ease;
}

.toolbar.compact {
    width: 60px;
    min-width: 60px;
    padding: 1rem 0.5rem;
}

/* Burger Menu Button - Siempre visible */
.burger-menu {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1200; /* Siempre sobre el header y el sidebar */
}


.burger-menu span {
    width: 100%;
    height: 3px;
    background-color: white;
    border-radius: 10px;
    transition: all 0.3s linear;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}


/* Submenús desplegables */
.toolbar-section {
    position: relative;
    width: 100%;
}

.toolbar-section-header {
    padding: 0.25rem 0.5rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
    position: relative;
    overflow: hidden;
    width: 100%;
}

.toolbar-section-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    transition: width 0.2s ease;
}

.toolbar-section-header:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    border-color: #3b82f6;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.toolbar-section-header:hover::before {
    width: 5px;
}

.toolbar-section-label {
    font-size: 0.6rem;
    color: #6b7280;
    background: rgba(59, 130, 246, 0.1);
    padding: 0.15rem 0.4rem;
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0.3px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    transition: all 0.2s ease;
    text-align: center;
    margin-bottom: 0.25rem;
}

.toolbar-section-header:hover .toolbar-section-label {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.3);
}

.toolbar-section-toggle {
    font-size: 0.7rem;
    color: #6b7280;
    transition: transform 0.2s ease;
    text-align: center;
}

.toolbar-section.expanded .toolbar-section-toggle {
    transform: rotate(180deg);
    color: #3b82f6;
}

.toolbar-section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-top: 0.25rem;
    width: 100%;
}

.toolbar-section.expanded .toolbar-section-content {
    max-height: 500px;
}

.toolbar.compact .toolbar-section-header {
    padding: 0.5rem;
    justify-content: center;
    flex-direction: row;
}

.toolbar.compact .toolbar-section-title-row {
    display: none;
}

.toolbar.compact .toolbar-section-toggle {
    display: none;
}

.toolbar.compact .toolbar-section-content {
    max-height: none;
    overflow: visible;
}

/* Paginación compacta */
.pagination-compact {
    margin-top: 1rem;
    padding: 0.5rem;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border-radius: 8px;
    border: 1px solid #cbd5e1;
}

.pagination-compact-header {
    font-size: 0.7rem;
    color: #475569;
    font-weight: 600;
    text-align: center;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
}

.pagination-btn {
    background: #ffffff;
    border: 1px solid #d1d5db;
    color: #374151;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: all 0.2s ease;
    font-weight: 600;
}

.pagination-btn:hover {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
    transform: scale(1.1);
}

.pagination-info {
    font-size: 0.65rem;
    color: #6b7280;
    font-weight: 600;
    text-align: center;
    flex: 1;
    background: rgba(255, 255, 255, 0.8);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: stretch;
    width: 100%;
}

.tool-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    background: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    min-height: 40px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    position: relative;
    text-align: left;
}

.toolbar.compact .tool-btn {
    padding: 0.5rem;
    justify-content: center;
    min-height: 48px;
    width: 48px;
    margin: 0 auto;
}

.tool-btn:hover {
    border-color: #3b82f6;
    background: #f3f4f6;
    color: #1f2937;
    transform: scale(1.02);
}

.toolbar.compact .tool-btn:hover {
    transform: scale(1.05);
}

.tool-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white !important;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.tool-btn.active .tool-btn-text {
    color: white !important;
}

.tool-btn.active .icon {
    color: white !important;
}

.tool-btn:active {
    transform: scale(0.98);
}

.toolbar.compact .tool-btn:active {
    transform: scale(0.95);
}

.icon {
    font-size: 0.9rem;
    line-height: 1;
    flex-shrink: 0;
}

.toolbar.compact .icon {
    font-size: 1.3rem;
}

.tool-btn-text {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toolbar.compact .tool-btn-text {
    display: none;
}

/* Botón toggle para modo compacto */
.toolbar-toggle {
    position: absolute;
    top: 1rem;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #3b82f6;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    z-index: 1000;
}

.toolbar-toggle:hover {
    background: #2563eb;
    transform: scale(1.1);
}

.toolbar.compact .toolbar-toggle {
    right: -15px;
}

.toolbar-toggle::before {
    content: '◀';
    transition: transform 0.3s ease;
}

.toolbar.compact .toolbar-toggle::before {
    content: '▶';
}

/* Tooltips para los botones del sidebar */
.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
    margin-left: 0.5rem;
}

/* Estilos adicionales para el sidebar */
.toolbar-section span {
    font-size: 0.7rem;
    color: #666;
    text-align: center;
    margin: 0.25rem 0;
    display: block;
}

/* Mejorar la apariencia de los controles en el sidebar */
/* Mejorar la apariencia de los controles en el sidebar expandido */
.toolbar-section input[type="color"] {
    width: 100%;
    height: 32px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    cursor: pointer;
    margin: 0.25rem 0;
}

.toolbar-section input[type="range"] {
    width: 100%;
    margin: 0.25rem 0;
}

.toolbar-section select {
    width: 100%;
    font-size: 0.8rem;
    padding: 0.5rem;
    margin: 0.25rem 0;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    background: white;
}

/* Estilos para el modo compacto */
.toolbar.compact .toolbar-section input[type="color"] {
    width: 32px;
    height: 32px;
    margin: 0.25rem auto;
}

.toolbar.compact .toolbar-section input[type="range"] {
    width: 100%;
    margin: 0.25rem 0;
}

.toolbar.compact .toolbar-section select {
    display: none; /* Ocultar selectores en modo compacto */
}

/* Scrollbar personalizado para el sidebar */
.toolbar::-webkit-scrollbar {
    width: 4px;
}

.toolbar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.toolbar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

.toolbar::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mejoras adicionales para el estilo WYSIWYG */
.tool-btn[data-tool="bold"],
.tool-btn[data-tool="italic"],
.tool-btn[data-tool="underline"],
.tool-btn[data-tool="strikethrough"] {
    font-weight: bold;
    font-style: italic;
    text-decoration: underline;
}

.tool-btn[data-tool="bold"] {
    font-weight: bold;
}

.tool-btn[data-tool="italic"] {
    font-style: italic;
}

.tool-btn[data-tool="underline"] {
    text-decoration: underline;
}

.tool-btn[data-tool="strikethrough"] {
    text-decoration: line-through;
}

/* Estilo para botones de formato de texto */
.tool-btn[data-tool="bold"]:not(.active) {
    font-weight: normal;
}

.tool-btn[data-tool="italic"]:not(.active) {
    font-style: normal;
}

.tool-btn[data-tool="underline"]:not(.active) {
    text-decoration: none;
}

.tool-btn[data-tool="strikethrough"]:not(.active) {
    text-decoration: none;
}

/* Controles de entrada - Estilo moderno */
input[type="color"],
input[type="range"],
select {
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0.25rem;
    background: white;
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
}

input[type="color"]:hover,
input[type="range"]:hover,
select:hover {
    border-color: #3b82f6;
}

input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 2px;
    cursor: pointer;
}

input[type="range"] {
    width: 60px;
    height: 4px;
    background: #e5e7eb;
    outline: none;
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

select {
    min-width: 100px;
    height: 32px;
    cursor: pointer;
}

/* Main Content - Ajustado para sidebar */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #f8f9fa;
    padding: 1rem;
    overflow: auto;
    height: calc(100vh - 56px); /* Altura total menos el header */
}

.pdf-viewer {
    width: 100%;
    max-width: 1200px;
}

.pdf-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
}

.pdf-page-wrapper {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    overflow: visible;
    margin: 10px 0;
}

.pdf-page-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.pdf-page-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 2;
    background: transparent;
}

.text-selection-overlay {
    position: absolute;
    background: rgba(0, 123, 255, 0.3);
    border: 1px solid #007bff;
    pointer-events: none;
    z-index: 3;
}

.text-editing-overlay {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #007bff;
    border-radius: 4px;
    padding: 5px;
    z-index: 4;
    min-width: 100px;
    min-height: 20px;
}

.text-editing-overlay input {
    border: none;
    outline: none;
    background: transparent;
    width: 100%;
    font-family: inherit;
    font-size: inherit;
}

/* Estilos para formas seleccionadas */
.selected-shape {
    outline: 2px solid #007bff !important;
    outline-offset: 2px !important;
    filter: drop-shadow(0 0 5px rgba(0, 123, 255, 0.5)) !important;
}

/* Asegurar que el grosor de línea no cambie al escalar dibujos */
.drawing-container svg *, 
.drawing-path, 
.drawing-line, 
.drawing-rectangle, 
.drawing-circle {
    vector-effect: non-scaling-stroke;
}

/* Estilos para handles de formas */
.shape-handles {
    position: absolute;
    pointer-events: auto;
    z-index: 1000;
}

.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #007bff;
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1001;
    transition: all 0.2s ease;
}

.resize-handle:hover {
    background-color: #0056b3;
    transform: scale(1.2);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.resize-handle-nw {
    cursor: nw-resize;
}

.resize-handle-ne {
    cursor: ne-resize;
}

.resize-handle-sw {
    cursor: sw-resize;
}

.resize-handle-se {
    cursor: se-resize;
}

.resize-handle-radius {
    cursor: ew-resize;
}

/* Estilos para formas interactivas */
.drawing-line,
.drawing-rectangle,
.drawing-circle {
    transition: all 0.2s ease;
}

.drawing-line:hover,
.drawing-rectangle:hover,
.drawing-circle:hover {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* Mejoras para dispositivos móviles */
@media (max-width: 768px) {
    .resize-handle {
        width: 12px;
        height: 12px;
    }
    
    .selected-shape {
        outline-width: 3px !important;
    }
}

/* Estilos para elementos agregados */
.added-text {
    cursor: move;
    user-select: none;
    transition: all 0.2s ease;
}

.added-text:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

.added-text:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Estilos para dibujo */
.drawing-overlay {
    pointer-events: none;
}

/* Estilos para imágenes arrastrables */
img[draggable] {
    cursor: move;
    transition: all 0.2s ease;
}

img[draggable]:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transform: scale(1.02);
}

img[draggable]:active {
    cursor: grabbing;
}

/* Mejoras para el contenedor de páginas */
.pdf-pages-container {
    scroll-behavior: smooth;
}

/* Indicador de página activa */
.pdf-page-wrapper.active {
    border: 3px solid #007bff;
    box-shadow: 0 6px 25px rgba(0,123,255,0.3);
}

/* Estilos para resaltado */
.highlight-overlay {
    position: absolute;
    background: rgba(255, 255, 0, 0.3);
    border: 1px solid #ffc107;
    pointer-events: none;
    z-index: 3;
}

/* Estilos para sellos */
.stamp-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 4;
    font-size: 24px;
    color: #dc3545;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* Estilos para elementos seleccionados */
.selected {
    outline: 3px solid #007bff !important;
    outline-offset: 2px;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5) !important;
}

/* Las imágenes no deben tener outline al seleccionarse */
.draggable-image.selected {
    outline: none !important;
    box-shadow: none !important;
}

/* Efecto de resplandor para elementos SVG seleccionados */
.selected-svg {
    filter: drop-shadow(0 0 4px #007bff) drop-shadow(0 0 2px #007bff);
    cursor: move !important;
}

.drawing-path, .shape-preview path, .shape-preview rect, .shape-preview circle, .shape-preview line {
    transition: filter 0.2s ease;
}

.dragging {
    opacity: 0.8;
    z-index: 999 !important;
}

/* Estilos para cuadros de texto */
.text-box-container {
    transition: all 0.2s ease;
}

.text-box-container:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.text-box-container.selected {
    border-color: #28a745 !important;
}

/* Estilos para elementos arrastrables */
.draggable-text,
.draggable-image {
    transition: all 0.2s ease;
}

.draggable-text:hover,
.draggable-image:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

/* Estilos para elementos sin bordes por defecto */
.added-text {
    border: none !important;
}

.added-text:hover {
    border: 1px solid #ccc !important;
}

.text-box-container {
    border: none !important;
}

.text-box-container:hover {
    border: 1px solid #ccc !important;
}

.text-box-container.selected {
    border: 2px solid #007bff !important;
}

/* Estilos para handles de redimensionado - NUEVO SISTEMA EXTERNO */
.resize-handle-external {
    position: absolute !important;
    width: 12px !important;
    height: 12px !important;
    background-color: #007bff !important;
    cursor: se-resize !important;
    border-radius: 0 0 4px 0 !important;
    border: 1px solid #fff !important;
    z-index: 9999 !important;
    opacity: 1 !important;
    display: block !important;
    transition: opacity 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5) !important;
    pointer-events: auto !important;
}

.resize-handle-external:hover {
    background-color: #0056b3 !important;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.6) !important;
}

/* Estilos para handles internos (compatibilidad) */
.resize-handle {
    position: absolute !important;
    bottom: 0 !important;
    right: 0 !important;
    width: 12px !important;
    height: 12px !important;
    background-color: #007bff !important;
    cursor: se-resize !important;
    border-radius: 0 0 4px 0 !important;
    border: 1px solid #fff !important;
    z-index: 1000 !important;
    opacity: 1 !important;
    display: block !important;
    transition: opacity 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Asegurar visibilidad en diferentes estados */
.draggable-image:hover .resize-handle,
.text-box-container:hover .resize-handle,
.selected .resize-handle,
.draggable-image .resize-handle,
.draggable-image.selected .resize-handle {
    opacity: 1 !important;
    display: block !important;
}

.resize-handle:hover {
    background-color: #0056b3 !important;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

/* Mejoras para resaltado */
.highlight-overlay {
    border-radius: 3px;
    transition: all 0.2s ease;
}

.highlight-overlay:hover {
    background: rgba(255, 255, 0, 0.5) !important;
}

/* Estilos para selección de texto nativa */
.text-selection-mode canvas {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

.text-selection-mode .pdf-page-overlay {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

/* Helper para selección de texto */
.text-selection-helper {
    pointer-events: none !important;
    background: transparent !important;
}

/* Cursor de texto para selección */
.text-selection-mode {
    cursor: text !important;
}

.text-selection-mode * {
    cursor: text !important;
}

/* Estilos para capa de texto */
.textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 0.2; /* Slightly visible for debugging */
    line-height: 1;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    pointer-events: auto;
    z-index: 999;
    color: transparent;
    background: transparent;
}

.textLayer span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    pointer-events: auto;
}

/* Resaltado de selección */
.textLayer ::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.textLayer ::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.textLayer span::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.textLayer span::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

/* Estilos para capa de texto precisa */
.precise-text-layer {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 999 !important;
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    cursor: text !important;
    background: transparent !important;
}

.precise-text-layer span {
    color: rgba(0, 0, 0, 0.01) !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    pointer-events: auto !important;
    cursor: text !important;
    white-space: pre !important;
    background: transparent !important;
}

.precise-text-layer ::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.precise-text-layer ::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.precise-text-layer span::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.precise-text-layer span::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

/* Estilos para capa de texto simple */
.simple-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    z-index: 10;
    cursor: text;
    background: transparent;
}

.simple-text-layer * {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    pointer-events: auto !important;
    cursor: text !important;
}

.simple-text-layer ::selection {
    background: rgba(0, 123, 255, 0.3);
}

.simple-text-layer ::-moz-selection {
    background: rgba(0, 123, 255, 0.3);
}

/* Estilos para capa de texto funcional */
.working-text-layer {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 999 !important;
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    cursor: text !important;
    background: transparent !important;
    color: transparent !important;
}

.working-text-layer * {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    pointer-events: auto !important;
    cursor: text !important;
}

.working-text-layer ::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.working-text-layer ::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.working-text-layer *::selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

.working-text-layer *::-moz-selection {
    background: rgba(0, 123, 255, 0.5) !important;
    color: white !important;
}

/* Loading */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(255,255,255,0.9);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .toolbar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .toolbar-section {
        min-width: auto;
    }
    
    .tool-group {
        justify-content: center;
    }
    
    .main-content {
        padding: 1rem;
    }
}

/* Estados de herramienta */
.drawing-mode {
    cursor: crosshair;
}

.text-mode {
    cursor: text;
}

.select-mode {
    cursor: default;
}

.image-mode {
    cursor: copy;
}

.text-selection-mode {
    cursor: text;
}

.hand-mode {
    cursor: grab;
}

.hand-mode:active {
    cursor: grabbing;
}

.text-edit-mode {
    cursor: text;
}

.textbox-mode {
    cursor: crosshair;
}

.text-add-mode {
    cursor: crosshair;
}

.shape-mode {
    cursor: crosshair;
}

.eraser-mode {
    cursor: crosshair;
}

.highlight-mode {
    cursor: crosshair;
}

.default-mode {
    cursor: default;
}

/* Animaciones */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Estilos para elementos seleccionados */
.selected-element {
    outline: 2px dashed #667eea;
    outline-offset: 2px;
}

/* Notificaciones */
.notification {
    position: fixed;
    top: 80px;
    right: 20px;
    background: #4CAF50;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    max-width: 300px;
    font-size: 0.9rem;
    font-weight: 500;
}

.notification.show {
    transform: translateX(0);
}

.notification.error {
    background: #f44336;
}

.notification.warning {
    background: #ff9800;
}

/* Responsive para notificaciones */
@media (max-width: 768px) {
    .notification {
        top: 70px;
        right: 10px;
        left: 10px;
        max-width: none;
        font-size: 0.85rem;
        padding: 0.75rem 1rem;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.modal-header h2 {
    margin: 0;
    color: #333;
    font-size: 1.25rem;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: #333;
}

.modal-body {
    padding: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    text-align: right;
}

/* Lista de proyectos */
.project-item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.project-item:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.project-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
}

.project-date {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.project-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.project-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Información del servidor */
.server-info {
    padding: 1rem 0;
}

.info-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-item:last-child {
    border-bottom: none;
}

.info-item strong {
    color: #333;
    min-width: 200px;
}

/* Mejoras para el canvas */
.canvas-wrapper {
    position: relative;
    display: inline-block;
}

#pdfCanvas {
    border: 1px solid #ddd;
    border-radius: 4px;
}

#fabricCanvas {
    border: 1px solid transparent;
    border-radius: 4px;
}

/* Mejoras para dispositivos móviles */
@media (max-width: 768px) {
    .pdf-container {
        margin-top: 1rem;
    }
    
    .main-content {
        padding: 1rem 0.5rem;
    }
    
    .toolbar {
        padding: 0.5rem;
        flex-wrap: wrap;
    }
    
    .toolbar-section {
        min-width: 120px;
    }
    
    .tool-group {
        flex-wrap: wrap;
    }
    
/* Responsive para móviles - Sidebar estilo Android */
@media (max-width: 768px) {
    .burger-menu {
        display: flex;
    }

    .app-container {
        flex-direction: column;
    }

    .toolbar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 1150; /* Por encima del header y overlay */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 4rem; /* Espacio para el header si fuera necesario, o para que el burger no se tape */
        box-shadow: 4px 0 15px rgba(0,0,0,0.3);
        border-right: none;
    }


    .toolbar.mobile-open {
        transform: translateX(0);
    }

    .toolbar.compact {
        width: 280px; /* En móvil no tiene sentido el modo compacto */
        min-width: 280px;
    }

    .toolbar-toggle {
        display: none; /* Ocultamos el toggle de escritorio en móvil */
    }

    .toolbar-section {
        margin-bottom: 1rem;
    }

    .app-header {
        padding: 0.75rem 1rem;
        justify-content: space-between;
        gap: 1rem;
        min-height: 56px;
    }

    .header-left {
        gap: 0.75rem;
    }

    .header-controls {
        width: auto;
        justify-content: flex-end;
    }


    .btn-home {
        margin-left: auto; /* Empuja el botón de inicio a la derecha */
    }

    .main-wrapper {
        height: calc(100vh - 56px);
    }

    .main-content {
        height: 100%;
        padding: 0.5rem;
    }

    .tool-btn {
        padding: 0.75rem 1rem;
        min-height: 48px;
    }

    .tool-btn-text {
        display: block !important; /* Mostramos el texto en el drawer de móvil */
        font-size: 0.9rem;
    }

    .toolbar.compact .tool-btn-text {
        display: block !important;
    }
    
    .toolbar.compact .tool-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 0.75rem 1rem;
    }

    .zoom-controls {
        display: none; /* Opcional: ocultar zoom en header para ganar espacio */
    }
}

