/*
 * sso's own pages (launcher, account, two-step, people, app
 * setup, activity), on top of the kit. Kit tokens only, no literal colours;
 * every class starts sso-.
 */

.sso-page {
    --sso-mono: var(--portal-font-mono, var(--bs-font-monospace));
}

/* The page behind the frame is the frame's own colour, the same as the top
   bar and theme-color (AppKit 3.2.6: #0d0b19 Dark, #05040a Arena). The portal
   kit's portal-page-theme.css paints body its Bootstrap colour (#0d0c14 in
   Dark and Arena alike) through body:has(.portal-page-themed[data-bs-theme]),
   which outranks frame.css's body rule; on an installed iPhone app that shows
   as a darker strip under the status bar. Remove this once AppKit's frame.css
   wins on its own. */
html[data-kit-shell="frame"] body:has(.portal-page-themed) {
    background-color: var(--nt-bg);
}

/* ── Columns of groups ───────────────────────────────────────────────── */

/* Groups stand 24px apart, AppKit's step between regions (--nt-space-5), the
   same as on the pages written in nt- components (.nt-group). The portal
   kit's own gap is 28px (.portal-ios-group's margin, none after the last),
   which made the two kinds of page look like different apps. A column of
   groups (.sso-stack) keeps that one gap instead of adding a flex gap on top,
   and two columns (.sso-columns, a .row) keep it when they stack on a narrow
   screen. */
.sso-columns {
    --bs-gutter-x: 1.5rem;
    --bs-gutter-y: var(--nt-space-5, 1.5rem);
}

.sso-stack {
    display: flex;
    flex-direction: column;
    gap: var(--nt-space-5, 1.5rem);
}

.sso-page .portal-ios-group:not(:last-child) {
    margin-bottom: var(--nt-space-5, 1.5rem);
}

.sso-page .sso-stack > .portal-ios-group {
    margin-bottom: 0;
}

.sso-mono {
    font-family: var(--sso-mono, var(--bs-font-monospace));
    font-size: 0.85em;
    overflow-wrap: anywhere;
}

.sso-badges {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
}

/* ── A value shown once (a set-password link, a client secret) ──────── */

.sso-once {
    padding: 0.85rem 1rem;
    border-radius: var(--bs-border-radius-lg);
    border: 1px solid color-mix(in srgb, var(--bs-warning) 55%, transparent);
    background: color-mix(in srgb, var(--bs-warning) 10%, transparent);
}

.sso-once[hidden] {
    display: none;
}

.sso-once-head {
    margin: 0 0 0.6rem;
    font-weight: var(--portal-weight-strong, 700);
}

.sso-once-head i {
    color: var(--bs-warning-text-emphasis, var(--bs-warning));
}

.sso-once-label {
    display: block;
    margin: 0.5rem 0 0.25rem;
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--portal-c-text-muted);
}

.sso-once-foot {
    margin: 0.6rem 0 0;
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--portal-c-text-muted);
}

.sso-secret {
    font-family: var(--sso-mono, var(--bs-font-monospace));
    min-width: 0;
}

/* ── Label / value pairs ─────────────────────────────────────────────── */

.sso-kv {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.35rem 1rem;
    margin: 0;
    font-size: var(--portal-text-sm, 0.875rem);
}

.sso-kv dt {
    font-weight: var(--portal-weight-medium, 500);
    color: var(--portal-c-text-muted);
}

.sso-kv dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 575.98px) {
    .sso-kv {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.1rem;
    }

    .sso-kv dd {
        margin-bottom: 0.4rem;
    }
}

/* ── Expandable rows (a person, an app) ──────────────────────────────── */

.sso-item > summary {
    list-style: none;
    cursor: pointer;
}

.sso-item > summary::-webkit-details-marker {
    display: none;
}

.sso-item > summary:hover {
    background-color: var(--portal-c-tab-hover);
}

/* Never squeezed by a long title: every row's chevron in the same place. */
.sso-item-chevron {
    flex: none;
    color: var(--portal-c-text-muted);
    transition: transform var(--portal-dur-1, 120ms) var(--portal-ease-out, ease-out);
}

.sso-item[open] .sso-item-chevron {
    transform: rotate(90deg);
}

.sso-item:not(:last-child) {
    border-bottom: 1px solid var(--portal-c-border);
}

/* The row's own hairline (the kit's .portal-ios-row::after) would double
   the line above, and draw one under the last row of a group: the
   <details> carries the separator instead. */
.sso-item > summary.portal-ios-row::after {
    display: none;
}

.sso-item-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

/* No fill of its own: the kit's fields are already the sunken tint, and a
   second one under them made them read as disabled (light mode). */
