/**
 * Collapsible Container Styles - OPTIMIZED
 * Оптимизированная версия с исправленными проблемами высоты
 */

/* CSS переменные для легкой настройки */
:root {
    --cc-primary: #c65d00;
    --cc-primary-hover: #a54d00;
    --cc-bg-hover: #faf8f5;
    --cc-border-radius: 12px;
    --cc-transition-duration: 0.4s;
    --cc-transition-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --cc-text-secondary: #7f8c8d;
    --cc-box-shadow: 0 2px 8px rgba(198, 93, 0, 0.08);
    --cc-box-shadow-hover: 0 8px 24px rgba(198, 93, 0, 0.15);
    --cc-content-padding: 30px;
}

/* Основной контейнер */
.cc-container {
    position: relative;
    margin: 40px 0;
    contain: layout; /* Оптимизация рендеринга */
}

/* Обертка кнопки */
.cc-toggle-wrapper {
    margin-bottom: 30px;
    text-align: center;
}

/* Кнопка переключения */
.cc-toggle-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px 36px;
    background: #ffffff;
    border: 2px solid var(--cc-primary);
    border-radius: var(--cc-border-radius);
    color: var(--cc-primary);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: all 0.3s var(--cc-transition-easing);
    box-shadow: var(--cc-box-shadow);
    position: relative;
    overflow: hidden;
    will-change: transform;
}

/* Hover эффект */
.cc-toggle-button:hover {
    background: var(--cc-bg-hover);
    transform: translateY(-2px);
    box-shadow: var(--cc-box-shadow-hover);
}

.cc-toggle-button:focus-visible {
    outline: 2px solid var(--cc-primary);
    outline-offset: 2px;
}

/* Иконка в кнопке */
.cc-toggle-icon {
    display: inline-flex;
    align-items: center;
    font-size: 16px;
    transition: transform 0.3s var(--cc-transition-easing);
    will-change: transform;
}

/* Анимация иконки */
.cc-container[data-state="expanded"] .cc-toggle-icon {
    transform: rotate(180deg);
}

/* Описание под кнопкой */
.cc-description {
    margin-top: 12px;
    font-size: 16px;
    color: var(--cc-text-secondary);
    font-weight: 400;
    line-height: 1.5;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* === ОПТИМИЗИРОВАННАЯ СИСТЕМА АНИМАЦИИ КОНТЕНТА === */

/* Контейнер контента - убран постоянный will-change */
.cc-content-wrapper {
    overflow: hidden;
    /* will-change применяется только во время анимации через классы */
}

/* Состояния через классы вместо inline стилей */
.cc-content-wrapper.is-collapsed,
.cc-content-wrapper:not(.is-expanded):not(.is-expanding) {
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-20px);
    transition: 
        opacity var(--cc-transition-duration) var(--cc-transition-easing),
        transform var(--cc-transition-duration) var(--cc-transition-easing),
        visibility 0s var(--cc-transition-duration);
}

.cc-content-wrapper.is-expanded {
    max-height: none; /* Убираем ограничение высоты */
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: 
        opacity var(--cc-transition-duration) var(--cc-transition-easing),
        transform var(--cc-transition-duration) var(--cc-transition-easing);
}

/* Переходные состояния */
.cc-content-wrapper.is-expanding,
.cc-content-wrapper.is-collapsing {
    transition: 
        opacity var(--cc-transition-duration) var(--cc-transition-easing),
        transform var(--cc-transition-duration) var(--cc-transition-easing);
}

