/* Convention:
 * - View IDs are JavaScript handles; existing one-off chrome IDs may style chrome.
 * - Grid owns the page, views, and primary/action tracks. gap owns sibling spacing.
 * - .stack, .split, and .cluster are the complete reusable layout vocabulary.
 * - Native elements and attributes own semantics and state; ARIA is never added solely for styling.
 * - Extract a new name only after a second real consumer proves the same contract.
 */

/* One palette and role-based type scale; layout spacing uses 4px steps.
 * Reading surfaces use body text. Operational surfaces use compact control text. */
:root {
    --page: #fdfdfc;
    --surface: #fff;
    --surface-subtle: #fafaf9;
    --surface-selected: #e7e5e4;
    --border: #e7e5e4;
    --border-control: #a8a29e;
    --ink: #1c1917;
    --text: #44403c;
    --text-secondary: #57534e;
    --text-muted: #78716c;
    --text-disabled: #a8a29e;
    --danger: #b91c1c;
    --font-sans: system-ui, sans-serif;
    --font-mono: ui-monospace, monospace;
    --type-title: 600 1.75rem / 2.25rem var(--font-sans);
    --type-section: 600 1.5rem / 2rem var(--font-sans);
    --type-subheading: 600 1.25rem / 1.75rem var(--font-sans);
    --type-body: 400 1rem / 1.5rem var(--font-sans);
    --type-control: 400 0.875rem / 1.25rem var(--font-sans);
    --type-caption: 400 0.75rem / 1rem var(--font-sans);
    --type-code: 400 0.875rem / 1.25rem var(--font-mono);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    margin: 0;
    display: grid;
    grid-template:
        "top  top" auto
        "side main" minmax(0, 1fr)
        "side footer" auto
        / 12rem minmax(0, 1fr);
    background: var(--page);
    color: var(--text);
    font: var(--type-control);
}

a {
    color: inherit;
}

.legal_footer {
    grid-area: footer;
    width: 100%;
    max-width: 56rem;
    display: flex;
    gap: 1rem;
    padding: 0 2rem 1rem;
    color: var(--text-muted);
    font: var(--type-caption);
}

:where(button, input, select) {
    font: inherit;
}

button {
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: 4px;
    background: var(--ink);
    color: var(--surface);
    cursor: pointer;
}

button:disabled,
select:disabled {
    opacity: 0.5;
    cursor: default;
}

input,
select {
    min-width: 0;
    padding: calc(0.5rem - 1px) 0.75rem;
    border: 1px solid var(--border-control);
    border-radius: 4px;
    background: var(--surface);
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

h1 {
    margin: 0;
    color: var(--ink);
    font: var(--type-title);
    letter-spacing: -0.02em;
}

.stack {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 1rem;
}

.split {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    align-items: center;
    gap: 0.5rem;
}

.split > * {
    min-width: 0;
}

.cluster {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.muted {
    color: var(--text-muted);
}

.quiet {
    background: none;
    color: var(--text-secondary);
}

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

#top {
    grid-area: top;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

#brand {
    color: var(--ink);
    font: var(--type-subheading);
    text-decoration: none;
}

.slash {
    color: var(--border);
}

.org_switcher {
    position: relative;
    font: var(--type-control);
}

.org_switcher > summary {
    max-width: 16rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--ink);
    font-weight: 600;
    list-style: none;
    cursor: pointer;
}

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

.org_switcher > summary:hover,
.org_switcher[open] > summary {
    background: var(--surface-selected);
}

.org_name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.caret {
    width: 0.75rem;
    height: 0.75rem;
    display: grid;
    place-items: center;
    color: var(--text-muted);
}

.caret::before {
    width: 0.4rem;
    height: 0.4rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    content: "";
    transform: translateY(-0.1rem) rotate(45deg);
}

.org_menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    z-index: 2;
    width: max-content;
    min-width: 100%;
    max-width: calc(100vw - 2rem);
    display: grid;
    gap: 0.25rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(28, 25, 23, 0.12);
}

.org_list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.org_link,
.org_create {
    width: 100%;
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    background: none;
    color: inherit;
    text-align: left;
    text-decoration: none;
}

.org_link:hover,
.org_create:hover,
.org_link[aria-current] {
    background: var(--surface-subtle);
}

.org_link[aria-current] {
    font-weight: 600;
}

.org_link {
    overflow-wrap: anywhere;
}

.org_create {
    display: grid;
    grid-template-columns: 1rem minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-subtle);
    color: var(--text-secondary);
    font-weight: 500;
}

.org_create:hover {
    background: var(--surface-selected);
}

