/* Auto Table of Contents Styles - Modern & Attractive Design */

/* Add some modern hover effects and micro-interactions */
#auto-toc-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.4), 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* Add a subtle pulse animation for active state */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 107, 107, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 107, 107, 0);
    }
}

/* Add shimmer effect for loading state */
@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

#auto-toc-container {
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 16px;
    padding: 24px;
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3), 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    width: 300px;
}

/* Drag handle */
#auto-toc-drag-handle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    cursor: move;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s ease;
    user-select: none;
}

#auto-toc-drag-handle:hover {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
    transform: scale(1.1);
}

/* Draggable state */
#auto-toc-container.auto-toc-draggable {
    cursor: move;
}

#auto-toc-container.auto-toc-dragging {
    transform: rotate(2deg) scale(1.05);
    box-shadow: 0 20px 50px rgba(102, 126, 234, 0.5), 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    max-height: none;
}

/* Minimized state */
#auto-toc-container.auto-toc-minimized {
    position: fixed !important;
    bottom: 20px;
    left: 20px;
    width: 80px !important;
    height: 80px !important;
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    max-height: none;
    overflow: hidden;
}

#auto-toc-container.auto-toc-minimized #auto-toc-header,
#auto-toc-container.auto-toc-minimized #auto-toc-list,
#auto-toc-container.auto-toc-minimized #auto-toc-progress.auto-toc-progress-rounded,
#auto-toc-container.auto-toc-minimized #auto-toc-progress.auto-toc-progress-square,
#auto-toc-container.auto-toc-minimized #auto-toc-progress.auto-toc-progress-bar,
#auto-toc-container.auto-toc-minimized #auto-toc-drag-handle {
    display: none;
}

#auto-toc-container.auto-toc-minimized #auto-toc-progress.auto-toc-progress-chart {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    margin: 0;
}

#auto-toc-container.auto-toc-minimized #auto-toc-progress-circle {
    width: 60px;
    height: 60px;
}

#auto-toc-container.auto-toc-minimized .progress-text {
    font-size: 12px;
    font-weight: 700;
}

/* Position variations */
#auto-toc-container.auto-toc-left {
    float: left;
    margin-right: 30px;
    margin-bottom: 20px;
}

#auto-toc-container.auto-toc-right {
    float: right;
    margin-left: 30px;
    margin-bottom: 20px;
}

#auto-toc-container.auto-toc-top {
    width: 100% !important;
    max-width: 800px;
    margin: 20px auto;
    float: none;
}

/* Sticky state */
#auto-toc-container.auto-toc-sticky {
    position: fixed !important;
    top: 100px;
    z-index: 9999;
    box-shadow: 0 20px 40px rgba(102, 126, 234, 0.4), 0 8px 25px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform: scale(0.98);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Header */
#auto-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
}

#auto-toc-header h4 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.5px;
}

#auto-toc-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #ffffff;
    backdrop-filter: blur(5px);
}

#auto-toc-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#auto-toc-toggle:focus {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

/* Progress bar - Base styles */
#auto-toc-progress {
    width: 100%;
    margin-bottom: 20px;
    position: relative;
}

/* Rounded progress bar (default) */
.auto-toc-progress-rounded {
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.auto-toc-progress-rounded #auto-toc-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
    background-size: 300% 100%;
    border-radius: 10px;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: gradientShift 3s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

/* Square progress bar */
.auto-toc-progress-square {
    height: 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.auto-toc-progress-square #auto-toc-progress-bar {
    height: 100%;
    background: linear-gradient(45deg, #667eea, #764ba2, #f093fb, #f5576c);
    background-size: 400% 100%;
    border-radius: 2px;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: gradientShift 4s ease-in-out infinite;
    position: relative;
}

.auto-toc-progress-square #auto-toc-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(255, 255, 255, 0.1) 2px,
        rgba(255, 255, 255, 0.1) 4px
    );
}

/* Bar progress bar */
.auto-toc-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.auto-toc-progress-bar #auto-toc-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    border-radius: 0;
    width: 0%;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.auto-toc-progress-bar #auto-toc-progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

/* Chart progress bar (circular) */
.auto-toc-progress-chart {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#auto-toc-progress-circle {
    position: relative;
    width: 50px;
    height: 50px;
}

#auto-toc-progress-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

#auto-toc-progress-circle .progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* TOC List */
#auto-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px;
    backdrop-filter: blur(5px);
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

/* Custom scrollbar for TOC list */
#auto-toc-list::-webkit-scrollbar {
    width: 6px;
}

#auto-toc-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#auto-toc-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

#auto-toc-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

#auto-toc-list li {
    margin-bottom: 8px;
    position: relative;
}

#auto-toc-list a {
    display: block;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 3px solid transparent;
    position: relative;
    overflow: hidden;
}

#auto-toc-list a:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border-left-color: var(--toc-hover-color, #ff6b6b);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

#auto-toc-list a:focus {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

#auto-toc-list a.active {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    border-left-color: var(--toc-active-color, #feca57);
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(254, 202, 87, 0.3);
    transform: translateX(6px);
    animation: pulse 2s infinite;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Add a subtle glow effect on hover for better interactivity */
#auto-toc-list a::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s;
}

#auto-toc-list a:hover::before {
    transform: translateX(100%);
}

/* Heading level indentation - Fixed hierarchy */
.auto-toc-h1 {
    padding-left: 0;
    font-weight: 700;
}

.auto-toc-h2 {
    padding-left: 15px;
    font-weight: 600;
}

