.chat-desktop-menu {
  box-sizing: border-box;
  width: 15rem;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-desktop-menu::backdrop {
  background: transparent;
  pointer-events: none;
}

.chat-desktop-reactions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  margin-bottom: 4px;
  padding: 2px 2px 5px;
  border-bottom: 1px solid #dce8df;
}

.chat-desktop-menu .chat-desktop-reaction {
  display: grid;
  place-items: center;
  min-height: 36px;
  padding: 3px;
  font-size: 19px;
  line-height: 1.15;
}

.chat-desktop-menu .chat-desktop-action {
  display: grid;
  grid-template-columns: 19px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 37px;
  padding: 6px 9px;
  font-size: 14px;
  line-height: 1.28;
}

.chat-desktop-action svg {
  width: 19px;
  height: 19px;
}

.chat-desktop-menu .chat-desktop-reaction[aria-pressed="true"] {
  background: #dcefe1;
  box-shadow: inset 0 0 0 1px #98bca4;
}

.chat-desktop-menu button:focus-visible,
#chat-reply-bar button:focus-visible,
.chat-reply-quote:focus-visible,
.chat-reaction:focus-visible {
  outline: 2px solid #387c62;
  outline-offset: -2px;
}

.desktop-chat #chat-conversation #chat-form:has(> #chat-reply-bar:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  row-gap: 4px;
}

#chat-reply-bar {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 5px 4px 9px;
  border-inline-start: 3px solid #659a7d;
  border-radius: 7px;
  background: #edf6ef;
  color: #214b3d;
}

#chat-reply-bar[hidden] {
  display: none;
}

.chat-reply-reference {
  display: grid;
  flex: 1 1 0;
  gap: 1px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: start;
}

#chat-reply-bar > button:not(.chat-reply-reference) {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #416a5a;
  font-size: 22px;
  line-height: 1;
}

#chat-reply-bar > button:not(.chat-reply-reference):hover {
  background: #dceee2;
}

.chat-reply-quote {
  display: grid;
  gap: 2px;
  min-width: 0;
  max-width: min(100%, 22rem);
  margin-bottom: 5px;
  padding: 4px 8px;
  border: 0;
  border-inline-start: 3px solid #659a7d;
  border-radius: 7px;
  background: #e9f4ed;
  color: #244e40;
  text-align: start;
}

.chat-message.mine .chat-reply-quote {
  background: #cfe7d7;
}

.chat-reply-quote:hover {
  border-color: #487d64;
  background: #dfefe5;
}

.chat-message.mine .chat-reply-quote:hover {
  background: #c6e1d0;
}

.chat-reply-author,
.chat-reply-excerpt {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.32;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-reply-author {
  color: #215d49;
  font-weight: 700;
}

.chat-reply-excerpt {
  color: #385e50;
}

.chat-message > .chat-reactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
}

#chat-messages .chat-reaction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 36px;
  min-height: 26px;
  padding: 2px 6px;
  border: 0;
  border-radius: 999px !important;
  background: #eaf5ed;
  color: #295846;
  font-size: 12px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

#chat-messages .chat-reaction[aria-pressed="true"] {
  background: #d7ecdf;
}

.chat-reply-highlight {
  outline: 2px solid #568c69;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
  .chat-reply-highlight {
    animation: chat-reply-focus 2s ease-out both;
  }

  @keyframes chat-reply-focus {
    60% { outline-color: #568c69; }
    100% { outline-color: transparent; }
  }
}

@media (max-width: 799px) {
  #chat-messages .chat-message,
  #chat-messages .chat-message .chat-media-photo,
  #chat-messages .chat-message .chat-media-photo img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  #chat-messages .chat-message,
  #chat-messages :is(.chat-media-photo, .chat-video-action),
  .chat-mobile-message-menu {
    -webkit-tap-highlight-color: transparent;
  }

  .chat-touch-message-menu:focus {
    outline: none;
  }

  #chat-messages .chat-message .chat-media-photo img {
    -webkit-user-drag: none;
    pointer-events: none;
  }

  .chat-mobile-message-menu {
    width: min(16rem, calc(100vw - 16px));
    max-height: calc(var(--chat-screen-height, 100dvh) - 16px);
  }

  .chat-mobile-message-menu .chat-desktop-action {
    min-height: 42px;
  }

  #chat-conversation #chat-form:has(> #chat-reply-bar:not([hidden])) {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    row-gap: 4px;
  }

  #chat-form:has(> #chat-reply-bar:not([hidden])) #chat-text {
    width: 100%;
  }

  #chat-reply-bar > button:not(.chat-reply-reference),
  .chat-mobile-message-menu .chat-desktop-reaction {
    min-height: 42px;
  }
}