.sso-item-body {
    padding: 0.9rem var(--portal-ios-gutter, 1rem) 1.1rem;
    border-top: 1px solid var(--portal-c-border);
}

/* Rows inside an opened row (Account: passkeys, codes) run edge to edge,
   as they do in a list, instead of a second gutter inside the first. The
   kit's rows are width: 100%, which would only slide them left: auto lets
   the margins widen them to both edges. */
.sso-item-body > .portal-ios-row,
.sso-item-body > [data-sso-refresh] > .portal-ios-row,
.sso-item-body > [data-sso-refresh] > .sso-item {
    width: auto;
    margin-inline: calc(-1 * var(--portal-ios-gutter, 1rem));
}

.sso-item-body > [data-sso-refresh]:first-child > :first-child {
    margin-top: -0.9rem;
}

.sso-item-body > section + section {
    margin-top: 1.1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--portal-c-border-subtle, var(--portal-c-border));
}

.sso-subhead {
    margin: 0 0 0.6rem;
    font-size: var(--portal-label-size-sm, 0.72rem);
    font-weight: var(--portal-weight-strong, 700);
    letter-spacing: var(--portal-label-tracking, 0.06em);
    text-transform: uppercase;
    color: var(--portal-c-text-muted);
}

.sso-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.sso-actions form {
    margin: 0;
}

/* App access: one line per app — the checkbox (none for an app everyone
   can use), the role, Save (and Clear). Each row is its own form; subgrid
   lines their columns up (a browser without it sizes each row alone). */
.sso-access {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 15rem) auto;
    gap: 0.45rem 0.5rem;
}

.sso-access-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 15rem) auto;
    grid-template-columns: subgrid;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.sso-access-row .form-check,
.sso-access-name {
    margin: 0;
    min-width: 0;
}

/* An app for everyone has no box to tick: an invisible one (the same
   .form-check-input, out of reach) holds its place, so its name lines up
   with the ticked rows' labels however the kit sizes the box. */
.sso-access-everyone {
    margin-left: 0.5rem;
    white-space: nowrap;
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--portal-c-text-muted);
}

.sso-access-row .form-check-label {
    overflow-wrap: anywhere;
}

.sso-access-buttons {
    display: flex;
    gap: 0.35rem;
}

/* An app with no roles: nothing to pick. */
.sso-access-norole {
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--portal-c-text-muted);
}

/* A grant whose role isn't on the app's list: its dropdown edged in the
   warning colour (over the kit's own field edge, which outranks a plain
   class), and a note under the row, full width. */
html[data-bs-theme] .sso-access .sso-access-row .form-select.sso-role-unknown-select:not(:focus) {
    border-color: var(--bs-warning);
}

.sso-access-unknown {
    grid-column: 1 / -1;
    margin: 0 0 0.25rem;
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--bs-warning-text-emphasis, var(--bs-warning));
}

@media (max-width: 575.98px) {
    .sso-access,
    .sso-access-row {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    /* Each app takes two lines here: more room between apps than inside
       one, so a role field reads as its own app's. */
    .sso-access {
        row-gap: 1rem;
    }

    .sso-access-row {
        grid-template-columns: subgrid;
    }

    .sso-access-row .form-check,
    .sso-access-name {
        grid-column: 1 / -1;
    }
}

/* An app's roles on App setup: name, then what it can do. */
.sso-roles {
    display: grid;
    grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
    gap: 0.4rem 0.5rem;
    align-items: center;
}

.sso-roles-head {
    font-size: var(--portal-text-sm, 0.875rem);
    color: var(--portal-c-text-muted);
}

.sso-role-unknown {
    color: var(--bs-warning-text-emphasis, var(--bs-warning));
}

@media (max-width: 575.98px) {
    .sso-roles {
        grid-template-columns: minmax(0, 6.5rem) minmax(0, 1fr);
    }
}

/* ── Forms ───────────────────────────────────────────────────────────── */

.sso-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1rem;
}

.sso-form-grid .sso-span-2 {
    grid-column: 1 / -1;
}

@media (max-width: 575.98px) {
    .sso-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.sso-uris {
    font-family: var(--sso-mono, var(--bs-font-monospace));
}

/* One address a line: a long one scrolls along its line instead of
   wrapping into the next, which a one-row box (After-sign-out
   addresses) cut in half. */
textarea.sso-uris {
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}

/* A note under a button (not under a field) needs more than the kit's
   0.25rem, or it reads as part of the button. */
.sso-page .btn + .form-text {
    margin-top: 0.5rem;
}

/* ── Two-step setup and recovery codes ───────────────────────────────── */

.sso-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: sso-step;
}

