/* ==========================================================================
   АККОРДЕОН РЕЛИГИЙ - УЛЬТРАКОМПАКТНЫЙ И ОПТИМИЗИРОВАННЫЙ
   Версия 3.3: Совместимость с обновленным JavaScript
   ========================================================================== */

/* --------------------------------------------------
   ОБЩИЕ СТИЛИ - БАЗОВЫЕ ДЛЯ ВСЕХ УСТРОЙСТВ
   -------------------------------------------------- */
#religion-accordion {
    position: relative;
    z-index: 1000;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    height: fit-content;
    overflow-x: hidden;
    min-width: 260px;
}

#religion-accordion.active {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.religion-menu {
    list-style: none;
    margin: 0;
    padding: 0rem;
}
.religion-menu li {margin-bottom: 0px;}

/* --------------------------------------------------
   АДАПТИВНАЯ ШИРИНА ДЛЯ ВСЕХ УСТРОЙСТВ
   -------------------------------------------------- */
@media (min-width: 769px) {
    #religion-accordion {
        width: 300px;
        min-width: 260px;
        /* ИЗМЕНЕНИЕ: Убраны ограничения высоты для ПК */
        max-height: none !important;
        overflow-y: visible !important;
    }
}

@media (max-width: 768px) {
    #religion-accordion {
        width: min(300px, 90vw);
        max-height: 100vh;
        overflow-y: auto;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* --------------------------------------------------
   КЛЮЧЕВЫЕ ИЗМЕНЕНИЯ: КОМПАКТНЫЕ ЭЛЕМЕНТЫ
   -------------------------------------------------- */

/* Базовые стили элементов */
.religion-item {
    position: relative;
    margin-bottom: 0.375rem;
    border-radius: 6px;
    background: #ffffff;
    border: 1px solid #f3f4f6;
    overflow: hidden;
    transition: all 0.2s ease;
    padding: 0.5rem 0.75rem;
    animation: fadeInUp 0.4s ease forwards;
    opacity: 0;
    transform: translateY(8px);
}

.religion-item:nth-child(1) { animation-delay: 0.05s; }
.religion-item:nth-child(2) { animation-delay: 0.1s; }
.religion-item:nth-child(3) { animation-delay: 0.15s; }
.religion-item:nth-child(4) { animation-delay: 0.2s; }

.religion-item:hover {
    transform: translateY(-1px);
    border-color: rgba(var(--color-sky-base-rgb), 0.2);
    box-shadow: 0 2px 8px rgba(var(--color-sky-base-rgb), 0.08);
}

/* УРОВЕНЬ 2 - КОМПАКТНЫЙ */
.sub-religions > .religion-item {
    padding: 0.4375rem 0.625rem;
    padding-left: 0.5rem;
    border-radius: 5px;
    background: #f9fafb;
    margin-bottom: 0.25rem;
    border: 1px solid #f1f5f9;
}

/* УРОВЕНЬ 3 - УЛЬТРАКОМПАКТНЫЙ */
.sub-religions .sub-religions > .religion-item {
    padding: 0.375rem 0.5rem;
    padding-left: 1rem;
    font-size: 0.9em;
    border-radius: 4px;
    margin-bottom: 0.125rem;
}

/* УРОВЕНЬ 4+ - МИНИМАЛИСТИЧНЫЙ */
.sub-religions .sub-religions .sub-religions > .religion-item {
    padding: 0.3125rem 0.375rem;
    padding-left: 0.75rem;
    font-size: 0.85em;
    border-radius: 3px;
    margin-bottom: 0.0625rem;
}

/* --------------------------------------------------
   ОПТИМИЗИРОВАННЫЕ ИКОНКИ
   -------------------------------------------------- */

.religion-icon {
    width: 36px;
    height: 36px;
    margin-right: 0.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--color-sky-base-rgb), 0.08);
    border-radius: 100%;
    padding: 0;
    border: 1px solid rgba(var(--color-sky-base-rgb), 0.12);
    transition: all 0.25s ease;
    overflow: hidden;
}

.religion-icon-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    padding: 2px;
    box-sizing: border-box;
    transition: transform 0.25s ease;
}

.religion-icon svg {
    width: 20px;
    height: 20px;
    fill: var(--color-sky-light);
    transition: all 0.25s ease;
}

