/**
 * TAZDUCA - ERROR PREVENTION CSS
 * Prevenir errores visuales y mejorar estabilidad - DREV1
 */

/* ============================================
   PREVENIR ERRORES DE RENDERIZADO
   ============================================ */

/* Ocultar elementos que puedan causar errores */
.error-prone-element,
.broken-component,
.failed-load {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Contenedor de respaldo para elementos que fallan */
.fallback-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #666;
    font-style: italic;
}

/* ============================================
   CHATBOT ERROR PREVENTION
   ============================================ */

/* Asegurar que el chatbot no rompa el layout */
#tazduca-chatbot {
    max-width: 100% !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    z-index: 1000 !important;
}

#tazduca-chatbot * {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Prevenir overflow en mensajes del chatbot */
.chatbot-messages,
.chatbot-message {
    overflow-wrap: break-word !important;
    word-break: break-word !important;
}

/* ============================================
   SERVICE WORKER ERROR PREVENTION
   ============================================ */

/* Ocultar errores de service worker */
.sw-error,
.service-worker-error {
    display: none !important;
}

/* ============================================
   FETCH ERROR PREVENTION
   ============================================ */

/* Fallback para contenido que depende de APIs */
.api-dependent {
    opacity: 1 !important;
    visibility: visible !important;
}

.api-dependent::after {
    content: '';
    display: block;
    clear: both;
}

/* Estados de carga para elementos con fetch */
.loading-fallback {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 2s infinite;
}

@keyframes loading-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ============================================
   MUTATION OBSERVER ERROR PREVENTION
   ============================================ */

/* Estabilizar elementos observados */
.observed-element {
    transition: all 0.3s ease !important;
    will-change: auto !important;
}

/* Prevenir cambios bruscos durante observación */
.mutation-safe {
    backface-visibility: hidden !important;
    transform: translateZ(0) !important;
}

/* ============================================
   DUPLICATE IDENTIFIER PREVENTION
   ============================================ */

/* Resetear estilos que puedan duplicarse */
.reset-duplicates {
    all: initial !important;
    display: block !important;
}

/* ============================================
   CONSOLE ERROR VISUAL FIXES
   ============================================ */

/* Ocultar elementos que generen errores visuales */
.console-error-source {
    opacity: 0.5 !important;
    pointer-events: none !important;
}

/* Overlay para errores críticos */
.critical-error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    font-family: monospace;
}

/* ============================================
   PERFORMANCE OPTIMIZATION
   ============================================ */

/* Optimizar elementos que causan reflow */
.performance-optimized {
    contain: layout style paint !important;
    will-change: transform !important;
    transform: translateZ(0) !important;
}

/* Lazy loading para imágenes problemáticas */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[data-src].loaded {
    opacity: 1;
}

/* ============================================
   RESPONSIVE ERROR PREVENTION
   ============================================ */

/* Prevenir errores en móvil */
@media (max-width: 768px) {
    .mobile-error-prone {
        display: none !important;
    }
    
    /* Simplificar elementos complejos en móvil */
    .complex-animation,
    .heavy-component {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}

/* ============================================
   DEBUG MODE
   ============================================ */

.debug-errors .error-prone-element {
    display: block !important;
    border: 2px solid red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

.debug-errors .error-prone-element::before {
    content: '⚠️ ERROR PRONE' !important;
    position: absolute !important;
    top: -20px !important;
    left: 0 !important;
    background: red !important;
    color: white !important;
    padding: 2px 6px !important;
    font-size: 10px !important;
    z-index: 999999 !important;
}