.auto-toc-h3 {
    padding-left: 30px;
    font-weight: 500;
}

.auto-toc-h4 {
    padding-left: 45px;
    font-weight: 400;
}

.auto-toc-h5 {
    padding-left: 60px;
    font-weight: 400;
    opacity: 0.9;
}

.auto-toc-h6 {
    padding-left: 75px;
    font-weight: 400;
    opacity: 0.8;
}

/* Heading level font sizes */
.auto-toc-h1 a {
    font-size: 15px;
    font-weight: 600;
}

.auto-toc-h2 a {
    font-size: 14px;
    font-weight: 500;
}

.auto-toc-h3 a {
    font-size: 13px;
}

.auto-toc-h4 a {
    font-size: 12px;
}

.auto-toc-h5 a {
    font-size: 12px;
    opacity: 0.9;
}

.auto-toc-h6 a {
    font-size: 11px;
    opacity: 0.8;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #auto-toc-container {
        width: 100% !important;
        margin: 15px 0;
        padding: 15px;
        float: none !important;
    }
    
    #auto-toc-container.auto-toc-left,
    #auto-toc-container.auto-toc-right {
        float: none !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    #auto-toc-container.auto-toc-sticky {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        transform: none !important;
        width: 100% !important;
        margin: 15px 0 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }
    
    #auto-toc-header h4 {
        font-size: 15px;
    }
    
    .auto-toc-h3,
    .auto-toc-h4,
    .auto-toc-h5,
    .auto-toc-h6 {
        padding-left: 15px;
    }
    
    .auto-toc-h4 {
        padding-left: 25px;
    }
    
    .auto-toc-h5 {
        padding-left: 35px;
    }
    
    .auto-toc-h6 {
        padding-left: 45px;
    }
}

@media (max-width: 480px) {
    #auto-toc-container {
        padding: 12px;
        font-size: 13px;
    }
    
    #auto-toc-header h4 {
        font-size: 14px;
    }
    
    #auto-toc-list a {
        padding: 5px 8px;
    }
    
    .auto-toc-h3,
    .auto-toc-h4,
    .auto-toc-h5,
    .auto-toc-h6 {
        padding-left: 10px;
    }
    
    .auto-toc-h4 {
        padding-left: 15px;
    }
    
    .auto-toc-h5 {
        padding-left: 20px;
    }
    
    .auto-toc-h6 {
        padding-left: 25px;
    }
}

/* Print styles */
@media print {
    #auto-toc-container {
        position: static !important;
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        background: white !important;
        page-break-inside: avoid;
    }
    
    #auto-toc-progress {
        display: none;
    }
    
    #auto-toc-toggle {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #auto-toc-container {
        border: 2px solid #000;
        background: #fff;
    }
    
    #auto-toc-list a {
        border-left-width: 4px;
    }
    
    #auto-toc-list a:hover,
    #auto-toc-list a.active {
        background-color: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    #auto-toc-container,
    #auto-toc-list a,
    #auto-toc-progress-bar,
    #auto-toc-toggle {
        transition: none;
    }
    
    @keyframes slideIn {
        from, to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    @keyframes gradientShift {
        0%, 100% {
            background-position: 0% 50%;
        }
        50% {
            background-position: 100% 50%;
        }
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #auto-toc-container {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
        border-color: rgba(255, 255, 255, 0.1);
        color: #e2e8f0;
        box-shadow: 0 10px 30px rgba(45, 55, 72, 0.4), 0 4px 15px rgba(0, 0, 0, 0.2);
    }
    
    #auto-toc-header {
        border-bottom-color: rgba(255, 255, 255, 0.2);
    }
    
    #auto-toc-header h4 {
        color: #f7fafc;
    }
    
    #auto-toc-toggle {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.2);
        color: #f7fafc;
    }
    
    #auto-toc-toggle:hover {
        background: rgba(255, 255, 255, 0.2);
        color: #f7fafc;
    }
    
    #auto-toc-progress {
        background: rgba(255, 255, 255, 0.1);
    }
    
    #auto-toc-list {
        background: rgba(255, 255, 255, 0.05);
    }
    
    #auto-toc-list a {
        color: rgba(247, 250, 252, 0.9);
    }
    
    #auto-toc-list a:hover {
        background: rgba(255, 255, 255, 0.15);
        color: #f7fafc;
        border-left-color: #ff6b6b;
    }
    
    #auto-toc-list a.active {
        background: rgba(255, 255, 255, 0.2);
        color: #f7fafc;
        border-left-color: #feca57;
    }
}

/* RTL support */
[dir="rtl"] #auto-toc-container.auto-toc-left {
    float: right;
    margin-left: 30px;
    margin-right: 0;
}

[dir="rtl"] #auto-toc-container.auto-toc-right {
    float: left;
    margin-right: 30px;
    margin-left: 0;
}

[dir="rtl"] #auto-toc-list a {
    border-left: none;
    border-right: 3px solid transparent;
}

[dir="rtl"] #auto-toc-list a:hover,
[dir="rtl"] #auto-toc-list a.active {
    border-right-color: #007cba;
}

[dir="rtl"] .auto-toc-h3 {
    padding-right: 20px;
    padding-left: 0;
}

[dir="rtl"] .auto-toc-h4 {
    padding-right: 40px;
    padding-left: 0;
}

[dir="rtl"] .auto-toc-h5 {
    padding-right: 60px;
    padding-left: 0;
}

[dir="rtl"] .auto-toc-h6 {
    padding-right: 80px;
    padding-left: 0;
}
