@layer components {

    /* A place we can reach someone: label and field on one line, stacking when
       there is no room. The label column holds one width across rows so the set
       reads as a list, which no utility expresses. */
    .app-channel-slot {
        display: grid;
        grid-template-columns: minmax(10rem, 14rem) 1fr;
        align-items: center;
        gap: var(--space-4);
        padding-block: var(--space-4);
        border-top: 1px solid var(--color-line);
    }

    .app-channel-slot:first-child {
        border-top: 0;
        padding-top: 0;
    }

    .app-channel-slot__label {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        font-weight: 600;
        color: var(--color-ink);
    }

    .app-channel-slot__label i {
        color: var(--color-ink-mute);
    }

    .app-channel-slot__address {
        color: var(--color-ink);
    }

    .app-channel-slot__note {
        color: var(--color-ink-mute);
        font-size: var(--fs-ui-sm);
    }

    /* The purpose-by-channel matrix. Wide: a real table, so each column names its
       channel once. Narrow: each purpose becomes a block of pill toggles, because
       a six-column table cannot be read on a phone. */
    .app-preference-matrix {
        width: 100%;
        border-collapse: collapse;
    }

    .app-preference-matrix th,
    .app-preference-matrix td {
        padding: var(--space-3);
        border-bottom: 1px solid var(--color-line);
        text-align: center;
        vertical-align: middle;
    }

    .app-preference-matrix tbody tr:last-child > * {
        border-bottom: 0;
    }

    .app-preference-matrix thead th {
        font-size: var(--fs-ui-sm);
        font-weight: 500;
        color: var(--color-ink-mute);
    }

    .app-preference-matrix th[scope="row"] {
        text-align: left;
        padding-left: 0;
    }

    .app-preference-matrix__name {
        display: block;
        font-weight: 600;
        color: var(--color-ink);
    }

    .app-preference-matrix__caption {
        display: block;
        font-size: var(--fs-ui-sm);
        color: var(--color-ink-mute);
    }

    /* Beside a column heading the channel name is for screen readers only. */
    .app-preference-matrix__channel {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .app-contact-preferences__summary {
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        margin: 0;
        padding: 0;
        list-style: none;
        font-size: var(--fs-body-sm);
        color: var(--color-ink);
    }

    .app-contact-preferences__warning {
        color: var(--color-warn-deep);
    }

    @media (max-width: 48rem) {
        .app-channel-slot {
            grid-template-columns: 1fr;
            gap: var(--space-2);
        }

        .app-preference-matrix,
        .app-preference-matrix tbody,
        .app-preference-matrix th,
        .app-preference-matrix td {
            display: block;
        }

        .app-preference-matrix thead {
            display: none;
        }

        .app-preference-matrix tr {
            display: flex;
            flex-wrap: wrap;
            gap: var(--space-2);
            padding-block: var(--space-4);
            border-bottom: 1px solid var(--color-line);
        }

        .app-preference-matrix tbody tr:last-child {
            border-bottom: 0;
        }

        .app-preference-matrix th,
        .app-preference-matrix td {
            padding: 0;
            border-bottom: 0;
        }

        .app-preference-matrix th[scope="row"] {
            flex-basis: 100%;
            margin-bottom: var(--space-1);
        }

        /* Each cell is a pill: the box is dropped and the pill fills when ticked.
           The native input stays in place, so keyboard and screen reader use is
           unchanged. */
        .app-preference-matrix__toggle {
            padding: var(--space-2) var(--space-4);
            border: 1px solid var(--color-line);
            border-radius: var(--radius-pill);
            background: var(--color-surface);
        }

        .app-preference-matrix__toggle .app-checkbox__box {
            display: none;
        }

        .app-preference-matrix__channel {
            position: static;
            width: auto;
            height: auto;
            overflow: visible;
            clip-path: none;
        }

        .app-preference-matrix__toggle:has(input:checked) {
            background: var(--color-accent);
            border-color: var(--color-accent);
        }

        .app-preference-matrix__toggle:has(input:checked) .app-checkbox__label {
            color: var(--color-on-dark);
        }

        .app-preference-matrix__toggle:has(input:focus-visible) {
            outline: 2px solid var(--color-accent-deep);
            outline-offset: 2px;
        }

        .app-preference-matrix__toggle.app-checkbox--disabled .app-checkbox__label {
            color: var(--color-ink-faint);
        }
    }
}
