/* The app's own rules, loaded after the theme (theme.json: "stylesheet"). */

/* While the agent has not said a word yet, a ring turns around its avatar.
 *
 * Between a question and the first word of the answer the agent searches the
 * documents, which takes 10 to 20 seconds. In that time its message is the
 * avatar alone, with nothing beside it.
 *
 * The rule goes by millwork's own markup, which it does not promise to keep:
 * an assistant message is [data-slot=message][data-align=start], and its
 * [data-slot=message-content] has no children until the first word, a step
 * or an error arrives. A reply that was stopped gets its row of buttons and
 * is no longer empty. If a millwork release changes this, the ring is simply
 * not drawn.
 */
[data-slot="message"][data-align="start"]:has(> [data-slot="message-content"]:empty)
  > [data-slot="message-avatar"] {
  position: relative;
}

[data-slot="message"][data-align="start"]:has(> [data-slot="message-content"]:empty)
  > [data-slot="message-avatar"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2rem;
  height: 2rem;
  margin: -1rem 0 0 -1rem;
  box-sizing: border-box;
  border-radius: 9999px;
  /* The brand's lime, in both schemes: the ring lies on the avatar's own
   * dark green disc, so it does not depend on the page behind it. */
  border: 2px solid hsl(78 73% 44% / 0.22);
  border-top-color: hsl(78 73% 44%);
  animation: agent-waiting 0.9s linear infinite;
  pointer-events: none;
}

@keyframes agent-waiting {
  to {
    transform: rotate(360deg);
  }
}

/* Asked for less motion: the ring is there and stands still. */
@media (prefers-reduced-motion: reduce) {
  [data-slot="message"][data-align="start"]:has(> [data-slot="message-content"]:empty)
    > [data-slot="message-avatar"]::after {
    animation: none;
  }
}

/* A select's menu is as wide as its longest option.
 *
 * millwork makes the menu exactly as wide as the button that opens it and
 * keeps every option on one line, so a project name longer than the
 * switcher in the header was cut off. The menu now grows with its options,
 * is never narrower than the button, and stops at 32rem or at the room the
 * window has. A name that still does not fit goes on to a second line.
 *
 * The menu is drawn outside the page's own tree, so this holds for every
 * ui.Select and cannot be said of the switcher alone. --anchor-width and
 * --available-width are set by millwork on the menu's positioner. As with
 * the ring above, this goes by markup millwork does not promise to keep: if
 * it changes, the menu is as wide as the button again.
 */
[data-slot="select-content"] {
  width: max-content;
  min-width: var(--anchor-width, 9rem);
  max-width: min(32rem, var(--available-width, 100vw));
}

[data-slot="select-item"] > div {
  flex-shrink: 1;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}
