/*
 * MAPEL question card, wide matrix and radio controls, design-and-build-state sections 4.4 and 4.5.
 * The artboards are the reference for anything section 4 does not state.
 */

/*
 * Card. 12px radius, a 1px border, the card shadow and no padding of its own.
 * The question block and the answer area carry their own insets instead.
 */
body.mapel .question-container {
    --bs-gutter-x: 0;
    margin-left: 0;
    margin-right: 0;
    padding: 0;
    background-color: var(--mapel-card);
    border: 1px solid var(--mapel-border);
    border-radius: 12px;
    box-shadow: var(--mapel-shadow);
    overflow: hidden;
}

body.mapel .question-container > .question-title-container {
    padding: 28px 32px 0;
}

body.mapel .question-container > .question-help-container,
body.mapel .question-container > .question-valid-container {
    padding: 0 32px;
}

body.mapel .question-container > .question-valid-container {
    padding-bottom: 24px;
}

body.mapel .question-container > .answer-container {
    padding: 26px 32px 28px;
    border-top: 1px solid var(--mapel-border);
}

body.mapel .question-container.array-flexible-row > .answer-container {
    padding: 0;
}

@media only screen and (max-width: 1023px) {
    body.mapel .question-container > .question-title-container {
        padding: 22px 20px 0;
    }

    body.mapel .question-container > .question-help-container,
    body.mapel .question-container > .question-valid-container {
        padding: 0 20px;
    }

    body.mapel .question-container > .question-valid-container {
        padding-bottom: 18px;
    }

    body.mapel .question-container > .answer-container,
    body.mapel .question-container.array-flexible-row > .answer-container {
        padding: 20px 18px 22px;
    }
}

/*
 * Radio controls, section 4.5. Drawn in CSS on the label LimeSurvey renders after each
 * radio, with the real input kept invisible on top for the click. The outer circle is
 * 21.6px with a 2px border in the unselected control color. The selected mark is a
 * 10.4px dot in the primary color. Both carry an explicit display property.
 */
body.mapel .radio-item input[type="radio"] + label::before {
    content: "";
    display: block;
    position: absolute;
    box-sizing: border-box;
    width: 21.6px;
    height: 21.6px;
    margin: 0;
    border: 2px solid var(--mapel-control);
    border-radius: 50%;
    background-color: transparent;
    outline: 0;
    transition: border-color 0.15s ease-in-out;
}

body.mapel .radio-item input[type="radio"] + label::after {
    content: "";
    display: block;
    position: absolute;
    width: 10.4px;
    height: 10.4px;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    background-color: var(--mapel-primary);
    transform: scale(0);
    transition: transform 0.1s ease-in-out;
}

body.mapel .radio-item input[type="radio"]:checked + label::after {
    transform: scale(1);
}

body.mapel .radio-item input[type="radio"]:focus + label::before {
    outline: 0;
}

body.mapel .radio-item input[type="radio"]:focus-visible + label::before {
    outline: 2px solid var(--mapel-primary);
    outline-offset: 2px;
}

/*
 * Checkboxes, drawn like the radio. The box is 21.6px with a 2px border in the unselected
 * control color and a 4px radius. When ticked the box keeps that color and a check mark in
 * the primary color is added, as the radio adds only its dot. The 4px radius is a
 * judgement, since neither section 4.5 nor the artboards define a checkbox.
 */
body.mapel .checkbox-item input[type="checkbox"] + label::before {
    content: "";
    display: block;
    position: absolute;
    box-sizing: border-box;
    width: 21.6px;
    height: 21.6px;
    margin: 0;
    border: 2px solid var(--mapel-control);
    border-radius: 4px;
    background-color: transparent;
    outline: 0;
}

body.mapel .checkbox-item input[type="checkbox"] + label::after {
    content: "";
    display: block;
    position: absolute;
    box-sizing: border-box;
    width: 6.5px;
    height: 11.5px;
    margin: 0;
    padding: 0;
    border: solid var(--mapel-primary);
    border-width: 0 2.5px 2.5px 0;
    border-radius: 0;
    background-color: transparent;
    font-size: 0;
    transform: rotate(45deg) scale(0);
    transition: transform 0.1s ease-in-out;
}

body.mapel .checkbox-item input[type="checkbox"]:checked + label::after {
    content: "";
    transform: rotate(45deg) scale(1);
}

body.mapel .checkbox-item input[type="checkbox"]:focus + label::before {
    outline: 0;
}

body.mapel .checkbox-item input[type="checkbox"]:focus-visible + label::before {
    outline: 2px solid var(--mapel-primary);
    outline-offset: 2px;
}

/*
 * Wide matrix, section 4.5. From 1024px. The table fills the card. The row label column
 * takes 24 percent on the five factual matrices and 25 percent on every other array, and
 * the response columns share the rest equally, which a fixed table layout does for
 * columns left at automatic width. LimeSurvey writes its own widths inline on the
 * column elements, so these rules carry !important to replace them.
 */
/* The height of the header and the progress bar that stay at the top of a wide window */
body.mapel {
    --mapel-sticky-top: calc(65px + 6px);
}

@supports (overflow: clip) {
    @media only screen and (min-width: 1024px) {
        body.mapel .question-container.array-flexible-row {
            overflow: clip;
        }
    }
}