.sso-steps > li {
    position: relative;
    padding-left: 2.4rem;
    counter-increment: sso-step;
}

.sso-steps > li + li {
    margin-top: 1.25rem;
}

.sso-steps > li::before {
    content: counter(sso-step);
    position: absolute;
    left: 0;
    /* Centred on the title's first line. */
    top: calc((1lh - 1.7rem) / 2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    background: var(--portal-c-accent);
    color: var(--portal-c-on-accent);
    font-weight: var(--portal-weight-strong, 700);
    font-size: 0.85rem;
}

.sso-step-title {
    margin: 0 0 0.5rem;
    font-weight: var(--portal-weight-strong, 700);
}

/* The QR code: dark modules on white whatever the theme, so any camera reads it. */
.sso-qr {
    width: 200px;
    max-width: 100%;
    aspect-ratio: 1;
    padding: 6px;
    border-radius: var(--nt-radius-lg, 10px);
    background: var(--bs-white);
    color: var(--bs-black);
}

.sso-qr svg {
    display: block;
    width: 100%;
    height: 100%;
}

.sso-code-input {
    max-width: 12rem;
    font-family: var(--sso-mono, var(--bs-font-monospace));
    font-size: 1.15rem;
    /* The bigger digits made the field 41.6px beside a 38px button: the line
       is the digits' own height, so the field is the kit's control height. */
    line-height: 1;
    padding-block: 0;
    letter-spacing: 0.15em;
}

.sso-codes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
}

.sso-codes li {
    padding: 0.5rem 0.6rem;
    border-radius: var(--bs-border-radius);
    border: 1px solid var(--portal-c-border);
    background: var(--portal-c-surface-sunken);
    font-family: var(--sso-mono, var(--bs-font-monospace));
    font-size: 1rem;
    letter-spacing: 0.06em;
    text-align: center;
}

/* ── Account ─────────────────────────────────────────────────────────── */

.sso-session-apps {
    display: block;
    margin-top: 0.1rem;
}

/* ── Activity ────────────────────────────────────────────────────────── */

.sso-activity td,
.sso-activity th {
    font-size: var(--portal-text-sm, 0.875rem);
}

/* The person and app links (each filters the log): a 44px target on
   touch, reaching into the cell's padding instead of making the row taller. */
@media (any-pointer: coarse) {
    .sso-activity td a {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        margin-block: calc((1lh - 44px) / 2);
    }
}

.sso-activity-time {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.sso-detail {
    display: block;
    max-width: 22rem;
    font-family: var(--sso-mono, var(--bs-font-monospace));
    font-size: 0.78rem;
    color: var(--portal-c-text-muted);
    overflow-wrap: anywhere;
}

.sso-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.75rem;
}

.sso-filters .form-select {
    min-width: 10rem;
    max-width: 100%;
}

@media (max-width: 575.98px) {
    .sso-filters > * {
        flex: 1 1 100%;
    }

    .sso-detail {
        max-width: none;
    }
}

/* A fieldset's legend reads as the other field labels do (the kit styles
   .form-label; Bootstrap's legend is a heading size). */
.sso-page fieldset > legend.form-label {
    float: none;
    width: auto;
    padding: 0;
    font-size: var(--portal-text-sm, 0.875rem);
    font-weight: var(--portal-weight-label, 600);
}

.sso-page .form-check-label {
    font-size: var(--portal-text-sm, 0.875rem);
}

.sso-ip {
    overflow-wrap: normal;
}

/* ── Passkeys ────────────────────────────────────────────────────────── */

/* Hidden until account.js knows the browser can make one (and the note
   that says it can't, once it knows it can). */
[data-passkey-add][hidden],
[data-passkey-unsupported][hidden] {
    display: none !important;
}

.sso-passkey-password {
    flex: 1 1 12rem;
    max-width: 20rem;
}

/* ── Account: Preferences, one setting a row ─────────────────────────── */

/* Every select the same width, in one column down the right. Under about
   34rem of row the kit's stacking row puts the select below its text, where
   it takes the whole width. */
.sso-pref-row > .portal-ios-row-control {
    flex: 1 1 17rem;
}

.sso-pref-row > .portal-ios-row-control > .form-select {
    width: 100%;
}

/* The row's text is the select's label: the whole of it is the target. */
.sso-pref-row > label.portal-ios-row-main {
    margin: 0;
    cursor: pointer;
}

/* An error from a save is shown at the top of the form, inside the list. */
#sso-preferences form > .sso-form-error {
    margin: 0.75rem var(--portal-ios-gutter, 1rem) 0.25rem;
}
