/* ============================================================================
   Thread Sidebar
   ============================================================================ */

.thread-sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  inline-size: min(450px, 100vw);
  background-color: var(--color-bg);
  border-inline-start: 1px solid var(--color-surface-high);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transform: translateX(100%);
  transition: transform 300ms ease;
  overflow: hidden;
}

.thread-sidebar--open {
  transform: translateX(0);
}

/* Full-screen overlay on mobile */
@media (max-width: 100ch) {
  .thread-sidebar {
    inline-size: 100vw;
  }
}

/* Header */
.thread-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-block-end: 1px solid var(--color-surface-high);
  flex-shrink: 0;
  min-block-size: 3rem;
  gap: 0.5rem;
}

.thread-sidebar__title {
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
  flex: 1;
}

.thread-sidebar__close {
  color: var(--color-text-variant);
  padding: 0.25rem;
  border-radius: 0.375rem;
  flex-shrink: 0;
  z-index: 1;
}

.thread-sidebar__close:hover {
  background-color: var(--color-surface-high);
}

/* Thread sidebar content wrapper — fill the sidebar */
.thread-sidebar__content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-block-size: 0;
}

/* Parent message */
.thread-sidebar__parent {
  padding: 0.75rem 1rem;
  background-color: var(--color-surface-low);
  border-block-end: 1px solid var(--color-surface-high);
  flex-shrink: 0;
  overflow: hidden;
}

.thread-sidebar__parent .message,
.thread-sidebar__replies .message {
  padding-inline: 0;
}

/* Compact message layout inside thread sidebar */
.thread-sidebar .message {
  grid-template-areas:
    "sep sep"
    "avatar body";
  grid-auto-columns: min-content 1fr;
  column-gap: 0.5rem;
  row-gap: 0;
  padding-inline: 0.5rem;
}

.thread-sidebar .message__avatar {
  --avatar-size: 1.75rem;
  --avatar-border-size: 0;

  align-self: start;
  margin-block-start: 0.2rem;
}

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

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

/* Hide reply badge inside thread sidebar — it's redundant */
.thread-sidebar .reply-badge {
  display: none;
}

/* Separator with reply count */
.thread-sidebar__separator {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
  border-block-end: 1px solid var(--color-surface-high);
}

.thread-sidebar__reply-count {
  font-family: var(--font-system);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-variant);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Replies list */
.thread-sidebar__replies {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.thread-sidebar__replies .message {
  padding-inline: 1rem;
}

/* Thread composer */
.thread-sidebar__composer {
  padding: 0.75rem 1rem;
  border-block-start: 1px solid var(--color-surface-high);
  flex-shrink: 0;
}

.thread-composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.thread-composer__input trix-editor {
  min-block-size: 3rem;
  max-block-size: 8rem;
  overflow-y: auto;
}

.thread-composer__actions {
  display: flex;
  justify-content: flex-end;
}

/* Reply badge (in main timeline) */
.reply-badge {
  display: inline-block;
  font-family: var(--font-system);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  padding: 0.15rem 0;
  text-decoration: none;
}

.reply-badge:hover {
  text-decoration: underline;
}

/* Backdrop overlay for mobile */
.thread-sidebar__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9;
}

@media (max-width: 100ch) {
  .thread-sidebar--open + .thread-sidebar__backdrop {
    display: block;
  }
}

/* Search result thread context */
.search-result__thread-context {
  padding: 0.25rem 1rem 0.5rem;
  font-size: 0.8rem;
}

.search-result__thread-label {
  color: var(--color-text-variant);
  font-weight: 500;
}

.search-result__thread-link {
  color: var(--color-primary);
  text-decoration: none;
}

.search-result__thread-link:hover {
  text-decoration: underline;
}

/* Highlighted message in thread */
.message--highlighted {
  animation: highlight-fade 3s ease-out;
}

@keyframes highlight-fade {
  0% { background-color: color-mix(in srgb, var(--color-primary-container) 30%, transparent); }
  100% { background-color: transparent; }
}

/* Reply badge unread indicator */
.reply-badge--unread {
  background: rgba(91, 110, 234, 0.1);
  border-color: rgba(91, 110, 234, 0.25);
}

.reply-badge__new {
  background: #5b6eea;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.05em 0.4em;
  border-radius: 0.5em;
  margin-left: 0.4em;
}
