/* Chat's side column — who's around, the rally point and the vibe board.
 * One <aside class="chat-side"> at every width (its stream targets exist once):
 *   narrow: only the vibe toggle above the messages, as before
 *   wide (@container main > 60rem): a right column beside the messages, the
 *   vibe board open, the composer still under the messages.
 */

@layer components {
  .chat-side {
    flex-shrink: 0;
  }

  .chat-side .chat-side__presence,
  .chat-side .chat-side__rally,
  .chat-side .chat-side__vibe-title {
    display: none;
  }

  .chat-side__label {
    margin: 0;
    color: var(--color-ink-muted);
    font-family: inherit;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .chat-side__section {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    border-block-end: 1px solid var(--color-border);
  }

  /* ── Who's around ── */

  .chat-presence {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .chat-presence__link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-height: var(--touch-min);
    padding: 0.25rem;
    border-radius: var(--radius);
    color: var(--color-ink);
    text-decoration: none;

    &:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }

    @media (hover: hover) {
      &:hover { background: color-mix(in oklch, var(--color-ink) 5%, transparent); }
    }
  }

  .chat-presence__avatar {
    position: relative;
    flex-shrink: 0;

    & .status-dot {
      width: 0.625rem;
      height: 0.625rem;
    }
  }

  .chat-presence__main {
    flex: 1;
    display: grid;
    min-width: 0;
  }

  .chat-presence__name {
    font-size: 0.875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-presence__detail {
    color: var(--color-ink-muted);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-presence__row--dark .chat-presence__name {
    color: var(--color-ink-muted);
  }

  .chat-presence__battery {
    color: var(--color-ink-muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
  }

  .chat-presence__battery--low {
    color: var(--color-negative);
    font-weight: 700;
  }

  /* ── Wide: the right column ── */

  @container main (width > 60rem) {
    .group-chat:has(> .chat-side) {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 20rem;
      grid-template-rows: minmax(0, 1fr) auto auto;

      & > * { grid-column: 1; }
      & > turbo-cable-stream-source { display: none; }

      & > .chat-side {
        grid-column: 2;
        grid-row: 1 / -1;
      }

      & .group-chat__messages,
      & .group-chat__typing,
      & .group-chat__compose {
        max-width: 46rem;
      }

      /* Centre the floating pills on the messages, not on both columns. */
      & .new-messages-badge,
      & .chat-coach {
        left: calc((100% - 20rem) / 2);
      }
    }

    .chat-side {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      min-width: 0;
      align-content: start;
      overflow-y: auto;
      background: var(--color-surface);
      border-inline-start: 1px solid var(--color-border);
    }

    .chat-side .chat-side__presence { display: grid; }
    .chat-side .chat-side__rally { display: block; }

    /* Lazy frame: it must stay rendered to load; it only takes room once
       there is an active rally point to show. */
    .chat-side__rally {
      min-height: 1px;

      &:has(.card) {
        padding: 1rem;
        border-block-end: 1px solid var(--color-border);
      }

      /* The Home card, at home in the column. */
      & .card {
        padding: 0;
        border: none;
        background: none;
      }
    }

    .chat-side .vibe-check {
      max-width: none;
      padding: 1rem;
      border: none;
    }

    .chat-side .vibe-check__toggle { display: none; }

    .chat-side .vibe-picker__options {
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      gap: 0.25rem;

      & > form { display: grid; min-width: 0; }
    }

    /* Emoji only in the narrow column; the label stays the button's name
       and shows as a tooltip. */
    .chat-side .vibe-picker__option {
      width: 100%;
      min-width: 0;
      min-height: var(--touch-min);
      justify-content: center;
      padding-inline: 0;
    }

    .chat-side .vibe-picker__emoji { font-size: 1.375rem; }

    .chat-side .vibe-picker__label {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    .chat-side .chat-side__vibe-title { display: block; }

    .chat-side .vibe-check__panel,
    .chat-side .vibe-check__panel--hidden {
      display: block;
      padding: 0.5rem 0 0;
      background: none;
    }
  }
}
