/* ============================================
   CHAT PHOTO FEATURE - STABLE IMAGE MESSAGING
   WhatsApp/Telegram-style photo sharing
   ============================================ */

/* ========================================
   PHOTO UPLOAD BUTTON
   ======================================== */
.photo-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #757575;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.photo-btn:hover {
    background: rgba(233, 30, 99, 0.1);
    color: #E91E63;
    transform: scale(1.1);
}

.photo-btn:active {
    transform: scale(0.95);
}

/* ========================================
   IMAGE MESSAGE BUBBLES
   ======================================== */

/* Image container with aspect ratio preservation */
.message-image-container {
    position: relative;
    width: 100%;
    max-width: 280px;
    border-radius: 12px;
    overflow: hidden;
    background: #F5F5F5;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.message-image-container:hover {
    transform: scale(1.02);
}

.message-image-container:active {
    transform: scale(0.98);
}

/* Aspect ratio box - PREVENTS LAYOUT SHIFT */
.message-image-aspect {
    position: relative;
    width: 100%;
    padding-bottom: 75%; /* Default 4:3 aspect ratio */
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
}

/* Image itself */
.message-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* Loading skeleton animation */
.message-image-aspect::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.5),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Hide shimmer when image is loaded */
.message-image.loaded ~ .message-image-aspect::before {
    display: none;
}

/* Image message bubble adjustments */
.message.image-message .message-bubble {
    padding: 0;
    background: transparent;
    box-shadow: none;
}

.message.received.image-message .message-bubble {
    border-radius: 12px;
}

.message.sent.image-message .message-bubble {
    border-radius: 12px;
}

/* Image caption (optional) */
.message-image-caption {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    font-size: 14px;
    color: #212121;
    border-radius: 0 0 12px 12px;
}

.message.sent .message-image-caption {
    background: rgba(233, 30, 99, 0.95);
    color: white;
}

/* ========================================
   IMAGE LIGHTBOX (FULLSCREEN VIEW)
   ======================================== */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    backdrop-filter: blur(10px);
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    animation: zoomIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes zoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.lightbox-close:active {
    transform: rotate(90deg) scale(0.9);
}

/* ========================================
   PHOTO UPLOAD PROGRESS
   ======================================== */
.photo-upload-progress {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    min-width: 280px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.photo-upload-progress-bar {
    width: 100%;
    height: 4px;
    background: #E0E0E0;
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.photo-upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #E91E63 0%, #FF4081 100%);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.photo-upload-text {
    font-size: 14px;
    color: #757575;
    font-weight: 500;
}

/* ========================================
   ERROR STATES
   ======================================== */
.message-image-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #F44336;
}

.message-image-error svg {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
}

.message-image-error p {
    font-size: 12px;
    margin: 0;
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */
@media (max-width: 480px) {
    .message-image-container {
        max-width: 240px;
    }

    .lightbox-content {
        max-width: 95%;
        max-height: 95%;
    }

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

    .photo-upload-progress {
        min-width: 260px;
        bottom: 80px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.photo-btn:focus-visible,
.lightbox-close:focus-visible {
    outline: 2px solid #E91E63;
    outline-offset: 2px;
}

/* Keyboard navigation for lightbox */
.lightbox-overlay:focus {
    outline: none;
}

/* ========================================
   LOADING PLACEHOLDER
   ======================================== */
.message-image-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #E0E0E0;
    border-top-color: #E91E63;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Hide loading spinner when image is loaded */
.message-image.loaded ~ .message-image-loading {
    display: none;
}

/* ========================================
   TIMESTAMP ON IMAGE MESSAGES
   ======================================== */
.message.image-message .message-time {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    backdrop-filter: blur(4px);
}

/* ========================================
   PREVENT LAYOUT SHIFT
   ======================================== */
.message.image-message {
    will-change: auto; /* Don't trigger will-change for images */
}

.message-image-container {
    contain: layout; /* CSS containment for stability */
}
