/**
 * Image Grid Styles
 * Responsive layouts for 1-9 images in chat messages
 * Includes lightbox/modal styles
 */

/* Image Caption */
.image-caption {
    margin-bottom: 10px;
    color: #333;
    font-size: 14px;
    line-height: 1.4;
}

/* Single Image Container */
.image-container.single {
    max-width: 100%;
    margin: 10px 0;
}

.single-image {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: block;
}

.single-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Image Grid Base */
.image-grid {
    display: grid;
    gap: 8px;
    margin: 10px 0;
    max-width: 100%;
}

.grid-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: transparent;
}

.grid-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: block;
}

.grid-image:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

/* 2 Images - 2 columns */
.image-grid.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.image-grid.grid-2 .grid-item {
    aspect-ratio: 1 / 1;
}

/* 3 Images - 3 columns */
.image-grid.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.image-grid.grid-3 .grid-item {
    aspect-ratio: 1 / 1;
}

/* 4 Images - 2x2 grid */
.image-grid.grid-4 {
    grid-template-columns: repeat(2, 1fr);
}

.image-grid.grid-4 .grid-item {
    aspect-ratio: 1 / 1;
}

/* 5 Images - 2 large + 3 small */
.image-grid.grid-5 {
    grid-template-columns: repeat(4, 1fr);
}

.image-grid.grid-5 .grid-item:nth-child(1),
.image-grid.grid-5 .grid-item:nth-child(2) {
    grid-column: span 2;
    aspect-ratio: 4 / 3;
}

.image-grid.grid-5 .grid-item:nth-child(n+3) {
    aspect-ratio: 1 / 1;
}

/* 6 Images - 3x2 grid */
.image-grid.grid-6 {
    grid-template-columns: repeat(3, 1fr);
}

.image-grid.grid-6 .grid-item {
    aspect-ratio: 1 / 1;
}

/* 7 Images - 1 large + 6 small */
.image-grid.grid-7 {
    grid-template-columns: repeat(3, 1fr);
}

.image-grid.grid-7 .grid-item:nth-child(1) {
    grid-column: span 3;
    aspect-ratio: 16 / 9;
}

.image-grid.grid-7 .grid-item:nth-child(n+2) {
    aspect-ratio: 1 / 1;
}

/* 8 Images - 2 rows of 4 */
.image-grid.grid-8 {
    grid-template-columns: repeat(4, 1fr);
}

.image-grid.grid-8 .grid-item {
    aspect-ratio: 1 / 1;
}

/* 9 Images - 3x3 grid */
.image-grid.grid-9 {
    grid-template-columns: repeat(3, 1fr);
}

.image-grid.grid-9 .grid-item {
    aspect-ratio: 1 / 1;
}

/* More images indicator */
.image-more {
    margin-top: 5px;
    color: #666;
    font-size: 13px;
    font-style: italic;
}

/* Mobile Responsive - Tablets */
@media (max-width: 768px) {
    .single-image {
        max-height: 300px;
    }

    /* 3 images become 2 columns on tablet */
    .image-grid.grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .image-grid.grid-3 .grid-item:nth-child(3) {
        grid-column: span 2;
    }

    /* 5 images adjust layout */
    .image-grid.grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }

    .image-grid.grid-5 .grid-item:nth-child(1),
    .image-grid.grid-5 .grid-item:nth-child(2) {
        grid-column: span 1;
    }

    /* 7 images adjust layout */
    .image-grid.grid-7 {
        grid-template-columns: repeat(2, 1fr);
    }

    .image-grid.grid-7 .grid-item:nth-child(1) {
        grid-column: span 2;
    }

    /* 8 images become 2x4 */
    .image-grid.grid-8 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile Responsive - Phones */
@media (max-width: 480px) {
    .single-image {
        max-height: 250px;
    }

    .image-grid {
        gap: 6px;
    }

    /* All grids become 2 columns max on mobile */
    .image-grid.grid-3,
    .image-grid.grid-6,
    .image-grid.grid-9 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 5 images */
    .image-grid.grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 7 images */
    .image-grid.grid-7 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 8 images */
    .image-grid.grid-8 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===================================
   LIGHTBOX MODAL STYLES
   =================================== */

.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Lightbox Controls */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: fixed;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 12px;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    backdrop-filter: blur(10px);
    z-index: 10001;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.lightbox-close {
    top: 20px;
    right: 20px;
}

.lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-prev:hover {
    transform: translateY(-50%) scale(1.1);
}

.lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-next:hover {
    transform: translateY(-50%) scale(1.1);
}

/* Lightbox Counter */
.lightbox-counter {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    backdrop-filter: blur(10px);
}

/* Mobile Lightbox Adjustments */
@media (max-width: 768px) {
    .lightbox-content {
        max-width: 95%;
        max-height: 95%;
    }

    .lightbox-close,
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 20px;
        padding: 10px;
    }

    .lightbox-close {
        top: 10px;
        right: 10px;
    }

    .lightbox-prev {
        left: 10px;
    }

    .lightbox-next {
        right: 10px;
    }

    .lightbox-counter {
        bottom: 10px;
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .grid-image:hover {
        transform: none;
        opacity: 1;
    }

    .single-image:hover {
        transform: none;
        box-shadow: none;
    }

    /* Larger touch targets */
    .lightbox-close,
    .lightbox-prev,
    .lightbox-next {
        width: 44px;
        height: 44px;
    }
}

/* Loading State */
.message-image {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

.message-image[src] {
    background: none;
    animation: none;
}

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

/* Accessibility - Focus Styles */
.lightbox-close:focus,
.lightbox-prev:focus,
.lightbox-next:focus {
    outline: 2px solid #4a9eff;
    outline-offset: 2px;
}

.message-image:focus {
    outline: 2px solid #4a9eff;
    outline-offset: 2px;
}
