/* Progressive Enhancement Styles */

/* Ensure tool cards work without JavaScript and prevent CLS */
.tool-card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-height: 80px; /* Ensure consistent height */
    contain: layout style; /* Prevent layout shifts */
    box-sizing: border-box; /* Include padding/border in size calculations */
}

.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Make static content visible by default with space reservation */
#static-content {
    display: block !important;
    contain: layout; /* Prevent layout shifts */
    min-height: 200px; /* Reserve minimum space */
}

/* Default: hide dynamic grid for no-JS; show when JS is enabled */
#dynamic-tools-grid {
    display: none; /* Hidden by default for no-JS */
}
.js-enabled #dynamic-tools-grid {
    display: block !important; /* Reveal dynamic category sections when JS is active */
}

/* When JS is enabled, prefer dynamic content and hide static fallback */
.js-enabled #static-content {
    display: none !important;
}

/* Additional CLS prevention */
.main-content {
    contain: layout style; /* Prevent external layout shifts */
}

.tools-grid {
    contain: layout; /* Isolate tool grid layout */
    /* Removed min-height since dynamic grid is not used */
}

/* Loading indicator should be hidden by default */
.loading-indicator {
    display: none;
}

.js-enabled .loading-indicator {
    display: flex;
}

/* News section should work without JavaScript */
#ai-news {
    display: block;
}

.news-loading {
    display: none !important;
}

/* Ensure search works as a regular form without JS */
.search-container form {
    display: flex;
    align-items: center;
}

/* Make icons show immediately with stable dimensions */
.tool-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    min-width: 48px; /* Prevent shrinking */
    min-height: 48px; /* Prevent shrinking */
    border-radius: 8px;
    background: transparent;
    margin-right: 12px;
    contain: layout size; /* Isolate layout and prevent size changes */
}

.fallback-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #475569;
}

.fallback-icon.text-logo {
    font-size: 14px;
    font-weight: 700;
}

/* Better text logo styling */
.text-logo {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    padding: 4px;
}

/* Skeleton loading styles */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, transparent 37%, #f0f0f0 63%);
    background-size: 400% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 100% 50%;
    }
    100% {
        background-position: -100% 50%;
    }
}

/* Optimize for no-JS experience */
@media (prefers-reduced-motion: reduce) {
    .tool-card {
        transition: none;
    }
    
    .skeleton {
        animation: none;
        background: #f0f0f0;
    }
}

/* Critical above-the-fold optimization */
.above-the-fold {
    /* contain: layout style paint; - Commented out as it creates stacking context that interferes with dropdowns */
}

/* Make sidebar work without JavaScript */
.sidebar .nav-item {
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.sidebar .nav-item:hover {
    background-color: rgba(102, 126, 234, 0.1);
}

/* Ensure no-JS navigation works with anchor links */
.nav-item a {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    width: 100%;
}

/* Mobile optimization for no-JS */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 1000;
    }
    
    /* Show sidebar when targeted (no-JS mobile menu) */
    .sidebar:target {
        left: 0;
    }
}

/* Performance-focused loading states */
.instant-load {
    opacity: 1 !important;
    transform: none !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tool-card {
        border: 2px solid #000;
    }
    
    .fallback-icon {
        border: 1px solid #000;
    }
}
