/* ---------------------------------------------------------------------------- */
/* Rules for partial templates */

#part-ui-scale {
    .scale-buttons {
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 200;
        display: flex !important;
        flex-direction: column;
        gap: 1rch;

        .btn {
            color: var(--gray-dark-3);
            border: none;
            background-color: var(--bg-color);
            font-size: 2em;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0.5ch;
            width: 2ch;
            height: 2ch;
            line-height: 1;
            border-radius: 50%;

            .msr-icon { font-size: 1em; }
        }

        .value {
            text-align: center;
            font-weight: 600;
            color: var(--gray-dark-4);
        }
    }
}

#part-clock {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 1ch;
    grid-template-areas:
        "clock meridian"
        "date  date";
    font-weight: 500;
    font-variant-numeric: tabular-nums;

    .clock {
        grid-area: clock;
        font-size: 2.5em;
        font-weight: 600;
        line-height: 1;
    }

    .meridian {
        grid-area: meridian;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .meridian>p {
        margin: 0;
        line-height: 1;
    }

    .meridian>p.inactive {
        color: var(--gray-dark-3);
    }

    .date {
        grid-area: date;
        line-height: 1.1;
    }
}

#part-error-message {
    background-color: var(--red-dark);
    font-weight: 650;
    font-size: 1.65rem;
    padding: 0.5ch 1.5ch;
    border-radius: var(--radius-small);

    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5ch;

    .msr-icon {
        font-size: 1.3em;
    }

    .msg {
        margin: 0;
    }
}

.part-no-stats {
    grid-column: 1 / -1;
    grid-row: 1 / -1;

    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 1.5ch;

    font-style: italic;
    color: var(--gray-dark-4);
    font-weight: 500;
    font-size: 1.5em;

    .msr-icon {
        font-size: 2em;
    }
}

.part-numpad-anchor {
    width: 50%;
}

#part-numpad {
    .header img {
        width: 5ch;
        aspect-ratio: 1 / 1;
        border: var(--border-w) solid var(--fg-color);
        border-radius: 100%;
        background-color: white;
        margin: 0 1.5ch 0 1ch;
    }

    .header .btn.close {
        color: var(--red);
        border: 0;
    }

    .numpad-value {
        border: 0;
        outline: 0;
        background-color: transparent;
        border-bottom: var(--line-w) solid var(--fg-color);
        color: var(--fg-color);
        font-size: 2.5em;
        text-align: center;

        line-height: 1em;
        caret-color: var(--gray-dark-1);
    }

    .numpad-value[type="password"] {
        letter-spacing: 0.3em;
        font-size: 3em;
    }

    .numpad-kbd {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 0.7ch;
        padding: 1.5ch 0 2ch;
    }

    .numpad-kbd .btn {
        font-size: 2.5em;
        font-weight: 600;
        aspect-ratio: 1 / 1;
        color: var(--fg-color);
        background-color: var(--gray-dark-2);
        padding: 0.5rch;
        display: flex;
        justify-content: center;
        align-items: center;
        line-height: 1;
        border: 0;
    }

    .numpad-kbd .btn.key-clr,
    .numpad-kbd .btn.key-del {
        color: var(--gray-dark-4);
        font-weight: 600;
        background-color: transparent;
    }

    .btn.enter {
        background-color: var(--green);
        color: var(--bg-color);
        font-weight: 700;
        font-size: 1.5em;
        margin-bottom: 1.8ch;
        padding: 0.2ch 1.5ch;
        line-height: 1;
        display: flex;
        align-items: center;
        gap: 1ch;
    }

    .btn.enter i {
        font-size: 1.5em;
    }
}

