/**
 * Solace Custom TOC - Styles
 * CSS Grid layout with sticky TOC and optional sidebar
 */

/* ==========================================================================
   Layout Wrapper - CSS Grid for 2-col or 3-col
   ========================================================================== */

.toc-layout-wrapper {
    position: relative;
    width: 100%;
}

/* Hide empty p tags that WordPress wpautop adds between shortcodes */
.toc-layout-wrapper > p:empty,
.toc-layout-wrapper > p:blank,
.toc-layout-wrapper > p:not(:has(*)):not(:has(img)) {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 0 !important;
    line-height: 0 !important;
}

/* Fallback: hide p tags that only contain whitespace or nbsp */
.toc-layout-wrapper > p {
    /* If p tag breaks grid, this ensures it doesn't take space */
}
.toc-layout-wrapper > p:only-child {
    /* Don't hide if it's the only child (actual content) */
}
.toc-layout-wrapper > p + .toc-menu-section,
.toc-layout-wrapper > .toc-menu-section + p,
.toc-layout-wrapper > p + .toc-content-section,
.toc-layout-wrapper > .toc-content-section + p,
.toc-layout-wrapper > p + .toc-sidebar-section,
.toc-layout-wrapper > .toc-sidebar-section + p {
    /* Adjacent p tags to sections - the p is likely empty wpautop junk */
}

/* Hide p tags that are direct children of wrapper to prevent grid breakage.
   Content inside section divs is not affected by this rule. */
.toc-layout-wrapper > p {
    display: none !important;
}

/* Desktop: 2-column layout (TOC + Content) */
@media (min-width: 1200px) {
    .toc-layout-wrapper.toc-layout-two-col {
        display: grid;
        grid-template-columns: 320px 1fr;
        gap: 40px;
    }
}

/* Desktop: 3-column layout (TOC + Content + Sidebar) */
@media (min-width: 1200px) {
    .toc-layout-wrapper.toc-layout-three-col {
        display: grid;
        grid-template-columns: 320px 1fr 300px;
        gap: 40px;
    }
}

/* ==========================================================================
   TOC Menu Section - Sticky in grid
   ========================================================================== */

@media (min-width: 1200px) {
    .toc-layout-wrapper .toc-menu-section {
        position: sticky;
        top: 80px;
        align-self: start;
        height: fit-content;
        background-color: var(--sgreenlight);
        border: 1px solid var(--sgreen);
        z-index: 3;
        border-radius: 8px;
        padding: 10px 0;
    }

    .admin-bar .toc-layout-wrapper .toc-menu-section {
        top: 112px;
    }

    /* Override any float from base CSS */
    .toc-layout-wrapper .toc-menu-section {
        float: none !important;
        width: 100% !important;
    }

    /* Ensure list items are visible */
    .toc-layout-wrapper .toc-menu-inner li {
        position: relative !important;
        width: auto !important;
    }

    .toc-layout-wrapper .toc-menu-inner li a {
        opacity: 1 !important;
        position: relative !important;
    }

    .toc-menu-section .toc-menu-inner {
        margin: 0 !important;
    }
}

/* ==========================================================================
   TOC Menu Inner Styles - 3-level accordion structure
   Like IBM: no padding on container, padding on each element
   ========================================================================== */

/* Title - has its own padding */
.toc-menu-section .toc-title {
    padding: 16px 16px 12px 16px;
    margin: 0;
}

/* Reset list styles */
.toc-menu-inner,
.toc-menu-inner ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Base item styles */
.toc-menu-inner .toc-item {
    position: relative;
}

/* Toggle arrow - positioned relative to each level's padding */
.toc-toggle {
    position: absolute;
    top: -2px;
    width: 20px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #666;
    z-index: 1;
}

.toc-toggle svg {
    transition: transform 0.2s ease;
}

/* Rotate arrow when expanded */
.toc-item.toc-expanded > .toc-toggle svg {
    transform: rotate(90deg);
}

/* Nav link styles - base */
.toc-menu-inner .toc-nav-link {
    display: block;
    padding: 6px 16px;
    color: #273749;
    text-decoration: none;
    font-size: 14px;
    line-height: 1.4;
    border-left: none;
    transition: color 0.2s ease, background-color 0.2s ease;
}

/* Expandable items (with children) - cursor pointer */
.toc-menu-inner .toc-expandable {
    cursor: pointer;
}

/* ==========================================================================
   Level 1 - Parent items (padding-left: 16px base, +20px if has toggle)
   ========================================================================== */
.toc-menu-inner > .toc-item > .toc-toggle {
    left: 12px;
}

.toc-menu-inner > .toc-item.toc-has-children > .toc-nav-link {
    font-weight: 600;
    padding-left: 32px; /* 12px + 20px toggle space */
}

.toc-menu-inner > .toc-item:not(.toc-has-children) > .toc-nav-link {
    font-weight: 600;
    padding-left: 16px;
}

/* ==========================================================================
   Level 2 - Child items (indent from level 1)
   ========================================================================== */
.toc-submenu > .toc-item > .toc-toggle {
    left: 24px;
}

.toc-submenu > .toc-item.toc-has-children > .toc-nav-link {
    font-weight: 400;
    padding-left: 44px;
}

.toc-submenu > .toc-item:not(.toc-has-children) > .toc-nav-link {
    font-weight: 400;
    padding-left: 44px;
}

/* ==========================================================================
   Level 3 - Grandchild items (indent from level 2)
   ========================================================================== */
.toc-submenu .toc-submenu > .toc-item > .toc-toggle {
    left: 40px;
}

