/*--------------------------------------------------------------
# Table of Contents Block Styles
--------------------------------------------------------------*/

/* --- Base Block Styles --- */
.wp-block-umbc-table-of-contents {
    background-color: #fff;
    /* Rounded corners */
    border: 1px solid #F1F1F1;
    box-shadow: 9px 9px 12px rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    /* Slightly stronger shadow */
    position: relative;
    margin: 0 1rem 1rem;
}

/* --- Header --- */
.wp-block-umbc-table-of-contents .toc-header {
    display: flex;
    align-items: center;
    /* Less space below header */
    padding: 0.5rem;
    /* Add padding for background */
    border-bottom: 1px solid #F1F1F1;
    border-radius: 8px 8px 0 0;
    /* Align title left (Point 3) */
    justify-content: flex-start;
}

.wp-block-umbc-table-of-contents .toc-title {
    margin: 0;
    margin-left: 0.5em !important;
    font-size: 18px;
    line-height: 20px;
    /* Slightly larger title */
    font-weight: 700;
    /* Bolder title */
    color: #000;
    /* Darker text */
}

/* --- Toggle Buttons --- */

/* Button INSIDE header (for non-sticky view) */
.wp-block-umbc-table-of-contents .toc-toggle-header {
    display: flex;
    /* Default display */
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    color: #666;
    flex-shrink: 0;
    margin-left: auto;
    /* Push to the right */
}

/* Button OUTSIDE header (main button, used for sticky toggle) */
.wp-block-umbc-table-of-contents>.toc-toggle {
    display: none;
    /* Hidden by default (shown when actually sticky) */
    position: absolute;
    /* Default position, overridden when sticky */
    z-index: 1001;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
}


/* SVG styles (apply to SVGs in BOTH buttons) */
.wp-block-umbc-table-of-contents .toc-toggle svg {
    width: 36px;
    /* Default size */
    height: 36px;
    fill: currentColor;
    display: block;
    /* Ensure SVGs are block */
}

/* Hover/focus for header button */
.wp-block-umbc-table-of-contents:not(.is-sticky) .toc-toggle-header:hover,
.wp-block-umbc-table-of-contents:not(.is-sticky) .toc-toggle-header:focus {
    background-color: transparent;
    color: #000;
    outline: none;
}


/* --- Icon Visibility --- */

/* Non-Sticky State (uses .toc-toggle-header) */
.wp-block-umbc-table-of-contents:not(.is-sticky):not(.is-expanded) .toc-toggle-header .toc-toggle-icon-expand {
    display: block !important;
}

.wp-block-umbc-table-of-contents:not(.is-sticky):not(.is-expanded) .toc-toggle-header .toc-toggle-icon-collapse {
    display: none !important;
}

.wp-block-umbc-table-of-contents:not(.is-sticky).is-expanded .toc-toggle-header .toc-toggle-icon-expand {
    display: none !important;
}

.wp-block-umbc-table-of-contents:not(.is-sticky).is-expanded .toc-toggle-header .toc-toggle-icon-collapse {
    display: block !important;
}

/* Sticky State (uses direct child > .toc-toggle and .is-actually-sticky) */
.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded)>.toc-toggle .toc-toggle-icon-expand {
    display: block !important;
}

