/**
 * PyziTheme - toc.css (pyzitheme/assets/css/toc.css)
 * 
 * Styl dla strony, podstron, które będą zawierać spis treści np. strona O mnie
 *
 * @package     PyziTheme
 * @subpackage  Assets/CSS
 * @author      Patryk Kowalski <p.kowalski@kamikstudio.pl>
 * @copyright   2025 KamikStudio & PyziPyzi
 * @license     Proprietary
 * @version     1.0.0
 * @since       1.0.0
 * 
 * Client: PyziPyzi - Domowe wyroby cukiernicze
 * Website: https://pyzipyzi.pl
 * 
 * This file is part of PyziTheme.
 * Unauthorized copying or distribution is prohibited.
 */
 
/* =============================================
   TABLE OF CONTENTS (SPIS TREŚCI)
   ============================================= */

/* === LAYOUT Z TOC === */
.page-with-toc {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 60px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 60px 20px;
    position: relative;
    /* WAŻNE: NIE używaj overflow-x: hidden na desktop - psuje sticky positioning */
}

/* === TOC SIDEBAR (DESKTOP) === */
.page-toc-sidebar {
    position: sticky;
    top: 100px;
    height: fit-content;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding-right: 10px;
}

/* Scrollbar TOC */
.page-toc-sidebar::-webkit-scrollbar {
    width: 6px;
}

.page-toc-sidebar::-webkit-scrollbar-track {
    background: #f5f0e8;
    border-radius: 3px;
}

.page-toc-sidebar::-webkit-scrollbar-thumb {
    background: #ef6341;
    border-radius: 3px;
}

.toc-header {
    font-size: 14px;
    font-weight: 700;
    color: #5e341c;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f5f0e8;
}

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

.toc-item {
    margin-bottom: 8px;
}

.toc-link {
    display: block;
    padding: 8px 15px;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    line-height: 1.4;
    border-left: 3px solid transparent;
    transition: all 0.3s;
    border-radius: 0 6px 6px 0;
}

.toc-link:hover {
    color: #ef6341;
    background: #f5f0e8;
    border-left-color: #ef6341;
    padding-left: 20px;
}

.toc-link.active {
    color: #ef6341;
    background: #f5f0e8;
    border-left-color: #ef6341;
    font-weight: 600;
}

/* Hierarchia nagłówków */
.toc-link[data-level="2"] {
    padding-left: 15px;
    font-weight: 600;
    font-size: 14px;
}

.toc-link[data-level="3"] {
    padding-left: 30px;
    font-size: 13px;
}

.toc-link[data-level="4"] {
    padding-left: 45px;
    font-size: 12px;
    color: #999;
}

.toc-link[data-level="3"]:hover,
.toc-link[data-level="4"]:hover {
    padding-left: 35px;
}

.toc-link[data-level="4"]:hover {
    padding-left: 50px;
}

/* === TOC MOBILE (ACCORDION) === */
.page-toc-mobile {
    display: none;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    margin-bottom: 40px;
    overflow: hidden;
}

.toc-mobile-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: #f5f0e8;
    border: none;
    cursor: pointer;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: #5e341c;
    transition: background 0.3s;
}

.toc-mobile-toggle:hover {
    background: #ebe4d8;
}

.toc-mobile-toggle svg {
    width: 20px;
    height: 20px;
    fill: #ef6341;
    transition: transform 0.3s;
}

.toc-mobile-toggle.active svg {
    transform: rotate(180deg);
}

.toc-mobile-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.toc-mobile-content.active {
    max-height: 600px;
    overflow-y: auto;
}

.toc-mobile-list {
    list-style: none;
    padding: 15px 20px 20px;
    margin: 0;
}

.toc-mobile-list .toc-item {
    margin-bottom: 12px;
}

.toc-mobile-list .toc-link {
    padding: 10px 15px;
    border-left: 3px solid #f5f0e8;
    border-radius: 0 8px 8px 0;
}

.toc-mobile-list .toc-link:hover {
    background: #f5f0e8;
}

/* === FLOATING TOC BUTTON (MOBILE ALTERNATYWA) === */
.toc-floating-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    background: #ef6341;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(239,99,65,0.4);
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: all 0.3s;
}

.toc-floating-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(239,99,65,0.5);
}

.toc-floating-btn svg {
    width: 24px;
    height: 24px;
    fill: white;
}

/* Modal TOC dla floating button */
.toc-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.toc-modal.active {
    display: flex;
}

.toc-modal-content {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
}

.toc-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f5f0e8;
}

.toc-modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #5e341c;
    margin: 0;
}

.toc-modal-close {
    width: 36px;
    height: 36px;
    background: #f5f0e8;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.toc-modal-close:hover {
    background: #ef6341;
}

.toc-modal-close svg {
    width: 18px;
    height: 18px;
    fill: #5e341c;
}

.toc-modal-close:hover svg {
    fill: white;
}

/* === PROGRESS BAR === */
.toc-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background: linear-gradient(90deg, #ef6341 0%, #d55431 100%);
    z-index: 9999;
    transition: width 0.1s ease;
}

/* === SMOOTH SCROLL === */
html {
    scroll-behavior: smooth;
}

/* Offset dla sticky header */
.entry-content h2,
.entry-content h3,
.entry-content h4 {
    scroll-margin-top: 100px;
}

