/**
 * Auto Table of Contents (TOC) Styles
 * 
 * Modern, Clean, Minimalist Design
 * Color Scheme: Green Pastel
 * 
 * @package PlantPedia
 * @version 1.0.0
 */

/* ==========================================================================
   TOC Container
   ========================================================================== */

.plantpedia-toc {
    /* Box Model */
    margin: 30px 0;
    padding: 0;
    max-width: 100%;
    
    /* Visual */
    background: linear-gradient(135deg, #e9f5ec 0%, #f0f9f2 100%);
    border: 1px solid #c3e6cb;
    border-left: 4px solid #2d6a4f;
    border-radius: 8px;
    
    /* Effects */
    box-shadow: 0 2px 8px rgba(45, 106, 79, 0.08);
    
    /* Animation */
    transition: box-shadow 0.3s ease;
}

.plantpedia-toc:hover {
    box-shadow: 0 4px 16px rgba(45, 106, 79, 0.12);
}

/* ==========================================================================
   TOC Header
   ========================================================================== */

.toc-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: rgba(45, 106, 79, 0.05);
    border-bottom: 1px solid rgba(45, 106, 79, 0.1);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    user-select: none;
}

.toc-icon {
    font-size: 20px;
    line-height: 1;
}

.toc-title {
    font-size: 16px;
    font-weight: 600;
    color: #2d6a4f;
    letter-spacing: -0.02em;
}

.toc-count {
    font-size: 13px;
    color: #52b788;
    font-weight: 500;
}

/* Toggle Button */
.toc-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 8px 14px;
    
    background: #fff;
    border: 1px solid #c3e6cb;
    border-radius: 6px;
    
    font-size: 13px;
    font-weight: 500;
    color: #2d6a4f;
    
    cursor: pointer;
    transition: all 0.2s ease;
}

.toc-toggle:hover {
    background: #2d6a4f;
    color: #fff;
    border-color: #2d6a4f;
}

.toggle-icon {
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    transition: transform 0.3s ease;
}

/* Collapsed state */
.plantpedia-toc.is-collapsed .toggle-icon {
    transform: rotate(0deg);
}

.plantpedia-toc.is-collapsed .toggle-text::before {
    content: "แสดง";
}

.plantpedia-toc.is-collapsed .toggle-text {
    font-size: 0;
}

.plantpedia-toc.is-collapsed .toggle-icon::before {
    content: "+";
}

.plantpedia-toc:not(.is-collapsed) .toggle-icon::before {
    content: "−";
}

/* ==========================================================================
   TOC Content
   ========================================================================== */

.toc-content {
    padding: 0;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.3s ease, opacity 0.3s ease;
}

/* Collapsed state */
.plantpedia-toc.is-collapsed .toc-content {
    max-height: 0;
    opacity: 0;
    padding: 0;
}

.plantpedia-toc:not(.is-collapsed) .toc-content {
    opacity: 1;
    padding: 16px 20px;
}

/* ==========================================================================
   TOC List
   ========================================================================== */

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

.toc-item {
    margin: 0;
    padding: 0;
}

/* Indent for H3 */
.toc-item.toc-indent {
    margin-left: 20px;
}

.toc-item.toc-indent .toc-link {
    font-size: 14px;
}

.toc-item.toc-indent .toc-link::before {
    content: "└";
    margin-right: 8px;
    color: #95d5b2;
    font-size: 12px;
}

/* TOC Link */
.toc-link {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px;
    margin: 4px 0;
    
    text-decoration: none;
    color: #2d6a4f;
    font-size: 15px;
    line-height: 1.5;
    
    background: transparent;
    border-radius: 6px;
    
    transition: all 0.2s ease;
}

.toc-link:hover {
    background: rgba(45, 106, 79, 0.1);
    color: #1b4332;
    transform: translateX(4px);
}

.toc-link:active {
    background: rgba(45, 106, 79, 0.15);
}

/* Active state (when scrolled to section) */
.toc-link.is-active {
    background: #2d6a4f;
    color: #fff;
    font-weight: 500;
}

.toc-link.is-active .toc-number {
    color: #95d5b2;
}

/* Number */
.toc-number {
    flex-shrink: 0;
    min-width: 24px;
    font-weight: 600;
    color: #52b788;
    font-size: 13px;
}

/* Text */
.toc-text {
    flex: 1;
}

/* ==========================================================================
   Heading Target Styles (Scroll Offset)
   ========================================================================== */

/* Add scroll margin to headings */
h2[id],
h3[id] {
    scroll-margin-top: 100px;
}

