/* The chat, shared by the Agents view and quick chat: the agent's
   settings beside it, the messages and their cards, Markdown in a body,
   the composer with its attachments, round button, @ picker, and model
   chip, and the working dot. */
@layer views {
  /* The chat, and beside it the agent's settings when they are open. */
  .chat-panel {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
  }

  .chat-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
  }

  /* On a desk the agent's settings slide in from the right (agents.js adds
     is-open once the aside is drawn closed, and hides it when the exit
     ends); the chat gives up the width with the same timing, so its
     messages reflow with the pane. The panel clips only while the aside
     moves, so the composer's pickers are never cut off at its edges. */
  @media (min-width: 720px) {
    .chat-panel:has(> .chat-details.panel-sliding) { overflow: hidden; }
    .chat-panel > .chat-details {
      margin-right: -340px;
      opacity: 0;
      transform: translateX(24px);
      transition: margin-right 200ms ease-out, opacity 200ms ease-out, transform 200ms ease-out;
    }
    .chat-panel > .chat-details.is-open {
      margin-right: 0;
      opacity: 1;
      transform: none;
    }
    .chat-panel > .chat-details.panel-closing { pointer-events: none; }
    /* With the pane open the stage's bell and menu float over the pane, not
       the chat, so the header clears only the panel toggle and the pill
       keeps room for the name in a narrow column. */
    .chat-panel:has(> .chat-details.is-open) > .chat-floating > .chat-header {
      padding-left: 56px;
      padding-right: 56px;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    .chat-panel > .chat-details { transition: none; }
  }

  /* The 96px foot lets the last control scroll clear of quick chat's button. */
  .chat-details {
    flex: 0 0 340px;
    min-height: 0;
    padding: var(--controls-h) 20px 96px;
    overflow: auto;
    overscroll-behavior: contain;
    border-left: 1px solid var(--line);
    background: var(--surface-column);
  }

  /* The pane's head: the avatar, the name (a button that renames it in
     place), the runtime it runs on, and the chevron that closes it. */
  .pane-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
  }
  .pane-avatar { display: flex; flex: none; }
  .pane-avatar .avatar { width: 40px; height: 40px; font-size: 15px; }
  .pane-head-text { flex: 1; min-width: 0; }
  .pane-head > .icon-button { flex: none; align-self: flex-start; }

  .details-name {
    margin: 0;
    font-family: var(--serif);
    font-size: 22px;
    font-weight: 400;
    line-height: 1.2;
  }
  .pane-name {
    max-width: 100%;
    padding: 2px 6px;
    margin: 0 -6px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--ink);
    font: inherit;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: text;
  }
  @media (hover: hover) {
    .pane-name:hover { background: var(--hover-tint); }
  }
  .pane-name-input { width: 100%; font-size: 16px; }
  .pane-runtime { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
  .pane-runtime[hidden] { display: none; }
  .pane-refusal { margin: -4px 0 12px; }

  /* The tabs under the head, and their panels. */
  /* The four icon tabs share the sheet's width evenly, down to a 320px phone. */
  .chat-details > .pane-tabs { margin: 0 -20px 16px; padding: 0 8px; --pane-tab-gap: 0; --pane-tab-padding: 8px; }
  .chat-details > #agent-pane-tabs.pane-tabs { margin: 0 0 16px; padding: 0; }
  .pane-panel[hidden] { display: none; }
  .pane-panel > .details-routines:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

  /* The agent's settings as a form (an agent), one field per row. Save is
     off until a field changed; the validator's problems list under it. */
  .details-form {
    display: grid;
    gap: 12px;
  }

  /* Three columns on a desk, the outer two sharing what is left, so the
     pill stays centered whatever the controls beside it. This is quick
     chat's bar; the Agents view's row floats (.chat-floating, below). */
  .chat-header {
    display: grid;
    grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr);
    align-items: center;
    gap: 8px 12px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
  }
  .chat-header > .chat-back { grid-column: 1; }
  .chat-header > .chat-title { grid-column: 2; }

  /* The way back to the list, a phone's only, while the To field shows. */
  .chat-back { display: none; }

  .chat-avatar { display: inline-flex; }
  .chat-avatar[hidden] { display: none; }

  /* The chips (the provider's 16px icon) hang off the pill's right side so
     they do not pull it off center; the title reserves their width and gap
     on both sides, so a long name ends in an ellipsis before the icon can
     reach New chat. */
  .chat-title {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 0 24px;
  }

  /* The agent's avatar and name on a raised pill, the composer box's
     surface. The border is a ring in the shadow, so the name is the pill's
     full 36px. The name's chevron shows on hover, focus, and while the
     settings are open. */
  .chat-pill {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    min-width: 0;
    max-width: 100%;
    height: 36px;
    border-radius: 999px;
    background: var(--paper);
    box-shadow: 0 0 0 1px var(--line), 0 2px 10px var(--shadow-pop);
    color: var(--ink);
  }
  .chat-pill-name {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 36px;
    padding: 0 14px 0 6px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: inherit;
    font: inherit;
    transition: background-color 120ms ease;
  }
  .chat-pill-name:has(> .chat-avatar[hidden]) { padding-left: 14px; }
  button.chat-pill-name:not(:disabled) { cursor: pointer; }
  @media (hover: hover) {
    button.chat-pill-name:not(:disabled):hover { background: color-mix(in srgb, var(--ink) 4%, var(--paper)); }
  }
  button.chat-pill-name[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 6%, var(--paper)); }

  .chat-name {
    overflow: hidden;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-pill-chevron {
    flex: none;
    width: 14px;
    margin: 0 -6px 0 -4px;
    color: var(--muted);
    opacity: 0;
    transition: opacity 120ms ease;
  }
  @media (hover: hover) {
    button.chat-pill-name:not(:disabled):hover .chat-pill-chevron { opacity: 1; }
  }
  button.chat-pill-name:focus-visible .chat-pill-chevron,
  button.chat-pill-name[aria-expanded="true"] .chat-pill-chevron { opacity: 1; }
  button.chat-pill-name:disabled .chat-pill-chevron { display: none; }

  @media (prefers-reduced-motion: reduce) {
    .chat-pill-name,
    .chat-pill-chevron { transition: none; }
  }

  .chat-chips {
    display: inline-flex;
    gap: 4px 8px;
  }
  .chat-chips:empty { display: none; }

  /* The Agents view's chat has no bar: the header is a row floating over
     the top of the messages, which scroll under it, and only its controls
     take the pointer. The row stops short of the scroller's scrollbar
     (chat-view.js measures it), and so does the fade: the column's paper
     to clear over the scroller's top, under the row. The messages start
     below the row; a title line, description, or notice above them starts
     below it too, and then the messages keep their own top and the fade
     only softens their edge. The column is its own stacking context, so the
     settings sheet still covers the row on a phone. */
  .chat-floating {
    --chat-row: 60px;
    --chat-fade: 56px;
    position: relative;
    isolation: isolate;
  }
  .chat-floating > .chat-header {
    position: absolute;
    top: 0;
    left: 0;
    right: var(--chat-scrollbar, 0px);
    z-index: 3;
    border-bottom: 0;
    background: none;
    pointer-events: none;
    /* Clear of the floating controls at both ends, so the pill stays
       centered between them. */
    padding-left: 112px;
    padding-right: 112px;
  }
  .chat-floating .chat-title { pointer-events: none; }
  .chat-floating .chat-back,
  .chat-floating .chat-pill { pointer-events: auto; }
  .chat-floating > .chat-messages {
    padding-top: calc(var(--chat-row) + 12px);
    scroll-padding-top: var(--chat-row);
  }
  .chat-floating > .chat-subtitle,
  .chat-floating > .chat-description,
  .chat-floating > .chat-notice { margin-top: var(--chat-row); }
  .chat-floating > .chat-subtitle:not([hidden]) ~ .chat-description,
  .chat-floating > .chat-subtitle:not([hidden]) ~ .chat-notice,
  .chat-floating > .chat-description:not([hidden]) ~ .chat-notice { margin-top: 0; }
  .chat-floating:has(> .chat-subtitle:not([hidden]), > .chat-description:not([hidden]), > .chat-notice:not([hidden])) {
    --chat-fade: 16px;
  }
  .chat-floating:has(> .chat-subtitle:not([hidden]), > .chat-description:not([hidden]), > .chat-notice:not([hidden])) > .chat-messages {
    padding-top: 16px;
    scroll-padding-top: 0;
  }
  .chat-fade {
    position: relative;
    z-index: 2;
    flex: none;
    height: 0;
    pointer-events: none;
  }
  .chat-fade::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: var(--chat-scrollbar, 0px);
    height: var(--chat-fade);
    background: linear-gradient(to bottom, var(--surface-column) 10%, color-mix(in srgb, var(--surface-column) 0%, transparent));
  }
  /* New chat's To field (chat-view.js to()): the column holds only a
     row at its top naming who the chat is with, a refusal under it, and
     the agents to choose from on a card, in the @ picker's rows. */
  .chat-composing > .chat-messages,
  .chat-composing > .chat-fade,
  .chat-composing .chat-title { display: none; }
  .chat-to {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    padding: 0 max(24px, calc((100% - 772px) / 2)) 24px;
  }
  /* In the Agents view the To row sits under the floating controls. */
  .chat-floating > .chat-to { margin-top: var(--controls-h); }
  .chat-to-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--chat-row, 60px);
    border-bottom: 1px solid var(--line);
  }
  .chat-to-row:focus-within { border-bottom-color: var(--green); }
  .chat-to-label { flex: none; color: var(--muted); }
  .chat-to-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 0;
    border: 0;
    outline: none;
    background: none;
    color: var(--ink);
    font: inherit;
    font-size: var(--field-font);
  }
  .chat-to-refusal {
    margin: 8px 0 0;
    color: var(--red);
    font-size: 13px;
  }
  .chat-to-menu {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    min-height: 0;
    margin-top: 12px;
    overflow: auto;
  }
  .chat-to-list {
    display: flex;
    flex-direction: column;
  }
  .chat-to-none {
    margin: 0;
    padding: 10px;
    color: var(--muted);
  }
  .chat-to-new-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--side);
    color: var(--muted);
  }

  .chat-description {
    margin: 0;
    padding: 16px 24px;
    color: var(--muted);
  }

  /* An archived chat: "This chat is archived." under the pill, and
     Unarchive. */
  .chat-subtitle {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 12px;
    margin: 0;
    padding: 6px 24px 0;
    color: var(--muted);
    font-size: 0.875rem;
  }

  .chat-subtitle[hidden] {
    display: none;
  }

  .chat-notice {
    margin: 0;
    padding: 10px 24px;
    background: var(--red-bg);
    color: var(--red);
    border-bottom: 1px solid var(--line);
  }

  /* The message column and, below, the composer row share one centered
     column (ChatGPT- and Claude-style), capped at 820px and full width
     below that. The chat header stays full width above them. The
     messages scroll in the pane's full width, so the scrollbar sits at
     the pane's right edge; the padding centers the column inside it (820px
     less the 24px gutters, the composer box's width). */
  .chat-messages {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    width: 100%;
    padding: 16px max(24px, (100% - 772px) / 2);
    overflow: auto;
    overscroll-behavior: contain;
  }
  /* The messages take the keyboard's focus, so Page Down and the arrows
     scroll them with no scroll bar to grab; the ring sits on their inside
     edge. */
  .chat-messages:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
  }

  /* Thin, quiet scrollbars on the chat and its input. */
  .chat-messages,
  .composer-box .composer-input {
    scrollbar-width: thin;
    scrollbar-color: var(--rule) transparent;
  }

  .chat-pages {
    display: flex;
    gap: 16px;
  }

  .chat-line {
    margin: 0;
    color: var(--muted);
  }

  .chat-message {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: min(44em, 100%);
  }
  .chat-message-user {
    align-self: flex-end;
    align-items: flex-end;
  }
  .created-undo { margin-left: 10px; font-size: inherit; }
  .created-refusal { display: block; margin-top: 4px; color: var(--red); }

  .chat-message-system {
    align-self: center;
    align-items: center;
  }

  .chat-message-text {
    min-width: 0;
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  .chat-message-user .chat-message-text {
    background: var(--bubble-user);
    color: var(--bubble-user-ink);
  }
  .chat-message-user .markdown a { color: var(--bubble-user-link); }
  .chat-message-user .markdown code,
  .chat-message-user .markdown pre { background: var(--bubble-user-code); }
  .chat-message-user .markdown pre code { background: none; }
  .chat-message-user .markdown pre { border-color: var(--bubble-user-code); }
  .chat-message-user .markdown .md-table :is(th, td) { border-color: var(--bubble-user-code); }
  .chat-message-user .markdown blockquote {
    border-left-color: var(--bubble-user-code);
    color: var(--bubble-user-ink);
  }
  .chat-message-assistant .chat-message-text {
    background: var(--bubble-assistant);
    border: 1px solid var(--bubble-assistant-border);
  }
  .chat-message-system .chat-message-text {
    padding: 2px 0;
    color: var(--muted);
    font-size: 13px;
  }

  /* The message a notification opened the chat at: the Feed's mark for
     a post it opened at (.feed-item[data-feed-target]), fading over 1.5 s
     (chat-view.js MARK_MS), and held without the fade under reduced
     motion until it is taken off. */
  .chat-message[data-message-mark] {
    border-radius: 4px;
    background: var(--green-bg);
    box-shadow: 0 0 0 8px var(--green-bg);
    animation: chat-message-mark 1.5s ease-in forwards;
  }
  @keyframes chat-message-mark {
    to { background: transparent; box-shadow: 0 0 0 8px transparent; }
  }
  @media (prefers-reduced-motion: reduce) {
    .chat-message[data-message-mark] { animation: none; }
  }

  /* A settled question: one centered row per question, the answer with a
     check, or why none came in muted text. */
  .chat-question {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 2px 8px;
    padding: 2px 0;
    font-size: 13px;
    color: var(--muted);
    overflow-wrap: anywhere;
  }
  .chat-question .request-chip { align-self: center; }
  .chat-question-answer {
    color: var(--ink);
    font-weight: 600;
  }
  .chat-question-check {
    margin-left: 4px;
    color: var(--green);
  }

  /* A proposal: a card across the column while open, with its actions and
     Discuss; once answered, its title opening to the body, the chosen label
     and a check below the title. Its answered line is a centered sentence. */
  .chat-message-proposal {
    align-self: stretch;
    max-width: none;
  }
  .chat-message-proposal .chat-message-meta { text-align: center; }
  .proposal-card {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--amber-bg);
  }
  .offer-card { background: var(--bubble-assistant); }
  .offer-card .proposal-title { margin-bottom: 12px; }
  .offer-card .settings-list-line { flex-wrap: nowrap; }
  .offer-card .button { white-space: nowrap; }
  .proposal-card-closed {
    padding: 0;
    border: 0;
    background: none;
  }
  .proposal-title {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
    overflow-wrap: anywhere;
  }
  .proposal-body {
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  .proposal-mail-text { white-space: pre-wrap; }
  .proposal-body.proposal-mail-text { margin: 10px 0; }
  .proposal-passage { margin-top: 10px; }
  .proposal-passage + .proposal-passage { padding-top: 8px; border-top: 1px solid var(--line); }
  /* What approving sets up, a checkbox per part, and once answered what
     became of each part, under the folded card. */
  .proposal-parts { margin: 10px 0 0; }
  .proposal-body + .chat-brief { margin-top: 10px; }
  .proposal-part {
    align-items: flex-start;
    min-height: 32px;
    padding: 6px 0;
    font-size: 15px;
    line-height: 1.4;
  }
  .proposal-part input { flex: none; margin-top: 1px; }
  .proposal-part-text { min-width: 0; overflow-wrap: anywhere; }
  /* A part the agent gave a line: the sentence over its muted kind and
     schedule; a new routine's prompt or command folds under it, in line
     with the text past the checkbox. */
  .proposal-part-text:has(.proposal-part-meta) { display: grid; gap: 2px; }
  .proposal-part-meta { color: var(--muted); font-size: 13px; line-height: 1.35; }
  .proposal-part-fold { margin: 2px 0 6px 30px; background: var(--paper); }
  .proposal-part-fold .chat-brief-summary { min-height: 38px; padding: 8px 12px; }
  .proposal-part-fold .chat-brief-body { padding: 10px 12px 12px; font-size: 14px; }
  .proposal-routine-check { margin: 6px 0 8px 30px; padding: 0 12px; }
  /* A long check wraps inside the card, as an agent's prompt does. */
  .proposal-routine-check .chat-routine-input { margin: 4px 0 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
  .proposal-part-prompt { white-space: pre-wrap; overflow-wrap: anywhere; }
  .proposal-outcomes {
    display: grid;
    gap: 4px;
    margin: 8px 0 0;
    padding: 0 14px;
    list-style: none;
    font-size: 14px;
    line-height: 1.4;
  }
  .proposal-outcome { overflow-wrap: anywhere; }
  .proposal-outcome-link { color: var(--green); font-weight: 600; }
  .proposal-outcome-state { margin-left: 8px; color: var(--muted); }
  .proposal-outcome-failed { color: var(--red); }
  /* A message card's recipients and subject, above the draft. */
  .proposal-to { margin: 6px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
  @media (max-width: 719.98px) {
    .proposal-part { min-height: 44px; padding: 10px 0; }
  }
  /* Dismiss and Discuss: quiet text at the end of the buttons' row, their
     padding hanging into the card's so the words line up with its edge,
     and narrow enough that a phone keeps Send and Always allow beside
     them. */
  .proposal-quiet-group { display: inline-flex; margin: 0 -8px 0 auto; }
  .proposal-quiet {
    padding-right: 8px;
    padding-left: 8px;
    border-color: transparent;
    background: none;
    color: var(--muted);
  }
  .proposal-quiet:hover { background: var(--hover-tint); color: var(--ink); }
  .proposal-refusal {
    margin: 8px 0 0;
    color: var(--red);
    font-size: 13px;
  }
  .proposal-details > .proposal-summary {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr);
    gap: 4px 10px;
    align-items: baseline;
  }
  .proposal-summary::before { margin: 0; }
  .proposal-summary-title { min-width: 0; overflow-wrap: anywhere; }
  .proposal-choice {
    grid-column: 2;
    min-width: 0;
    font-weight: 600;
  }
  .proposal-check {
    margin-left: 4px;
    color: var(--green);
  }

  /* A purchase: a card across the column, the merchant and total over its
     state, the items and totals, the receipt once paid, the reason folded,
     and while open Approve (a link to Link's page), Dismiss, and Discuss. */
  .chat-message-purchase {
    align-self: stretch;
    max-width: none;
  }
  .chat-message-purchase .chat-message-meta { text-align: center; }
  .purchase-card {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
  }
  .purchase-card[data-state="waiting"] { background: var(--amber-bg); }
  .purchase-card-closed { color: var(--muted); text-align: center; border: 0; background: none; }
  .purchase-gone { margin: 0; }
  .purchase-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
  }
  .purchase-merchant { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
  .purchase-total { font-weight: 600; font-variant-numeric: tabular-nums; }
  .purchase-state,
  .purchase-message,
  .purchase-finish,
  .purchase-test { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
  .purchase-state.is-bad { color: var(--red); }
  .purchase-message,
  .purchase-test { color: var(--muted); }
  .purchase-link { color: inherit; text-decoration: underline; }
  /* A prepared line (chat/messages.ts) puts the sentence under its text,
     in the line's own size. */
  .chat-message-prepared .purchase-finish { margin-top: 4px; font-size: inherit; }
  .purchase-items { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
  .purchase-item,
  .purchase-totals-row,
  .purchase-receipt-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }
  .purchase-item-name { min-width: 0; overflow-wrap: anywhere; }
  .purchase-item-price,
  .purchase-totals dd { font-variant-numeric: tabular-nums; }
  .purchase-totals,
  .purchase-receipt { display: grid; gap: 2px; margin: 0; font-size: 14px; }
  .purchase-totals { padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); }
  .purchase-totals .is-total { color: var(--ink); font-weight: 600; }
  .purchase-totals dd,
  .purchase-receipt dd { margin: 0; }
  .purchase-receipt dt { color: var(--muted); }
  .purchase-receipt dd { overflow-wrap: anywhere; text-align: right; }
  .purchase-reason-summary { min-height: 32px; }
  .purchase-reason-text { margin: 4px 0 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
  .purchase-approve {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
  }
  .purchase-discuss {
    border-color: transparent;
    background: none;
  }
  .purchase-discuss:hover { border-color: var(--line); }

  /* A message's attached files, above its text: images as thumbnails up to
     240px, other files as tiles with their name and type; each opens the
     file in a new tab. */
  .chat-attachments {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 6px;
    margin-bottom: 4px;
  }
  .chat-message-assistant .chat-attachments { justify-content: flex-start; }
  .chat-message-system .chat-attachments { justify-content: center; margin-top: 4px; }
  .chat-message-proposal .chat-attachments { justify-content: flex-start; }
  .proposal-details > .chat-attachments { margin: 12px 14px 0; }
  .chat-attachment-image {
    display: block;
    max-width: min(240px, 100%);
    line-height: 0;
    border-radius: 12px;
  }
  .chat-attachment-image img {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    object-fit: cover;
  }
  .chat-attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 280px;
    min-height: 52px;
    padding: 8px 14px 8px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
    text-decoration: none;
  }
  .chat-attachment-file:hover { background: var(--bg); }
  .chat-attachment-icon {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--green-bg);
    color: var(--green);
  }
  .chat-attachment-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .chat-attachment-name {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-attachment-type {
    color: var(--muted);
    font-size: 12px;
  }

  .chat-message-meta {
    padding: 0 4px;
    color: var(--muted);
    font-size: 12px;
  }

  /* A message's time shows under it only after a gap of 15 minutes or a
     new day (chat-view.ts). A message that follows closely (is-quiet)
     sits 2px under the one above and keeps a 13px strip for its line,
     where its time fades in on hover or while its menu is open, so nothing
     moves. On a touch screen, with no hover to fill it, the strip folds
     away and the message sits 4px under the one above. "Not saved.", "Cut short.", and "Copied" always show. */
  .chat-message.is-quiet { margin-top: -10px; }
  .chat-message.is-quiet .chat-message-meta { line-height: 13px; }
  .chat-message.is-quiet .chat-message-time {
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 140ms ease-out 120ms, transform 140ms ease-out 120ms;
  }
  .chat-message.is-quiet:hover .chat-message-time,
  .chat-message.is-quiet[data-message-menu] .chat-message-time {
    opacity: 1;
    transform: none;
    transition-delay: 0s;
  }

  /* Reply and Copy beside a plain message's bubble, centered on it: right of
     an agent's, left of the person's own, nearest icon first. They fade in
     on hover and while the message's menu is open, and fade out a moment
     after the pointer leaves, so crossing messages does not flicker. The
     strip's padding spans the gap to the bubble, so the pointer reaches
     them without leaving the message. On a desk a message leaves room for
     them inside the column. On a touch screen a long press opens the menu
     instead, and the message's text is not selected by it. */
  .chat-message-content { position: relative; max-width: 100%; }
  .chat-message-actions {
    position: absolute;
    top: 50%;
    left: 100%;
    display: flex;
    gap: 2px;
    padding-left: 6px;
    opacity: 0;
    transform: translate(-4px, -50%);
    pointer-events: none;
    transition: opacity 140ms ease-out 120ms, transform 140ms ease-out 120ms;
  }
  .chat-message-user .chat-message-actions {
    right: 100%;
    left: auto;
    flex-direction: row-reverse;
    padding-right: 6px;
    padding-left: 0;
    transform: translate(4px, -50%);
  }
  .chat-message:hover .chat-message-actions,
  .chat-message[data-message-menu] .chat-message-actions {
    opacity: 1;
    transform: translateY(-50%);
    pointer-events: auto;
    transition-delay: 0s;
  }
  @media (hover: hover) {
    .chat-message[data-message-actions] { max-width: min(44em, 100% - 68px); }
  }
  .chat-message-foot {
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .chat-message-user > .chat-message-foot { flex-direction: row-reverse; }
  .chat-message-unsent { color: var(--muted); font-size: 13px; }
  .chat-message-copied {
    padding: 0 4px;
    color: var(--muted);
    font-size: 12px;
  }
  .chat-message.is-quiet .chat-message-copied { line-height: 13px; }
  @media (hover: none) {
    .chat-message-actions { display: none; }
    .chat-message.is-quiet { margin-top: -8px; }
    .chat-message.is-quiet:not(.is-copied) .chat-message-meta.is-time-only { display: none; }
    .chat-message[data-message-actions] {
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      user-select: none;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    .chat-message-actions { transform: translateY(-50%); }
    .chat-message.is-quiet .chat-message-time { transform: none; }
  }
  .message-menu .message-menu-entry { gap: 10px; }
  .message-menu .message-menu-entry svg { flex: none; color: var(--muted); }

  /* The person's message past fifteen lines folds: the text stops at
     fifteen lines and fades out, and Show more under it in the bubble
     unfolds it in place and becomes Show less. */
  .chat-message-fold.is-collapsed {
    max-height: calc(15lh);
    overflow: hidden;
  }
  .chat-message.is-long .chat-message-fold.is-collapsed {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 2lh), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 2lh), transparent);
  }
  .chat-message-more {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    white-space: nowrap;
  }
  .chat-message-more[hidden] { display: none; }
  .chat-message-more-chevron { flex: none; transition: transform 120ms ease; }
  .chat-message-more[aria-expanded="true"] .chat-message-more-chevron { transform: rotate(180deg); }

  /* A message that answers another: a quote of that one above it, who
     wrote it over a line of its text, which reveals it when pressed. */
  .chat-message-reply {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    min-width: 0;
    max-width: min(100%, 28em);
    margin-bottom: 2px;
    padding: 4px 10px 5px;
    border: 0;
    border-left: 3px solid var(--rule);
    border-radius: 4px;
    background: var(--hover-tint);
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
  }
  .chat-message-reply:hover { color: var(--ink); }
  /* A quote of a message the person deleted: the same quote, in italics,
     leading nowhere. */
  .chat-message-reply-deleted { font-style: italic; cursor: default; }
  .chat-message-reply-deleted:hover { color: var(--muted); }
  .chat-message-reply-name { color: var(--ink); font-weight: 600; }
  .chat-message-reply-text {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Delete's question under the person's message (.delete-confirm,
     agents.css), at the bubble's edge. */
  .chat-message-confirm { width: max-content; max-width: 100%; margin-top: 4px; font-size: 14px; }
  /* The message after it keeps a full gap, not a close one's. */
  .chat-message:has(> .chat-message-confirm) + .chat-message.is-quiet { margin-top: 0; }

  /* A date line between days in a chat. */
  .chat-day {
    align-self: center;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.02em;
    text-align: center;
  }

  /* The morning brief's notice: a card on the reply bubble's surface
     (.chat-message-assistant .chat-message-text), its heading and
     time in a row over the day at a glance, and Open brief under them. */
  .chat-message-brief-card {
    align-self: flex-start;
    align-items: flex-start;
    max-width: min(100%, 30rem);
  }
  .chat-brief-card {
    padding: 12px 14px 14px;
    border: 1px solid var(--bubble-assistant-border);
    border-radius: 10px;
    background: var(--bubble-assistant);
    color: var(--ink);
  }
  .chat-brief-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    line-height: 1.4;
  }
  .chat-brief-card-title { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
  .chat-brief-card-time { flex: none; color: var(--muted); font-size: 12px; }
  .chat-brief-card-opening {
    margin-top: 6px;
    font-size: 15px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  .chat-brief-card-opening.markdown > * + * { margin-top: 0.4em; }
  .chat-brief-card-open { display: block; margin-top: 12px; }

  /* A line that opens to more: a routine's run, a delegation, a context. */
  .chat-message-brief {
    align-self: stretch;
    align-items: stretch;
    max-width: none;
  }
  .chat-message-brief .chat-message-meta { text-align: center; }
  .chat-brief {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
  }
  /* The summary is a fold (components.css's .fold-mark): the chevron, in
     the accent, then the card's line. */
  .chat-brief-summary {
    display: block;
    min-height: 44px;
    padding: 11px 14px;
    box-sizing: border-box;
    color: var(--ink);
    font-size: 14px;
    line-height: 22px;
    overflow-wrap: anywhere;
  }
  .chat-brief[open] .chat-brief-summary { border-bottom: 1px solid var(--line); }
  .chat-brief-summary::before { border-color: var(--green); }
  .chat-brief-body {
    padding: 12px 14px 14px;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  /* A message another agent sent: the sender's name above the bubble. */
  .chat-message-sender {
    display: inline-flex;
    align-items: center;
    gap: 2px;
  }
  .chat-message-from {
    padding: 0 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
  }
  .chat-message-from:hover,
  .chat-message-from:focus-visible { color: var(--ink); text-decoration: underline; }

  /* A line about a delegation: centered like a date line; the agent's name
     links to its chat. A finished one reuses the brief's disclosure row. */
  .chat-delegation-text a {
    color: var(--green);
    text-decoration: none;
  }
  .chat-delegation-text a:hover,
  .chat-delegation-text a:focus-visible { text-decoration: underline; }
  .chat-delegation-link {
    color: var(--green);
    text-decoration: none;
  }
  .chat-delegation-link:hover,
  .chat-delegation-link:focus-visible { text-decoration: underline; }

  /* An agent named with @ in a sent message. */
  .mention {
    display: inline-block;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--side);
    color: var(--green);
    font-weight: 600;
    line-height: 1.35;
  }

  /* Markdown in a message body (markdown.js). A one-line message is one
     paragraph with no margins, so it reads as plain text did. */
  .markdown > :first-child { margin-top: 0; }
  .markdown :where(p, ul, ol, pre, blockquote, h3, h4, h5, hr) { margin: 0; }
  .markdown > * + *,
  .markdown li > * + *,
  .markdown blockquote > * + * { margin-top: 0.6em; }
  .markdown .md-heading {
    font-size: 1em;
    font-weight: 650;
    line-height: inherit;
  }
  .markdown h3.md-heading { font-size: 1.07em; }
  .markdown * + .md-heading { margin-top: 0.9em; }
  .markdown ul,
  .markdown ol { padding-left: 1.4em; }
  .markdown li + li { margin-top: 0.2em; }
  .markdown li > ul,
  .markdown li > ol { margin-top: 0.2em; }
  .markdown code {
    padding: 0.1em 0.3em;
    border-radius: 4px;
    background: var(--side);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.88em;
  }
  .markdown pre {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--side);
    overflow-x: auto;
    white-space: pre;
    overflow-wrap: normal;
  }
  .markdown pre code {
    padding: 0;
    background: none;
    font-size: 13px;
    line-height: 1.45;
  }
  .markdown .md-table {
    max-width: 100%;
    overflow-x: auto;
  }
  .markdown .md-table:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
  }
  .markdown .md-table table {
    border-collapse: collapse;
    width: max-content;
    font-variant-numeric: tabular-nums;
  }
  .markdown .md-table :is(th, td) {
    max-width: 24em;
    padding: 6px 14px 6px 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    overflow-wrap: break-word;
  }
  .markdown .md-table :is(th, td):last-child { padding-right: 0; }
  .markdown .md-table th { font-weight: 600; }
  .markdown .md-table [data-align="center"] { text-align: center; }
  .markdown .md-table [data-align="right"] { text-align: right; white-space: nowrap; }
  .markdown blockquote {
    padding-left: 12px;
    border-left: 3px solid var(--line);
    color: var(--ink-soft);
  }
  .markdown hr {
    height: 0;
    border: 0;
    border-top: 1px solid var(--line);
  }
  .markdown a { color: var(--green); }

  .chat-request {
    max-height: 60%;
    padding: 12px 24px;
    overflow: auto;
    background: var(--amber-bg);
    border-top: 1px solid var(--line);
  }

  .request-card {
    padding: 12px 0;
  }
  .request-card + .request-card { border-top: 1px solid var(--border-faint); }

  .request-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin-bottom: 8px;
  }

  .request-chip {
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--paper);
    color: var(--amber);
    font-size: 12px;
    font-weight: 600;
  }

  .request-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  .request-options {
    display: grid;
    gap: 8px;
  }

  .option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .option:hover { border-color: var(--rule); }
  .option[aria-pressed="true"] {
    border-color: var(--green);
    background: var(--green-bg);
    box-shadow: inset 0 0 0 1px var(--green);
  }
  .option:disabled { color: var(--muted); cursor: default; }

  .option-label { font-weight: 600; }
  .option-description { color: var(--muted); font-size: 13px; }

  .request-other {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 8px;
  }
  .request-other-label { font-weight: 600; }

  .request-other-field {
    flex: 1;
    min-width: 160px;
    min-height: var(--field-height);
    padding: 0 var(--field-pad-x);
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
  }

  .request-input {
    max-height: 240px;
    margin: 0 0 8px;
    padding: 10px 12px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre;
  }

  .request-note {
    margin: 0 0 8px;
    color: var(--amber);
    font-size: 13px;
  }

  /* An approval's command, folder, files, or permissions. */
  .request-details {
    display: grid;
    /* A long command or input scrolls inside the card. */
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin: 0 0 8px;
  }
  .request-detail { margin: 0; }
  .request-detail-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  .request-detail .request-input { margin: 4px 0 0; }
  .request-detail ul {
    margin: 0;
    padding-left: 1.2em;
    overflow-wrap: anywhere;
  }
  .request-detail-text { overflow-wrap: anywhere; }

  .request-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding-top: 8px;
  }

  .request-missing { color: var(--red); font-size: 13px; }

  /* The chat's own composer: one rounded box in the message column's
     centered width, with no divider above it, holding the input and, under
     it, the bar (the attach slot, the model button or note, and the round
     button). Focus anywhere in the box rings the box. Other composers
     (Goals, Feed instructions) keep the plain .composer look. */
  .composer.chat-composer {
    padding-top: 4px;
    padding-bottom: max(16px, var(--composer-inset-bottom, env(safe-area-inset-bottom)));
    border-top: 0;
  }
  .chat-composer .composer-box,
  .chat-composer .composer-reason,
  .chat-composer .composer-runtime-trouble {
    max-width: 820px;
    margin-inline: auto;
  }
  .chat-composer .composer-reason {
    margin-top: 8px;
    padding: 0 18px;
  }

  .chat-composer .composer-runtime-trouble {
    margin-top: 0;
    margin-bottom: 8px;
    padding: 0 18px;
    color: var(--red);
    font-size: 13px;
  }

  /* The paperclip at the bar's left, a 44px target like the round button. */
  .attach-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    cursor: pointer;
  }
  .attach-button:hover,
  .attach-button:focus-visible { color: var(--ink); background: var(--bg); }
  .attach-button:disabled { color: var(--faint); background: none; cursor: default; }

  /* Dictate, between the model button and the round button, in the
     paperclip's look. While listening it is Stop, the square icon on the
     tint a pressed or open button takes. The piece still being heard is
     the line under the box, in italics. */
  .mic-button { flex: none; }
  .mic-button[data-mode="dictate"] .mic-button-stop,
  .mic-button[data-mode="listening"] .mic-button-mic { display: none; }
  .mic-button[data-mode="listening"] { color: var(--ink); background: var(--bg); }
  .composer-reason.composer-reason-heard { font-style: italic; }
  /* Sign in after a runtime's sentence: the chat's Retry link, at the
     reason line's size. */
  .composer-reason .composer-sign-in,
  .composer-runtime-trouble .composer-sign-in { min-height: 0; padding: 0 2px; font-size: inherit; }

  /* The attached files above the input: 64px rounded squares, an image as
     its thumbnail and any other file as an icon over its name and type. A
     spinner covers a tile while it uploads, a failed one is ringed in red,
     and the x at the corner removes it: a small dark disc in a 44px target,
     shown on hover or focus with a pointer and always on touch. */
  .attach-tile {
    position: relative;
    flex: none;
    width: 64px;
    height: 64px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
  }
  .attach-thumb {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 11px;
    object-fit: cover;
  }
  .attach-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    height: 100%;
    padding: 4px 5px;
    color: var(--muted);
    text-align: center;
  }
  .attach-icon { display: inline-flex; }
  .attach-name {
    max-width: 100%;
    overflow: hidden;
    color: var(--ink);
    font-size: 11px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .attach-ext {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
  }
  .attach-tile[data-status="preparing"] > :not(.attach-spinner):not(.attach-remove),
  .attach-tile[data-status="uploading"] > :not(.attach-spinner):not(.attach-remove) { opacity: 0.45; }
  .attach-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border: 2px solid var(--line);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: attach-spin 0.8s linear infinite;
  }
  @keyframes attach-spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) {
    .attach-spinner { animation-duration: 2.4s; }
  }
  .attach-tile[data-status="failed"] {
    border-color: var(--red);
    box-shadow: 0 0 0 1px var(--red);
  }
  .attach-tile[data-status="failed"] > .attach-thumb,
  .attach-tile[data-status="failed"] > .attach-file { opacity: 0.45; }
  .attach-failed {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border-radius: 50%;
    background: var(--red);
    color: var(--on-accent);
    font-size: 13px;
    font-weight: 700;
  }
  .attach-remove {
    position: absolute;
    top: -16px;
    right: -16px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    opacity: 0;
  }
  .attach-tile:hover .attach-remove,
  .attach-remove:focus-visible { opacity: 1; }
  @media (hover: none) {
    .attach-remove { opacity: 1; }
  }
  .attach-remove-disc {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--paper);
    border-radius: 50%;
    background: var(--ink);
    color: var(--paper);
  }
  .attach-remove:hover .attach-remove-disc { background: var(--ink-soft); }

  /* The round button: Send (an arrow) while the turn is closed, Stop (a
     square) while it is open, a 36px disc inside a 44px target. The ink
     disc fades when Send has nothing to send. */
  .round-button {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 4px;
    border: 0;
    border-radius: 50%;
    background: var(--ink);
    background-clip: content-box;
    color: var(--paper);
    cursor: pointer;
  }
  .round-button:hover { background-color: var(--ink-soft); }
  .round-button:focus-visible { outline-offset: 0; }
  .round-button:disabled {
    background-color: var(--line);
    color: var(--muted);
    cursor: default;
  }
  /* The dark composer is lighter than a hairline, so the faded disc takes
     the rule to stay a disc. */
  :root[data-theme="dark"] .round-button:disabled { background-color: var(--rule); }
  .round-button[data-mode="send"] .round-button-stop,
  .round-button[data-mode="stop"] .round-button-send { display: none; }

  /* The @ picker over the input: the agents whose name starts with what was
     typed, one per row by name. It stays over the input at every
     width, so the text being typed is never covered. */
  .mention-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    width: min(360px, 100%);
    max-height: 264px;
    overflow: auto;
  }
  /* An agent in the @, To, and quick chat menus: a menu entry
     (components.css's .menu-entry) with the avatar before the name. */
  .mention-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--menu-row);
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-entry);
    background: none;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .mention-option:hover { background: var(--hover-tint); }
  .mention-option[aria-selected="true"] { background: var(--button-tint-hover); }
  .mention-option-name { font-weight: 500; }

  /* In the bar, beside the round button: the model and effort the next
     turn runs on, as a bare button that opens the picker above the box (a
     sheet from the bottom on a phone). */
  .model-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 7px;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }
  .model-button:hover,
  .model-button:focus-visible,
  .model-button[aria-expanded="true"] { color: var(--ink); background: var(--bg); }
  /* The dark composer is raised off the page, so its buttons tint up from
     it rather than down to the page. */
  :root[data-theme="dark"] :is(.attach-button, .model-button):not(:disabled):is(:hover, :focus-visible),
  :root[data-theme="dark"] .mic-button[data-mode="listening"]:not(:disabled),
  :root[data-theme="dark"] .model-button[aria-expanded="true"]:not(:disabled) {
    background: color-mix(in srgb, var(--ink) 8%, var(--composer));
  }
  .model-button:disabled {
    color: var(--muted);
    background: none;
    cursor: default;
  }
  .model-button svg { flex: none; }
  /* Short of room the name ends in an ellipsis. */
  .model-button { max-width: 100%; min-width: 0; }
  .model-button > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .model-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    z-index: 3;
    width: min(420px, 100%);
    padding: 12px 10px 10px;
  }
  .model-menu-heading {
    margin: 0 0 4px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
  }
  .model-menu-heading + .model-menu-heading,
  .model-list + .model-menu-heading { margin-top: 12px; }
  .model-list {
    display: flex;
    flex-direction: column;
  }
  .model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: var(--menu-row);
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-entry);
    background: none;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .model-option:hover { background: var(--hover-tint); }
  .model-option[aria-selected="true"] {
    background: var(--green-bg);
    font-weight: 600;
  }
  .model-option-default {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
  }
  .effort-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  /* Effort's levels are secondary buttons in a row, the chosen one in the
     accent's tint. */
  .effort-option {
    flex: 1 1 0;
    min-height: var(--menu-row);
    padding: 0 8px;
    white-space: nowrap;
    border: 1px solid transparent;
    border-radius: var(--radius-entry);
    background: var(--button-tint);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  .effort-option:hover { background: var(--button-tint-hover); }
  .effort-option[aria-pressed="true"] {
    border-color: var(--green);
    background: var(--green-bg);
    font-weight: 600;
  }
  .model-menu-reset {
    display: block;
    min-height: var(--menu-row);
    margin: 6px 0 0;
    padding: 0 10px;
    border: 0;
    background: none;
    color: var(--green);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }
  .model-menu-reset:hover,
  .model-menu-reset:focus-visible { color: var(--green-dark); }
  .model-menu-reset:disabled { color: var(--muted); cursor: default; }

  /* The agent is working: a dot after the last message that breathes, as
     ChatGPT's does, and holds still under reduced motion. While the
     runtime waits to try again, a line beside it says so in the muted
     13px of a system line (.chat-message-system .chat-message-text). */
  .chat-working {
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin: 6px 0 6px 6px;
  }
  .chat-working-dot {
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ink);
    animation: chat-working 1.2s ease-in-out infinite;
  }
  .chat-working-note {
    min-width: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
  }
  @keyframes chat-working {
    0%, 100% { transform: scale(0.8); opacity: 0.55; }
    50% { transform: scale(1.15); opacity: 1; }
  }
  @media (prefers-reduced-motion: reduce) {
    .chat-working-dot { animation: none; }
  }

  .chat-failure {
    margin: 0;
    padding: 0 24px 12px;
    color: var(--red);
    font-size: 13px;
  }

  @media (max-width: 719.98px) {
    /* One floating row: the outer columns kept clear for the band's toggle
       (or the way back) and its menu, the pill centered between them and as
       wide as the space between them allows. With the row's 12px and the 8px
       gap, each column ends 64px in, past the band's 56px (a 44px control
       from 12px in), and the name ends in an ellipsis only when the space
       runs out. Nothing wraps. The pill and the way back match the band's
       44px rounds and sit on their line. */
    .chat-floating { --chat-row: 52px; --chat-fade: 60px; }
    .chat-floating .chat-title { padding: 0; }
    .chat-floating > .chat-header {
      grid-template-columns: 44px minmax(0, 1fr) 44px;
      gap: 8px;
      padding-top: 6px;
      padding-bottom: 2px;
      padding-left: 12px;
      padding-right: 12px;
    }
    .chat-composing.chat-floating .chat-back { display: inline-flex; }
    /* The way back sits on a round of the controls' fill, so the messages
       passing under it never show through. */
    .chat-floating .ghost-button {
      width: 44px;
      height: 44px;
      border-radius: 999px;
      background: var(--float-fill);
      box-shadow: 0 0 0 1px var(--line), 0 2px 10px var(--shadow-pop);
    }
    /* Under a pointer it still takes the ghost button's hover tint. */
    @media (hover: hover) {
      .chat-floating .ghost-button:hover:not(:disabled) { background: var(--hover-tint); }
    }
    .chat-floating .chat-pill { height: 44px; background: var(--float-fill); }
    .chat-floating button.chat-pill-name[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 10%, var(--paper)); }
    .chat-floating .chat-pill-name { gap: 8px; height: 44px; padding: 0 16px 0 10px; }
    .chat-floating .chat-pill-name:has(> .chat-avatar[hidden]) { padding-left: 16px; }
    .chat-floating button.chat-pill-name:not([aria-expanded="true"]):not(:focus-visible) .chat-pill-chevron { display: none; }
    .chat-floating > .chat-to { padding-left: 16px; padding-right: 16px; }

    /* The settings cover the whole chat and stay under the floating
       controls (5). */
    .chat-details {
      position: absolute;
      inset: 0;
      z-index: 1;
      padding: var(--controls-h) 16px 96px;
      border-left: 0;
    }
    .chat-details > .pane-tabs { margin: 0 -16px 16px; padding: 0 4px; --pane-tab-padding: 6px; }
    .chat-details > #agent-pane-tabs.pane-tabs { margin: 0 0 16px; padding: 0; }

    .chat-header,
    .chat-notice,
    .chat-description,
    .chat-subtitle,
    .chat-messages,
    .chat-request,
    .composer,
    .chat-failure {
      padding-left: 16px;
      padding-right: 16px;
    }

    /* The @ picker stays over the input on a phone, so what is typed stays
       in view; only the model picker becomes a sheet from the bottom. */
    .mention-menu { max-height: 200px; }
    .model-menu {
      position: fixed;
      inset: auto 0 var(--nav-bar-h);
      z-index: 7;
      width: auto;
      padding: 16px 10px;
      border-radius: var(--radius-card) var(--radius-card) 0 0;
      box-shadow: 0 -8px 24px var(--shadow-sheet);
    }
  }
}
