#thread-panel {
  display: none;
  flex-direction: column;
  grid-area: sidebar;
  min-block-size: 0;
  min-inline-size: 0;
  z-index: 4;
}

#thread-panel.thread-panel--open,
body.thread-open #thread-panel {
  display: flex;
}

.thread-panel__backdrop {
  display: none;
}

.thread-panel__chrome {
  background-color: var(--color-bg);
  block-size: 100dvh;
  display: flex;
  flex-direction: column;
  max-block-size: 100dvh;
  min-block-size: 0;
}

.thread-panel__header {
  align-items: center;
  border-block-end: 1px solid var(--color-border-dark);
  display: flex;
  flex-shrink: 0;
  gap: 0.5em;
  justify-content: space-between;
  padding: 0.85em 1em;
}

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

.thread-panel__close {
  flex-shrink: 0;
}

.thread-panel__messages {
  --message-column-gap: 0.66ch;
  --message-row-gap: 0.1em;
  --message-space: 1.33em;

  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.75em;
  min-block-size: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 0.75em;
}

.thread-panel__parent {
  border-block-end: 1px solid var(--color-border);
  padding-block-end: 0.75em;
}

.thread-panel__replies {
  display: flex;
  flex-direction: column;
  gap: var(--block-space, 1em);
}

.thread-panel__composer {
  border-block-start: 1px solid var(--color-border);
  flex-shrink: 0;
  padding: 0.75em 1em calc(0.75em + env(safe-area-inset-bottom, 0px));
}

#thread-panel .thread-summary,
#thread-panel .message__day-separator {
  display: none !important;
}

#thread-panel .message {
  --thread-avatar-col: 3.5ch;

  grid-auto-columns: var(--thread-avatar-col) minmax(0, 1fr) var(--thread-avatar-col);
  max-inline-size: 100%;
  min-inline-size: 0;
  padding-inline: 0.75em;
  visibility: visible;
}

#thread-panel .message--me {
  grid-auto-columns: var(--thread-avatar-col) minmax(0, 1fr) var(--thread-avatar-col);
}

#thread-panel .message__body {
  max-inline-size: 100%;
  min-inline-size: 0;
}

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

#thread-panel .message__meta,
#thread-panel .message__heading {
  column-gap: 0.5em;
  max-inline-size: 100%;
}

#thread-panel .message__permalink {
  flex-shrink: 0;
}

#thread-panel .message--me .message__avatar {
  margin-inline: 0;
}

/* Only the panel frame is a flex column. Message edit frames must keep
   the global `turbo-frame { display: contents }` so `.message__body`
   stays a grid item. A descendant `display: flex` collapses replies
   into a smashed meta pill with no body. */
#thread-panel-frame {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-block-size: 0;
}

#thread-panel .message turbo-frame {
  display: contents;
}

@media (max-width: 100ch) {
  #thread-panel.thread-panel--open,
  body.thread-open #thread-panel {
    inset: 0;
    position: fixed;
    z-index: 6;
  }

  .thread-panel__backdrop {
    background: oklch(var(--lch-black) / 0.28);
    display: block;
    inset: 0;
    position: fixed;
    z-index: -1;
  }

  .thread-panel__chrome {
    background-color: var(--color-bg);
    position: relative;
    z-index: 1;
  }
}

@media (min-width: 100ch) {
  .thread-panel__chrome {
    border-inline-start: 1px solid var(--color-border-darker);
  }
}