.religion-icon i {
    font-size: 16px;
    color: var(--color-sky-base);
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Компактные иконки для вложенных уровней */
.sub-religions .religion-icon {
    width: 32px;
    height: 32px;
    margin-right: 0.4375rem;
}

.sub-religions .sub-religions .religion-icon {
    width: 28px;
    height: 28px;
    margin-right: 0.375rem;
}

.sub-religions .sub-religions .sub-religions .religion-icon {
    width: 24px;
    height: 24px;
    margin-right: 0.3125rem;
}

/* --------------------------------------------------
   СТИЛИ ТЕКСТА И ССЫЛОК
   -------------------------------------------------- */
.religion-item-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px;
}

.religion-link {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0;
    color: #1f2937;
    text-decoration: none !important;
    transition: all 0.25s ease;
}

.religion-title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 10px);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    color: #374151;
    transition: all 0.25s ease;
}

.religion-link:hover .religion-title {
    color: var(--color-sky-dark);
    text-decoration: none;
}

.religion-item.current-menu-item .religion-title,
.religion-item.current-menu-ancestor .religion-title {
    color: #1b4260;
    font-weight: 400;
}

.religion-item.current-menu-item .religion-title {
    color: var(--color-sky-dark);
    font-weight: 400;
}

/* --------------------------------------------------
   КНОПКИ ПЕРЕКЛЮЧЕНИЯ - ОБНОВЛЕННЫЕ СТИЛИ
   -------------------------------------------------- */
.toggle-submenu {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.25s ease;
    flex-shrink: 0;
    margin-left: auto;
    border-radius: 4px;
    position: relative;
    overflow: hidden; /* Для ripple эффекта */
}

.toggle-submenu:hover {
    color: var(--color-sky-dark);
    background: rgba(var(--color-sky-base-rgb), 0.08);
}

