/* Theme tokens. The palette follows the OS preference and nothing else:
   light values on :root, dark values under prefers-color-scheme. */
:root {
    color-scheme: light dark;

    --bg: #f4f5f7;
    --surface: #ffffff;
    --line: #e2e5ea;
    --line-strong: #cdd2da;
    --text: #1c2128;
    --text-dim: #5b6472;
    --accent: #2563eb;
    --accent-soft: #e8effd;
    --on-accent: #ffffff;
    --ok: #1a7f37;
    --ok-soft: #e6f4ea;
    --warn: #8f6000;
    --warn-soft: #fff4d6;
    --bad: #c62828;
    --bad-soft: #fdecea;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --mark-filter: none;

    /* One column: header, content and footer share its edges. */
    --col: 60rem;
    --gut: 1rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --surface: #171a20;
        --line: #272b33;
        --line-strong: #3a4049;
        --text: #e6e9ee;
        --text-dim: #98a1ad;
        --accent: #6ea8fe;
        --accent-soft: #1c2a45;
        --on-accent: #0f1115;
        --ok: #4ac26b;
        --ok-soft: #152a1c;
        --warn: #d9a441;
        --warn-soft: #2b2413;
        --bad: #f28b82;
        --bad-soft: #33161a;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
        --mark-filter: invert(1); /* logo.svg is black ink — flip it on dark */
    }
}

html,
body {
    height: 100%;
    font-size: 20px;
    margin: 0px;
    box-sizing: border-box;
}

