/* ============================================
   CLS (Cumulative Layout Shift) FIXES
   Correcciones para mejorar Lighthouse Performance
   Objetivo: CLS < 0.1
============================================ */

/* === FONT LOADING OPTIMIZATION === */
/* Prevenir reflow al cargar fuentes */
@font-face {
    font-family: 'Inter';
    font-display: swap; /* Mostrar fuente del sistema mientras carga */
    /* Agregar src cuando se implemente web fonts */
}

/* === RESERVED SPACE FOR DYNAMIC CONTENT === */

/* Notification Panel - Reservar espacio mínimo */
.notification-panel {
    min-height: 200px; /* Altura mínima para prevenir CLS */
    transition: none; /* Evitar animaciones que causen CLS */
}

.notification-list {
    min-height: 150px; /* Espacio reservado para notificaciones */
}

/* Chat Panel - Reservar espacio mínimo */
.chat-panel {
    min-height: 300px; /* Altura mínima para prevenir CLS */
}

.chat-messages {
    min-height: 250px; /* Espacio reservado para mensajes */
}

/* Content Area - Reservar espacio mínimo */
.content-area {
    min-height: 400px; /* Altura mínima para contenido principal */
}

/* Tab Bar - Altura fija */
.tab-bar {
    min-height: 48px; /* Altura fija para tabs */
}

/* Modal - Dimensiones mínimas */
.modal {
    min-width: 300px;
    min-height: 200px;
}

/* === IMAGE PLACEHOLDERS === */
/* Asegurar que todas las imágenes tengan dimensiones */
img {
    /* Prevenir CLS en imágenes sin dimensiones */
    max-width: 100%;
    height: auto;
}

/* Placeholder para imágenes de documentos */
.document-preview img,
.file-preview img {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9; /* Ratio por defecto */
    object-fit: contain;
    background: rgba(13, 33, 55, 0.6); /* Fondo mientras carga */
}

/* Placeholder para avatares */
.user-avatar,
.avatar-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(136, 192, 208, 0.2); /* Fondo mientras carga */
}

/* === SKELETON LOADERS === */
/* Placeholders para contenido que se carga dinámicamente */

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(136, 192, 208, 0.1) 0%,
        rgba(136, 192, 208, 0.2) 50%,
        rgba(136, 192, 208, 0.1) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 120px;
    margin-bottom: 12px;
}

/* === PREVENT LAYOUT SHIFTS ON LOAD === */

/* Asegurar que badges no causen CLS */
.notification-badge,
.chat-badge {
    min-width: 20px;
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Asegurar que botones mantengan tamaño */
.btn,
.btn-primary,
.btn-secondary {
    min-height: 36px;
    white-space: nowrap;
}

.btn-sm {
    min-height: 32px;
}

.btn-xs {
    min-height: 28px;
}

/* === FIXED DIMENSIONS FOR CRITICAL ELEMENTS === */

/* Header - Altura fija */
.app-header {
    min-height: 80px;
    max-height: 80px;
}

/* Sidebar - Ancho fijo */
.sidebar {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
}

/* === PREVENT SHIFTS FROM DYNAMIC CONTENT === */

/* Asegurar que listas vacías tengan altura */
.task-list:empty::before,
.project-list:empty::before,
.notification-list:empty::before,
.chat-messages:empty::before {
    content: '';
    display: block;
    height: 100px;
}

/* === SMOOTH TRANSITIONS WITHOUT CLS === */
/* Solo usar transforms y opacity para animaciones */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Evitar animaciones que causen CLS */
* {
    /* Prevenir cambios de layout por animaciones */
    will-change: auto !important;
}

/* Solo permitir transforms y opacity en animaciones */
.animated {
    will-change: transform, opacity;
}

/* === PREVENT REFLOW FROM SCROLLBARS === */
/* Reservar espacio para scrollbar */
html {
    overflow-y: scroll; /* Siempre mostrar scrollbar vertical */
}

/* === LOADING STATES === */
/* Mostrar placeholder mientras carga contenido */
.loading-placeholder {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #81A1C1;
}

.loading-placeholder::before {
    content: 'Carregant...';
    font-size: 14px;
}

/* === RESPONSIVE IMAGES === */
/* Asegurar que imágenes responsive no causen CLS */
.responsive-img {
    width: 100%;
    height: auto;
    display: block;
}

/* Contenedor con aspect ratio */
.img-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
    background: rgba(13, 33, 55, 0.6);
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* === PREVENT CLS FROM DYNAMIC BADGES === */
/* Badges con ancho mínimo */
.badge {
    min-width: 24px;
    display: inline-block;
    text-align: center;
}

/* === PREVENT CLS FROM TOOLTIPS === */
/* Tooltips no deben afectar layout */
.tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 9999;
}

/* === GRID LAYOUTS WITH FIXED GAPS === */
/* Prevenir CLS en grids */
.grid-layout {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.grid-item {
    min-height: 150px;
}

/* === PREVENT CLS FROM FORM VALIDATION === */
/* Reservar espacio para mensajes de error */
.form-group {
    margin-bottom: 24px; /* Espacio para mensaje de error */
}

.error-message {
    min-height: 20px;
    margin-top: 4px;
}

/* === CRITICAL CSS FOR ABOVE-THE-FOLD === */
/* Estilos críticos que deben cargarse primero */

/* Login screen - Dimensiones fijas */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
    min-height: 400px;
}

/* === PREVENT CLS FROM LAZY LOADED CONTENT === */
/* Placeholder para contenido lazy loaded */
[data-lazy] {
    min-height: 200px;
    background: rgba(13, 33, 55, 0.6);
}

/* === PERFORMANCE OPTIMIZATIONS === */
/* Reducir repaints y reflows */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* === PREVENT CLS FROM DYNAMIC LISTS === */
/* Listas con altura mínima por item */
.list-item {
    min-height: 48px;
}

.task-item {
    min-height: 60px;
}

.project-item {
    min-height: 80px;
}

/* === PREVENT CLS FROM MODALS === */
/* Modal overlay con dimensiones fijas */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

/* === PREVENT CLS FROM DROPDOWNS === */
/* Dropdowns con posición absoluta */
.dropdown-menu {
    position: absolute;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
}

/* === FINAL OPTIMIZATIONS === */
/* Asegurar que elementos críticos tengan contain */
.sidebar,
.main-area,
.content-area {
    contain: layout style paint;
}

/* Prevenir CLS en elementos con scroll */
.scrollable {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* === MEDIA QUERIES === */
/* Mantener dimensiones consistentes en responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        min-height: auto;
    }
    
    .app-container {
        flex-direction: column;
    }
    
    .content-area {
        min-height: 300px;
    }
}

/* === DEBUG MODE === */
/* Descomentar para visualizar elementos que causan CLS */
/*
* {
    outline: 1px solid rgba(255, 0, 0, 0.2) !important;
}

[style*="display: none"] {
    outline: 2px solid rgba(255, 255, 0, 0.5) !important;
}
*/