.toggle-arrow {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-submenu[aria-expanded="true"] .toggle-arrow {
    transform: rotate(180deg);
}

/* Совместимость с существующим классом religion-toggle */
.religion-toggle {
    composes: toggle-submenu;
}

/* --------------------------------------------------
   АКЦЕНТНЫЕ ЭФФЕКТЫ
   -------------------------------------------------- */
.religion-link:hover .religion-icon {
    background: rgba(var(--color-sky-base-rgb), 0.12);
    border-color: rgba(var(--color-sky-base-rgb), 0.25);
}

.religion-link:hover .religion-icon-img {
    transform: scale(1.05);
}

.religion-link:hover .religion-icon svg,
.religion-link:hover .religion-icon i {
    fill: var(--color-sky-light);
    transform: scale(1.1);
    color: var(--color-sky-light);
}

.religion-item.current-menu-item .religion-icon,
.religion-item.current-menu-ancestor .religion-icon {
    background: rgba(var(--color-sky-base-rgb), 0.1);
    border-color: rgba(var(--color-sky-base-rgb), 0.3);
}

/* --------------------------------------------------
   ПОДМЕНЮ И АНИМАЦИИ - ОБНОВЛЕННЫЕ СТИЛИ
   -------------------------------------------------- */
.sub-religions {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-left: 0.75rem;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    /* Убраны transform и opacity для лучшей производительности */
}

.religion-item.expanded > .sub-religions {
    max-height: 5000px; /* Большое значение для плавной анимации */
    padding: 0.375rem 0 0.375rem 0.75rem;
}

/* Сохраняем видимость для уже раскрытых элементов */
.religion-item.expanded .sub-religions {
    visibility: visible;
    opacity: 1;
}

/* --------------------------------------------------
   МОБИЛЬНАЯ ВЕРСИЯ - КЛЮЧЕВЫЕ ИСПРАВЛЕНИЯ
   -------------------------------------------------- */
@media (max-width: 768px) {
    #religion-accordion {
        position: fixed;
        top: 0;
        left: 0;
        width: 85vw;
        max-width: 300px;
        height: 100vh;
        border-radius: 0;
        border-right: 1px solid #e5e7eb;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 12px 0 40px rgba(0, 0, 0, 0.1);
        z-index: 10001;
        overflow-y: auto;
        padding-top: 56px;
        background: #ffffff;
        opacity: 1 !important;
        visibility: visible !important;
        max-height: 100vh;
        display: none; /* Скрыт по умолчанию */
    }

    #religion-accordion.mobile-accordion-panel {
        display: flex;
        flex-direction: column;
    }

    #religion-accordion.active {
        transform: translateX(0);
        display: flex;
    }

    /* Заголовок мобильной панели */
    .mobile-panel-header {
        position: fixed;
        top: 0;
        left: 0;
        width: 85vw;
        max-width: 100%;
        height: 56px;
        background: #ffffff;
        border-bottom: 1px solid #e5e7eb;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        z-index: 10002;
        box-sizing: border-box;
    }

    .mobile-panel-header h3 {
        margin: 0;
        font-size: 1rem;
        color: #d7e9ff;
        font-weight: 400;
        font-family: var(--font-family-serif);
    }

    .mobile-panel-close {
        background: transparent;
        border: none;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        color: #6b7280;
        border-radius: 4px;
        transition: all 0.2s ease;
    }

    .mobile-panel-close:hover {
        background: rgba(var(--color-sky-base-rgb), 0.08);
        color: var(--color-sky-base);
    }

    /* Кнопка-книжечка */
    .mobile-accordion-shortcut {
        position: fixed !important;
        bottom: 24px;
        right: 6%;
        width: 52px;
        height: 52px;
        background: var(--color-sky-base);
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 999999 !important;
        box-shadow: 0 4px 16px rgba(var(--color-sky-base-rgb), 0.3);
        transition: all 0.3s ease;
    }

    .mobile-accordion-shortcut:hover {
        transform: scale(1.08);
        box-shadow: 0 6px 20px rgba(var(--color-sky-base-rgb), 0.4);
        border-radius: 100%;
    }

    .mobile-accordion-shortcut img {
        width: 24px;
        height: 24px;
        transition: opacity 0.25s ease;
    }

    .mobile-accordion-shortcut .icon-open,
    .mobile-accordion-shortcut .icon-close {
        filter: brightness(0) invert(1);
    }

    /* Управление видимостью иконок */
    .mobile-accordion-shortcut .icon-open {
        display: block;
    }
    
    .mobile-accordion-shortcut .icon-close {
        display: none;
    }
    
    /* Когда аккордеон открыт */
    .mobile-accordion-shortcut .icon-open {
        display: none;
    }
    
    .mobile-accordion-shortcut .icon-close {
        display: block;
    }

    /* ОВЕРЛЕЙ - КЛЮЧЕВОЕ ИСПРАВЛЕНИЕ */
    .mobile-accordion-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(7, 14, 24, 0.79);
        backdrop-filter: blur(2px);
        z-index: 10000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        pointer-events: none;
    }

    .mobile-accordion-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }

    /* Класс блокировки скролла */
    body.no-scroll-accordion,
    html.no-scroll-accordion {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        touch-action: none;
    }
}

/* --------------------------------------------------
   ДЕСКТОПНАЯ ВЕРСИЯ - КЛЮЧЕВЫЕ ИЗМЕНЕНИЯ
   -------------------------------------------------- */
@media (min-width: 769px) {
    #religion-accordion {
        display: block !important;
        position: relative;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        height: auto !important;
        /* ИЗМЕНЕНИЕ: Убраны ограничения высоты */
        max-height: none !important;
        overflow-y: visible !important;
    }

    .mobile-accordion-overlay,
    .mobile-accordion-shortcut,
    .mobile-panel-header {
        display: none !important;
    }
    
    /* Компактные классы для десктопной версии */
    .desktop-compact .sub-religions .religion-icon {
        width: 30px;
        height: 30px;
    }
    
    .desktop-compact .sub-religions .sub-religions .religion-icon {
        width: 26px;
        height: 26px;
    }
}

/* --------------------------------------------------
   АНИМАЦИИ И ДОПОЛНИТЕЛЬНЫЕ СТИЛИ
   -------------------------------------------------- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Стили для активных элементов */
.religion-item.current-menu-item,
.religion-item.current-menu-ancestor {
    background: rgba(var(--color-sky-base-rgb), 0.02);
    border-color: rgba(var(--color-sky-base-rgb), 0.2);
    box-shadow: 0 1px 3px rgba(var(--color-sky-base-rgb), 0.1);
}

.religion-item.current-menu-item {
    border-left: 3px solid #d4af37;
    background: #FFF;
}

