/**
 * mos77.ru - Редизайн галереи фотографий в записях
 */

/* Заголовок раздела «Фотографии» */
.entry-content h2[id^="fotografii"],
.entry-content h2:has(+ .gallery),
.entry-content h2:has(+ * > .gallery) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 40px;
    margin-bottom: 20px;
    font-size: 22px;
    font-weight: 700;
    color: #1e293b;
    position: relative;
    padding-bottom: 12px;
    border-bottom: 2px solid #eef2f6;
}

.entry-content h2[id^="fotografii"]::before,
.entry-content h2:has(+ .gallery)::before {
    content: "";
    display: inline-flex;
    width: 32px;
    height: 32px;
    background: #eff6ff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='4' ry='4'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21 15 16 10 5 21'/%3E%3C/svg%3E") no-repeat center center;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.12);
}

.gallery-count-badge {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    background: #f1f5f9;
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
}

/* Сетка галереи */
.entry-content .gallery {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 16px !important;
    margin: 20px 0 36px 0 !important;
    padding: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.entry-content .gallery::before,
.entry-content .gallery::after {
    display: none !important;
}

/* Колонки при явном указании в шорткоде */
.entry-content .gallery.gallery-columns-1 { grid-template-columns: 1fr !important; }
.entry-content .gallery.gallery-columns-2 { grid-template-columns: repeat(2, 1fr) !important; }
.entry-content .gallery.gallery-columns-4 { grid-template-columns: repeat(4, 1fr) !important; }

/* Карточка фотографии */
.entry-content .gallery .gallery-item {
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    border-radius: 16px !important;
    overflow: hidden !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03) !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.35s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.3s ease !important;
    box-sizing: border-box !important;
}

.entry-content .gallery .gallery-item:hover {
    transform: translateY(-5px) !important;
    box-shadow: 0 14px 28px -6px rgba(15, 23, 42, 0.15), 0 4px 10px rgba(15, 23, 42, 0.06) !important;
    border-color: #cbd5e1 !important;
}

/* Обертка картинки */
.entry-content .gallery .gallery-icon {
    position: relative !important;
    width: 100% !important;
    aspect-ratio: 4 / 3 !important;
    overflow: hidden !important;
    background: #f1f5f9 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.entry-content .gallery .gallery-icon a {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    position: relative !important;
    cursor: pointer !important;
    outline: none !important;
}

/* Картинка */
.entry-content .gallery .gallery-icon img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.35s ease !important;
}

.entry-content .gallery .gallery-item:hover .gallery-icon img {
    transform: scale(1.06) !important;
    filter: brightness(0.95) !important;
}

/* Полупрозрачное затемнение при наведении */
.entry-content .gallery .gallery-icon a::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.05) 0%, rgba(15, 23, 42, 0.32) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

/* Иконка лупы на карточке */
.entry-content .gallery .gallery-icon a::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.6);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%231e293b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3Cline x1='11' y1='8' x2='11' y2='14'%3E%3C/line%3E%3Cline x1='8' y1='11' x2='14' y2='11'%3E%3C/line%3E%3C/svg%3E") no-repeat center center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
    opacity: 0;
    z-index: 2;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.entry-content .gallery .gallery-item:hover .gallery-icon a::after {
    opacity: 1;
}

.entry-content .gallery .gallery-item:hover .gallery-icon a::before {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Подпись к фото */
.entry-content .gallery .gallery-caption {
    display: block !important;
    padding: 10px 14px 12px !important;
    font-size: 13px !important;
    line-height: 1.45 !important;
    color: #475569 !important;
    font-weight: 500 !important;
    text-align: center !important;
    margin: 0 !important;
    background: #ffffff !important;
    border-top: 1px solid #f1f5f9 !important;
}

/* Адаптивность сетки */
@media (max-width: 820px) {
    .entry-content .gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
}

@media (max-width: 560px) {
    .entry-content .gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        margin: 16px 0 28px 0 !important;
    }
    .entry-content .gallery .gallery-item {
        border-radius: 12px !important;
    }
    .entry-content .gallery .gallery-icon a::before {
        width: 38px;
        height: 38px;
        background-size: 16px;
    }
    .entry-content h2[id^="fotografii"],
    .entry-content h2:has(+ .gallery) {
        font-size: 19px;
        margin-top: 30px;
    }
}

@media (max-width: 360px) {
    .entry-content .gallery {
        grid-template-columns: 1fr !important;
    }
}

/* Полноэкранный просмотрщик галереи (Lightbox) */
.m77-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    background: rgba(10, 15, 29, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
    user-select: none;
    -webkit-user-select: none;
}

.m77-lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

/* Верхняя панель */
.m77-lightbox__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    z-index: 10;
    color: #ffffff;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%);
}

.m77-lightbox__info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.m77-lightbox__title {
    font-size: 16px;
    font-weight: 600;
    color: #f8fafc;
    letter-spacing: -0.01em;
    max-width: 450px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.m77-lightbox__counter {
    font-size: 13px;
    font-weight: 500;
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

.m77-lightbox__tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.m77-lightbox__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    padding: 0;
}

.m77-lightbox__btn:hover {
    background: rgba(255, 255, 255, 0.24);
    transform: scale(1.06);
}

.m77-lightbox__btn:active {
    transform: scale(0.94);
}

/* Основная область с фото и стрелками */
.m77-lightbox__main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 10px 80px 20px;
    overflow: hidden;
    box-sizing: border-box;
}

.m77-lightbox__image-wrap {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.m77-lightbox__img {
    max-width: 100%;
    max-height: calc(100vh - 160px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 1;
    transform: scale(1);
}

.m77-lightbox__img.is-loading {
    opacity: 0.3;
    transform: scale(0.98);
}

/* Стрелки навигации */
.m77-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    padding: 0;
}

.m77-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: translateY(-50%) scale(1.08);
}

.m77-lightbox__nav:active {
    transform: translateY(-50%) scale(0.95);
}

.m77-lightbox__nav--prev { left: 24px; }
.m77-lightbox__nav--next { right: 24px; }

/* Нижняя панель с подписью */
.m77-lightbox__footer {
    padding: 12px 24px 20px;
    text-align: center;
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 500;
    min-height: 24px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%);
}

.m77-lightbox__caption {
    max-width: 700px;
    margin: 0 auto;
    color: #cbd5e1;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* Мобильная адаптация лайтбокса */
@media (max-width: 768px) {
    .m77-lightbox__main {
        padding: 10px 16px 20px;
    }
    .m77-lightbox__img {
        max-height: calc(100vh - 140px);
        border-radius: 8px;
    }
    .m77-lightbox__nav {
        width: 44px;
        height: 44px;
        background: rgba(0, 0, 0, 0.4);
    }
    .m77-lightbox__nav--prev { left: 10px; }
    .m77-lightbox__nav--next { right: 10px; }
    .m77-lightbox__title {
        max-width: 200px;
        font-size: 14px;
    }
}
