/**
 * Smart Table of Contents - Styles
 * Full Elementor Compatibility
 * Multiple Style Variations
 */

/* ====================================
   Base Styles - Default Theme
   ==================================== */

.smart-toc-wrapper {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 24px;
    margin: 30px 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    max-width: 100%;
    box-sizing: border-box;
}

.smart-toc-wrapper:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

/* Header Section */
.smart-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 2px solid #dee2e6;
}

.smart-toc-title {
    margin: 0;
    font-size: 1.4em;
    color: #212529;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toc-icon-book {
    font-size: 1.2em;
    display: inline-block;
}

/* Toggle Button */
.smart-toc-toggle {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

.smart-toc-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.smart-toc-toggle:active {
    transform: translateY(0);
}

.smart-toc-toggle:focus {
    outline: 3px solid rgba(0, 123, 255, 0.4);
    outline-offset: 2px;
}

.toc-toggle-icon {
    display: inline-block;
    transition: transform 0.2s;
    font-size: 12px;
}

/* Content Area */
.smart-toc-content {
    overflow: hidden;
}

/* List Styles */
.smart-toc-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.smart-toc-list li {
    margin: 10px 0;
    line-height: 1.7;
}

.smart-toc-sublist {
    list-style: none;
    padding-left: 24px;
    margin-top: 10px;
    margin-bottom: 10px;
    border-left: 2px solid #e9ecef;
}

/* Loading State */
.toc-loading {
    color: #6c757d;
    font-style: italic;
    padding: 10px 0;
}

/* Link Styles */
.toc-link {
    color: #007bff;
    text-decoration: none;
    transition: all 0.25s ease;
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    position: relative;
    padding: 4px 0;
    font-size: 0.95em;
}

.toc-link:hover {
    color: #0056b3;
    padding-left: 6px;
}

.toc-link:focus {
    outline: 2px solid #007bff;
    outline-offset: 3px;
    border-radius: 3px;
}

/* Numbering */
.toc-number {
    font-weight: 700;
    color: #495057;
    min-width: 32px;
    display: inline-block;
}

/* Active Link Indicator */
.toc-link.active {
    color: #0056b3;
    font-weight: 700;
    background: linear-gradient(90deg, rgba(0, 123, 255, 0.1) 0%, transparent 100%);
    padding-left: 12px;
    border-left: 4px solid #007bff;
    margin-left: -12px;
}

/* Heading Level Styles */
.toc-level-1 .toc-link {
    font-weight: 700;
    font-size: 1.08em;
    color: #212529;
}

.toc-level-1 .toc-link:hover {
    color: #007bff;
}

.toc-level-2 .toc-link {
    font-weight: 600;
    font-size: 1.02em;
    color: #343a40;
}

.toc-level-3 .toc-link {
    font-weight: 500;
    font-size: 0.98em;
    color: #495057;
}

.toc-level-4 .toc-link,
.toc-level-5 .toc-link,
.toc-level-6 .toc-link {
    font-weight: 400;
    font-size: 0.92em;
    color: #6c757d;
}

/* ====================================
   Alternative Styles
   ==================================== */

/* Minimal Style */
.smart-toc-wrapper.toc-style-minimal {
    background: transparent;
    border: none;
    border-left: 4px solid #007bff;
    box-shadow: none;
    padding: 16px 20px;
}

.toc-style-minimal .smart-toc-header {
    border-bottom: 1px solid #e9ecef;
}

.toc-style-minimal .smart-toc-toggle {
    background: transparent;
    color: #007bff;
    box-shadow: none;
    border: 2px solid #007bff;
}

/* Boxed Style */
.smart-toc-wrapper.toc-style-boxed {
    background: #ffffff;
    border: 3px solid #007bff;
    box-shadow: 0 6px 24px rgba(0, 123, 255, 0.15);
}

.toc-style-boxed .smart-toc-header {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    margin: -24px -24px 18px -24px;
    padding: 16px 24px;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
}

.toc-style-boxed .smart-toc-title {
    color: white;
}

.toc-style-boxed .smart-toc-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
}