#part-confirm {
    max-width: 60vmin;

    .header > .icon {
        font-size: 3.5em;
        padding-left: 0.5rch;
    }

    .header button.close {
        --back-color: transparent;

        color: var(--red);
        border: none;
        margin-left: 1ch;
    }

    .body .message {
        margin: 1.5ch 1.2ch;
        line-height: 1.2;
        width: stretch;

        .accordion {
            --bs-accordion-btn-color: var(--gray-dark-3);
            --bs-accordion-active-color: var(--gray-light-1);
            --bs-accordion-color: var(--gray-light-1);
            --bs-accordion-bg: transparent;
            --bs-accordion-active-bg: transparent;
            --bs-accordion-border-color: none;
            --bs-accordion-btn-focus-box-shadow: none;
            --bs-accordion-btn-padding-x: 0;
            --bs-accordion-btn-padding-y: 0;
            --bs-accordion-body-padding-y: 0;
            --bs-accordion-body-padding-x: 0;

            margin-top: 1ch;

            .details {
                font-size: initial;
                padding: 1ch;
                margin-top: 1ch;
                background-color: var(--gray-dark-2);
                border-radius: var(--radius-small);
            }
        }
    }

    .body .buttons {
        display: flex;
        flex-direction: row;
        gap: 2ch;
        width: 100%;
        justify-content: flex-end;
        padding: 1ch 2ch 2ch;

        .btn {
            font-size: 1.5em;
            font-weight: bold;
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 1ch;
            padding: 0.2ch 0.7ch;
            border-radius: var(--radius-small);
        }

        .btn > i {
            font-size: 1.2em;
        }

        .cancel {
            color: var(--fg-color);
            border: var(--border-w) solid var(--fg-color);
        }

        .accept {
            border: none;
            background-color: var(--red-dark);
        }
    }
}

#part-user-header {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    .buttons {
        flex: 1;
        justify-content: flex-end;
        padding: 0;
        color: var(--gray-light-1);
        font-size: 1.7em;
        margin-right: 0.4ch;
        gap: 0.3ch;

        & div {
            display: flex;
            line-height: 1;
            padding: 0;
            margin: 0;
        }

        & div > .msr-icon {
            font-variation-settings: 'wght' 600, 'opsz' 48;
        }

        a {
            display: flex;
            align-items: center;
            gap: 0.4ch;
        }

        .header-home-btn {
            font-variation-settings: 'FILL' 1;
        }

        .header-back-btn {
            font-size: 1.4em;
            letter-spacing: -0.1ch;
            font-variation-settings: 'opsz' 12, 'wght' 700;
        }

        /* icons in dropdown menus */
        a > .msr-icon {
            font-size: 1.2em;
            font-variation-settings: 'wght' 700;
        }
    }

    .user-info {
        border: var(--line-w) solid var(--gray-light-1);
        border-radius: var(--radius-normal);
        padding: 0.5ch 1ch;
        max-width: 60vmin;
        display: grid;
        grid-template-areas:
            "name icon"
            "greet icon";
        column-gap: 0.5ch;
        row-gap: 0.2ch;
        align-items: center;

        h1 {
            font-size: 1.2em;
            grid-area: name;
            margin: 0;
            align-self: flex-end;
            text-align: right;
        }

        h2 {
            grid-area: greet;
            color: var(--gray-light-1);
            font-size: 0.6em;
            align-self: flex-start;
        }

        img {
            grid-area: icon;
            width: 4ch;
            aspect-ratio: 1 / 1;
            border-radius: 50%;
            border: var(--line-w) solid var(--gray-light-1);
            background-color: var(--gray-light-1);
        }
    }
}

#part-qr-link {
    height: 100%;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "info    qr"
        "buttons buttons";

    font-size: 1.8em;
    line-height: 1;

    h1 {
        font-weight: 700;
        font-size: 1.7em;
        margin-bottom: 1.2ch;
    }

    .info {
        grid-area: info;

        p {
            margin-bottom: 1.5ch;
        }
    }

    .qr-code {
        grid-area: qr;
        margin-left: 2ch;

        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1ch;

        .expire-msg,
        .expired-msg {
            font-size: 0.5em;
            font-weight: 600;
            color: var(--gray-light-1);
            opacity: 75%;

            i { font-style: normal; }
        }
    }

    .buttons {
        grid-area: buttons;
        width: 100%;
        display: flex;
        justify-content: center;
        padding: 2ch 0 0 0;
    }

    #auth-qrcode {
        border: 1ch solid white;
        border-radius: var(--radius-big);
        background-color: white;;
        position: relative;
        aspect-ratio: 1 / 1;
        width: 13ch;

        /* to show a loading message */
        color: var(--gray-dark-1);
        font-weight: 500;
        display: flex;
        align-items: center;
        justify-content: center;

        img {
            width: 100%;
        }

        &.expired img {
            filter: blur(1.1rch);
            opacity: 70%;
        }

        &.expired::after,
        &.invalid::after {
            content: "!";
            position: absolute;
            top: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 5em;
            font-weight: 800;
            color: var(--red);
            width: 100%;
            height: 100%;
        }

        &.invalid::after {
            content: "⚠";
            backdrop-filter: blur(0.05ch);
        }
    }
}

/* This is a class because there may be multiple instances */
.part-window-anchor {
    position: absolute;
    z-index: 100;
    align-self: center;
    top: 20vmax;
}