body {
    display: grid;
    grid-template-rows: auto 1fr auto;
    background-color: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

body>nav,
body>main,
body>footer {
    padding-inline: max(var(--gut), calc((100% - var(--col)) / 2));
}

body>nav {
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.35rem 1.25rem;
    min-height: 3rem;
    padding-block: 0.4rem;
}

nav>.brand,
nav>.controls {
    display: flex;
    align-items: center;
    min-width: 0;
}

nav>.brand {
    gap: 0.75rem;
}

nav>.controls {
    gap: 1rem;
    min-width: 0;
}

/* The name is never cut short: it is what tells you which machine you are on,
   so the header grows and wraps rather than truncating it. */
.page-title {
    margin: 0;
    min-width: 0;
    flex: 0 1 auto;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

nav a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.9rem;
}

nav a:hover {
    color: var(--text);
}

nav>.brand>a {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    height: 3rem;
    color: var(--text);
}

nav>.brand img {
    height: 2rem;
    filter: var(--mark-filter);
}

nav>.controls button {
    font: inherit;
    font-size: 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background-color: var(--surface);
    color: var(--text);
    padding: 0.3rem 0.75rem;
    cursor: pointer;
}

nav>.controls button:hover {
    border-color: var(--text-dim);
}

main {
    padding-block: var(--gut);
    overflow-wrap: anywhere;
}

footer {
    background-color: var(--surface);
    border-top: 1px solid var(--line);
    color: var(--text-dim);
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    min-height: 3rem;
}

main.pageOut {
    animation-duration: 200ms;
    animation-name: fadeOut;
}

main.pageIn {
    animation-duration: 200ms;
    animation-name: fadeIn;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Home: the index of public apps — a plain list, no pitch. */
.home h1 {
    font-size: 1.25rem;
    margin: 0 0 1rem;
}

.home .apps {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background-color: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.home .apps li+li {
    border-top: 1px solid var(--line);
}

.home .apps a {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 1rem;
    row-gap: 0.2rem;
    align-items: center;
    padding: 1rem 1.25rem;
    text-decoration: none;
    color: var(--text);
}

.home .apps a:hover {
    background-color: var(--accent-soft);
}

.home .apps .name,
.home .apps .desc {
    min-width: 0;
    overflow-wrap: anywhere;
}

.home .apps .name {
    grid-column: 1;
    grid-row: 1;
    font-weight: 650;
}

.home .apps .desc {
    grid-column: 1;
    grid-row: 2;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.home .apps .arr {
    grid-column: 2;
    grid-row: 1 / span 2;
    justify-self: center;
    align-self: center;
    color: var(--text-dim);
}

.snacks {
    position: fixed;
    right: max(var(--gut), calc((100% - var(--col)) / 2));
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    width: min(24rem, calc(100% - 2 * var(--gut)));
    max-height: calc(100dvh - 7rem - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.75rem;
    z-index: 20;
    transition: bottom 0.3s;
}

.snacks.closed {
    bottom: -20rem;
}

.snacks .toast {
    display: grid;
    grid-template-columns: 1.5rem minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: start;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 0.9rem 1rem;
}

.snacks .status {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: 0.85rem;
    font-weight: 700;
    background-color: var(--accent);
    color: var(--on-accent);
}

.snacks .status.ok {
    background-color: var(--ok);
}

.snacks .status.quiet {
    background-color: var(--line-strong);
    color: var(--text);
}

.snacks .toast-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 650;
    color: var(--text);
}

.snacks .toast-body {
    margin: 0.2rem 0 0;
    font-size: 0.85rem;
    color: var(--text-dim);
    overflow-wrap: anywhere;
}

.snacks .toast-body a {
    color: var(--accent);
}

.snacks .toast-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin-top: 0.5rem;
}

.snacks button {
    font: inherit;
    font-size: 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background-color: var(--surface);
    color: var(--text);
    padding: 0.4rem 0.8rem;
    cursor: pointer;
}

.snacks button:hover {
    border-color: var(--text-dim);
}

.snacks button.primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 650;
}

.snacks button.primary:hover {
    opacity: 0.9;
}

.snacks .toast-close {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-color: transparent;
    background-color: transparent;
    color: var(--text-dim);
    font-size: 1.1rem;
    line-height: 1;
}

.snacks .toast-close:hover {
    background-color: var(--bg);
    color: var(--text);
}

.attention {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.attention-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
    color: var(--text-dim);
    margin: 0 0 0.5rem;
}

.attention .alert {
    display: grid;
    grid-template-columns: 0.3rem 1fr auto;
    gap: 0.75rem;
    align-items: center;
    min-width: 0;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.6rem 0.75rem 0.6rem 0;
}

.attention .alert .stripe {
    align-self: stretch;
    border-radius: 0 3px 3px 0;
    background: currentColor;
}

.attention .alert p {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text);
}

.attention .alert.warn {
    color: var(--warn);
    background-color: var(--warn-soft);
}

.attention .alert.bad {
    color: var(--bad);
    background-color: var(--bad-soft);
}

.pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.attention .pill.warn {
    color: var(--warn);
    background-color: var(--warn-soft);
}

.attention .pill.bad {
    color: var(--bad);
    background-color: var(--bad-soft);
}

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

.attention .stale {
    padding: 0.75rem;
    border: 1px dashed var(--bad);
    border-radius: 8px;
    color: var(--bad);
}

.hosts {
    display: grid;
    gap: 0.6rem;
    margin: 0 0 1.25rem;
}

.hosts a {
    display: grid;
    grid-template-columns: minmax(8rem, 16rem) minmax(0, 1fr) auto;
    grid-template-areas: "head stats arr";
    column-gap: 1.25rem;
    row-gap: 0.75rem;
    align-items: center;
    min-width: 0;
    overflow-wrap: anywhere;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 0.85rem 1rem;
    color: var(--text);
    text-decoration: none;
}

.hosts a:hover {
    border-color: var(--line-strong);
}

.hosts a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.hosts a .host-head {
    grid-area: head;
}

.hosts a .host-note,
.hosts a .host-stats {
    grid-area: stats;
}

.hosts a .host-arr {
    grid-area: arr;
}

.host-head {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.host-name {
    font-size: 1.1rem;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.host-note {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.host-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.25rem 1rem;
    min-width: 0;
}

.host-stat {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.host-stat-label {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--text-dim);
}

.host-stat-value {
    font-size: 1rem;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.host-meter {
    display: block;
    height: 0.2rem;
    margin-top: 0.15rem;
    border-radius: 999px;
    background-color: var(--line);
    overflow: hidden;
}

.host-meter-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background-color: var(--accent);
}

.host-arr {
    color: var(--text-dim);
    font-size: 0.95rem;
}

@media (max-width: 48rem) {
    .hosts a {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "head arr"
            "stats stats";
    }
}

@media (max-width: 30rem) {
    .host-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem 1rem;
    }
}

.host-line {
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
    color: var(--text-dim);
}

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

.live {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin: 0 0 1rem;
}

.live .dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background-color: var(--ok);
}

.not-answering {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
    margin: 0 0 1.25rem;
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text);
}

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

.hostpage > .col {
    display: grid;
    gap: 1rem;
    min-width: 0;
}