@media only screen and (min-width: 1024px) {

    body.mapel .array-flexible-row table.ls-answers {
        width: 100%;
        margin: 0;
        padding: 0;
        table-layout: fixed;
        border-collapse: separate;
        border-spacing: 0;
        border: 0;
        -webkit-hyphens: manual;
        hyphens: manual;
    }

    body.mapel .array-flexible-row table.ls-answers > colgroup > col.col-answers {
        width: 25% !important;
    }

    body.mapel .array-flexible-row table.ls-answers[data-mapel-matrix] > colgroup > col.col-answers {
        width: 24% !important;
    }

    body.mapel .array-flexible-row table.ls-answers > colgroup > col:not(.col-answers) {
        width: auto !important;
    }

    /* Every cell starts from the same reserved edges, so a hover outline shifts nothing */
    body.mapel .array-flexible-row table.ls-answers > thead > tr > *,
    body.mapel .array-flexible-row table.ls-answers > tbody > tr > * {
        --bs-table-accent-bg: transparent;
        --bs-table-bg-type: transparent;
        --bs-table-bg-state: transparent;
        box-shadow: none;
        background-color: transparent;
        border: 0;
        border-top: 1px solid transparent;
        border-bottom: 1px solid var(--mapel-divider);
        padding: 13px 6px;
        vertical-align: middle;
        color: var(--mapel-text);
    }

    /*
     * Column header strip. It stays in view just below the header and the progress bar while
     * the rows of its matrix scroll past, and leaves with the matrix. The card clips with
     * overflow clip rather than hidden, because hidden would make the card the scrolling
     * box and the strip would never stick.
     */
    body.mapel .array-flexible-row table.ls-answers > thead > tr > * {
        position: sticky;
        top: var(--mapel-sticky-top);
        z-index: 2;
        background-color: var(--mapel-band);
        padding-top: 14px;
        padding-bottom: 14px;
        border-top: 0;
        border-bottom: 1px solid var(--mapel-border);
        font-size: 12px;
        font-weight: 600;
        line-height: 1.3;
        color: var(--mapel-heading);
        text-align: center;
        vertical-align: bottom;
    }

    /* Row label column */
    body.mapel .array-flexible-row table.ls-answers > thead > tr > :first-child,
    body.mapel .array-flexible-row table.ls-answers > tbody > tr > :first-child {
        padding-left: 32px;
        border-left: 1px solid transparent;
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr > th.answertext {
        padding-right: 20px;
        text-align: left;
        font-size: 14px;
        font-weight: 400;
        line-height: 1.45;
        color: var(--mapel-text);
    }

    /* Non-answer column, the last one. A rule on its left edge that takes no width */
    body.mapel .array-flexible-row table.ls-answers > thead > tr > :last-child,
    body.mapel .array-flexible-row table.ls-answers > tbody > tr > :last-child {
        padding-right: 32px;
        border-right: 1px solid transparent;
        background-image: linear-gradient(var(--mapel-border), var(--mapel-border));
        background-repeat: no-repeat;
        background-size: 1px 100%;
        background-position: left top;
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr > td.answer-item {
        text-align: center;
    }

    /* Alternate visible rows carry the band, edge to edge */
    body.mapel .array-flexible-row table.ls-answers > tbody > tr:nth-child(even of .answers-list:not(.ls-hidden):not(.ls-irrelevant)) > * {
        background-color: var(--mapel-band);
    }

    /* The last row closes on the card edge */
    body.mapel .array-flexible-row table.ls-answers > tbody > tr:last-child > * {
        border-bottom-color: transparent;
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr:last-child > :first-child {
        border-bottom-left-radius: 11px;
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr:last-child > :last-child {
        border-bottom-right-radius: 11px;
    }

    /* Hover outlines the row on all four sides and changes nothing else */
    body.mapel .array-flexible-row table.ls-answers > tbody > tr:hover > * {
        border-top-color: var(--mapel-primary);
        border-bottom-color: var(--mapel-primary);
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr:hover > :first-child {
        border-left-color: var(--mapel-primary);
    }

    body.mapel .array-flexible-row table.ls-answers > tbody > tr:hover > :last-child {
        border-right-color: var(--mapel-primary);
    }

    /* Radios in a matrix cell, centered */
    body.mapel .array-flexible-row table.ls-answers td.radio-item {
        position: relative;
        cursor: pointer;
    }

    body.mapel .array-flexible-row table.ls-answers td.radio-item input[type="radio"] {
        left: 50%;
        top: 50%;
        width: 21.6px;
        height: 21.6px;
        margin: 0;
        transform: translate(-50%, -50%);
    }

    body.mapel .array-flexible-row table.ls-answers td.radio-item label.ls-label-xs-visibility {
        display: block;
        position: relative;
        width: 21.6px;
        height: 21.6px;
        margin: 0 auto;
        left: auto;
        overflow: hidden;
        white-space: nowrap;
        text-indent: 200%;
    }

    body.mapel .array-flexible-row table.ls-answers td.radio-item input[type="radio"] + label::before {
        left: 0;
        top: 0;
        margin: 0;
    }

    body.mapel .array-flexible-row table.ls-answers td.radio-item input[type="radio"] + label::after {
        left: 5.6px;
        top: 5.6px;
        margin: 0;
    }
}

/*
 * Radios in the narrow layout. The ring sits 12px inside the option's edge with a 12px
 * gap before the text, as on the narrow artboard, and never shrinks beside a long label.
 * LimeSurvey's own narrow rules give the mark a -20px margin, which is cleared here.
 */
@media only screen and (max-width: 1023px) {
    body.mapel table.ls-answers td.radio-item label.ls-label-xs-visibility {
        position: relative;
        margin-left: 0;
        padding-left: 0;
    }

    body.mapel table.ls-answers td.radio-item input[type="radio"] + label::before {
        left: calc(-12px - 21.6px);
        top: 0;
        margin: 0;
        flex: none;
    }

    body.mapel table.ls-answers td.radio-item input[type="radio"] + label::after {
        left: calc(-12px - 21.6px + 5.6px);
        top: 5.6px;
        margin: 0;
        flex: none;
    }
}