/* Оптимизированный скроллбар - теперь только для мобильной версии */
@media (max-width: 768px) {
    #religion-accordion::-webkit-scrollbar {
        width: 5px;
    }

    #religion-accordion::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 8px;
    }

    #religion-accordion::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, 
            var(--color-sky-light) 0%, 
            var(--color-sky-light) 100%);
        border-radius: 8px;
    }

    #religion-accordion::-webkit-scrollbar-thumb:hover {
        background: var(--color-sky-base);
    }
}

/* Ripple эффект */
.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(var(--color-sky-base-rgb), 0.3);
    transform: scale(0);
    animation: ripple 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 1;
}

.ripple-effect.active {
    animation: ripple 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Мобильный тултип */
.mobile-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 100000;
    max-width: 80vw;
    word-wrap: break-word;
    text-align: center;
    animation: tooltipFadeIn 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.mobile-tooltip.fade-out {
    animation: tooltipFadeOut 0.3s ease forwards;
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translate(-50%, -90%); }
    to { opacity: 1; transform: translate(-50%, -100%); }
}

@keyframes tooltipFadeOut {
    to { opacity: 0; transform: translate(-50%, -110%); }
}

/* Переменные по умолчанию */
:root {
    --color-sky-base: #3b82f6;
    --color-sky-base-rgb: 59, 130, 246;
    --color-sky-dark: #2563eb;
    --color-sky-light: #60a5fa;
}

/* Скрыть кнопку sidebar-toggle */
.sidebar-toggle { display: none; }


/* ============================================
   ИСПРАВЛЕНИЯ ДЛЯ АККОРДЕОНА И ОВЕРЛЕЯ
   ============================================ */

/* Оверлей для мобильного аккордеона */
#mobile-accordion-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
                visibility 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

#mobile-accordion-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Кнопка мобильного аккордеона */
.mobile-accordion-shortcut {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-sky-base, #3b82f6) 0%, var(--color-sky-dark, #1d4ed8) 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.mobile-accordion-shortcut:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.mobile-accordion-shortcut:active {
    transform: translateY(0);
}

.mobile-accordion-shortcut img {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);
    top: 50%;
    left: 50%;
    transition: opacity 0.3s ease;
}

.mobile-accordion-shortcut .icon-open {
    opacity: 1;
}

.mobile-accordion-shortcut .icon-close {
    opacity: 0;
}

/* Когда аккордеон открыт */
.mobile-accordion-shortcut .icon-open {
    opacity: 0;
}

.mobile-accordion-shortcut .icon-close {
    opacity: 1;
}

/* Заголовок мобильной панели */
.mobile-panel-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--color-sky-base, #3b82f6) 0%, var(--color-sky-dark, #1d4ed8) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* Предотвращает сжатие */
}

.mobile-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.mobile-panel-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-panel-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-panel-close svg {
    width: 24px;
    height: 24px;
}

/* Классы для блокировки скролла */
.no-scroll-accordion {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}

/* Мобильный аккордеон */
.mobile-accordion-panel {
    background: white;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

@keyframes slideOutLeft {
    from { transform: translateX(0); }
    to { transform: translateX(-100%); }
}

/* Адаптация для iOS Safari */
@supports (-webkit-touch-callout: none) {
    .no-scroll-accordion {
        position: fixed !important;
        width: 100% !important;
        height: -webkit-fill-available !important;
    }
}

/* Медиа-запросы */
@media (max-width: 768px) {
    #religion-accordion.mobile-accordion-panel {
        animation: slideInLeft 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    #religion-accordion.mobile-accordion-panel.closing {
        animation: slideOutLeft 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* Улучшенная анимация для затемнения */
.mobile-accordion-overlay.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.mobile-accordion-overlay.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Стили для компактных уровней */
.compact-level-1 .religion-icon {
    width: 36px;
    height: 36px;
    margin-right: 0.5rem;
}

.compact-level-2 .religion-icon {
    width: 32px;
    height: 32px;
    margin-right: 0.4375rem;
}

.compact-level-3 .religion-icon {
    width: 28px;
    height: 28px;
    margin-right: 0.375rem;
}

.compact-level-4 .religion-icon {
    width: 24px;
    height: 24px;
    margin-right: 0.3125rem;
}

/* Улучшенная поддержка анимаций */
.religion-item {
    animation-fill-mode: both;
}

.sub-religions {
    animation-fill-mode: both;
}