/*
 * One stylesheet, no build step. Colours and spacing are custom properties so
 * dark mode is a matter of redefining them.
 *
 * Ported from identity-provider.net, retinted: amber where that site is cyan,
 * so the two read as siblings rather than as the same site.
 */

:root {
    --bg: #faf8f5;
    --bg-accent: #fcf1e4;
    --surface: #ffffff;
    --ink: #1c1914;
    --muted: #6b635a;
    --line: #e8e2da;
    --accent: #b4530a;
    --accent-ink: #ffffff;
    --accent-soft: #fbeedf;
    --ok: #137a4b;
    --ok-soft: #e3f5ec;
    --warn: #7a6400;
    --warn-soft: #fbf4cc;
    --danger: #b3261e;
    --danger-soft: #fdecea;
    --radius: 14px;
    --radius-small: 8px;
    --shadow: 0 1px 2px rgb(16 24 32 / 5%), 0 4px 16px rgb(16 24 32 / 5%);
    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17130e;
        --bg-accent: #2a1d0e;
        --surface: #1f1a14;
        --ink: #f0ebe4;
        --muted: #a89f94;
        --line: #342c22;
        --accent: #f5a54a;
        --accent-ink: #1d1206;
        --accent-soft: #3a2610;
        --ok: #5fd39a;
        --ok-soft: #173327;
        --warn: #e8d35a;
        --warn-soft: #332d0e;
        --danger: #ff8d85;
        --danger-soft: #3b1d1b;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(60rem 30rem at 10% -10%, var(--bg-accent), transparent 70%),
        var(--bg);
    color: var(--ink);
    font: 16px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }
h1 { margin: 0 0 .5rem; font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem); }
h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
h3 { margin: 0 0 .35rem; font-size: 1rem; }
p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

code {
    font-family: var(--mono);
    font-size: .875em;
    background: var(--accent-soft);
    border-radius: 5px;
    padding: .1em .35em;
    overflow-wrap: anywhere;
}

img { max-width: 100%; }

/* A section break inside a long form. */
hr {
    margin: 2rem 0 1.25rem;
    border: 0;
    border-top: 1px solid var(--line);
}

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------- chrome */

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: saturate(1.4) blur(10px);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    border-bottom: 1px solid var(--line);
}

.bar {
    max-width: 72rem;
    margin: 0 auto;
    padding: .75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
    letter-spacing: -0.01em;
}

.brand-mark {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: conic-gradient(from 200deg, #b4530a, #f59e0b, #fcd34d, #b4530a);
    box-shadow: inset 0 0 0 4px var(--surface);
    border: 1px solid var(--line);
}

.shell {
    flex: 1;
    width: 100%;
    max-width: 36rem;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem;
}

.shell.wide { max-width: 56rem; }

.site-footer {
    padding: 2rem 1.25rem 2.5rem;
    border-top: 1px solid var(--line);
    text-align: center;
    color: var(--muted);
    font-size: .875rem;
}

.site-footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem 1.25rem; margin-bottom: .5rem; }
.site-footer a { color: var(--muted); }

/*
 * The main menu: a sidebar of stacked links beside the page on wide screens.
 * On narrow screens it is a popover drawer opened by the header's menu button
 * (popovertarget), so the browser handles Escape, tapping outside and focus
 * with no JavaScript. Browsers without popover support show it as a plain
 * list above the page.
 */
.frame {
    flex: 1;
    width: 100%;
    max-width: 72rem;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
}

.frame > .shell { grid-column: 2; grid-row: 1; margin: 0; padding-inline: 0; }

.site-menu {
    /* Undo the browser's popover styles: a sidebar until narrow screens. */
    position: sticky;
    inset: auto;
    top: 3.5rem;
    width: auto;
    height: auto;
    margin: 0;
    border: 0;
    color: inherit;
    background: none;
    overflow: visible;

    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 2.5rem 0 2rem;
    font-size: .9375rem;
}

.menu-group { display: flex; flex-direction: column; gap: .15rem; }
.menu-group + .menu-group { padding-top: 1rem; border-top: 1px solid var(--line); }
.menu-group form { margin: 0; }

.menu-heading {
    margin: 0 0 .25rem;
    padding: 0 .75rem;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
}