.org_create > span:first-child {
    font-size: 1rem;
    line-height: 1;
    text-align: center;
}

.form_dialog {
    width: 28rem;
    max-width: calc(100% - 2rem);
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: inherit;
}

.form_dialog::backdrop {
    background: rgba(28, 25, 23, 0.24);
}

.form_dialog h2 {
    margin: 0;
    color: var(--ink);
    font: var(--type-subheading);
}

.form_dialog :where(input, select) {
    width: 100%;
}

.select_control {
    position: relative;
    display: grid;
}

.select_control > select {
    appearance: none;
    padding-right: 2.25rem;
}

.select_control > .caret {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    pointer-events: none;
    transform: translateY(-50%);
}

.select_control > select:disabled + .caret {
    opacity: 0.5;
}

.dialog_actions {
    justify-content: end;
}

.chip {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: var(--ink);
    color: var(--surface);
    font: var(--type-caption);
    font-weight: 600;
}

#account {
    position: relative;
}

#account > summary {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem;
    border-radius: 6px;
    list-style: none;
    cursor: pointer;
}

#account > summary::-webkit-details-marker {
    display: none;
}

#account > summary:hover,
#account[open] > summary {
    background: var(--surface-subtle);
}

.menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 1;
    min-width: 14rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(28, 25, 23, 0.12);
}

#who {
    display: grid;
    padding: 0.5rem 0.75rem;
    font: var(--type-control);
}

#who > span {
    color: var(--text-muted);
}

#side {
    grid-area: side;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 1rem;
    padding: 1rem 0.75rem;
    border-right: 1px solid var(--border);
}

#side > nav {
    display: grid;
    align-content: start;
    gap: 0.25rem;
}

.nav_heading {
    margin: 0;
    padding: 0.75rem 0.75rem 0.25rem;
    color: var(--text-muted);
    font: var(--type-caption);
    font-weight: 600;
}

#side :where(a, button) {
    width: 100%;
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: none;
    color: inherit;
    text-align: left;
    text-decoration: none;
    font: var(--type-control);
}

#side .settings_link {
    padding-left: 1rem;
}

#side a[href]:hover,
#side button:hover {
    background: var(--surface-selected);
}

#side a[aria-current="page"] {
    background: var(--surface-selected);
    font-weight: 600;
}

#side a:not([href]) {
    color: var(--text-disabled);
}

#logout {
    color: var(--text-muted);
    font: var(--type-control);
}

main {
    grid-area: main;
    min-width: 0;
    width: 100%;
    max-width: 56rem;
    padding: 1.5rem 2rem;
}

.view_header {
    align-items: baseline;
    gap: 0.75rem;
}

.view_header > span {
    font: var(--type-caption);
}

.page_status {
    font: var(--type-control);
}

.empty_state > p {
    font: var(--type-body);
}

.page_status,
.page_error,
.empty_state > p {
    margin: 0;
}

.page_error {
    color: var(--danger);
    font: var(--type-control);
}

.agent_list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.agent_list > li {
    gap: 0.75rem;
    padding: 0.75rem 0.25rem;
    border-bottom: 1px solid var(--border);
}

.agent_list > li:last-child {
    border-bottom: 0;
}

.agent_link {
    overflow-wrap: anywhere;
    font-weight: 500;
    text-decoration: none;
}

.agent_link:hover {
    text-decoration: underline;
}

.agent_status {
    font: var(--type-caption);
}

.agent_badge {
    font: var(--type-caption);
    color: var(--danger);
    border: 1px solid currentColor;
    border-radius: 0.25rem;
    padding: 0 0.375rem;
}

.agent_toggle {
    font: var(--type-caption);
    padding: 0 0.375rem;
}

.delete,
.revoke,
.dismiss,
.member_remove {
    padding: 0 0.25rem;
}

.delete {
    font-size: 1rem;
}

.delete:hover,
.revoke:hover,
.dismiss:hover,
.member_remove:hover {
    color: var(--danger);
}

.agent_list > .empty {
    font: var(--type-body);
}

.member_role {
    flex-wrap: nowrap;
}

.org_access_note,
.key_access_note {
    margin: 0;
    font: var(--type-body);
}

.key_mint {
    gap: 0.5rem;
}