/* === FIX DLA PODPISÓW ZDJĘĆ - WSZYSTKIE ROZDZIELCZOŚCI === */
.page-with-toc .entry-content figcaption {
    font-style: normal !important;
    text-align: center !important;
    font-size: 13px !important;
    color: #666 !important;
    margin-top: 10px !important;
    margin-bottom: 0 !important;
    padding: 8px 12px !important;
    background: #f5f0e8;
    border-radius: 6px;
    line-height: 1.4 !important;
    display: inline-block !important;
    max-width: 100% !important;
}

/* Fix dla obrazów w figure */
.page-with-toc .entry-content figure {
    margin: 30px 0 !important;
    max-width: 100% !important;
    text-align: center !important;
}

.page-with-toc .entry-content figure img {
    margin-bottom: 0 !important;
}

/* === RESPONSYWNOŚĆ === */
@media (max-width: 1024px) {
    .page-with-toc {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 40px 15px;
        overflow-x: hidden; /* Overflow tylko na mobile */
    }

    .page-toc-sidebar {
        display: none;
    }

    .page-toc-mobile {
        display: block;
        margin-left: 0;
        margin-right: 0;
    }

    .toc-floating-btn {
        display: flex;
    }
    
    /* Zapewnij że artykuł nie wychodzi poza ekran */
    .page-article {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Entry content fix */
    .entry-content {
        max-width: 100%;
        overflow-x: hidden;
    }
}

@media (max-width: 768px) {
    .page-with-toc {
        padding: 30px 15px;
    }
    
    .toc-floating-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }

    .toc-modal-content {
        padding: 25px 20px;
    }

    .toc-mobile-content.active {
        max-height: 400px;
    }
    
    /* FIX DLA SZEROKOŚCI OBRAZÓW I TABEL */
    .page-with-toc .entry-content img,
    .page-with-toc .entry-content figure,
    .page-with-toc .entry-content table {
        max-width: 100% !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .page-with-toc .entry-content .alignwide,
    .page-with-toc .entry-content .alignfull {
        max-width: 100% !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* === FIX DLA EMOJI NA MOBILE === */
    .page-with-toc .entry-content img.emoji,
    .page-with-toc .entry-content img[alt*="emoji"],
    .page-with-toc .entry-content img[src*="emoji"],
    .page-with-toc .entry-content img[class*="emoji"] {
        max-width: 20px !important;
        max-height: 20px !important;
        width: 20px !important;
        height: 20px !important;
        display: inline !important;
        margin: 0 4px !important;
        vertical-align: middle !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    
    /* Fix dla dużych dekoracyjnych emoji/grafik */
    .page-with-toc .entry-content p img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        margin: 20px auto !important;
    }
    
    /* Jeśli emoji jest jedynym elementem w paragrafie */
    .page-with-toc .entry-content p > img:only-child {
        max-width: 150px !important;
        max-height: 150px !important;
        width: auto !important;
        height: auto !important;
    }
    
    /* === FIX DLA PODPISÓW ZDJĘĆ - KOMPAKTOWE === */
    .page-with-toc .entry-content figcaption {
        font-style: normal !important;
        text-align: left !important;
        font-size: 12px !important;
        color: #666 !important;
        margin-top: 8px !important;
        margin-bottom: 0 !important;
        padding: 6px 10px !important;
        background: #f5f0e8;
        border-radius: 6px;
        line-height: 1.3 !important;
        display: inline-block !important;
        max-width: 100% !important;
    }
    
    /* Fix dla obrazów w figure */
    .page-with-toc .entry-content figure {
        margin: 20px 0 !important;
        max-width: 100% !important;
    }
    
    .page-with-toc .entry-content figure img {
        margin-bottom: 0 !important;
    }
    
    /* Alt text styling */
    .page-with-toc .entry-content img {
        font-size: 12px !important;
        color: #666 !important;
        font-style: normal !important;
    }
    
    /* === FIX DLA TEKSTU POCHYLONEGO === */
    .page-with-toc .entry-content em,
    .page-with-toc .entry-content i {
        font-style: normal !important;
        font-weight: 500;
    }
    
    /* Zachowaj kursywę dla cytatów */
    .page-with-toc .entry-content blockquote em,
    .page-with-toc .entry-content blockquote i,
    .page-with-toc .entry-content cite {
        font-style: italic !important;
    }
    
    /* === FIX DLA DŁUGIEGO TEKSTU === */
    .page-with-toc .entry-content p,
    .page-with-toc .entry-content div,
    .page-with-toc .entry-content span {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
        hyphens: auto !important;
    }
}

@media (max-width: 480px) {
    .page-with-toc {
        padding: 20px 10px;
    }
    
    .page-with-toc .entry-content figcaption {
        font-size: 11px !important;
        padding: 5px 8px !important;
        line-height: 1.2 !important;
    }
    
    /* Emoji na bardzo małych ekranach */
    .page-with-toc .entry-content img.emoji,
    .page-with-toc .entry-content p > img:only-child {
        max-width: 100px !important;
        max-height: 100px !important;
    }
}

/* === PRINT === */
@media print {
    .page-toc-sidebar,
    .page-toc-mobile,
    .toc-floating-btn,
    .toc-progress-bar {
        display: none !important;
    }

    .page-with-toc {
        grid-template-columns: 1fr;
    }
}