@layer components {

  /* Claude beside the designer (houses/_chat): bottom right of the 3D view, left of the panel. */
  .chat {
    position: fixed;
    right: calc(var(--panel-width) + 14px);
    bottom: 14px;
    z-index: 14;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .chat__open {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 6px 20px color-mix(in oklch, var(--black) 35%, transparent);
  }

  .chat__card {
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - var(--panel-width) - 28px));
    height: min(560px, calc(100vh - 120px));
    box-shadow: 0 10px 30px color-mix(in oklch, var(--black) 35%, transparent);
  }

  .chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 6px 12px;
    border-bottom: 1px solid var(--color-edge);
  }

  .chat__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
  }

  .chat__close {
    padding: 2px 6px;
    color: var(--color-ink-muted);
    background: none;
    border: 0;
    cursor: pointer;

    &:hover {
      color: var(--color-ink);
    }
  }

  .chat__log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    font-size: 13px;
    line-height: 1.45;
  }

  .chat__empty {
    margin: auto 0;
    color: var(--color-ink-muted);
    text-align: center;
  }

  /* Plain text as Claude wrote it: its line breaks and "-" lists kept. */
  .chat__message {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .chat__message--user {
    align-self: flex-end;
    max-width: 85%;
    padding: 6px 10px;
    background: var(--color-primary-surface);
    border-radius: 10px 10px 2px 10px;
  }

  .chat__tool {
    margin: 0;
    font-size: 11px;
    color: var(--color-ink-muted);

    &::before {
      content: "⚙ ";
    }
  }

  .chat__tool--failed {
    color: var(--color-danger-ink);
  }

  .chat__status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: var(--color-ink-muted);

    form {
      margin-left: auto;
    }
  }

  .chat__pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    animation: assistant-pulse 1.2s ease-in-out infinite;
    /* viewer.css */
  }

  .chat__failure {
    margin: 0;
    padding: 6px 10px;
    color: var(--color-danger-ink);
    background: color-mix(in oklch, var(--color-danger) 14%, transparent);
    border-radius: 6px;
  }

  .chat__action {
    padding: 2px 8px;
    font-size: 12px;
  }

  .chat__form,
  .chat__setup {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin: 0;
    padding: 8px 10px 10px;
    border-top: 1px solid var(--color-edge);
  }

  .chat__setup {
    display: block;
    font-size: 12px;
    color: var(--color-ink-muted);
  }

  /* A field as the forms' (form.css .input), without their wrapper. */
  .chat__input {
    flex: 1;
    field-sizing: content;
    /* Control vertical growth using line-height (lh) units */
    min-height: 2lh;
    max-height: 12lh;
    padding: 6px 8px;
    resize: none;
    font: inherit;
    font-size: 13px;
    color: var(--color-ink);
    background-color: var(--color-surface-sunken);
    border: var(--hairline) solid var(--color-line);
    border-radius: 4px;
  }

  @media (prefers-reduced-motion: reduce) {
    .chat__pulse {
      animation: none;
    }
  }

  /* Phones are read-only viewers: no chat there. */
  @media (max-width: 760px) {
    .chat {
      display: none;
    }
  }
}