/* Highlight heading when targeted */
h2[id]:target,
h3[id]:target {
    animation: highlight-heading 2s ease;
}

@keyframes highlight-heading {
    0%, 30% {
        background: linear-gradient(90deg, #e9f5ec, transparent);
        border-left: 3px solid #2d6a4f;
        padding-left: 12px;
        margin-left: -15px;
    }
    100% {
        background: transparent;
        border-left: none;
        padding-left: 0;
        margin-left: 0;
    }
}

/* ==========================================================================
   Mobile Styles (< 768px)
   ========================================================================== */

@media (max-width: 991px) {
    .plantpedia-toc {
        margin: 20px 0;
        border-radius: 10px;
    }
    
    /* Header - Larger touch target */
    .toc-header {
        padding: 14px 16px;
        flex-wrap: wrap;
    }
    
    .toc-icon {
        font-size: 18px;
    }
    
    .toc-title {
        font-size: 15px;
    }
    
    .toc-count {
        font-size: 12px;
    }
    
    /* Toggle Button - Larger for mobile */
    .toc-toggle {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px; /* Accessibility: minimum touch target */
        border-radius: 8px;
    }
    
    /* Content */
    .plantpedia-toc:not(.is-collapsed) .toc-content {
        padding: 12px 16px;
        max-height: 400px;
        overflow-y: auto;
    }
    
    /* Links - Larger touch target */
    .toc-link {
        padding: 12px 14px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .toc-item.toc-indent {
        margin-left: 12px;
    }
    
    .toc-item.toc-indent .toc-link {
        font-size: 13px;
    }
    
    /* Start collapsed on mobile */
    .plantpedia-toc.mobile-collapsed .toc-content {
        max-height: 0;
        opacity: 0;
        padding: 0;
    }
    
    /* Scroll margin for mobile */
    h2[id],
    h3[id] {
        scroll-margin-top: 80px;
    }
}

/* ==========================================================================
   Tablet Styles (768px - 1024px)
   ========================================================================== */

@media (min-width: 992px) and (max-width: 1024px) {
    .plantpedia-toc {
        margin: 25px 0;
    }
    
    .toc-header {
        padding: 15px 18px;
    }
    
    .toc-toggle {
        padding: 8px 12px;
    }
    
    .plantpedia-toc:not(.is-collapsed) .toc-content {
        padding: 14px 18px;
    }
}

/* ==========================================================================
   Dark Mode Support (Optional)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .plantpedia-toc {
        background: linear-gradient(135deg, #1a3a2a 0%, #0d261a 100%);
        border-color: #2d5a4f;
    }
    
    .toc-header {
        background: rgba(255, 255, 255, 0.05);
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
    
    .toc-title {
        color: #95d5b2;
    }
    
    .toc-count {
        color: #74c69d;
    }
    
    .toc-toggle {
        background: #1a3a2a;
        border-color: #2d5a4f;
        color: #95d5b2;
    }
    
    .toc-toggle:hover {
        background: #95d5b2;
        color: #1a3a2a;
    }
    
    .toc-link {
        color: #b7e4c7;
    }
    
    .toc-link:hover {
        background: rgba(149, 213, 178, 0.1);
        color: #d8f3dc;
    }
    
    .toc-link.is-active {
        background: #52b788;
        color: #081c15;
    }
    
    .toc-number {
        color: #74c69d;
    }
}

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

@media print {
    .plantpedia-toc {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #999;
        box-shadow: none;
    }
    
    .toc-toggle {
        display: none;
    }
    
    .toc-content {
        max-height: none !important;
        opacity: 1 !important;
        padding: 16px 20px !important;
    }
    
    .toc-link {
        color: #000;
    }
    
    .toc-link::after {
        content: " (หน้า " attr(href) ")";
        font-size: 11px;
        color: #666;
    }
}

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

/* Focus styles */
.toc-toggle:focus,
.toc-link:focus {
    outline: 2px solid #2d6a4f;
    outline-offset: 2px;
}

.toc-toggle:focus:not(:focus-visible),
.toc-link:focus:not(:focus-visible) {
    outline: none;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .plantpedia-toc,
    .toc-content,
    .toc-link,
    .toc-toggle,
    .toggle-icon,
    h2[id]:target,
    h3[id]:target {
        transition: none;
        animation: none;
    }
}

/* ==========================================================================
   Shortcode Version
   ========================================================================== */

.plantpedia-toc-shortcode {
    /* Same styles, just for identification */
}
