/**
 * Frontend styles for Smart TOC Pro
 * 
 * @package Smart_TOC_Generator
 * @version 1.0.0
 */

/* ========================================
   TOC Container Base Styles
   ======================================== */

.smart-toc-container {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
}

.smart-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.smart-toc-title {
    margin: 0;
    font-size: 1.25em;
    font-weight: 600;
    color: #333;
}

.smart-toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.smart-toc-toggle:hover {
    transform: scale(1.1);
}

.smart-toc-toggle-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.smart-toc-toggle-icon::before,
.smart-toc-toggle-icon::after {
    content: '';
    position: absolute;
    background-color: #666;
    transition: transform 0.3s ease;
}

.smart-toc-toggle-icon::before {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.smart-toc-toggle-icon::after {
    width: 2px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.smart-toc-container.collapsed .smart-toc-toggle-icon::after {
    transform: translateX(-50%) rotate(90deg);
}

.smart-toc-list {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.smart-toc-container.collapsed .smart-toc-list {
    max-height: 0;
    opacity: 0;
}

.smart-toc-list ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.smart-toc-list li {
    margin: 8px 0;
}

.smart-toc-list a {
    text-decoration: none;
    color: #0073aa;
    transition: color 0.2s ease;
    display: inline-block;
}

.smart-toc-list a:hover {
    color: #005177;
    text-decoration: underline;
}

.smart-toc-list a.active {
    font-weight: 600;
    color: #005177;
}

/* ========================================
   Heading Level Indentation
   ======================================== */

.smart-toc-h1 { padding-left: 0; }
.smart-toc-h2 { padding-left: 0; }
.smart-toc-h3 { padding-left: 20px; }
.smart-toc-h4 { padding-left: 40px; }
.smart-toc-h5 { padding-left: 60px; }
.smart-toc-h6 { padding-left: 80px; }

/* ========================================
   Template: Minimal
   ======================================== */

.smart-toc-template-minimal {
    background-color: #f9f9f9;
    padding: 20px;
    border-radius: 4px;
}

.smart-toc-template-minimal .smart-toc-title {
    color: #333;
}

/* ========================================
   Template: Boxed
   ======================================== */

.smart-toc-template-boxed {
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.smart-toc-template-boxed .smart-toc-header {
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 15px;
}

.smart-toc-template-boxed .smart-toc-title {
    color: #2c3e50;
}

/* ========================================
   Template: Bordered
   ======================================== */

.smart-toc-template-bordered {
    background-color: #fff;
    border-left: 4px solid #0073aa;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.smart-toc-template-bordered .smart-toc-title {
    color: #0073aa;
}

.smart-toc-template-bordered .smart-toc-list a {
    color: #2c3e50;
}

.smart-toc-template-bordered .smart-toc-list a:hover {
    color: #0073aa;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .smart-toc-container {
        font-size: 14px;
        margin: 15px 0;
        padding: 15px;
    }

    .smart-toc-title {
        font-size: 1.1em;
    }

    .smart-toc-h3 { padding-left: 15px; }
    .smart-toc-h4 { padding-left: 30px; }
    .smart-toc-h5 { padding-left: 45px; }
    .smart-toc-h6 { padding-left: 60px; }
}

@media (max-width: 480px) {
    .smart-toc-container {
        font-size: 13px;
        padding: 12px;
    }

    .smart-toc-list li {
        margin: 6px 0;
    }
}

/* ========================================
   Smooth Scroll Offset
   ======================================== */

html {
    scroll-behavior: smooth;
}

/* Utility class for scroll offset */
.smart-toc-anchor {
    display: block;
    position: relative;
    top: -100px;
    visibility: hidden;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .smart-toc-container {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .smart-toc-toggle {
        display: none;
    }

    .smart-toc-list {
        max-height: none !important;
        opacity: 1 !important;
    }
}

/* ========================================
   Accessibility
   ======================================== */

.smart-toc-list a:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.smart-toc-toggle:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
    border-radius: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .smart-toc-container {
        border: 2px solid currentColor;
    }

    .smart-toc-list a {
        text-decoration: underline;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .smart-toc-list,
    .smart-toc-toggle,
    .smart-toc-list a {
        transition: none;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ========================================
   RTL Support
   ======================================== */

[dir="rtl"] .smart-toc-h3 { padding-right: 20px; padding-left: 0; }
[dir="rtl"] .smart-toc-h4 { padding-right: 40px; padding-left: 0; }
[dir="rtl"] .smart-toc-h5 { padding-right: 60px; padding-left: 0; }
[dir="rtl"] .smart-toc-h6 { padding-right: 80px; padding-left: 0; }

[dir="rtl"] .smart-toc-template-bordered {
    border-left: none;
    border-right: 4px solid #0073aa;
}

/* ========================================
   Template: Modern Gradient
   ======================================== */

.smart-toc-template-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.smart-toc-template-gradient .smart-toc-title {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.smart-toc-template-gradient .smart-toc-list a {
    color: #ffffff;
    opacity: 0.9;
}

.smart-toc-template-gradient .smart-toc-list a:hover {
    opacity: 1;
    text-decoration: underline;
}

.smart-toc-template-gradient .smart-toc-list a.active {
    opacity: 1;
    font-weight: 600;
}

.smart-toc-template-gradient .smart-toc-toggle-icon::before,
.smart-toc-template-gradient .smart-toc-toggle-icon::after {
    background-color: #ffffff;
}

/* ========================================
   Template: Card
   ======================================== */

.smart-toc-template-card {
    background-color: #ffffff;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.smart-toc-template-card .smart-toc-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.smart-toc-template-card .smart-toc-title {
    color: #1a202c;
    font-size: 1.3em;
}

.smart-toc-template-card .smart-toc-list a {
    color: #4a5568;
    padding: 5px 0;
    display: block;
}

.smart-toc-template-card .smart-toc-list a:hover {
    color: #2d3748;
    transform: translateX(5px);
    transition: transform 0.2s ease;
}

.smart-toc-template-card .smart-toc-list a.active {
    color: #667eea;
    font-weight: 600;
}

/* ========================================
   Template: Sidebar
   ======================================== */

.smart-toc-template-sidebar {
    background-color: #f7fafc;
    border-left: 3px solid #4299e1;
    padding: 20px;
    font-size: 14px;
}

.smart-toc-template-sidebar .smart-toc-title {
    color: #2d3748;
    font-size: 1.1em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.smart-toc-template-sidebar .smart-toc-list a {
    color: #4a5568;
    padding: 8px 0;
    display: block;
    border-bottom: 1px solid #e2e8f0;
}

.smart-toc-template-sidebar .smart-toc-list a:hover {
    color: #4299e1;
    padding-left: 5px;
    transition: padding-left 0.2s ease;
}

.smart-toc-template-sidebar .smart-toc-list a.active {
    color: #4299e1;
    font-weight: 600;
    border-left: 3px solid #4299e1;
    padding-left: 10px;
}

/* ========================================
   Template: Compact
   ======================================== */

.smart-toc-template-compact {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 15px;
    border-radius: 6px;
    font-size: 14px;
}

.smart-toc-template-compact .smart-toc-header {
    margin-bottom: 12px;
}

.smart-toc-template-compact .smart-toc-title {
    color: #2d3748;
    font-size: 1em;
    font-weight: 600;
}

.smart-toc-template-compact .smart-toc-list {
    line-height: 1.4;
}

.smart-toc-template-compact .smart-toc-list ul {
    margin: 0;
}

.smart-toc-template-compact .smart-toc-list li {
    margin: 4px 0;
}

.smart-toc-template-compact .smart-toc-list a {
    color: #4a5568;
    font-size: 13px;
}

.smart-toc-template-compact .smart-toc-list a:hover {
    color: #2b6cb0;
}

.smart-toc-template-compact .smart-toc-list a.active {
    color: #2b6cb0;
    font-weight: 600;
}

.smart-toc-template-compact .smart-toc-h3 {
    padding-left: 15px;
}

.smart-toc-template-compact .smart-toc-h4 {
    padding-left: 30px;
}

/* ========================================
   Sticky/Floating TOC
   ======================================== */

/* Sticky positioning */
.smart-toc-container.smart-toc-sticky {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    z-index: 100;
}

/* Floating (fixed) positioning */
.smart-toc-container.smart-toc-floating {
    position: fixed;
    top: 20px;
    max-width: 300px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Adjust for WordPress admin bar when logged in */
.admin-bar .smart-toc-container.smart-toc-floating {
    top: 52px; /* 32px admin bar + 20px spacing */
    max-height: calc(100vh - 72px); /* Adjust height accordingly */
}

.smart-toc-container.smart-toc-floating.smart-toc-left {
    left: 20px;
}

.smart-toc-container.smart-toc-floating.smart-toc-right {
    right: 20px;
}

/* Hide on scroll option */
.smart-toc-container.smart-toc-floating.smart-toc-hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.smart-toc-container.smart-toc-floating.smart-toc-visible {
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Scrollbar styling for sticky/floating TOC */
.smart-toc-container.smart-toc-sticky::-webkit-scrollbar,
.smart-toc-container.smart-toc-floating::-webkit-scrollbar {
    width: 6px;
}

.smart-toc-container.smart-toc-sticky::-webkit-scrollbar-track,
.smart-toc-container.smart-toc-floating::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.smart-toc-container.smart-toc-sticky::-webkit-scrollbar-thumb,
.smart-toc-container.smart-toc-floating::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.smart-toc-container.smart-toc-sticky::-webkit-scrollbar-thumb:hover,
.smart-toc-container.smart-toc-floating::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Mobile: disable sticky/floating */
@media (max-width: 768px) {
    .smart-toc-container.smart-toc-sticky,
    .smart-toc-container.smart-toc-floating {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        max-width: 100%;
        max-height: none;
        overflow-y: visible;
    }
}

/* ========================================
   Back to Top Button
   ======================================== */

.smart-toc-back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background-color: #0073aa;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    z-index: 9999;
}

.smart-toc-back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.smart-toc-back-to-top:hover {
    background-color: #005177;
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.smart-toc-back-to-top:active {
    transform: translateY(-1px);
}

.smart-toc-back-to-top:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .smart-toc-back-to-top {
        width: 45px;
        height: 45px;
        bottom: 20px;
        right: 20px;
        font-size: 20px;
    }
}

/* ========================================
   Dark Mode Support
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Minimal Template - Dark Mode */
    .smart-toc-template-minimal {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }
    
    .smart-toc-template-minimal .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-template-minimal .smart-toc-list a {
        color: #58a6ff;
    }
    
    .smart-toc-template-minimal .smart-toc-list a:hover {
        color: #79c0ff;
    }
    
    .smart-toc-template-minimal .smart-toc-list a.active {
        color: #79c0ff;
        font-weight: 600;
    }
    
    .smart-toc-template-minimal .smart-toc-toggle-icon::before,
    .smart-toc-template-minimal .smart-toc-toggle-icon::after {
        background-color: #e0e0e0;
    }
    
    /* Boxed Template - Dark Mode */
    .smart-toc-template-boxed {
        background-color: #1e1e1e;
        border-color: #404040;
        color: #e0e0e0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    }
    
    .smart-toc-template-boxed .smart-toc-header {
        border-bottom-color: #404040;
    }
    
    .smart-toc-template-boxed .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-template-boxed .smart-toc-list a {
        color: #58a6ff;
    }
    
    .smart-toc-template-boxed .smart-toc-list a:hover {
        color: #79c0ff;
    }
    
    .smart-toc-template-boxed .smart-toc-list a.active {
        color: #79c0ff;
        font-weight: 600;
    }
    
    .smart-toc-template-boxed .smart-toc-toggle-icon::before,
    .smart-toc-template-boxed .smart-toc-toggle-icon::after {
        background-color: #e0e0e0;
    }
    
    /* Bordered Template - Dark Mode */
    .smart-toc-template-bordered {
        background-color: #1e1e1e;
        border-left-color: #58a6ff;
        color: #e0e0e0;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    }
    
    .smart-toc-template-bordered .smart-toc-title {
        color: #58a6ff;
    }
    
    .smart-toc-template-bordered .smart-toc-list a {
        color: #e0e0e0;
    }
    
    .smart-toc-template-bordered .smart-toc-list a:hover {
        color: #58a6ff;
    }
    
    .smart-toc-template-bordered .smart-toc-list a.active {
        color: #58a6ff;
        font-weight: 600;
    }
    
    .smart-toc-template-bordered .smart-toc-toggle-icon::before,
    .smart-toc-template-bordered .smart-toc-toggle-icon::after {
        background-color: #e0e0e0;
    }
    
    /* RTL Dark Mode */
    [dir="rtl"] .smart-toc-template-bordered {
        border-right-color: #58a6ff;
    }
    
    /* Gradient Template - Dark Mode (adjust gradient) */
    .smart-toc-template-gradient {
        background: linear-gradient(135deg, #4c5fd5 0%, #5a3d7a 100%);
    }
    
    /* Card Template - Dark Mode */
    .smart-toc-template-card {
        background-color: #1e1e1e;
        border-color: #404040;
    }
    
    .smart-toc-template-card .smart-toc-header {
        border-bottom-color: #404040;
    }
    
    .smart-toc-template-card .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-template-card .smart-toc-list a {
        color: #b0b0b0;
    }
    
    .smart-toc-template-card .smart-toc-list a:hover {
        color: #58a6ff;
    }
    
    .smart-toc-template-card .smart-toc-list a.active {
        color: #58a6ff;
    }
    
    /* Sidebar Template - Dark Mode */
    .smart-toc-template-sidebar {
        background-color: #2d2d2d;
        border-left-color: #58a6ff;
    }
    
    .smart-toc-template-sidebar .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-template-sidebar .smart-toc-list a {
        color: #b0b0b0;
        border-bottom-color: #404040;
    }
    
    .smart-toc-template-sidebar .smart-toc-list a:hover {
        color: #58a6ff;
    }
    
    .smart-toc-template-sidebar .smart-toc-list a.active {
        color: #58a6ff;
        border-left-color: #58a6ff;
    }
    
    /* Compact Template - Dark Mode */
    .smart-toc-template-compact {
        background-color: #1e1e1e;
        border-color: #404040;
    }
    
    .smart-toc-template-compact .smart-toc-title {
        color: #ffffff;
    }
    
    .smart-toc-template-compact .smart-toc-list a {
        color: #b0b0b0;
    }
    
    .smart-toc-template-compact .smart-toc-list a:hover {
        color: #58a6ff;
    }
    
    .smart-toc-template-compact .smart-toc-list a.active {
        color: #58a6ff;
    }
    
    /* Back to Top Button - Dark Mode */
    .smart-toc-back-to-top {
        background-color: #58a6ff;
    }
    
    .smart-toc-back-to-top:hover {
        background-color: #79c0ff;
    }
}