@media (min-width: 900px) {
    .hostpage {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.hostpage .host {
    display: grid;
    gap: 0.75rem;
    min-width: 0;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1rem;
}

.hostpage .label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
    color: var(--text-dim);
}

.hostpage .host-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1.25rem;
}

.hostpage .host-stat-value {
    font-variant-numeric: tabular-nums;
}

.host-stat-detail {
    font-size: 0.72rem;
    color: var(--text-dim);
    overflow-wrap: anywhere;
}

.hostpage .live {
    margin: 0;
    font-size: 0.8rem;
}

@media (max-width: 30rem) {
    .hostpage .host-stats {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
    }
}

.hostpage .gauge {
    margin: 0;
    font-size: 0.92rem;
    color: var(--text);
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
}

.hostpage .mount {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.hostpage .mount .row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.hostpage .mount .mountpoint {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.hostpage .mount .usage {
    color: var(--text-dim);
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
}

.hostpage .bar {
    height: 0.5rem;
    border-radius: 999px;
    background-color: var(--line);
    overflow: hidden;
}

.hostpage .bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background-color: var(--ok);
}

.hostpage .bar.warn i {
    background-color: var(--warn);
}

.hostpage .bar.bad i {
    background-color: var(--bad);
}

.hostpage .operation {
    display: grid;
    gap: 0.35rem;
}

.hostpage .operation button {
    justify-self: start;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--on-accent);
    background-color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    cursor: pointer;
}

.hostpage .operation button:hover {
    opacity: 0.9;
}

.hostpage .operation .detail {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-dim);
    overflow-wrap: anywhere;
}

.hostpage .result {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text);
    overflow-wrap: anywhere;
}

.hostpage .result.ok {
    color: var(--ok);
}

.hostpage .result.bad {
    color: var(--bad);
}

.hostpage .notice {
    margin: 0;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.hostpage .notice.bad {
    color: var(--bad);
}

.hostpage .pill {
    justify-self: start;
    color: var(--bad);
    background-color: var(--bad-soft);
}

.hostpage .none {
    margin: 0;
    font-size: 0.92rem;
    color: var(--text-dim);
}

.hostpage .units {
    margin: 0;
    padding: 0;
    list-style: none;
    min-width: 0;
    font-size: 0.92rem;
    line-height: 1.4;
    color: var(--text);
    overflow-wrap: anywhere;
    max-height: 11em;
    overflow-y: auto;
}

.hostpage .system {
    display: grid;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
    list-style: none;
    min-width: 0;
}

.hostpage .system li {
    display: grid;
    grid-template-columns: 1rem minmax(0, 1fr);
    gap: 0.6rem;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text);
}

.hostpage .system-text {
    overflow-wrap: anywhere;
}

