@import url('https://fonts.googleapis.com/css2?family=Lora:wght@500&family=Roboto+Flex:wght@400&display=swap');

:root {
    --contrast: #222222;
    --contrast-2: #575760;
    --contrast-3: #b2b2be;
    --base-2: #f7f8f9;
    --base-3: #ffffff;
    --global-color-8: #1A6B54;
    --global-color-9: #2B8C67;
}

/* Body scroll control - NO global styles, handled in JS per device */
body.seris-toc-open .seris-toc-container {
    pointer-events: all;
    z-index: 999999 !important;
}

/* Floating TOC Button */
.seris-toc-button {
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 20px;
    height: 60px;
    background: var(--global-color-8);
    color: var(--base-3);
    border-radius: 0 6px 6px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 10000 !important;
    transition: all 0.3s ease;
    font-family: 'Roboto Flex', sans-serif;
}

.seris-toc-button.expanded {
    width: 50px;
    background: var(--global-color-9);
}

.seris-toc-button:hover {
    background: var(--global-color-9);
    width: 30px;
}

.seris-toc-button.expanded:hover {
    width: 50px;
}

.seris-toc-button i {
    font-size: 16px;
    transition: all 0.3s ease;
}

.seris-toc-button.expanded i {
    font-size: 20px;
}

/* Button notification */
.seris-toc-notification {
    position: absolute;
    bottom: 65px;
    left: 25px;
    background: var(--contrast);
    color: var(--base-3);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    font-family: 'Roboto Flex', sans-serif;
    z-index: 10001 !important;
}

.seris-toc-notification::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 15px;
    border-width: 6px;
    border-style: solid;
    border-color: var(--contrast) transparent transparent transparent;
}

.seris-toc-notification.active {
    opacity: 1;
    transform: translateY(0);
}

/* Pulse animation */
@keyframes seris-pulse {
    0% { box-shadow: 0 0 0 0 rgba(26, 107, 84, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(26, 107, 84, 0); }
    100% { box-shadow: 0 0 0 0 rgba(26, 107, 84, 0); }
}

.seris-toc-button.pulse {
    animation: seris-pulse 2s infinite;
}

/* TOC Container - DESKTOP FIRST */
.seris-toc-container {
    position: fixed;
    bottom: 90px;
    left: 20px;
    width: 320px;
    max-height: 60vh;
    height: auto;
    background: var(--base-3);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    padding: 0;
    z-index: 999999 !important;
    opacity: 0;
    transform: translateX(-340px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    font-family: 'Roboto Flex', sans-serif;
    display: flex;
    flex-direction: column;
    overflow: visible;
    isolation: isolate;
}

.seris-toc-container.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

/* Header and Search */
.seris-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px 10px;
    border-bottom: 2px solid var(--base-2);
    flex-shrink: 0;
    flex-grow: 0;
    min-height: 50px;
}

.seris-toc-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--contrast);
    font-family: 'Lora', serif;
}

.seris-toc-close {
    background: none;
    border: none;
    color: var(--contrast-2);
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.seris-toc-close:hover {
    background: var(--base-2);
    color: var(--contrast);
}

.seris-toc-search {
    padding: 12px 20px;
    flex-shrink: 0;
    flex-grow: 0;
    min-height: 45px;
}

.seris-toc-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--contrast-3);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--base-2);
    font-family: 'Roboto Flex', sans-serif;
    box-sizing: border-box;
}

.seris-toc-search input:focus {
    outline: none;
    border-color: var(--global-color-8);
    background: var(--base-3);
    box-shadow: 0 0 0 2px rgba(26, 107, 84, 0.1);
}

/* Scrollable List Container */
.seris-toc-list-container {
    flex: 1;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 10px 20px 20px;
    min-height: 0;
    max-height: calc(60vh - 105px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--contrast-3) var(--base-2);
    box-sizing: border-box;
}

.seris-toc-list-container::-webkit-scrollbar {
    width: 6px;
}

.seris-toc-list-container::-webkit-scrollbar-track {
    background: var(--base-2);
    border-radius: 3px;
}

.seris-toc-list-container::-webkit-scrollbar-thumb {
    background: var(--contrast-3);
    border-radius: 3px;
}

.seris-toc-list-container::-webkit-scrollbar-thumb:hover {
    background: var(--contrast-2);
}

/* TOC List */
.seris-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.seris-toc-item,
.seris-toc-sub-item {
    margin: 0;
    padding: 0;
    width: 100%;
}

.seris-toc-item {
    border-bottom: 1px solid var(--base-2);
}

.seris-toc-item:last-child,
.seris-toc-sub-item:last-child {
    border-bottom: none;
}

