/* Thread panel (layout shell: #thread-panel in layout.css) */

.thread-panel__header {
  align-items: center;
  border-block-end: 1px solid var(--color-border-darker);
  display: flex;
  flex-shrink: 0;
  gap: var(--inline-space-half);
  min-block-size: var(--navbar-height);
  padding-inline: calc(var(--inline-space) + 1vw);
}

.thread-panel__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.thread-panel__room {
  color: var(--color-text);
  opacity: 0.5;
}

.thread-panel__close-btn {
  --btn-padding: 0.35em;

  flex-shrink: 0;
  margin-inline-start: auto;

  /* On narrow screens the panel is a pushed page: the control becomes a
     leading back chevron instead of a trailing X */
  @media (max-width: 100ch) {
    margin-inline-start: 0;
    order: -1;
  }
}

.thread-panel__close-icon {
  display: block;
  inline-size: 1em;
  opacity: 0.75;
}

.thread-panel__close-icon--back {
  display: none;
}

@media (max-width: 100ch) {
  .thread-panel__close-icon--x {
    display: none;
  }

  .thread-panel__close-icon--back {
    display: block;
    inline-size: 1.2em;
  }
}

.thread-panel__close-btn:hover .thread-panel__close-icon {
  opacity: 1;
}

.thread-panel__messages {
  flex: 1;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block-end: var(--block-space-half);

  /* The flat row baseline lives in messages.css; only narrow-column
     adjustments belong here. */

  .message {
    column-gap: 1ch;
    padding-inline: var(--inline-space);
  }

  .message__body {
    max-inline-size: 100%;
  }

  .message__avatar {
    --avatar-size: 3ch;

    box-shadow: none;
  }

  .message--threaded .message__meta {
    inset-inline-end: var(--inline-space);
  }

  /* Divider diet: the in-panel date marker is plain small text */
  .message__day-separator {
    font-size: 0.7rem;
    margin-block: var(--block-space-half);

    &::before,
    &::after {
      display: none;
    }

    time,
    span {
      background: none;
      opacity: 0.6;
      padding: 0.2em;
    }
  }
}

.thread-panel__parent {
  padding: var(--block-space) calc(var(--inline-space) + 1vw) var(--block-space-half);
}

/* Thread parent message: flat layout, no bubble */
.thread-parent {
  display: flex;
  flex-direction: column;
  gap: var(--block-space-half);
}

.thread-parent__header {
  align-items: center;
  display: flex;
  gap: 0.5ch;
}

.thread-parent__avatar {
  --avatar-size: 2.5ch;
  --avatar-border-size: 1px;

  flex-shrink: 0;
  margin-inline-end: 0.2ch;
}

.thread-parent__author {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-parent__time {
  color: var(--color-text);
  font-size: 0.8rem;
  margin-inline-start: auto;
  opacity: 0.5;
  text-decoration: none;
  white-space: nowrap;
}

.thread-parent__body {
  font-weight: 400;
  word-break: break-word;

  .trix-content {
    font-size: 0.95rem;
  }
}

/* Always visible on touch; hover-revealed only where hover exists */
.thread-parent__copy-link {
  --btn-background: transparent;
  --btn-border-color: transparent;
  --btn-padding: 0.35em;

  border-radius: 0.35em;

  @media (hover: hover) and (pointer: fine) {
    opacity: 0;
    transition: opacity 0.15s;

    .thread-parent:hover &,
    &:focus-visible {
      opacity: 1;
    }
  }
}

.thread-panel__earlier {
  color: var(--color-link);
  display: block;
  padding: 0.4em var(--inline-space);
  text-align: center;
}

.thread-panel__empty {
  opacity: 0.5;
  padding: var(--block-space) calc(var(--inline-space) + 1vw);
  text-align: center;
}

/* Loading state while the frame fetches a thread */
.thread-panel__content[busy]:empty::after {
  animation: pulsing-background 1.2s ease-in-out infinite;
  background-color: var(--color-message-bg);
  border-radius: 0.5em;
  content: "";
  display: block;
  block-size: 5em;
  margin: var(--block-space) calc(var(--inline-space) + 1vw);
}

.thread-panel__separator {
  align-items: center;
  display: flex;
  gap: var(--inline-space);
  padding: var(--block-space-half) calc(var(--inline-space) + 0.5vw);

  &::before,
  &::after {
    border-top: 1px solid var(--color-border);
    content: "";
    flex: 1;
  }
}

.thread-panel__separator-text {
  color: var(--color-text);
  font-weight: 600;
  opacity: 0.6;
  white-space: nowrap;
}

.thread-panel__composer {
  flex-shrink: 0;
  padding: var(--block-space-half) calc(var(--inline-space) + 1vw);
  padding-block-end: max(var(--block-space-half), env(safe-area-inset-bottom, 0px));
}

.thread-panel__composer > .composer {
  inline-size: 100%;
  margin: 0;
  min-inline-size: 0;
}

/* Thread badge on messages (inside .message__body-content) */
.thread-badge {
  align-items: center;
  background: none;
  border: 1px solid var(--color-border-dark);
  border-radius: 2em;
  color: var(--color-link);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.8rem;
  font-weight: 500;
  gap: 0.5ch;
  inline-size: fit-content;
  margin-block-start: 0.33em;
  min-block-size: 2.2em;
  padding: 0.25em 1.2ch;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;

  &:hover {
    background-color: oklch(var(--lch-black) / 0.06);
  }
}

.thread-badge__avatars {
  display: inline-flex;

  .avatar {
    --avatar-size: 1.8ch;
    --avatar-border-size: 1px;

    &:not(:first-child) {
      margin-inline-start: -0.4ch;
    }
  }
}

.thread-badge__text {
  white-space: nowrap;
}

.thread-badge__time {
  opacity: 0.6;
  white-space: nowrap;
}

.thread-badge--unread::after {
  background-color: var(--color-link);
  block-size: 0.6em;
  border-radius: 50%;
  content: "";
  inline-size: 0.6em;
}
