/**
 * Image Optimization CSS
 * Ensures images display properly across all contexts
 */

/* ================================
   SMART IMAGE CONTAINERS
   ================================ */

.smart-image-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 0; /* Height set by padding-bottom */
    background: #f8f9fa;
    border-radius: inherit;
}

.smart-image-wrapper img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease;
}

/* ================================
   CONTEXT-SPECIFIC OPTIMIZATIONS
   ================================ */

/* Homepage Article Cards */
.context-homepage .smart-image-wrapper,
.article-card-image {
    height: 320px !important;
    padding-bottom: 0 !important; /* Override aspect ratio for fixed height */
    border-radius: clamp(12px, 2vw, 20px) clamp(12px, 2vw, 20px) 0 0;
}

.context-homepage .smart-image-wrapper img,
.article-card-image img {
    object-fit: cover !important;
    object-position: center !important;
    width: 100% !important;
    height: 100% !important;
}
/* Single Post Featured Images */
.context-single .smart-image-wrapper,
.tech-article-featured-image,
.featured-image-container {
    height: auto !important;
    padding-bottom: 35% !important; /* Reduced from 56.25% to 35% for smaller image */
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.context-single .smart-image-wrapper img,
.tech-article-featured-image img,
.featured-image-container img {
    object-fit: cover !important;
    object-position: center !important;
    border-radius: var(--radius-lg);
}

/* Related Articles */
.tech-related-image,
.context-related .smart-image-wrapper {
    height: 180px !important;
    padding-bottom: 0 !important;
    border-radius: 12px 12px 0 0;
}

.tech-related-image img,
.context-related .smart-image-wrapper img {
    object-fit: cover !important;
    object-position: center !important;
}

/* Hero Images */
.hero-featured-image,
.context-hero .smart-image-wrapper {
    height: 280px !important;
    padding-bottom: 0 !important;
    border-radius: var(--radius-lg);
}

.hero-featured-image img,
.context-hero .smart-image-wrapper img {
    object-fit: cover !important;
    object-position: center !important;
}

/* Square Thumbnails */
.context-square .smart-image-wrapper {
    height: 0 !important;
    padding-bottom: 100% !important; /* 1:1 aspect ratio */
    border-radius: 8px;
}

.context-square .smart-image-wrapper img {
    object-fit: cover !important;
    object-position: center !important;
}

/* ================================
   OPTIMIZED IMAGE CLASSES
   ================================ */

.optimized-image {
    max-width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease, filter 0.3s ease;
}

/* ================================
   FORMAT-SPECIFIC OPTIMIZATIONS
   ================================ */

/* PNG Images - Preserve transparency */
.format-png {
    background: transparent !important;
}

/* WebP Images - Modern format support */
.format-webp {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* JPEG Images - Standard optimization */
.format-jpeg,
.format-jpg {
    image-rendering: auto;
}

/* GIF Images - Preserve animation and quality */
.format-gif {
    image-rendering: auto;
    background: transparent !important;
}

/* SVG Images - Vector graphics optimization */
.format-svg,
.special-format-image[data-format="svg"] {
    background: transparent !important;
    image-rendering: auto;
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
    object-position: center !important;
}

/* TIFF Images - High quality preservation */
.format-tiff,
.format-tif {
    image-rendering: auto;
}

/* BMP Images - Basic bitmap support */
.format-bmp {
    image-rendering: auto;
}

/* Special format images (SVG, etc.) */
.special-format-image {
    background: transparent !important;
    object-fit: contain !important;
    position: static !important;
}

/* Exclude logo and branding images from optimization */
.site-branding img,
.custom-logo,
.footer-logo img,
.logo-icon img,
.site-logo img {
    background: transparent !important;
    object-fit: contain !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
}

/* Specific logo size constraints */
.custom-logo {
    max-height: 45px !important;
    max-width: 200px !important;
}

.footer-logo img {
    max-height: 50px !important;
    max-width: 150px !important;
}

/* Prevent smart image wrapper from affecting logos */
.site-branding .smart-image-wrapper,
.custom-logo-link .smart-image-wrapper,
.footer-logo .smart-image-wrapper {
    display: none !important;
}

/* Override any global image styles for logos */
.site-branding,
.custom-logo-link,
.footer-logo {
    background: transparent !important;
}

.site-branding img,
.custom-logo-link img,
.footer-logo img {
    position: static !important;
    top: auto !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    background: transparent !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    filter: none !important;
}

.responsive-image {
    width: 100%;
    height: 100%;
}

/* Image Loading States */
.optimized-image[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

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

/* Image Hover Effects */
.article-card:hover .optimized-image,
.tech-related-card:hover .optimized-image,
.hero-featured-post:hover .optimized-image {
    transform: scale(1.05);
}

/* ================================
   IMAGE PLACEHOLDERS
   ================================ */

.image-placeholder {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border: 1px solid #e2e8f0;
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
}

.image-placeholder:hover {
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    color: #475569;
}

.image-placeholder svg {
    opacity: 0.6;
    margin-bottom: 8px;
}

/* ================================
   RESPONSIVE BREAKPOINTS
   ================================ */

/* Large tablets and small desktops */
@media (max-width: 1024px) {
    .context-homepage .smart-image-wrapper,
    .article-card-image {
        height: 280px !important;
    }
    
    .context-single .smart-image-wrapper,
    .tech-article-featured-image {
        padding-bottom: 40% !important; /* Reduced for smaller image on tablets */
    }
    
    .tech-related-image,
    .context-related .smart-image-wrapper {
        height: 160px !important;
    }
}

/* Tablets */
@media (max-width: 768px) {
    .context-homepage .smart-image-wrapper,
    .article-card-image {
        height: 240px !important;
    }
    
    .context-single .smart-image-wrapper,
    .tech-article-featured-image {
        padding-bottom: 45% !important; /* Reduced for smaller image on mobile */
        margin-bottom: 1.5rem;
    }
    
    .tech-related-image,
    .context-related .smart-image-wrapper {
        height: 140px !important;
    }
    
    .hero-featured-image,
    .context-hero .smart-image-wrapper {
        height: 220px !important;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    .context-homepage .smart-image-wrapper,
    .article-card-image {
        height: 200px !important;
    }
    
    .context-single .smart-image-wrapper,
    .tech-article-featured-image {
        padding-bottom: 50% !important; /* Reduced for smaller image on small mobile */
        margin-bottom: 1rem;
        border-radius: 12px;
    }
    
    .tech-related-image,
    .context-related .smart-image-wrapper {
        height: 120px !important;
    }
    
    .hero-featured-image,
    .context-hero .smart-image-wrapper {
        height: 180px !important;
    }
}

/* ================================
   BROWSER COMPATIBILITY
   ================================ */

/* WebP fallback support */
.webp-fallback {
    background: #f8f9fa;
}

.webp-optimized {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Cross-browser image rendering */
.optimized-image {
    -ms-interpolation-mode: bicubic; /* IE */
    image-rendering: -webkit-optimize-contrast; /* Webkit */
    image-rendering: optimize-contrast; /* Standard */
}

/* Prevent image dragging */
.optimized-image {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: auto;
}

/* Fix for Safari image loading */
@supports (-webkit-appearance: none) {
    .optimized-image {
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Fix for Firefox image quality */
@-moz-document url-prefix() {
    .optimized-image {
        image-rendering: -moz-crisp-edges;
    }
}

/* Edge/IE compatibility */
@supports (-ms-ime-align: auto) {
    .optimized-image {
        -ms-interpolation-mode: bicubic;
    }
}

/* ================================
   FORMAT ERROR HANDLING
   ================================ */

/* Image loading error states */
.optimized-image[src=""],
.optimized-image:not([src]) {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.optimized-image[src=""]:before,
.optimized-image:not([src]):before {
    content: "Image not available";
    color: #64748b;
    font-size: 14px;
}

/* Broken image fallback */
.optimized-image[alt]:after {
    content: attr(alt);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.optimized-image[alt]:hover:after {
    opacity: 1;
}

/* ================================
   PERFORMANCE OPTIMIZATIONS
   ================================ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .optimized-image,
    .smart-image-wrapper img {
        transition: none;
    }
    
    .optimized-image[loading="lazy"] {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .image-placeholder {
        border: 2px solid currentColor;
        background: transparent;
    }
    
    .smart-image-wrapper {
        border: 1px solid currentColor;
    }
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    .image-placeholder {
        background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
        border-color: #475569;
        color: #94a3b8;
    }
    
    .smart-image-wrapper {
        background: #1e293b;
    }
    
    .optimized-image[loading="lazy"] {
        background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    }
}

/* ================================
   PRINT STYLES
   ================================ */

@media print {
    .smart-image-wrapper,
    .optimized-image {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .optimized-image {
        max-width: 100% !important;
        height: auto !important;
    }
    
    .image-placeholder {
        display: none;
    }
}