/* This is a class because there may be multiple instances */
.part-heatmap-anchor {
    --num-rows: 5; /* keep this an int, not a function */
    --size: 2rch;
    --label-w: 42rch;
    --cell-size: round(nearest, 3.9rch, 1px);
    --cell-gap: round(nearest, 0.5rch, 1px);
    --margin: round(nearest, 1.3rch, 1px);

    font-size: var(--size);
    line-height: 1;
    display: grid;
    justify-self: center;
    grid-template-columns:
        var(--label-w)
        calc(var(--cell-size) + 3.5rch)
        1fr;
    grid-template-areas:
        ".     btn-up   col-ids"
        "items items    items"
        ".     btn-down legend";

    .col-ids {
        grid-area: col-ids;
        width: 100%;
        display: flex;
        align-items: center;
        font-size: 1.6em;
        font-weight: 700;
        column-gap: var(--cell-gap);

        span {
            aspect-ratio: 1 / 1;
            height: var(--cell-size);
            text-align: center;
        }

        span:nth-child(15n + 5),
        span:nth-child(15n + 10) {
            margin-right: var(--margin);
        }

        span:last-child {
            position: relative;

            &::after {
                content: "";
                position: absolute;
                top: -0.5rch;
                left: -0.2rch;
                right: -0.2rch;
                height: calc(((var(--cell-size) + var(--cell-gap)) * (var(--num-rows) + 1)) + (var(--cell-gap) * 3));

                border: 0.2rch solid var(--gray-light-1);
                border-radius: 0.5rch;
                z-index: 5;
            }
        }
    }

    .items {
        grid-area: items;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        overflow: hidden auto;
        max-height: calc((var(--cell-gap) + var(--cell-size)) * var(--num-rows));

        .items-row {
            display: flex;
            flex-direction: row;
            align-items: center;
            width: 100%;
            flex-shrink: 0;
            overflow: hidden;
        }

        .label {
            width: var(--label-w);
            text-align: right;
            font-size: 1.3em;
            font-weight: 300;
        }

        .row-cells {
            width: fit-content;
            display: flex;
            flex-direction: row;
            column-gap: var(--cell-gap);
            overflow: hidden;
        }

        .row-id,
        .cell {
            aspect-ratio: 1 / 1;
            height: var(--cell-size);
            background-color: color-mix(in srgb, var(--color), transparent var(--opacity));
            position: relative;

            text-shadow:
                -1px -1px 1px #000,
                 1px -1px 1px #000,
                -1px  1px 1px #000,
                 1px  1px 1px #000;

            border-radius: 10%;
            font-weight: 900;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: var(--cell-gap);
        }

        .cell.empty {
            background-color: var(--gray-dark-2);
            color: var(--gray-dark-4);
        }

        .row-id {
            text-shadow: none;
            background-color: color-mix(in srgb, var(--color), transparent 50%);
            margin: 0 1.75rch var(--cell-gap);
        }

        .cell:nth-child(15n + 5),
        .cell:nth-child(15n + 10) {
            margin-right: var(--margin);

            &::after {
                content: "";
                position: absolute;
                top: calc(-2 * var(--cell-gap));
                bottom: calc(-2 * var(--cell-gap));
                right: calc(-0.5 * calc(var(--margin) + var(--cell-gap)));
                width: 0.1ch;
                background-color: var(--fg-color);
            }
        }
    }

    .legend {
        grid-area: legend;
        display: flex;
        gap: 1ch;
        justify-content: flex-end;
        align-items: center;
        margin-top: 1.5ch;
        font-size: 1.3em;
        font-weight: 500;

        .cell {
            aspect-ratio: 1 / 1;
            height: var(--cell-size);
            background-color: var(--green);
            position: relative;
            font-size: 0.9em;

            text-shadow:
                -1px -1px 1px #000,
                 1px -1px 1px #000,
                -1px  1px 1px #000,
                 1px  1px 1px #000;

            border-radius: 10%;
            font-weight: 900;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: var(--cell-gap);
        }
    }

    .scroll-up { grid-area: btn-up; }
    .scroll-down { grid-area: btn-down; }

    .scroll-up,
    .scroll-down {
        padding: 0;
        width: calc(var(--cell-size) + 3.5rch);
        display: flex;
        align-items: center;
        justify-content: center;
        height: min-content;

        .msr-icon {
            font-size: 3em;
            line-height: 0.5;
        }
    }

}