.site-menu a, .site-menu .menu-link {
    display: block;
    width: 100%;
    padding: .5rem .75rem;
    text-align: left;
    color: var(--ink);
    text-decoration: none;
    border-radius: var(--radius-small);
}

/* A form button (Log out) dressed as the links around it. */
.site-menu .menu-link { font: inherit; background: none; border: 0; cursor: pointer; }

.site-menu a:hover, .site-menu .menu-link:hover { color: var(--ink); background: var(--accent-soft); }
.site-menu [aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* The sandbox session id: identifying, not actionable, so it reads as a note
   rather than as another menu entry. */
.menu-note { margin: .25rem 0 0; padding: 0 .75rem; font-size: .8125rem; color: var(--muted); }
.menu-note code { background: none; padding: 0; }

.menu-button {
    display: none;
    align-items: center;
    gap: .5rem;
    padding: .45rem .8rem;
    font: inherit;
    font-size: .9375rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    cursor: pointer;
}

.menu-button:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 48rem) {
    .frame { display: block; padding: 0; }
    .frame > .shell { padding-inline: 1.25rem; }
    .site-menu { position: static; padding: 1.5rem 1.25rem 0; }

    @supports selector(:popover-open) {
        .menu-button { display: inline-flex; }

        .site-menu {
            position: fixed;
            /* From the right, the side the header's menu button is on. */
            inset: 0 0 0 auto;
            width: min(18rem, 85vw);
            height: 100dvh;
            padding: 1.25rem .75rem;
            overflow-y: auto;
            background: var(--surface);
            border-left: 1px solid var(--line);
            box-shadow: var(--shadow);
            transform: translateX(100%);
            transition: transform .2s ease, display .2s allow-discrete, overlay .2s allow-discrete;
        }

        .site-menu:not(:popover-open) { display: none; }
        .site-menu:popover-open { transform: none; }
        .site-menu::backdrop { background: rgb(0 0 0 / .4); }

        @starting-style {
            .site-menu:popover-open { transform: translateX(100%); }
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-menu { transition: none; }
}

/* --------------------------------------------------------------- blocks */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(1.25rem, 1rem + 1vw, 2rem);
}

.card + .card, .notice + .card, .alert + .card, .warn + .card,
.page-header + .card, .actions + .card { margin-top: 1.25rem; }

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem 1rem;
    margin-bottom: .75rem;
}

.card-header h2 { margin: 0; overflow-wrap: anywhere; }
/* The identifier under a record's name — a client_id, an entity id, an issuer. */
.card-header .subtitle { margin: .15rem 0 0; font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }
.card-header > div:first-child { min-width: 0; }

.card-secret { border-color: var(--accent); border-width: 2px; }

.page-header { margin-bottom: 1.5rem; }
.page-header .badge { margin-top: .25rem; }

.lede { margin: 0; font-size: 1.05rem; color: var(--muted); max-width: 44rem; }
.page-header .lede { margin-top: .25rem; }

.empty { color: var(--muted); font-style: italic; }

.notice, .alert, .warn {
    margin: 0 0 1.25rem;
    padding: .8rem 1rem;
    border-radius: var(--radius-small);
    font-size: .9375rem;
}

.notice { background: var(--ok-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); }
.alert { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
/* Something for the reader to do, as opposed to .notice's "nothing to do here"
   or .alert's "something is wrong". */
.warn { background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); }
.card .alert:last-child { margin-bottom: 0; }
.card .notice { background: var(--accent-soft); border-color: transparent; }

/* URLs quoted in a banner are tinted with the banner's own colour rather than
   the accent; `code` already lets them break mid-URL on a narrow screen. */
.notice code, .alert code, .warn code { background: color-mix(in srgb, currentColor 12%, transparent); }

/* What the banner means for the reader, set apart from the message itself. */
.notice p, .alert p, .warn p { margin: .5rem 0 0; }
.notice p:first-child, .alert p:first-child, .warn p:first-child { margin-top: 0; }
.notice strong:first-child, .alert strong:first-child, .warn strong:first-child { display: block; margin-bottom: .25rem; }
.alert ul, .notice ul, .warn ul { margin: .5rem 0 0; padding-left: 1.25rem; }

