/* =============================================================
   Chapter Block — Frontend Styles
   ============================================================= */

/* Layout wrapper */
.chapter-block {
    margin-bottom: 40px;
    overflow: visible; /* Ensure sticky positioning works */
}

.chapter-block__layout {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    overflow: visible; /* Ensure sticky positioning works */
}

/* =============================================================
   Chapter Navigation (left column)
   ============================================================= */

/* Apply sticky to the grid column wrapper */
.chapter-block__layout > .nhsuk-grid-column-one-quarter {
    position: -webkit-sticky; /* Safari support */
    position: sticky;
    top: 24px;
    align-self: flex-start;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

.chapter-block__nav {
    z-index: 100;
}

/* Active (current) chapter enhancement */
.chapter-block .nhsuk-contents-list__current {
    color: #005eb8;
}

/* Focus state — WCAG 2.2 2.4.11 */
.chapter-block .nhsuk-contents-list__link:focus {
    outline: 4px solid #ffeb3b;
    outline-offset: 0;
    background-color: #ffeb3b;
    color: #212b32;
    text-decoration: none;
}

/* =============================================================
   Sub-Chapter Navigation (nested list)
   ============================================================= */

.chapter-block .nhsuk-contents-list__list--nested {
    margin-top: 8px;
    margin-bottom: 0;
    margin-left: 0;
    padding-left: 8px;
    list-style: none;
}

.chapter-block .nhsuk-contents-list__item--sub {
    margin-bottom: 4px;
}

.chapter-block .nhsuk-contents-list__link--sub {
    display: inline-block;
    padding: 4px 0;
}

/* Additional indentation for H3 sub-chapters */
.chapter-block .nhsuk-contents-list__link--sub[data-level="h3"] {
    padding-left: 16px;
}

.chapter-block .nhsuk-contents-list__link--sub.nhsuk-contents-list__current {
    font-weight: 600;
}

/* Hide inactive sub-chapters when collapse feature is enabled */
.chapter-block .nhsuk-contents-list__list--nested[hidden] {
    display: none;
}

/* =============================================================
   Chapter Content Panels (right column)
   ============================================================= */

.chapter-block__content {
    min-height: 200px;
}

.chapter-block__panel {
    outline: none; /* Focus outline is on nav links, not panels */
}

/* Hide panels — set by JS and PHP (hidden attribute) */
.chapter-block__panel[hidden] {
    display: none;
}

.chapter-block__panel-title {
    margin-top: 0;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #d8dde0;
    font-size: 28px;
    font-weight: bold;
    color: #212b32;
}

.chapter-block__chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid #d8dde0;
}

.chapter-block__chapter-nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-weight: 600;
    color: #005eb8;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chapter-block__chapter-nav-link:hover {
    color: #003087;
}

.chapter-block__chapter-nav-link--prev {
    margin-right: auto;
}

.chapter-block__chapter-nav-link--next {
    margin-left: auto;
    text-align: right;
}

/* =============================================================
   Responsive — stack on mobile
   ============================================================= */

@media (max-width: 640px) {
    .chapter-block__nav {
        position: static;
        width: 100% !important;
        margin-bottom: 24px;
    }

    .chapter-block__content {
        width: 100% !important;
    }
}
