/* ============================================================================
 * MODERN FLOATING TOC WIDGET - Современный виджет оглавления
 * ============================================================================ */

/* ========== ОСНОВНОЙ КОНТЕЙНЕР ========== */
.floating-toc-widget {
    position: fixed !important;
    bottom: 0 !important;
    right: 20px !important;
    width: 380px !important;
    max-height: 65px !important;
    z-index: 999 !important;
    
    background: linear-gradient(135deg, #1a1a27 0%, #2a2a3e 100%) !important;
    border: 2px solid transparent !important;
    background-clip: padding-box !important;
    border-radius: 20px 20px 0 0 !important;
    box-shadow: 
        0 -8px 32px rgba(0, 0, 0, 0.6),
        0 -2px 8px rgba(234, 60, 70, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
    
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif !important;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
    backdrop-filter: blur(20px) !important;
}

/* Эффект стекломорфизма */
.floating-toc-widget::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: linear-gradient(135deg, rgba(234, 60, 70, 0.03) 0%, rgba(255, 90, 93, 0.02) 100%) !important;
    border-radius: 20px 20px 0 0 !important;
    pointer-events: none !important;
}

/* Показываем виджет сразу */
.floating-toc-widget.visible {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Развернутое состояние - раскрывается вверх */
.floating-toc-widget.expanded {
    max-height: 75vh !important;
    border-color: rgba(234, 60, 70, 0.3) !important;
    box-shadow: 
        0 -12px 48px rgba(0, 0, 0, 0.8),
        0 -4px 16px rgba(234, 60, 70, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 0 1px rgba(234, 60, 70, 0.2) !important;
}

/* ========== ЗАГОЛОВОК ========== */
.floating-toc-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 18px 24px !important;
    background: linear-gradient(90deg, rgba(234, 60, 70, 0.08) 0%, rgba(255, 90, 93, 0.05) 100%) !important;
    border-bottom: 1px solid rgba(234, 60, 70, 0.1) !important;
    cursor: pointer !important;
    user-select: none !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Анимированный фон при наведении (только для небольших списков и устройств с мышью) */
@media (hover: hover) and (pointer: fine) {
    .floating-toc-widget:not(.large-list) .floating-toc-header::after {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: -100% !important;
        width: 100% !important;
        height: 100% !important;
        background: linear-gradient(90deg, transparent, rgba(234, 60, 70, 0.15), transparent) !important;
        transition: left 0.5s ease !important;
    }

    .floating-toc-widget:not(.large-list) .floating-toc-header:hover::after {
        left: 100% !important;
    }
}

/* Hover только на устройствах с мышью */
@media (hover: hover) and (pointer: fine) {
    .floating-toc-header:hover {
        background: linear-gradient(90deg, rgba(234, 60, 70, 0.12) 0%, rgba(255, 90, 93, 0.08) 100%) !important;
        border-bottom-color: rgba(234, 60, 70, 0.2) !important;
    }
}

/* Фокус для клавиатурной навигации */
.floating-toc-header:focus {
    outline: none !important;
    box-shadow: 
        0 0 0 3px rgba(234, 60, 70, 0.5) !important,
        inset 0 0 0 2px rgba(255, 255, 255, 0.2) !important;
}

.floating-toc-header:focus:not(:focus-visible) {
    box-shadow: none !important;
}

.floating-toc-widget.expanded .floating-toc-header {
    background: linear-gradient(90deg, rgba(234, 60, 70, 0.15) 0%, rgba(255, 90, 93, 0.1) 100%) !important;
    border-bottom-color: rgba(234, 60, 70, 0.3) !important;
    box-shadow: 0 4px 12px rgba(234, 60, 70, 0.1) !important;
}

.floating-toc-title-wrap {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    position: relative !important;
    z-index: 1 !important;
}

.floating-toc-icon {
    width: 22px !important;
    height: 22px !important;
    fill: #ea3c46 !important;
    flex-shrink: 0 !important;
}

@keyframes iconPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Отключаем анимацию иконки для больших списков */
.floating-toc-widget.large-list .floating-toc-icon {
    animation: none !important;
}

.floating-toc-title {
    font-size: 16px !important;
    font-weight: 700 !important;
    color: #fff !important;
    margin: 0 !important;
    letter-spacing: 0.5px !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

.floating-toc-count {
    font-size: 12px !important;
    color: #fff !important;
    background: linear-gradient(135deg, #ea3c46, #ff5a5d) !important;
    padding: 4px 12px !important;
    border-radius: 20px !important;
    font-weight: 600 !important;
    box-shadow: 
        0 2px 8px rgba(234, 60, 70, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    min-width: 36px !important;
    text-align: center !important;
}

.floating-toc-toggle {
    all: unset !important;
    width: 32px !important;
    height: 32px !important;
    fill: rgba(255, 255, 255, 0.7) !important;
    pointer-events: none !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    flex-shrink: 0 !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    z-index: 1 !important;
}

.floating-toc-toggle svg {
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.floating-toc-widget.expanded .floating-toc-toggle svg {
    transform: rotate(180deg) !important;
}

/* ========== КОНТЕНТ ========== */
.floating-toc-content {
    max-height: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    transform: translateY(20px) !important;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    background: rgba(0, 0, 0, 0.1) !important;
}

.floating-toc-widget.expanded .floating-toc-content {
    max-height: calc(75vh - 90px) !important;
    overflow-y: auto !important;
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* Красивый современный скроллбар - Webkit (Chrome, Safari, Edge) */
.floating-toc-content::-webkit-scrollbar {
    width: 6px !important;
}

.floating-toc-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2) !important;
    border-radius: 10px !important;
    margin: 8px 0 !important;
}

.floating-toc-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ea3c46, #ff5a5d) !important;
    border-radius: 10px !important;
    box-shadow: 0 0 6px rgba(234, 60, 70, 0.5) !important;
}

.floating-toc-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #ff5a5d, #ea3c46) !important;
    box-shadow: 0 0 10px rgba(234, 60, 70, 0.7) !important;
}

/* Скроллбар для Firefox */
.floating-toc-content {
    scrollbar-width: thin !important;
    scrollbar-color: #ea3c46 rgba(0, 0, 0, 0.2) !important;
}

/* ========== СПИСОК ========== */
.floating-toc-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 16px 0 !important;
}

.floating-toc-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ========== ССЫЛКИ ========== */
.floating-toc-link {
    display: flex !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 12px 20px !important;
    color: rgba(255, 255, 255, 0.75) !important;
    text-decoration: none !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    border-radius: 0 !important;
    border-left: 3px solid transparent !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer !important;
    margin: 0 !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Анимированная подложка (только для небольших списков и устройств с мышью) */
@media (hover: hover) and (pointer: fine) {
    .floating-toc-widget:not(.large-list) .floating-toc-link::after {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: -100% !important;
        width: 100% !important;
        height: 100% !important;
        background: linear-gradient(90deg, transparent, rgba(234, 60, 70, 0.08), transparent) !important;
        transition: left 0.5s ease !important;
    }

    .floating-toc-link:hover {
        color: #fff !important;
        background: rgba(234, 60, 70, 0.08) !important;
        transform: translateX(4px) !important;
        border-left-color: rgba(234, 60, 70, 0.4) !important;
    }

    .floating-toc-widget:not(.large-list) .floating-toc-link:hover::after {
        left: 100% !important;
    }
}

/* Фокус для ссылок */
.floating-toc-link:focus {
    outline: 2px solid rgba(234, 60, 70, 0.6) !important;
    outline-offset: -2px !important;
}

.floating-toc-link:focus:not(:focus-visible) {
    outline: none !important;
}

.floating-toc-link::before {
    content: '' !important;
    display: block !important;
    width: 6px !important;
    height: 6px !important;
    min-width: 6px !important;
    background: rgba(234, 60, 70, 0.6) !important;
    border-radius: 50% !important;
    flex-shrink: 0 !important;
    margin-top: 6px !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 0 0 rgba(234, 60, 70, 0.5) !important;
}

@media (hover: hover) and (pointer: fine) {
    .floating-toc-link:hover::before {
        transform: scale(1.4) !important;
        box-shadow: 0 0 8px rgba(234, 60, 70, 0.6) !important;
    }
}

.floating-toc-link.active {
    color: #fff !important;
    background: linear-gradient(90deg, rgba(234, 60, 70, 0.2) 0%, rgba(234, 60, 70, 0.05) 100%) !important;
    border-left-color: #ea3c46 !important;
    font-weight: 700 !important;
    transform: translateX(4px) !important;
}

.floating-toc-link.active::before {
    background: #ea3c46 !important;
    transform: scale(1.5) !important;
    box-shadow: 0 0 12px rgba(234, 60, 70, 0.9) !important;
}

/* Подзаголовки (H3) */
.floating-toc-link--sub,
a.floating-toc-link.floating-toc-link--sub {
    padding-left: 40px !important;
    font-size: 13px !important;
    color: rgba(255, 255, 255, 0.6) !important;
    -webkit-padding-start: 40px !important; /* Safari fix */
}

.floating-toc-link--sub::before {
    width: 4px !important;
    height: 4px !important;
    min-width: 4px !important;
    background: rgba(165, 173, 207, 0.5) !important;
    margin-left: 0 !important; /* Safari fix */
}

.floating-toc-link--sub.active {
    transform: translateX(4px) !important;
    -webkit-transform: translateX(4px) !important; /* Safari fix */
}

@media (hover: hover) and (pointer: fine) {
    .floating-toc-link--sub:hover {
        transform: translateX(4px) !important;
        -webkit-transform: translateX(4px) !important; /* Safari fix */
    }
}

.floating-toc-link--sub.active::before {
    background: #ea3c46 !important;
}

/* ========== АДАПТАЦИЯ ПОД МОБИЛЬНЫЕ ========== */
@media (max-width: 1200px) {
    .floating-toc-widget {
        width: 340px !important;
        right: 15px !important;
    }
}

@media (max-width: 768px) {
    .floating-toc-widget {
        left: 10px !important;
        right: 10px !important;
        width: calc(100% - 20px) !important;
        max-height: 56px !important;
        border-radius: 16px 16px 0 0 !important;
    }
    
    .floating-toc-widget::before {
        border-radius: 16px 16px 0 0 !important;
    }
    
    .floating-toc-widget.expanded {
        max-height: 50vh !important;
    }
    
    .floating-toc-header {
        padding: 14px 16px !important;
    }
    
    .floating-toc-title {
        font-size: 14px !important;
    }
    
    .floating-toc-icon {
        width: 18px !important;
        height: 18px !important;
    }
    
    .floating-toc-count {
        font-size: 11px !important;
        padding: 3px 10px !important;
        min-width: 32px !important;
    }
    
    .floating-toc-toggle {
        width: 28px !important;
        height: 28px !important;
    }
    
    .floating-toc-toggle svg {
        width: 16px !important;
        height: 16px !important;
    }
    
    .floating-toc-widget.expanded .floating-toc-content {
        max-height: calc(50vh - 80px) !important;
    }
    
    .floating-toc-link {
        font-size: 13px !important;
        padding: 10px 16px !important;
        gap: 10px !important;
    }
    
    .floating-toc-link.active {
        transform: translateX(4px) !important;
    }
    
    .floating-toc-link--sub,
    a.floating-toc-link.floating-toc-link--sub {
        padding-left: 40px !important;
        font-size: 12px !important;
        -webkit-padding-start: 40px !important; /* Safari fix */
    }
    
    .floating-toc-link--sub.active {
        transform: translateX(4px) !important;
        -webkit-transform: translateX(4px) !important; /* Safari fix */
    }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
    .floating-toc-widget {
        left: 8px !important;
        right: 8px !important;
        width: calc(100% - 16px) !important;
        border-radius: 12px 12px 0 0 !important;
    }
    
    .floating-toc-widget::before {
        border-radius: 12px 12px 0 0 !important;
    }
    
    .floating-toc-header {
        padding: 12px 14px !important;
    }
    
    .floating-toc-title {
        font-size: 13px !important;
    }
    
    .floating-toc-link {
        font-size: 12px !important;
        padding: 8px 14px !important;
    }
}

/* ========== АНИМАЦИИ ========== */

/* Плавное появление снизу */
@keyframes slideUpSmooth {
    0% {
        bottom: -100px;
        opacity: 0;
        transform: translateY(50px) scale(0.95);
    }
    60% {
        bottom: 0;
        transform: translateY(-5px) scale(1);
    }
    100% {
        bottom: 0;
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.floating-toc-widget.visible.loaded {
    animation: slideUpSmooth 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

/* Мягкое пульсирование при первом появлении */
@keyframes gentlePulse {
    0%, 100% {
        box-shadow: 
            0 -8px 32px rgba(0, 0, 0, 0.6),
            0 -2px 8px rgba(234, 60, 70, 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.05);
    }
    50% {
        box-shadow: 
            0 -12px 40px rgba(0, 0, 0, 0.7),
            0 -4px 16px rgba(234, 60, 70, 0.3),
            inset 0 1px 0 rgba(255, 255, 255, 0.08);
    }
}

.floating-toc-widget.visible.loaded {
    animation: 
        slideUpSmooth 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
        gentlePulse 2.5s ease-in-out 0.6s !important;
}

/* Анимация для элементов списка при раскрытии */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px) translateX(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateX(0);
    }
}

/* Анимации ТОЛЬКО для небольших списков (< 50 элементов) */
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item .floating-toc-link {
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards !important;
}

/* Сохраняем transform для active и hover поверх анимации */
.floating-toc-widget.expanded:not(.large-list) .floating-toc-link.active,
.floating-toc-widget.expanded:not(.large-list) .floating-toc-link:hover {
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards !important;
}

.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(1) .floating-toc-link { animation-delay: 0.05s !important; }
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(2) .floating-toc-link { animation-delay: 0.08s !important; }
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(3) .floating-toc-link { animation-delay: 0.11s !important; }
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(4) .floating-toc-link { animation-delay: 0.14s !important; }
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(5) .floating-toc-link { animation-delay: 0.17s !important; }
.floating-toc-widget.expanded:not(.large-list) .floating-toc-item:nth-child(n+6) .floating-toc-link { animation-delay: 0.2s !important; }

/* Для больших списков (>50 элементов) - мгновенное появление */
.floating-toc-widget.large-list.expanded .floating-toc-content {
    transition: max-height 0.3s ease, opacity 0.2s ease !important;
}

.floating-toc-widget.large-list .floating-toc-link {
    transition: all 0.15s ease !important; /* Быстрые переходы */
}

/* GPU acceleration для плавной прокрутки больших списков */
.floating-toc-widget.large-list .floating-toc-content {
    will-change: scroll-position !important;
    transform: translateZ(0) !important; /* GPU layer */
}

/* Стили для Schema.org разметки (span внутри ссылок) */
.floating-toc-link span[itemprop="name"] {
    display: inline !important;
    color: inherit !important;
    text-decoration: none !important;
    font-size: inherit !important;
    line-height: inherit !important;
}

