/* 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, SFMono-Regular, Menlo, Consolas, 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;
}

/* a phone number is read and dialed as one unit, so a narrow screen never splits it */
a[href^="sms:"] {
    white-space: nowrap;
}

.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, textarea) {
    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,
textarea {
    min-width: 0;
    padding: calc(0.5rem - 1px) 0.75rem;
    border: 1px solid var(--border-control);
    border-radius: 4px;
    background: var(--surface);
    color: inherit;
}

::placeholder {
    color: var(--text-disabled);
    opacity: 1;
}

: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);
}

/* the button that ends something for good, red as GitHub's and Vercel's are */
.danger {
    background: var(--danger);
}

.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);
}

#crumb {
    align-items: baseline;
}

#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: var(--type-body);
    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,
#account_delete_open {
    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,
#account_delete_open:hover,
.org_link[aria-current] {
    background: var(--surface-subtle);
}

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

.org_link {
    overflow-wrap: anywhere;
}

/* the org in view carries its rename button inside its row, at the right */
.org_list > li {
    display: grid;
    align-items: center;
}

.org_list > li > * {
    grid-area: 1 / 1;
}

.org_link:has(+ .org_rename) {
    padding-right: 2.5rem;
}

.org_rename {
    justify-self: end;
    display: grid;
    margin-right: 0.375rem;
    padding: 0.375rem;
    color: var(--text-muted);
}

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

.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,
.settings h2 {
    margin: 0;
    color: var(--ink);
    font: var(--type-subheading);
}

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

.form_dialog textarea {
    resize: vertical;
}

/* a field an editor opens filled hides its placeholder, so each names
   itself above the field it wraps */
.form_dialog label {
    display: grid;
    gap: 0.25rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form_dialog label > :where(input, textarea) {
    color: var(--text);
    font-weight: 400;
}

.form_dialog p {
    margin: 0;
}

.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);
}

/* the account's one action, a menu row in the danger hue */
#account_delete_open {
    color: var(--danger);
    font: var(--type-control);
}

#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);
}

/* a failed request's id after its message: one click selects it whole, the
   button beside it copies it */
.error_id {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem;
    color: var(--text-muted);
    font: var(--type-caption);
}

.error_id code {
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
    user-select: all;
}

.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;
}

/* a section with no line yet (Models, until chat connects one) shows its
   hint under its heading, with no gap where the list would be */
.settings > .agent_list:empty {
    display: none;
}

/* a row's name never gives way to its state: a long state (an account, a
   repair) wraps instead */
.agent_list .split {
    grid-template-columns: minmax(min-content, 1fr);
    grid-auto-columns: minmax(min-content, max-content);
}

/* a group's own rows (a device's channels, a family's accounts) sit under
   its head, indented and without rules */
.agent_list .agent_list > li {
    padding: 0.5rem 0 0 1rem;
    border-bottom: 0;
}

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

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

.agent_status {
    overflow-wrap: anywhere;
    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);
}

/* the owner's notes on a device, lines as written: secondary to its name,
   a step smaller and muted, as a row's state is */
.device_notes {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
    font: var(--type-caption);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* The Voice section: each model a group that opens on its voices, a voice a
   line, its name and facets the choice's label, its Play at the end and the
   provider's description under it, set in from the choice */
.voice_form > * {
    margin: 0;
}

.voice_picker {
    min-width: 0;
    padding: 0;
    border: 0;
}

.voice_model {
    border-bottom: 1px solid var(--border);
}

.voice_model > summary {
    padding: 0.75rem 0.25rem;
    color: var(--ink);
    font-weight: 500;
    cursor: pointer;
}

.voice_model > summary > .agent_status {
    font-weight: 400;
}

.voice_model > .agent_list {
    padding: 0 0 0.5rem 1rem;
}

.voice_pick {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
    cursor: pointer;
}

.voice_pick:has(:disabled) {
    cursor: default;
}

.voice_pick > input {
    margin: 0;
    align-self: center;
}

.voice_description {
    margin: 0.25rem 0 0 1.5rem;
    color: var(--text-muted);
    font: var(--type-caption);
    overflow-wrap: anywhere;
}

/* a sample's first play waits seconds on the model saying it: a ring turns
   before its word, and holds still for a reader who asked for less motion */
.voice_play[aria-busy="true"]::before {
    content: "";
    display: inline-block;
    width: 0.625rem;
    height: 0.625rem;
    margin-right: 0.25rem;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.0625rem;
    animation: voice_spin 0.8s linear infinite;
}

@keyframes voice_spin {
    to {
        transform: rotate(1turn);
    }
}

@media (prefers-reduced-motion: reduce) {
    .voice_play[aria-busy="true"]::before {
        animation: none;
    }
}

.voice_instructions {
    display: grid;
    gap: 0.25rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.voice_instructions > textarea {
    width: 100%;
    resize: vertical;
    color: var(--text);
    font-weight: 400;
}

.voice_instructions > textarea:read-only {
    background: var(--surface-subtle);
}

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

.member_role {
    flex-wrap: nowrap;
}

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

/* a list's chat hint: a row's state size, a shade lighter, tucked under
   its list, whose last row pads it already */
.settings > p {
    margin: -0.75rem 0 0;
    padding: 0 0.25rem;
    color: var(--text-disabled);
    font: var(--type-caption);
}

/* a platform mailbox's name, joined to the domain it is created on (the
   gateway's NYLAS_AGENT_MAIL_DOMAIN, n72.io on staging and production), and
   sized to a name rather than the row, so the field reads as the address
   Create makes, as Gmail's sign-up joins a name to @gmail.com */
.mailbox_address {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
}

.mailbox_address > input {
    border-radius: 4px 0 0 4px;
}

.mailbox_address > label {
    padding: calc(0.5rem - 1px) 0.75rem;
    border: 1px solid var(--border-control);
    border-left: 0;
    border-radius: 0 4px 4px 0;
    background: var(--surface-subtle);
    color: var(--text-muted);
}

.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);
}