.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded)>.toc-toggle .toc-toggle-icon-collapse {
    display: none !important;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle .toc-toggle-icon-expand {
    display: none !important;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle .toc-toggle-icon-collapse {
    display: block !important;
}


/* --- Back Link --- */
.wp-block-umbc-table-of-contents .toc-back-link {
    display: inline-flex;
    /* Use inline-flex for icon alignment */
    align-items: center;
    padding: 0.6rem 1.25rem;
    /* More space below back link */
    /* Indent back link to align with list items (Point 4) */
    font-size: 0.95rem;
    /* Match list item size */
    color: #007A87;
    /* Teal color */
    text-decoration: none;
    font-weight: 500;
}

.wp-block-umbc-table-of-contents .toc-back-link:hover {
    text-decoration: underline;
}

.wp-block-umbc-table-of-contents .toc-back-link svg {
    width: 16px;
    /* Adjust icon size */
    height: 16px;
    margin-right: 6px;
    /* Space between icon and text */
    fill: currentColor;
}


/* --- List Styles --- */
.wp-block-umbc-table-of-contents .toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.wp-block-umbc-table-of-contents .toc-list-item {
    margin: 0;
    padding: 0;
    /* border-bottom: 1px solid #eee; */
    /* Removed border */
}

/* Removed last-child border rule */
/* .wp-block-umbc-table-of-contents .toc-list-item:last-child { border-bottom: none; } */

/* Round bottom corners of the last item's link (Point 1) */
.wp-block-umbc-table-of-contents .toc-list-item:last-child a {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.wp-block-umbc-table-of-contents .toc-list-item a {
    display: block;
    /* Changed from flex */
    /* justify-content: space-between; */
    /* Removed */
    /* align-items: center; */
    /* Removed */
    padding: 0.5rem 1.25rem;
    /* Adjusted padding */
    text-decoration: none;
    color: #000;
    font-size: 0.95rem;
    background-color: #f1f1f1;
    /* Light grey background */
    /* transition: color 0.15s ease; */
    /* Removed transition */
}

/* Add rule for even items */
.wp-block-umbc-table-of-contents .toc-list-item:nth-child(even) a {
    background-color: #fff;
    /* White background for even rows */
}

.wp-block-umbc-table-of-contents .toc-list-item a:hover {
    /* background-color: #f1f1f1; */
    /* No hover background change */
    color: #333;
    /* No hover text color change */
}

/* --- Link Icons --- */
.wp-block-umbc-table-of-contents .toc-link-icon {
    display: none;
    /* Hide original SVG icons */
    /* fill: #888; */
    /* margin-left: 0.75rem; */
    /* flex-shrink: 0; */
    /* width: 14px; */
    /* height: 14px; */
    /* transition: fill 0.15s ease; */
}

/* Removed hover rule for original icons */
/* .wp-block-umbc-table-of-contents .toc-list-item a:hover .toc-link-icon { fill: #007A87; } */

/* Add new icon using pseudo-element */
.wp-block-umbc-table-of-contents .toc-list-item-internal a::after {
    content: '↓';
    display: inline-block;
    margin-left: 0.5em;
    font-weight: bold;
    color: #666;
    vertical-align: middle;
    /* Adjust alignment if needed */
}


/* --- Desktop Styles (Non-Sticky State) --- */
@media (min-width: 768px) {

    /* Hide the *outer* toggle button on desktop when NOT actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky)>.toc-toggle,
    .wp-block-umbc-table-of-contents .toc-toggle-header {
        display: none;
    }

    /* Hide header button when sticky functionality is enabled (original PHP class) */
    /* We still need this rule so the header toggle doesn't show when sticky is possible */
    .wp-block-umbc-table-of-contents.is-sticky .toc-toggle-header {
        display: none;
    }

    /* Ensure content is always visible on desktop when NOT actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky) .toc-content {
        display: block;
    }

    /* Adjust header padding when toggle is hidden (applies when sticky is enabled but not active, and on non-sticky blocks) */
    .wp-block-umbc-table-of-contents.is-sticky:not(.is-actually-sticky) .toc-header,
    .wp-block-umbc-table-of-contents:not(.is-sticky) .toc-header {
        padding-right: 1.25rem;
        /* Maintain right padding */
    }
}


/* --- Mobile Accordion Styles --- */
@media (max-width: 767px) {

    .wp-block-umbc-table-of-contents .toc-toggle-header {
        display: flex !important;
    }

    .wp-block-umbc-table-of-contents:not(.is-actually-sticky) {
        /* Reset position */
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        /* Remove shadow */
    }

    .wp-block-umbc-table-of-contents:not(.is-actually-sticky):not(.is-expanded) .toc-header {
        border-bottom-right-radius: 8px;
        border-bottom-left-radius: 8px;
        /* Rounded corners for header */
    }

    /* Hide the OUTER toggle button on mobile when not actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky)>.toc-toggle {
        display: none;
    }

    /* Hide content by default on mobile when not actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky) .toc-content {
        display: none;
    }

    /* Control icon visibility in mobile view - more specific selectors */
    /* Hide collapse icon by default */
    .wp-block-umbc-table-of-contents .toc-toggle-header .toc-toggle-icon-collapse {
        display: none;
    }

    /* Show expand icon by default */
    .wp-block-umbc-table-of-contents .toc-toggle-header .toc-toggle-icon-expand {
        display: block;
    }

    /* When expanded, hide expand icon and show collapse icon */
    .wp-block-umbc-table-of-contents.is-expanded .toc-toggle-header .toc-toggle-icon-expand {
        display: none;
    }

    .wp-block-umbc-table-of-contents.is-expanded .toc-toggle-header .toc-toggle-icon-collapse {
        display: block;
    }

    /* Show content when expanded on mobile when not actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky).is-expanded .toc-content {
        display: block;
    }

    /* Adjust header padding for mobile when not actually sticky */
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky) .toc-header {
        padding-right: 0.75rem;
        /* Adjust as needed */
    }
}


/* --- Mobile Accordion Styles --- */
@media (max-width: 400px) {
    .wp-block-umbc-table-of-contents:not(.is-actually-sticky) {
        /* Add padding for mobile view */
        margin-left: 1rem;
        margin-right: 1rem;
    }
}

/* --- Sticky Styles (Applied when .is-actually-sticky is present) --- */
/* Default closed state (button view) */
.wp-block-umbc-table-of-contents.is-actually-sticky {
    position: fixed;
    top: 33vh;
    /* Position 1/3 down the viewport */
    left: 0;
    /* Align to the left edge */
    /* Adjust position as needed */
    z-index: 1000;
    /* High z-index */
    width: 50px;
    /* Button width */
    height: 50px;
    /* Button height */
    max-width: none;
    background-color: #007A87;
    /* Teal background like image */
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    border-radius: 0 8px 8px 0;
    /* Rounded corners only on the right */
    /* overflow: hidden; <-- Let button overflow */
    margin-block-start: 0;
    /* Remove transition to prevent flashing */
    transition: none;
}

/* Hide header and content in closed sticky state */
.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded) .toc-header,
.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded) .toc-content {
    display: none;
}

