/**
 * Image Gallery Component
 * Telegram-style image viewer with sender info, actions, and message text
 */

/* ===== Gallery Container ===== */
.image-gallery {
    /* CSS Custom Properties */
    --gallery-backdrop: rgba(0, 0, 0, 0.95);
    --gallery-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --gallery-nav-color: rgba(255, 255, 255, 0.9);
    --gallery-nav-hover: rgba(255, 255, 255, 1);
    --gallery-control-bg: rgba(0, 0, 0, 0.6);
    --gallery-control-hover: rgba(0, 0, 0, 0.8);
}

.image-gallery {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--gallery-backdrop);
    z-index: var(--z-modal, 1050);
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: var(--gallery-transition);
}

.image-gallery.active {
    display: flex;
    opacity: 1;
}

/* ===== Gallery Header ===== */
.gallery-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
    z-index: 2;
}

/* Sender Info (Left Side) */
.gallery-sender-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gallery-sender-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.gallery-sender-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-sender-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.gallery-sender-name {
    color: white;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.gallery-sender-time {
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    line-height: 1.2;
}

/* Actions (Right Side) */
.gallery-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gallery-action-btn {
    background: var(--gallery-control-bg);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: var(--gallery-transition);
    backdrop-filter: blur(10px);
}

.gallery-action-btn:hover {
    background: var(--gallery-control-hover);
    transform: scale(1.1);
}

.gallery-action-btn .material-symbols-outlined {
    font-size: 20px;
}

/* ===== Gallery Counter ===== */
.gallery-counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gallery-control-bg);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    z-index: 2;
}

/* ===== Gallery Image Container ===== */
.gallery-image-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 80px 120px 80px; /* Space for header, arrows, and caption */
}

.gallery-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    border-radius: 4px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
}

/* ===== Gallery Navigation Arrows ===== */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gallery-control-bg);
    border: none;
    color: var(--gallery-nav-color);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: var(--gallery-transition);
    z-index: 2;
    backdrop-filter: blur(10px);
}

.gallery-nav:hover {
    background: var(--gallery-control-hover);
    color: var(--gallery-nav-hover);
    transform: translateY(-50%) scale(1.1);
}

.gallery-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.gallery-nav:disabled:hover {
    background: var(--gallery-control-bg);
    transform: translateY(-50%);
}

.gallery-nav-prev {
    left: 20px;
}

.gallery-nav-next {
    right: 20px;
}

/* ===== Gallery Caption / Message Text ===== */
.gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 150px;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
    color: white;
    font-size: 15px;
    line-height: 1.5;
    text-align: center;
    z-index: 2;
    display: none; /* Hidden by default, shown when text exists */
}

.gallery-caption::-webkit-scrollbar {
    width: 4px;
}

.gallery-caption::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.gallery-caption::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* ===== Gallery Loading Spinner ===== */
.gallery-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 0;
}

/* ===== Animations ===== */
@keyframes imageZoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Slide animation for navigation */
.gallery-image.slide-in-left {
    animation: slideInLeft 0.3s ease;
}

.gallery-image.slide-in-right {
    animation: slideInRight 0.3s ease;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== Zoom Feature ===== */
.gallery-image.zoomed {
    transform: scale(2);
    cursor: zoom-out;
}

.gallery-image:not(.zoomed) {
    cursor: zoom-in;
}

/* ===== Touch Indicators ===== */
.gallery-swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 60px;
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1;
}

.gallery-swipe-indicator.left {
    left: 20px;
}

.gallery-swipe-indicator.right {
    right: 20px;
}

.gallery-swipe-indicator.active {
    opacity: 1;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .gallery-header {
        padding: 12px 15px;
    }

    .gallery-sender-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .gallery-sender-name {
        font-size: 14px;
    }

    .gallery-sender-time {
        font-size: 12px;
    }

    .gallery-action-btn {
        width: 36px;
        height: 36px;
    }

    .gallery-action-btn .material-symbols-outlined {
        font-size: 18px;
    }

    .gallery-counter {
        top: 15px;
        font-size: 12px;
        padding: 6px 12px;
    }

    .gallery-image-container {
        padding: 70px 60px 100px 60px;
    }

    .gallery-nav {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }

    .gallery-nav-prev {
        left: 10px;
    }

    .gallery-nav-next {
        right: 10px;
    }

    .gallery-caption {
        font-size: 14px;
        padding: 15px;
        max-height: 120px;
    }
}

@media (max-width: 480px) {
    .gallery-sender-info {
        gap: 8px;
    }

    .gallery-sender-avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .gallery-sender-name {
        font-size: 13px;
    }

    .gallery-sender-time {
        font-size: 11px;
    }

    .gallery-actions {
        gap: 4px;
    }

    .gallery-action-btn {
        width: 32px;
        height: 32px;
    }

    .gallery-action-btn .material-symbols-outlined {
        font-size: 16px;
    }

    .gallery-image-container {
        padding: 65px 50px 90px 50px;
    }

    .gallery-nav {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }

    .gallery-caption {
        font-size: 13px;
        padding: 12px;
    }
}