/* Альтернативная система для старых браузеров */
.cc-container[data-state="collapsed"] .cc-content-wrapper {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

.cc-container[data-state="expanded"] .cc-content-wrapper {
    max-height: none;
    opacity: 1;
    overflow: visible;
}

/* Без анимации */
.cc-container.no-animation .cc-content-wrapper {
    transition: none !important;
}

/* Внутренний контейнер */
.cc-content-inner {
    padding: var(--cc-content-padding) 0;
}

/* Анимация первого открытия */
.cc-container[data-first-open="true"] .cc-content-inner > * {
    animation: fadeInUp 0.5s var(--cc-transition-easing) backwards;
}

.cc-container[data-first-open="true"] .cc-content-inner > *:nth-child(1) { animation-delay: 0.1s; }
.cc-container[data-first-open="true"] .cc-content-inner > *:nth-child(2) { animation-delay: 0.2s; }
.cc-container[data-first-open="true"] .cc-content-inner > *:nth-child(3) { animation-delay: 0.3s; }
.cc-container[data-first-open="true"] .cc-content-inner > *:nth-child(4) { animation-delay: 0.4s; }

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === ОПТИМИЗАЦИЯ ДЛЯ ВЛОЖЕННОГО КОНТЕНТА === */

/* Убираем лишние отступы у вложенных элементов */
.cc-content-inner .thematic-groups-section {
    padding-top: 0;
    background: transparent;
}

/* Оптимизация z-index через CSS переменные */
.cc-content-wrapper {
    --z-base: 1;
    --z-active: 10;
    --z-content: 20;
}

.cc-content-wrapper .group-item {
    position: relative;
    z-index: var(--z-base);
}

.cc-content-wrapper .group-item.active {
    z-index: var(--z-active);
}

.cc-content-wrapper .group-item.active .group-content {
    position: relative;
    z-index: var(--z-content);
}

/* === АДАПТИВНОСТЬ === */

/* Планшеты */
@media (max-width: 1024px) {
    :root {
        --cc-content-padding: 20px;
    }
    
    .cc-toggle-button {
        padding: 16px 30px;
        font-size: 17px;
    }
    
    .cc-description {
        font-size: 15px;
        padding: 0 20px;
    }
}

/* Мобильные */
@media (max-width: 768px) {
    :root {
        --cc-content-padding: 15px;
    }
    
    .cc-container {
        margin: 30px 0;
    }
    
    .cc-toggle-wrapper {
        margin-bottom: 20px;
    }
    
    .cc-toggle-button {
        width: calc(100% - 40px);
        max-width: 400px;
        padding: 16px 24px;
        font-size: 16px;
        gap: 10px;
    }
    
    .cc-description {
        font-size: 14px;
        margin-top: 10px;
        padding: 0 15px;
    }
}

/* Маленькие мобильные */
@media (max-width: 480px) {
    .cc-container {
        margin: 20px 0;
    }
    
    .cc-toggle-button {
        width: calc(100% - 30px);
        padding: 14px 20px;
        font-size: 15px;
        border-radius: 10px;
    }
    
    .cc-description {
        font-size: 13px;
        padding: 0 10px;
    }
}

/* === ДОСТУПНОСТЬ === */

/* Уменьшение движения */
@media (prefers-reduced-motion: reduce) {
    :root {
        --cc-transition-duration: 0.01ms;
    }
    
    .cc-toggle-button,
    .cc-toggle-icon,
    .cc-content-wrapper,
    .cc-content-inner {
        animation-duration: 0.01ms !important;
    }
}

/* Высокая контрастность */
@media (prefers-contrast: high) {
    .cc-toggle-button {
        border-width: 3px;
    }
    
    .cc-toggle-button:focus-visible {
        outline-width: 3px;
    }
}

/* === ТЕМНАЯ ТЕМА === */
@media (prefers-color-scheme: dark) {
    .cc-toggle-button {
        background: #2c3e50;
        color: #ffffff;
    }
    
    .cc-toggle-button:hover {
        background: #34495e;
    }
    
    .cc-description {
        color: #bdc3c7;
    }
}

/* === PRINT === */
@media print {
    .cc-container[data-state="collapsed"] .cc-content-wrapper {
        max-height: none !important;
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
    }
    
    .cc-toggle-button {
        display: none;
    }
}

/* === ПРОИЗВОДИТЕЛЬНОСТЬ === */

/* will-change применяется только во время анимации */
.cc-content-wrapper.is-expanding,
.cc-content-wrapper.is-collapsing {
    will-change: opacity, transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* После завершения анимации убираем will-change */
.cc-content-wrapper.is-expanded,
.cc-content-wrapper.is-collapsed {
    will-change: auto;
}

/* Оптимизация рендеринга для больших списков */
.cc-content-wrapper .groups-accordion {
    contain: layout style;
}

/* Предотвращаем layout thrashing */
.cc-content-wrapper {
    transform-style: preserve-3d;
}

/* === СОВМЕСТИМОСТЬ С ТЕМОЙ === */

/* Сброс стилей темы если они конфликтуют */
.cc-container * {
    box-sizing: border-box;
}

.cc-container button {
    font-family: inherit;
}

/* Фикс для Elementor */
.elementor-widget-collapsible_container .cc-container {
    width: 100%;
}

/* === МИНИМАЛЬНЫЕ СТИЛИ ДЛЯ ЗАГРУЗЧИКА === */
.cc-container.is-loading .cc-content-inner {
    position: relative;
    min-height: 100px;
}

.cc-container.is-loading .cc-content-inner::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(198, 93, 0, 0.2);
    border-top-color: var(--cc-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}