/* ---------------------------------------------------------------- forms */

/*
 * A form's vertical rhythm comes from the grid rather than from margins: a
 * hidden CSRF input is display:none and so occupies no track, where a
 * margin-based rule would leave a gap above the first real field. `.fields`
 * gives an inner group of fields the same rhythm — `.auth-section` beside it
 * is a hook script.js reads, and stays free of styling.
 */
form.card, .fields { display: grid; align-content: start; gap: 1.1rem; }
form.card > h3 { margin: 0; }
form.card > hr { margin: .9rem 0 0; }
form.card > .notice, form.card > .alert, form.card > .warn { margin: 0; }
form.card > .actions { margin: .4rem 0 0; }
/* A hint under the row it explains, rather than floating between two rows. */
form.card > .hint { margin-top: -.6rem; }

.field { display: grid; gap: .35rem; }
.field label { font-size: .9rem; font-weight: 600; }

/* Two or three inputs that belong on one line, stacking when they cannot. */
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.1rem; }
/* A group nested under a checkbox that switches it on, set off from its hint. */
.field > .field-row, .field > .field { margin-top: .4rem; }

input[type="text"], input[type="url"], input[type="email"], input[type="password"], input:not([type]), select, textarea {
    width: 100%;
    padding: .65rem .8rem;
    font: inherit;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

textarea { font-family: var(--mono); font-size: .875rem; line-height: 1.5; }

input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-color: var(--accent);
}

/* The field the server rejected. */
.field-error > label { color: var(--danger); }
.field-error input, .field-error select, .field-error textarea {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger-soft) 60%, var(--bg));
}

.hint { margin: 0; font-size: .8125rem; color: var(--muted); }
.hint code { font-size: .9em; }
.actions + .hint { margin-top: .6rem; }
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .7rem 1.2rem;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: var(--accent-ink);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    transition: filter .15s, transform .05s;
}

.button:hover { filter: brightness(1.08); }
.button:active { transform: translateY(1px); }
.button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.button:disabled { opacity: .55; cursor: not-allowed; }
/* .button sets display, so the UA's [hidden] rule alone would not hide one. */
.button[hidden] { display: none; }

