/**
 * CCDSS / SCSMC Technical Notes — sticky "On this page" + glossary layout.
 * Scoped to technical-notes.html / notes-techniques.html only.
 */

/* --- Sticky left "On this page" (CARSS / MHBC flex pattern) --- */
.toc-layout-container {
    display: flex;
    align-items: flex-start;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 15px;
}

.sticky-toc {
    position: -webkit-sticky;
    position: sticky;
    top: 20px;
    z-index: 10;
    width: 301px;
    flex-shrink: 0;
    margin-right: 25px;
}

.main-content-col {
    flex-grow: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.main-content-col .table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Override Bootstrap phone nowrap so Technical notes tables reflow (P1) */
.main-content-col .table-responsive > .table > thead > tr > th,
.main-content-col .table-responsive > .table > tbody > tr > th,
.main-content-col .table-responsive > .table > tbody > tr > td {
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
}

/*
 * Phone / narrow: stack each body row as a card (publications pattern).
 * Needs data-label on cells (builder + live HTML) for column names.
 */
@media (max-width: 575px) {
    .main-content-col .table-responsive {
        border: 0;
        overflow-x: visible;
    }

    .main-content-col .table-responsive > .table {
        display: block;
        width: 100%;
        margin-bottom: 0;
        border: 0;
    }

    .main-content-col .table-responsive > .table > thead {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        border: 0;
    }

    .main-content-col .table-responsive > .table > tbody,
    .main-content-col .table-responsive > .table > tbody > tr,
    .main-content-col .table-responsive > .table > tbody > tr > th,
    .main-content-col .table-responsive > .table > tbody > tr > td {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .main-content-col .table-responsive > .table > tbody > tr {
        margin: 0 0 1rem;
        padding: 0.65rem 0.75rem;
        border: 1px solid #ddd;
        background: #fff;
    }

    .main-content-col .table-responsive > .table > tbody > tr:nth-child(even) {
        background: #f9f9f9;
    }

    .main-content-col .table-responsive > .table > tbody > tr > th,
    .main-content-col .table-responsive > .table > tbody > tr > td {
        padding: 0.35rem 0;
        border: 0;
        text-align: left;
    }

    .main-content-col .table-responsive > .table > tbody > tr > th[scope="row"] {
        font-weight: 700;
        color: #26374a;
        padding-bottom: 0.5rem;
        margin-bottom: 0.35rem;
        border-bottom: 1px solid #e5e8ec;
    }

    .main-content-col .table-responsive > .table > tbody > tr > td[data-label]::before,
    .main-content-col .table-responsive > .table > tbody > tr > th[data-label]:not([scope="row"])::before {
        content: attr(data-label);
        display: block;
        font-size: 0.85em;
        font-weight: 700;
        color: #5c6b7a;
        margin-bottom: 0.15rem;
    }

    /* Row header already visible — skip repeating its column label. */
    .main-content-col .table-responsive > .table > tbody > tr > th[scope="row"][data-label]::before {
        content: none;
    }
}

.sticky-toc h2,
.sticky-toc .h4 {
    margin-top: 0;
    border-bottom: 2px solid #F2C037;
    padding-bottom: 5px;
    font-size: 1.2em;
}

.sticky-toc ul {
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
}

.sticky-toc li {
    margin-bottom: 8px;
    line-height: 1.25;
}

.sticky-toc a {
    text-decoration: none;
    color: #333;
    font-size: 0.9em;
    display: block;
    padding: 4px 8px 4px 10px;
    margin-left: -10px;
    border-left: 3px solid transparent;
    border-radius: 0 2px 2px 0;
}

.sticky-toc a:hover {
    text-decoration: underline;
    color: #0535d2;
}

.sticky-toc a.sticky-toc-current {
    font-weight: bold;
    background-color: #e8e8e8;
    border-left-color: #F2C037;
}

@media (max-width: 1150px) {
    .toc-layout-container {
        flex-direction: column;
    }

    .sticky-toc {
        position: static;
        width: 100%;
        margin-right: 0;
        margin-bottom: 2rem;
        border: 1px solid #ddd;
        padding: 15px;
        border-radius: 4px;
    }

    .sticky-toc ul {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 5px 15px;
    }
}

@media (max-width: 600px) {
    .sticky-toc ul {
        grid-template-columns: 1fr;
    }
}

/*
 * Glossary: side-by-side terms/definitions.
 * WET .dl-horizontal floats leave dt/dd tops misaligned (our old padding-top: 0
 * on dt only made it worse). Use a simple grid so baselines match.
 */
@media (min-width: 768px) {
    .ccdss-tn-glossary.dl-horizontal {
        display: grid;
        grid-template-columns: minmax(10em, 12em) minmax(0, 1fr);
        column-gap: 1.25em;
        align-items: start;
    }

    .ccdss-tn-glossary.dl-horizontal dt,
    .ccdss-tn-glossary.dl-horizontal dd {
        float: none;
        width: auto;
        max-width: none;
        margin: 0;
        margin-left: 0;
        border-top: 1px solid #ccc;
        padding: 10px 0;
        overflow: visible;
        text-overflow: unset;
        white-space: normal;
        text-align: left;
    }

    /* Kill WET clearfix — it adds an extra anonymous box above dd text */
    .ccdss-tn-glossary.dl-horizontal dd:before,
    .ccdss-tn-glossary.dl-horizontal dd:after {
        content: none;
        display: none;
    }
}

.ccdss-tn-glossary.dl-horizontal dd > p:first-child {
    margin-top: 0;
}

.ccdss-tn-glossary.dl-horizontal dd > p:last-child {
    margin-bottom: 0;
}

@media (max-width: 767px) {
    .ccdss-tn-glossary.dl-horizontal dt,
    .ccdss-tn-glossary.dl-horizontal dd {
        float: none;
        width: auto;
        margin-left: 0;
        display: block;
    }
}

/*
 * Phone only: GCWeb/WET details chrome (same as Data Tool notes/table).
 * sm+: strip the disclosure shell so tables read as plain open content.
 */
.ccdss-tn-table-disclosure {
    margin-bottom: 0.75em;
}

@media (min-width: 768px) {
    .ccdss-tn-table-disclosure,
    .ccdss-tn-table-disclosure[open] {
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        margin: 0 0 1rem;
        padding: 0;
    }

    .ccdss-tn-table-disclosure > summary {
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        /* GCWeb sets summary to list-item with !important. */
        display: none !important;
    }

    .ccdss-tn-table-disclosure::details-content {
        content-visibility: visible;
        block-size: auto;
    }

    .ccdss-tn-table-disclosure > .table-responsive {
        display: block !important;
    }
}
