/* Image Component - Cacao UI Framework */

.image {
    position: relative;
    display: inline-block;
    overflow: hidden;
    border-radius: 4px;
    background-color: #f8f9fa;
    border: 1px solid #e8e8e8;
    transition: all 0.3s ease;
}

.image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.image:hover img {
    transform: scale(1.05);
}

/* Image Placeholder */
.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background-color: #f8f9fa;
    color: #666;
    font-size: 14px;
    text-align: center;
    border: 2px dashed #e8e8e8;
}

.image-placeholder-icon {
    font-size: 48px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Image Loading State */
.image.loading {
    position: relative;
}

.image.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.image.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid #e8e8e8;
    border-top: 3px solid #8B4513;
    border-radius: 50%;
    animation: imageSpin 1s linear infinite;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
}

@keyframes imageSpin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Image Error State */
.image.error {
    background-color: #fff2f0;
    border-color: #ffccc7;
}

.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #ff4d4f;
    font-size: 14px;
    text-align: center;
    flex-direction: column;
}

.image-error-icon {
    font-size: 48px;
    margin-bottom: 8px;
    opacity: 0.7;
}

/* Image Sizes */
.image.small {
    width: 80px;
    height: 80px;
}

.image.medium {
    width: 120px;
    height: 120px;
}

.image.large {
    width: 200px;
    height: 200px;
}

.image.fullwidth {
    width: 100%;
    height: auto;
}

/* Image Shapes */
.image.circle {
    border-radius: 50%;
}

.image.rounded {
    border-radius: 8px;
}

.image.square {
    border-radius: 0;
}

/* Image Fit Options */
.image.fit-cover img {
    object-fit: cover;
}

.image.fit-contain img {
    object-fit: contain;
}

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

.image.fit-scale-down img {
    object-fit: scale-down;
}

/* Image Preview */
.image.preview {
    cursor: pointer;
    position: relative;
}

.image.preview::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0);
    transition: background-color 0.3s ease;
    z-index: 1;
}

.image.preview:hover::before {
    background-color: rgba(0, 0, 0, 0.1);
}

.image.preview::after {
    content: '🔍';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #fff;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
}

.image.preview:hover::after {
    opacity: 1;
}

/* Image Caption */
.image-caption {
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-top: 1px solid #e8e8e8;
    font-size: 12px;
    color: #666;
    text-align: center;
    line-height: 1.4;
}

/* Image Gallery */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.image-gallery .image {
    width: 100%;
    height: 150px;
}

/* Image Lazy Loading */
.image.lazy {
    background-color: #f8f9fa;
    background-image: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    background-size: 200% 100%;
    animation: imageLazyLoading 1.5s infinite;
}

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

/* Image Zoom */
.image.zoom {
    cursor: zoom-in;
}

.image.zoom:hover {
    transform: scale(1.02);
}

/* Image Overlay */
.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7));
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.image:hover .image-overlay {
    opacity: 1;
}

.image-overlay-content {
    color: #fff;
    padding: 12px;
    text-align: center;
    font-size: 12px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .image.large {
        width: 150px;
        height: 150px;
    }
    
    .image.medium {
        width: 100px;
        height: 100px;
    }
    
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
    
    .image-gallery .image {
        height: 120px;
    }
}

/* Accessibility */
.image:focus {
    outline: 2px solid #8B4513;
    outline-offset: 2px;
}

.image img {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .image {
        border: 2px solid #000;
    }
    
    .image-placeholder {
        border: 2px solid #000;
    }
    
    .image-caption {
        border-top: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .image {
        transition: none;
    }
    
    .image img {
        transition: none;
    }
    
    .image:hover img {
        transform: none;
    }
    
    .image:hover {
        transform: none;
    }
    
    .image.loading::after {
        animation: none;
    }
    
    .image.lazy {
        animation: none;
    }
    
    .image-overlay {
        transition: none;
    }
}

/* Print Styles */
@media print {
    .image {
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .image.preview::before,
    .image.preview::after {
        display: none;
    }
    
    .image-overlay {
        opacity: 0;
    }
}