.button-quiet { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button-small { padding: .4rem .8rem; font-size: .875rem; }
.button-danger-quiet { color: var(--danger); background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1.25rem; }
.actions form { margin: 0; }

.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.inline-form input { flex: 1 1 12rem; width: auto; padding: .45rem .7rem; }

/* ----------------------------------------------------------------- lists */

.rows { margin: 1rem 0; padding: 0; list-style: none; display: grid; gap: .5rem; }

.rows > li {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

.rows p { margin: .1rem 0 0; }
.row-main { color: var(--ink); text-decoration: none; }
.row-main:hover strong { color: var(--accent); }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row-actions form { margin: 0; }

.badge {
    display: inline-block;
    padding: .15rem .6rem;
    font-size: .75rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    vertical-align: middle;
    /* Badges carry auth method names, which otherwise wrapped inside the pill
       as "client_secre t_basic". */
    white-space: nowrap;
}

.badge-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge-warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.badge-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge-small { padding: 0 .45rem; font-size: .6875rem; }

.facts { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; font-size: .9375rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
/* Opaque identifiers stay intact and wrap only when they genuinely cannot fit. */
.facts code { word-break: normal; overflow-wrap: anywhere; }

/* Several values under one term — a client's redirect URIs, say. */
.lines { display: grid; gap: .2rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
th, td { padding: .5rem .75rem .5rem 0; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8125rem; }

.code-block {
    margin: .75rem 0;
    padding: .9rem 1rem;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: .875rem;
    line-height: 1.5;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

.code-block code { padding: 0; background: none; font-size: inherit; overflow-wrap: normal; white-space: pre; }
.code-block.secret code { user-select: all; font-size: 1rem; }
/* A long single-line value — a recovery URL — should wrap rather than scroll. */
.code-block.break code { white-space: pre-wrap; overflow-wrap: anywhere; }

/* A code block with a copy button attached to its end. */
.copy-field { display: flex; align-items: stretch; margin: .75rem 0; }
.copy-field .code-block { flex: 1; min-width: 0; margin: 0; }

.copy-field:has(.copy-button:not([hidden])) .code-block {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.copy-button {
    flex: none;
    padding: 0 1rem;
    font: inherit;
    font-size: .875rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 var(--radius-small) var(--radius-small) 0;
    cursor: pointer;
    white-space: nowrap;
}

.copy-button:hover { filter: brightness(0.97); }
.copy-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

/* ------------------------------------------------------------ dashboard */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.card-grid .card { margin-top: 0; }

/* A whole tile that is one link, so there is no separate "Manage" button. */
.card-link { display: flow-root; color: inherit; text-decoration: none; transition: border-color .15s, transform .05s; }
.card-link:hover { border-color: var(--accent); }
.card-link:active { transform: translateY(1px); }
.card-link:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.card-link h2 { margin: 0 0 .25rem; }
.card-link p { color: var(--muted); font-size: .9375rem; }

.count {
    float: right;
    margin-left: .75rem;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--accent);
}

@media (max-width: 36rem) {
    .facts { grid-template-columns: 1fr; gap: .1rem; }
    .facts dd { margin-bottom: .5rem; }
}

/* ------------------------------------------------------------ this app */

/* Where a tenant page sits, above its heading. */
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .5rem; margin-bottom: .75rem; font-size: .875rem; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb > * + *::before { content: "›"; margin-right: .5rem; color: var(--line); }
.breadcrumb [aria-current] { color: var(--ink); }

/* The heading row of a page that also carries an action, like Sign out. */
.page-header.with-action { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem 1rem; }
.page-header.with-action form { margin: 0; }

/* The one value the reader must carry over to their IdP: the tenant_id. */
.card-accent { border-left: 4px solid var(--accent); }

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card > h2 + p, .card > h3 + p { margin-top: .25rem; }

/* An input fused to the button after it: "Add", "Fetch discovery". */
.input-action { display: flex; align-items: stretch; }
.input-action input { flex: 1; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-action .button { flex: none; border-radius: 0 var(--radius-small) var(--radius-small) 0; }

/* The server's reason under a rejected field. */
.field-message { margin: 0; font-size: .8125rem; font-weight: 600; color: var(--danger); }

/* A checkbox with its label beside it rather than above. */
.check { display: flex; align-items: center; gap: .55rem; font-size: .9375rem; font-weight: 400; cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; margin: 0; accent-color: var(--accent); }
/* Lines a checkbox up with the inputs in the other columns of a .field-row. */
.field-row > .check { align-self: end; min-height: 2.9rem; }

/* A square button holding only an icon. */
.icon-button {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    cursor: pointer;
}

.icon-button:hover { color: var(--danger); background: var(--danger-soft); }
.icon-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.icon-button svg { display: block; }

/* The todo list: a round toggle, the title with who added it, and delete. */
.todo-list { margin-top: 1.25rem; }
.todo-list > li { flex-wrap: nowrap; gap: .75rem; padding: .6rem .75rem; justify-content: flex-start; }
.todo-list form { margin: 0; }
.todo-body { flex: 1; min-width: 0; }
.todo-title { overflow-wrap: anywhere; }
.todo-meta { margin: .1rem 0 0; font-size: .8125rem; color: var(--muted); }

.todo-toggle {
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    color: transparent;
    background: var(--surface);
    border: 2px solid color-mix(in srgb, var(--accent) 55%, var(--line));
    border-radius: 50%;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.todo-toggle:hover { border-color: var(--accent); color: color-mix(in srgb, var(--accent) 50%, transparent); }
.todo-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.todo-done .todo-toggle { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.todo-done .todo-title { color: var(--muted); text-decoration: line-through; }

@media (prefers-reduced-motion: reduce) {
    .todo-toggle { transition: none; }
}

.input-action + .empty { margin-top: 1.25rem; }
.card > h3 + .actions { margin-top: .75rem; }
/* A copyable value inside a list of facts sits flush with its term. */
.facts .copy-field { margin: 0; }
.facts .code-block { padding: .45rem .7rem; }
.facts .hint { margin-top: .35rem; }
.section-break { margin-top: 2.5rem; }
.card + .alert, .card + form { margin-top: 1.25rem; }
form > .actions { margin-top: 1.5rem; }