/* a device sign-in's code: one click selects all of it, the icon beside it
   copies it */
.agent_list code {
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0.05em;
    user-select: all;
}

.copy,
.agent_settings {
    display: grid;
    padding: 0.25rem;
    color: var(--text-muted);
    font: var(--type-caption);
}

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

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, ol, 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;
}

/* plain text, such as a graph page's schema, wraps a long line under itself;
   code keeps its lines and scrolls */
.docs_body pre.wrap {
    overflow-x: visible;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.docs_body pre.wrap .line {
    display: block;
    min-height: 1lh;
    padding-left: 2ch;
    text-indent: -2ch;
}

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

.docs_body :is(ul, ol) {
    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.
 * One rhythm: the heading block, then one 0.75rem step between the rest. */
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;
    font: var(--type-section);
}

/* an intro reads with its heading; the fields start the same step below */
.auth_page h1:has(+ .intro) {
    margin-bottom: -0.25rem;
}

.auth_page .intro {
    margin: 0 0 0.5rem;
    color: var(--text-secondary);
    font: var(--type-body);
    overflow-wrap: anywhere;
}

/* body size: the fields are read, and iOS Safari zooms into anything smaller.
 * The placeholder is the field's visible cue, quieter than what is typed */
.auth_page input {
    font: var(--type-body);
    width: 100%;
    min-height: 44px;
    border-color: var(--border);
}

.auth_page input::placeholder {
    font-size: 0.875rem;
    font-weight: 300;
}

/* the ring takes the border's place: the field darkens, it does not grow */
.auth_page input:focus-visible {
    outline-width: 1px;
    outline-offset: -1px;
}

/* Primary actions are as tall as the fields above them. */
.auth_page form > button,
.auth_page #entry_actions > button {
    padding: 0.625rem 0.75rem;
    font-weight: 500;
    min-height: 44px;
}

.auth_page #entry_actions {
    display: grid;
}

.auth_page #entry_actions.auth_signup_actions {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.auth_page #entry_actions > button:disabled {
    opacity: 1;
    color: var(--text-disabled);
}

.auth_page :is(.consent_line, .hint) {
    margin: 0;
    color: var(--text-muted);
    font: var(--type-caption);
}

/* the fine print recedes; its two links stay findable */
.auth_page .consent_line {
    color: var(--text-disabled);
    font-size: 0.6875rem;
}

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

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

.auth_page .auth_entry_links a {
    display: inline-block;
    padding-block: 0.25rem;
    text-underline-offset: 2px;
}

.auth_page .hint {
    overflow-wrap: anywhere;
}

.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 :is(.page_error, .page_status):empty {
    display: none;
}

/* the way out of each card: quiet text actions, aligned with the rest */
.auth_page .alt {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
}

.auth_page .alt > :is(button, a) {
    padding: 0.5rem 0;
    min-height: 44px;
    background: none;
    color: var(--ink);
    font-weight: 500;
    text-decoration: none;
}

.auth_page .alt > :is(button, a):hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth_page .auth_actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1rem;
}

@media (max-width: 400px) {
    .auth_page > form {
        padding: 1.25rem;
    }
}

.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);
}

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;
}

/* a section's heading, its Add at the end, in line with its rows' actions */
.settings_head {
    padding-right: 0.25rem;
}

/* the settings page's one popup, a section's Add: its choices, the own
   address's name, or the sentence on an app the agent does not run. A card
   under the button that opened it, right edges aligned, flipped above near
   the viewport's end, as a menu sits under its button. Without anchor
   positioning the browser centres it, which still reads. A layout class
   never goes on the popup, nor on what it shows and hides: its display would
   show it hidden */
.app_popover {
    min-width: min(16rem, calc(100vw - 2rem));
    max-width: min(24rem, calc(100vw - 2rem));
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 4px 16px rgba(28, 25, 23, 0.08);
    font: var(--type-control);
}

.app_popover > * {
    margin: 0;
}

/* a small text action inside a sentence (the popup's Install now) reads at
   the sentence's size, flush with its words */
.app_popover .agent_toggle {
    padding: 0;
    font: inherit;
}

.app_popover > * + * {
    margin-top: 0.5rem;
}

/* an Add's choices: a menu, a choice a line, what it binds muted at its end */
.add_choices {
    padding: 0;
    list-style: none;
}

.add_choices button {
    width: 100%;
    padding: 0.375rem 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
}

.add_choices button:hover > :first-child {
    text-decoration: underline;
}

/* the own address, made rather than signed into, set off below the sign-ins */
.add_choices:not([hidden]) + .add_own {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.add_own > .cluster,
.add_install > p + p {
    margin-top: 0.5rem;
}

.add_install > p {
    margin: 0;
}

@supports (position-area: bottom) {
    .app_popover {
        inset: auto;
        margin: 0.25rem 0;
        position-area: bottom span-left;
        position-try-fallbacks: flip-block;
    }
}