.key_reveal {
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.key_reveal > p {
    margin: 0;
    color: var(--danger);
    font: var(--type-control);
}

.key_token {
    overflow-wrap: anywhere;
    font: var(--type-code);
}

.table_scroll {
    position: relative;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border: 1px solid var(--border);
    border-collapse: collapse;
    border-radius: 8px;
    background: var(--surface);
    font: var(--type-control);
}

th,
td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

th {
    background: var(--surface-subtle);
    color: var(--text-secondary);
    font-weight: 600;
}

tr:last-child > td {
    border-bottom: 0;
}

tr.dead {
    color: var(--text-disabled);
}

td > code {
    font-family: var(--font-mono);
}

tr.empty > td {
    text-align: center;
}

/* The docs intro and body share one measure and one prose style. */
.docs_body,
.docs_lede {
    color: var(--text);
    font: var(--type-body);
}

.docs_body {
    display: grid;
    gap: 0.75rem;
}

.docs_body :where(h2, h3, h4, p, ul, blockquote, pre) {
    margin: 0;
}

.docs_body :is(h2, h3, h4) {
    color: var(--ink);
    font-weight: 600;
}

.docs_body h2 {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font: var(--type-section);
}

.docs_body h2:first-of-type {
    margin-top: 0.75rem;
    padding-top: 0;
    border-top: 0;
}

.docs_body h3 {
    padding-top: 0.75rem;
    font: var(--type-subheading);
}

.docs_body h4 {
    padding-top: 0.5rem;
    font: var(--type-body);
    font-weight: 600;
}

.docs_body pre {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font: var(--type-code);
    overflow-x: auto;
}

.docs_body code {
    color: var(--ink);
    font: var(--type-code);
}

.docs_body pre code {
    font-size: inherit;
}

.docs_body table code {
    font-size: inherit;
}

.docs_body ul {
    display: grid;
    gap: 0.25rem;
    padding-left: 1.25rem;
}

.docs_body blockquote {
    padding: 0.25rem 0 0.25rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-secondary);
}

.docs_body td {
    white-space: normal;
}

/* Account pages keep their centered forms while using the shared UI roles. */
body.auth_page {
    grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
    place-items: center;
}

.auth_page > form {
    display: grid;
    gap: 0.75rem;
    width: 24rem;
    max-width: calc(100% - 2rem);
    margin: 1rem 0;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.auth_page h1 {
    margin-bottom: 0.5rem;
}

.auth_page .intro {
    margin: 0;
    color: var(--text-secondary);
    font: var(--type-body);
}

.auth_page label {
    display: grid;
    gap: 0.25rem;
}

.auth_page .consent_line {
    margin: 0;
    color: var(--text-secondary);
    font: var(--type-caption);
}

.auth_page .code_display {
    margin: 0.5rem 0;
    font-size: 2rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.15em;
    text-align: center;
}

.auth_page input[name="code"] {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.25em;
    text-align: center;
}

.auth_page input[name="code"]::placeholder {
    letter-spacing: normal;
}

.auth_page .page_error:empty {
    display: none;
}

.auth_page .alt {
    margin: 0.25rem 0 0;
    text-align: center;
}

.auth_page .legal_footer {
    grid-area: auto;
    width: auto;
    padding: 1rem;
}

body.legal_page {
    grid-template:
        "top" auto
        "main" minmax(0, 1fr)
        "footer" auto
        / minmax(0, 1fr);
}

.legal_header {
    grid-area: top;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.legal_header > a {
    font-weight: 600;
    text-decoration: none;
}

body.legal_page main,
body.legal_page .legal_footer {
    max-width: 48rem;
    justify-self: center;
}

body.legal_page main {
    padding-top: 3rem;
    padding-bottom: 3rem;
}

.legal_document {
    display: grid;
    gap: 1rem;
    font: var(--type-body);
}

.legal_document :where(h1, h2, h3, p, ul, ol, blockquote) {
    margin: 0;
}

.legal_document h2 {
    padding-top: 1.25rem;
    color: var(--ink);
    font: var(--type-section);
}

.legal_document h3 {
    padding-top: 0.75rem;
    color: var(--ink);
    font: var(--type-subheading);
}

.legal_document :where(ul, ol) {
    display: grid;
    gap: 0.5rem;
    padding-left: 1.5rem;
}

.legal_document blockquote {
    padding: 0.25rem 0 0.25rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-secondary);
}

@media (max-width: 700px) {
    body {
        grid-template:
            "top" auto
            "side" auto
            "main" minmax(0, 1fr)
            "footer" auto
            / minmax(0, 1fr);
    }

    #top {
        align-items: start;
    }

    .org_switcher > summary {
        max-width: 11rem;
    }

    #side {
        grid-template-rows: auto;
        grid-template-columns: max-content minmax(0, 1fr);
        padding: 0.5rem 0.75rem;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    #side > nav {
        min-width: 0;
        grid-auto-flow: column;
        grid-auto-columns: max-content;
        overflow-x: auto;
    }

    .nav_heading {
        padding: 0.5rem 0.75rem;
    }

    main {
        padding: 1.25rem 1rem;
    }

    .legal_footer {
        padding-right: 1rem;
        padding-left: 1rem;
    }

    body.legal_page main {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }
}