.seris-toc-link-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 5px;
}

.seris-toc-link, .seris-toc-sub-link {
    display: flex;
    align-items: center;
    padding: 8px 8px;
    text-decoration: none;
    color: var(--contrast);
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 0.88rem;
    min-height: 32px;
    margin: 2px 0;
    border-left: 3px solid transparent;
    font-family: 'Roboto Flex', sans-serif;
    flex: 1;
    box-sizing: border-box;
}

.seris-toc-link:hover, .seris-toc-sub-link:hover {
    background: var(--base-2);
    color: var(--global-color-8);
    border-left-color: var(--global-color-8);
}

.seris-toc-link.active, .seris-toc-sub-link.active {
    background: var(--global-color-9);
    color: var(--base-3);
    border-left-color: #1a5276;
}

/* Toggle Button */
.seris-toc-toggle {
    background: var(--base-2) !important;
    border: 1.5px solid var(--global-color-8) !important;
    color: var(--global-color-8) !important;
    cursor: pointer !important;
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    margin-left: 5px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 4px !important;
    transition: all 0.2s ease !important;
    font-size: 12px !important;
    flex-shrink: 0 !important;
    z-index: 10 !important;
    pointer-events: auto !important;
    position: relative !important;
}

.seris-toc-toggle:hover {
    background: var(--global-color-8) !important;
    color: white !important;
    transform: scale(1.05) !important;
}

.seris-toc-toggle:active {
    transform: scale(0.95) !important;
}

.seris-toc-toggle i {
    pointer-events: none;
}

/* Sublist */
.seris-toc-sublist {
    list-style: none;
    margin: 0;
    padding: 0 0 0 15px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.3s ease;
    background: var(--base-2);
    border-radius: 4px;
}

.seris-toc-sublist.expanded {
    max-height: 2000px !important;
    padding-top: 5px;
    padding-bottom: 5px;
    border-top: 1px solid rgba(0,0,0,0.05);
}

.seris-toc-h3-link { 
    font-weight: 600;
}

.seris-toc-h4-link { 
    color: var(--contrast-2);
    font-size: 0.82rem;
    opacity: 0.8;
}

.seris-toc-text { 
    flex: 1;
    line-height: 1.4;
}

/* No headings message */
.seris-toc-no-headings,
.seris-toc-not-available {
    padding: 20px;
    text-align: center;
    color: var(--contrast-2);
    font-style: italic;
    background: var(--base-2);
}

/* Toggle area - hidden */
.seris-toc-toggle-area {
    display: none;
}

/* TABLET ADJUSTMENTS */
@media (max-width: 1024px) {
    .seris-toc-container {
        bottom: 85px;
        max-height: 55vh;
    }
    
    .seris-toc-list-container {
        max-height: calc(55vh - 105px);
    }
}

/* MOBILE - PROPER FULLSCREEN MODAL */
@media (max-width: 768px) {
    .seris-toc-container {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0.9);
        bottom: auto;
        width: calc(100vw - 40px);
        max-width: 400px;
        max-height: 70vh;
        opacity: 0;
        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    }
    
    .seris-toc-container.active {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    
    /* Add backdrop */
    .seris-toc-container::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }
    
    .seris-toc-container.active::before {
        opacity: 1;
        pointer-events: all;
    }
    
    .seris-toc-list-container {
        max-height: calc(70vh - 110px);
        padding: 8px 15px 15px;
    }
    
    .seris-toc-header {
        padding: 15px;
        min-height: 50px;
    }
    
    .seris-toc-search {
        padding: 10px 15px;
        min-height: 45px;
    }
    
    .seris-toc-link, .seris-toc-sub-link {
        font-size: 0.88rem;
        padding: 10px 8px;
        min-height: 36px;
    }
    
    .seris-toc-button {
        width: 22px;
        height: 60px;
        bottom: 20px;
    }
    
    .seris-toc-button.expanded {
        width: 50px;
    }
    
    .seris-toc-toggle {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        font-size: 13px !important;
    }
}

/* SMALL MOBILE */
@media (max-width: 480px) {
    .seris-toc-container {
        width: calc(100vw - 30px);
        max-height: 75vh;
    }
    
    .seris-toc-list-container {
        max-height: calc(75vh - 105px);
        padding: 8px 12px 12px;
    }
    
    .seris-toc-header {
        padding: 12px;
    }
    
    .seris-toc-search {
        padding: 10px 12px;
    }
    
    .seris-toc-link, .seris-toc-sub-link {
        font-size: 0.85rem;
        padding: 8px 6px;
    }
    
    .seris-toc-title {
        font-size: 1rem;
    }
}