.hostpage .system-icon {
    width: 1rem;
    height: 1rem;
    background-color: var(--text-dim);
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

.hostpage .system-icon-cpu {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Crect x=%225%22 y=%225%22 width=%2214%22 height=%2214%22 rx=%222%22/%3E%3Cpath d=%22M9 1v4M15 1v4M9 19v4M15 19v4M1 9h4M1 15h4M19 9h4M19 15h4%22/%3E%3C/svg%3E");
}

.hostpage .system-icon-gpu {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Crect x=%222%22 y=%224%22 width=%2220%22 height=%2213%22 rx=%222%22/%3E%3Cpath d=%22M8 21h8M12 17v4%22/%3E%3C/svg%3E");
}

.hostpage .system-icon-os {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M21 8l-9-5-9 5v8l9 5 9-5z%22/%3E%3Cpath d=%22M3 8l9 5 9-5M12 13v8%22/%3E%3C/svg%3E");
}

.hostpage .system-icon-kernel {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Crect x=%223%22 y=%223%22 width=%2213%22 height=%2213%22 rx=%222%22/%3E%3Crect x=%228%22 y=%228%22 width=%2213%22 height=%2213%22 rx=%222%22/%3E%3C/svg%3E");
}

.hostpage .system-icon-machine {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Crect x=%222%22 y=%223%22 width=%2220%22 height=%227%22 rx=%222%22/%3E%3Crect x=%222%22 y=%2214%22 width=%2220%22 height=%227%22 rx=%222%22/%3E%3Cpath d=%22M6 6.5h.01M6 17.5h.01%22/%3E%3C/svg%3E");
}

.hostpage .system-icon-installed {
    --icon: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Ccircle cx=%2212%22 cy=%2212%22 r=%229%22/%3E%3Cpath d=%22M12 7v5l3 2%22/%3E%3C/svg%3E");
}

.hostpage .operation button:disabled {
    color: var(--text-dim);
    background-color: var(--line);
    border-color: var(--line-strong);
    cursor: not-allowed;
}

.hostpage .operation button:disabled:hover {
    opacity: 1;
}

.pi-host {
    margin: 0 0 1.25rem;
}

.hosts a .state {
    grid-area: stats;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.state .dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background-color: var(--ok);
}

.state .dot.idle {
    background-color: var(--text-dim);
}

.state .dot.waiting {
    background-color: var(--warn);
}

.hosts a.offline {
    opacity: 0.6;
}

body:has(> main.chat) {
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
}

body:has(> main.chat) > footer {
    display: none;
}

body:has(> main.chat) > .snacks {
    bottom: calc(7rem + env(safe-area-inset-bottom, 0px));
}

main.chat {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    padding-block: 0;
}

.chat .feed {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 0;
    padding-block: var(--gut);
    overflow-y: auto;
    overscroll-behavior: contain;
    overflow-anchor: none;
}

.chat .feed > :first-child {
    margin-top: auto;
}

.chat .bubble {
    max-width: 85%;
    padding: 0.5rem 0.8rem;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.chat .bubble.me {
    align-self: flex-end;
    background-color: var(--accent);
    color: var(--on-accent);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.chat .bubble.pi {
    align-self: flex-start;
    background-color: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-bottom-left-radius: 4px;
}

.chat .caret::after {
    content: "▍";
    color: var(--accent);
}

.chat .bubble.pi > :first-child {
    margin-top: 0;
}

.chat .bubble.pi > :last-child {
    margin-bottom: 0;
}

.chat .bubble.pi p {
    margin: 0.4em 0;
}

.chat .bubble.pi h1,
.chat .bubble.pi h2,
.chat .bubble.pi h3,
.chat .bubble.pi h4,
.chat .bubble.pi h5,
.chat .bubble.pi h6 {
    margin: 0.6em 0 0.3em;
    font-size: 0.95rem;
    line-height: 1.3;
}

.chat .bubble.pi ul,
.chat .bubble.pi ol {
    margin: 0.4em 0;
    padding-left: 1.2em;
}

.chat .bubble.pi li {
    margin: 0.15em 0;
}

.chat .bubble.pi blockquote {
    margin: 0.4em 0;
    padding-left: 0.6em;
    border-left: 2px solid var(--line-strong);
    color: var(--text-dim);
}

/* What pi thinks out loud is full of things with no space to break at: a URL
   with a token in it, a command line in a fenced block. A fenced block keeps
   `white-space: pre` and wraps nowhere, and nothing inside a thinking block was
   kept inside it, so one long line widened the whole conversation and gave a
   phone a sideways scroll bar (lmnt5/apex#110). A fenced block is therefore a
   scroll box of its own: one rule for both markdown bodies, each body writing
   only its spacing under it. The other block that cannot wrap — a table too
   wide for the phone — gets the same treatment, down with the table rules. The
   running text already broke anywhere and is left as it was. */
.chat .bubble.pi pre,
.chat .think-body pre {
    border-radius: 6px;
    background-color: var(--bg);
    overflow-x: auto;
}

.chat .bubble.pi pre {
    margin: 0.5em 0;
    padding: 0.5em 0.6em;
}

.chat .think-body pre {
    margin: 0.4em 0;
    padding: 0.4em 0.5em;
}

/* Both markdown bodies — the answer bubble and the thinking bubble — render the
   same blocks and draw them the same way, so they share these selectors rather
   than carrying two copies (lmnt5/apex#110). */
.chat .bubble.pi code,
.chat .think-body code {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.8em;
}

.chat .bubble.pi pre code,
.chat .think-body pre code {
    font-size: 0.85em;
    line-height: 1.4;
}

.chat .bubble.pi :not(pre) > code,
.chat .think-body :not(pre) > code {
    padding: 0.1em 0.3em;
    border-radius: 4px;
    background-color: var(--bg);
}

.chat .bubble.pi a {
    color: inherit;
    text-decoration: underline;
}

.chat .bubble.pi hr {
    margin: 0.6em 0;
    border: 0;
    border-top: 1px solid var(--line);
}

.chat .bubble.pi table,
.chat .think-body table {
    border-collapse: collapse;
    font-size: 0.75rem;
}

.chat .bubble.pi table {
    margin: 0.5em 0;
}

/* A table is the other block with no room to wrap, so a thinking table scrolls
   inside the bubble instead of widening the conversation (lmnt5/apex#110). The
   answer's table is drawn exactly as it was before this issue — only its own
   margin is written here. */
.chat .think-body table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.chat .bubble.pi th,
.chat .bubble.pi td,
.chat .think-body th,
.chat .think-body td {
    padding: 0.2em 0.5em;
    border: 1px solid var(--line);
    text-align: left;
}

.chat .think-body p {
    margin: 0.35em 0;
}

.chat details.think,
.chat details.tool {
    align-self: flex-start;
    max-width: 85%;
    min-width: 0;
    font-size: 0.75rem;
    border-radius: 8px;
}

.chat details.think {
    color: var(--text-dim);
    background-color: var(--accent-soft);
    padding: 0.25rem 0.6rem;
}

.chat details.think > * {
    overflow-wrap: anywhere;
}

.chat details.tool {
    background-color: var(--surface);
    border: 1px solid var(--line);
}

.chat details summary {
    cursor: pointer;
}

.chat details.tool summary {
    padding: 0.25rem 0.6rem;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat details.tool pre {
    margin: 0;
    padding: 0.4rem 0.6rem;
    border-top: 1px solid var(--line);
    font-size: 0.7rem;
    max-height: 10rem;
    overflow: auto;
    white-space: pre-wrap;
}

.chat details.tool pre.bad {
    color: var(--bad);
}

.chat .typing {
    align-self: flex-start;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.chat .notice {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.6rem 0.85rem;
    font-size: 0.8rem;
}

.chat .notice.warn {
    border-color: var(--warn);
    background-color: var(--warn-soft);
}

.chat .notice.bad {
    border-color: var(--bad);
    background-color: var(--bad-soft);
}

.chat .commands {
    margin-bottom: 0.35rem;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat .commands-list {
    display: grid;
    gap: 0.1rem;
    max-height: 11rem;
    overflow-y: auto;
    padding: 0.25rem;
}

.chat .command {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.6rem;
    align-items: baseline;
    width: 100%;
    text-align: left;
    font: inherit;
    font-size: 0.72rem;
    line-height: 1.35;
    color: var(--text);
    background: none;
    border: 0;
    border-radius: 8px;
    padding: 0.3rem 0.45rem;
    cursor: pointer;
}

.chat .command.on {
    background-color: var(--accent-soft);
}

.chat .command-name {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 650;
}

.chat .command-line {
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat .composer {
    padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom, 0px));
    background-color: var(--bg);
}

.chat .box {
    display: grid;
    gap: 0.35rem;
    background-color: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    padding: 0.45rem 0.45rem 0.45rem 0.8rem;
    box-shadow: var(--shadow);
}

.chat .box:focus-within {
    border-color: var(--accent);
}

.chat .box textarea {
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: transparent;
    border: 0;
    outline: 0;
    resize: none;
    padding: 0.2rem 0;
    min-height: 1.4rem;
    max-height: 7rem;
    overflow-y: auto;
    field-sizing: content;
}

.chat .box .row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

.chat .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    min-width: 0;
    position: relative;
    font-size: 0.68rem;
    line-height: 1.2;
    color: var(--text-dim);
    background-color: var(--bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    cursor: pointer;
}

.chat .chip:hover {
    border-color: var(--line-strong);
    color: var(--text);
}

.chat .chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat .chip.model {
    flex: 0 1 auto;
}

.chat .chip.thinking {
    flex: none;
}

.chat .chip i {
    font-style: normal;
    font-size: 0.6rem;
}

.chat .chip select {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    font-size: 16px;
}

.chat .chip.off {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat .send {
    margin-left: auto;
    flex: none;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    border: 0;
    display: grid;
    place-items: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--on-accent);
    background-color: var(--accent);
    cursor: pointer;
}

.chat .send:hover {
    opacity: 0.9;
}

.chat .send.stop {
    background-color: var(--text);
    color: var(--surface);
}

.chat .send.stop::before {
    content: "";
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 2px;
    background-color: currentColor;
}

.chat .send:disabled,
.chat .box textarea:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