.toc-submenu .toc-submenu > .toc-item.toc-has-children > .toc-nav-link {
    padding-left: 56px;
    font-size: 14px;
}

.toc-submenu .toc-submenu > .toc-item:not(.toc-has-children) > .toc-nav-link {
    padding-left: 56px;
    font-size: 14px;
}

/* ==========================================================================
   States
   ========================================================================== */

/* Hover states */
.toc-menu-inner .toc-nav-link:hover {
    color: #00c895;
    background-color: rgba(0, 200, 149, 0.08);
}

/* Active state - full width background */
.toc-menu-inner .toc-item.toc-active > .toc-nav-link {
    background-color: var(--sblue);
    color: white;
    font-weight: 600;
}

/* Submenu - hidden by default */
.toc-submenu {
    display: none;
    overflow: hidden;
    margin: 0 !important;
}

/* Submenu - visible when parent is expanded */
.toc-item.toc-expanded > .toc-submenu {
    display: block;
}

/* Remove default border-left from all links */
.toc-menu-inner .toc-nav-link {
    border-left: none !important;
}

/* ==========================================================================
   Mobile Slide-in Drawer
   ========================================================================== */

@media (max-width: 1199px) {
    /* Mobile: Stack layout */
    .toc-layout-wrapper {
        display: block;
    }

    /* TOC drawer - hidden off-screen by default */
    .toc-menu-section {
        position: fixed;
        top: 0;
        left: -320px;
        width: 300px;
        height: 100vh;
        background-color: var(--sgreenlight);
        z-index: 9999;
        overflow-y: auto;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.15);
        transition: left 0.3s ease;
        padding: 10px 0;
        border: none;
    }

    .admin-bar .toc-menu-section {
        top: 46px;
        height: calc(100vh - 46px);
    }

    @media (max-width: 782px) {
        .admin-bar .toc-menu-section {
            top: 0;
            height: 100vh;
        }
    }

    /* Drawer open state */
    .toc-menu-section.toc-drawer-open {
        left: 0;
    }

    /* Show all items when drawer is open */
    .toc-menu-section .toc-menu-inner li,
    .toc-menu-section .toc-menu-inner li a {
        position: relative !important;
        opacity: 1 !important;
        width: auto !important;
    }

    /* Close button inside drawer */
    .toc-drawer-close {
        position: absolute;
        top: 15px;
        right: 15px;
        width: 32px;
        height: 32px;
        background: #f3f4f6;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        color: #273749;
        transition: background-color 0.2s ease;
        z-index:10;
    }

    .toc-drawer-close:hover {
        background-color: #e0e0e0;
    }

    /* Overlay behind drawer */
    .toc-drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .toc-drawer-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Half-circle toggle button - sticks to left edge, vertically centered */
    .toc-drawer-toggle {
        position: fixed;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 28px;
        height: 56px;
        background-color: #00c895;
        border: none;
        border-radius: 0 28px 28px 0;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 16px;
        z-index: 9997;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
        transition: background-color 0.2s ease, width 0.2s ease;
        padding-left: 4px;
    }

    .toc-drawer-toggle:hover {
        background-color: #00b386;
        width: 34px;
    }

    .toc-drawer-toggle:active {
        background-color: #009970;
    }

    /* Hide toggle when drawer is open */
    .toc-drawer-toggle.hidden {
        opacity: 0;
        pointer-events: none;
    }

    /* Title in mobile drawer */
    .toc-menu-section .toc-title {
        padding: 10px 50px 10px 16px;
        margin: 0;
    }

    .toc-menu-section .toc-menu-inner {
        margin: 0 !important;
    }
}

/* Hide mobile elements on desktop */
@media (min-width: 1200px) {
    .toc-drawer-toggle,
    .toc-drawer-overlay,
    .toc-drawer-close {
        display: none !important;
    }
}

/* ==========================================================================
   Right Sidebar Section
   ========================================================================== */

.toc-sidebar-section {
    background-color: #fff;
}

@media (min-width: 1200px) {
    .toc-layout-wrapper .toc-sidebar-section {
        position: sticky;
        top: 80px;
        align-self: start;
        height: fit-content;
        z-index: 3;
    }

    .admin-bar .toc-layout-wrapper .toc-sidebar-section {
        top: 112px;
    }
}

.toc-sidebar-inner {
    padding: 0;
}

/* Card styling for sidebar content */
.toc-sidebar-inner .toc-sidebar-card {
    background-color: #f3f4f6;
    border-radius: 0;
    padding: 30px;
    margin-bottom: 20px;
}

.toc-sidebar-inner .toc-sidebar-card-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #666;
    margin-bottom: 10px;
}

.toc-sidebar-inner .toc-sidebar-card-title {
    font-size: 22px;
    font-weight: 600;
    color: #273749;
    line-height: 1.3;
    margin-bottom: 20px;
}

.toc-sidebar-inner .toc-sidebar-card-text {
    font-size: 14px;
    line-height: 1.6;
    color: #666;
    margin-bottom: 20px;
}

.toc-sidebar-inner .toc-sidebar-card-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #0f62fe;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s ease;
}

.toc-sidebar-inner .toc-sidebar-card-link:hover {
    color: #0043ce;
    text-decoration: underline;
}

.toc-sidebar-inner .toc-sidebar-card-link::after {
    content: '\2192';
    font-size: 16px;
}

/* Mobile: Show sidebar below content */
@media (max-width: 1199px) {
    .toc-sidebar-section {
        display: block;
        margin-top: 40px;
        padding: 0 20px;
    }
}
