/* =============================================================================
   STANDARDIZED IMAGE DISPLAY SYSTEM
   Provides consistent image display across all pages
   ============================================================================= */

/* Base image container classes */
.img-container {
    position: relative;
    overflow: hidden;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-container img {
    transition: transform 0.3s ease;
    width: 100%;
    height: 100%;
}

/* Aspect ratio containers */
.img-aspect-square {
    aspect-ratio: 1 / 1;
}

.img-aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.img-aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.img-aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* Display modes with smart cropping */
.img-cover img {
    object-fit: cover;
    object-position: center center;
}

.img-contain img {
    object-fit: contain;
    object-position: center;
    padding: 0.5rem;
}

.img-fill img {
    object-fit: fill;
}

/* Add direct classes for object-fit properties */
.object-contain {
    object-fit: contain;
    object-position: center;
}

.object-cover {
    object-fit: cover;
    object-position: center center;
}

.object-fill {
    object-fit: fill;
}

/* Special class for subcategory 16:9 hero images - stretched sideways to fill container width */
.subcategory-hero-16x9 {
    object-fit: fill;
    object-position: center;
    width: 100%;
    height: 100%;
}

/* Size variants */
.img-thumbnail {
    width: 64px;
    height: 64px;
}

.img-small {
    width: 200px;
    height: 150px;
}

.img-medium {
    width: 400px;
    height: 300px;
}

.img-large {
    width: 600px;
    height: 450px;
}

/* Responsive image classes */
.img-responsive-card {
    width: 100%;
    height: 200px;
}

@media (min-width: 768px) {
    .img-responsive-card {
        height: 240px;
    }
}

@media (min-width: 1024px) {
    .img-responsive-card {
        height: 280px;
    }
}

/* Product-specific display modes with smart cropping */
.product-card-image {
    object-fit: cover !important;
    object-position: center center;
    width: 100%;
    height: 100%;
}

.product-detail-image {
    object-fit: contain;
    object-position: center;
    width: 100%;
    height: auto;
    max-height: 500px;
}

.product-thumbnail-image {
    object-fit: cover;
    object-position: center;
    width: 64px;
    height: 64px;
    border-radius: 0.5rem;
}

/* Hover effects */
.img-hover-zoom:hover img {
    transform: scale(1.05);
}

.img-hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Enhanced Universal Image Loading States and Optimizations */
.img-loading {
    background-color: #f0f0f0;
    min-height: 200px;
}

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

/* Enhanced Error State */
.img-error {
    background-color: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 0.875rem;
    min-height: 200px;
}

/* Responsive Image Container */
.responsive-img-container {
    position: relative;
    overflow: hidden;
}

.responsive-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all 0.3s ease;
}

/* Enhanced Hover Effects */
.hover-zoom:hover img {
    transform: scale(1.05);
}

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

/* Lazy Loading Intersection Observer Support */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-image.loaded {
    opacity: 1;
}

/* Fallback handling */
.img-fallback {
    background-color: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 0.75rem;
    text-align: center;
    padding: 1rem;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .hover-zoom:hover img {
        transform: none; /* Disable zoom on mobile */
    }
    
    .responsive-img-container img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .responsive-img-container img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Error states */
.img-error {
    background-color: #fee2e2;
    color: #dc2626;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    text-align: center;
}

.img-error::before {
    content: "⚠️";
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

/* Lazy loading optimizations */
.img-lazy {
    opacity: 0;
    transition: opacity 0.3s;
}

.img-lazy.loaded {
    opacity: 1;
}

/* Print optimizations */
@media print {
    .img-container img {
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
    }
}

/* CKEditor image styles */
.figure {
    display: table;
    margin: 1em auto;
    text-align: center;
}

.figure.image-style-side {
    float: right;
    margin-left: var(--ck-image-figure-side-margin, 1.5em);
    margin-right: 0;
    max-width: 50%;
    width: auto !important;
    height: auto !important;
}

.figure.image-style-align-left {
    float: left;
    margin-right: 1.5em;
    margin-left: 0;
    max-width: 50%;
}

.figure.image-style-align-center {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.figure.image-style-align-right {
    float: right;
    margin-left: 1.5em;
    margin-right: 0;
    max-width: 50%;
}

img.image-style-side {
    width: auto !important;
    max-width: 100%;
    height: auto !important;
}

img.image-style-align-left {
    float: left;
    margin-right: 1.5em;
}

img.image-style-align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

img.image-style-align-right {
    float: right;
    margin-left: 1.5em;
}

/* Clear floats after images */
.clear-floats {
    clear: both;
}

/* Ensure proper text wrapping around floated images */
.article-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

.article-content p {
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

/* Make sure content flows around floated images */
.article-content > * {
    clear: none;
}

/* Specific rule for paragraphs that should accommodate floated images */
.article-content p:not(.image-style-side) {
    overflow: visible;
    clear: none;
}

/* Make sure figures with images don't break text flow */
.article-content figure.image-style-side {
    margin-top: 0;
    margin-bottom: 1rem;
}

/* Content container for CKEditor content with proper text wrapping */
.blog-content-html {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.6;
}

.blog-content-html p {
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* Ensure proper text wrapping around floated images */
.blog-content-html figure,
.blog-content-html .image {
    margin: 1em 0;
}

/* Side image style - floats image to right with text wrapping */
.blog-content-html .image-style-side {
    float: right;
    margin-left: 1.5em;
    margin-right: 0;
    max-width: 50%;
    width: auto !important;
    height: auto !important;
}

/* Left aligned image */
.blog-content-html .image-style-align-left {
    float: left;
    margin-right: 1.5em;
    margin-left: 0;
    max-width: 50%;
}

/* Center aligned image */
.blog-content-html .image-style-align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

/* Right aligned image */
.blog-content-html .image-style-align-right {
    float: right;
    margin-left: 1.5em;
    margin-right: 0;
    max-width: 50%;
}

/* Clear floats when needed */
.blog-content-html .image-style-block {
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    clear: both;
}

/* Make sure text flows properly around images */
.blog-content-html > *:not(.image-style-side):not(.image-style-align-left):not(.image-style-align-right) {
    clear: none;
    overflow: visible;
}

/* Clear after images when needed */
.blog-content-html .clear {
    clear: both;
    display: table;
    content: "";
    width: 100%;
}

/* Blog content image float styles - preserve CKEditor inline styles */
.blog-content-html img[style*="float: right"],
.blog-content-html img[style*="float:right"] {
    float: right;
    margin: 0 0 1rem 1rem;
}

.blog-content-html img[style*="float: left"],
.blog-content-html img[style*="float:left"] {
    float: left;
    margin: 0 1rem 1rem 0;
}

/* Support for width and height from inline styles */
.blog-content-html img[style*="width:"] {
    width: auto !important;
    height: auto !important;
}

/* Ensure text wraps around floated images */
.blog-content-html p {
    overflow: auto;
    clear: none;
}

/* Make sure container allows floats */
.blog-content-html {
    overflow: visible;
    clear: none;
}

/* Clear floats when needed */
.blog-content-html .clearfix::after {
    content: "";
    display: table;
    clear: both;
}