/* ================== Modal de Galería con Navegación ================== */
/* Estilos específicos para el modal de galería con sistema de navegación */

:root {
    --modal-bg: rgba(0, 0, 0, 0.9);
    --modal-content-bg: #ffffff;
    --modal-border: #e0e1e3;
    --zikpic-green: #81d742;
    --zikpic-dark-green: #6bb536;
    --text-dark: #2E3440;
    --text-light: #5E6E6D;
}

/* ================== Modal Base ================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--modal-bg);
    z-index: 9999;
    display: flex; /* Oculto por defecto */
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    display: flex; /* Mostrar cuando esté activo */
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-container {
    width: 95vw;
    height: 98vh;
    max-width: 1300px;
    background: var(--modal-content-bg);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    position: relative;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-overlay.active .modal-container {
    transform: scale(1) translateY(0);
}

/* ================== Navegación con flechas ================== */
.modal-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    transition: all 0.3s ease;
    font-size: 1.5rem;
    color: var(--text-dark);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.modal-nav-arrow:hover {
    background: var(--zikpic-green);
    color: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(129, 215, 66, 0.4);
}

.modal-nav-arrow.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.modal-nav-arrow.prev {
    left: -60px;
}

.modal-nav-arrow.next {
    right: -60px;
}

/* Indicador de progreso */
.modal-progress {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 10000;
}

/* ================== Botón de cerrar ================== */
.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(63, 63, 63, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10000;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Por defecto, mostrar solo desktop */
.modal-close-mobile {
    display: none;
}

.modal-close-desktop {
    display: flex;
}

.modal-close:hover {
    background: #a8a8a8;
    transform: scale(1.1);
    color: #ffffff!important;
}

/* ================== Botón de menú (3 puntos) ================== */
.modal-media-menu-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10001;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}
@media (max-width: 768px) {
    .modal-media-menu-btn {
    right: unset;
    left: 10px;
}
}

.modal-media-menu-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.modal-media-menu-btn:active {
    transform: scale(0.95);
}

/* ================== Contenido del modal ================== */
.modal-media-section {
    flex: 1;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Limitar al ancho máximo de las imágenes (900px) */
    width: 100%;
    max-width: 900px; /* Ancho máximo de las imágenes */
    max-height: 98vh;
}

.modal-media-content {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
    display: block;
}

.modal-media-content.loading {
    opacity: 0.5;
}

/* Reglas específicas para videos */
.modal-media-content video {
    max-width: 100%;
    max-height: 100vh;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Reglas específicas para imágenes */
.modal-media-content img {
    max-width: 100%;
    max-height: 100vh;
    width: auto; /* 🎯 CORREGIDO: auto en lugar de 100% para evitar franjas */
    height: auto; /* 🎯 CORREGIDO: auto en lugar de 100% */
    object-fit: contain; /* Mantener aspecto sin recortar */
}

/* Spinner de carga */
.modal-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ================== Sidebar de información ================== */
.modal-sidebar {
    width: 400px;
    background: var(--modal-content-bg);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--modal-border);
    overflow: hidden; /* Prevenir overflow del sidebar completo */
    max-height: 100%; /* Asegurar que no exceda la altura del modal */
}

.modal-header {
  /*   padding: 16px 20px;
    border-bottom: 1px solid var(--modal-border);
    background: #fafbfc;*/
    flex-shrink: 0; 
}

/* ================== Acciones del modal ================== */
.modal-actions {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--modal-border);
    background: var(--modal-content-bg);
    flex-shrink: 0; /* No se comprime */
}

.modal-author {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-author-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--zikpic-green);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1.2rem;
}

.modal-author-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.modal-author-info h3 {
    /* margin: 0 0 4px 0; */
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
}

.modal-author-info p {
    margin: 0;
    color: var(--text-light);
    font-size: 0.9rem;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.modal-description {
    color: var(--text-light);
    line-height: 1.5;
    margin: 0;
}

/* ================== Acciones del modal ================== */
.modal-actions {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--modal-border);
    background: var(--modal-content-bg);
    flex-shrink: 0; /* No se comprime */
}