/* Modern Style */
.smart-toc-wrapper.toc-style-modern {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.toc-style-modern .smart-toc-title {
    color: white;
}

.toc-style-modern .smart-toc-header {
    border-bottom-color: rgba(255, 255, 255, 0.3);
}

.toc-style-modern .toc-link {
    color: white;
    font-weight: 500;
}

.toc-style-modern .toc-link:hover {
    color: #ffd700;
}

.toc-style-modern .toc-link.active {
    background: rgba(255, 255, 255, 0.2);
    border-left-color: #ffd700;
}

.toc-style-modern .smart-toc-toggle {
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid white;
}

.toc-style-modern .smart-toc-sublist {
    border-left-color: rgba(255, 255, 255, 0.3);
}

.toc-style-modern .toc-number {
    color: rgba(255, 255, 255, 0.9);
}

/* ====================================
   Alignment Options
   ==================================== */

.smart-toc-wrapper.toc-align-center {
    margin-left: auto;
    margin-right: auto;
    max-width: 600px;
}

.smart-toc-wrapper.toc-align-right {
    margin-left: auto;
    margin-right: 0;
    max-width: 600px;
}

.smart-toc-wrapper.toc-align-left {
    margin-left: 0;
    margin-right: auto;
    max-width: 600px;
}

/* ====================================
   Elementor Compatibility
   ==================================== */

/* Fix for Elementor widget container */
.elementor-widget-container .smart-toc-wrapper {
    margin-top: 0;
}

.elementor-widget-shortcode .smart-toc-wrapper {
    width: 100%;
}

/* Elementor column compatibility */
.elementor-column .smart-toc-wrapper {
    margin: 0;
}

/* Prevent conflicts with Elementor editor */
.elementor-editor-active .smart-toc-wrapper {
    pointer-events: auto !important;
}

.elementor-element-edit-mode .smart-toc-wrapper {
    position: relative;
    z-index: 1;
}

/* ====================================
   Mobile Responsive
   ==================================== */

@media (max-width: 768px) {
    .smart-toc-wrapper {
        padding: 18px;
        margin: 20px 0;
    }
    
    .smart-toc-title {
        font-size: 1.2em;
    }
    
    .smart-toc-sublist {
        padding-left: 18px;
    }
    
    .toc-link {
        font-size: 0.92em;
    }
    
    .toc-level-1 .toc-link {
        font-size: 1em;
    }
    
    .smart-toc-toggle {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    /* Full width on mobile */
    .smart-toc-wrapper.toc-align-center,
    .smart-toc-wrapper.toc-align-right,
    .smart-toc-wrapper.toc-align-left {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .smart-toc-wrapper {
        padding: 14px;
        margin: 15px 0;
        border-radius: 8px;
    }
    
    .smart-toc-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .smart-toc-toggle {
        align-self: flex-end;
    }
    
    .smart-toc-title {
        font-size: 1.1em;
    }
    
    .toc-icon-book {
        font-size: 1em;
    }
}

/* ====================================
   Print Styles
   ==================================== */

@media print {
    .smart-toc-toggle {
        display: none !important;
    }
    
    .smart-toc-content {
        display: block !important;
    }
    
    .smart-toc-wrapper {
        box-shadow: none;
        border: 2px solid #ddd;
        page-break-inside: avoid;
    }
    
    .toc-link {
        color: #000 !important;
        text-decoration: underline;
    }
}

/* ====================================
   Accessibility - High Contrast
   ==================================== */

@media (prefers-contrast: high) {
    .smart-toc-wrapper {
        border: 3px solid #000;
    }
    
    .toc-link {
        text-decoration: underline;
        font-weight: 600;
    }
    
    .smart-toc-toggle {
        border: 2px solid #000;
    }
}

/* ====================================
   Accessibility - Reduced Motion
   ==================================== */

@media (prefers-reduced-motion: reduce) {
    .toc-link,
    .smart-toc-toggle,
    .toc-toggle-icon,
    .smart-toc-wrapper {
        transition: none !important;
        animation: none !important;
    }
    
    .toc-link:hover {
        transform: none !important;
    }
    
    .smart-toc-toggle:hover {
        transform: none !important;
    }
}

/* ====================================
   Dark Mode Support
   ==================================== */

/* @media (prefers-color-scheme: dark) {
    .smart-toc-wrapper {
        background: #1e1e1e;
        border-color: #3a3a3a;
        color: #e0e0e0;
    }
    
    .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-header {
        border-bottom-color: #3a3a3a;
    }
    
    .toc-link {
        color: #eceef0;
    }
    
    .toc-link:hover {
        color: #eceef0;
    }
    
    .toc-link.active {
        background: rgba(88, 166, 255, 0.15);
        border-left-color: #eceef0;
    }
    
    .smart-toc-sublist {
        border-left-color: #3a3a3a;
    }
    
    .toc-number {
        color: #eceef0;
    }
    
    .toc-level-1 .toc-link {
        color: #e0e0e0;
    }
} */

/* ====================================
   Smooth Animations
   ==================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.smart-toc-list li {
    animation: fadeIn 0.3s ease forwards;
    opacity: 0;
}

.smart-toc-list li:nth-child(1) { animation-delay: 0.05s; }
.smart-toc-list li:nth-child(2) { animation-delay: 0.1s; }
.smart-toc-list li:nth-child(3) { animation-delay: 0.15s; }
.smart-toc-list li:nth-child(4) { animation-delay: 0.2s; }
.smart-toc-list li:nth-child(5) { animation-delay: 0.25s; }
.smart-toc-list li:nth-child(n+6) { animation-delay: 0.3s; }

/* ====================================
   Custom Scrollbar for TOC
   ==================================== */

.smart-toc-content::-webkit-scrollbar {
    width: 6px;
}

.smart-toc-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.smart-toc-content::-webkit-scrollbar-thumb {
    background: #007bff;
    border-radius: 10px;
}

.smart-toc-content::-webkit-scrollbar-thumb:hover {
    background: #0056b3;
}

/* ====================================
   Focus Visible for Better Accessibility
   ==================================== */

.toc-link:focus-visible {
    outline: 3px solid #007bff;
    outline-offset: 3px;
    border-radius: 4px;
}

.smart-toc-toggle:focus-visible {
    outline: 3px solid rgba(0, 123, 255, 0.5);
    outline-offset: 3px;
}


/* ====================================
   Force Light Theme on Mobile
   ==================================== */
@media (max-width: 768px) {
  .smart-toc-wrapper {
    background: #f8f9fa !important;
    color: #212529 !important;
    border-color: #e9ecef !important;
  }

  .smart-toc-header {
    border-bottom-color: #dee2e6 !important;
  }

  .smart-toc-title {
    color: #212529 !important;
  }

  .toc-link {
    color: #007bff !important;
  }

  .toc-link:hover {
    color: #0056b3 !important;
  }

  .toc-number {
    color: #495057 !important;
  }

  .toc-link.active {
    background: rgba(0, 123, 255, 0.1) !important;
    border-left-color: #007bff !important;
    color: #0056b3 !important;
  }

  .smart-toc-toggle {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3) !important;
  }

  .smart-toc-sublist {
    border-left-color: #e9ecef !important;
  }

  .toc-level-1 .toc-link {
    color: #212529 !important;
  }

  .toc-level-2 .toc-link {
    color: #343a40 !important;
  }

  .toc-level-3 .toc-link {
    color: #495057 !important;
  }

  .toc-level-4 .toc-link,
  .toc-level-5 .toc-link,
  .toc-level-6 .toc-link {
    color: #6c757d !important;
  }

  /* Override any style variations on mobile */
  .smart-toc-wrapper.toc-style-minimal {
    background: transparent !important;
    border-left-color: #007bff !important;
  }

  .smart-toc-wrapper.toc-style-boxed {
    background: #ffffff !important;
    border-color: #007bff !important;
  }

  .smart-toc-wrapper.toc-style-modern {
    background: #f8f9fa !important;
    color: #212529 !important;
  }

  .toc-style-modern .smart-toc-title,
  .toc-style-modern .toc-link {
    color: #007bff !important;
  }

  .toc-style-boxed .smart-toc-header {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%) !important;
  }
}
