/* Reset и базовые стили */
.gallery-item {
    margin-bottom: 20px;
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    transform: translateZ(0); /* Аппаратное ускорение */
    animation: fadeInUp 0.5s ease;
}

.gallery-item:hover {
    transform: translateY(-5px);
}

.photo-container {
    position: relative;
    cursor: pointer;
    background: #f8f9fa; /* Фон на время загрузки */
    min-height: 200px; /* Минимальная высота для сохранения места */
}

.photo-img {
    width: 100%;
    height: auto;
    display: block;
    opacity: 100;
    transition: opacity 0.3s ease;
}

.photo-img.loaded {
    opacity: 1;
}

.photo-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.3) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.4) 100%);
    opacity: 1;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    pointer-events: none; /* Позволяет кликать сквозь overlay */
}

.photo-top-actions {
    opacity: 0;
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    pointer-events: auto; /* Включаем события для кнопок */
}

.photo-bottom-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: auto; /* Включаем события для ссылок */
}
.photo-container:hover .photo-overlay .photo-top-actions{
    opacity: 1;
}


.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #e6e6e6;
    flex-shrink: 0;
}

.user-name {
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.photo-date {
    color: white;
    font-size: 0.8rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    flex-shrink: 0;
}

.btn-like, .btn-favorite {
    background: rgba(255,255,255,0.9);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    pointer-events: auto;
}

.btn-like:hover, .btn-favorite:hover {
    background: white;
    transform: scale(1.1);
}

.btn-like.liked {
    color: #dc3545;
}

.btn-favorite.favorited {
    color: #ffc107;
}

.album-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 5;
}

/* Lightbox стили */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    max-width: 90%;
    max-height: 90%;
    position: relative;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.lightbox-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #000;
    min-height: 300px;
    position: relative;
}

.lightbox-img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
    transition: opacity 0.3s ease;
}

.lightbox-info {
    padding: 20px;
    background: white;
    flex-shrink: 0;
}

.lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.lightbox-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.lightbox-actions .btn-like,
.lightbox-actions .btn-favorite {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
}

.lightbox-caption {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
    word-break: break-word;
}

.lightbox-description {
    color: #666;
    line-height: 1.5;
    margin-bottom: 15px;
    word-break: break-word;
}

.lightbox-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #888;
    flex-wrap: wrap;
    gap: 10px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.lightbox-close:hover {
    background: rgba(0,0,0,0.9);
    transform: scale(1.1);
}

/* Навигация в lightbox для альбомов - ВНЕ картинки */
.lightbox-navigation {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    align-items: center;
    transform: translateY(-50%);
    z-index: 100;
    pointer-events: none; /* Позволяет кликать сквозь навигацию */
}

/* Кнопки навигации вынесены за пределы контента */
.nav-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.5rem;
    color: #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    pointer-events: auto; /* Включаем события для кнопок */
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Левая кнопка - за пределами слева */
.nav-prev {
    transform: translateX(-70px);
}

/* Правая кнопка - за пределами справа */
.nav-next {
    transform: translateX(70px);
}

.nav-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
}

/* Для левой кнопки при hover сохраняем смещение */
.nav-prev:hover {
    transform: translateX(-70px) scale(1.1);
}

/* Для правой кнопки при hover сохраняем смещение */
.nav-next:hover {
    transform: translateX(70px) scale(1.1);
}

/* Счетчик альбома в нижней части картинки */
.album-counter {
    position: absolute;
    bottom: -200px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 500;
    z-index: 101;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Индикатор загрузки */
#loading {
    transition: opacity 0.3s ease;
    display: none;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* Уведомления */
.alert {
    border-radius: 10px;
    padding: 15px 20px;
    margin-bottom: 20px;
    border: 1px solid transparent;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Анимации */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Masonry улучшения */
.row {
    transition: height 0.3s ease;
}

/* Адаптивность */
@media (max-width: 768px) {
    .lightbox-content {
        max-width: 95%;
        max-height: 95%;
    }
    
    .lightbox-image-container {
        padding: 10px;
    }
    
    .lightbox-img {
        max-height: 50vh;
    }
    
    .lightbox-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .lightbox-actions {
        align-self: stretch;
        justify-content: flex-end;
    }
    
    .lightbox-caption {
        font-size: 1.3rem;
    }
    
    /* Адаптация навигации для планшетов */
    .nav-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    
    .nav-prev {
        transform: translateX(-50px);
    }
    
    .nav-next {
        transform: translateX(50px);
    }
    
    .nav-prev:hover {
        transform: translateX(-50px) scale(1.1);
    }
    
    .nav-next:hover {
        transform: translateX(50px) scale(1.1);
    }
    
    .album-counter {
        font-size: 0.9rem;
        padding: 8px 16px;
        bottom: 15px;
    }
    
    .user-name {
        max-width: 80px;
    }
}

@media (max-width: 480px) {
    .gallery-item {
        margin-bottom: 15px;
    }
    
    .photo-container {
        min-height: 150px;
    }
    
    .lightbox-content {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
    }
    
    .lightbox-info {
        padding: 15px;
    }
    
    .lightbox-caption {
        font-size: 1.1rem;
    }
    
    /* Адаптация навигации для мобильных */
    .nav-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
        position: fixed; /* Для мобильных делаем фиксированным */
    }
    
    .nav-prev {
        transform: translateX(-15px);
        left: 10px;
    }
    
    .nav-next {
        transform: translateX(15px);
        right: 10px;
    }
    
    .nav-prev:hover {
        transform: translateX(-15px) scale(1.1);
    }
    
    .nav-next:hover {
        transform: translateX(15px) scale(1.1);
    }
    
    .album-counter {
        font-size: 0.8rem;
        padding: 6px 12px;
        bottom: 10px;
    }
    
    .lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .user-name {
        max-width: 60px;
        font-size: 0.8rem;
    }
}

/* Для очень маленьких экранов */
@media (max-width: 360px) {
    .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .nav-prev {
        transform: translateX(-10px);
        left: 5px;
    }
    
    .nav-next {
        transform: translateX(10px);
        right: 5px;
    }
    
    .album-counter {
        font-size: 0.75rem;
        padding: 5px 10px;
    }
}

/* Улучшения для accessibility */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .photo-img,
    .lightbox-img,
    .nav-btn,
    .lightbox-close,
    .btn-like,
    .btn-favorite {
        transition: none;
        animation: none;
    }
    
    .nav-btn:hover {
        transform: none;
    }
    
    .nav-prev,
    .nav-next {
        transform: none;
    }
}

/* Поддержка высокого DPI */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .photo-img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Анимация появления кнопок навигации */
.lightbox.active .nav-btn {
    animation: slideIn 0.3s ease-out;
}

.lightbox.active .nav-prev {
    animation-delay: 0.1s;
}

.lightbox.active .nav-next {
    animation-delay: 0.2s;
}