.action-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-light);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s;
    padding: 6px 10px;
    border-radius: 8px;
    transition: all 0.2s;
}

.action-item:hover {
    color: var(--zikpic-green);
    background: rgba(129, 215, 66, 0.1);
}

.action-item.liked {
    color: #e74c3c;
}

.action-item i {
    font-size: 1.1rem;
}

/* ================== Responsive ================== */
@media (max-width: 1024px) {
    .modal-container {
        width: 100vw;
        height: 100vh;
        flex-direction: column;
        border-radius: 0px;
    }
    
    .modal-sidebar {
        width: 100%;
        height: 50%;
        border-left: none;
        border-top: 1px solid var(--modal-border);
    }
    
    .modal-media-section {
        height: 50%;
        max-width: 100vw;
    }
    
    .modal-media-content img,
    .modal-media-content video {
        max-height: 50vh;
        max-width: 100vw;
    }
    
    .modal-nav-arrow {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
    
    .modal-nav-arrow.prev {
        left: 15px;
    }
    
    .modal-nav-arrow.next {
        right: 15px;
    }
}

@media (max-width: 768px) {
    /* ================== NUEVO DISEÑO MÓVIL - TODO EN UN SOLO SCROLL ================== */
    
    .modal-overlay {
        background: white; /* Fondo blanco en móvil para el scroll */
    }
    
    .modal-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: none; /* Permitir altura mayor al viewport para scroll */
        border-radius: 0; /* Sin bordes redondeados en móvil */
        flex-direction: column; /* Cambiar a columna vertical */
        overflow-y: auto; /* Hacer todo scrolleable */
        overflow-x: hidden;
        display: block; /* Cambiar de flex a block para scroll natural */
        padding-bottom: 60px; /* Espacio extra al final para ver todo el contenido */
        position: relative;
        z-index: 1; /* Por debajo de la X */
    }
    
    /* MÓVIL: Ocultar botón desktop, mostrar botón móvil */
    .modal-close-desktop {
        display: none !important;
    }
    
    .modal-close-mobile {
        display: flex !important;
        position: fixed !important; /* Fijo al viewport, FUERA del container */
        top: 15px !important;
        right: 15px !important;
        width: 44px !important;
        height: 44px !important;
        font-size: 1.4rem !important;
        z-index: 99999 !important; /* Máxima prioridad sobre TODO */
        background: rgba(0, 0, 0, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(8px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        pointer-events: auto !important; /* Siempre clickeable */
        cursor: pointer !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Sección de imagen/video - Parte natural del scroll, ancho completo */
    .modal-media-section {
        width: 100vw !important; /* Ancho completo del viewport */
        height: auto; /* Altura automática según la imagen */
        min-height: auto;
        max-height: none;
        max-width: 100vw;
        position: relative;
        background: #000;
        display: block;
        padding: 0; /* Sin padding */
        margin: auto !important; /* Sin margin */
    }
    
    .modal-media-content {
        width: 100vw !important; /* Ancho completo */
        height: auto;
        display: block;
        padding: 0;
        margin: auto !important;
    }
    
    .modal-media-content img,
    .modal-media-content video {
        width: auto !important; /* 🎯 CORREGIDO: auto para evitar franjas en imágenes cuadradas */
        height: auto !important;
        max-width: 100vw !important;
        display: block;
        object-fit: contain;
        padding: 0;
        margin: 0;
    }
    
    /* Flechas de navegación sobre la imagen (no fijas, scrollean con la imagen) */
    .modal-nav-arrow.mobile-nav {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        background: rgba(0, 0, 0, 0.6);
        color: white;
        backdrop-filter: blur(4px);
    }
    
    .modal-nav-arrow.mobile-nav.prev {
        left: 10px;
    }
    
    .modal-nav-arrow.mobile-nav.next {
        right: 10px;
    }
    
    /* Ocultar flechas desktop en móvil */
    .modal-nav-arrow.desktop-nav {
        display: none;
    }
    
    /* Sidebar ahora es contenido normal debajo de la imagen */
    .modal-sidebar {
        width: 100%; /* Ancho completo */
        height: auto; /* Altura automática según contenido */
        position: relative; /* Posición normal */
        border-left: none; /* Sin borde lateral */
        /*overflow-y: visible;  Parte del scroll global */
        display: block !important; /* Block para flow natural */
        flex: none !important;
        overflow: visible !important;
        background: white;
    }
    
    /* FORZAR que header NO se pegue */
    .modal-overlay .modal-container .modal-sidebar .modal-header,
    .modal-sidebar .modal-header,
    .modal-header {
        display: block !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        padding: 16px !important;
        flex-shrink: 0 !important;
    }
    
    /* FORZAR que autor NO se pegue */
    .modal-author {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
    }
    
    .modal-author {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 12px;
    }
    
    .modal-title {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
    
    .modal-description {
        font-size: 0.9rem;
    }
    
    /* Acciones (likes, vistas) - FORZAR posición relativa */
    .modal-overlay .modal-container .modal-sidebar .modal-actions,
    .modal-sidebar .modal-actions,
    .modal-actions {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        padding: 12px 16px !important;
        gap: 16px;
        border-top: 1px solid var(--modal-border);
        border-bottom: 1px solid var(--modal-border);
        flex-shrink: 0 !important;
        display: flex !important;
    }
    
    .action-item {
        padding: 8px;
        font-size: 0.9rem;
        position: relative !important;
    }
    
    /* Sección de comentarios - parte natural del scroll */

    .comments-header {
        display: flex;
        flex-direction: row;
    }

    .modal-comments-section {
        height: auto !important; /* Altura automática */
        min-height: auto !important;
        max-height: none !important;
        overflow-y: visible !important; /* Parte del scroll global */
        display: block !important;
    }
    
    /* FORZAR que lista de comentarios sea parte del flujo natural */
    .modal-overlay .modal-container .modal-sidebar .modal-comments-section .comments-list,
    .comments-list {
        flex: none !important;
        overflow-y: visible !important;
        overflow-x: hidden !important;
        height: auto !important;
        max-height: none !important;
        min-height: auto !important;
        display: block !important;
        position: relative !important;
    }

    /* FORZAR que header de comentarios NO se pegue */
    .modal-overlay .modal-container .modal-sidebar .modal-comments-section .comments-header,
    .modal-comments-section .comments-header,
    .comments-header {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        display: flex !important;
        flex-direction: row !important;
        flex-shrink: 0 !important;
    }

    /* Mostrar composer natural (no botón flotante) - FORZAR posición relativa */
    .modal-overlay .modal-container .modal-sidebar .comment-composer,
    .modal-overlay .modal-container .modal-sidebar .modal-comments-section .comment-composer,
    .modal-sidebar .comment-composer,
    .modal-comments-section .comment-composer,
    .comment-composer {
        display: block !important; /* Forzar mostrar composer */
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        padding: 16px !important;
        background: white !important;
        border-top: 1px solid var(--modal-border);
        height: auto !important;
        transform: none !important; /* Remover cualquier transform que lo oculte */
    }
    
    /* Footer del composer también relativo */
    .comment-composer-footer {
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
    }
    
    /* Textarea del composer visible */
    .comment-composer textarea,
    .comment-composer .comment-input {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Botones del composer visibles */
    .comment-composer .comment-actions,
    .comment-composer button {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Botón flotante para scroll al composer - SOLO MOBILE */
    .masonry-scroll-to-composer-btn {
        position: fixed !important;
        bottom: 80px !important;
        right: 20px !important;
        width: 56px !important;
        height: 56px !important;
        background: linear-gradient(135deg, #6bb536 0%, #81d742 100%) !important;
        border: none !important;
        border-radius: 50% !important;
        color: white !important;
        font-size: 24px !important;
        cursor: pointer !important;
        box-shadow: 0 4px 12px rgba(129, 215, 66, 0.4) !important;
        z-index: 99999 !important;
        display: none;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
    }

    .masonry-scroll-to-composer-btn.visible {
        display: flex !important;
    }

    .masonry-scroll-to-composer-btn:active {
        transform: scale(0.95);
    }

    /* Asegurar scroll suave en el container */
    .modal-container {
        scroll-behavior: smooth !important;
    }
    
    /* Mensaje de comentarios vacíos - asegurar visibilidad completa */
    .modal-comments-section .empty-comments,
    .modal-comments-section .comments-empty {
        padding: 40px 20px !important;
        margin-bottom: 30px !important;
        text-align: center;
    }
    
    /* Progress indicator fijo */
    .modal-progress {
        position: fixed; /* Fijo como la X */
        top: 15px;
        left: 15px;
        font-size: 0.85rem;
        padding: 6px 12px;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        backdrop-filter: blur(4px);
        z-index: 10001;
    }
}

/* ================== Animaciones de transición ================== */
.modal-content-transition {
    transition: all 0.3s ease;
}

.modal-content-transition.loading {
    opacity: 0.7;
    transform: scale(0.98);
}

/* Efecto de entrada */
@keyframes modalEnter {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-container.entering {
    animation: modalEnter 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ================== Estados especiales ================== */
.modal-overlay.loading .modal-container {
    pointer-events: none;
}

.modal-sidebar.comments-expanded .modal-comments-section {
    flex: 1;
}

/* ================== Sección de Comentarios ================== */
.modal-comments-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Importante para que funcione el scroll */
    height: 100%; /* Asegurar altura completa disponible */
    max-height: 100%; /* Prevenir desbordamiento */
    overflow: hidden; /* Prevenir overflow del contenedor padre */
    box-sizing: border-box; /* Incluir padding en cálculos de tamaño */
    /* ELIMINAR padding para maximizar espacio */
    padding: 0;
    margin: 0;
}

/* Contenedor que incluye header y composer - altura fija */
.comments-header,
.comment-composer {
    flex-shrink: 0; /* No se comprimen */
}

/* Header de comentarios - MÁS compacto */
.modal-comments-section .comments-header {
    padding: 8px 16px 4px 16px; /* Muy reducido */
    margin-bottom: 4px; /* Mínimo margen */
}

/* Composer - MÁS compacto */
.modal-comments-section .comment-composer {
    padding: 8px 16px; /* Muy reducido */
    margin-bottom: 0; /* SIN margen inferior */
}

.comments-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 16px 8px 16px;
    margin: 0;
    min-height: 0;
    max-height: none;
    height: 100%;
    border: none;
    outline: none;
    scroll-behavior: smooth;
    box-sizing: border-box;
    word-wrap: break-word;
    word-break: break-word;
    scrollbar-width: thin !important;
    scrollbar-color: rgba(129, 215, 66, 0.6) rgba(255, 255, 255, 0.05) !important;
    -ms-overflow-style: none;
}

/* Ocultar scrollbar en Chrome, Safari y Opera */
.comments-list::-webkit-scrollbar {
    display: none;
}

/* Mensaje de comentarios vacíos */
.empty-comments {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: #666;
    min-height: 200px;
}

.empty-comments i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
    color: var(--zikpic-green);
}

.empty-comments p {
    font-size: 1.1rem;
    margin: 0;
}

/* Loading state */
.loading-comments {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #666;
}

.loading-comments i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--zikpic-green);
}

/* Ocultar scrollbar en Firefox */
.modal-sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--modal-border) transparent;
}

/* ================== OPTIMIZACIONES PARA MAXIMIZAR ESPACIO DE COMENTARIOS ================== */
/* Reducir padding de acciones para más espacio */
.modal-sidebar .modal-actions {
    padding: 10px 20px; /* Más compacto */
}

/* Optimizar espacio en responsive */
@media (max-width: 1024px) {
    .modal-sidebar .modal-header {
        padding: 12px 16px; /* Más compacto en pantallas pequeñas */
    }
    
    .modal-sidebar .modal-actions {
        padding: 8px 16px; /* Más compacto en pantallas pequeñas */
    }
    
    .modal-comments-section .comments-header {
        padding: 8px 12px 6px 12px; /* Más compacto */
    }
    
    .modal-comments-section .comment-composer {
        padding: 8px 12px; /* Más compacto */
    }
}

/* ================== Fin estilos modal galería ================== */