/* Docs: the map rendered for people. The shell owns the title and the
 * three-form strip; the rail and the operation rows are what a browser adds. */
body.docs_page main {
    max-width: 74rem;
}

.docs_lede {
    margin: 0;
}

.docs_grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
}

.docs_rail {
    display: none;
}

@media (min-width: 1100px) {
    .docs_grid {
        grid-template-columns: minmax(0, 56rem) 12rem;
    }

    .docs_rail {
        position: sticky;
        top: 1rem;
        display: grid;
        gap: 1.25rem;
        max-height: calc(100dvh - 2rem);
        padding-top: 0.5rem;
        overflow-y: auto;
        font: var(--type-caption);
        line-height: 1.25rem;
    }
}

.docs_toc {
    display: grid;
    gap: 0.25rem;
}

.docs_toc_label,
.docs_stamp {
    margin: 0;
}

.docs_toc_label {
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font: var(--type-caption);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.docs_toc a {
    padding-left: 0.5rem;
    border-left: 2px solid transparent;
    color: var(--text-muted);
    font-weight: 600;
    text-decoration: none;
}

.docs_toc a.sub {
    padding-left: 1.5rem;
    font-weight: 400;
}

.docs_toc a[aria-current="true"] {
    border-left-color: var(--ink);
    color: var(--ink);
}

.docs_stamp {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font: var(--type-caption);
}

.docs_body h2,
.docs_body h3 {
    scroll-margin-top: 1rem;
}

.docs_body .anchor {
    margin-left: 0.25rem;
    color: var(--text-disabled);
    font-weight: 400;
    text-decoration: none;
    opacity: 0;
}

.docs_body :is(h2, h3):hover .anchor,
.docs_body .anchor:focus {
    opacity: 1;
}

.docs_body pre {
    position: relative;
    padding-right: 4.5rem;
}

/* the index tables share one column grid, section to section */
.op_index th:first-child {
    width: 40%;
}

.op_index th:nth-child(2) {
    width: 9rem;
}

.op_index th:nth-child(3) {
    width: 8rem;
}

.docs_body .copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: calc(0.25rem - 1px) 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    font: var(--type-caption);
}

.docs_body .copy:hover {
    color: var(--ink);
}

.method {
    display: inline-block;
    min-width: 3.75rem;
    margin-right: 0.5rem;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    background: var(--text-secondary);
    color: var(--surface);
    font: var(--type-caption);
    font-family: var(--font-mono);
    font-weight: 600;
    text-align: center;
}

.method_get {
    background: #0f766e;
}

.method_post {
    background: #1d4ed8;
}

.method_delete {
    background: var(--danger);
}

/* long paths and contract cells wrap inside the page instead of scrolling it */
.docs_body td > code {
    white-space: normal;
    overflow-wrap: break-word;
}

.path .param {
    color: var(--text-muted);
}

.cred {
    display: inline-block;
    padding: calc(0.125rem - 1px) 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-subtle);
    color: var(--text-muted);
    font: var(--type-caption);
    white-space: nowrap;
}

.cred_none {
    border-style: dashed;
}

tr.op_row {
    cursor: pointer;
}

.op_call {
    position: relative;
    padding-left: 1.75rem;
}

.op_call::before {
    content: "";
    position: absolute;
    top: 1rem;
    left: 0.75rem;
    width: 0.375rem;
    height: 0.375rem;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: rotate(-45deg);
}

tr.op_row[aria-expanded="true"] .op_call::before {
    transform: rotate(45deg);
}

tr.op_row:hover > td,
tr.op_row[aria-expanded="true"] > td {
    background: var(--surface-subtle);
}

tr.op_row:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: -2px;
}

tr.op_detail > td {
    padding: 0;
    white-space: normal;
}

.op_detail_body {
    display: grid;
    gap: 0.75rem;
    padding: 0.75rem 1rem 1rem;
    background: var(--surface-subtle);
    font: var(--type-control);
}

.op_detail_row {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    gap: 0.75rem;
}

.op_detail_row > span:first-child {
    color: var(--text-muted);
}

.op_detail_body ul {
    display: grid;
    gap: 0.25rem;
    margin: 0;
    padding-left: 1.25rem;
}

.op_detail_body pre {
    margin: 0;
    padding: 0.75rem 4.5rem 0.75rem 1rem;
}
