/* Область сообщений: pinned bar + лента (без наложения) */
.chat-messages-stack {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}

.chat-messages-stack > .messages {
  flex: 1;
  min-height: 0;
}

.chat-messages-stack--has-pinned {
  padding-top: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}

#chatMessagesStack.chat-messages-stack--has-pinned > .messages {
  padding-top: 86px;
}

#pinnedMessagesBar.pinned-messages-bar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  width: auto;
  max-width: none;
  margin: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 60px;
  max-height: 65px;
  box-sizing: border-box;
  overflow: hidden;
  background: rgba(32, 42, 58, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(90, 150, 255, 0.12);
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  color: var(--text);
  isolation: isolate;
  pointer-events: auto;
}

#pinnedMessagesBar.pinned-messages-bar:not(.hidden) {
  animation: pinnedBarEnter 0.2s ease;
}

[data-theme="light"] #pinnedMessagesBar.pinned-messages-bar {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(90, 150, 255, 0.12);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

#pinnedMessagesBar.pinned-messages-bar.hidden {
  display: none;
}

@keyframes pinnedBarEnter {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  #pinnedMessagesBar.pinned-messages-bar:not(.hidden) {
    animation: none;
  }
}

.pinned-messages-bar__body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: center;
}

.pinned-messages-bar__header-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-bottom: 1px;
}

.pinned-messages-bar__pin-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #6ea8ff;
  line-height: 0;
}

.pinned-messages-bar__pin-icon svg {
  display: block;
}

.pinned-messages-bar__label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  color: color-mix(in srgb, var(--muted, #9aa8bc) 92%, var(--text));
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pinned-messages-bar__counter {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  color: color-mix(in srgb, var(--muted, #9aa8bc) 88%, var(--text));
  opacity: 0.72;
  white-space: nowrap;
}

.pinned-messages-bar__counter.hidden {
  display: none;
}

.pinned-messages-bar__author {
  display: block;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.15;
  color: color-mix(in srgb, var(--text) 58%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pinned-messages-bar__author:empty {
  display: none;
}

.pinned-messages-bar__text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  max-height: 2.4em;
  color: var(--text);
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  transition: color 120ms ease;
  margin-top: 1px;
}

.pinned-messages-bar__body:hover .pinned-messages-bar__text {
  color: color-mix(in srgb, var(--text) 96%, #6ea8ff);
}

.pinned-messages-bar__controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  align-self: center;
}

.pinned-messages-bar__controls:not(:has(.pinned-messages-bar__nav:not(.hidden))) {
  display: none;
}

.pinned-messages-bar__controls-nav-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pinned-messages-bar__nav {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  color: color-mix(in srgb, var(--text) 62%, transparent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.pinned-messages-bar__nav:hover {
  background: rgba(255, 255, 255, 0.1);
  color: color-mix(in srgb, var(--text) 82%, transparent);
}

.pinned-messages-bar__nav:active {
  opacity: 0.82;
}

.pinned-messages-bar__nav.hidden {
  display: none;
}

.pinned-messages-list-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(280px, 40vh);
  overflow-y: auto;
  padding: 6px;
  border-radius: 12px;
  background: rgba(23, 31, 45, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(90, 150, 255, 0.22);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

[data-theme="light"] .pinned-messages-list-panel {
  background: rgba(255, 255, 255, 0.94);
}

.pinned-messages-list-panel.hidden {
  display: none;
}

.pinned-messages-list-panel__item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
}

.pinned-messages-list-panel__item:hover {
  background: rgba(110, 168, 255, 0.1);
}

.pinned-messages-list-panel__meta {
  font-size: 11px;
  color: color-mix(in srgb, var(--text) 65%, transparent);
}

.pinned-messages-list-panel__author {
  font-size: 11px;
  font-weight: 600;
  color: #6ea8ff;
}

.pinned-messages-list-panel__text {
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.message-highlight {
  animation: pinnedMessageHighlight 2s ease;
}

@keyframes pinnedMessageHighlight {
  0% {
    background-color: color-mix(in srgb, var(--accent) 22%, transparent);
    outline: 2px solid color-mix(in srgb, var(--invite-accent, #8ab4ff) 55%, transparent);
    outline-offset: 2px;
    transform: scale(1.01);
  }
  70% {
    background-color: color-mix(in srgb, var(--accent) 10%, transparent);
    outline: 2px solid color-mix(in srgb, var(--invite-accent, #8ab4ff) 25%, transparent);
    outline-offset: 3px;
    transform: scale(1);
  }
  100% {
    background-color: transparent;
    outline: 2px solid transparent;
    outline-offset: 4px;
    transform: scale(1);
  }
}

.bubble.message-highlight,
.channel-post.message-highlight {
  border-radius: 12px;
}

@media (max-width: 640px) {
  #chatMessagesStack.chat-messages-stack--has-pinned > .messages {
    padding-top: 82px;
  }

  #pinnedMessagesBar.pinned-messages-bar {
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 8px 10px;
    min-height: 58px;
    max-height: 64px;
  }

  .pinned-messages-bar__text {
    font-size: 12px;
  }

  .pinned-messages-bar__nav {
    width: 28px;
    height: 28px;
  }
}