/* Style the OUTER toggle button for the closed sticky state */
.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded)>.toc-toggle {
    display: flex;
    /* Make it visible */
    position: fixed;
    /* Position it relative to viewport */
    top: 33vh;
    /* Match main block position */
    left: 0;
    /* Match main block */
    width: 50px;
    /* Match main block */
    height: 50px;
    /* Match main block */
    align-items: center;
    justify-content: center;
    padding: 0;
    background-color: #007A87;
    /* Teal background */
    border: none;
    border-radius: 0 8px 8px 0;
    /* Match main block */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    /* Match main block */
    cursor: pointer;
    color: #fff;
    /* White icon */
    z-index: 1001;
    /* Above main block */
    transition: opacity 0.3s ease;
    /* Add transition for appearance */
}

/* Style the SVG within the OUTER sticky toggle button */
.wp-block-umbc-table-of-contents.is-actually-sticky>.toc-toggle svg {
    width: 30px;
    /* Smaller icon for sticky button */
    height: 30px;
    fill: currentColor;
    display: block;
}

/* Hover for OUTER sticky button */
.wp-block-umbc-table-of-contents.is-actually-sticky:not(.is-expanded)>.toc-toggle:hover {
    color: #eee;
    /* Change color on hover, SVG will inherit */
}


/* Expanded sticky state (Main Block) */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded {
    width: 280px;
    /* Expanded width */
    height: auto;
    /* Auto height */
    max-height: calc(100vh - 120px);
    /* Limit height */
    background-color: transparent;
    /* Transparent background */
    border: none;
    box-shadow: none;
    overflow: visible;
    /* Allow content to be visible */
    position: fixed;
    /* Ensure it stays fixed */
    top: 33vh;
    /* Position 1/3 down */
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: none;
    /* Remove transition to prevent flashing */
}

/* Show header and content in expanded sticky state */
/* Header is hidden later, but content needs display: block */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-content {
    display: block;
}

/* Position the OUTER toggle button at the top when sticky AND expanded */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle {
    display: flex;
    position: relative;
    /* Position relative to the expanded container */
    width: 50px;
    height: 50px;
    padding: 0;
    background-color: #007A87;
    border: none;
    border-radius: 0 8px 0 0;
    cursor: pointer;
    color: #fff;
    z-index: 1001;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    margin-bottom: 0;
    transition: none;
    /* Remove transition to prevent flashing */
}

/* Style the content container */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-content {
    background-color: #fff;
    border: 1px solid #F1F1F1;
    border-radius: 0 8px 8px 0;
    box-shadow: 9px 9px 12px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
    max-height: calc(100vh - 170px);
    /* Account for toggle height */
    margin-top: 0;
    position: relative;
    z-index: 1000;
    transition: none;
    /* Remove transition to prevent flashing */
}

/* Ensure back link appears at the top of content */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-back-link {
    border-bottom: 1px solid #F1F1F1;
    background-color: #fff;
}

/* Ensure proper spacing between toggle and content */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle {
    margin-bottom: 0;
}

/* Style SVG specifically for OUTER expanded sticky button */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle svg {
    width: 36px;
    /* Restore original size */
    height: 36px;
    fill: currentColor;
    display: block;
}

/* Hover for OUTER expanded sticky button */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded>.toc-toggle:hover {
    color: #fff;
    /* Keep white icon on hover */
    opacity: 0.9;
    /* Subtle hover effect */
}


/* Hide header in expanded sticky state since we're using the toggle as header */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-header {
    display: none;
}

/* Ensure list items look correct */
.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-list-item a {
    background-color: #f1f1f1;
    color: #000;
    margin: 0;
    font-size: 18px;
    line-height: 20px;
}

/* Ensure list items look correct */
.wp-block-umbc-table-of-contents.is-sticky.is-expanded .toc-list-item a {
    padding: 0.5rem 1.25rem;
    display: block;
    text-decoration: none;
    font-size: 0.95rem;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-list-item:nth-child(even) a {
    background-color: #fff;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-list-item:last-child a {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-list-item a:hover {
    color: #333;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-list-item-internal a::after {
    content: "↓";
    display: inline-block;
    margin-left: 0.5em;
    font-weight: bold;
    color: #666;
    vertical-align: middle;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-back-link {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    color: #007A87;
    text-decoration: none;
    font-weight: 500;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-back-link:hover {
    text-decoration: underline;
}

.wp-block-umbc-table-of-contents.is-actually-sticky.is-expanded .toc-back-link svg {
    width: 16px;
    height: 16px;
    margin-right: 6px;
    fill: currentColor;
}


/* --- Screen Reader Text --- */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute !important;
    width: 1px;
    word-wrap: normal !important;
}